Просмотр исходного кода

Add minBatchId parameter to /api/batches/ and deprecate lastBatchId.
Add maxRemoteId parameter to /api/vendorevents/.

Andrew Klopper лет назад: 8
Родитель
Сommit
05697292c0

+ 8 - 2
BulkPrintingAPI/Controllers/BatchesController.cs

@@ -61,12 +61,18 @@ namespace BulkPrintingAPI.Controllers
61 61
 
62 62
         [HttpGet]
63 63
         public async Task<Page<Batch>> GetBatchesAsync([FromQuery] int page = 1,
64
-            [FromQuery] int pageSize = 100, [FromQuery] int? lastBatchId = null)
64
+            [FromQuery] int pageSize = 100, [FromQuery] int? lastBatchId = null, int? minBatchId = null)
65 65
         {
66 66
             var credentials = await Utils.GetLoginCredentialsFromRequestAsync(HttpContext, _context);
67 67
             var query = BatchesForVendor(credentials.Vendor.Id);
68
-            if (lastBatchId.HasValue)
68
+            if (minBatchId.HasValue)
69 69
             {
70
+                query = query.Where(b => b.Id >= minBatchId.Value).OrderBy(b => b.Id);
71
+            }
72
+            else if (lastBatchId.HasValue)
73
+            {
74
+                // Deprecated in favour of minBatchId for clarity. Use minBatchId = lastBatchId + 1 for equivalent
75
+                // functionality
70 76
                 query = query.Where(b => b.Id > lastBatchId.Value).OrderBy(b => b.Id);
71 77
             }
72 78
             else

+ 13 - 4
BulkPrintingAPI/Controllers/VendorEventsController.cs

@@ -44,12 +44,21 @@ namespace BulkPrintingAPI.Controllers
44 44
 
45 45
         [HttpGet]
46 46
         public async Task<Page<VendorEvent>> GetVendorEventsAsync([FromQuery] int page = 1,
47
-            [FromQuery] int pageSize = 100)
47
+            [FromQuery] int pageSize = 100, [FromQuery] int? maxRemoteId = null)
48 48
         {
49 49
             var credentials = await Utils.GetLoginCredentialsFromRequestAsync(HttpContext, _context);
50
-            return await Page<VendorEvent>.GetPageAsync(
51
-                VendorEventsForVendor(credentials.Vendor.Id).OrderByDescending(e => e.EventDate),
52
-                page, pageSize);
50
+            var query = VendorEventsForVendor(credentials.Vendor.Id);
51
+            if (maxRemoteId.HasValue)
52
+            {
53
+                query = query.Where(e => e.RemoteId <= maxRemoteId)
54
+                    .OrderByDescending(e => e.VendorId)
55
+                    .ThenByDescending(e => e.RemoteId);
56
+            }
57
+            else
58
+            {
59
+                query = query.OrderByDescending(e => e.Id);
60
+            }
61
+            return await Page<VendorEvent>.GetPageAsync(query, page, pageSize);
53 62
         }
54 63
 
55 64
         [HttpPost]