Skip to content

Commit 10f3e17

Browse files
author
Carlos Cañizares Estévez
committed
Add Swagger to Basket Api
SQL databases with the same prefix for services Move application tier to api tier in ordering api
1 parent 31753fc commit 10f3e17

26 files changed

Lines changed: 429 additions & 83 deletions

File tree

docker-compose.override.yml

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,22 @@ version: '2'
99

1010
services:
1111

12-
# webmvc:
13-
# environment:
14-
# - CatalogUrl=http://catalog.api
15-
# - OrderingUrl=http://ordering.api:5102
16-
#- IdentityUrl=http://104.40.62.65:5105 #Remote: VM Needs to have public access at 5105.
17-
# - IdentityUrl=http://identity.service:5105 #Local: You need a entry in windows host file to run identity in local docker.
18-
# - BasketUrl=http://basket.api:5103
19-
# ports:
20-
# - "5100:5100"
12+
webmvc:
13+
environment:
14+
- CatalogUrl=http://catalog.api
15+
- OrderingUrl=http://ordering.api:5102
16+
#- IdentityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105.
17+
#- IdentityUrl=http://10.0.75.1:5105 #Local: You need to open windows firewall at range 5100-5105.
18+
- IdentityUrl=http://identity.service:5105 #Local: You need a entry in windows host file to run identity in local docker.
19+
- BasketUrl=http://basket.api:5103
20+
ports:
21+
- "5100:5100"
2122

2223
webspa:
2324
environment:
2425
- CatalogUrl=http://catalog.api
2526
- OrderingUrl=http://ordering.api
26-
#- IdentityUrl=http://104.40.62.65:5105 #Remote: VM Needs to have public access at 5105.
27+
#- IdentityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105.
2728
- IdentityUrl=http://identity.service:5105 #Local: You need a entry in windows host file to run identity in local docker.
2829
- BasketUrl=http://basket.api:5103
2930
ports:
@@ -32,30 +33,30 @@ services:
3233
basket.api:
3334
environment:
3435
- ConnectionString=basket.data
35-
#- identityUrl=http://104.40.62.65:5105 #Remote: VM Needs to have public access at 5105.
36+
#- identityUrl=http://13.88.8.119:5105 #Remote
3637
- identityUrl=http://identity.service:5105 #Local: You need a entry in windows host file to run identity in local docker.
3738
ports:
3839
- "5103:5103"
3940

4041
catalog.api:
4142
environment:
42-
- ConnectionString=Server=sql.data;Database=CatalogDB;User Id=sa;Password=Pass@word
43+
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word
4344
ports:
4445
- "5101:80"
4546

46-
# ordering.api:
47-
# environment:
48-
# - ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word
49-
# - identityUrl=http://identity.service:5105 #local
50-
#- identityUrl=http://104.40.62.65:5105 #remote
51-
# ports:
52-
# - "5102:5102"
47+
ordering.api:
48+
environment:
49+
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word
50+
- identityUrl=http://identity.service:5105 #local
51+
#- identityUrl=http://13.88.8.119:5105 #remote
52+
ports:
53+
- "5102:5102"
5354

5455
identity.service:
5556
environment:
5657
- SpaClient=http://localhost:5104
57-
- ConnectionStrings__DefaultConnection=Server=sql.data;Database=aspnet-Microsoft.eShopOnContainers;User Id=sa;Password=Pass@word
58-
#- MvcClient=http://104.40.62.65:5100 #Remote: VM Needs to have public access at 5105.
58+
- ConnectionStrings__DefaultConnection=Server=sql.data;Database=Microsoft.eShopOnContainers.Service.IdentityDb;User Id=sa;Password=Pass@word
59+
#- MvcClient=http://13.88.8.119:5100 #Remote: VM Needs to have public access at 5105.
5960
- MvcClient=http://localhost:5100 #Local: You need a entry in windows host file to run identity in local docker.
6061
#10.0.75.1:5105 CCE/TODO: try to avoid host entry.
6162
ports:

docker-compose.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
version: '2'
88

99
services:
10-
# webmvc:
11-
# image: eshop/web
12-
# depends_on:
13-
# - identity.service
14-
# - basket.api
10+
webmvc:
11+
image: eshop/web
12+
links:
13+
- identity.service:localhost
14+
depends_on:
15+
- identity.service
16+
- basket.api
1517

1618
webspa:
1719
image: eshop/webspa
@@ -30,10 +32,10 @@ services:
3032
depends_on:
3133
- sql.data
3234

33-
# ordering.api:
34-
# image: eshop/ordering.api
35-
# depends_on:
36-
# - sql.data
35+
ordering.api:
36+
image: eshop/ordering.api
37+
depends_on:
38+
- sql.data
3739

3840
identity.service:
3941
image: eshop/identity
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
7+
// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
8+
9+
namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
10+
{
11+
public class HomeController : Controller
12+
{
13+
// GET: /<controller>/
14+
public IActionResult Index()
15+
{
16+
return new RedirectResult("~/swagger/ui");
17+
}
18+
}
19+
}

src/Services/Basket/Basket.API/Startup.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ public void ConfigureServices(IServiceCollection services)
4747
return ConnectionMultiplexer.Connect(ips.First().ToString());
4848
});
4949

50+
services.AddSwaggerGen();
51+
services.ConfigureSwaggerGen(options =>
52+
{
53+
options.DescribeAllEnumsAsStrings();
54+
options.SingleApiVersion(new Swashbuckle.Swagger.Model.Info()
55+
{
56+
Title = "Basket HTTP API",
57+
Version = "v1",
58+
Description = "The Basket Service HTTP API",
59+
TermsOfService = "Terms Of Service"
60+
});
61+
});
62+
63+
5064
services.AddCors(options =>
5165
{
5266
options.AddPolicy("CorsPolicy",
@@ -77,7 +91,11 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
7791
RequireHttpsMetadata = false
7892
});
7993

80-
app.UseMvc();
94+
app.UseMvcWithDefaultRoute();
95+
96+
app.UseSwagger()
97+
.UseSwaggerUi();
98+
8199
}
82100
}
83101
}

src/Services/Basket/Basket.API/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
1818
"StackExchange.Redis": "1.1.608",
1919
"Newtonsoft.Json": "9.0.1",
20-
"IdentityServer4.AccessTokenValidation": "1.0.1-rc3"
20+
"IdentityServer4.AccessTokenValidation": "1.0.1-rc3",
21+
"Swashbuckle": "6.0.0-beta902"
2122
},
2223
"tools": {
2324
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"

src/Services/Catalog/Catalog.API/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"ConnectionString": "Server=tcp:127.0.0.1,5433;Initial Catalog=CatalogDB;User Id=sa;Password=Pass@word",
2+
"ConnectionString": "Server=tcp:127.0.0.1,5433;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word",
33
"Logging": {
44
"IncludeScopes": false,
55
"LogLevel": {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace eShopOnContainers.Identity
7+
{
8+
public class AppSettings
9+
{
10+
public string MvcClient { get; set; }
11+
}
12+
}

src/Services/Identity/eShopOnContainers.Identity/Configuration/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static IEnumerable<Client> GetClients(Dictionary<string,string> clientsUr
7878
new Secret("secret".Sha256())
7979
},
8080
ClientUri = $"{clientsUrl["Mvc"]}", // public uri of the client
81-
AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
81+
AllowedGrantTypes = GrantTypes.Hybrid,
8282
RedirectUris = new List<string>
8383
{
8484
$"{clientsUrl["Mvc"]}/signin-oidc",

src/Services/Identity/eShopOnContainers.Identity/Controllers/AccountController.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,9 @@ public async Task<IActionResult> Login(LoginViewModel model)
8585
if (ModelState.IsValid)
8686
{
8787
var user = await _loginService.FindByUsername(model.Email);
88-
// validate username/password against in-memory store
8988
if (await _loginService.ValidateCredentials(user, model.Password))
9089
{
91-
// issue authentication cookie with subject ID and username
92-
//var user = _loginService.FindByUsername(model.Username);
93-
94-
AuthenticationProperties props = null;
95-
// only set explicit expiration here if persistent.
96-
// otherwise we reply upon expiration configured in cookie middleware.
90+
AuthenticationProperties props = null;
9791
if (model.RememberMe)
9892
{
9993
props = new AuthenticationProperties
@@ -217,15 +211,7 @@ public async Task<IActionResult> Logout(LogoutViewModel model)
217211

218212
// get context information (client name, post logout redirect URI and iframe for federated signout)
219213
var logout = await _interaction.GetLogoutContextAsync(model.LogoutId);
220-
221-
var vm = new LoggedOutViewModel
222-
{
223-
PostLogoutRedirectUri = logout?.PostLogoutRedirectUri,
224-
ClientName = logout?.ClientId,
225-
SignOutIframeUrl = logout?.SignOutIFrameUrl
226-
};
227-
228-
return View("LoggedOut", vm);
214+
return Redirect(logout?.PostLogoutRedirectUri);
229215
}
230216

231217
/// <summary>

src/Services/Identity/eShopOnContainers.Identity/Controllers/HomeController.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,31 @@
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33

44

5+
using eShopOnContainers.Identity;
56
using IdentityServer4.Quickstart.UI.Models;
67
using IdentityServer4.Services;
78
using Microsoft.AspNetCore.Mvc;
9+
using Microsoft.Extensions.Options;
810
using System.Threading.Tasks;
911

1012
namespace IdentityServer4.Quickstart.UI.Controllers
1113
{
1214
public class HomeController : Controller
1315
{
1416
private readonly IIdentityServerInteractionService _interaction;
17+
private readonly IOptions<AppSettings> _settings;
1518

16-
public HomeController(IIdentityServerInteractionService interaction)
19+
public HomeController(IIdentityServerInteractionService interaction, IOptions<AppSettings> settings)
1720
{
1821
_interaction = interaction;
22+
_settings = settings;
1923
}
2024

21-
public IActionResult Index()
25+
public IActionResult Index(string returnUrl)
2226
{
27+
if (returnUrl != "")
28+
return Redirect(_settings.Value.MvcClient);
29+
2330
return View();
2431
}
2532

0 commit comments

Comments
 (0)