Generator Changes at 9/27/2025 10:36:00 AM
This commit is contained in:
64
src/FrontOffice.BFF.WebApi/Common/Mappings/GeneralMapping.cs
Normal file
64
src/FrontOffice.BFF.WebApi/Common/Mappings/GeneralMapping.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System.Globalization;
|
||||
namespace FrontOffice.BFF.WebApi.Common.Mappings;
|
||||
|
||||
public class GeneralMapping : IRegister
|
||||
{
|
||||
void IRegister.Register(TypeAdapterConfig config)
|
||||
{
|
||||
config.NewConfig<string, decimal>()
|
||||
.MapWith(src => decimal.Parse(src));
|
||||
|
||||
config.NewConfig<decimal, string>()
|
||||
.MapWith(src => src.ToString("R", new CultureInfo("en-us")));
|
||||
|
||||
config.NewConfig<decimal?, string>()
|
||||
.MapWith(src => src == null ? string.Empty : src.Value.ToString("R", new CultureInfo("en-us")));
|
||||
|
||||
config.NewConfig<string, decimal?>()
|
||||
.MapWith(src => string.IsNullOrEmpty(src) ? null : decimal.Parse(src));
|
||||
|
||||
config.NewConfig<Guid, string>()
|
||||
.MapWith(src => src == Guid.Empty ? string.Empty : src.ToString());
|
||||
|
||||
config.NewConfig<string, Guid>()
|
||||
.MapWith(src => string.IsNullOrEmpty(src) ? Guid.Empty : Guid.Parse(src));
|
||||
|
||||
config.NewConfig<string, Guid?>()
|
||||
.MapWith(src => string.IsNullOrEmpty(src) ? null : Guid.Parse(src));
|
||||
|
||||
config.NewConfig<Timestamp, DateTime>()
|
||||
.MapWith(src => src.ToDateTime());
|
||||
|
||||
config.NewConfig<Timestamp, DateTime?>()
|
||||
.MapWith(src => src == null ? null : src.ToDateTime());
|
||||
|
||||
config.NewConfig<DateTime, Timestamp>()
|
||||
.MapWith(src => Timestamp.FromDateTime(DateTime.SpecifyKind(src, DateTimeKind.Utc)));
|
||||
|
||||
config.NewConfig<DateTime?, Timestamp>()
|
||||
.MapWith(src => src.HasValue ? Timestamp.FromDateTime(DateTime.SpecifyKind(src.Value, DateTimeKind.Utc)) : null);
|
||||
|
||||
config.NewConfig<Duration, TimeSpan>()
|
||||
.MapWith(src => src.ToTimeSpan());
|
||||
|
||||
config.NewConfig<Duration, TimeSpan?>()
|
||||
.MapWith(src => src == null ? null : src.ToTimeSpan());
|
||||
|
||||
config.NewConfig<TimeSpan, Duration>()
|
||||
.MapWith(src => Duration.FromTimeSpan(src));
|
||||
|
||||
config.NewConfig<TimeSpan?, Duration>()
|
||||
.MapWith(src => src.HasValue ? Duration.FromTimeSpan(src.Value) : null);
|
||||
|
||||
config.Default
|
||||
.UseDestinationValue(member => member.SetterModifier == AccessModifier.None &&
|
||||
member.Type.IsGenericType &&
|
||||
member.Type.GetGenericTypeDefinition() == typeof(Google.Protobuf.Collections.RepeatedField<>));
|
||||
|
||||
config.NewConfig<Google.Protobuf.ByteString, byte[]>()
|
||||
.MapWith(src => src.ToByteArray());
|
||||
|
||||
config.NewConfig<byte[], Google.Protobuf.ByteString>()
|
||||
.MapWith(src => Google.Protobuf.ByteString.CopyFrom(src));
|
||||
}
|
||||
}
|
||||
10
src/FrontOffice.BFF.WebApi/Common/Mappings/PackageProfile.cs
Normal file
10
src/FrontOffice.BFF.WebApi/Common/Mappings/PackageProfile.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace FrontOffice.BFF.WebApi.Common.Mappings;
|
||||
|
||||
public class PackageProfile : IRegister
|
||||
{
|
||||
void IRegister.Register(TypeAdapterConfig config)
|
||||
{
|
||||
//config.NewConfig<Source,Destination>()
|
||||
// .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}");
|
||||
}
|
||||
}
|
||||
10
src/FrontOffice.BFF.WebApi/Common/Mappings/RoleProfile.cs
Normal file
10
src/FrontOffice.BFF.WebApi/Common/Mappings/RoleProfile.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace FrontOffice.BFF.WebApi.Common.Mappings;
|
||||
|
||||
public class RoleProfile : IRegister
|
||||
{
|
||||
void IRegister.Register(TypeAdapterConfig config)
|
||||
{
|
||||
//config.NewConfig<Source,Destination>()
|
||||
// .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace FrontOffice.BFF.WebApi.Common.Mappings;
|
||||
|
||||
public class UserAddressProfile : IRegister
|
||||
{
|
||||
void IRegister.Register(TypeAdapterConfig config)
|
||||
{
|
||||
//config.NewConfig<Source,Destination>()
|
||||
// .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace FrontOffice.BFF.WebApi.Common.Mappings;
|
||||
|
||||
public class UserOrderProfile : IRegister
|
||||
{
|
||||
void IRegister.Register(TypeAdapterConfig config)
|
||||
{
|
||||
//config.NewConfig<Source,Destination>()
|
||||
// .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}");
|
||||
}
|
||||
}
|
||||
10
src/FrontOffice.BFF.WebApi/Common/Mappings/UserProfile.cs
Normal file
10
src/FrontOffice.BFF.WebApi/Common/Mappings/UserProfile.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace FrontOffice.BFF.WebApi.Common.Mappings;
|
||||
|
||||
public class UserProfile : IRegister
|
||||
{
|
||||
void IRegister.Register(TypeAdapterConfig config)
|
||||
{
|
||||
//config.NewConfig<Source,Destination>()
|
||||
// .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace FrontOffice.BFF.WebApi.Common.Mappings;
|
||||
|
||||
public class UserRoleProfile : IRegister
|
||||
{
|
||||
void IRegister.Register(TypeAdapterConfig config)
|
||||
{
|
||||
//config.NewConfig<Source,Destination>()
|
||||
// .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using FrontOffice.BFF.Application.Common.Interfaces;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace FrontOffice.BFF.WebApi.Common.Services;
|
||||
|
||||
public class AppTokenProvider : ITokenProvider
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private string? _token;
|
||||
|
||||
public AppTokenProvider(IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
public async Task<string> GetTokenAsync()
|
||||
{
|
||||
if (_token != null)
|
||||
{
|
||||
return _token;
|
||||
}
|
||||
|
||||
// get token string
|
||||
var authorizationToken = _httpContextAccessor.HttpContext?.Request.Headers[HeaderNames.Authorization];
|
||||
|
||||
if (!string.IsNullOrEmpty(authorizationToken))
|
||||
_token = authorizationToken.ToString().Replace("Bearer ", "");
|
||||
|
||||
return _token;
|
||||
|
||||
// return await Task.FromResult(GetToken()) ?? string.Empty;
|
||||
}
|
||||
|
||||
private string? GetToken()
|
||||
{
|
||||
if (_token != null) return _token;
|
||||
|
||||
// get token string
|
||||
var authorizationToken = _httpContextAccessor.HttpContext?.Request.Headers[HeaderNames.Authorization];
|
||||
if (authorizationToken is null) return _token;
|
||||
|
||||
var token = authorizationToken.Value.ToString();
|
||||
if (string.IsNullOrEmpty(token)) return _token;
|
||||
|
||||
_token = token;
|
||||
|
||||
return _token;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Security.Claims;
|
||||
using FrontOffice.BFF.Application.Common.Interfaces;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace FrontOffice.BFF.WebApi.Common.Services;
|
||||
|
||||
public class CurrentUserService : ICurrentUserService
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public CurrentUserService(IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
public string? UserId => _httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
namespace FrontOffice.BFF.WebApi.Common.Services;
|
||||
public interface IDispatchRequestToCQRS
|
||||
{
|
||||
Task<TResponse> Handle<TRequest, TCommand, TResponse>(TRequest request,
|
||||
ServerCallContext context);
|
||||
Task<Empty> Handle<TRequest, TCommand>(TRequest request,
|
||||
ServerCallContext context);
|
||||
Task<TResponse> Handle<TCommand, TResponse>(ServerCallContext context);
|
||||
}
|
||||
public class DispatchRequestToCQRS : IDispatchRequestToCQRS
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
|
||||
public DispatchRequestToCQRS(ISender sender)
|
||||
{
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
public async Task<TResponse> Handle<TRequest, TCommand, TResponse>(TRequest request,
|
||||
ServerCallContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (request is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
var cqrsInput = request.Adapt<TCommand>();
|
||||
|
||||
if (cqrsInput is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(cqrsInput));
|
||||
}
|
||||
|
||||
var output = await _sender.Send(cqrsInput, context.CancellationToken);
|
||||
return (output ?? throw new InvalidOperationException()).Adapt<TResponse>();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public async Task<TResponse> Handle<TCommand, TResponse>(ServerCallContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
var cqrsInput = Activator.CreateInstance<TCommand>();
|
||||
if (cqrsInput is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(cqrsInput));
|
||||
}
|
||||
|
||||
var output = await _sender.Send(cqrsInput, context.CancellationToken);
|
||||
return (output ?? throw new InvalidOperationException()).Adapt<TResponse>();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public async Task<Empty> Handle<TRequest, TCommand>(TRequest request,
|
||||
ServerCallContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (request is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
var cqrsInput = request.Adapt<TCommand>();
|
||||
|
||||
if (cqrsInput is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(cqrsInput));
|
||||
}
|
||||
|
||||
await _sender.Send(cqrsInput, context.CancellationToken);
|
||||
return new Empty();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
68
src/FrontOffice.BFF.WebApi/ConfigureServices.cs
Normal file
68
src/FrontOffice.BFF.WebApi/ConfigureServices.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using FrontOffice.BFF.Application.Common.Interfaces;
|
||||
using FrontOffice.BFF.WebApi.Common.Services;
|
||||
using MapsterMapper;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
public static class ConfigureServices
|
||||
{
|
||||
public static IServiceCollection AddPresentationServices(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddMapping();
|
||||
services.AddHttpContextAccessor();
|
||||
services.AddTransient<ICurrentUserService, CurrentUserService>();
|
||||
services.AddTransient<ITokenProvider, AppTokenProvider>();
|
||||
services.AddScoped<IDispatchRequestToCQRS, DispatchRequestToCQRS>();
|
||||
return services;
|
||||
}
|
||||
|
||||
private static IServiceCollection AddMapping(this IServiceCollection services)
|
||||
{
|
||||
var typeAdapterConfig = TypeAdapterConfig.GlobalSettings;
|
||||
// scans the assembly and gets the IRegister, adding the registration to the TypeAdapterConfig
|
||||
typeAdapterConfig.Scan(Assembly.GetExecutingAssembly());
|
||||
// register the mapper as Singleton service for my application
|
||||
var mapperConfig = new Mapper(typeAdapterConfig);
|
||||
services.AddSingleton<IMapper>(mapperConfig);
|
||||
return services;
|
||||
}
|
||||
|
||||
// get all grpc endpoint that end with "Service" in specified assembly and register them as grpc client
|
||||
public static WebApplication ConfigureGrpcEndpoints(this WebApplication app, Assembly? assembly = null,
|
||||
Action<IEndpointRouteBuilder>? configure = null)
|
||||
{
|
||||
if (assembly is not null)
|
||||
{
|
||||
var assemblyName = assembly.GetName().Name;
|
||||
var grpcServices = assembly.GetTypes()
|
||||
// check name and type
|
||||
.Where(t => t.Name.EndsWith("Service") && t.IsClass)
|
||||
// check folder by assembly qualified name
|
||||
.Where(t => t.AssemblyQualifiedName != null &&
|
||||
t.AssemblyQualifiedName.Contains($"{assemblyName}.Services"))
|
||||
// check parent name ends with "ContractBase"
|
||||
.Where(t => t.BaseType?.Name.EndsWith("ContractBase") == true)
|
||||
.ToList();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
foreach (var service in grpcServices)
|
||||
{
|
||||
// how to use type as generic parameter in csharp?
|
||||
// https://stackoverflow.com/questions/3957817/calling-generic-method-with-type-variable
|
||||
var method = typeof(GrpcEndpointRouteBuilderExtensions).GetMethod("MapGrpcService");
|
||||
var generic = method?.MakeGenericMethod(service);
|
||||
generic?.Invoke(null, new object[] { endpoints });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (configure is not null)
|
||||
{
|
||||
app.UseEndpoints(configure.Invoke);
|
||||
}
|
||||
|
||||
return app;
|
||||
}
|
||||
}
|
||||
32
src/FrontOffice.BFF.WebApi/FrontOffice.BFF.WebApi.csproj
Normal file
32
src/FrontOffice.BFF.WebApi/FrontOffice.BFF.WebApi.csproj
Normal file
@@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<DockerfileContext>..\..\..</DockerfileContext>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Grpc.AspNetCore" Version="2.54.0" />
|
||||
<PackageReference Include="Grpc.AspNetCore.Web" Version="2.54.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Grpc.Swagger" Version="0.3.8" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="6.3.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Seq" Version="5.2.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FrontOffice.BFF.Application\FrontOffice.BFF.Application.csproj" />
|
||||
<ProjectReference Include="..\FrontOffice.BFF.Infrastructure\FrontOffice.BFF.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Protobufs\FrontOffice.BFF.User.Protobuf\FrontOffice.BFF.User.Protobuf.csproj" />
|
||||
<ProjectReference Include="..\Protobufs\FrontOffice.BFF.UserAddress.Protobuf\FrontOffice.BFF.UserAddress.Protobuf.csproj" />
|
||||
<ProjectReference Include="..\Protobufs\FrontOffice.BFF.Package.Protobuf\FrontOffice.BFF.Package.Protobuf.csproj" />
|
||||
<ProjectReference Include="..\Protobufs\FrontOffice.BFF.UserOrder.Protobuf\FrontOffice.BFF.UserOrder.Protobuf.csproj" />
|
||||
<ProjectReference Include="..\Protobufs\FrontOffice.BFF.Role.Protobuf\FrontOffice.BFF.Role.Protobuf.csproj" />
|
||||
<ProjectReference Include="..\Protobufs\FrontOffice.BFF.UserRole.Protobuf\FrontOffice.BFF.UserRole.Protobuf.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
11
src/FrontOffice.BFF.WebApi/GlobalUsings.cs
Normal file
11
src/FrontOffice.BFF.WebApi/GlobalUsings.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
global using Google.Protobuf.WellKnownTypes;
|
||||
global using Grpc.Core;
|
||||
global using Mapster;
|
||||
global using MediatR;
|
||||
global using Microsoft.AspNetCore.Authorization;
|
||||
global using Microsoft.AspNetCore.Http;
|
||||
global using System.Threading.Tasks;
|
||||
global using Microsoft.AspNetCore.Builder;
|
||||
global using System;
|
||||
global using Microsoft.AspNetCore.Routing;
|
||||
global using System.Linq;
|
||||
109
src/FrontOffice.BFF.WebApi/Program.cs
Normal file
109
src/FrontOffice.BFF.WebApi/Program.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using Serilog;
|
||||
using Serilog.Core;
|
||||
using Serilog.Sinks.MSSqlServer;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
builder.WebHost.ConfigureKestrel(options =>
|
||||
{
|
||||
// Setup a HTTP/2 endpoint without TLS.
|
||||
options.ListenLocalhost(5000, o => o.Protocols =
|
||||
HttpProtocols.Http2);
|
||||
});
|
||||
}
|
||||
|
||||
var levelSwitch = new LoggingLevelSwitch();
|
||||
var logger = new LoggerConfiguration()
|
||||
//.WriteTo.Console()
|
||||
.WriteTo.MSSqlServer(builder.Configuration.GetConnectionString("LogConnection"),
|
||||
sinkOptions: new MSSqlServerSinkOptions
|
||||
{
|
||||
TableName = "Log_FrontOffice_BFF_WebApi_Events",
|
||||
SchemaName = "Log",
|
||||
AutoCreateSqlTable = true
|
||||
})
|
||||
/* .WriteTo.Seq("http://localhost:5341",
|
||||
apiKey: "IeEfKjIMoCGLljdp9e7A",
|
||||
controlLevelSwitch: levelSwitch)*/
|
||||
.CreateLogger();
|
||||
builder.Logging.AddSerilog(logger);
|
||||
#if DEBUG
|
||||
Serilog.Debugging.SelfLog.Enable(msg => Console.WriteLine(msg));
|
||||
#endif
|
||||
// Additional configuration is required to successfully run gRPC on macOS.
|
||||
// For instructions on how to configure Kestrel and gRPC clients on macOS, visit https://go.microsoft.com/fwlink/?linkid=2099682
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddGrpc(options =>
|
||||
{
|
||||
options.EnableDetailedErrors = true;
|
||||
options.MaxReceiveMessageSize = 1000 * 1024 * 1024; // 1 GB
|
||||
options.MaxSendMessageSize = 1000 * 1024 * 1024; // 1 GB
|
||||
}).AddJsonTranscoding();
|
||||
builder.Services.AddInfrastructureServices(builder.Configuration);
|
||||
builder.Services.AddApplicationServices();
|
||||
builder.Services.AddPresentationServices(builder.Configuration);
|
||||
|
||||
#region Configure Cors
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAll",
|
||||
builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().WithExposedHeaders("Grpc-Status",
|
||||
"Grpc-Message", "Grpc-Encoding", "Grpc-Accept-Encoding", "validation-errors-text"));
|
||||
});
|
||||
|
||||
#endregion
|
||||
builder.Services.AddGrpcSwagger();
|
||||
builder.Services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "gRPC transcoding", Version = "v1" });
|
||||
c.CustomSchemaIds(type=>type.ToString());
|
||||
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
||||
{
|
||||
In = ParameterLocation.Header,
|
||||
Description = "Please insert JWT with Bearer into field",
|
||||
Name = "Authorization",
|
||||
Type = SecuritySchemeType.ApiKey
|
||||
});
|
||||
c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||
{
|
||||
{
|
||||
new OpenApiSecurityScheme
|
||||
{
|
||||
Reference = new OpenApiReference
|
||||
{
|
||||
Type = ReferenceType.SecurityScheme,
|
||||
Id = "Bearer"
|
||||
}
|
||||
},
|
||||
new string[] { }
|
||||
}
|
||||
});
|
||||
});
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseRouting();
|
||||
app.UseCors("AllowAll");
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.UseGrpcWeb(new GrpcWebOptions { DefaultEnabled = true }); // Configure the HTTP request pipeline.
|
||||
app.ConfigureGrpcEndpoints(Assembly.GetExecutingAssembly(), endpoints =>
|
||||
{
|
||||
// endpoints.MapGrpcService<ProductService>();
|
||||
});
|
||||
app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
|
||||
});
|
||||
app.Run();
|
||||
37
src/FrontOffice.BFF.WebApi/Services/PackageService.cs
Normal file
37
src/FrontOffice.BFF.WebApi/Services/PackageService.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using FrontOffice.BFF.Package.Protobuf.Protos.Package;
|
||||
using FrontOffice.BFF.WebApi.Common.Services;
|
||||
using FrontOffice.BFF.Application.PackageCQ.Commands.CreateNewPackage;
|
||||
using FrontOffice.BFF.Application.PackageCQ.Commands.UpdatePackage;
|
||||
using FrontOffice.BFF.Application.PackageCQ.Commands.DeletePackage;
|
||||
using FrontOffice.BFF.Application.PackageCQ.Queries.GetPackage;
|
||||
using FrontOffice.BFF.Application.PackageCQ.Queries.GetAllPackageByFilter;
|
||||
namespace FrontOffice.BFF.WebApi.Services;
|
||||
public class PackageService : PackageContract.PackageContractBase
|
||||
{
|
||||
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
|
||||
|
||||
public PackageService(IDispatchRequestToCQRS dispatchRequestToCQRS)
|
||||
{
|
||||
_dispatchRequestToCQRS = dispatchRequestToCQRS;
|
||||
}
|
||||
public override async Task<CreateNewPackageResponse> CreateNewPackage(CreateNewPackageRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<CreateNewPackageRequest, CreateNewPackageCommand, CreateNewPackageResponse>(request, context);
|
||||
}
|
||||
public override async Task<Empty> UpdatePackage(UpdatePackageRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<UpdatePackageRequest, UpdatePackageCommand>(request, context);
|
||||
}
|
||||
public override async Task<Empty> DeletePackage(DeletePackageRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<DeletePackageRequest, DeletePackageCommand>(request, context);
|
||||
}
|
||||
public override async Task<GetPackageResponse> GetPackage(GetPackageRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetPackageRequest, GetPackageQuery, GetPackageResponse>(request, context);
|
||||
}
|
||||
public override async Task<GetAllPackageByFilterResponse> GetAllPackageByFilter(GetAllPackageByFilterRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetAllPackageByFilterRequest, GetAllPackageByFilterQuery, GetAllPackageByFilterResponse>(request, context);
|
||||
}
|
||||
}
|
||||
37
src/FrontOffice.BFF.WebApi/Services/RoleService.cs
Normal file
37
src/FrontOffice.BFF.WebApi/Services/RoleService.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using FrontOffice.BFF.Role.Protobuf.Protos.Role;
|
||||
using FrontOffice.BFF.WebApi.Common.Services;
|
||||
using FrontOffice.BFF.Application.RoleCQ.Commands.CreateNewRole;
|
||||
using FrontOffice.BFF.Application.RoleCQ.Commands.UpdateRole;
|
||||
using FrontOffice.BFF.Application.RoleCQ.Commands.DeleteRole;
|
||||
using FrontOffice.BFF.Application.RoleCQ.Queries.GetRole;
|
||||
using FrontOffice.BFF.Application.RoleCQ.Queries.GetAllRoleByFilter;
|
||||
namespace FrontOffice.BFF.WebApi.Services;
|
||||
public class RoleService : RoleContract.RoleContractBase
|
||||
{
|
||||
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
|
||||
|
||||
public RoleService(IDispatchRequestToCQRS dispatchRequestToCQRS)
|
||||
{
|
||||
_dispatchRequestToCQRS = dispatchRequestToCQRS;
|
||||
}
|
||||
public override async Task<CreateNewRoleResponse> CreateNewRole(CreateNewRoleRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<CreateNewRoleRequest, CreateNewRoleCommand, CreateNewRoleResponse>(request, context);
|
||||
}
|
||||
public override async Task<Empty> UpdateRole(UpdateRoleRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<UpdateRoleRequest, UpdateRoleCommand>(request, context);
|
||||
}
|
||||
public override async Task<Empty> DeleteRole(DeleteRoleRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<DeleteRoleRequest, DeleteRoleCommand>(request, context);
|
||||
}
|
||||
public override async Task<GetRoleResponse> GetRole(GetRoleRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetRoleRequest, GetRoleQuery, GetRoleResponse>(request, context);
|
||||
}
|
||||
public override async Task<GetAllRoleByFilterResponse> GetAllRoleByFilter(GetAllRoleByFilterRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetAllRoleByFilterRequest, GetAllRoleByFilterQuery, GetAllRoleByFilterResponse>(request, context);
|
||||
}
|
||||
}
|
||||
37
src/FrontOffice.BFF.WebApi/Services/UserAddressService.cs
Normal file
37
src/FrontOffice.BFF.WebApi/Services/UserAddressService.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using FrontOffice.BFF.UserAddress.Protobuf.Protos.UserAddress;
|
||||
using FrontOffice.BFF.WebApi.Common.Services;
|
||||
using FrontOffice.BFF.Application.UserAddressCQ.Commands.CreateNewUserAddress;
|
||||
using FrontOffice.BFF.Application.UserAddressCQ.Commands.UpdateUserAddress;
|
||||
using FrontOffice.BFF.Application.UserAddressCQ.Commands.DeleteUserAddress;
|
||||
using FrontOffice.BFF.Application.UserAddressCQ.Queries.GetUserAddress;
|
||||
using FrontOffice.BFF.Application.UserAddressCQ.Queries.GetAllUserAddressByFilter;
|
||||
namespace FrontOffice.BFF.WebApi.Services;
|
||||
public class UserAddressService : UserAddressContract.UserAddressContractBase
|
||||
{
|
||||
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
|
||||
|
||||
public UserAddressService(IDispatchRequestToCQRS dispatchRequestToCQRS)
|
||||
{
|
||||
_dispatchRequestToCQRS = dispatchRequestToCQRS;
|
||||
}
|
||||
public override async Task<CreateNewUserAddressResponse> CreateNewUserAddress(CreateNewUserAddressRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<CreateNewUserAddressRequest, CreateNewUserAddressCommand, CreateNewUserAddressResponse>(request, context);
|
||||
}
|
||||
public override async Task<Empty> UpdateUserAddress(UpdateUserAddressRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<UpdateUserAddressRequest, UpdateUserAddressCommand>(request, context);
|
||||
}
|
||||
public override async Task<Empty> DeleteUserAddress(DeleteUserAddressRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<DeleteUserAddressRequest, DeleteUserAddressCommand>(request, context);
|
||||
}
|
||||
public override async Task<GetUserAddressResponse> GetUserAddress(GetUserAddressRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetUserAddressRequest, GetUserAddressQuery, GetUserAddressResponse>(request, context);
|
||||
}
|
||||
public override async Task<GetAllUserAddressByFilterResponse> GetAllUserAddressByFilter(GetAllUserAddressByFilterRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetAllUserAddressByFilterRequest, GetAllUserAddressByFilterQuery, GetAllUserAddressByFilterResponse>(request, context);
|
||||
}
|
||||
}
|
||||
37
src/FrontOffice.BFF.WebApi/Services/UserOrderService.cs
Normal file
37
src/FrontOffice.BFF.WebApi/Services/UserOrderService.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using FrontOffice.BFF.UserOrder.Protobuf.Protos.UserOrder;
|
||||
using FrontOffice.BFF.WebApi.Common.Services;
|
||||
using FrontOffice.BFF.Application.UserOrderCQ.Commands.CreateNewUserOrder;
|
||||
using FrontOffice.BFF.Application.UserOrderCQ.Commands.UpdateUserOrder;
|
||||
using FrontOffice.BFF.Application.UserOrderCQ.Commands.DeleteUserOrder;
|
||||
using FrontOffice.BFF.Application.UserOrderCQ.Queries.GetUserOrder;
|
||||
using FrontOffice.BFF.Application.UserOrderCQ.Queries.GetAllUserOrderByFilter;
|
||||
namespace FrontOffice.BFF.WebApi.Services;
|
||||
public class UserOrderService : UserOrderContract.UserOrderContractBase
|
||||
{
|
||||
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
|
||||
|
||||
public UserOrderService(IDispatchRequestToCQRS dispatchRequestToCQRS)
|
||||
{
|
||||
_dispatchRequestToCQRS = dispatchRequestToCQRS;
|
||||
}
|
||||
public override async Task<CreateNewUserOrderResponse> CreateNewUserOrder(CreateNewUserOrderRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<CreateNewUserOrderRequest, CreateNewUserOrderCommand, CreateNewUserOrderResponse>(request, context);
|
||||
}
|
||||
public override async Task<Empty> UpdateUserOrder(UpdateUserOrderRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<UpdateUserOrderRequest, UpdateUserOrderCommand>(request, context);
|
||||
}
|
||||
public override async Task<Empty> DeleteUserOrder(DeleteUserOrderRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<DeleteUserOrderRequest, DeleteUserOrderCommand>(request, context);
|
||||
}
|
||||
public override async Task<GetUserOrderResponse> GetUserOrder(GetUserOrderRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetUserOrderRequest, GetUserOrderQuery, GetUserOrderResponse>(request, context);
|
||||
}
|
||||
public override async Task<GetAllUserOrderByFilterResponse> GetAllUserOrderByFilter(GetAllUserOrderByFilterRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetAllUserOrderByFilterRequest, GetAllUserOrderByFilterQuery, GetAllUserOrderByFilterResponse>(request, context);
|
||||
}
|
||||
}
|
||||
37
src/FrontOffice.BFF.WebApi/Services/UserRoleService.cs
Normal file
37
src/FrontOffice.BFF.WebApi/Services/UserRoleService.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using FrontOffice.BFF.UserRole.Protobuf.Protos.UserRole;
|
||||
using FrontOffice.BFF.WebApi.Common.Services;
|
||||
using FrontOffice.BFF.Application.UserRoleCQ.Commands.CreateNewUserRole;
|
||||
using FrontOffice.BFF.Application.UserRoleCQ.Commands.UpdateUserRole;
|
||||
using FrontOffice.BFF.Application.UserRoleCQ.Commands.DeleteUserRole;
|
||||
using FrontOffice.BFF.Application.UserRoleCQ.Queries.GetUserRole;
|
||||
using FrontOffice.BFF.Application.UserRoleCQ.Queries.GetAllUserRoleByFilter;
|
||||
namespace FrontOffice.BFF.WebApi.Services;
|
||||
public class UserRoleService : UserRoleContract.UserRoleContractBase
|
||||
{
|
||||
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
|
||||
|
||||
public UserRoleService(IDispatchRequestToCQRS dispatchRequestToCQRS)
|
||||
{
|
||||
_dispatchRequestToCQRS = dispatchRequestToCQRS;
|
||||
}
|
||||
public override async Task<CreateNewUserRoleResponse> CreateNewUserRole(CreateNewUserRoleRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<CreateNewUserRoleRequest, CreateNewUserRoleCommand, CreateNewUserRoleResponse>(request, context);
|
||||
}
|
||||
public override async Task<Empty> UpdateUserRole(UpdateUserRoleRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<UpdateUserRoleRequest, UpdateUserRoleCommand>(request, context);
|
||||
}
|
||||
public override async Task<Empty> DeleteUserRole(DeleteUserRoleRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<DeleteUserRoleRequest, DeleteUserRoleCommand>(request, context);
|
||||
}
|
||||
public override async Task<GetUserRoleResponse> GetUserRole(GetUserRoleRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetUserRoleRequest, GetUserRoleQuery, GetUserRoleResponse>(request, context);
|
||||
}
|
||||
public override async Task<GetAllUserRoleByFilterResponse> GetAllUserRoleByFilter(GetAllUserRoleByFilterRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetAllUserRoleByFilterRequest, GetAllUserRoleByFilterQuery, GetAllUserRoleByFilterResponse>(request, context);
|
||||
}
|
||||
}
|
||||
37
src/FrontOffice.BFF.WebApi/Services/UserService.cs
Normal file
37
src/FrontOffice.BFF.WebApi/Services/UserService.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using FrontOffice.BFF.User.Protobuf.Protos.User;
|
||||
using FrontOffice.BFF.WebApi.Common.Services;
|
||||
using FrontOffice.BFF.Application.UserCQ.Commands.CreateNewUser;
|
||||
using FrontOffice.BFF.Application.UserCQ.Commands.UpdateUser;
|
||||
using FrontOffice.BFF.Application.UserCQ.Commands.DeleteUser;
|
||||
using FrontOffice.BFF.Application.UserCQ.Queries.GetUser;
|
||||
using FrontOffice.BFF.Application.UserCQ.Queries.GetAllUserByFilter;
|
||||
namespace FrontOffice.BFF.WebApi.Services;
|
||||
public class UserService : UserContract.UserContractBase
|
||||
{
|
||||
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
|
||||
|
||||
public UserService(IDispatchRequestToCQRS dispatchRequestToCQRS)
|
||||
{
|
||||
_dispatchRequestToCQRS = dispatchRequestToCQRS;
|
||||
}
|
||||
public override async Task<CreateNewUserResponse> CreateNewUser(CreateNewUserRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<CreateNewUserRequest, CreateNewUserCommand, CreateNewUserResponse>(request, context);
|
||||
}
|
||||
public override async Task<Empty> UpdateUser(UpdateUserRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<UpdateUserRequest, UpdateUserCommand>(request, context);
|
||||
}
|
||||
public override async Task<Empty> DeleteUser(DeleteUserRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<DeleteUserRequest, DeleteUserCommand>(request, context);
|
||||
}
|
||||
public override async Task<GetUserResponse> GetUser(GetUserRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetUserRequest, GetUserQuery, GetUserResponse>(request, context);
|
||||
}
|
||||
public override async Task<GetAllUserByFilterResponse> GetAllUserByFilter(GetAllUserByFilterRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetAllUserByFilterRequest, GetAllUserByFilterQuery, GetAllUserByFilterResponse>(request, context);
|
||||
}
|
||||
}
|
||||
10
src/FrontOffice.BFF.WebApi/appsettings.Development.json
Normal file
10
src/FrontOffice.BFF.WebApi/appsettings.Development.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Grpc": "Information",
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/FrontOffice.BFF.WebApi/appsettings.json
Normal file
19
src/FrontOffice.BFF.WebApi/appsettings.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"AllowedHosts": "*",
|
||||
"Kestrel": {
|
||||
"EndpointDefaults": {
|
||||
"Protocols": "Http2"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"LogConnection": "Data Source=.,2019; Initial Catalog=DBName;User ID=dbuser;Password=dbpassword;Connection Timeout=300000;MultipleActiveResultSets=True;Encrypt=False",
|
||||
"providerName": "System.Data.SqlClient"
|
||||
},
|
||||
"GrpcChannelOptions": {
|
||||
//"FileManagementMSAddress": "https://localhost:31307"
|
||||
},
|
||||
"Authentication": {
|
||||
"Authority": "https://ids.domain.com/",
|
||||
"Audience": "domain_api"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user