diff --git a/Core.Inventory.DAL.API/Controllers/FurnitureBaseController.cs b/Core.Inventory.DAL.API/Controllers/FurnitureBaseController.cs index 25549b7..9c99c2c 100644 --- a/Core.Inventory.DAL.API/Controllers/FurnitureBaseController.cs +++ b/Core.Inventory.DAL.API/Controllers/FurnitureBaseController.cs @@ -40,12 +40,12 @@ namespace Core.Inventory.DAL.API.Controllers /// Gets a furniture base record by ID. /// [HttpGet] - [Route("{id}")] + [Route("{_id}")] [ProducesResponseType(typeof(FurnitureBase), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task GetByIdAsync([FromRoute] string id, CancellationToken cancellationToken) + public async Task GetByIdAsync([FromRoute] string _id, CancellationToken cancellationToken) { - var result = await service.GetByIdAsync(id, cancellationToken); + var result = await service.GetByIdAsync(_id, cancellationToken); return result is not null ? Ok(result) : NotFound("Entity not found"); } @@ -80,11 +80,11 @@ namespace Core.Inventory.DAL.API.Controllers /// Changes the status of a furniture base record. /// [HttpPatch] - [Route("{id}/{newStatus}/ChangeStatus")] + [Route("{_id}/{newStatus}/ChangeStatus")] [ProducesResponseType(typeof(FurnitureBase), StatusCodes.Status200OK)] - public async Task ChangeStatusAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) + public async Task ChangeStatusAsync([FromRoute] string _id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) { - var result = await service.ChangeStatusAsync(id, newStatus, 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 index 746dce7..7651d20 100644 --- a/Core.Inventory.DAL.API/Controllers/FurnitureVariantController.cs +++ b/Core.Inventory.DAL.API/Controllers/FurnitureVariantController.cs @@ -29,8 +29,9 @@ namespace Core.Inventory.DAL.API.Controllers /// Gets all furniture variant records. /// [HttpGet] + [Route("ByModel/{modelId}")] [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] - public async Task GetAllVariantsByModelIdAsync([FromRoute] string modelId, CancellationToken cancellationToken) + public async Task GetAllVariantsByModelIdAsync(string modelId, CancellationToken cancellationToken) { var result = await service.GetAllByModelIdAsync(modelId, cancellationToken).ConfigureAwait(false); @@ -46,15 +47,38 @@ namespace Core.Inventory.DAL.API.Controllers /// Gets a furniture variant record by ID. /// [HttpGet] - [Route("{id}")] + [Route("{_id}")] [ProducesResponseType(typeof(FurnitureVariant), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task GetByIdAsync([FromRoute] string id, CancellationToken cancellationToken) + public async Task GetByIdAsync([FromRoute] string _id, CancellationToken cancellationToken) { - var result = await service.GetByIdAsync(id, cancellationToken); + var result = await service.GetByIdAsync(_id, cancellationToken); return result is not null ? Ok(result) : NotFound("Entity not found"); } + /// + /// Gets multiple furniture variants by their identifiers. + /// + /// List of variant IDs. + /// Cancellation token. + /// A list of . + [HttpPost("ByIds")] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + public async Task GetVariantsByIdsAsync([FromBody] string[] ids, CancellationToken cancellationToken) + { + if (ids is null || ids.Length == 0) + return BadRequest("At least one variant ID must be provided."); + + var result = await service.GetAllByIdsAsync(ids, cancellationToken); + + if (result is null || !result.Any()) + return NoContent(); + + return Ok(result); + } + /// /// Creates a new furniture variant. /// @@ -86,11 +110,11 @@ namespace Core.Inventory.DAL.API.Controllers /// Changes the status of a furniture variant record. /// [HttpPatch] - [Route("{id}/{newStatus}/ChangeStatus")] + [Route("{_id}/{newStatus}/ChangeStatus")] [ProducesResponseType(typeof(FurnitureVariant), StatusCodes.Status200OK)] - public async Task ChangeStatusAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) + public async Task ChangeStatusAsync([FromRoute] string _id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) { - var result = await service.ChangeStatusAsync(id, newStatus, cancellationToken); + var result = await service.ChangeStatusAsync(_id, newStatus, cancellationToken); return Ok(result); } } diff --git a/Core.Inventory.DAL.API/appsettings.Development.json b/Core.Inventory.DAL.API/appsettings.Development.json index 1b17bad..b1cce74 100644 --- a/Core.Inventory.DAL.API/appsettings.Development.json +++ b/Core.Inventory.DAL.API/appsettings.Development.json @@ -12,7 +12,7 @@ }, "MongoDb": { "DatabaseName": "Inventory", - "LocalAudience": "" + "LocalAudience": "InventotyDev" }, "DetailedErrors": true, "UseRedisCache": true, diff --git a/Core.Inventory.DAL.API/appsettings.Local.json b/Core.Inventory.DAL.API/appsettings.Local.json index 3568cfa..30170dd 100644 --- a/Core.Inventory.DAL.API/appsettings.Local.json +++ b/Core.Inventory.DAL.API/appsettings.Local.json @@ -12,7 +12,7 @@ }, "MongoDb": { "DatabaseName": "Inventory", - "LocalAudience": "" + "LocalAudience": "InventotyLocal" }, "DetailedErrors": true, "UseRedisCache": true, diff --git a/Core.Inventory.Domain/Contexts/Inventory/Request/InventoryItemRequestBase.cs b/Core.Inventory.Domain/Contexts/Inventory/Request/InventoryItemRequestBase.cs index 659abc6..9962045 100644 --- a/Core.Inventory.Domain/Contexts/Inventory/Request/InventoryItemRequestBase.cs +++ b/Core.Inventory.Domain/Contexts/Inventory/Request/InventoryItemRequestBase.cs @@ -37,7 +37,7 @@ namespace Core.Inventory.Domain.Contexts.Inventory.Request [BsonElement("currency")] [BsonRepresentation(BsonType.String)] [JsonPropertyName("currency")] - public string Currency { get; set; } = "MXN"; + public string Currency { get; set; } = "USD"; /// /// Gets or sets the category identifier the item belongs to. diff --git a/Core.Inventory.Provider/Contracts/IFurnitureBaseProvider.cs b/Core.Inventory.Provider/Contracts/IFurnitureBaseProvider.cs index ce905bc..50ec874 100644 --- a/Core.Inventory.Provider/Contracts/IFurnitureBaseProvider.cs +++ b/Core.Inventory.Provider/Contracts/IFurnitureBaseProvider.cs @@ -25,10 +25,10 @@ namespace Core.Inventory.Provider.Contracts /// /// Gets a furniture base entity by its ID. /// - /// The unique identifier (_id) of the furniture base. + /// The unique identifier (_id) of the furniture base. /// Cancellation token. /// The corresponding . - ValueTask GetByIdAsync(string id, CancellationToken cancellationToken); + ValueTask GetByIdAsync(string _id, CancellationToken cancellationToken); /// /// Retrieves all furniture base entries. @@ -49,10 +49,10 @@ namespace Core.Inventory.Provider.Contracts /// /// Changes the status of a furniture base entity. /// - /// The entity identifier. + /// The entity identifier. /// The new status to apply. /// Cancellation token. /// The updated . - ValueTask ChangeStatusAsync(string id, StatusEnum newStatus, CancellationToken cancellationToken); + ValueTask ChangeStatusAsync(string _id, StatusEnum newStatus, CancellationToken cancellationToken); } } diff --git a/Core.Inventory.Provider/Contracts/IFurnitureVariantProvider.cs b/Core.Inventory.Provider/Contracts/IFurnitureVariantProvider.cs index ee3dbfa..bdbaf40 100644 --- a/Core.Inventory.Provider/Contracts/IFurnitureVariantProvider.cs +++ b/Core.Inventory.Provider/Contracts/IFurnitureVariantProvider.cs @@ -25,10 +25,18 @@ namespace Core.Inventory.Provider.Contracts /// /// Gets a furniture variant entity by its ID. /// - /// The unique identifier (_id) of the furniture variant. + /// The unique identifier (_id) of the furniture variant. /// Cancellation token. /// The corresponding . - ValueTask GetByIdAsync(string id, CancellationToken cancellationToken); + ValueTask GetByIdAsync(string _id, CancellationToken cancellationToken); + + /// + /// Retrieves all furniture variants by a list of variant IDs. + /// + /// Array of variant IDs. + /// Cancellation token. + /// A list of matching the specified IDs. + ValueTask> GetAllByIdsAsync(string[] ids, CancellationToken cancellationToken); /// /// Retrieves all furniture variants associated with a base model. @@ -50,10 +58,10 @@ namespace Core.Inventory.Provider.Contracts /// /// Changes the status of a furniture variant entity. /// - /// The entity identifier. + /// The entity identifier. /// The new status to apply. /// Cancellation token. /// The updated . - ValueTask ChangeStatusAsync(string id, StatusEnum newStatus, CancellationToken cancellationToken); + 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 index ebc0782..82fdd36 100644 --- a/Core.Inventory.Provider/Core.Inventory.Provider.csproj +++ b/Core.Inventory.Provider/Core.Inventory.Provider.csproj @@ -9,7 +9,7 @@ - + diff --git a/Core.Inventory.Provider/Providers/Inventory/FurnitureBaseProvider.cs b/Core.Inventory.Provider/Providers/Inventory/FurnitureBaseProvider.cs index ebe208e..fd57e96 100644 --- a/Core.Inventory.Provider/Providers/Inventory/FurnitureBaseProvider.cs +++ b/Core.Inventory.Provider/Providers/Inventory/FurnitureBaseProvider.cs @@ -83,17 +83,17 @@ namespace Core.Inventory.Provider.Providers.Inventory /// /// Gets a FurnitureBase entity by its ID. /// - /// The furniture base identifier. + /// The furniture base identifier. /// Cancellation token. /// The corresponding . - public async ValueTask GetByIdAsync(string id, CancellationToken cancellationToken) + public async ValueTask GetByIdAsync(string _id, CancellationToken cancellationToken) { - var cacheKey = CacheKeyHelper.GenerateCacheKey(this, nameof(GetByIdAsync), id); + 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); + var result = await repository.FindByIdAsync(_id); await cacheProvider.SetAsync(cacheKey, result); return result; } diff --git a/Core.Inventory.Provider/Providers/Inventory/FurnitureVariantProvider.cs b/Core.Inventory.Provider/Providers/Inventory/FurnitureVariantProvider.cs index 6a759d5..e1379c8 100644 --- a/Core.Inventory.Provider/Providers/Inventory/FurnitureVariantProvider.cs +++ b/Core.Inventory.Provider/Providers/Inventory/FurnitureVariantProvider.cs @@ -11,6 +11,7 @@ using Core.Inventory.Domain.Contexts.Inventory.Request; using Core.Inventory.Provider.Contracts; using Mapster; using Microsoft.Extensions.Options; +using MongoDB.Driver; namespace Core.Inventory.Provider.Providers.Inventory { @@ -38,13 +39,13 @@ namespace Core.Inventory.Provider.Providers.Inventory /// /// Changes the status of a FurnitureVariant entity. /// - /// The furniture variant identifier. + /// The furniture variant identifier. /// The new status to apply. /// Cancellation token. /// The updated . - public async ValueTask ChangeStatusAsync(string id, StatusEnum newStatus, CancellationToken cancellationToken) + public async ValueTask ChangeStatusAsync(string _id, StatusEnum newStatus, CancellationToken cancellationToken) { - var entity = await repository.FindByIdAsync(id); + var entity = await repository.FindByIdAsync(_id); entity.Status = newStatus; await repository.ReplaceOneAsync(entity); return entity; @@ -70,34 +71,62 @@ namespace Core.Inventory.Provider.Providers.Inventory /// A list of . public async ValueTask> GetAllByModelIdAsync(string modelId, CancellationToken cancellationToken) { - var cacheKey = CacheKeyHelper.GenerateCacheKey(this, nameof(GetAllByModelIdAsync)); + var cacheKey = CacheKeyHelper.GenerateCacheKey(this, nameof(GetAllByModelIdAsync), modelId); + var cachedData = await cacheProvider.GetAsync>(cacheKey); + if (cachedData is not null && cachedData.Any()) + return cachedData; - if (cachedData.Any()) return cachedData; + var filter = Builders.Filter.Eq(x => x.ModelId, modelId); + var variants = await repository.FilterByMongoFilterAsync(filter); - var data = await repository.AsQueryable(); - await cacheProvider.SetAsync(cacheKey, data); - return data; + if (variants is not null && variants.Any()) + await cacheProvider.SetAsync(cacheKey, variants); + + return variants ?? []; } /// /// Gets a FurnitureVariant entity by its ID. /// - /// The furniture variant identifier. + /// The furniture variant identifier. /// Cancellation token. /// The corresponding . - public async ValueTask GetByIdAsync(string id, CancellationToken cancellationToken) + public async ValueTask GetByIdAsync(string _id, CancellationToken cancellationToken) { - var cacheKey = CacheKeyHelper.GenerateCacheKey(this, nameof(GetByIdAsync), id); + 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); + var result = await repository.FindByIdAsync(_id); await cacheProvider.SetAsync(cacheKey, result); return result; } + /// + /// Retrieves all furniture variants by a list of variant IDs. + /// + /// Array of variant IDs. + /// Cancellation token. + /// A list of matching the specified IDs. + public async ValueTask> GetAllByIdsAsync(string[] ids, CancellationToken cancellationToken) + { + var cacheKey = CacheKeyHelper.GenerateCacheKey(this, nameof(GetAllByIdsAsync), ids); + + var cachedData = await cacheProvider.GetAsync>(cacheKey); + if (cachedData is not null && cachedData.Any()) + return cachedData; + + var filter = Builders.Filter.In(x => x.Id, ids); + var variants = await repository.FilterByMongoFilterAsync(filter); + + if (variants is not null && variants.Any()) + await cacheProvider.SetAsync(cacheKey, variants); + + return variants ?? []; + } + /// /// Updates a FurnitureVariant entity by ID. ///