First version of DAL
This commit is contained in:
commit
658e3f4277
363
.gitignore
vendored
Normal file
363
.gitignore
vendored
Normal file
@ -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
|
||||
@ -0,0 +1,91 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="FurnitureBaseController.cs">
|
||||
// Core.Inventory
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles all requests for furniture base CRUD operations.
|
||||
/// </summary>
|
||||
[ApiVersion(MimeTypes.ApplicationVersion)]
|
||||
[Route("api/v{api-version:apiVersion}/[controller]")]
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[ApiController]
|
||||
[AllowAnonymous]
|
||||
public class FurnitureBaseController(IFurnitureBaseProvider service) : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all furniture base records.
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(IEnumerable<FurnitureBase>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetAllAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.GetAllAsync(cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a furniture base record by ID.
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[Route("{id}")]
|
||||
[ProducesResponseType(typeof(FurnitureBase), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetByIdAsync([FromRoute] string id, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.GetByIdAsync(id, cancellationToken);
|
||||
return result is not null ? Ok(result) : NotFound("Entity not found");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new furniture base record.
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(FurnitureBase), StatusCodes.Status201Created)]
|
||||
public async Task<IActionResult> CreateAsync([FromBody] FurnitureBaseRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.CreateAsync(request, cancellationToken);
|
||||
return Created("CreatedWithIdAsync", result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a furniture base record by ID.
|
||||
/// </summary>
|
||||
[HttpPut]
|
||||
[Route("{id}")]
|
||||
[ProducesResponseType(typeof(FurnitureBase), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the status of a furniture base record.
|
||||
/// </summary>
|
||||
[HttpPatch]
|
||||
[Route("{id}/{newStatus}/ChangeStatus")]
|
||||
[ProducesResponseType(typeof(FurnitureBase), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> ChangeStatusAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.ChangeStatusAsync(id, newStatus, cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,97 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="FurnitureVariantController.cs">
|
||||
// Core.Inventory
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles all requests for furniture variant CRUD operations.
|
||||
/// </summary>
|
||||
[ApiVersion(MimeTypes.ApplicationVersion)]
|
||||
[Route("api/v{api-version:apiVersion}/[controller]")]
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[ApiController]
|
||||
[AllowAnonymous]
|
||||
public class FurnitureVariantController(IFurnitureVariantProvider service) : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all furniture variant records.
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(IEnumerable<FurnitureVariant>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a furniture variant record by ID.
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[Route("{id}")]
|
||||
[ProducesResponseType(typeof(FurnitureVariant), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetByIdAsync([FromRoute] string id, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.GetByIdAsync(id, cancellationToken);
|
||||
return result is not null ? Ok(result) : NotFound("Entity not found");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new furniture variant.
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(FurnitureVariant), StatusCodes.Status201Created)]
|
||||
public async Task<IActionResult> CreateAsync([FromBody] FurnitureVariantRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.CreateAsync(request, cancellationToken);
|
||||
return Created("CreatedWithIdAsync", result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a furniture variant record by ID.
|
||||
/// </summary>
|
||||
[HttpPut]
|
||||
[Route("{id}")]
|
||||
[ProducesResponseType(typeof(FurnitureVariant), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the status of a furniture variant record.
|
||||
/// </summary>
|
||||
[HttpPatch]
|
||||
[Route("{id}/{newStatus}/ChangeStatus")]
|
||||
[ProducesResponseType(typeof(FurnitureVariant), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> ChangeStatusAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.ChangeStatusAsync(id, newStatus, cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
20
Core.Inventory.DAL.API/Core.Inventory.DAL.API.csproj
Normal file
20
Core.Inventory.DAL.API/Core.Inventory.DAL.API.csproj
Normal file
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
|
||||
<PackageReference Include="Core.Blueprint.Logging" Version="1.0.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core.Inventory.Domain\Core.Inventory.Domain.csproj" />
|
||||
<ProjectReference Include="..\Core.Inventory.Provider\Core.Inventory.Provider.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
6
Core.Inventory.DAL.API/Core.Inventory.DAL.API.http
Normal file
6
Core.Inventory.DAL.API/Core.Inventory.DAL.API.http
Normal file
@ -0,0 +1,6 @@
|
||||
@Core.Inventory.DAL.API_HostAddress = http://localhost:5069
|
||||
|
||||
GET {{Core.Inventory.DAL.API_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
66
Core.Inventory.DAL.API/Extensions/SwaggerExtensions.cs
Normal file
66
Core.Inventory.DAL.API/Extensions/SwaggerExtensions.cs
Normal file
@ -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<IConfigureOptions<SwaggerGenOptions>, 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<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.MapType<DateOnly>(() => new()
|
||||
{
|
||||
Format= "date",
|
||||
Example = new OpenApiString(DateOnly.MinValue.ToString())
|
||||
});
|
||||
|
||||
options.CustomSchemaIds(type => type.ToString().Replace("+", "."));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
81
Core.Inventory.DAL.API/Program.cs
Normal file
81
Core.Inventory.DAL.API/Program.cs
Normal file
@ -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<Microsoft.AspNetCore.Http.Json.JsonOptions>(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();
|
||||
41
Core.Inventory.DAL.API/Properties/launchSettings.json
Normal file
41
Core.Inventory.DAL.API/Properties/launchSettings.json
Normal file
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Core.Inventory.DAL.API/appsettings.Development.json
Normal file
22
Core.Inventory.DAL.API/appsettings.Development.json
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
26
Core.Inventory.DAL.API/appsettings.Local.json
Normal file
26
Core.Inventory.DAL.API/appsettings.Local.json
Normal file
@ -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"
|
||||
}
|
||||
}
|
||||
22
Core.Inventory.DAL.API/appsettings.json
Normal file
22
Core.Inventory.DAL.API/appsettings.json
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
35
Core.Inventory.DAL.API/sample.settings.json
Normal file
35
Core.Inventory.DAL.API/sample.settings.json
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
46
Core.Inventory.DAL.sln
Normal file
46
Core.Inventory.DAL.sln
Normal file
@ -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
|
||||
@ -0,0 +1,101 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="FurnitureBaseRequest.cs">
|
||||
// Core.Inventory
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Core.Inventory.Domain.Contexts.Inventory.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// Data transfer object (DTO) for creating or updating a furniture base model.
|
||||
/// </summary>
|
||||
public class FurnitureBaseRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the model.
|
||||
/// </summary>
|
||||
[BsonElement("modelName")]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
[JsonPropertyName("modelName")]
|
||||
public string ModelName { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the material of the furniture.
|
||||
/// </summary>
|
||||
[BsonElement("material")]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
[JsonPropertyName("material")]
|
||||
public string Material { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the condition (e.g., new, refurbished).
|
||||
/// </summary>
|
||||
[BsonElement("condition")]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
[JsonPropertyName("condition")]
|
||||
public string Condition { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the base description.
|
||||
/// </summary>
|
||||
[BsonElement("baseDescription")]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
[JsonPropertyName("baseDescription")]
|
||||
public string? BaseDescription { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the 3D or graphical representation.
|
||||
/// </summary>
|
||||
[BsonElement("representation")]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
[JsonPropertyName("representation")]
|
||||
public string? Representation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maintenance notes.
|
||||
/// </summary>
|
||||
[BsonElement("maintenanceNotes")]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
[JsonPropertyName("maintenanceNotes")]
|
||||
public string? MaintenanceNotes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the dimensions of the furniture.
|
||||
/// </summary>
|
||||
[BsonElement("dimensions")]
|
||||
[JsonPropertyName("dimensions")]
|
||||
public DimensionsRequest Dimensions { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of variant IDs related to this model.
|
||||
/// </summary>
|
||||
[BsonElement("variantIds")]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
[JsonPropertyName("variantIds")]
|
||||
public List<string>? VariantIds { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dimensions DTO for width, height and depth.
|
||||
/// </summary>
|
||||
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; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="FurnitureVariantRequest.cs">
|
||||
// Core.Inventory
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Core.Inventory.Domain.Contexts.Inventory.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// Data transfer object (DTO) for creating or updating a furniture variant.
|
||||
/// </summary>
|
||||
public class FurnitureVariantRequest : InventoryItemRequestBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the model ID this variant belongs to (FK).
|
||||
/// </summary>
|
||||
[Required]
|
||||
[BsonElement("modelId")]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
[JsonPropertyName("modelId")]
|
||||
public string ModelId { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the variant.
|
||||
/// </summary>
|
||||
[Required]
|
||||
[BsonElement("name")]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the furniture variant.
|
||||
/// </summary>
|
||||
[Required]
|
||||
[BsonElement("color")]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
[JsonPropertyName("color")]
|
||||
public string Color { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the product line (e.g., Premium, Eco).
|
||||
/// </summary>
|
||||
[BsonElement("line")]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
[JsonPropertyName("line")]
|
||||
public string? Line { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="InventoryItemRequestBase.cs">
|
||||
// Core.Inventory
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Core.Inventory.Domain.Contexts.Inventory.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// Base data transfer object (DTO) for inventory-related items.
|
||||
/// Serves as a foundation for specific item types such as furniture variants, tools, or electronics.
|
||||
/// </summary>
|
||||
public abstract class InventoryItemRequestBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the quantity in stock.
|
||||
/// </summary>
|
||||
[BsonElement("stock")]
|
||||
[BsonRepresentation(BsonType.Int32)]
|
||||
[JsonPropertyName("stock")]
|
||||
public int Stock { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the unit price of the item.
|
||||
/// </summary>
|
||||
[BsonElement("price")]
|
||||
[BsonRepresentation(BsonType.Decimal128)]
|
||||
[JsonPropertyName("price")]
|
||||
public decimal Price { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the currency in which the price is expressed.
|
||||
/// </summary>
|
||||
[BsonElement("currency")]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
[JsonPropertyName("currency")]
|
||||
public string Currency { get; set; } = "MXN";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the category identifier the item belongs to.
|
||||
/// </summary>
|
||||
[BsonElement("categoryId")]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
[JsonPropertyName("categoryId")]
|
||||
public Guid CategoryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the provider or vendor identifier of the item.
|
||||
/// </summary>
|
||||
[BsonElement("providerId")]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
[JsonPropertyName("providerId")]
|
||||
public Guid ProviderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets additional customizable attributes.
|
||||
/// Useful for storing arbitrary metadata specific to the item type.
|
||||
/// </summary>
|
||||
[BsonElement("attributes")]
|
||||
[JsonPropertyName("attributes")]
|
||||
public Dictionary<string, object> Attributes { get; set; } = [];
|
||||
}
|
||||
}
|
||||
13
Core.Inventory.Domain/Core.Inventory.Domain.csproj
Normal file
13
Core.Inventory.Domain/Core.Inventory.Domain.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BuildingBlocks.Library" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
58
Core.Inventory.Provider/Contracts/IFurnitureBaseProvider.cs
Normal file
58
Core.Inventory.Provider/Contracts/IFurnitureBaseProvider.cs
Normal file
@ -0,0 +1,58 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="IFurnitureBaseProvider.cs">
|
||||
// Core.Inventory
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
using Core.Adapters.Lib;
|
||||
using Core.Blueprint.Mongo;
|
||||
using Core.Inventory.Domain.Contexts.Inventory.Request;
|
||||
|
||||
namespace Core.Inventory.Provider.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for managing base furniture models.
|
||||
/// </summary>
|
||||
public interface IFurnitureBaseProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new FurnitureBase entity.
|
||||
/// </summary>
|
||||
/// <param name="newFurniture">The DTO representing the furniture base.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>The created <see cref="FurnitureBase"/>.</returns>
|
||||
ValueTask<FurnitureBase> CreateAsync(FurnitureBaseRequest newFurniture, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a furniture base entity by its ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier (_id) of the furniture base.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>The corresponding <see cref="FurnitureBase"/>.</returns>
|
||||
ValueTask<FurnitureBase> GetByIdAsync(string id, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all furniture base entries.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>A list of <see cref="FurnitureBase"/>.</returns>
|
||||
ValueTask<IEnumerable<FurnitureBase>> GetAllAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing furniture base by ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The furniture base identifier.</param>
|
||||
/// <param name="entity">The updated entity data.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>The updated <see cref="FurnitureBase"/>.</returns>
|
||||
ValueTask<FurnitureBase> UpdateAsync(string id, FurnitureBase entity, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Changes the status of a furniture base entity.
|
||||
/// </summary>
|
||||
/// <param name="id">The entity identifier.</param>
|
||||
/// <param name="newStatus">The new status to apply.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>The updated <see cref="FurnitureBase"/>.</returns>
|
||||
ValueTask<FurnitureBase> ChangeStatusAsync(string id, StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="IFurnitureVariantProvider.cs">
|
||||
// Core.Inventory
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
using Core.Adapters.Lib;
|
||||
using Core.Blueprint.Mongo;
|
||||
using Core.Inventory.Domain.Contexts.Inventory.Request;
|
||||
|
||||
namespace Core.Inventory.Provider.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for managing furniture variants associated with a base furniture model.
|
||||
/// </summary>
|
||||
public interface IFurnitureVariantProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new FurnitureVariant entity.
|
||||
/// </summary>
|
||||
/// <param name="newVariant">The DTO representing the furniture variant.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>The created <see cref="FurnitureVariant"/>.</returns>
|
||||
ValueTask<FurnitureVariant> CreateAsync(FurnitureVariantRequest newVariant, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a furniture variant entity by its ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier (_id) of the furniture variant.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>The corresponding <see cref="FurnitureVariant"/>.</returns>
|
||||
ValueTask<FurnitureVariant> GetByIdAsync(string id, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all furniture variants associated with a base model.
|
||||
/// </summary>
|
||||
/// <param name="modelId">The ID of the base furniture model.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>A list of <see cref="FurnitureVariant"/>.</returns>
|
||||
ValueTask<IEnumerable<FurnitureVariant>> GetAllByModelIdAsync(string modelId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing furniture variant by ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The variant identifier.</param>
|
||||
/// <param name="entity">The updated entity data.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>The updated <see cref="FurnitureVariant"/>.</returns>
|
||||
ValueTask<FurnitureVariant> UpdateAsync(string id, FurnitureVariant entity, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Changes the status of a furniture variant entity.
|
||||
/// </summary>
|
||||
/// <param name="id">The entity identifier.</param>
|
||||
/// <param name="newStatus">The new status to apply.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>The updated <see cref="FurnitureVariant"/>.</returns>
|
||||
ValueTask<FurnitureVariant> ChangeStatusAsync(string id, StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
20
Core.Inventory.Provider/Core.Inventory.Provider.csproj
Normal file
20
Core.Inventory.Provider/Core.Inventory.Provider.csproj
Normal file
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Adapters.Lib" Version="1.0.3" />
|
||||
<PackageReference Include="Core.Blueprint.Mongo" Version="1.0.0" />
|
||||
<PackageReference Include="Core.Blueprint.Redis" Version="1.0.1" />
|
||||
<PackageReference Include="Mapster" Version="7.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core.Inventory.Domain\Core.Inventory.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,114 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="FurnitureBaseProvider.cs">
|
||||
// Core.Inventory
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles all operations related to <see cref="FurnitureBase"/>.
|
||||
/// </summary>
|
||||
public class FurnitureBaseProvider : IFurnitureBaseProvider
|
||||
{
|
||||
private readonly CollectionRepository<FurnitureBase> repository;
|
||||
private readonly IRedisCacheProvider cacheProvider;
|
||||
private readonly CacheSettings cacheSettings;
|
||||
|
||||
public FurnitureBaseProvider(
|
||||
CollectionRepository<FurnitureBase> repository,
|
||||
IRedisCacheProvider cacheProvider,
|
||||
IOptions<CacheSettings> cacheSettings
|
||||
)
|
||||
{
|
||||
this.repository = repository;
|
||||
this.repository.CollectionInitialization();
|
||||
this.cacheProvider = cacheProvider;
|
||||
this.cacheSettings = cacheSettings.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the status of a FurnitureBase entity.
|
||||
/// </summary>
|
||||
/// <param name="id">The furniture base identifier.</param>
|
||||
/// <param name="newStatus">The new status to apply.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>The updated <see cref="FurnitureBase"/>.</returns>
|
||||
public async ValueTask<FurnitureBase> ChangeStatusAsync(string id, StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await repository.FindByIdAsync(id);
|
||||
entity.Status = newStatus;
|
||||
await repository.ReplaceOneAsync(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new FurnitureBase entity.
|
||||
/// </summary>
|
||||
/// <param name="newFurniture">The DTO representing the base furniture model.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>The created <see cref="FurnitureBase"/>.</returns>
|
||||
public async ValueTask<FurnitureBase> CreateAsync(FurnitureBaseRequest newFurniture, CancellationToken cancellationToken)
|
||||
{
|
||||
var furnitureCollection = newFurniture.Adapt<FurnitureBase>();
|
||||
await repository.InsertOneAsync(furnitureCollection);
|
||||
return furnitureCollection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all FurnitureBase entries.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>A list of <see cref="FurnitureBase"/>.</returns>
|
||||
public async ValueTask<IEnumerable<FurnitureBase>> GetAllAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, nameof(GetAllAsync));
|
||||
var cachedData = await cacheProvider.GetAsync<IEnumerable<FurnitureBase>>(cacheKey) ?? [];
|
||||
|
||||
if (cachedData.Any()) return cachedData;
|
||||
|
||||
var data = await repository.AsQueryable();
|
||||
await cacheProvider.SetAsync(cacheKey, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a FurnitureBase entity by its ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The furniture base identifier.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>The corresponding <see cref="FurnitureBase"/>.</returns>
|
||||
public async ValueTask<FurnitureBase> GetByIdAsync(string id, CancellationToken cancellationToken)
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, nameof(GetByIdAsync), id);
|
||||
var cached = await cacheProvider.GetAsync<FurnitureBase>(cacheKey);
|
||||
|
||||
if (cached is not null) return cached;
|
||||
|
||||
var result = await repository.FindByIdAsync(id);
|
||||
await cacheProvider.SetAsync(cacheKey, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a FurnitureBase entity by ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The furniture base identifier.</param>
|
||||
/// <param name="entity">The updated entity data.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>The updated <see cref="FurnitureBase"/>.</returns>
|
||||
public async ValueTask<FurnitureBase> UpdateAsync(string id, FurnitureBase entity, CancellationToken cancellationToken)
|
||||
{
|
||||
await repository.ReplaceOneAsync(entity);
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,114 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="FurnitureVariantProvider.cs">
|
||||
// Core.Inventory
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles all operations related to <see cref="FurnitureVariant"/>.
|
||||
/// </summary>
|
||||
public class FurnitureVariantProvider : IFurnitureVariantProvider
|
||||
{
|
||||
private readonly CollectionRepository<FurnitureVariant> repository;
|
||||
private readonly IRedisCacheProvider cacheProvider;
|
||||
private readonly CacheSettings cacheSettings;
|
||||
|
||||
public FurnitureVariantProvider(
|
||||
CollectionRepository<FurnitureVariant> repository,
|
||||
IRedisCacheProvider cacheProvider,
|
||||
IOptions<CacheSettings> cacheSettings
|
||||
)
|
||||
{
|
||||
this.repository = repository;
|
||||
this.repository.CollectionInitialization();
|
||||
this.cacheProvider = cacheProvider;
|
||||
this.cacheSettings = cacheSettings.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the status of a FurnitureVariant entity.
|
||||
/// </summary>
|
||||
/// <param name="id">The furniture variant identifier.</param>
|
||||
/// <param name="newStatus">The new status to apply.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>The updated <see cref="FurnitureVariant"/>.</returns>
|
||||
public async ValueTask<FurnitureVariant> ChangeStatusAsync(string id, StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await repository.FindByIdAsync(id);
|
||||
entity.Status = newStatus;
|
||||
await repository.ReplaceOneAsync(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new FurnitureVariant entity.
|
||||
/// </summary>
|
||||
/// <param name="newVariant">The DTO representing the furniture variant.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>The created <see cref="FurnitureVariant"/>.</returns>
|
||||
public async ValueTask<FurnitureVariant> CreateAsync(FurnitureVariantRequest newVariant, CancellationToken cancellationToken)
|
||||
{
|
||||
var variantCollection = newVariant.Adapt<FurnitureVariant>();
|
||||
await repository.InsertOneAsync(variantCollection);
|
||||
return variantCollection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all FurnitureVariant entries.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>A list of <see cref="FurnitureVariant"/>.</returns>
|
||||
public async ValueTask<IEnumerable<FurnitureVariant>> GetAllByModelIdAsync(string modelId, CancellationToken cancellationToken)
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, nameof(GetAllByModelIdAsync));
|
||||
var cachedData = await cacheProvider.GetAsync<IEnumerable<FurnitureVariant>>(cacheKey);
|
||||
|
||||
if (cachedData.Any()) return cachedData;
|
||||
|
||||
var data = await repository.AsQueryable();
|
||||
await cacheProvider.SetAsync(cacheKey, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a FurnitureVariant entity by its ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The furniture variant identifier.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>The corresponding <see cref="FurnitureVariant"/>.</returns>
|
||||
public async ValueTask<FurnitureVariant> GetByIdAsync(string id, CancellationToken cancellationToken)
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, nameof(GetByIdAsync), id);
|
||||
var cached = await cacheProvider.GetAsync<FurnitureVariant>(cacheKey);
|
||||
|
||||
if (cached is not null) return cached;
|
||||
|
||||
var result = await repository.FindByIdAsync(id);
|
||||
await cacheProvider.SetAsync(cacheKey, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a FurnitureVariant entity by ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The furniture variant identifier.</param>
|
||||
/// <param name="entity">The updated entity data.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>The updated <see cref="FurnitureVariant"/>.</returns>
|
||||
public async ValueTask<FurnitureVariant> UpdateAsync(string id, FurnitureVariant entity, CancellationToken cancellationToken)
|
||||
{
|
||||
await repository.ReplaceOneAsync(entity);
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
Core.Inventory.Provider/ServiceCollectionExtensions.cs
Normal file
24
Core.Inventory.Provider/ServiceCollectionExtensions.cs
Normal file
@ -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<IFurnitureBaseProvider, FurnitureBaseProvider>();
|
||||
services.AddScoped<CollectionRepository<FurnitureBase>>();
|
||||
|
||||
services.AddScoped<IFurnitureVariantProvider, FurnitureVariantProvider>();
|
||||
services.AddScoped<CollectionRepository<FurnitureVariant>>();
|
||||
|
||||
return services;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user