Revize 42bb0025
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 |
[HttpGet("/document/{documentId}")] |
|
73 |
[Authorize(Models.Enums.ERole.ADMINISTRATOR)] |
|
74 |
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(DocumentPreviewResponse))] |
|
75 |
[ProducesResponseType((int)HttpStatusCode.Forbidden)] |
|
76 |
public ActionResult GetDocumentPreview([FromServices] ClientInfo clientInfo, Guid documentId) |
|
77 |
{ |
|
78 |
if (clientInfo.LoggedUser == null) |
|
79 |
{ |
|
80 |
logger.Warning("ClientInfo has null LoggerUser in [Authorized] controller /documents"); |
|
81 |
return Problem(); |
|
82 |
} |
|
83 |
|
|
84 |
try |
|
85 |
{ |
|
86 |
return Ok(documentService.GetDocumentPreview(documentId)); |
|
87 |
} |
|
88 |
catch (InvalidOperationException e) |
|
89 |
{ |
|
90 |
throw new BadRequestException(e.Message); |
|
91 |
} |
|
92 |
} |
|
93 |
|
|
72 | 94 |
} |
73 | 95 |
|
Backend/Core/Services/DocumentService/DocumentServiceEF.cs | ||
---|---|---|
12 | 12 |
using AutoMapper; |
13 | 13 |
using Models.Users; |
14 | 14 |
using Ganss.XSS; |
15 |
using Microsoft.EntityFrameworkCore; |
|
15 | 16 |
|
16 | 17 |
namespace Core.Services.DocumentService |
17 | 18 |
{ |
... | ... | |
169 | 170 |
}; |
170 | 171 |
} |
171 | 172 |
|
173 |
public DocumentPreviewResponse GetDocumentPreview(Guid documentId) |
|
174 |
{ |
|
175 |
try |
|
176 |
{ |
|
177 |
var document = databaseContext.Documents.Include(d => d.Content).Single(d => d.Id == documentId); |
|
178 |
HtmlSanitizer sanitizer = new HtmlSanitizer(); |
|
179 |
return new DocumentPreviewResponse() |
|
180 |
{ |
|
181 |
Content = sanitizer.Sanitize(document.Content.Content) |
|
182 |
}; |
|
183 |
} |
|
184 |
catch (InvalidOperationException e) |
|
185 |
{ |
|
186 |
throw new InvalidOperationException("Document not found"); |
|
187 |
} |
|
188 |
} |
|
172 | 189 |
} |
173 | 190 |
} |
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 DocumentPreviewResponse GetDocumentPreview(Guid documentId); |
|
17 | 19 |
} |
18 | 20 |
} |
Backend/Models/Documents/DocumentPreviewResponse.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 DocumentPreviewResponse |
|
10 |
{ |
|
11 |
public string Content { get; set; } |
|
12 |
} |
|
13 |
} |
Také k dispozici: Unified diff
Added endpoint for document preview