Revize 42c654f6
Přidáno uživatelem Vojtěch Bartička před asi 2 roky(ů)
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 |
}; |
Také k dispozici: Unified diff
Same fix in DocumentController - moved to QueryParams