Revize c8159dc5
Přidáno uživatelem Vojtěch Bartička před téměř 3 roky(ů)
Backend/Backend/Controllers/DocumentController.cs | ||
---|---|---|
182 | 182 |
} |
183 | 183 |
} |
184 | 184 |
|
185 |
[HttpDelete("/documents")] |
|
186 |
[Authorize(Models.Enums.ERole.ADMINISTRATOR)] |
|
187 |
[ProducesResponseType((int)HttpStatusCode.OK)] |
|
188 |
[ProducesResponseType((int)HttpStatusCode.Forbidden)] |
|
189 |
public ActionResult DeleteDocument([FromServices] ClientInfo clientInfo, [FromBody] DeleteDocumentsRequest request) |
|
190 |
{ |
|
191 |
if (clientInfo.LoggedUser == null) |
|
192 |
{ |
|
193 |
logger.Warning("ClientInfo has null LoggerUser in [Authorized] controller /documents"); |
|
194 |
return Problem(); |
|
195 |
} |
|
196 |
|
|
197 |
try |
|
198 |
{ |
|
199 |
documentService.DeleteDocuments(request); |
|
200 |
return Ok(); |
|
201 |
} |
|
202 |
catch (InvalidOperationException e) |
|
203 |
{ |
|
204 |
throw new BadRequestException(e.Message); |
|
205 |
} |
|
206 |
} |
|
207 |
|
|
185 | 208 |
[HttpPost("/document/{documentId}/final")] |
186 | 209 |
[Authorize(Models.Enums.ERole.ADMINISTRATOR)] |
187 | 210 |
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(CreateFinalAnnotationResponse))] |
Backend/Core/Services/DocumentService/DocumentServiceEF.cs | ||
---|---|---|
148 | 148 |
.Include(fa => fa.Annotations) |
149 | 149 |
.ThenInclude(a => a.User) |
150 | 150 |
.Single(fa => fa.Document == document); |
151 |
|
|
151 |
|
|
152 | 152 |
dli.FinalizedAnnotationId = finalizedAnnotation.Id; |
153 | 153 |
dli.FinalizedState = finalizedAnnotation.State; |
154 | 154 |
dli.FinalAnnotations = new(); |
... | ... | |
199 | 199 |
return int.Parse(requiredAnnotationsItem.Value); |
200 | 200 |
} |
201 | 201 |
|
202 |
public void DeleteDocuments(DeleteDocumentsRequest request) |
|
203 |
{ |
|
204 |
var documentsToDelete = databaseContext.Documents. |
|
205 |
Where(d => request.DocumentIds.Contains(d.Id)).ToList(); |
|
206 |
|
|
207 |
var associatedAnnotations = databaseContext.Annotations. |
|
208 |
Where(a => documentsToDelete.Contains(a.Document)).ToList(); |
|
209 |
|
|
210 |
databaseContext.Annotations.RemoveRange(associatedAnnotations); |
|
211 |
databaseContext.Documents.RemoveRange(documentsToDelete); |
|
212 |
|
|
213 |
databaseContext.SaveChanges(); |
|
214 |
} |
|
215 |
|
|
202 | 216 |
public DocumentPreviewResponse GetDocumentPreview(Guid documentId) |
203 | 217 |
{ |
204 | 218 |
try |
Backend/Core/Services/DocumentService/IDocumentService.cs | ||
---|---|---|
12 | 12 |
public interface IDocumentService |
13 | 13 |
{ |
14 | 14 |
public void AddDocuments(DocumentAddRequest request, Guid userId); |
15 |
|
|
16 | 15 |
public DocumentListResponse GetDocuments(); |
17 |
|
|
18 | 16 |
public DocumentPreviewResponse GetDocumentPreview(Guid documentId); |
17 |
public void DeleteDocuments(DeleteDocumentsRequest request); |
|
19 | 18 |
public void SetRequiredAnnotationsForDocuments(SetRequiredAnnotationsRequest request); |
20 |
|
|
21 | 19 |
public void SetRequiredAnnotationsGlobal(int requiredAnnotations); |
22 |
|
|
23 | 20 |
public int GetRequiredAnnotationsGlobal(); |
24 | 21 |
} |
25 | 22 |
} |
Backend/Models/Documents/DeleteDocumentsRequest.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 DeleteDocumentsRequest |
|
10 |
{ |
|
11 |
public List<Guid> DocumentIds { get; set; } |
|
12 |
} |
|
13 |
} |
Také k dispozici: Unified diff
Added endpoint DELETE /documents