First version of Service

This commit is contained in:
2025-06-22 19:34:07 -06:00
commit e99b2c5a5a
51 changed files with 2167 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
using Core.Inventory.Application.UseCases.Inventory;
using Core.Inventory.Application.UseCases.Inventory.Adapter;
using Core.Inventory.Application.UseCases.Inventory.Input;
using Core.Inventory.Application.UseCases.Inventory.Ports;
using Core.Inventory.Application.UseCases.Inventory.Validator;
using FluentValidation;
using Lib.Architecture.BuildingBlocks;
namespace Core.Inventory.Service.API.Extensions
{
public static class ServiceCollectionExtension
{
public static IServiceCollection AddServiceConfigurationLayer(this IServiceCollection services)
{
#region FurnitureBase
services.AddScoped<IFurnitureBasePort, FurnitureBasePort>();
services.AddScoped<IComponentHandler<GetAllFurnitureBaseRequest>, InventoryHandler>();
services.AddScoped<IComponentHandler<GetFurnitureBaseByIdRequest>, InventoryHandler>();
services.AddScoped<IComponentHandler<CreateFurnitureBaseRequest>, InventoryHandler>();
services.AddScoped<IComponentHandler<UpdateFurnitureBaseRequest>, InventoryHandler>();
services.AddScoped<IComponentHandler<ChangeFurnitureBaseStatusRequest>, InventoryHandler>();
services.AddValidatorsFromAssemblyContaining<CreateFurnitureBaseValidator>();
services.AddScoped<IValidator<CreateFurnitureBaseRequest>, CreateFurnitureBaseValidator>();
services.AddValidatorsFromAssemblyContaining<UpdateFurnitureBaseValidator>();
services.AddScoped<IValidator<UpdateFurnitureBaseRequest>, UpdateFurnitureBaseValidator>();
services.AddValidatorsFromAssemblyContaining<ChangeFurnitureBaseStatusValidator>();
services.AddScoped<IValidator<ChangeFurnitureBaseStatusRequest>, ChangeFurnitureBaseStatusValidator>();
services.AddValidatorsFromAssemblyContaining<GetFurnitureBaseByIdValidator>();
services.AddScoped<IValidator<GetFurnitureBaseByIdRequest>, GetFurnitureBaseByIdValidator>();
#endregion
#region FurnitureVariant
services.AddScoped<IFurnitureVariantPort, FurnitureVariantPort>();
services.AddScoped<IComponentHandler<GetAllFurnitureVariantsByModelIdRequest>, InventoryHandler>();
services.AddScoped<IComponentHandler<GetFurnitureVariantByIdRequest>, InventoryHandler>();
services.AddScoped<IComponentHandler<CreateFurnitureVariantRequest>, InventoryHandler>();
services.AddScoped<IComponentHandler<UpdateFurnitureVariantRequest>, InventoryHandler>();
services.AddScoped<IComponentHandler<ChangeFurnitureVariantStatusRequest>, InventoryHandler>();
services.AddValidatorsFromAssemblyContaining<CreateFurnitureVariantValidator>();
services.AddScoped<IValidator<CreateFurnitureVariantRequest>, CreateFurnitureVariantValidator>();
services.AddValidatorsFromAssemblyContaining<UpdateFurnitureVariantValidator>();
services.AddScoped<IValidator<UpdateFurnitureVariantRequest>, UpdateFurnitureVariantValidator>();
services.AddValidatorsFromAssemblyContaining<ChangeFurnitureVariantStatusValidator>();
services.AddScoped<IValidator<ChangeFurnitureVariantStatusRequest>, ChangeFurnitureVariantStatusValidator>();
services.AddValidatorsFromAssemblyContaining<GetFurnitureVariantByIdValidator>();
services.AddScoped<IValidator<GetFurnitureVariantByIdRequest>, GetFurnitureVariantByIdValidator>();
services.AddValidatorsFromAssemblyContaining<GetAllFurnitureVariantsByModelIdValidator>();
services.AddScoped<IValidator<GetAllFurnitureVariantsByModelIdRequest>, GetAllFurnitureVariantsByModelIdValidator>();
#endregion
return services;
}
}
}

View File

@@ -0,0 +1,98 @@
using Asp.Versioning.ApiExplorer;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using Swashbuckle.AspNetCore.SwaggerUI;
namespace Core.Inventory.Service.API.Extensions
{
public static class SwaggerExtensions
{
public static void AddSwagger(this IServiceCollection services, IConfiguration configuration)
{
services.AddEndpointsApiExplorer();
AddSwaggerGen(services, configuration);
services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
}
/// <summary>
/// Configures Swagger generation with OAuth2 security and XML comments.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
/// <param name="configuration">The <see cref="IConfiguration"/> containing Swagger and OAuth2 configuration settings.</param>
public static void AddSwaggerGen(this IServiceCollection services, IConfiguration configuration)
{
services.AddSwaggerGen(c =>
{
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Description = "JWT Authorization header using the Bearer scheme",
Name = "Authorization",
In = ParameterLocation.Header,
Type = SecuritySchemeType.Http,
Scheme = "bearer",
BearerFormat = "JWT"
});
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "Bearer"
}
},
Array.Empty<string>()
}
});
});
}
public static void ConfigureSwagger(this WebApplication app)
{
//Swagger Stuff Goes Here
app.UseSwagger();
app.UseSwaggerUI(options =>
{
foreach (var version in app.DescribeApiVersions().Select(version => version.GroupName))
options.SwaggerEndpoint($"/swagger/{version}/swagger.json", version);
options.DisplayRequestDuration();
options.EnableTryItOutByDefault();
options.DocExpansion(DocExpansion.None);
});
}
public static IServiceCollection AddVersioning(this IServiceCollection services)
{
services.AddApiVersioning(options => options.ReportApiVersions = true)
.AddApiExplorer(options =>
{
options.GroupNameFormat = "'v'VVV";
options.SubstituteApiVersionInUrl = true;
});
return services;
}
}
public class ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) : IConfigureOptions<SwaggerGenOptions>
{
private readonly IApiVersionDescriptionProvider _provider = provider;
public void Configure(SwaggerGenOptions options)
{
foreach (var description in _provider.ApiVersionDescriptions)
options.SwaggerDoc(description.GroupName, new()
{
Title = AppDomain.CurrentDomain.FriendlyName,
Version = description.ApiVersion.ToString()
});
options.CustomSchemaIds(type => type.ToString().Replace("+", "."));
}
}
}