diff --git a/src/HelloShop.AppHost/Extensions/DaprSidecarResourceBuilderExtensions.cs b/src/HelloShop.AppHost/Extensions/DaprSidecarResourceBuilderExtensions.cs index 1ede3b2..7b31e03 100644 --- a/src/HelloShop.AppHost/Extensions/DaprSidecarResourceBuilderExtensions.cs +++ b/src/HelloShop.AppHost/Extensions/DaprSidecarResourceBuilderExtensions.cs @@ -13,7 +13,7 @@ namespace HelloShop.AppHost.Extensions { public static class DaprSidecarResourceBuilderExtensions { - public static IResourceBuilder WithReference(this IResourceBuilder builder, IResourceBuilder resourceBuilder, int waitInSeconds = 5) + public static IResourceBuilder WithReference(this IResourceBuilder builder, IResourceBuilder resourceBuilder, int waitInSeconds = 10) { builder.WithAnnotation(new EnvironmentCallbackAnnotation(async context => { diff --git a/src/HelloShop.IdentityService/DataSeeding/UserDataSeedingProvider.cs b/src/HelloShop.IdentityService/DataSeeding/UserDataSeedingProvider.cs index bc348a7..1e1d1de 100644 --- a/src/HelloShop.IdentityService/DataSeeding/UserDataSeedingProvider.cs +++ b/src/HelloShop.IdentityService/DataSeeding/UserDataSeedingProvider.cs @@ -2,16 +2,20 @@ // See the license file in the project root for more information. using HelloShop.IdentityService.Entities; +using HelloShop.IdentityService.Infrastructure; using HelloShop.ServiceDefaults.Infrastructure; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; namespace HelloShop.IdentityService.DataSeeding { public class UserDataSeedingProvider(UserManager userManager, RoleManager roleManager) : IDataSeedingProvider { - public async Task SeedingAsync(IServiceProvider ServiceProvider, CancellationToken cancellationToken = default) + public async Task SeedingAsync(IServiceProvider serviceProvider, CancellationToken cancellationToken = default) { + await serviceProvider.GetRequiredService().Database.EnsureCreatedAsync(cancellationToken); + var adminRole = await roleManager.Roles.SingleOrDefaultAsync(x => x.Name == "AdminRole", cancellationToken); if (adminRole == null) diff --git a/src/HelloShop.IdentityService/Infrastructure/IdentityServiceDbContext.cs b/src/HelloShop.IdentityService/Infrastructure/IdentityServiceDbContext.cs index 1269915..a7b4fbc 100644 --- a/src/HelloShop.IdentityService/Infrastructure/IdentityServiceDbContext.cs +++ b/src/HelloShop.IdentityService/Infrastructure/IdentityServiceDbContext.cs @@ -15,9 +15,6 @@ namespace HelloShop.IdentityService.Infrastructure base.OnModelCreating(modelBuilder); modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); - - AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); - AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true); } } } diff --git a/src/HelloShop.OrderingService/AutoMapper/OrdersMapConfiguration.cs b/src/HelloShop.OrderingService/AutoMapper/OrdersMapConfiguration.cs index f46077a..0ac190b 100644 --- a/src/HelloShop.OrderingService/AutoMapper/OrdersMapConfiguration.cs +++ b/src/HelloShop.OrderingService/AutoMapper/OrdersMapConfiguration.cs @@ -3,6 +3,7 @@ using AutoMapper; using HelloShop.OrderingService.Commands.Orders; +using HelloShop.OrderingService.Entities.Orders; using HelloShop.OrderingService.Models.Orders; namespace HelloShop.OrderingService.AutoMapper @@ -11,8 +12,10 @@ namespace HelloShop.OrderingService.AutoMapper { public OrdersMapConfiguration() { - CreateMap().ForMember(dest => dest.Units, opts => opts.MapFrom(src => src.Quantity)); CreateMap().ForMember(dest => dest.OrderItems, opt => opt.MapFrom(src => src.Items)); + CreateMap().ForMember(dest => dest.Units, opt => opt.MapFrom(src => src.Quantity)); + CreateMap(); + CreateMap(); } } } diff --git a/src/HelloShop.OrderingService/Extensions/Extensions.cs b/src/HelloShop.OrderingService/Extensions/Extensions.cs index 53253d0..d09af82 100644 --- a/src/HelloShop.OrderingService/Extensions/Extensions.cs +++ b/src/HelloShop.OrderingService/Extensions/Extensions.cs @@ -10,7 +10,9 @@ using HelloShop.ServiceDefaults.DistributedEvents.Abstractions; using HelloShop.ServiceDefaults.DistributedEvents.DaprBuildingBlocks; using HelloShop.ServiceDefaults.Extensions; using Microsoft.EntityFrameworkCore; +using Microsoft.IdentityModel.Tokens; using System.Reflection; +using System.Text; namespace HelloShop.OrderingService.Extensions { @@ -18,6 +20,17 @@ namespace HelloShop.OrderingService.Extensions { public static void AddApplicationServices(this IHostApplicationBuilder builder) { + const string issuerSigningKey = ServiceDefaults.Constants.IdentityConstants.IssuerSigningKey; + + builder.Services.AddAuthentication().AddJwtBearer(options => + { + options.TokenValidationParameters.ValidateIssuer = false; + options.TokenValidationParameters.ValidateAudience = false; + options.TokenValidationParameters.IssuerSigningKey = new SymmetricSecurityKey(Encoding.Default.GetBytes(issuerSigningKey)); + }); + + builder.Services.AddHttpContextAccessor(); + builder.Services.AddDataSeedingProviders(); builder.Services.AddDbContext(options => @@ -30,9 +43,9 @@ namespace HelloShop.OrderingService.Extensions builder.Services.AddMediatR(options => { options.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()); - options.AddBehavior(typeof(LoggingBehavior<,>)); - options.AddBehavior(typeof(ValidatorBehavior<,>)); - options.AddBehavior(typeof(TransactionBehavior<,>)); + options.AddOpenBehavior(typeof(LoggingBehavior<,>)); + options.AddOpenBehavior(typeof(ValidatorBehavior<,>)); + options.AddOpenBehavior(typeof(TransactionBehavior<,>)); }); builder.Services.AddModelMapper().AddModelValidator(); @@ -50,10 +63,14 @@ namespace HelloShop.OrderingService.Extensions builder.Services.AddHostedService(); builder.Services.AddTransient>(); + + builder.Services.AddOpenApi(); } public static WebApplication MapApplicationEndpoints(this WebApplication app) { + app.UseCors(options => options.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); + app.UseOpenApi(); app.UseDataSeedingProviders(); app.MapDaprDistributedEventBus(); diff --git a/src/HelloShop.OrderingService/HelloShop.OrderingService.http b/src/HelloShop.OrderingService/HelloShop.OrderingService.http index 10f409f..b767d74 100644 --- a/src/HelloShop.OrderingService/HelloShop.OrderingService.http +++ b/src/HelloShop.OrderingService/HelloShop.OrderingService.http @@ -1,6 +1,37 @@ -@HelloShop.OrderingService_HostAddress = http://localhost:5015 +@HelloShop.OrderingService_HostAddress = https://localhost:8105 -GET {{HelloShop.OrderingService_HostAddress}}/weatherforecast/ -Accept: application/json +POST {{HelloShop.OrderingService_HostAddress}}/api/orders +Content-Type: application/json +x-request-id: 5ddc1737-6a31-4b4f-bccd-63d0966348a1 +Authorization : Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxIiwidW5pcXVlX25hbWUiOiJhZG1pbiIsInJvbGVpZCI6IjEiLCJuYmYiOjE3MjA1NzY3NDYsImV4cCI6MTc0MjYwODc0NiwiaWF0IjoxNzIwNTc2NzQ2fQ.ju_D3zeGLKqJYVckbb8Y3yNkp40nOqRAJrdOsISs4d4 -### +{ + "country": "USA", + "state": "CA", + "city": "San Francisco", + "street": "123 Market St", + "zipCode": "941032", + "cardAlias": "Jack", + "cardNumber": "4111111111111111", + "cardHolderName": "John Doe", + "cardSecurityNumber": "123456", + "cardExpiration": "2025-12-31T23:59:59Z", + "items": [ + { + "productId": 100, + "productName": "Smartphone", + "quantity": 1, + "unitPrice": 699.99, + "pictureUrl": "https://example.com/images/phone-123.jpg" + }, + { + "productId": 101, + "productName": "Tablet", + "quantity": 2, + "unitPrice": 499.99, + "pictureUrl": "https://example.com/images/tablet-456.jpg" + } + ] +} + +### \ No newline at end of file diff --git a/src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/ProductEntityTypeConfiguration.cs b/src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/ProductEntityTypeConfiguration.cs index e14cb02..eee4494 100644 --- a/src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/ProductEntityTypeConfiguration.cs +++ b/src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/ProductEntityTypeConfiguration.cs @@ -13,7 +13,7 @@ public class ProductEntityTypeConfiguration : IEntityTypeConfiguration { builder.ToTable("Products"); - builder.Property(x => x.Name).HasMaxLength(32); + builder.Property(x => x.Name).HasMaxLength(64); builder.Property(x => x.ImageUrl).HasMaxLength(256);