Fixes in endpoints etc
This commit is contained in:
		| @@ -40,12 +40,12 @@ namespace Core.Inventory.DAL.API.Controllers | ||||
|         /// Gets a furniture base record by ID. | ||||
|         /// </summary> | ||||
|         [HttpGet] | ||||
|         [Route("{id}")] | ||||
|         [Route("{_id}")] | ||||
|         [ProducesResponseType(typeof(FurnitureBase), StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||
|         public async Task<IActionResult> GetByIdAsync([FromRoute] string id, CancellationToken cancellationToken) | ||||
|         public async Task<IActionResult> 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. | ||||
|         /// </summary> | ||||
|         [HttpPatch] | ||||
|         [Route("{id}/{newStatus}/ChangeStatus")] | ||||
|         [Route("{_id}/{newStatus}/ChangeStatus")] | ||||
|         [ProducesResponseType(typeof(FurnitureBase), StatusCodes.Status200OK)] | ||||
|         public async Task<IActionResult> ChangeStatusAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||
|         public async Task<IActionResult> 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); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -29,8 +29,9 @@ namespace Core.Inventory.DAL.API.Controllers | ||||
|         /// Gets all furniture variant records. | ||||
|         /// </summary> | ||||
|         [HttpGet] | ||||
|         [Route("ByModel/{modelId}")] | ||||
|         [ProducesResponseType(typeof(IEnumerable<FurnitureVariant>), StatusCodes.Status200OK)] | ||||
|         public async Task<IActionResult> GetAllVariantsByModelIdAsync([FromRoute] string modelId, CancellationToken cancellationToken) | ||||
|         public async Task<IActionResult> 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. | ||||
|         /// </summary> | ||||
|         [HttpGet] | ||||
|         [Route("{id}")] | ||||
|         [Route("{_id}")] | ||||
|         [ProducesResponseType(typeof(FurnitureVariant), StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||
|         public async Task<IActionResult> GetByIdAsync([FromRoute] string id, CancellationToken cancellationToken) | ||||
|         public async Task<IActionResult> 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"); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets multiple furniture variants by their identifiers. | ||||
|         /// </summary> | ||||
|         /// <param name="request">List of variant IDs.</param> | ||||
|         /// <param name="cancellationToken">Cancellation token.</param> | ||||
|         /// <returns>A list of <see cref="FurnitureVariant"/>.</returns> | ||||
|         [HttpPost("ByIds")] | ||||
|         [ProducesResponseType(typeof(IEnumerable<FurnitureVariant>), StatusCodes.Status200OK)] | ||||
|         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||
|         public async Task<IActionResult> 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); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new furniture variant. | ||||
|         /// </summary> | ||||
| @@ -86,11 +110,11 @@ namespace Core.Inventory.DAL.API.Controllers | ||||
|         /// Changes the status of a furniture variant record. | ||||
|         /// </summary> | ||||
|         [HttpPatch] | ||||
|         [Route("{id}/{newStatus}/ChangeStatus")] | ||||
|         [Route("{_id}/{newStatus}/ChangeStatus")] | ||||
|         [ProducesResponseType(typeof(FurnitureVariant), StatusCodes.Status200OK)] | ||||
|         public async Task<IActionResult> ChangeStatusAsync([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||
|         public async Task<IActionResult> 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); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -12,7 +12,7 @@ | ||||
|   }, | ||||
|   "MongoDb": { | ||||
|     "DatabaseName": "Inventory", | ||||
|     "LocalAudience": "" | ||||
|     "LocalAudience": "InventotyDev" | ||||
|   }, | ||||
|   "DetailedErrors": true, | ||||
|   "UseRedisCache": true, | ||||
|   | ||||
| @@ -12,7 +12,7 @@ | ||||
|   }, | ||||
|   "MongoDb": { | ||||
|     "DatabaseName": "Inventory", | ||||
|     "LocalAudience": "" | ||||
|     "LocalAudience": "InventotyLocal" | ||||
|   }, | ||||
|   "DetailedErrors": true, | ||||
|   "UseRedisCache": true, | ||||
|   | ||||
| @@ -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"; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets or sets the category identifier the item belongs to. | ||||
|   | ||||
| @@ -25,10 +25,10 @@ namespace Core.Inventory.Provider.Contracts | ||||
|         /// <summary> | ||||
|         /// Gets a furniture base entity by its ID. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The unique identifier (_id) of the furniture base.</param> | ||||
|         /// <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); | ||||
|         ValueTask<FurnitureBase> GetByIdAsync(string _id, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Retrieves all furniture base entries. | ||||
| @@ -49,10 +49,10 @@ namespace Core.Inventory.Provider.Contracts | ||||
|         /// <summary> | ||||
|         /// Changes the status of a furniture base entity. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The entity identifier.</param> | ||||
|         /// <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); | ||||
|         ValueTask<FurnitureBase> ChangeStatusAsync(string _id, StatusEnum newStatus, CancellationToken cancellationToken); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -25,10 +25,18 @@ namespace Core.Inventory.Provider.Contracts | ||||
|         /// <summary> | ||||
|         /// Gets a furniture variant entity by its ID. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The unique identifier (_id) of the furniture variant.</param> | ||||
|         /// <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); | ||||
|         ValueTask<FurnitureVariant> GetByIdAsync(string _id, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Retrieves all furniture variants by a list of variant IDs. | ||||
|         /// </summary> | ||||
|         /// <param name="ids">Array of variant IDs.</param> | ||||
|         /// <param name="cancellationToken">Cancellation token.</param> | ||||
|         /// <returns>A list of <see cref="FurnitureVariant"/> matching the specified IDs.</returns> | ||||
|         ValueTask<IEnumerable<FurnitureVariant>> GetAllByIdsAsync(string[] ids, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Retrieves all furniture variants associated with a base model. | ||||
| @@ -50,10 +58,10 @@ namespace Core.Inventory.Provider.Contracts | ||||
|         /// <summary> | ||||
|         /// Changes the status of a furniture variant entity. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The entity identifier.</param> | ||||
|         /// <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); | ||||
|         ValueTask<FurnitureVariant> ChangeStatusAsync(string _id, StatusEnum newStatus, CancellationToken cancellationToken); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -9,7 +9,7 @@ | ||||
|   <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="Core.Blueprint.Redis" Version="1.0.2" /> | ||||
|     <PackageReference Include="Mapster" Version="7.4.0" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   | ||||
| @@ -83,17 +83,17 @@ namespace Core.Inventory.Provider.Providers.Inventory | ||||
|         /// <summary> | ||||
|         /// Gets a FurnitureBase entity by its ID. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The furniture base identifier.</param> | ||||
|         /// <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) | ||||
|         public async ValueTask<FurnitureBase> 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<FurnitureBase>(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; | ||||
|         } | ||||
|   | ||||
| @@ -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 | ||||
|         /// <summary> | ||||
|         /// Changes the status of a FurnitureVariant entity. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The furniture variant identifier.</param> | ||||
|         /// <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) | ||||
|         public async ValueTask<FurnitureVariant> 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 | ||||
|         /// <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 cacheKey = CacheKeyHelper.GenerateCacheKey(this, nameof(GetAllByModelIdAsync), modelId); | ||||
|  | ||||
|             var cachedData = await cacheProvider.GetAsync<IEnumerable<FurnitureVariant>>(cacheKey); | ||||
|             if (cachedData is not null && cachedData.Any()) | ||||
|                 return cachedData; | ||||
|  | ||||
|             if (cachedData.Any()) return cachedData; | ||||
|             var filter = Builders<FurnitureVariant>.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 ?? []; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets a FurnitureVariant entity by its ID. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The furniture variant identifier.</param> | ||||
|         /// <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) | ||||
|         public async ValueTask<FurnitureVariant> 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<FurnitureVariant>(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; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Retrieves all furniture variants by a list of variant IDs. | ||||
|         /// </summary> | ||||
|         /// <param name="ids">Array of variant IDs.</param> | ||||
|         /// <param name="cancellationToken">Cancellation token.</param> | ||||
|         /// <returns>A list of <see cref="FurnitureVariant"/> matching the specified IDs.</returns> | ||||
|         public async ValueTask<IEnumerable<FurnitureVariant>> GetAllByIdsAsync(string[] ids, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, nameof(GetAllByIdsAsync), ids); | ||||
|  | ||||
|             var cachedData = await cacheProvider.GetAsync<IEnumerable<FurnitureVariant>>(cacheKey); | ||||
|             if (cachedData is not null && cachedData.Any()) | ||||
|                 return cachedData; | ||||
|  | ||||
|             var filter = Builders<FurnitureVariant>.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 ?? []; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a FurnitureVariant entity by ID. | ||||
|         /// </summary> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user