commit 5adba4c4e8c5ba9091f703e8efecdcd5e1549e3d
Author: Vojtěch Bartička <aitakaitov@gmail.com>
Date:   Wed Apr 27 11:02:48 2022 +0200

    Implemented static global config, added endpoint to set req annotations per document

diff --git a/Backend/Backend/Controllers/DocumentController.cs b/Backend/Backend/Controllers/DocumentController.cs
index ba846bc..acc701f 100644
--- a/Backend/Backend/Controllers/DocumentController.cs
+++ b/Backend/Backend/Controllers/DocumentController.cs
@@ -69,5 +69,35 @@ public class DocumentController : Common.CommonControllerBase
         return Ok();
     }
 
+
+
+
+    [HttpPost("/documents/requiredAnnotations")]
+    [Authorize(Models.Enums.ERole.ADMINISTRATOR)]
+    [ProducesResponseType((int)HttpStatusCode.OK)]
+    [ProducesResponseType((int)HttpStatusCode.Forbidden)]
+    public ActionResult SetRequiredAnnotationsForDocuments([FromServices] ClientInfo clientInfo, [FromBody] SetRequiredAnnotationsRequest request)
+    {
+        if (clientInfo.LoggedUser == null)
+        {
+            logger.Warning("ClientInfo has null LoggerUser in [Authorized] controller /documents");
+            return Problem();
+        }
+
+        try
+        {
+            documentService.SetRequiredAnnotationsForDocuments(request);
+        }
+        catch (InvalidOperationException e)
+        {
+            throw new BadRequestException(e.Message);
+        }
+        catch (Exception e)
+        {
+            throw new InternalErrorException(e.Message);
+        }
+
+        return Ok();
+    }
 }
 
diff --git a/Backend/Core/Services/DocumentService/DocumentServiceEF.cs b/Backend/Core/Services/DocumentService/DocumentServiceEF.cs
index 893ced4..811f3ea 100644
--- a/Backend/Core/Services/DocumentService/DocumentServiceEF.cs
+++ b/Backend/Core/Services/DocumentService/DocumentServiceEF.cs
@@ -12,6 +12,7 @@ using System.Web;
 using AutoMapper;
 using Models.Users;
 using Ganss.XSS;
+using Core.StaticConfig;
 
 namespace Core.Services.DocumentService
 {
@@ -105,27 +106,12 @@ namespace Core.Services.DocumentService
                 UserAdded = userAdded,
                 Name = documentName,
                 Length = documentContent.Content.Length,
-                RequiredAnnotations = 3                     // TODO this is only for testing purposes
+                RequiredAnnotations = GlobalConfiguration.RequiredAnnotations
             };
 
-            /*foreach (var user in users)
-            {
-                Annotation annotation = new Annotation()
-                {
-                    User = user,
-                    UserAssigned = userAdded,
-                    State = Models.Enums.EState.NEW,
-                    DateAssigned = DateTime.Now,
-                    DateLastChanged = DateTime.Now,
-                    Document = document,
-                    Note = ""
-                };
-                databaseContext.Annotations.Add(annotation);
-            }*/
-
             databaseContext.DocumentContents.Add(documentContent);
             databaseContext.Documents.Add(document);
-            databaseContext.SaveChanges();                  // Maybe do this after all the documents are added
+            databaseContext.SaveChanges();
         }
 
         public DocumentListResponse GetDocuments(int pageIndex, int pageSize)
@@ -169,5 +155,14 @@ namespace Core.Services.DocumentService
             };
         }
 
+        public void SetRequiredAnnotationsForDocuments(SetRequiredAnnotationsRequest request)
+        {
+            var documents = databaseContext.Documents.Where(d => request.DocumentIds.Contains(d.Id));
+            foreach (var doc in documents)
+            {
+                doc.RequiredAnnotations = request.RequiredAnnotations;
+            }
+            databaseContext.SaveChanges();
+        }
     }
 }
diff --git a/Backend/Core/Services/DocumentService/IDocumentService.cs b/Backend/Core/Services/DocumentService/IDocumentService.cs
index ed2943b..016349e 100644
--- a/Backend/Core/Services/DocumentService/IDocumentService.cs
+++ b/Backend/Core/Services/DocumentService/IDocumentService.cs
@@ -14,5 +14,7 @@ namespace Core.Services.DocumentService
         public void AddDocuments(DocumentAddRequest request, Guid userId);
 
         public DocumentListResponse GetDocuments(int pageIdnex, int pageSize);
+
+        public void SetRequiredAnnotationsForDocuments(SetRequiredAnnotationsRequest request);
     }
 }
diff --git a/Backend/Core/StaticConfig/GlobalConfiguration.cs b/Backend/Core/StaticConfig/GlobalConfiguration.cs
new file mode 100644
index 0000000..1048034
--- /dev/null
+++ b/Backend/Core/StaticConfig/GlobalConfiguration.cs
@@ -0,0 +1,25 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Core.StaticConfig
+{
+    public class GlobalConfiguration
+    {
+        // Default count of required annotations
+        private static Mutex RequiredAnnotationsMutex = new Mutex();
+        private static int requiredAnnotations = 3;
+        public static int RequiredAnnotations
+        {
+            get { return requiredAnnotations; }
+            set
+            {
+                RequiredAnnotationsMutex.WaitOne();
+                requiredAnnotations = value;
+                RequiredAnnotationsMutex.ReleaseMutex();
+            }
+        }     
+    }
+}
diff --git a/Backend/Models/Documents/DocumentAddInfo.cs b/Backend/Models/Documents/DocumentAddInfo.cs
index 771b59b..7df8a76 100644
--- a/Backend/Models/Documents/DocumentAddInfo.cs
+++ b/Backend/Models/Documents/DocumentAddInfo.cs
@@ -15,6 +15,6 @@ namespace Models.Documents;
 public class DocumentAddInfo
 {
     public string Name { get; set; }
-    public EAddDocumentFormat Format { get; set; }
+    public EAddDocumentFormat Format { get; set; } = EAddDocumentFormat.TEXTFILE;
     public string Content { get; set; }
 }
diff --git a/Backend/Models/Documents/SetRequiredAnnotationsRequest.cs b/Backend/Models/Documents/SetRequiredAnnotationsRequest.cs
new file mode 100644
index 0000000..a9a1f85
--- /dev/null
+++ b/Backend/Models/Documents/SetRequiredAnnotationsRequest.cs
@@ -0,0 +1,14 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Models.Documents
+{
+    public class SetRequiredAnnotationsRequest
+    {
+        public int RequiredAnnotations { get; set; }
+        public List<Guid> DocumentIds { get; set; } = new();
+    }
+}
