Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 004c4a4e

Přidáno uživatelem Vojtěch Bartička před asi 2 roky(ů)

Removed paging from GET /documents

Zobrazit rozdíly:

Backend/Backend/Controllers/DocumentController.cs
30 30
    [Authorize(Models.Enums.ERole.ADMINISTRATOR)]
31 31
    [ProducesResponseType((int)HttpStatusCode.OK)]
32 32
    [ProducesResponseType((int)HttpStatusCode.Forbidden)]
33
    public ActionResult<DocumentListResponse> GetDocuments([FromServices] ClientInfo clientInfo, [FromQuery] int pageIndex, [FromQuery] int pageSize)
33
    public ActionResult<DocumentListResponse> GetDocuments([FromServices] ClientInfo clientInfo)
34 34
    {
35 35
        if (clientInfo.LoggedUser == null)
36 36
        {
......
38 38
            return Problem();
39 39
        }
40 40

  
41
        return documentService.GetDocuments(pageIndex, pageSize);
41
        return documentService.GetDocuments();
42 42
    }
43 43

  
44 44
    [HttpPost("/documents")]
Backend/BackendTesting/DocumentManagementTesting.cs
82 82
            }
83 83

  
84 84

  
85
            var documents = DS.GetDocuments(index, numberOfDocs);
85
            var documents = DS.GetDocuments(); //= DS.GetDocuments(index, numberOfDocs);
86 86
            Assert.IsNotNull(documents);
87 87
            Assert.AreEqual(documents.Documents.Count, numberOfDocs);
88 88
            for (int i = 0; i < numberOfDocs; i++)
Backend/Core/Services/DocumentService/DocumentServiceEF.cs
113 113
            databaseContext.SaveChanges();
114 114
        }
115 115

  
116
        public DocumentListResponse GetDocuments(int pageIndex, int pageSize)
116
        public DocumentListResponse GetDocuments()
117 117
        {
118
            var firstIndex = pageIndex * pageSize;
119
            var documents = databaseContext.Documents.Select(d => d).ToList();
120
            var totalCount = documents.Count;
121
            var pageCount = totalCount / pageSize;
122
            if (pageCount == 0 && totalCount > 0)
123
            {
124
                pageCount = 1;
125
            }
126

  
127
            if (firstIndex > documents.Count - 1)
128
            {
129
                throw new Exception("Page index or page size too large");
130
            }
131

  
132
            if (firstIndex + pageSize > documents.Count - 1)
133
            {
134
                pageSize = documents.Count - firstIndex;
135
            }
136

  
118
            var documents = databaseContext.Documents.ToList();
137 119
            List<DocumentListInfo> documentInfos = new List<DocumentListInfo>();
138
            foreach (var document in documents.GetRange(firstIndex, pageSize))
120
            foreach (var document in documents)
139 121
            {
140 122
                var annotatingUsers = databaseContext.Annotations
141 123
                    .Where(a => !(a is FinalAnnotation))
......
190 172

  
191 173
            return new DocumentListResponse()
192 174
            {
193
                PageCount = pageCount,
194
                PageIndex = pageIndex,
195
                TotalCount = totalCount,
196 175
                Documents = documentInfos.OrderBy(di => di.Name).ToList()
197 176
            };
198 177
        }
Backend/Core/Services/DocumentService/IDocumentService.cs
13 13
    {
14 14
        public void AddDocuments(DocumentAddRequest request, Guid userId);
15 15

  
16
        public DocumentListResponse GetDocuments(int pageIdnex, int pageSize);
16
        public DocumentListResponse GetDocuments();
17 17

  
18 18
        public DocumentPreviewResponse GetDocumentPreview(Guid documentId);
19 19
        public void SetRequiredAnnotationsForDocuments(SetRequiredAnnotationsRequest request);
Backend/Models/Documents/DocumentListResponse.cs
8 8

  
9 9
public class DocumentListResponse
10 10
{
11
    /** Total number of results */
12
    public int TotalCount { get; set; }
13
    /** Number of pages */
14
    public int PageCount { get; set; }
15
    /** Current page index */
16
    public int PageIndex { get; set; }
17

  
18 11
    public List<DocumentListInfo> Documents { get; set; } = new();
19 12
}
20 13

  

Také k dispozici: Unified diff