commit 658e3f4277c764844f98b7c283620dbe5a200106 Author: Ignacio Gomez Date: Sun Jun 22 04:38:36 2025 -0600 First version of DAL diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9491a2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,363 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Oo]ut/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd \ No newline at end of file diff --git a/Core.Inventory.DAL.API/Controllers/FurnitureBaseController.cs b/Core.Inventory.DAL.API/Controllers/FurnitureBaseController.cs new file mode 100644 index 0000000..25549b7 --- /dev/null +++ b/Core.Inventory.DAL.API/Controllers/FurnitureBaseController.cs @@ -0,0 +1,91 @@ +// *********************************************************************** +// +// Core.Inventory +// +// *********************************************************************** +using Asp.Versioning; +using Core.Adapters.Lib; +using Core.Blueprint.Logging; +using Core.Blueprint.Mongo; +using Core.Inventory.Domain.Contexts.Inventory.Request; +using Core.Inventory.Provider.Contracts; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Core.Inventory.DAL.API.Controllers +{ + /// + /// Handles all requests for furniture base CRUD operations. + /// + [ApiVersion(MimeTypes.ApplicationVersion)] + [Route("api/v{api-version:apiVersion}/[controller]")] + [Produces(MimeTypes.ApplicationJson)] + [Consumes(MimeTypes.ApplicationJson)] + [ApiController] + [AllowAnonymous] + public class FurnitureBaseController(IFurnitureBaseProvider service) : ControllerBase + { + /// + /// Gets all furniture base records. + /// + [HttpGet] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + public async Task GetAllAsync(CancellationToken cancellationToken) + { + var result = await service.GetAllAsync(cancellationToken); + return Ok(result); + } + + /// + /// Gets a furniture base record by ID. + /// + [HttpGet] + [Route("{id}")] + [ProducesResponseType(typeof(FurnitureBase), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetByIdAsync([FromRoute] string id, CancellationToken cancellationToken) + { + var result = await service.GetByIdAsync(id, cancellationToken); + return result is not null ? Ok(result) : NotFound("Entity not found"); + } + + /// + /// Creates a new furniture base record. + /// + [HttpPost] + [ProducesResponseType(typeof(FurnitureBase), StatusCodes.Status201Created)] + public async Task CreateAsync([FromBody] FurnitureBaseRequest request, CancellationToken cancellationToken) + { + var result = await service.CreateAsync(request, cancellationToken); + return Created("CreatedWithIdAsync", result); + } + + /// + /// Updates a furniture base record by ID. + /// + [HttpPut] + [Route("{id}")] + [ProducesResponseType(typeof(FurnitureBase), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + public async Task UpdateAsync([FromRoute] string id, [FromBody] FurnitureBase entity, CancellationToken cancellationToken) + { + if (id != entity.Id?.ToString()) + return BadRequest("Furniture ID mismatch"); + + var result = await service.UpdateAsync(id, entity, cancellationToken); + return Ok(result); + } + + /// + /// Changes the status of a furniture base record. + /// + [HttpPatch] + [Route("{id}/{newStatus}/ChangeStatus")] + [ProducesResponseType(typeof(FurnitureBase), StatusCodes.Status200OK)] + public async Task ChangeStatusAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) + { + var result = await service.ChangeStatusAsync(id, newStatus, cancellationToken); + return Ok(result); + } + } +} diff --git a/Core.Inventory.DAL.API/Controllers/FurnitureVariantController.cs b/Core.Inventory.DAL.API/Controllers/FurnitureVariantController.cs new file mode 100644 index 0000000..746dce7 --- /dev/null +++ b/Core.Inventory.DAL.API/Controllers/FurnitureVariantController.cs @@ -0,0 +1,97 @@ +// *********************************************************************** +// +// Core.Inventory +// +// *********************************************************************** +using Asp.Versioning; +using Core.Adapters.Lib; +using Core.Blueprint.Logging; +using Core.Blueprint.Mongo; +using Core.Inventory.Domain.Contexts.Inventory.Request; +using Core.Inventory.Provider.Contracts; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Core.Inventory.DAL.API.Controllers +{ + /// + /// Handles all requests for furniture variant CRUD operations. + /// + [ApiVersion(MimeTypes.ApplicationVersion)] + [Route("api/v{api-version:apiVersion}/[controller]")] + [Produces(MimeTypes.ApplicationJson)] + [Consumes(MimeTypes.ApplicationJson)] + [ApiController] + [AllowAnonymous] + public class FurnitureVariantController(IFurnitureVariantProvider service) : ControllerBase + { + /// + /// Gets all furniture variant records. + /// + [HttpGet] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + public async Task GetAllVariantsByModelIdAsync([FromRoute] string modelId, CancellationToken cancellationToken) + { + var result = await service.GetAllByModelIdAsync(modelId, cancellationToken).ConfigureAwait(false); + + if (result is null || !result.Any()) + { + return NotFound($"No variants found for base model with ID '{modelId}'."); + } + + return Ok(result); + } + + /// + /// Gets a furniture variant record by ID. + /// + [HttpGet] + [Route("{id}")] + [ProducesResponseType(typeof(FurnitureVariant), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetByIdAsync([FromRoute] string id, CancellationToken cancellationToken) + { + var result = await service.GetByIdAsync(id, cancellationToken); + return result is not null ? Ok(result) : NotFound("Entity not found"); + } + + /// + /// Creates a new furniture variant. + /// + [HttpPost] + [ProducesResponseType(typeof(FurnitureVariant), StatusCodes.Status201Created)] + public async Task CreateAsync([FromBody] FurnitureVariantRequest request, CancellationToken cancellationToken) + { + var result = await service.CreateAsync(request, cancellationToken); + return Created("CreatedWithIdAsync", result); + } + + /// + /// Updates a furniture variant record by ID. + /// + [HttpPut] + [Route("{id}")] + [ProducesResponseType(typeof(FurnitureVariant), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + public async Task UpdateAsync([FromRoute] string id, [FromBody] FurnitureVariant entity, CancellationToken cancellationToken) + { + if (id != entity.Id?.ToString()) + return BadRequest("Furniture Variant ID mismatch"); + + var result = await service.UpdateAsync(id, entity, cancellationToken); + return Ok(result); + } + + /// + /// Changes the status of a furniture variant record. + /// + [HttpPatch] + [Route("{id}/{newStatus}/ChangeStatus")] + [ProducesResponseType(typeof(FurnitureVariant), StatusCodes.Status200OK)] + public async Task ChangeStatusAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) + { + var result = await service.ChangeStatusAsync(id, newStatus, cancellationToken); + return Ok(result); + } + } +} diff --git a/Core.Inventory.DAL.API/Core.Inventory.DAL.API.csproj b/Core.Inventory.DAL.API/Core.Inventory.DAL.API.csproj new file mode 100644 index 0000000..4d7f5c3 --- /dev/null +++ b/Core.Inventory.DAL.API/Core.Inventory.DAL.API.csproj @@ -0,0 +1,20 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + diff --git a/Core.Inventory.DAL.API/Core.Inventory.DAL.API.http b/Core.Inventory.DAL.API/Core.Inventory.DAL.API.http new file mode 100644 index 0000000..23dc8bd --- /dev/null +++ b/Core.Inventory.DAL.API/Core.Inventory.DAL.API.http @@ -0,0 +1,6 @@ +@Core.Inventory.DAL.API_HostAddress = http://localhost:5069 + +GET {{Core.Inventory.DAL.API_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/Core.Inventory.DAL.API/Extensions/SwaggerExtensions.cs b/Core.Inventory.DAL.API/Extensions/SwaggerExtensions.cs new file mode 100644 index 0000000..9ad1747 --- /dev/null +++ b/Core.Inventory.DAL.API/Extensions/SwaggerExtensions.cs @@ -0,0 +1,66 @@ +using Asp.Versioning.ApiExplorer; +using Microsoft.Extensions.Options; +using Microsoft.OpenApi.Any; +using Swashbuckle.AspNetCore.SwaggerGen; +using Swashbuckle.AspNetCore.SwaggerUI; + +namespace Core.Inventory.DAL.API.Extensions +{ + public static class SwaggerExtensions + { + public static void AddSwagger(this IServiceCollection services) + { + services.AddEndpointsApiExplorer(); + services.AddSwaggerGen(); + services.AddTransient, ConfigureSwaggerOptions>(); + } + + public static void ConfigureSwagger(this WebApplication app) + { + 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 + { + 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.MapType(() => new() + { + Format= "date", + Example = new OpenApiString(DateOnly.MinValue.ToString()) + }); + + options.CustomSchemaIds(type => type.ToString().Replace("+", ".")); + } + } + } +} diff --git a/Core.Inventory.DAL.API/Program.cs b/Core.Inventory.DAL.API/Program.cs new file mode 100644 index 0000000..457599e --- /dev/null +++ b/Core.Inventory.DAL.API/Program.cs @@ -0,0 +1,81 @@ +using Core.Blueprint.DAL.Mongo.Configuration; +using Core.Blueprint.Logging.Configuration; +using Core.Blueprint.Redis.Configuration; +using Core.Inventory.DAL.API.Extensions; +using Core.Inventory.Provider; +using Microsoft.AspNetCore.HttpLogging; +using System.Reflection; +using System.Text.Json.Serialization; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); +builder.Configuration + .AddUserSecrets(Assembly.GetExecutingAssembly()) + .AddEnvironmentVariables(); + +builder.Services.AddResponseCompression(); +builder.Services.AddProblemDetails(); +builder.Services.AddMemoryCache(); +builder.Services.AddLogs(builder); +builder.Services.AddRedis(builder.Configuration); +builder.Services.AddMongoLayer(builder.Configuration); +builder.Services.AddDALLayerServices(builder.Configuration); + +builder.Host.ConfigureServices((context, services) => +{ + + services.AddLogging(); + services.AddControllers(); + services.AddProblemDetails(); + services.AddCors(options + => options.AddDefaultPolicy(policyBuilder + => policyBuilder + .AllowAnyOrigin() + .AllowAnyHeader() + .AllowAnyMethod())); + + builder.Services.Configure(options => + { + options.SerializerOptions.Converters.Add(new JsonStringEnumConverter()); + }); + + services + .AddEndpointsApiExplorer() + .AddVersioning() + .AddSwagger(); + + services.AddHealthChecks(); + services.AddHttpLogging(options => options.LoggingFields = HttpLoggingFields.All); + + builder.Services.AddOutputCache(options => + { + options.AddBasePolicy(builder => + builder.Expire(TimeSpan.FromSeconds(10))); + options.AddPolicy("Expire20", builder => + builder.Expire(TimeSpan.FromSeconds(20))); + options.AddPolicy("Expire30", builder => + builder.Expire(TimeSpan.FromSeconds(30))); + }); +}); + +var app = builder.Build(); + +app.UseSwagger(); +app.UseSwaggerUI(); +app.UseAuthentication(); +app.UseAuthorization(); +app.MapControllers(); +app.UseCors(); +app.ConfigureSwagger(); +app.UseHttpsRedirection(); +app.UseStaticFiles(); +app.UseRouting(); +app.UseResponseCompression(); +app.UseOutputCache(); +app.UseResponseCaching(); +app.UseLogging(builder.Configuration); +app.MapHealthChecks("/health"); + +app.Run(); diff --git a/Core.Inventory.DAL.API/Properties/launchSettings.json b/Core.Inventory.DAL.API/Properties/launchSettings.json new file mode 100644 index 0000000..ed1afc3 --- /dev/null +++ b/Core.Inventory.DAL.API/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:16111", + "sslPort": 44378 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5069", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Local" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7037;http://localhost:5069", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Local" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Local" + } + } + } +} diff --git a/Core.Inventory.DAL.API/appsettings.Development.json b/Core.Inventory.DAL.API/appsettings.Development.json new file mode 100644 index 0000000..1b17bad --- /dev/null +++ b/Core.Inventory.DAL.API/appsettings.Development.json @@ -0,0 +1,22 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "ConnectionStrings": { + "MongoDB": "mongodb://localhost:27017", + "Redis": "localhost:6379" + }, + "MongoDb": { + "DatabaseName": "Inventory", + "LocalAudience": "" + }, + "DetailedErrors": true, + "UseRedisCache": true, + "CacheSettings": { + "DefaultCacheDurationInMinutes": 3 + } +} diff --git a/Core.Inventory.DAL.API/appsettings.Local.json b/Core.Inventory.DAL.API/appsettings.Local.json new file mode 100644 index 0000000..3568cfa --- /dev/null +++ b/Core.Inventory.DAL.API/appsettings.Local.json @@ -0,0 +1,26 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "ConnectionStrings": { + "MongoDB": "mongodb://admin_agile:Admin%40agileWebs@portainer.white-enciso.pro:27017/?authMechanism=SCRAM-SHA-256", + "Redis": "100.123.31.103:6379" + }, + "MongoDb": { + "DatabaseName": "Inventory", + "LocalAudience": "" + }, + "DetailedErrors": true, + "UseRedisCache": true, + "CacheSettings": { + "DefaultCacheDurationInMinutes": 3 + }, + "ServiceSettings": { + "ApplicationName": "inventory", + "LayerName": "dal" + } +} diff --git a/Core.Inventory.DAL.API/appsettings.json b/Core.Inventory.DAL.API/appsettings.json new file mode 100644 index 0000000..1c4dc87 --- /dev/null +++ b/Core.Inventory.DAL.API/appsettings.json @@ -0,0 +1,22 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "ConnectionStrings": { + "MongoDB": "mongodb://admin_agile:Admin%40agileWebs@portainer.white-enciso.pro:27017/?authMechanism=SCRAM-SHA-256", + "Redis": "localhost:6379" + }, + "MongoDb": { + "DatabaseName": "Inventory", + "LocalAudience": "" + }, + "DetailedErrors": true, + "UseRedisCache": true, + "CacheSettings": { + "DefaultCacheDurationInMinutes": 3 + } +} \ No newline at end of file diff --git a/Core.Inventory.DAL.API/sample.settings.json b/Core.Inventory.DAL.API/sample.settings.json new file mode 100644 index 0000000..417e3fa --- /dev/null +++ b/Core.Inventory.DAL.API/sample.settings.json @@ -0,0 +1,35 @@ +{ + "ConnectionStrings": { + "DefaultConnection": "", // Sandbox MongoDB connection string + "Redis": "", // New Redis connection string + "KeyVault": "" //KeyVault Uri + }, + "MongoDb": { + "DatabaseName": "Inventory" + }, + "CacheSettings": { + "DefaultCacheDurationInMinutes": 3 // Default cache duration set to 3 minutes + }, + "JwtIssuerOptions": { + "Audience": "", // Audience for token creation, specifies intended recipients + "Issuer": "" // Issuer for token creation, identifies the issuer of the token + }, + "AzureAdB2C": { + "Instance": "", // Azure AD instance URL (STORED IN KEY VAULT) + "TenantId": "", // Azure AD tenant ID (STORED IN KEY VAULT) + "ClientId": "", // Azure AD application client ID (STORED IN KEY VAULT) + "ClientSecret": "", // Azure AD application client secret (STORED IN KEY VAULT) + "CallbackPath": "", // Path for redirect after authentication + "Scopes": "" // Access scopes for user permissions + }, + "InventoryApp": { + "AuthorizationUrl": "", // URL for authorization endpoint (STORED IN KEY VAULT) + "TokenUrl": "", // URL for token endpoint (STORED IN KEY VAULT) + "Scope": "", // Scope for application permissions (STORED IN KEY VAULT) + "ClientId": "" // Client ID for Inventory application (STORED IN KEY VAULT) + }, + "MicrosoftGraph": { + "Scopes": "", // Scopes for Microsoft Graph API access + "BaseUrl": "" // Base URL for Microsoft Graph API + } +} diff --git a/Core.Inventory.DAL.sln b/Core.Inventory.DAL.sln new file mode 100644 index 0000000..4d19b68 --- /dev/null +++ b/Core.Inventory.DAL.sln @@ -0,0 +1,46 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36212.18 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Inventory.DAL.API", "Core.Inventory.DAL.API\Core.Inventory.DAL.API.csproj", "{96859D04-7CAE-477B-B839-16A4B2D3582B}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Application", "Application", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Presentation", "Presentation", "{B1AD1822-B4BC-407E-9EA9-51D3F4992277}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Inventory.Domain", "Core.Inventory.Domain\Core.Inventory.Domain.csproj", "{09CAECFB-DD53-4D26-A5CB-964C032AF9E5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Inventory.Provider", "Core.Inventory.Provider\Core.Inventory.Provider.csproj", "{5A6BD82A-AF9C-4920-BA0E-D44B1D64A689}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {96859D04-7CAE-477B-B839-16A4B2D3582B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {96859D04-7CAE-477B-B839-16A4B2D3582B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {96859D04-7CAE-477B-B839-16A4B2D3582B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {96859D04-7CAE-477B-B839-16A4B2D3582B}.Release|Any CPU.Build.0 = Release|Any CPU + {09CAECFB-DD53-4D26-A5CB-964C032AF9E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {09CAECFB-DD53-4D26-A5CB-964C032AF9E5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {09CAECFB-DD53-4D26-A5CB-964C032AF9E5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {09CAECFB-DD53-4D26-A5CB-964C032AF9E5}.Release|Any CPU.Build.0 = Release|Any CPU + {5A6BD82A-AF9C-4920-BA0E-D44B1D64A689}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5A6BD82A-AF9C-4920-BA0E-D44B1D64A689}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5A6BD82A-AF9C-4920-BA0E-D44B1D64A689}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5A6BD82A-AF9C-4920-BA0E-D44B1D64A689}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {96859D04-7CAE-477B-B839-16A4B2D3582B} = {B1AD1822-B4BC-407E-9EA9-51D3F4992277} + {09CAECFB-DD53-4D26-A5CB-964C032AF9E5} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} + {5A6BD82A-AF9C-4920-BA0E-D44B1D64A689} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DBCCBC76-3980-4B8C-8C1D-CF99F076774B} + EndGlobalSection +EndGlobal diff --git a/Core.Inventory.Domain/Contexts/Inventory/Request/FurnitureBaseRequest.cs b/Core.Inventory.Domain/Contexts/Inventory/Request/FurnitureBaseRequest.cs new file mode 100644 index 0000000..319c451 --- /dev/null +++ b/Core.Inventory.Domain/Contexts/Inventory/Request/FurnitureBaseRequest.cs @@ -0,0 +1,101 @@ +// *********************************************************************** +// +// Core.Inventory +// +// *********************************************************************** +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; +using System.Text.Json.Serialization; + +namespace Core.Inventory.Domain.Contexts.Inventory.Request +{ + /// + /// Data transfer object (DTO) for creating or updating a furniture base model. + /// + public class FurnitureBaseRequest + { + /// + /// Gets or sets the name of the model. + /// + [BsonElement("modelName")] + [BsonRepresentation(BsonType.String)] + [JsonPropertyName("modelName")] + public string ModelName { get; set; } = null!; + + /// + /// Gets or sets the material of the furniture. + /// + [BsonElement("material")] + [BsonRepresentation(BsonType.String)] + [JsonPropertyName("material")] + public string Material { get; set; } = null!; + + /// + /// Gets or sets the condition (e.g., new, refurbished). + /// + [BsonElement("condition")] + [BsonRepresentation(BsonType.String)] + [JsonPropertyName("condition")] + public string Condition { get; set; } = null!; + + /// + /// Gets or sets the base description. + /// + [BsonElement("baseDescription")] + [BsonRepresentation(BsonType.String)] + [JsonPropertyName("baseDescription")] + public string? BaseDescription { get; set; } + + /// + /// Gets or sets the 3D or graphical representation. + /// + [BsonElement("representation")] + [BsonRepresentation(BsonType.String)] + [JsonPropertyName("representation")] + public string? Representation { get; set; } + + /// + /// Gets or sets the maintenance notes. + /// + [BsonElement("maintenanceNotes")] + [BsonRepresentation(BsonType.String)] + [JsonPropertyName("maintenanceNotes")] + public string? MaintenanceNotes { get; set; } + + /// + /// Gets or sets the dimensions of the furniture. + /// + [BsonElement("dimensions")] + [JsonPropertyName("dimensions")] + public DimensionsRequest Dimensions { get; set; } = new(); + + /// + /// Gets or sets the list of variant IDs related to this model. + /// + [BsonElement("variantIds")] + [BsonRepresentation(BsonType.String)] + [JsonPropertyName("variantIds")] + public List? VariantIds { get; set; } + } + + /// + /// Dimensions DTO for width, height and depth. + /// + public class DimensionsRequest + { + [BsonElement("width")] + [BsonRepresentation(BsonType.Double)] + [JsonPropertyName("width")] + public float Width { get; set; } + + [BsonElement("height")] + [BsonRepresentation(BsonType.Double)] + [JsonPropertyName("height")] + public float Height { get; set; } + + [BsonElement("depth")] + [BsonRepresentation(BsonType.Double)] + [JsonPropertyName("depth")] + public float Depth { get; set; } + } +} diff --git a/Core.Inventory.Domain/Contexts/Inventory/Request/FurnitureVariantRequest.cs b/Core.Inventory.Domain/Contexts/Inventory/Request/FurnitureVariantRequest.cs new file mode 100644 index 0000000..528b9c2 --- /dev/null +++ b/Core.Inventory.Domain/Contexts/Inventory/Request/FurnitureVariantRequest.cs @@ -0,0 +1,53 @@ +// *********************************************************************** +// +// Core.Inventory +// +// *********************************************************************** +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; +using System.ComponentModel.DataAnnotations; +using System.Text.Json.Serialization; + +namespace Core.Inventory.Domain.Contexts.Inventory.Request +{ + /// + /// Data transfer object (DTO) for creating or updating a furniture variant. + /// + public class FurnitureVariantRequest : InventoryItemRequestBase + { + /// + /// Gets or sets the model ID this variant belongs to (FK). + /// + [Required] + [BsonElement("modelId")] + [BsonRepresentation(BsonType.String)] + [JsonPropertyName("modelId")] + public string ModelId { get; set; } = null!; + + /// + /// Gets or sets the name of the variant. + /// + [Required] + [BsonElement("name")] + [BsonRepresentation(BsonType.String)] + [JsonPropertyName("name")] + public string Name { get; set; } = null!; + + /// + /// Gets or sets the color of the furniture variant. + /// + [Required] + [BsonElement("color")] + [BsonRepresentation(BsonType.String)] + [JsonPropertyName("color")] + public string Color { get; set; } = null!; + + /// + /// Gets or sets the product line (e.g., Premium, Eco). + /// + [BsonElement("line")] + [BsonRepresentation(BsonType.String)] + [JsonPropertyName("line")] + public string? Line { get; set; } + } +} diff --git a/Core.Inventory.Domain/Contexts/Inventory/Request/InventoryItemRequestBase.cs b/Core.Inventory.Domain/Contexts/Inventory/Request/InventoryItemRequestBase.cs new file mode 100644 index 0000000..659abc6 --- /dev/null +++ b/Core.Inventory.Domain/Contexts/Inventory/Request/InventoryItemRequestBase.cs @@ -0,0 +1,66 @@ +// *********************************************************************** +// +// Core.Inventory +// +// *********************************************************************** +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; +using System.Text.Json.Serialization; + +namespace Core.Inventory.Domain.Contexts.Inventory.Request +{ + /// + /// Base data transfer object (DTO) for inventory-related items. + /// Serves as a foundation for specific item types such as furniture variants, tools, or electronics. + /// + public abstract class InventoryItemRequestBase + { + /// + /// Gets or sets the quantity in stock. + /// + [BsonElement("stock")] + [BsonRepresentation(BsonType.Int32)] + [JsonPropertyName("stock")] + public int Stock { get; set; } + + /// + /// Gets or sets the unit price of the item. + /// + [BsonElement("price")] + [BsonRepresentation(BsonType.Decimal128)] + [JsonPropertyName("price")] + public decimal Price { get; set; } + + /// + /// Gets or sets the currency in which the price is expressed. + /// + [BsonElement("currency")] + [BsonRepresentation(BsonType.String)] + [JsonPropertyName("currency")] + public string Currency { get; set; } = "MXN"; + + /// + /// Gets or sets the category identifier the item belongs to. + /// + [BsonElement("categoryId")] + [BsonRepresentation(BsonType.String)] + [JsonPropertyName("categoryId")] + public Guid CategoryId { get; set; } + + /// + /// Gets or sets the provider or vendor identifier of the item. + /// + [BsonElement("providerId")] + [BsonRepresentation(BsonType.String)] + [JsonPropertyName("providerId")] + public Guid ProviderId { get; set; } + + /// + /// Gets or sets additional customizable attributes. + /// Useful for storing arbitrary metadata specific to the item type. + /// + [BsonElement("attributes")] + [JsonPropertyName("attributes")] + public Dictionary Attributes { get; set; } = []; + } +} diff --git a/Core.Inventory.Domain/Core.Inventory.Domain.csproj b/Core.Inventory.Domain/Core.Inventory.Domain.csproj new file mode 100644 index 0000000..08eec88 --- /dev/null +++ b/Core.Inventory.Domain/Core.Inventory.Domain.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/Core.Inventory.Provider/Contracts/IFurnitureBaseProvider.cs b/Core.Inventory.Provider/Contracts/IFurnitureBaseProvider.cs new file mode 100644 index 0000000..ce905bc --- /dev/null +++ b/Core.Inventory.Provider/Contracts/IFurnitureBaseProvider.cs @@ -0,0 +1,58 @@ +// *********************************************************************** +// +// Core.Inventory +// +// *********************************************************************** +using Core.Adapters.Lib; +using Core.Blueprint.Mongo; +using Core.Inventory.Domain.Contexts.Inventory.Request; + +namespace Core.Inventory.Provider.Contracts +{ + /// + /// Interface for managing base furniture models. + /// + public interface IFurnitureBaseProvider + { + /// + /// Creates a new FurnitureBase entity. + /// + /// The DTO representing the furniture base. + /// Cancellation token. + /// The created . + ValueTask CreateAsync(FurnitureBaseRequest newFurniture, CancellationToken cancellationToken); + + /// + /// Gets a furniture base entity by its ID. + /// + /// The unique identifier (_id) of the furniture base. + /// Cancellation token. + /// The corresponding . + ValueTask GetByIdAsync(string id, CancellationToken cancellationToken); + + /// + /// Retrieves all furniture base entries. + /// + /// Cancellation token. + /// A list of . + ValueTask> GetAllAsync(CancellationToken cancellationToken); + + /// + /// Updates an existing furniture base by ID. + /// + /// The furniture base identifier. + /// The updated entity data. + /// Cancellation token. + /// The updated . + ValueTask UpdateAsync(string id, FurnitureBase entity, CancellationToken cancellationToken); + + /// + /// Changes the status of a furniture base entity. + /// + /// The entity identifier. + /// The new status to apply. + /// Cancellation token. + /// The updated . + ValueTask ChangeStatusAsync(string id, StatusEnum newStatus, CancellationToken cancellationToken); + } +} diff --git a/Core.Inventory.Provider/Contracts/IFurnitureVariantProvider.cs b/Core.Inventory.Provider/Contracts/IFurnitureVariantProvider.cs new file mode 100644 index 0000000..ee3dbfa --- /dev/null +++ b/Core.Inventory.Provider/Contracts/IFurnitureVariantProvider.cs @@ -0,0 +1,59 @@ +// *********************************************************************** +// +// Core.Inventory +// +// *********************************************************************** +using Core.Adapters.Lib; +using Core.Blueprint.Mongo; +using Core.Inventory.Domain.Contexts.Inventory.Request; + +namespace Core.Inventory.Provider.Contracts +{ + /// + /// Interface for managing furniture variants associated with a base furniture model. + /// + public interface IFurnitureVariantProvider + { + /// + /// Creates a new FurnitureVariant entity. + /// + /// The DTO representing the furniture variant. + /// Cancellation token. + /// The created . + ValueTask CreateAsync(FurnitureVariantRequest newVariant, CancellationToken cancellationToken); + + /// + /// Gets a furniture variant entity by its ID. + /// + /// The unique identifier (_id) of the furniture variant. + /// Cancellation token. + /// The corresponding . + ValueTask GetByIdAsync(string id, CancellationToken cancellationToken); + + /// + /// Retrieves all furniture variants associated with a base model. + /// + /// The ID of the base furniture model. + /// Cancellation token. + /// A list of . + ValueTask> GetAllByModelIdAsync(string modelId, CancellationToken cancellationToken); + + /// + /// Updates an existing furniture variant by ID. + /// + /// The variant identifier. + /// The updated entity data. + /// Cancellation token. + /// The updated . + ValueTask UpdateAsync(string id, FurnitureVariant entity, CancellationToken cancellationToken); + + /// + /// Changes the status of a furniture variant entity. + /// + /// The entity identifier. + /// The new status to apply. + /// Cancellation token. + /// The updated . + ValueTask ChangeStatusAsync(string id, StatusEnum newStatus, CancellationToken cancellationToken); + } +} diff --git a/Core.Inventory.Provider/Core.Inventory.Provider.csproj b/Core.Inventory.Provider/Core.Inventory.Provider.csproj new file mode 100644 index 0000000..ebc0782 --- /dev/null +++ b/Core.Inventory.Provider/Core.Inventory.Provider.csproj @@ -0,0 +1,20 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + diff --git a/Core.Inventory.Provider/Providers/Inventory/FurnitureBaseProvider.cs b/Core.Inventory.Provider/Providers/Inventory/FurnitureBaseProvider.cs new file mode 100644 index 0000000..ebe208e --- /dev/null +++ b/Core.Inventory.Provider/Providers/Inventory/FurnitureBaseProvider.cs @@ -0,0 +1,114 @@ +// *********************************************************************** +// +// Core.Inventory +// +// *********************************************************************** +using Core.Adapters.Lib; +using Core.Blueprint.Mongo; +using Core.Blueprint.Redis; +using Core.Blueprint.Redis.Helpers; +using Core.Inventory.Domain.Contexts.Inventory.Request; +using Core.Inventory.Provider.Contracts; +using Mapster; +using Microsoft.Extensions.Options; + +namespace Core.Inventory.Provider.Providers.Inventory +{ + /// + /// Handles all operations related to . + /// + public class FurnitureBaseProvider : IFurnitureBaseProvider + { + private readonly CollectionRepository repository; + private readonly IRedisCacheProvider cacheProvider; + private readonly CacheSettings cacheSettings; + + public FurnitureBaseProvider( + CollectionRepository repository, + IRedisCacheProvider cacheProvider, + IOptions cacheSettings + ) + { + this.repository = repository; + this.repository.CollectionInitialization(); + this.cacheProvider = cacheProvider; + this.cacheSettings = cacheSettings.Value; + } + + /// + /// Changes the status of a FurnitureBase entity. + /// + /// The furniture base identifier. + /// The new status to apply. + /// Cancellation token. + /// The updated . + public async ValueTask ChangeStatusAsync(string id, StatusEnum newStatus, CancellationToken cancellationToken) + { + var entity = await repository.FindByIdAsync(id); + entity.Status = newStatus; + await repository.ReplaceOneAsync(entity); + return entity; + } + + /// + /// Creates a new FurnitureBase entity. + /// + /// The DTO representing the base furniture model. + /// Cancellation token. + /// The created . + public async ValueTask CreateAsync(FurnitureBaseRequest newFurniture, CancellationToken cancellationToken) + { + var furnitureCollection = newFurniture.Adapt(); + await repository.InsertOneAsync(furnitureCollection); + return furnitureCollection; + } + + /// + /// Retrieves all FurnitureBase entries. + /// + /// Cancellation token. + /// A list of . + public async ValueTask> GetAllAsync(CancellationToken cancellationToken) + { + var cacheKey = CacheKeyHelper.GenerateCacheKey(this, nameof(GetAllAsync)); + var cachedData = await cacheProvider.GetAsync>(cacheKey) ?? []; + + if (cachedData.Any()) return cachedData; + + var data = await repository.AsQueryable(); + await cacheProvider.SetAsync(cacheKey, data); + return data; + } + + /// + /// Gets a FurnitureBase entity by its ID. + /// + /// The furniture base identifier. + /// Cancellation token. + /// The corresponding . + public async ValueTask GetByIdAsync(string id, CancellationToken cancellationToken) + { + var cacheKey = CacheKeyHelper.GenerateCacheKey(this, nameof(GetByIdAsync), id); + var cached = await cacheProvider.GetAsync(cacheKey); + + if (cached is not null) return cached; + + var result = await repository.FindByIdAsync(id); + await cacheProvider.SetAsync(cacheKey, result); + return result; + } + + /// + /// Updates a FurnitureBase entity by ID. + /// + /// The furniture base identifier. + /// The updated entity data. + /// Cancellation token. + /// The updated . + public async ValueTask UpdateAsync(string id, FurnitureBase entity, CancellationToken cancellationToken) + { + await repository.ReplaceOneAsync(entity); + return entity; + } + } +} diff --git a/Core.Inventory.Provider/Providers/Inventory/FurnitureVariantProvider.cs b/Core.Inventory.Provider/Providers/Inventory/FurnitureVariantProvider.cs new file mode 100644 index 0000000..6a759d5 --- /dev/null +++ b/Core.Inventory.Provider/Providers/Inventory/FurnitureVariantProvider.cs @@ -0,0 +1,114 @@ +// *********************************************************************** +// +// Core.Inventory +// +// *********************************************************************** +using Core.Adapters.Lib; +using Core.Blueprint.Mongo; +using Core.Blueprint.Redis; +using Core.Blueprint.Redis.Helpers; +using Core.Inventory.Domain.Contexts.Inventory.Request; +using Core.Inventory.Provider.Contracts; +using Mapster; +using Microsoft.Extensions.Options; + +namespace Core.Inventory.Provider.Providers.Inventory +{ + /// + /// Handles all operations related to . + /// + public class FurnitureVariantProvider : IFurnitureVariantProvider + { + private readonly CollectionRepository repository; + private readonly IRedisCacheProvider cacheProvider; + private readonly CacheSettings cacheSettings; + + public FurnitureVariantProvider( + CollectionRepository repository, + IRedisCacheProvider cacheProvider, + IOptions cacheSettings + ) + { + this.repository = repository; + this.repository.CollectionInitialization(); + this.cacheProvider = cacheProvider; + this.cacheSettings = cacheSettings.Value; + } + + /// + /// Changes the status of a FurnitureVariant entity. + /// + /// The furniture variant identifier. + /// The new status to apply. + /// Cancellation token. + /// The updated . + public async ValueTask ChangeStatusAsync(string id, StatusEnum newStatus, CancellationToken cancellationToken) + { + var entity = await repository.FindByIdAsync(id); + entity.Status = newStatus; + await repository.ReplaceOneAsync(entity); + return entity; + } + + /// + /// Creates a new FurnitureVariant entity. + /// + /// The DTO representing the furniture variant. + /// Cancellation token. + /// The created . + public async ValueTask CreateAsync(FurnitureVariantRequest newVariant, CancellationToken cancellationToken) + { + var variantCollection = newVariant.Adapt(); + await repository.InsertOneAsync(variantCollection); + return variantCollection; + } + + /// + /// Retrieves all FurnitureVariant entries. + /// + /// Cancellation token. + /// A list of . + public async ValueTask> GetAllByModelIdAsync(string modelId, CancellationToken cancellationToken) + { + var cacheKey = CacheKeyHelper.GenerateCacheKey(this, nameof(GetAllByModelIdAsync)); + var cachedData = await cacheProvider.GetAsync>(cacheKey); + + if (cachedData.Any()) return cachedData; + + var data = await repository.AsQueryable(); + await cacheProvider.SetAsync(cacheKey, data); + return data; + } + + /// + /// Gets a FurnitureVariant entity by its ID. + /// + /// The furniture variant identifier. + /// Cancellation token. + /// The corresponding . + public async ValueTask GetByIdAsync(string id, CancellationToken cancellationToken) + { + var cacheKey = CacheKeyHelper.GenerateCacheKey(this, nameof(GetByIdAsync), id); + var cached = await cacheProvider.GetAsync(cacheKey); + + if (cached is not null) return cached; + + var result = await repository.FindByIdAsync(id); + await cacheProvider.SetAsync(cacheKey, result); + return result; + } + + /// + /// Updates a FurnitureVariant entity by ID. + /// + /// The furniture variant identifier. + /// The updated entity data. + /// Cancellation token. + /// The updated . + public async ValueTask UpdateAsync(string id, FurnitureVariant entity, CancellationToken cancellationToken) + { + await repository.ReplaceOneAsync(entity); + return entity; + } + } +} diff --git a/Core.Inventory.Provider/ServiceCollectionExtensions.cs b/Core.Inventory.Provider/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..c6af67e --- /dev/null +++ b/Core.Inventory.Provider/ServiceCollectionExtensions.cs @@ -0,0 +1,24 @@ +using Core.Adapters.Lib; +using Core.Blueprint.Mongo; +using Core.Inventory.Provider.Contracts; +using Core.Inventory.Provider.Providers.Inventory; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Core.Inventory.Provider +{ + public static class ServiceCollectionExtensions + { + public static IServiceCollection AddDALLayerServices(this IServiceCollection services, IConfiguration configuration) + { + services.AddScoped(); + services.AddScoped>(); + + services.AddScoped(); + services.AddScoped>(); + + return services; + + } + } +}