Revize 5adba4c4
Přidáno uživatelem Vojtěch Bartička před téměř 3 roky(ů)
Backend/Backend/Controllers/DocumentController.cs | ||
---|---|---|
69 | 69 |
return Ok(); |
70 | 70 |
} |
71 | 71 |
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
[HttpPost("/documents/requiredAnnotations")] |
|
76 |
[Authorize(Models.Enums.ERole.ADMINISTRATOR)] |
|
77 |
[ProducesResponseType((int)HttpStatusCode.OK)] |
|
78 |
[ProducesResponseType((int)HttpStatusCode.Forbidden)] |
|
79 |
public ActionResult SetRequiredAnnotationsForDocuments([FromServices] ClientInfo clientInfo, [FromBody] SetRequiredAnnotationsRequest request) |
|
80 |
{ |
|
81 |
if (clientInfo.LoggedUser == null) |
|
82 |
{ |
|
83 |
logger.Warning("ClientInfo has null LoggerUser in [Authorized] controller /documents"); |
|
84 |
return Problem(); |
|
85 |
} |
|
86 |
|
|
87 |
try |
|
88 |
{ |
|
89 |
documentService.SetRequiredAnnotationsForDocuments(request); |
|
90 |
} |
|
91 |
catch (InvalidOperationException e) |
|
92 |
{ |
|
93 |
throw new BadRequestException(e.Message); |
|
94 |
} |
|
95 |
catch (Exception e) |
|
96 |
{ |
|
97 |
throw new InternalErrorException(e.Message); |
|
98 |
} |
|
99 |
|
|
100 |
return Ok(); |
|
101 |
} |
|
72 | 102 |
} |
73 | 103 |
|
Backend/Core/Services/DocumentService/DocumentServiceEF.cs | ||
---|---|---|
12 | 12 |
using AutoMapper; |
13 | 13 |
using Models.Users; |
14 | 14 |
using Ganss.XSS; |
15 |
using Core.StaticConfig; |
|
15 | 16 |
|
16 | 17 |
namespace Core.Services.DocumentService |
17 | 18 |
{ |
... | ... | |
105 | 106 |
UserAdded = userAdded, |
106 | 107 |
Name = documentName, |
107 | 108 |
Length = documentContent.Content.Length, |
108 |
RequiredAnnotations = 3 // TODO this is only for testing purposes
|
|
109 |
RequiredAnnotations = GlobalConfiguration.RequiredAnnotations
|
|
109 | 110 |
}; |
110 | 111 |
|
111 |
/*foreach (var user in users) |
|
112 |
{ |
|
113 |
Annotation annotation = new Annotation() |
|
114 |
{ |
|
115 |
User = user, |
|
116 |
UserAssigned = userAdded, |
|
117 |
State = Models.Enums.EState.NEW, |
|
118 |
DateAssigned = DateTime.Now, |
|
119 |
DateLastChanged = DateTime.Now, |
|
120 |
Document = document, |
|
121 |
Note = "" |
|
122 |
}; |
|
123 |
databaseContext.Annotations.Add(annotation); |
|
124 |
}*/ |
|
125 |
|
|
126 | 112 |
databaseContext.DocumentContents.Add(documentContent); |
127 | 113 |
databaseContext.Documents.Add(document); |
128 |
databaseContext.SaveChanges(); // Maybe do this after all the documents are added
|
|
114 |
databaseContext.SaveChanges(); |
|
129 | 115 |
} |
130 | 116 |
|
131 | 117 |
public DocumentListResponse GetDocuments(int pageIndex, int pageSize) |
... | ... | |
169 | 155 |
}; |
170 | 156 |
} |
171 | 157 |
|
158 |
public void SetRequiredAnnotationsForDocuments(SetRequiredAnnotationsRequest request) |
|
159 |
{ |
|
160 |
var documents = databaseContext.Documents.Where(d => request.DocumentIds.Contains(d.Id)); |
|
161 |
foreach (var doc in documents) |
|
162 |
{ |
|
163 |
doc.RequiredAnnotations = request.RequiredAnnotations; |
|
164 |
} |
|
165 |
databaseContext.SaveChanges(); |
|
166 |
} |
|
172 | 167 |
} |
173 | 168 |
} |
Backend/Core/Services/DocumentService/IDocumentService.cs | ||
---|---|---|
14 | 14 |
public void AddDocuments(DocumentAddRequest request, Guid userId); |
15 | 15 |
|
16 | 16 |
public DocumentListResponse GetDocuments(int pageIdnex, int pageSize); |
17 |
|
|
18 |
public void SetRequiredAnnotationsForDocuments(SetRequiredAnnotationsRequest request); |
|
17 | 19 |
} |
18 | 20 |
} |
Backend/Core/StaticConfig/GlobalConfiguration.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
|
|
7 |
namespace Core.StaticConfig |
|
8 |
{ |
|
9 |
public class GlobalConfiguration |
|
10 |
{ |
|
11 |
// Default count of required annotations |
|
12 |
private static Mutex RequiredAnnotationsMutex = new Mutex(); |
|
13 |
private static int requiredAnnotations = 3; |
|
14 |
public static int RequiredAnnotations |
|
15 |
{ |
|
16 |
get { return requiredAnnotations; } |
|
17 |
set |
|
18 |
{ |
|
19 |
RequiredAnnotationsMutex.WaitOne(); |
|
20 |
requiredAnnotations = value; |
|
21 |
RequiredAnnotationsMutex.ReleaseMutex(); |
|
22 |
} |
|
23 |
} |
|
24 |
} |
|
25 |
} |
Backend/Models/Documents/DocumentAddInfo.cs | ||
---|---|---|
15 | 15 |
public class DocumentAddInfo |
16 | 16 |
{ |
17 | 17 |
public string Name { get; set; } |
18 |
public EAddDocumentFormat Format { get; set; } |
|
18 |
public EAddDocumentFormat Format { get; set; } = EAddDocumentFormat.TEXTFILE;
|
|
19 | 19 |
public string Content { get; set; } |
20 | 20 |
} |
Backend/Models/Documents/SetRequiredAnnotationsRequest.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
|
|
7 |
namespace Models.Documents |
|
8 |
{ |
|
9 |
public class SetRequiredAnnotationsRequest |
|
10 |
{ |
|
11 |
public int RequiredAnnotations { get; set; } |
|
12 |
public List<Guid> DocumentIds { get; set; } = new(); |
|
13 |
} |
|
14 |
} |
Také k dispozici: Unified diff
Implemented static global config, added endpoint to set req annotations per document