From 2201f3642204c946b05e885fd11f11111e03806e Mon Sep 17 00:00:00 2001 From: hello Date: Thu, 29 Aug 2024 23:07:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=BE=AE=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=AE=9E=E4=BD=93=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/HelloShop.AppHost/Program.cs | 2 +- .../Authentication/CustomJwtBearerDefaults.cs | 2 +- .../CustomJwtBearerExtensions.cs | 2 +- .../Authentication/CustomJwtBearerHandler.cs | 2 +- .../Authentication/CustomJwtBearerOptions.cs | 2 +- .../CustomUserClaimsPrincipalFactory.cs | 2 +- .../Authorization/LocalPermissionChecker.cs | 2 +- .../Controllers/AccountController.cs | 4 +- .../Controllers/PermissionsController.cs | 2 +- .../Controllers/UsersController.cs | 3 +- .../DataSeeding/UserDataSeedingProvider.cs | 6 +- ...ermissionGrantedEntityTypeConfiguration.cs | 2 +- .../RoleClaimEntityTypeConfiguration.cs | 2 +- .../RoleEntityTypeConfiguration.cs | 2 +- .../UserClaimEntityTypeConfiguration.cs | 2 +- .../UserEntityTypeConfiguration.cs | 2 +- .../UserLoginEntityTypeConfiguration.cs | 2 +- .../UserRoleEntityTypeConfiguration.cs | 2 +- .../UserTokenEntityTypeConfiguration.cs | 2 +- .../IdentityServiceDbContext.cs | 2 +- .../20240403122821_InitialCreate.Designer.cs | 2 +- .../20240403122821_InitialCreate.cs | 0 .../IdentityServiceDbContextModelSnapshot.cs | 2 +- .../README.md | 2 +- .../Models/Accounts/AccountLoginRequest.cs | 2 +- .../Models/Accounts/AccountRefreshRequest.cs | 2 +- .../Models/Accounts/AccountRegisterRequest.cs | 2 +- .../Models/Users/UserListItem.cs | 2 +- .../IdentityPermissionDefinitionProvider.cs | 2 +- .../IdentityPermissions.cs | 2 +- src/HelloShop.IdentityService/Program.cs | 4 +- .../Users/UserCreateRequestValidator.cs | 2 +- .../Users/UserUpdateRequestValidator.cs | 2 +- .../Constants/DbConstants.cs | 12 + .../OrderingDataSeedingProvider.cs | 16 ++ .../Entities/Buyers/Buyer.cs | 14 + .../Entities/Buyers/PaymentMethod.cs | 22 ++ .../Entities/Orders/Address.cs | 33 +++ .../Entities/Orders/Order.cs | 40 +++ .../Entities/Orders/OrderItem.cs | 22 ++ .../Entities/Orders/OrderStatus.cs | 15 ++ .../Extensions/Extensions.cs | 30 +++ .../HelloShop.OrderingService.csproj | 8 + .../Buyers/BuyerEntityTypeConfiguration.cs | 19 ++ .../PaymentMethodEntityTypeConfiguration.cs | 22 ++ .../Orders/OrderEntityTypeConfiguration.cs | 34 +++ .../OrderItemEntityTypeConfiguration.cs | 20 ++ .../20240829142135_InitialCreate.Designer.cs | 247 ++++++++++++++++++ .../20240829142135_InitialCreate.cs | 149 +++++++++++ .../OrderingServiceDbContextModelSnapshot.cs | 244 +++++++++++++++++ .../OrderingServiceDbContext.cs | 18 ++ .../Infrastructure/README.md | 6 + src/HelloShop.OrderingService/Program.cs | 15 +- .../appsettings.json | 6 +- .../Controllers/BrandsController.cs | 4 +- .../Controllers/ProductsController.cs | 4 +- .../DataSeeding/ProductDataSeedingProvider.cs | 10 +- .../Products/BrandEntityTypeConfiguration.cs | 2 +- .../ProductEntityTypeConfiguration.cs | 2 +- .../20240419145737_InitialCreate.Designer.cs | 2 +- .../20240419145737_InitialCreate.cs | 0 .../ProductServiceDbContextModelSnapshot.cs | 2 +- .../ProductServiceDbContext.cs | 2 +- src/HelloShop.ProductService/Program.cs | 2 +- .../Services/ProductService.cs | 2 +- .../Infrastructure/IDataSeedingProvider.cs | 2 +- .../Utilities/CustomWebApplicationFactory.cs | 2 +- .../ProductsControllerTest.cs | 6 +- .../Utilities/FakeDbContextFactory.cs | 2 +- 69 files changed, 1042 insertions(+), 67 deletions(-) rename src/HelloShop.IdentityService/{EntityFrameworks => Infrastructure}/EntityConfigurations/PermissionGrantedEntityTypeConfiguration.cs (92%) rename src/HelloShop.IdentityService/{EntityFrameworks => Infrastructure}/EntityConfigurations/RoleClaimEntityTypeConfiguration.cs (88%) rename src/HelloShop.IdentityService/{EntityFrameworks => Infrastructure}/EntityConfigurations/RoleEntityTypeConfiguration.cs (92%) rename src/HelloShop.IdentityService/{EntityFrameworks => Infrastructure}/EntityConfigurations/UserClaimEntityTypeConfiguration.cs (88%) rename src/HelloShop.IdentityService/{EntityFrameworks => Infrastructure}/EntityConfigurations/UserEntityTypeConfiguration.cs (95%) rename src/HelloShop.IdentityService/{EntityFrameworks => Infrastructure}/EntityConfigurations/UserLoginEntityTypeConfiguration.cs (90%) rename src/HelloShop.IdentityService/{EntityFrameworks => Infrastructure}/EntityConfigurations/UserRoleEntityTypeConfiguration.cs (87%) rename src/HelloShop.IdentityService/{EntityFrameworks => Infrastructure}/EntityConfigurations/UserTokenEntityTypeConfiguration.cs (89%) rename src/HelloShop.IdentityService/{EntityFrameworks => Infrastructure}/IdentityServiceDbContext.cs (94%) rename src/HelloShop.IdentityService/{EntityFrameworks => Infrastructure}/Migrations/20240403122821_InitialCreate.Designer.cs (99%) rename src/HelloShop.IdentityService/{EntityFrameworks => Infrastructure}/Migrations/20240403122821_InitialCreate.cs (100%) rename src/HelloShop.IdentityService/{EntityFrameworks => Infrastructure}/Migrations/IdentityServiceDbContextModelSnapshot.cs (99%) rename src/HelloShop.IdentityService/{EntityFrameworks => Infrastructure}/README.md (55%) create mode 100644 src/HelloShop.OrderingService/Constants/DbConstants.cs create mode 100644 src/HelloShop.OrderingService/DataSeeding/OrderingDataSeedingProvider.cs create mode 100644 src/HelloShop.OrderingService/Entities/Buyers/Buyer.cs create mode 100644 src/HelloShop.OrderingService/Entities/Buyers/PaymentMethod.cs create mode 100644 src/HelloShop.OrderingService/Entities/Orders/Address.cs create mode 100644 src/HelloShop.OrderingService/Entities/Orders/Order.cs create mode 100644 src/HelloShop.OrderingService/Entities/Orders/OrderItem.cs create mode 100644 src/HelloShop.OrderingService/Entities/Orders/OrderStatus.cs create mode 100644 src/HelloShop.OrderingService/Extensions/Extensions.cs create mode 100644 src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Buyers/BuyerEntityTypeConfiguration.cs create mode 100644 src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Buyers/PaymentMethodEntityTypeConfiguration.cs create mode 100644 src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Orders/OrderEntityTypeConfiguration.cs create mode 100644 src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Orders/OrderItemEntityTypeConfiguration.cs create mode 100644 src/HelloShop.OrderingService/Infrastructure/Migrations/20240829142135_InitialCreate.Designer.cs create mode 100644 src/HelloShop.OrderingService/Infrastructure/Migrations/20240829142135_InitialCreate.cs create mode 100644 src/HelloShop.OrderingService/Infrastructure/Migrations/OrderingServiceDbContextModelSnapshot.cs create mode 100644 src/HelloShop.OrderingService/Infrastructure/OrderingServiceDbContext.cs create mode 100644 src/HelloShop.OrderingService/Infrastructure/README.md rename src/HelloShop.ProductService/{EntityFrameworks => Infrastructure}/EntityConfigurations/Products/BrandEntityTypeConfiguration.cs (86%) rename src/HelloShop.ProductService/{EntityFrameworks => Infrastructure}/EntityConfigurations/Products/ProductEntityTypeConfiguration.cs (88%) rename src/HelloShop.ProductService/{EntityFrameworks => Infrastructure}/Migrations/20240419145737_InitialCreate.Designer.cs (98%) rename src/HelloShop.ProductService/{EntityFrameworks => Infrastructure}/Migrations/20240419145737_InitialCreate.cs (100%) rename src/HelloShop.ProductService/{EntityFrameworks => Infrastructure}/Migrations/ProductServiceDbContextModelSnapshot.cs (98%) rename src/HelloShop.ProductService/{EntityFrameworks => Infrastructure}/ProductServiceDbContext.cs (90%) diff --git a/src/HelloShop.AppHost/Program.cs b/src/HelloShop.AppHost/Program.cs index fe936b5..0c0c73f 100644 --- a/src/HelloShop.AppHost/Program.cs +++ b/src/HelloShop.AppHost/Program.cs @@ -3,7 +3,7 @@ var builder = DistributedApplication.CreateBuilder(args); -var cache = builder.AddRedis("cache", port:6379); +var cache = builder.AddRedis("cache", port: 6379); var identityService = builder.AddProject("identityservice"); diff --git a/src/HelloShop.IdentityService/Authentication/CustomJwtBearerDefaults.cs b/src/HelloShop.IdentityService/Authentication/CustomJwtBearerDefaults.cs index 3de91cb..2e1d034 100644 --- a/src/HelloShop.IdentityService/Authentication/CustomJwtBearerDefaults.cs +++ b/src/HelloShop.IdentityService/Authentication/CustomJwtBearerDefaults.cs @@ -1,7 +1,7 @@ // Copyright (c) HelloShop Corporation. All rights reserved. // See the license file in the project root for more information. -namespace HelloShop.IdentityService; +namespace HelloShop.IdentityService.Authentication; public class CustomJwtBearerDefaults { diff --git a/src/HelloShop.IdentityService/Authentication/CustomJwtBearerExtensions.cs b/src/HelloShop.IdentityService/Authentication/CustomJwtBearerExtensions.cs index c544527..df67c0d 100644 --- a/src/HelloShop.IdentityService/Authentication/CustomJwtBearerExtensions.cs +++ b/src/HelloShop.IdentityService/Authentication/CustomJwtBearerExtensions.cs @@ -5,7 +5,7 @@ using HelloShop.IdentityService.Entities; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Identity; -namespace HelloShop.IdentityService; +namespace HelloShop.IdentityService.Authentication; public static class CustomJwtBearerExtensions { diff --git a/src/HelloShop.IdentityService/Authentication/CustomJwtBearerHandler.cs b/src/HelloShop.IdentityService/Authentication/CustomJwtBearerHandler.cs index f5e86bd..d3abc10 100644 --- a/src/HelloShop.IdentityService/Authentication/CustomJwtBearerHandler.cs +++ b/src/HelloShop.IdentityService/Authentication/CustomJwtBearerHandler.cs @@ -10,7 +10,7 @@ using System.Security.Claims; using System.Text; using System.Text.Encodings.Web; -namespace HelloShop.IdentityService; +namespace HelloShop.IdentityService.Authentication; public class CustomJwtBearerHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder) : SignInAuthenticationHandler(options, logger, encoder) { diff --git a/src/HelloShop.IdentityService/Authentication/CustomJwtBearerOptions.cs b/src/HelloShop.IdentityService/Authentication/CustomJwtBearerOptions.cs index 394b9fc..e6b7363 100644 --- a/src/HelloShop.IdentityService/Authentication/CustomJwtBearerOptions.cs +++ b/src/HelloShop.IdentityService/Authentication/CustomJwtBearerOptions.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.IdentityModel.Tokens; -namespace HelloShop.IdentityService; +namespace HelloShop.IdentityService.Authentication; public class CustomJwtBearerOptions : AuthenticationSchemeOptions { diff --git a/src/HelloShop.IdentityService/Authentication/CustomUserClaimsPrincipalFactory.cs b/src/HelloShop.IdentityService/Authentication/CustomUserClaimsPrincipalFactory.cs index 36cf815..07aa3ba 100644 --- a/src/HelloShop.IdentityService/Authentication/CustomUserClaimsPrincipalFactory.cs +++ b/src/HelloShop.IdentityService/Authentication/CustomUserClaimsPrincipalFactory.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Options; using System.Security.Claims; -namespace HelloShop.IdentityService; +namespace HelloShop.IdentityService.Authentication; public class CustomUserClaimsPrincipalFactory(UserManager userManager, RoleManager roleManager, IOptions options) : UserClaimsPrincipalFactory(userManager, roleManager, options) where TUser : IdentityUser where TRole : IdentityRole { diff --git a/src/HelloShop.IdentityService/Authorization/LocalPermissionChecker.cs b/src/HelloShop.IdentityService/Authorization/LocalPermissionChecker.cs index c8a7a55..3eee3b3 100644 --- a/src/HelloShop.IdentityService/Authorization/LocalPermissionChecker.cs +++ b/src/HelloShop.IdentityService/Authorization/LocalPermissionChecker.cs @@ -2,7 +2,7 @@ // See the license file in the project root for more information. using HelloShop.IdentityService.Entities; -using HelloShop.IdentityService.EntityFrameworks; +using HelloShop.IdentityService.Infrastructure; using HelloShop.ServiceDefaults.Authorization; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Distributed; diff --git a/src/HelloShop.IdentityService/Controllers/AccountController.cs b/src/HelloShop.IdentityService/Controllers/AccountController.cs index a8cb9ac..d4dc521 100644 --- a/src/HelloShop.IdentityService/Controllers/AccountController.cs +++ b/src/HelloShop.IdentityService/Controllers/AccountController.cs @@ -1,7 +1,9 @@ // Copyright (c) HelloShop Corporation. All rights reserved. // See the license file in the project root for more information. +using HelloShop.IdentityService.Authentication; using HelloShop.IdentityService.Entities; +using HelloShop.IdentityService.Models.Accounts; using Microsoft.AspNetCore.Authentication.BearerToken; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Http.HttpResults; @@ -13,7 +15,7 @@ using System.Diagnostics; using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; -namespace HelloShop.IdentityService; +namespace HelloShop.IdentityService.Controllers; [Route("api/[controller]")] [ApiController] diff --git a/src/HelloShop.IdentityService/Controllers/PermissionsController.cs b/src/HelloShop.IdentityService/Controllers/PermissionsController.cs index 6b4da01..3a2a9cf 100644 --- a/src/HelloShop.IdentityService/Controllers/PermissionsController.cs +++ b/src/HelloShop.IdentityService/Controllers/PermissionsController.cs @@ -2,7 +2,7 @@ // See the license file in the project root for more information. using HelloShop.IdentityService.Entities; -using HelloShop.IdentityService.EntityFrameworks; +using HelloShop.IdentityService.Infrastructure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; diff --git a/src/HelloShop.IdentityService/Controllers/UsersController.cs b/src/HelloShop.IdentityService/Controllers/UsersController.cs index 3571b29..88ed957 100644 --- a/src/HelloShop.IdentityService/Controllers/UsersController.cs +++ b/src/HelloShop.IdentityService/Controllers/UsersController.cs @@ -4,8 +4,9 @@ using AutoMapper; using FluentValidation; using HelloShop.IdentityService.Entities; -using HelloShop.IdentityService.EntityFrameworks; +using HelloShop.IdentityService.Infrastructure; using HelloShop.IdentityService.Models.Users; +using HelloShop.IdentityService.PermissionProviders; using HelloShop.ServiceDefaults.Authorization; using HelloShop.ServiceDefaults.Extensions; using HelloShop.ServiceDefaults.Models.Paging; diff --git a/src/HelloShop.IdentityService/DataSeeding/UserDataSeedingProvider.cs b/src/HelloShop.IdentityService/DataSeeding/UserDataSeedingProvider.cs index 648ca0b..bc348a7 100644 --- a/src/HelloShop.IdentityService/DataSeeding/UserDataSeedingProvider.cs +++ b/src/HelloShop.IdentityService/DataSeeding/UserDataSeedingProvider.cs @@ -10,9 +10,9 @@ namespace HelloShop.IdentityService.DataSeeding { public class UserDataSeedingProvider(UserManager userManager, RoleManager roleManager) : IDataSeedingProvider { - public async Task SeedingAsync(IServiceProvider ServiceProvider) + public async Task SeedingAsync(IServiceProvider ServiceProvider, CancellationToken cancellationToken = default) { - var adminRole = await roleManager.Roles.SingleOrDefaultAsync(x => x.Name == "AdminRole"); + var adminRole = await roleManager.Roles.SingleOrDefaultAsync(x => x.Name == "AdminRole", cancellationToken); if (adminRole == null) { @@ -20,7 +20,7 @@ namespace HelloShop.IdentityService.DataSeeding await roleManager.CreateAsync(adminRole); } - var guestRole = await roleManager.Roles.SingleOrDefaultAsync(x => x.Name == "GuestRole"); + var guestRole = await roleManager.Roles.SingleOrDefaultAsync(x => x.Name == "GuestRole", cancellationToken: cancellationToken); if (guestRole == null) { diff --git a/src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/PermissionGrantedEntityTypeConfiguration.cs b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/PermissionGrantedEntityTypeConfiguration.cs similarity index 92% rename from src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/PermissionGrantedEntityTypeConfiguration.cs rename to src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/PermissionGrantedEntityTypeConfiguration.cs index 5087b2d..66fed53 100644 --- a/src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/PermissionGrantedEntityTypeConfiguration.cs +++ b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/PermissionGrantedEntityTypeConfiguration.cs @@ -4,7 +4,7 @@ using HelloShop.IdentityService.Entities; using Microsoft.EntityFrameworkCore; -namespace HelloShop.IdentityService.EntityFrameworks.EntityConfigurations; +namespace HelloShop.IdentityService.Infrastructure.EntityConfigurations; public class PermissionGrantedEntityTypeConfiguration : IEntityTypeConfiguration { diff --git a/src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/RoleClaimEntityTypeConfiguration.cs b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/RoleClaimEntityTypeConfiguration.cs similarity index 88% rename from src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/RoleClaimEntityTypeConfiguration.cs rename to src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/RoleClaimEntityTypeConfiguration.cs index c41239c..595c729 100644 --- a/src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/RoleClaimEntityTypeConfiguration.cs +++ b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/RoleClaimEntityTypeConfiguration.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace HelloShop.IdentityService.EntityFrameworks.EntityConfigurations +namespace HelloShop.IdentityService.Infrastructure.EntityConfigurations { public class RoleClaimEntityTypeConfiguration : IEntityTypeConfiguration> { diff --git a/src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/RoleEntityTypeConfiguration.cs b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/RoleEntityTypeConfiguration.cs similarity index 92% rename from src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/RoleEntityTypeConfiguration.cs rename to src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/RoleEntityTypeConfiguration.cs index f27c24f..f7802f1 100644 --- a/src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/RoleEntityTypeConfiguration.cs +++ b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/RoleEntityTypeConfiguration.cs @@ -5,7 +5,7 @@ using HelloShop.IdentityService.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace HelloShop.IdentityService.EntityFrameworks.EntityConfigurations +namespace HelloShop.IdentityService.Infrastructure.EntityConfigurations { public class RoleEntityTypeConfiguration : IEntityTypeConfiguration { diff --git a/src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/UserClaimEntityTypeConfiguration.cs b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserClaimEntityTypeConfiguration.cs similarity index 88% rename from src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/UserClaimEntityTypeConfiguration.cs rename to src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserClaimEntityTypeConfiguration.cs index f710067..97107f7 100644 --- a/src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/UserClaimEntityTypeConfiguration.cs +++ b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserClaimEntityTypeConfiguration.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace HelloShop.IdentityService.EntityFrameworks.EntityConfigurations +namespace HelloShop.IdentityService.Infrastructure.EntityConfigurations { public class UserClaimEntityTypeConfiguration : IEntityTypeConfiguration> { diff --git a/src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/UserEntityTypeConfiguration.cs b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserEntityTypeConfiguration.cs similarity index 95% rename from src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/UserEntityTypeConfiguration.cs rename to src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserEntityTypeConfiguration.cs index de7c7f6..6693c88 100644 --- a/src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/UserEntityTypeConfiguration.cs +++ b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserEntityTypeConfiguration.cs @@ -5,7 +5,7 @@ using HelloShop.IdentityService.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace HelloShop.IdentityService.EntityFrameworks.EntityConfigurations +namespace HelloShop.IdentityService.Infrastructure.EntityConfigurations { public class UserEntityTypeConfiguration : IEntityTypeConfiguration { diff --git a/src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/UserLoginEntityTypeConfiguration.cs b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserLoginEntityTypeConfiguration.cs similarity index 90% rename from src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/UserLoginEntityTypeConfiguration.cs rename to src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserLoginEntityTypeConfiguration.cs index 7635ca5..0d6f408 100644 --- a/src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/UserLoginEntityTypeConfiguration.cs +++ b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserLoginEntityTypeConfiguration.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace HelloShop.IdentityService.EntityFrameworks.EntityConfigurations +namespace HelloShop.IdentityService.Infrastructure.EntityConfigurations { public class UserLoginEntityTypeConfiguration : IEntityTypeConfiguration> { diff --git a/src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/UserRoleEntityTypeConfiguration.cs b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserRoleEntityTypeConfiguration.cs similarity index 87% rename from src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/UserRoleEntityTypeConfiguration.cs rename to src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserRoleEntityTypeConfiguration.cs index 16ad132..91f9101 100644 --- a/src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/UserRoleEntityTypeConfiguration.cs +++ b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserRoleEntityTypeConfiguration.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; -namespace HelloShop.IdentityService.EntityFrameworks.EntityConfigurations +namespace HelloShop.IdentityService.Infrastructure.EntityConfigurations { public class UserRoleEntityTypeConfiguration : IEntityTypeConfiguration> { diff --git a/src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/UserTokenEntityTypeConfiguration.cs b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserTokenEntityTypeConfiguration.cs similarity index 89% rename from src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/UserTokenEntityTypeConfiguration.cs rename to src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserTokenEntityTypeConfiguration.cs index 0840c61..5576364 100644 --- a/src/HelloShop.IdentityService/EntityFrameworks/EntityConfigurations/UserTokenEntityTypeConfiguration.cs +++ b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserTokenEntityTypeConfiguration.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace HelloShop.IdentityService.EntityFrameworks.EntityConfigurations +namespace HelloShop.IdentityService.Infrastructure.EntityConfigurations { public class UserTokenEntityTypeConfiguration : IEntityTypeConfiguration> { diff --git a/src/HelloShop.IdentityService/EntityFrameworks/IdentityServiceDbContext.cs b/src/HelloShop.IdentityService/Infrastructure/IdentityServiceDbContext.cs similarity index 94% rename from src/HelloShop.IdentityService/EntityFrameworks/IdentityServiceDbContext.cs rename to src/HelloShop.IdentityService/Infrastructure/IdentityServiceDbContext.cs index d477352..1269915 100644 --- a/src/HelloShop.IdentityService/EntityFrameworks/IdentityServiceDbContext.cs +++ b/src/HelloShop.IdentityService/Infrastructure/IdentityServiceDbContext.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using System.Reflection; -namespace HelloShop.IdentityService.EntityFrameworks +namespace HelloShop.IdentityService.Infrastructure { public class IdentityServiceDbContext(DbContextOptions options) : IdentityDbContext(options) { diff --git a/src/HelloShop.IdentityService/EntityFrameworks/Migrations/20240403122821_InitialCreate.Designer.cs b/src/HelloShop.IdentityService/Infrastructure/Migrations/20240403122821_InitialCreate.Designer.cs similarity index 99% rename from src/HelloShop.IdentityService/EntityFrameworks/Migrations/20240403122821_InitialCreate.Designer.cs rename to src/HelloShop.IdentityService/Infrastructure/Migrations/20240403122821_InitialCreate.Designer.cs index 8348a16..1802852 100644 --- a/src/HelloShop.IdentityService/EntityFrameworks/Migrations/20240403122821_InitialCreate.Designer.cs +++ b/src/HelloShop.IdentityService/Infrastructure/Migrations/20240403122821_InitialCreate.Designer.cs @@ -1,6 +1,6 @@ // using System; -using HelloShop.IdentityService.EntityFrameworks; +using HelloShop.IdentityService.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/HelloShop.IdentityService/EntityFrameworks/Migrations/20240403122821_InitialCreate.cs b/src/HelloShop.IdentityService/Infrastructure/Migrations/20240403122821_InitialCreate.cs similarity index 100% rename from src/HelloShop.IdentityService/EntityFrameworks/Migrations/20240403122821_InitialCreate.cs rename to src/HelloShop.IdentityService/Infrastructure/Migrations/20240403122821_InitialCreate.cs diff --git a/src/HelloShop.IdentityService/EntityFrameworks/Migrations/IdentityServiceDbContextModelSnapshot.cs b/src/HelloShop.IdentityService/Infrastructure/Migrations/IdentityServiceDbContextModelSnapshot.cs similarity index 99% rename from src/HelloShop.IdentityService/EntityFrameworks/Migrations/IdentityServiceDbContextModelSnapshot.cs rename to src/HelloShop.IdentityService/Infrastructure/Migrations/IdentityServiceDbContextModelSnapshot.cs index 19ab4a6..f4e4dc2 100644 --- a/src/HelloShop.IdentityService/EntityFrameworks/Migrations/IdentityServiceDbContextModelSnapshot.cs +++ b/src/HelloShop.IdentityService/Infrastructure/Migrations/IdentityServiceDbContextModelSnapshot.cs @@ -1,6 +1,6 @@ // using System; -using HelloShop.IdentityService.EntityFrameworks; +using HelloShop.IdentityService.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; diff --git a/src/HelloShop.IdentityService/EntityFrameworks/README.md b/src/HelloShop.IdentityService/Infrastructure/README.md similarity index 55% rename from src/HelloShop.IdentityService/EntityFrameworks/README.md rename to src/HelloShop.IdentityService/Infrastructure/README.md index ca72c96..f0592d7 100644 --- a/src/HelloShop.IdentityService/EntityFrameworks/README.md +++ b/src/HelloShop.IdentityService/Infrastructure/README.md @@ -1,6 +1,6 @@ ```shell dotnet ef database drop --force dotnet ef migrations remove -dotnet ef migrations add InitialCreate --output-dir EntityFrameworks/Migrations +dotnet ef migrations add InitialCreate --output-dir Infrastructure/Migrations dotnet ef database update ``` \ No newline at end of file diff --git a/src/HelloShop.IdentityService/Models/Accounts/AccountLoginRequest.cs b/src/HelloShop.IdentityService/Models/Accounts/AccountLoginRequest.cs index 7e8bb90..9b156d8 100644 --- a/src/HelloShop.IdentityService/Models/Accounts/AccountLoginRequest.cs +++ b/src/HelloShop.IdentityService/Models/Accounts/AccountLoginRequest.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; -namespace HelloShop.IdentityService; +namespace HelloShop.IdentityService.Models.Accounts; public class AccountLoginRequest { diff --git a/src/HelloShop.IdentityService/Models/Accounts/AccountRefreshRequest.cs b/src/HelloShop.IdentityService/Models/Accounts/AccountRefreshRequest.cs index 38f3e18..c0d1242 100644 --- a/src/HelloShop.IdentityService/Models/Accounts/AccountRefreshRequest.cs +++ b/src/HelloShop.IdentityService/Models/Accounts/AccountRefreshRequest.cs @@ -1,7 +1,7 @@ // Copyright (c) HelloShop Corporation. All rights reserved. // See the license file in the project root for more information. -namespace HelloShop.IdentityService; +namespace HelloShop.IdentityService.Models.Accounts; public class AccountRefreshRequest { diff --git a/src/HelloShop.IdentityService/Models/Accounts/AccountRegisterRequest.cs b/src/HelloShop.IdentityService/Models/Accounts/AccountRegisterRequest.cs index a165967..41f1816 100644 --- a/src/HelloShop.IdentityService/Models/Accounts/AccountRegisterRequest.cs +++ b/src/HelloShop.IdentityService/Models/Accounts/AccountRegisterRequest.cs @@ -1,7 +1,7 @@ // Copyright (c) HelloShop Corporation. All rights reserved. // See the license file in the project root for more information. -namespace HelloShop.IdentityService; +namespace HelloShop.IdentityService.Models.Accounts; public class AccountRegisterRequest { diff --git a/src/HelloShop.IdentityService/Models/Users/UserListItem.cs b/src/HelloShop.IdentityService/Models/Users/UserListItem.cs index 145a15e..c2cccec 100644 --- a/src/HelloShop.IdentityService/Models/Users/UserListItem.cs +++ b/src/HelloShop.IdentityService/Models/Users/UserListItem.cs @@ -1,7 +1,7 @@ // Copyright (c) HelloShop Corporation. All rights reserved. // See the license file in the project root for more information. -namespace HelloShop.IdentityService; +namespace HelloShop.IdentityService.Models.Users; public class UserListItem { diff --git a/src/HelloShop.IdentityService/PermissionProviders/IdentityPermissionDefinitionProvider.cs b/src/HelloShop.IdentityService/PermissionProviders/IdentityPermissionDefinitionProvider.cs index 8ebde7c..fa3058d 100644 --- a/src/HelloShop.IdentityService/PermissionProviders/IdentityPermissionDefinitionProvider.cs +++ b/src/HelloShop.IdentityService/PermissionProviders/IdentityPermissionDefinitionProvider.cs @@ -3,7 +3,7 @@ using HelloShop.ServiceDefaults.Permissions; -namespace HelloShop.IdentityService; +namespace HelloShop.IdentityService.PermissionProviders; public class IdentityPermissionDefinitionProvider : IPermissionDefinitionProvider { diff --git a/src/HelloShop.IdentityService/PermissionProviders/IdentityPermissions.cs b/src/HelloShop.IdentityService/PermissionProviders/IdentityPermissions.cs index 16cbb3d..cbac8aa 100644 --- a/src/HelloShop.IdentityService/PermissionProviders/IdentityPermissions.cs +++ b/src/HelloShop.IdentityService/PermissionProviders/IdentityPermissions.cs @@ -1,7 +1,7 @@ // Copyright (c) HelloShop Corporation. All rights reserved. // See the license file in the project root for more information. -namespace HelloShop.IdentityService; +namespace HelloShop.IdentityService.PermissionProviders; public static class IdentityPermissions { diff --git a/src/HelloShop.IdentityService/Program.cs b/src/HelloShop.IdentityService/Program.cs index 72e5898..2891143 100644 --- a/src/HelloShop.IdentityService/Program.cs +++ b/src/HelloShop.IdentityService/Program.cs @@ -1,11 +1,11 @@ // Copyright (c) HelloShop Corporation. All rights reserved. // See the license file in the project root for more information. -using HelloShop.IdentityService; +using HelloShop.IdentityService.Authentication; using HelloShop.IdentityService.Authorization; using HelloShop.IdentityService.Constants; using HelloShop.IdentityService.Entities; -using HelloShop.IdentityService.EntityFrameworks; +using HelloShop.IdentityService.Infrastructure; using HelloShop.ServiceDefaults.Authorization; using HelloShop.ServiceDefaults.Extensions; using Microsoft.AspNetCore.Authentication.JwtBearer; diff --git a/src/HelloShop.IdentityService/Validations/Users/UserCreateRequestValidator.cs b/src/HelloShop.IdentityService/Validations/Users/UserCreateRequestValidator.cs index 0c276cb..02ce5e7 100644 --- a/src/HelloShop.IdentityService/Validations/Users/UserCreateRequestValidator.cs +++ b/src/HelloShop.IdentityService/Validations/Users/UserCreateRequestValidator.cs @@ -3,7 +3,7 @@ using FluentValidation; using HelloShop.IdentityService.Entities; -using HelloShop.IdentityService.EntityFrameworks; +using HelloShop.IdentityService.Infrastructure; using HelloShop.IdentityService.Models.Users; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Localization; diff --git a/src/HelloShop.IdentityService/Validations/Users/UserUpdateRequestValidator.cs b/src/HelloShop.IdentityService/Validations/Users/UserUpdateRequestValidator.cs index dfc1a34..245d289 100644 --- a/src/HelloShop.IdentityService/Validations/Users/UserUpdateRequestValidator.cs +++ b/src/HelloShop.IdentityService/Validations/Users/UserUpdateRequestValidator.cs @@ -3,7 +3,7 @@ using FluentValidation; using HelloShop.IdentityService.Entities; -using HelloShop.IdentityService.EntityFrameworks; +using HelloShop.IdentityService.Infrastructure; using HelloShop.IdentityService.Models.Users; using Microsoft.EntityFrameworkCore; diff --git a/src/HelloShop.OrderingService/Constants/DbConstants.cs b/src/HelloShop.OrderingService/Constants/DbConstants.cs new file mode 100644 index 0000000..1b28bc3 --- /dev/null +++ b/src/HelloShop.OrderingService/Constants/DbConstants.cs @@ -0,0 +1,12 @@ +// Copyright (c) HelloShop Corporation. All rights reserved. +// See the license file in the project root for more information. + +namespace HelloShop.OrderingService.Constants +{ + public class DbConstants + { + public const string MasterConnectionStringName = "OrderingDatabaseMaster"; + + public const string SlaveConnectionStringName = "OrderingDatabaseSlave"; + } +} diff --git a/src/HelloShop.OrderingService/DataSeeding/OrderingDataSeedingProvider.cs b/src/HelloShop.OrderingService/DataSeeding/OrderingDataSeedingProvider.cs new file mode 100644 index 0000000..569b1b0 --- /dev/null +++ b/src/HelloShop.OrderingService/DataSeeding/OrderingDataSeedingProvider.cs @@ -0,0 +1,16 @@ +// Copyright (c) HelloShop Corporation. All rights reserved. +// See the license file in the project root for more information. + +using HelloShop.OrderingService.Infrastructure; +using HelloShop.ServiceDefaults.Infrastructure; + +namespace HelloShop.OrderingService.DataSeeding +{ + public class OrderingDataSeedingProvider(OrderingServiceDbContext dbContext) : IDataSeedingProvider + { + public async Task SeedingAsync(IServiceProvider serviceProvider, CancellationToken cancellationToken = default) + { + await dbContext.Database.EnsureCreatedAsync(cancellationToken); + } + } +} diff --git a/src/HelloShop.OrderingService/Entities/Buyers/Buyer.cs b/src/HelloShop.OrderingService/Entities/Buyers/Buyer.cs new file mode 100644 index 0000000..353a27d --- /dev/null +++ b/src/HelloShop.OrderingService/Entities/Buyers/Buyer.cs @@ -0,0 +1,14 @@ +// Copyright (c) HelloShop Corporation. All rights reserved. +// See the license file in the project root for more information. + +namespace HelloShop.OrderingService.Entities.Buyers +{ + public class Buyer + { + public int Id { get; set; } + + public required string Name { get; set; } + + public List? PaymentMethods { get; set; } + } +} diff --git a/src/HelloShop.OrderingService/Entities/Buyers/PaymentMethod.cs b/src/HelloShop.OrderingService/Entities/Buyers/PaymentMethod.cs new file mode 100644 index 0000000..9cc2859 --- /dev/null +++ b/src/HelloShop.OrderingService/Entities/Buyers/PaymentMethod.cs @@ -0,0 +1,22 @@ +// Copyright (c) HelloShop Corporation. All rights reserved. +// See the license file in the project root for more information. + +namespace HelloShop.OrderingService.Entities.Buyers +{ + public class PaymentMethod + { + public int Id { get; set; } + + public int BuyerId { get; set; } + + public required string Alias { get; set; } + + public required string CardNumber { get; set; } + + public required string CardHolderName { get; set; } + + public string? SecurityNumber { get; set; } + + public DateTimeOffset? Expiration { get; set; } + } +} diff --git a/src/HelloShop.OrderingService/Entities/Orders/Address.cs b/src/HelloShop.OrderingService/Entities/Orders/Address.cs new file mode 100644 index 0000000..945fd81 --- /dev/null +++ b/src/HelloShop.OrderingService/Entities/Orders/Address.cs @@ -0,0 +1,33 @@ +// Copyright (c) HelloShop Corporation. All rights reserved. +// See the license file in the project root for more information. + +namespace HelloShop.OrderingService.Entities.Orders +{ + public record Address + { + /// + /// 国家 + /// + public required string Country { get; set; } + + /// + /// 省份 + /// + public required string State { get; set; } + + /// + /// 城市 + /// + public required string City { get; set; } + + /// + /// 街道 + /// + public required string Street { get; set; } + + /// + /// 邮编 + /// + public required string ZipCode { get; set; } + } +} diff --git a/src/HelloShop.OrderingService/Entities/Orders/Order.cs b/src/HelloShop.OrderingService/Entities/Orders/Order.cs new file mode 100644 index 0000000..cea4de4 --- /dev/null +++ b/src/HelloShop.OrderingService/Entities/Orders/Order.cs @@ -0,0 +1,40 @@ +// Copyright (c) HelloShop Corporation. All rights reserved. +// See the license file in the project root for more information. + +using System.Diagnostics.CodeAnalysis; + +namespace HelloShop.OrderingService.Entities.Orders +{ + public class Order + { + public int Id { get; set; } + + public DateTimeOffset OrderDate { get; private set; } = DateTimeOffset.UtcNow; + + public required Address Address { get; init; } + + public OrderStatus OrderStatus { get; set; } = OrderStatus.Submitted; + + public int BuyerId { get; set; } + + public int? PaymentMethodId { get; set; } + + public required IReadOnlyCollection OrderItems { get; init; } + + public string? Description { get; set; } + + /// + /// EF Core cannot set navigation properties using a constructor. + /// The constructor can be public, private, or have any other accessibility. + /// + private Order() { } + + [SetsRequiredMembers] + public Order(int buyerId, Address address, IEnumerable orderItems) + { + Address = address; + BuyerId = buyerId; + OrderItems = orderItems.ToList(); + } + } +} diff --git a/src/HelloShop.OrderingService/Entities/Orders/OrderItem.cs b/src/HelloShop.OrderingService/Entities/Orders/OrderItem.cs new file mode 100644 index 0000000..57bc554 --- /dev/null +++ b/src/HelloShop.OrderingService/Entities/Orders/OrderItem.cs @@ -0,0 +1,22 @@ +// Copyright (c) HelloShop Corporation. All rights reserved. +// See the license file in the project root for more information. + +namespace HelloShop.OrderingService.Entities.Orders +{ + public class OrderItem + { + public int Id { get; set; } + + public int OrderId { get; set; } + + public int ProductId { get; set; } + + public required string ProductName { get; set; } + + public required string PictureUrl { get; set; } + + public decimal UnitPrice { get; set; } + + public int Units { get; set; } + } +} diff --git a/src/HelloShop.OrderingService/Entities/Orders/OrderStatus.cs b/src/HelloShop.OrderingService/Entities/Orders/OrderStatus.cs new file mode 100644 index 0000000..0405d3b --- /dev/null +++ b/src/HelloShop.OrderingService/Entities/Orders/OrderStatus.cs @@ -0,0 +1,15 @@ +// Copyright (c) HelloShop Corporation. All rights reserved. +// See the license file in the project root for more information. + +namespace HelloShop.OrderingService.Entities.Orders +{ + public enum OrderStatus + { + Submitted = 1, + AwaitingValidation = 2, + StockConfirmed = 3, + Paid = 4, + Shipped = 5, + Cancelled = 6 + } +} diff --git a/src/HelloShop.OrderingService/Extensions/Extensions.cs b/src/HelloShop.OrderingService/Extensions/Extensions.cs new file mode 100644 index 0000000..28c9048 --- /dev/null +++ b/src/HelloShop.OrderingService/Extensions/Extensions.cs @@ -0,0 +1,30 @@ +// Copyright (c) HelloShop Corporation. All rights reserved. +// See the license file in the project root for more information. + +using HelloShop.OrderingService.Constants; +using HelloShop.OrderingService.Infrastructure; +using HelloShop.ServiceDefaults.Extensions; +using Microsoft.EntityFrameworkCore; + +namespace HelloShop.OrderingService.Extensions +{ + public static class Extensions + { + public static void AddApplicationServices(this IHostApplicationBuilder builder) + { + builder.Services.AddDataSeedingProviders(); + + builder.Services.AddDbContext(options => + { + options.UseNpgsql(builder.Configuration.GetConnectionString(DbConstants.MasterConnectionStringName)); + }); + } + + public static WebApplication MapApplicationEndpoints(this WebApplication app) + { + app.UseDataSeedingProviders(); + + return app; + } + } +} diff --git a/src/HelloShop.OrderingService/HelloShop.OrderingService.csproj b/src/HelloShop.OrderingService/HelloShop.OrderingService.csproj index 6aa8756..7fe73e5 100644 --- a/src/HelloShop.OrderingService/HelloShop.OrderingService.csproj +++ b/src/HelloShop.OrderingService/HelloShop.OrderingService.csproj @@ -7,4 +7,12 @@ + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + \ No newline at end of file diff --git a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Buyers/BuyerEntityTypeConfiguration.cs b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Buyers/BuyerEntityTypeConfiguration.cs new file mode 100644 index 0000000..3f80e5b --- /dev/null +++ b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Buyers/BuyerEntityTypeConfiguration.cs @@ -0,0 +1,19 @@ +// Copyright (c) HelloShop Corporation. All rights reserved. +// See the license file in the project root for more information. + +using HelloShop.OrderingService.Entities.Buyers; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Buyers +{ + public class BuyerEntityTypeConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("Buyer"); + builder.Property(x => x.Name).HasMaxLength(16).IsRequired(); + builder.HasMany(b => b.PaymentMethods).WithOne().HasForeignKey(x => x.BuyerId).OnDelete(DeleteBehavior.Cascade); + } + } +} diff --git a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Buyers/PaymentMethodEntityTypeConfiguration.cs b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Buyers/PaymentMethodEntityTypeConfiguration.cs new file mode 100644 index 0000000..ca696b1 --- /dev/null +++ b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Buyers/PaymentMethodEntityTypeConfiguration.cs @@ -0,0 +1,22 @@ +// Copyright (c) HelloShop Corporation. All rights reserved. +// See the license file in the project root for more information. + +using HelloShop.OrderingService.Entities.Buyers; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Buyers +{ + public class PaymentMethodEntityTypeConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("PaymentMethods"); + + builder.Property(x => x.Alias).HasMaxLength(16); + builder.Property(x => x.CardNumber).HasMaxLength(16); + builder.Property(x => x.CardHolderName).HasMaxLength(16); + builder.Property(x => x.SecurityNumber).HasMaxLength(6); + } + } +} diff --git a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Orders/OrderEntityTypeConfiguration.cs b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Orders/OrderEntityTypeConfiguration.cs new file mode 100644 index 0000000..90f707a --- /dev/null +++ b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Orders/OrderEntityTypeConfiguration.cs @@ -0,0 +1,34 @@ +// Copyright (c) HelloShop Corporation. All rights reserved. +// See the license file in the project root for more information. + +using HelloShop.OrderingService.Entities.Buyers; +using HelloShop.OrderingService.Entities.Orders; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Orders +{ + public class OrderEntityTypeConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("Orders"); + + builder.Property(x => x.Description).HasMaxLength(64); + builder.Property(x => x.OrderStatus).HasConversion(); + + builder.OwnsOne(x => x.Address, ownedAddress => + { + ownedAddress.Property(x => x.Country).HasColumnName(nameof(Address.Country)).HasMaxLength(8).IsRequired(); + ownedAddress.Property(x => x.State).HasColumnName(nameof(Address.State)).HasMaxLength(16).IsRequired(); + ownedAddress.Property(x => x.City).HasColumnName(nameof(Address.City)).HasMaxLength(16).IsRequired(); + ownedAddress.Property(x => x.Street).HasColumnName(nameof(Address.Street)).HasMaxLength(32).IsRequired(); + ownedAddress.Property(x => x.ZipCode).HasColumnName(nameof(Address.ZipCode)).HasMaxLength(6).IsRequired(); + }); + + builder.HasOne().WithMany().HasForeignKey(x => x.BuyerId).OnDelete(DeleteBehavior.Cascade); + builder.HasMany(x => x.OrderItems).WithOne().HasForeignKey(x => x.OrderId).OnDelete(DeleteBehavior.Cascade); + builder.HasOne().WithMany().HasForeignKey(x => x.PaymentMethodId).OnDelete(DeleteBehavior.Restrict); + } + } +} diff --git a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Orders/OrderItemEntityTypeConfiguration.cs b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Orders/OrderItemEntityTypeConfiguration.cs new file mode 100644 index 0000000..4c2afe7 --- /dev/null +++ b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Orders/OrderItemEntityTypeConfiguration.cs @@ -0,0 +1,20 @@ +// Copyright (c) HelloShop Corporation. All rights reserved. +// See the license file in the project root for more information. + +using HelloShop.OrderingService.Entities.Orders; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Orders +{ + public class OrderItemEntityTypeConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("OrderItems"); + + builder.Property(x => x.ProductName).HasMaxLength(16); + builder.Property(x => x.PictureUrl).HasMaxLength(256); + } + } +} diff --git a/src/HelloShop.OrderingService/Infrastructure/Migrations/20240829142135_InitialCreate.Designer.cs b/src/HelloShop.OrderingService/Infrastructure/Migrations/20240829142135_InitialCreate.Designer.cs new file mode 100644 index 0000000..268cbb1 --- /dev/null +++ b/src/HelloShop.OrderingService/Infrastructure/Migrations/20240829142135_InitialCreate.Designer.cs @@ -0,0 +1,247 @@ +// +using System; +using HelloShop.OrderingService.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HelloShop.OrderingService.Infrastructure.Migrations +{ + [DbContext(typeof(OrderingServiceDbContext))] + [Migration("20240829142135_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.Buyer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("character varying(16)"); + + b.HasKey("Id"); + + b.ToTable("Buyer", (string)null); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Alias") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("character varying(16)"); + + b.Property("BuyerId") + .HasColumnType("integer"); + + b.Property("CardHolderName") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("character varying(16)"); + + b.Property("CardNumber") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("character varying(16)"); + + b.Property("Expiration") + .HasColumnType("timestamp with time zone"); + + b.Property("SecurityNumber") + .HasMaxLength(6) + .HasColumnType("character varying(6)"); + + b.HasKey("Id"); + + b.HasIndex("BuyerId"); + + b.ToTable("PaymentMethods", (string)null); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BuyerId") + .HasColumnType("integer"); + + b.Property("Description") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("OrderDate") + .HasColumnType("timestamp with time zone"); + + b.Property("OrderStatus") + .IsRequired() + .HasColumnType("text"); + + b.Property("PaymentMethodId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("BuyerId"); + + b.HasIndex("PaymentMethodId"); + + b.ToTable("Orders", (string)null); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.OrderItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("OrderId") + .HasColumnType("integer"); + + b.Property("PictureUrl") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("ProductId") + .HasColumnType("integer"); + + b.Property("ProductName") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("character varying(16)"); + + b.Property("UnitPrice") + .HasColumnType("numeric"); + + b.Property("Units") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.ToTable("OrderItems", (string)null); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", b => + { + b.HasOne("HelloShop.OrderingService.Entities.Buyers.Buyer", null) + .WithMany("PaymentMethods") + .HasForeignKey("BuyerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b => + { + b.HasOne("HelloShop.OrderingService.Entities.Buyers.Buyer", null) + .WithMany() + .HasForeignKey("BuyerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", null) + .WithMany() + .HasForeignKey("PaymentMethodId") + .OnDelete(DeleteBehavior.Restrict); + + b.OwnsOne("HelloShop.OrderingService.Entities.Orders.Address", "Address", b1 => + { + b1.Property("OrderId") + .HasColumnType("integer"); + + b1.Property("City") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("character varying(16)") + .HasColumnName("City"); + + b1.Property("Country") + .IsRequired() + .HasMaxLength(8) + .HasColumnType("character varying(8)") + .HasColumnName("Country"); + + b1.Property("State") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("character varying(16)") + .HasColumnName("State"); + + b1.Property("Street") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)") + .HasColumnName("Street"); + + b1.Property("ZipCode") + .IsRequired() + .HasMaxLength(6) + .HasColumnType("character varying(6)") + .HasColumnName("ZipCode"); + + b1.HasKey("OrderId"); + + b1.ToTable("Orders"); + + b1.WithOwner() + .HasForeignKey("OrderId"); + }); + + b.Navigation("Address") + .IsRequired(); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.OrderItem", b => + { + b.HasOne("HelloShop.OrderingService.Entities.Orders.Order", null) + .WithMany("OrderItems") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.Buyer", b => + { + b.Navigation("PaymentMethods"); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b => + { + b.Navigation("OrderItems"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/HelloShop.OrderingService/Infrastructure/Migrations/20240829142135_InitialCreate.cs b/src/HelloShop.OrderingService/Infrastructure/Migrations/20240829142135_InitialCreate.cs new file mode 100644 index 0000000..45433aa --- /dev/null +++ b/src/HelloShop.OrderingService/Infrastructure/Migrations/20240829142135_InitialCreate.cs @@ -0,0 +1,149 @@ +// Copyright (c) HelloShop Corporation. All rights reserved. +// See the license file in the project root for more information. + +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HelloShop.OrderingService.Infrastructure.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Buyer", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "character varying(16)", maxLength: 16, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Buyer", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "PaymentMethods", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + BuyerId = table.Column(type: "integer", nullable: false), + Alias = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), + CardNumber = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), + CardHolderName = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), + SecurityNumber = table.Column(type: "character varying(6)", maxLength: 6, nullable: true), + Expiration = table.Column(type: "timestamp with time zone", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_PaymentMethods", x => x.Id); + table.ForeignKey( + name: "FK_PaymentMethods_Buyer_BuyerId", + column: x => x.BuyerId, + principalTable: "Buyer", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + OrderDate = table.Column(type: "timestamp with time zone", nullable: false), + Country = table.Column(type: "character varying(8)", maxLength: 8, nullable: false), + State = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), + City = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), + Street = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), + ZipCode = table.Column(type: "character varying(6)", maxLength: 6, nullable: false), + OrderStatus = table.Column(type: "text", nullable: false), + BuyerId = table.Column(type: "integer", nullable: false), + PaymentMethodId = table.Column(type: "integer", nullable: true), + Description = table.Column(type: "character varying(64)", maxLength: 64, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Buyer_BuyerId", + column: x => x.BuyerId, + principalTable: "Buyer", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_PaymentMethods_PaymentMethodId", + column: x => x.PaymentMethodId, + principalTable: "PaymentMethods", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "OrderItems", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + OrderId = table.Column(type: "integer", nullable: false), + ProductId = table.Column(type: "integer", nullable: false), + ProductName = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), + PictureUrl = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), + UnitPrice = table.Column(type: "numeric", nullable: false), + Units = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OrderItems", x => x.Id); + table.ForeignKey( + name: "FK_OrderItems_Orders_OrderId", + column: x => x.OrderId, + principalTable: "Orders", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_OrderItems_OrderId", + table: "OrderItems", + column: "OrderId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_BuyerId", + table: "Orders", + column: "BuyerId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_PaymentMethodId", + table: "Orders", + column: "PaymentMethodId"); + + migrationBuilder.CreateIndex( + name: "IX_PaymentMethods_BuyerId", + table: "PaymentMethods", + column: "BuyerId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "OrderItems"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "PaymentMethods"); + + migrationBuilder.DropTable( + name: "Buyer"); + } + } +} diff --git a/src/HelloShop.OrderingService/Infrastructure/Migrations/OrderingServiceDbContextModelSnapshot.cs b/src/HelloShop.OrderingService/Infrastructure/Migrations/OrderingServiceDbContextModelSnapshot.cs new file mode 100644 index 0000000..1aaa316 --- /dev/null +++ b/src/HelloShop.OrderingService/Infrastructure/Migrations/OrderingServiceDbContextModelSnapshot.cs @@ -0,0 +1,244 @@ +// +using System; +using HelloShop.OrderingService.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HelloShop.OrderingService.Infrastructure.Migrations +{ + [DbContext(typeof(OrderingServiceDbContext))] + partial class OrderingServiceDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.Buyer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("character varying(16)"); + + b.HasKey("Id"); + + b.ToTable("Buyer", (string)null); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Alias") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("character varying(16)"); + + b.Property("BuyerId") + .HasColumnType("integer"); + + b.Property("CardHolderName") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("character varying(16)"); + + b.Property("CardNumber") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("character varying(16)"); + + b.Property("Expiration") + .HasColumnType("timestamp with time zone"); + + b.Property("SecurityNumber") + .HasMaxLength(6) + .HasColumnType("character varying(6)"); + + b.HasKey("Id"); + + b.HasIndex("BuyerId"); + + b.ToTable("PaymentMethods", (string)null); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BuyerId") + .HasColumnType("integer"); + + b.Property("Description") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("OrderDate") + .HasColumnType("timestamp with time zone"); + + b.Property("OrderStatus") + .IsRequired() + .HasColumnType("text"); + + b.Property("PaymentMethodId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("BuyerId"); + + b.HasIndex("PaymentMethodId"); + + b.ToTable("Orders", (string)null); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.OrderItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("OrderId") + .HasColumnType("integer"); + + b.Property("PictureUrl") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("ProductId") + .HasColumnType("integer"); + + b.Property("ProductName") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("character varying(16)"); + + b.Property("UnitPrice") + .HasColumnType("numeric"); + + b.Property("Units") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.ToTable("OrderItems", (string)null); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", b => + { + b.HasOne("HelloShop.OrderingService.Entities.Buyers.Buyer", null) + .WithMany("PaymentMethods") + .HasForeignKey("BuyerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b => + { + b.HasOne("HelloShop.OrderingService.Entities.Buyers.Buyer", null) + .WithMany() + .HasForeignKey("BuyerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", null) + .WithMany() + .HasForeignKey("PaymentMethodId") + .OnDelete(DeleteBehavior.Restrict); + + b.OwnsOne("HelloShop.OrderingService.Entities.Orders.Address", "Address", b1 => + { + b1.Property("OrderId") + .HasColumnType("integer"); + + b1.Property("City") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("character varying(16)") + .HasColumnName("City"); + + b1.Property("Country") + .IsRequired() + .HasMaxLength(8) + .HasColumnType("character varying(8)") + .HasColumnName("Country"); + + b1.Property("State") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("character varying(16)") + .HasColumnName("State"); + + b1.Property("Street") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)") + .HasColumnName("Street"); + + b1.Property("ZipCode") + .IsRequired() + .HasMaxLength(6) + .HasColumnType("character varying(6)") + .HasColumnName("ZipCode"); + + b1.HasKey("OrderId"); + + b1.ToTable("Orders"); + + b1.WithOwner() + .HasForeignKey("OrderId"); + }); + + b.Navigation("Address") + .IsRequired(); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.OrderItem", b => + { + b.HasOne("HelloShop.OrderingService.Entities.Orders.Order", null) + .WithMany("OrderItems") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.Buyer", b => + { + b.Navigation("PaymentMethods"); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b => + { + b.Navigation("OrderItems"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/HelloShop.OrderingService/Infrastructure/OrderingServiceDbContext.cs b/src/HelloShop.OrderingService/Infrastructure/OrderingServiceDbContext.cs new file mode 100644 index 0000000..16b3ed6 --- /dev/null +++ b/src/HelloShop.OrderingService/Infrastructure/OrderingServiceDbContext.cs @@ -0,0 +1,18 @@ +// Copyright (c) HelloShop Corporation. All rights reserved. +// See the license file in the project root for more information. + +using Microsoft.EntityFrameworkCore; +using System.Reflection; + +namespace HelloShop.OrderingService.Infrastructure +{ + public partial class OrderingServiceDbContext(DbContextOptions options) : DbContext(options) + { + protected override void OnModelCreating(ModelBuilder builder) + { + base.OnModelCreating(builder); + + builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); + } + } +} diff --git a/src/HelloShop.OrderingService/Infrastructure/README.md b/src/HelloShop.OrderingService/Infrastructure/README.md new file mode 100644 index 0000000..f0592d7 --- /dev/null +++ b/src/HelloShop.OrderingService/Infrastructure/README.md @@ -0,0 +1,6 @@ +```shell +dotnet ef database drop --force +dotnet ef migrations remove +dotnet ef migrations add InitialCreate --output-dir Infrastructure/Migrations +dotnet ef database update +``` \ No newline at end of file diff --git a/src/HelloShop.OrderingService/Program.cs b/src/HelloShop.OrderingService/Program.cs index 6f7bf8b..7c4ae8a 100644 --- a/src/HelloShop.OrderingService/Program.cs +++ b/src/HelloShop.OrderingService/Program.cs @@ -1,27 +1,22 @@ // Copyright (c) HelloShop Corporation. All rights reserved. // See the license file in the project root for more information. -using HelloShop.ServiceDefaults.Extensions; +using HelloShop.OrderingService.Extensions; var builder = WebApplication.CreateBuilder(args); -builder.AddServiceDefaults(); - // Add services to the container. - +builder.AddServiceDefaults(); +builder.AddApplicationServices(); builder.Services.AddControllers(); -builder.Services.AddOpenApi(); var app = builder.Build(); +// Configure the HTTP request pipeline. app.MapDefaultEndpoints(); -app.UseAuthorization(); - -app.UseCors(options => options.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); +app.MapApplicationEndpoints(); app.MapControllers(); -app.UseOpenApi(); - app.Run(); diff --git a/src/HelloShop.OrderingService/appsettings.json b/src/HelloShop.OrderingService/appsettings.json index 10f68b8..2e367cf 100644 --- a/src/HelloShop.OrderingService/appsettings.json +++ b/src/HelloShop.OrderingService/appsettings.json @@ -5,5 +5,9 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ConnectionStrings": { + "OrderingDatabaseMaster": "Host=localhost;Port=5432;Database=OrderingService;Username=postgres;Password=postgres", + "OrderingDatabaseSlave": "Host=localhost;Port=5432;Database=OrderingService;Username=postgres;Password=postgres" + } } diff --git a/src/HelloShop.ProductService/Controllers/BrandsController.cs b/src/HelloShop.ProductService/Controllers/BrandsController.cs index dc60411..a8f61d2 100644 --- a/src/HelloShop.ProductService/Controllers/BrandsController.cs +++ b/src/HelloShop.ProductService/Controllers/BrandsController.cs @@ -3,7 +3,7 @@ using AutoMapper; using HelloShop.ProductService.Entities.Products; -using HelloShop.ProductService.EntityFrameworks; +using HelloShop.ProductService.Infrastructure; using HelloShop.ProductService.Models.Products; using HelloShop.ProductService.PermissionProviders; using HelloShop.ServiceDefaults.Extensions; @@ -12,7 +12,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace HelloShop.ProductService; +namespace HelloShop.ProductService.Controllers; [Route("api/[controller]")] [ApiController] public class BrandsController(ProductServiceDbContext dbContext, IMapper mapper) : ControllerBase diff --git a/src/HelloShop.ProductService/Controllers/ProductsController.cs b/src/HelloShop.ProductService/Controllers/ProductsController.cs index 9eb2f5c..061e129 100644 --- a/src/HelloShop.ProductService/Controllers/ProductsController.cs +++ b/src/HelloShop.ProductService/Controllers/ProductsController.cs @@ -3,7 +3,7 @@ using AutoMapper; using HelloShop.ProductService.Entities.Products; -using HelloShop.ProductService.EntityFrameworks; +using HelloShop.ProductService.Infrastructure; using HelloShop.ProductService.Models.Products; using HelloShop.ProductService.PermissionProviders; using HelloShop.ServiceDefaults.Extensions; @@ -12,7 +12,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace HelloShop.ProductService; +namespace HelloShop.ProductService.Controllers; [Route("api/[controller]")] [ApiController] diff --git a/src/HelloShop.ProductService/DataSeeding/ProductDataSeedingProvider.cs b/src/HelloShop.ProductService/DataSeeding/ProductDataSeedingProvider.cs index 66aca16..5574e74 100644 --- a/src/HelloShop.ProductService/DataSeeding/ProductDataSeedingProvider.cs +++ b/src/HelloShop.ProductService/DataSeeding/ProductDataSeedingProvider.cs @@ -2,14 +2,14 @@ // See the license file in the project root for more information. using HelloShop.ProductService.Entities.Products; -using HelloShop.ProductService.EntityFrameworks; +using HelloShop.ProductService.Infrastructure; using HelloShop.ServiceDefaults.Infrastructure; namespace HelloShop.ProductService.DataSeeding { public class ProductDataSeedingProvider(ProductServiceDbContext dbContext) : IDataSeedingProvider { - public async Task SeedingAsync(IServiceProvider ServiceProvider) + public async Task SeedingAsync(IServiceProvider ServiceProvider, CancellationToken cancellationToken = default) { if (!dbContext.Set().Any()) { @@ -82,16 +82,16 @@ namespace HelloShop.ProductService.DataSeeding { var brand = new Brand { Name = brandName }; - await dbContext.AddAsync(brand); + await dbContext.AddAsync(brand, cancellationToken); foreach (var product in productList) { product.Brand = brand; - await dbContext.AddAsync(product); + await dbContext.AddAsync(product, cancellationToken); } } - await dbContext.SaveChangesAsync(); + await dbContext.SaveChangesAsync(cancellationToken); } } } diff --git a/src/HelloShop.ProductService/EntityFrameworks/EntityConfigurations/Products/BrandEntityTypeConfiguration.cs b/src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/BrandEntityTypeConfiguration.cs similarity index 86% rename from src/HelloShop.ProductService/EntityFrameworks/EntityConfigurations/Products/BrandEntityTypeConfiguration.cs rename to src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/BrandEntityTypeConfiguration.cs index f8177b7..314e379 100644 --- a/src/HelloShop.ProductService/EntityFrameworks/EntityConfigurations/Products/BrandEntityTypeConfiguration.cs +++ b/src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/BrandEntityTypeConfiguration.cs @@ -5,7 +5,7 @@ using HelloShop.ProductService.Entities.Products; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace HelloShop.ProductService.EntityFrameworks.EntityConfigurations.Products; +namespace HelloShop.ProductService.Infrastructure.EntityConfigurations.Products; public class BrandEntityTypeConfiguration : IEntityTypeConfiguration { diff --git a/src/HelloShop.ProductService/EntityFrameworks/EntityConfigurations/Products/ProductEntityTypeConfiguration.cs b/src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/ProductEntityTypeConfiguration.cs similarity index 88% rename from src/HelloShop.ProductService/EntityFrameworks/EntityConfigurations/Products/ProductEntityTypeConfiguration.cs rename to src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/ProductEntityTypeConfiguration.cs index d3ddb61..e14cb02 100644 --- a/src/HelloShop.ProductService/EntityFrameworks/EntityConfigurations/Products/ProductEntityTypeConfiguration.cs +++ b/src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/ProductEntityTypeConfiguration.cs @@ -5,7 +5,7 @@ using HelloShop.ProductService.Entities.Products; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace HelloShop.ProductService.EntityFrameworks.EntityConfigurations.Products; +namespace HelloShop.ProductService.Infrastructure.EntityConfigurations.Products; public class ProductEntityTypeConfiguration : IEntityTypeConfiguration { diff --git a/src/HelloShop.ProductService/EntityFrameworks/Migrations/20240419145737_InitialCreate.Designer.cs b/src/HelloShop.ProductService/Infrastructure/Migrations/20240419145737_InitialCreate.Designer.cs similarity index 98% rename from src/HelloShop.ProductService/EntityFrameworks/Migrations/20240419145737_InitialCreate.Designer.cs rename to src/HelloShop.ProductService/Infrastructure/Migrations/20240419145737_InitialCreate.Designer.cs index 9c17e47..ad3d2af 100644 --- a/src/HelloShop.ProductService/EntityFrameworks/Migrations/20240419145737_InitialCreate.Designer.cs +++ b/src/HelloShop.ProductService/Infrastructure/Migrations/20240419145737_InitialCreate.Designer.cs @@ -1,6 +1,6 @@ // using System; -using HelloShop.ProductService.EntityFrameworks; +using HelloShop.ProductService.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/HelloShop.ProductService/EntityFrameworks/Migrations/20240419145737_InitialCreate.cs b/src/HelloShop.ProductService/Infrastructure/Migrations/20240419145737_InitialCreate.cs similarity index 100% rename from src/HelloShop.ProductService/EntityFrameworks/Migrations/20240419145737_InitialCreate.cs rename to src/HelloShop.ProductService/Infrastructure/Migrations/20240419145737_InitialCreate.cs diff --git a/src/HelloShop.ProductService/EntityFrameworks/Migrations/ProductServiceDbContextModelSnapshot.cs b/src/HelloShop.ProductService/Infrastructure/Migrations/ProductServiceDbContextModelSnapshot.cs similarity index 98% rename from src/HelloShop.ProductService/EntityFrameworks/Migrations/ProductServiceDbContextModelSnapshot.cs rename to src/HelloShop.ProductService/Infrastructure/Migrations/ProductServiceDbContextModelSnapshot.cs index 2554a97..7889042 100644 --- a/src/HelloShop.ProductService/EntityFrameworks/Migrations/ProductServiceDbContextModelSnapshot.cs +++ b/src/HelloShop.ProductService/Infrastructure/Migrations/ProductServiceDbContextModelSnapshot.cs @@ -1,6 +1,6 @@ // using System; -using HelloShop.ProductService.EntityFrameworks; +using HelloShop.ProductService.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; diff --git a/src/HelloShop.ProductService/EntityFrameworks/ProductServiceDbContext.cs b/src/HelloShop.ProductService/Infrastructure/ProductServiceDbContext.cs similarity index 90% rename from src/HelloShop.ProductService/EntityFrameworks/ProductServiceDbContext.cs rename to src/HelloShop.ProductService/Infrastructure/ProductServiceDbContext.cs index 9a05e06..69cfff7 100644 --- a/src/HelloShop.ProductService/EntityFrameworks/ProductServiceDbContext.cs +++ b/src/HelloShop.ProductService/Infrastructure/ProductServiceDbContext.cs @@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore; using System.Reflection; -namespace HelloShop.ProductService.EntityFrameworks; +namespace HelloShop.ProductService.Infrastructure; public class ProductServiceDbContext(DbContextOptions options) : DbContext(options) { diff --git a/src/HelloShop.ProductService/Program.cs b/src/HelloShop.ProductService/Program.cs index 1b4dc3a..cf34178 100644 --- a/src/HelloShop.ProductService/Program.cs +++ b/src/HelloShop.ProductService/Program.cs @@ -2,7 +2,7 @@ // See the license file in the project root for more information. using HelloShop.ProductService.Constants; -using HelloShop.ProductService.EntityFrameworks; +using HelloShop.ProductService.Infrastructure; using HelloShop.ServiceDefaults.Extensions; using Microsoft.EntityFrameworkCore; diff --git a/src/HelloShop.ProductService/Services/ProductService.cs b/src/HelloShop.ProductService/Services/ProductService.cs index 659e9c2..6f7db3e 100644 --- a/src/HelloShop.ProductService/Services/ProductService.cs +++ b/src/HelloShop.ProductService/Services/ProductService.cs @@ -6,7 +6,7 @@ using HelloShop.ProductService.Entities.Products; // Copyright (c) HelloShop Corporation. All rights reserved. // See the license file in the project root for more information. -using HelloShop.ProductService.EntityFrameworks; +using HelloShop.ProductService.Infrastructure; using Microsoft.EntityFrameworkCore; namespace HelloShop.ProductService.Services diff --git a/src/HelloShop.ServiceDefaults/Infrastructure/IDataSeedingProvider.cs b/src/HelloShop.ServiceDefaults/Infrastructure/IDataSeedingProvider.cs index c9c06f8..72fe0bc 100644 --- a/src/HelloShop.ServiceDefaults/Infrastructure/IDataSeedingProvider.cs +++ b/src/HelloShop.ServiceDefaults/Infrastructure/IDataSeedingProvider.cs @@ -7,6 +7,6 @@ namespace HelloShop.ServiceDefaults.Infrastructure { int Order => default; - Task SeedingAsync(IServiceProvider serviceProvider); + Task SeedingAsync(IServiceProvider serviceProvider, CancellationToken cancellationToken = default); } } diff --git a/tests/HelloShop.ProductService.FunctionalTests/Utilities/CustomWebApplicationFactory.cs b/tests/HelloShop.ProductService.FunctionalTests/Utilities/CustomWebApplicationFactory.cs index 4dbf993..e6a0a55 100644 --- a/tests/HelloShop.ProductService.FunctionalTests/Utilities/CustomWebApplicationFactory.cs +++ b/tests/HelloShop.ProductService.FunctionalTests/Utilities/CustomWebApplicationFactory.cs @@ -1,7 +1,7 @@ // Copyright (c) HelloShop Corporation. All rights reserved. // See the license file in the project root for more information. -using HelloShop.ProductService.EntityFrameworks; +using HelloShop.ProductService.Infrastructure; using HelloShop.ServiceDefaults.Authorization; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Testing; diff --git a/tests/HelloShop.ProductService.UnitTests/ProductsControllerTest.cs b/tests/HelloShop.ProductService.UnitTests/ProductsControllerTest.cs index 10db17e..3ee4ee5 100644 --- a/tests/HelloShop.ProductService.UnitTests/ProductsControllerTest.cs +++ b/tests/HelloShop.ProductService.UnitTests/ProductsControllerTest.cs @@ -3,7 +3,9 @@ using AutoMapper; using HelloShop.ProductService.AutoMapper; +using HelloShop.ProductService.Controllers; using HelloShop.ProductService.Entities.Products; +using HelloShop.ProductService.Infrastructure; using HelloShop.ProductService.Models.Products; using HelloShop.ProductService.UnitTests.Utilities; using Microsoft.AspNetCore.Mvc; @@ -16,7 +18,7 @@ namespace HelloShop.ProductService.UnitTests public async Task GetProductByIdReturnsProductDetailsResponse() { // Arrange - await using EntityFrameworks.ProductServiceDbContext dbContext = new FakeDbContextFactory().CreateDbContext(); + await using ProductServiceDbContext dbContext = new FakeDbContextFactory().CreateDbContext(); await dbContext.AddAsync(new Product { Id = 1, Name = "Product 1", Price = 10 }); @@ -40,7 +42,7 @@ namespace HelloShop.ProductService.UnitTests public async Task PostProductReturnsProductDetailsResponse(string productName, decimal price) { // Arrange - await using EntityFrameworks.ProductServiceDbContext dbContext = new FakeDbContextFactory().CreateDbContext(); + await using ProductServiceDbContext dbContext = new FakeDbContextFactory().CreateDbContext(); IMapper mapper = new MapperConfiguration(configure => configure.AddProfile()).CreateMapper(); diff --git a/tests/HelloShop.ProductService.UnitTests/Utilities/FakeDbContextFactory.cs b/tests/HelloShop.ProductService.UnitTests/Utilities/FakeDbContextFactory.cs index 1f72208..da99e87 100644 --- a/tests/HelloShop.ProductService.UnitTests/Utilities/FakeDbContextFactory.cs +++ b/tests/HelloShop.ProductService.UnitTests/Utilities/FakeDbContextFactory.cs @@ -1,7 +1,7 @@ // Copyright (c) HelloShop Corporation. All rights reserved. // See the license file in the project root for more information. -using HelloShop.ProductService.EntityFrameworks; +using HelloShop.ProductService.Infrastructure; using Microsoft.EntityFrameworkCore; namespace HelloShop.ProductService.UnitTests.Utilities