Revize 42c654f6
Přidáno uživatelem Vojtěch Bartička před téměř 3 roky(ů)
Backend/Backend/Controllers/DocumentController.cs | ||
---|---|---|
28 | 28 |
[Authorize(Models.Enums.ERole.ADMINISTRATOR)] |
29 | 29 |
[ProducesResponseType((int)HttpStatusCode.OK)] |
30 | 30 |
[ProducesResponseType((int)HttpStatusCode.Forbidden)] |
31 |
public ActionResult<DocumentListResponse> GetDocuments([FromServices] ClientInfo clientInfo, [FromBody] DocumentListRequest documentListRequest)
|
|
31 |
public ActionResult<DocumentListResponse> GetDocuments([FromServices] ClientInfo clientInfo, [FromQuery] int pageIndex, [FromQuery] int pageSize)
|
|
32 | 32 |
{ |
33 | 33 |
if (clientInfo.LoggedUser == null) |
34 | 34 |
{ |
... | ... | |
36 | 36 |
return Problem(); |
37 | 37 |
} |
38 | 38 |
|
39 |
return documentService.GetDocuments(documentListRequest);
|
|
39 |
return documentService.GetDocuments(pageIndex, pageSize);
|
|
40 | 40 |
} |
41 | 41 |
|
42 | 42 |
[HttpPost("/documents")] |
Backend/Core/Services/DocumentService/DocumentServiceEF.cs | ||
---|---|---|
110 | 110 |
databaseContext.SaveChanges(); // Maybe do this after all the documents are added |
111 | 111 |
} |
112 | 112 |
|
113 |
public DocumentListResponse GetDocuments(DocumentListRequest request)
|
|
113 |
public DocumentListResponse GetDocuments(int pageIndex, int pageSize)
|
|
114 | 114 |
{ |
115 |
var firstIndex = request.PageIndex * request.PageSize;
|
|
115 |
var firstIndex = pageIndex * pageSize;
|
|
116 | 116 |
var documents = databaseContext.Documents.Select(d => d).ToList(); |
117 | 117 |
var totalCount = documents.Count; |
118 |
var pageCount = totalCount / request.PageSize;
|
|
118 |
var pageCount = totalCount / pageSize;
|
|
119 | 119 |
if (pageCount == 0 && totalCount > 0) |
120 | 120 |
{ |
121 | 121 |
pageCount = 1; |
... | ... | |
126 | 126 |
throw new Exception("Page index or page size too large"); |
127 | 127 |
} |
128 | 128 |
|
129 |
if (firstIndex + request.PageSize > documents.Count - 1)
|
|
129 |
if (firstIndex + pageSize > documents.Count - 1)
|
|
130 | 130 |
{ |
131 |
request.PageSize = documents.Count - firstIndex;
|
|
131 |
pageSize = documents.Count - firstIndex;
|
|
132 | 132 |
} |
133 | 133 |
|
134 | 134 |
List<DocumentListInfo> documentInfos = new List<DocumentListInfo>(); |
135 |
foreach (var document in documents.GetRange(firstIndex, request.PageSize))
|
|
135 |
foreach (var document in documents.GetRange(firstIndex, pageSize))
|
|
136 | 136 |
{ |
137 | 137 |
var annotatingUsers = databaseContext.Annotations.Where(a => a.Document == document).Select(a => a.User).ToList(); |
138 | 138 |
List<UserInfo> annotatingUsersDto = annotatingUsers.Select(a => mapper.Map<UserInfo>(a)).ToList(); |
... | ... | |
145 | 145 |
return new DocumentListResponse() |
146 | 146 |
{ |
147 | 147 |
PageCount = pageCount, |
148 |
PageIndex = request.PageIndex,
|
|
148 |
PageIndex = pageIndex,
|
|
149 | 149 |
TotalCount = totalCount, |
150 | 150 |
Documents = documentInfos |
151 | 151 |
}; |
Backend/Core/Services/DocumentService/IDocumentService.cs | ||
---|---|---|
13 | 13 |
{ |
14 | 14 |
public void AddDocuments(DocumentAddRequest request, Guid userId); |
15 | 15 |
|
16 |
public DocumentListResponse GetDocuments(DocumentListRequest request);
|
|
16 |
public DocumentListResponse GetDocuments(int pageIdnex, int pageSize);
|
|
17 | 17 |
} |
18 | 18 |
} |
Také k dispozici: Unified diff
Same fix in DocumentController - moved to QueryParams