This repository was archived by the owner on Nov 17, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 11 files changed +53
-72
lines changed
ApiGateways/Web.Bff.Shopping/aggregator Expand file tree Collapse file tree 11 files changed +53
-72
lines changed Original file line number Diff line number Diff line change 32
32
app . UseAuthentication ( ) ;
33
33
app . UseAuthorization ( ) ;
34
34
35
- app . MapGet ( "/" , ( ) => Results . Redirect ( "/swagger" ) ) ;
36
-
37
35
app . MapControllers ( ) ;
38
36
app . MapReverseProxy ( ) ;
39
37
Original file line number Diff line number Diff line change 49
49
<PackageVersion Include =" Microsoft.AspNetCore.Identity.UI" Version =" 7.0.3" />
50
50
<PackageVersion Include =" Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version =" 7.0.3" />
51
51
<PackageVersion Include =" Microsoft.AspNetCore.Mvc.Testing" Version =" 7.0.3" />
52
+ <PackageVersion Include =" Microsoft.AspNetCore.OpenApi" Version =" 7.0.5" />
52
53
<PackageVersion Include =" Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version =" 7.0.3" />
53
54
<PackageVersion Include =" Microsoft.AspNetCore.SpaServices.Extensions" Version =" 7.0.3" />
54
55
<PackageVersion Include =" Microsoft.AspNetCore.TestHost" Version =" 7.0.3" />
Original file line number Diff line number Diff line change 19
19
20
20
app . UseServiceDefaults ( ) ;
21
21
22
- app . MapGet ( "/" , ( ) => Results . Redirect ( "/swagger" ) ) ;
23
-
24
22
app . MapGrpcService < BasketService > ( ) ;
25
23
app . MapControllers ( ) ;
26
24
Original file line number Diff line number Diff line change
1
+ using Microsoft . AspNetCore . Routing ;
2
+
3
+ namespace Catalog . API . Apis ;
4
+
5
+ public static class PicApi
6
+ {
7
+ public static IEndpointConventionBuilder MapPicApi ( this IEndpointRouteBuilder routes )
8
+ {
9
+ return routes . MapGet ( "api/v1/catalog/items/{catalogItemId:int}/pic" ,
10
+ async ( int catalogItemId , CatalogContext db , IWebHostEnvironment environment ) =>
11
+ {
12
+ var item = await db . CatalogItems . FindAsync ( catalogItemId ) ;
13
+
14
+ if ( item is null )
15
+ {
16
+ return Results . NotFound ( ) ;
17
+ }
18
+
19
+ var path = Path . Combine ( environment . ContentRootPath , "Pics" , item . PictureFileName ) ;
20
+
21
+ string imageFileExtension = Path . GetExtension ( item . PictureFileName ) ;
22
+ string mimetype = GetImageMimeTypeFromImageFileExtension ( imageFileExtension ) ;
23
+
24
+ return Results . File ( path , mimetype ) ;
25
+ } )
26
+ . WithTags ( "Pic" )
27
+ . Produces ( 404 ) ;
28
+
29
+ static string GetImageMimeTypeFromImageFileExtension ( string extension ) => extension switch
30
+ {
31
+ ".png" => "image/png" ,
32
+ ".gif" => "image/gif" ,
33
+ ".jpg" or ".jpeg" => "image/jpeg" ,
34
+ ".bmp" => "image/bmp" ,
35
+ ".tiff" => "image/tiff" ,
36
+ ".wmf" => "image/wmf" ,
37
+ ".jp2" => "image/jp2" ,
38
+ ".svg" => "image/svg+xml" ,
39
+ _ => "application/octet-stream" ,
40
+ } ;
41
+ }
42
+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 35
35
global using Microsoft . eShopOnContainers . Services . Catalog . API . ViewModel ;
36
36
global using Microsoft . Extensions . Configuration ;
37
37
global using Microsoft . Extensions . DependencyInjection ;
38
- global using Microsoft . Extensions . FileProviders ;
39
38
global using Microsoft . Extensions . Logging ;
40
39
global using Microsoft . Extensions . Options ;
41
40
global using Polly ;
42
41
global using Polly . Retry ;
43
42
global using Services . Common ;
43
+ global using Catalog . API . Apis ;
Original file line number Diff line number Diff line change 18
18
19
19
app . UseServiceDefaults ( ) ;
20
20
21
- app . MapGet ( "/" , ( ) => Results . Redirect ( "/swagger" ) ) ;
22
-
21
+ app . MapPicApi ( ) ;
23
22
app . MapControllers ( ) ;
24
23
app . MapGrpcService < CatalogService > ( ) ;
25
24
Original file line number Diff line number Diff line change 44
44
45
45
app . UseServiceDefaults ( ) ;
46
46
47
- app . MapGet ( "/" , ( ) => Results . Redirect ( "/swagger" ) ) ;
48
-
49
47
app . MapGrpcService < OrderingService > ( ) ;
50
48
app . MapControllers ( ) ;
51
49
Original file line number Diff line number Diff line change 4
4
using Microsoft . AspNetCore . Builder ;
5
5
using Microsoft . AspNetCore . Diagnostics . HealthChecks ;
6
6
using Microsoft . AspNetCore . Hosting ;
7
+ using Microsoft . AspNetCore . Http ;
7
8
using Microsoft . AspNetCore . Routing ;
8
9
using Microsoft . eShopOnContainers . BuildingBlocks . EventBus ;
9
10
using Microsoft . eShopOnContainers . BuildingBlocks . EventBus . Abstractions ;
@@ -100,7 +101,7 @@ public static async Task<bool> CheckHealthAsync(this WebApplication app)
100
101
return true ;
101
102
}
102
103
103
- public static IApplicationBuilder UseDefaultOpenApi ( this IApplicationBuilder app , IConfiguration configuration )
104
+ public static IApplicationBuilder UseDefaultOpenApi ( this WebApplication app , IConfiguration configuration )
104
105
{
105
106
var openApiSection = configuration . GetSection ( "OpenApi" ) ;
106
107
@@ -139,6 +140,9 @@ public static IApplicationBuilder UseDefaultOpenApi(this IApplicationBuilder app
139
140
}
140
141
} ) ;
141
142
143
+ // Add a redirect from the root of the app to the swagger endpoint
144
+ app . MapGet ( "/" , ( ) => Results . Redirect ( "/swagger" ) ) . ExcludeFromDescription ( ) ;
145
+
142
146
return app ;
143
147
}
144
148
@@ -151,6 +155,8 @@ public static IServiceCollection AddDefaultOpenApi(this IServiceCollection servi
151
155
return services ;
152
156
}
153
157
158
+ services . AddEndpointsApiExplorer ( ) ;
159
+
154
160
return services . AddSwaggerGen ( options =>
155
161
{
156
162
/// {
Original file line number Diff line number Diff line change 29
29
<PackageReference Include =" Microsoft.AspNetCore.HealthChecks" />
30
30
<PackageReference Include =" Microsoft.AspNetCore.Identity.EntityFrameworkCore" />
31
31
<PackageReference Include =" Microsoft.AspNetCore.Identity.UI" />
32
+ <PackageReference Include =" Microsoft.AspNetCore.OpenApi" />
32
33
<PackageReference Include =" Microsoft.EntityFrameworkCore.Design" >
33
34
<PrivateAssets >all</PrivateAssets >
34
35
<IncludeAssets >runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets >
You can’t perform that action at this time.
0 commit comments