Browse Source

Add response compression.
Add lastBatchId parameter to /api/batches

Andrew Klopper 8 years ago
parent
commit
488efd8fbd

+ 1 - 1
BulkPrintingAPI/BulkPrintingAPI.csproj

@@ -9,10 +9,10 @@
9 9
     <Folder Include="wwwroot\" />
10 10
   </ItemGroup>
11 11
   <ItemGroup>
12
-    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
13 12
     <PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
14 13
     <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="1.1.2" />
15 14
     <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
15
+    <PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="1.0.3" />
16 16
     <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
17 17
     <PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />
18 18
     <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" />

+ 11 - 4
BulkPrintingAPI/Controllers/BatchesController.cs

@@ -61,12 +61,19 @@ 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)
64
+            [FromQuery] int pageSize = 100, [FromQuery] int? lastBatchId = null)
65 65
         {
66 66
             var credentials = await Utils.GetLoginCredentialsFromRequestAsync(HttpContext, _context);
67
-            return await Page<Batch>.GetPageAsync(
68
-                BatchesForVendor(credentials.Vendor.Id).OrderByDescending(b => b.OrderDate),
69
-                page, pageSize);
67
+            var query = BatchesForVendor(credentials.Vendor.Id);
68
+            if (lastBatchId.HasValue)
69
+            {
70
+                query = query.Where(b => b.Id > lastBatchId.Value).OrderBy(b => b.Id);
71
+            }
72
+            else
73
+            {
74
+                query = query.OrderByDescending(b => b.Id);
75
+            }
76
+            return await Page<Batch>.GetPageAsync(query, page, pageSize);
70 77
         }
71 78
 
72 79
         [HttpGet("{id}")]

+ 0 - 1
BulkPrintingAPI/Program.cs

@@ -13,7 +13,6 @@ namespace BulkPrintingAPI
13 13
                 .UseContentRoot(Directory.GetCurrentDirectory())
14 14
                 .UseIISIntegration()
15 15
                 .UseStartup<Startup>()
16
-                .UseApplicationInsights()
17 16
                 .Build();
18 17
 
19 18
             host.Run();

+ 12 - 0
BulkPrintingAPI/Startup.cs

@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Authorization;
4 4
 using Microsoft.AspNetCore.Builder;
5 5
 using Microsoft.AspNetCore.Hosting;
6 6
 using Microsoft.AspNetCore.Mvc.Authorization;
7
+using Microsoft.AspNetCore.ResponseCompression;
7 8
 using Microsoft.EntityFrameworkCore;
8 9
 using Microsoft.Extensions.Configuration;
9 10
 using Microsoft.Extensions.DependencyInjection;
@@ -31,6 +32,15 @@ namespace BulkPrintingAPI
31 32
 
32 33
         public void ConfigureServices(IServiceCollection services)
33 34
         {
35
+            services.Configure<GzipCompressionProviderOptions>(options =>
36
+            {
37
+                options.Level = System.IO.Compression.CompressionLevel.Optimal;
38
+            });
39
+            services.AddResponseCompression(options =>
40
+            {
41
+                options.EnableForHttps = true;
42
+                options.Providers.Add<GzipCompressionProvider>();
43
+            });
34 44
             services.AddMemoryCache();
35 45
             services.AddMvc(config =>
36 46
             {
@@ -81,6 +91,8 @@ namespace BulkPrintingAPI
81 91
                 TokenValidationParameters = tokenValidationParameters
82 92
             };
83 93
 
94
+            app.UseResponseCompression();
95
+
84 96
             app.UseMiddleware<ExceptionHandlerMiddleware>();
85 97
 
86 98
             app.UseJwtBearerAuthentication(bearerOptions);