commit c8159dc5cf4489e041f6611e2ecedd9cf05c37e0
Author: Vojtěch Bartička <aitakaitov@gmail.com>
Date:   Mon May 16 19:45:05 2022 +0200

    Added endpoint DELETE /documents

diff --git a/Backend/Backend/Controllers/DocumentController.cs b/Backend/Backend/Controllers/DocumentController.cs
index 17b1aea..284462d 100644
--- a/Backend/Backend/Controllers/DocumentController.cs
+++ b/Backend/Backend/Controllers/DocumentController.cs
@@ -182,6 +182,29 @@ public class DocumentController : Common.CommonControllerBase
         }
     }
 
+    [HttpDelete("/documents")]
+    [Authorize(Models.Enums.ERole.ADMINISTRATOR)]
+    [ProducesResponseType((int)HttpStatusCode.OK)]
+    [ProducesResponseType((int)HttpStatusCode.Forbidden)]
+    public ActionResult DeleteDocument([FromServices] ClientInfo clientInfo, [FromBody] DeleteDocumentsRequest request)
+    {
+        if (clientInfo.LoggedUser == null)
+        {
+            logger.Warning("ClientInfo has null LoggerUser in [Authorized] controller /documents");
+            return Problem();
+        }
+
+        try
+        {
+            documentService.DeleteDocuments(request);
+            return Ok();
+        }
+        catch (InvalidOperationException e)
+        {
+            throw new BadRequestException(e.Message);
+        }
+    }
+
     [HttpPost("/document/{documentId}/final")]
     [Authorize(Models.Enums.ERole.ADMINISTRATOR)]
     [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(CreateFinalAnnotationResponse))]
diff --git a/Backend/Core/Services/DocumentService/DocumentServiceEF.cs b/Backend/Core/Services/DocumentService/DocumentServiceEF.cs
index d5cd380..1b1cc7c 100644
--- a/Backend/Core/Services/DocumentService/DocumentServiceEF.cs
+++ b/Backend/Core/Services/DocumentService/DocumentServiceEF.cs
@@ -148,7 +148,7 @@ namespace Core.Services.DocumentService
                         .Include(fa => fa.Annotations)
                         .ThenInclude(a => a.User)
                         .Single(fa => fa.Document == document);
-                    
+
                     dli.FinalizedAnnotationId = finalizedAnnotation.Id;
                     dli.FinalizedState = finalizedAnnotation.State;
                     dli.FinalAnnotations = new();
@@ -199,6 +199,20 @@ namespace Core.Services.DocumentService
             return int.Parse(requiredAnnotationsItem.Value);
         }
 
+        public void DeleteDocuments(DeleteDocumentsRequest request)
+        {
+            var documentsToDelete = databaseContext.Documents.
+                Where(d => request.DocumentIds.Contains(d.Id)).ToList();
+
+            var associatedAnnotations = databaseContext.Annotations.
+                Where(a => documentsToDelete.Contains(a.Document)).ToList();
+
+            databaseContext.Annotations.RemoveRange(associatedAnnotations);
+            databaseContext.Documents.RemoveRange(documentsToDelete);
+
+            databaseContext.SaveChanges();
+        }
+
         public DocumentPreviewResponse GetDocumentPreview(Guid documentId)
         {
             try
diff --git a/Backend/Core/Services/DocumentService/IDocumentService.cs b/Backend/Core/Services/DocumentService/IDocumentService.cs
index 734146d..3112796 100644
--- a/Backend/Core/Services/DocumentService/IDocumentService.cs
+++ b/Backend/Core/Services/DocumentService/IDocumentService.cs
@@ -12,14 +12,11 @@ namespace Core.Services.DocumentService
     public interface IDocumentService
     {
         public void AddDocuments(DocumentAddRequest request, Guid userId);
-
         public DocumentListResponse GetDocuments();
-
         public DocumentPreviewResponse GetDocumentPreview(Guid documentId);
+        public void DeleteDocuments(DeleteDocumentsRequest request);
         public void SetRequiredAnnotationsForDocuments(SetRequiredAnnotationsRequest request);
-
         public void SetRequiredAnnotationsGlobal(int requiredAnnotations);
-
         public int GetRequiredAnnotationsGlobal();
     }
 }
diff --git a/Backend/Models/Documents/DeleteDocumentsRequest.cs b/Backend/Models/Documents/DeleteDocumentsRequest.cs
new file mode 100644
index 0000000..93808fc
--- /dev/null
+++ b/Backend/Models/Documents/DeleteDocumentsRequest.cs
@@ -0,0 +1,13 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Models.Documents
+{
+    public class DeleteDocumentsRequest
+    {
+        public List<Guid> DocumentIds { get; set; }
+    }
+}
