Added new endpoint for variants and temporal fix for reset cache
This commit is contained in:
parent
55475e0f97
commit
9effaf3b22
@ -25,10 +25,22 @@ namespace Core.Inventory.DAL.API.Controllers
|
|||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public class FurnitureVariantController(IFurnitureVariantProvider service) : ControllerBase
|
public class FurnitureVariantController(IFurnitureVariantProvider service) : ControllerBase
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets all furniture variant records.
|
/// Gets all furniture variant records.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<FurnitureVariant>), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetAllAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.GetAllAsync(cancellationToken);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all furniture variant records by ModelId.
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet]
|
||||||
[Route("ByModel/{modelId}")]
|
[Route("ByModel/{modelId}")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<FurnitureVariant>), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(IEnumerable<FurnitureVariant>), StatusCodes.Status200OK)]
|
||||||
public async Task<IActionResult> GetAllVariantsByModelIdAsync(string modelId, CancellationToken cancellationToken)
|
public async Task<IActionResult> GetAllVariantsByModelIdAsync(string modelId, CancellationToken cancellationToken)
|
||||||
|
|||||||
@ -63,5 +63,12 @@ namespace Core.Inventory.Provider.Contracts
|
|||||||
/// <param name="cancellationToken">Cancellation token.</param>
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
/// <returns>The updated <see cref="FurnitureVariant"/>.</returns>
|
/// <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);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves all furniture variant entities.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
|
/// <returns>A list of all <see cref="FurnitureVariant"/> entities.</returns>
|
||||||
|
ValueTask<IEnumerable<FurnitureVariant>> GetAllAsync(CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,6 +47,7 @@ namespace Core.Inventory.Provider.Providers.Inventory
|
|||||||
var entity = await repository.FindByIdAsync(mongoId);
|
var entity = await repository.FindByIdAsync(mongoId);
|
||||||
entity.Status = newStatus;
|
entity.Status = newStatus;
|
||||||
await repository.ReplaceOneAsync(entity);
|
await repository.ReplaceOneAsync(entity);
|
||||||
|
await ResetCollectionCache();
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,6 +61,7 @@ namespace Core.Inventory.Provider.Providers.Inventory
|
|||||||
{
|
{
|
||||||
var furnitureCollection = newFurniture.Adapt<FurnitureBase>();
|
var furnitureCollection = newFurniture.Adapt<FurnitureBase>();
|
||||||
await repository.InsertOneAsync(furnitureCollection);
|
await repository.InsertOneAsync(furnitureCollection);
|
||||||
|
await ResetCollectionCache();
|
||||||
return furnitureCollection;
|
return furnitureCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +110,20 @@ namespace Core.Inventory.Provider.Providers.Inventory
|
|||||||
public async ValueTask<FurnitureBase> UpdateAsync(string id, FurnitureBase entity, CancellationToken cancellationToken)
|
public async ValueTask<FurnitureBase> UpdateAsync(string id, FurnitureBase entity, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
await repository.ReplaceOneAsync(entity);
|
await repository.ReplaceOneAsync(entity);
|
||||||
|
await ResetCollectionCache();
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Temporary method to "reset" collections cache
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task ResetCollectionCache()
|
||||||
|
{
|
||||||
|
//TODO: remove this method when necessary.
|
||||||
|
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllFurnitureBases");
|
||||||
|
|
||||||
|
await cacheProvider.SetAsync(cacheKey, Enumerable.Empty<FurnitureBase>(), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,6 +48,7 @@ namespace Core.Inventory.Provider.Providers.Inventory
|
|||||||
var entity = await repository.FindByIdAsync(mongoId);
|
var entity = await repository.FindByIdAsync(mongoId);
|
||||||
entity.Status = newStatus;
|
entity.Status = newStatus;
|
||||||
await repository.ReplaceOneAsync(entity);
|
await repository.ReplaceOneAsync(entity);
|
||||||
|
await ResetCollectionCache();
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,6 +62,7 @@ namespace Core.Inventory.Provider.Providers.Inventory
|
|||||||
{
|
{
|
||||||
var variantCollection = newVariant.Adapt<FurnitureVariant>();
|
var variantCollection = newVariant.Adapt<FurnitureVariant>();
|
||||||
await repository.InsertOneAsync(variantCollection);
|
await repository.InsertOneAsync(variantCollection);
|
||||||
|
await ResetCollectionCache();
|
||||||
return variantCollection;
|
return variantCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +139,37 @@ namespace Core.Inventory.Provider.Providers.Inventory
|
|||||||
public async ValueTask<FurnitureVariant> UpdateAsync(string id, FurnitureVariant entity, CancellationToken cancellationToken)
|
public async ValueTask<FurnitureVariant> UpdateAsync(string id, FurnitureVariant entity, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
await repository.ReplaceOneAsync(entity);
|
await repository.ReplaceOneAsync(entity);
|
||||||
|
await ResetCollectionCache();
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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>> GetAllAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, nameof(GetAllAsync));
|
||||||
|
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>
|
||||||
|
/// Temporary method to "reset" collections cache
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task ResetCollectionCache()
|
||||||
|
{
|
||||||
|
//TODO: remove this method when necessary.
|
||||||
|
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllFurnitureVariants");
|
||||||
|
|
||||||
|
await cacheProvider.SetAsync(cacheKey, Enumerable.Empty<FurnitureVariant>(), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user