Compare commits
17 Commits
e191851982
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c9fecb909 | ||
| 88d3d46cd7 | |||
|
|
b60c6894bc | ||
| af51189640 | |||
| 1818de98c0 | |||
|
|
6146fcfed2 | ||
| 97992e5cdb | |||
| 12fe25e71e | |||
| e1612e4301 | |||
| 17c94d1095 | |||
|
|
38f097f5e6 | ||
| 827b0d8f03 | |||
| a706f96bd8 | |||
| 1f9bae385c | |||
|
|
53a420ffd1 | ||
| 406ff07f62 | |||
|
|
54dd38cfd6 |
12
.dockerignore
Normal file
12
.dockerignore
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
**/bin
|
||||||
|
**/obj
|
||||||
|
**/out
|
||||||
|
**/.vs
|
||||||
|
**/.idea
|
||||||
|
**/.git
|
||||||
|
**/.gitignore
|
||||||
|
**/node_modules
|
||||||
|
*.user
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
.DS_Store
|
||||||
231
Core.Inventory.DAL.API/Controllers/ProductController.cs
Normal file
231
Core.Inventory.DAL.API/Controllers/ProductController.cs
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
using Asp.Versioning;
|
||||||
|
using Core.Adapters.Lib.Inventory;
|
||||||
|
using Core.Blueprint.Logging;
|
||||||
|
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 Product operations.
|
||||||
|
/// </summary>
|
||||||
|
[ApiVersion(MimeTypes.ApplicationVersion)]
|
||||||
|
[Route("api/v{api-version:apiVersion}/[controller]")]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[ApiController]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class ProductController(IProductProvider service) : ControllerBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the Products.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="IEnumerable{ProductAdapter}"/> found entities.</returns>
|
||||||
|
/// <response code="200">The products found.</response>
|
||||||
|
/// <response code="404">The products not found error.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpGet]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<ProductAdapter>), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetAllProductsAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.GetAllProducts(cancellationToken).ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the Products by Product identifiers.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="products">The list of Product identifiers.</param>
|
||||||
|
/// <returns>The <see cref="IEnumerable{ProductAdapter}"/> found entities.</returns>
|
||||||
|
/// <response code="200">The Products found.</response>
|
||||||
|
/// <response code="404">The Products not found error.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpPost]
|
||||||
|
[Route("GetProductList")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<ProductAdapter>), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetAllProductsByList([FromBody] string[] products, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (products == null || !products.Any())
|
||||||
|
{
|
||||||
|
return BadRequest("Product identifiers are required.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await service.GetAllProductsByList(products, cancellationToken).ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Product by identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The Product identifier.</param>
|
||||||
|
/// <returns>The <see cref="ProductAdapter"/> found entity.</returns>
|
||||||
|
/// <response code="200">The Product found.</response>
|
||||||
|
/// <response code="404">The Product not found error.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpGet]
|
||||||
|
[Route("{id}")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(ProductAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetProductByIdAsync([FromRoute] string id, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.GetProductById(id, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
|
{
|
||||||
|
return NotFound("Entity not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new Product.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="newProduct">The Product to be added.</param>
|
||||||
|
/// <returns>The <see cref="ProductAdapter"/> created entity.</returns>
|
||||||
|
/// <response code="201">The Product created.</response>
|
||||||
|
/// <response code="422">The Product could not be created.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpPost]
|
||||||
|
[ProducesResponseType(typeof(ProductAdapter), StatusCodes.Status201Created)]
|
||||||
|
public async Task<IActionResult> CreateProductAsync([FromBody] ProductRequest newProduct, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.CreateProduct(newProduct, cancellationToken).ConfigureAwait(false);
|
||||||
|
return Created("CreatedWithIdAsync", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a full Product by identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The Product to update.</param>
|
||||||
|
/// <param name="id">The Product identifier.</param>
|
||||||
|
/// <returns>The <see cref="ProductAdapter"/> updated entity.</returns>
|
||||||
|
/// <response code="200">The Product updated.</response>
|
||||||
|
/// <response code="404">The Product not found.</response>
|
||||||
|
/// <response code="422">The Product could not be updated.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpPut]
|
||||||
|
[Route("{id}")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(ProductAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> UpdateProductAsync([FromRoute] string id, ProductAdapter entity, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (id != entity.Id?.ToString())
|
||||||
|
{
|
||||||
|
return BadRequest("Product ID mismatch");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await service.UpdateProduct(entity, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the status of the Product.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The Product identifier.</param>
|
||||||
|
/// <param name="newStatus">The new status of the Product.</param>
|
||||||
|
/// <returns>The <see cref="ProductAdapter"/> updated entity.</returns>
|
||||||
|
/// <response code="200">The Product updates.</response>
|
||||||
|
/// <response code="404">The Product not found.</response>
|
||||||
|
/// <response code="422">The Product could not be deleted.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpPatch]
|
||||||
|
[Route("{id}/{newStatus}/ChangeStatus")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(ProductAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> ChangeProductStatus([FromRoute] string id, [FromRoute] ProductStatus newStatus, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.ChangeProductStatus(id, newStatus, cancellationToken).ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a tag to the product.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="productId">The Product identifier.</param>
|
||||||
|
/// <param name="tagId">The Tag identifier to add.</param>
|
||||||
|
/// <returns>The <see cref="ProductAdapter"/> updated entity.</returns>
|
||||||
|
/// <response code="200">The tag added to product.</response>
|
||||||
|
/// <response code="404">The Product not found.</response>
|
||||||
|
/// <response code="422">The tag could not be added.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpPost]
|
||||||
|
[Route("{productId}/tags/{tagId}")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(ProductAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> AddTagToProduct([FromRoute] string productId, [FromRoute] string tagId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.AddTagToProduct(productId, tagId, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
|
{
|
||||||
|
return NotFound("Product not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a tag from the product.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="productId">The Product identifier.</param>
|
||||||
|
/// <param name="tagId">The Tag identifier to remove.</param>
|
||||||
|
/// <returns>The <see cref="ProductAdapter"/> updated entity.</returns>
|
||||||
|
/// <response code="200">The tag removed from product.</response>
|
||||||
|
/// <response code="404">The Product not found.</response>
|
||||||
|
/// <response code="422">The tag could not be removed.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpDelete]
|
||||||
|
[Route("{productId}/tags/{tagId}")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(ProductAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> RemoveTagFromProduct([FromRoute] string productId, [FromRoute] string tagId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.RemoveTagFromProduct(productId, tagId, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
|
{
|
||||||
|
return NotFound("Product not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a Product by its MongoDB identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The Product MongoDB identifier.</param>
|
||||||
|
/// <returns>The result of the delete operation.</returns>
|
||||||
|
/// <response code="200">The Product deleted successfully.</response>
|
||||||
|
/// <response code="404">The Product not found.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpDelete]
|
||||||
|
[Route("{id}")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> DeleteProduct([FromRoute] string id, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.DeleteProduct(id, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return NotFound("Product not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
212
Core.Inventory.DAL.API/Controllers/TagController.cs
Normal file
212
Core.Inventory.DAL.API/Controllers/TagController.cs
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
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 Tag authentication.
|
||||||
|
/// </summary>
|
||||||
|
[ApiVersion(MimeTypes.ApplicationVersion)]
|
||||||
|
[Route("api/v{api-version:apiVersion}/[controller]")]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[ApiController]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class TagController(ITagProvider service) : ControllerBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the Tags.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="IEnumerable{TagAdapter}"/> found entities.</returns>
|
||||||
|
/// <response code="200">The Tags found.</response>
|
||||||
|
/// <response code="404">The Tags not found error.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpGet]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<TagAdapter>), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetAllTagsAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.GetAllTags(cancellationToken).ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the Tags by Tag identifiers.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Tags">The list of Tag identifiers.</param>
|
||||||
|
/// <returns>The <see cref="IEnumerable{TagAdapter}"/> found entities.</returns>
|
||||||
|
/// <response code="200">The Tags found.</response>
|
||||||
|
/// <response code="404">The Tags not found error.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpPost]
|
||||||
|
[Route("GetTagList")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<TagAdapter>), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetAllTagsByList([FromBody] string[] tags, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (tags == null || !tags.Any())
|
||||||
|
{
|
||||||
|
return BadRequest("Tag identifiers are required.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await service.GetAllTagsByList(tags, cancellationToken).ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Tag by identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The Tag identifier.</param>
|
||||||
|
/// <returns>The <see cref="TagAdapter"/> found entity.</returns>
|
||||||
|
/// <response code="200">The Tag found.</response>
|
||||||
|
/// <response code="404">The Tag not found error.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpGet]
|
||||||
|
[Route("{id}")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(TagAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetTagByIdAsync([FromRoute] string id, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.GetTagById(id, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
|
{
|
||||||
|
return NotFound("Entity not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new Tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="newTag">The Tag to be added.</param>
|
||||||
|
/// <returns>The <see cref="TagAdapter"/> created entity.</returns>
|
||||||
|
/// <response code="201">The Tag created.</response>
|
||||||
|
/// <response code="422">The Tag could not be created.</response>
|
||||||
|
/// <response code="500">The service internal e|ror.</response>
|
||||||
|
[HttpPost]
|
||||||
|
[ProducesResponseType(typeof(TagAdapter), StatusCodes.Status201Created)]
|
||||||
|
public async Task<IActionResult> CreateTagAsync([FromBody] TagRequest newTag, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.CreateTag(newTag, cancellationToken).ConfigureAwait(false);
|
||||||
|
return Created("CreatedWithIdAsync", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a full Tag by identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The Tag to update.</param>
|
||||||
|
/// <param name="id">The Tag identifier.</param>
|
||||||
|
/// <returns>The <see cref="TagAdapter"/> updated entity.</returns>
|
||||||
|
/// <response code="200">The Tag updated.</response>
|
||||||
|
/// <response code="404">The Tag not found.</response>
|
||||||
|
/// <response code="422">The Tag could not be updated.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpPut]
|
||||||
|
[Route("{id}")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(TagAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> UpdateTagAsync([FromRoute] string id, TagAdapter entity, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (id != entity.Id?.ToString())
|
||||||
|
{
|
||||||
|
return BadRequest("Tag ID mismatch");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await service.UpdateTag(entity, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the status of the Tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The Tag identifier.</param>
|
||||||
|
/// <param name="newStatus">The new status of the Tag.</param>
|
||||||
|
/// <returns>The <see cref="TagAdapter"/> updated entity.</returns>
|
||||||
|
/// <response code="200">The Tag updates.</response>
|
||||||
|
/// <response code="404">The Tag not found.</response>
|
||||||
|
/// <response code="422">The Tag could not be deleted.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpPatch]
|
||||||
|
[Route("{id}/{newStatus}/ChangeStatus")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(TagAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> ChangeTagStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.ChangeTagStatus(id, newStatus, cancellationToken).ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a parentTag to the tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tagId">The tag identifier.</param>
|
||||||
|
/// <param name="parentTagId">The parentTag identifier to add.</param>
|
||||||
|
/// <returns>The updated <see cref="TagAdapter"/> entity.</returns>
|
||||||
|
/// <response code="200">The tag with the updated parentTags.</response>
|
||||||
|
/// <response code="404">The tag or parentTag not found.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpPost]
|
||||||
|
[Route("{tagId}/ParentTags/{parentTagId}/Add")]
|
||||||
|
[ProducesResponseType(typeof(TagAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> AddParentTagAsync([FromRoute] string tagId, [FromRoute] string parentTagId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.AddParentTag(tagId, parentTagId, cancellationToken).ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove a parentTag to the tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tagId">The tag identifier.</param>
|
||||||
|
/// <param name="parentTagId">The parentTag identifier to remove.</param>
|
||||||
|
/// <returns>The updated <see cref="TagAdapter"/> entity.</returns>
|
||||||
|
/// <response code="200">The tag with the updated parentTags.</response>
|
||||||
|
/// <response code="404">The tag or parentTag not found.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpDelete]
|
||||||
|
[Route("{tagId}/ParentTags/{parentTagId}/Remove")]
|
||||||
|
[ProducesResponseType(typeof(TagAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> RemoveParentTagAsync([FromRoute] string tagId, [FromRoute] string parentTagId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.RemoveParentTag(tagId, parentTagId, cancellationToken).ConfigureAwait(false); ;
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a Tag by its MongoDB identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The Tag MongoDB identifier.</param>
|
||||||
|
/// <returns>The result of the delete operation.</returns>
|
||||||
|
/// <response code="200">The Tag deleted successfully.</response>
|
||||||
|
/// <response code="404">The Tag not found.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpDelete]
|
||||||
|
[Route("{id}")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(TagAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> DeleteTag([FromRoute] string id, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.DeleteTag(id, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (result is null) return NotFound("Tag not found");
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
176
Core.Inventory.DAL.API/Controllers/TagOverrideController.cs
Normal file
176
Core.Inventory.DAL.API/Controllers/TagOverrideController.cs
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
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 TagOverride authentication.
|
||||||
|
/// </summary>
|
||||||
|
[ApiVersion(MimeTypes.ApplicationVersion)]
|
||||||
|
[Route("api/v{api-version:apiVersion}/[controller]")]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[ApiController]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class TagOverrideController(ITagOverrideProvider service) : ControllerBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the TagOverrides.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="IEnumerable{TagOverrideAdapter}"/> found entities.</returns>
|
||||||
|
/// <response code="200">The TagOverrides found.</response>
|
||||||
|
/// <response code="404">The TagOverrides not found error.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpGet]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<TagOverrideAdapter>), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetAllTagOverridesAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.GetAllTagOverrides(cancellationToken).ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the TagOverrides by TagOverride identifiers.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="TagOverrides">The list of TagOverride identifiers.</param>
|
||||||
|
/// <returns>The <see cref="IEnumerable{TagOverrideAdapter}"/> found entities.</returns>
|
||||||
|
/// <response code="200">The TagOverrides found.</response>
|
||||||
|
/// <response code="404">The TagOverrides not found error.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpPost]
|
||||||
|
[Route("GetTagOverrideList")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<TagOverrideAdapter>), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetAllTagOverridesByList([FromBody] string[] tagOverrides, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (tagOverrides == null || !tagOverrides.Any())
|
||||||
|
{
|
||||||
|
return BadRequest("TagOverride identifiers are required.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await service.GetAllTagOverridesByList(tagOverrides, cancellationToken).ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the TagOverride by identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The TagOverride identifier.</param>
|
||||||
|
/// <returns>The <see cref="TagOverrideAdapter"/> found entity.</returns>
|
||||||
|
/// <response code="200">The TagOverride found.</response>
|
||||||
|
/// <response code="404">The TagOverride not found error.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpGet]
|
||||||
|
[Route("{id}")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(TagOverrideAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetTagOverrideByIdAsync([FromRoute] string id, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.GetTagOverrideById(id, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
|
{
|
||||||
|
return NotFound("Entity not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new TagOverride.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="newTagOverride">The TagOverride to be added.</param>
|
||||||
|
/// <returns>The <see cref="TagOverrideAdapter"/> created entity.</returns>
|
||||||
|
/// <response code="201">The TagOverride created.</response>
|
||||||
|
/// <response code="422">The TagOverride could not be created.</response>
|
||||||
|
/// <response code="500">The service internal e|ror.</response>
|
||||||
|
[HttpPost]
|
||||||
|
[ProducesResponseType(typeof(TagOverrideAdapter), StatusCodes.Status201Created)]
|
||||||
|
public async Task<IActionResult> CreateTagOverrideAsync([FromBody] TagOverrideRequest newTagOverride, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.CreateTagOverride(newTagOverride, cancellationToken).ConfigureAwait(false);
|
||||||
|
return Created("CreatedWithIdAsync", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a full TagOverride by identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The TagOverride to update.</param>
|
||||||
|
/// <param name="id">The TagOverride identifier.</param>
|
||||||
|
/// <returns>The <see cref="TagOverrideAdapter"/> updated entity.</returns>
|
||||||
|
/// <response code="200">The TagOverride updated.</response>
|
||||||
|
/// <response code="404">The TagOverride not found.</response>
|
||||||
|
/// <response code="422">The TagOverride could not be updated.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpPut]
|
||||||
|
[Route("{id}")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(TagOverrideAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> UpdateTagOverrideAsync([FromRoute] string id, TagOverrideAdapter entity, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (id != entity.Id?.ToString())
|
||||||
|
{
|
||||||
|
return BadRequest("TagOverride ID mismatch");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await service.UpdateTagOverride(entity, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the status of the TagOverride.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The TagOverride identifier.</param>
|
||||||
|
/// <param name="newStatus">The new status of the TagOverride.</param>
|
||||||
|
/// <returns>The <see cref="TagOverrideAdapter"/> updated entity.</returns>
|
||||||
|
/// <response code="200">The TagOverride updates.</response>
|
||||||
|
/// <response code="404">The TagOverride not found.</response>
|
||||||
|
/// <response code="422">The TagOverride could not be deleted.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpPatch]
|
||||||
|
[Route("{id}/{newStatus}/ChangeStatus")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(TagOverrideAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> ChangeTagOverrideStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.ChangeTagOverrideStatus(id, newStatus, cancellationToken).ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a TagOverride by its MongoDB identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The TagOverride MongoDB identifier.</param>
|
||||||
|
/// <returns>The result of the delete operation.</returns>
|
||||||
|
/// <response code="200">The TagOverride deleted successfully.</response>
|
||||||
|
/// <response code="404">The TagOverride not found.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpDelete]
|
||||||
|
[Route("{id}")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(TagOverrideAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> DeleteTagOverride([FromRoute] string id, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.DeleteTagOverride(id, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (result is null) return NotFound("TagOverride not found");
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
176
Core.Inventory.DAL.API/Controllers/TagTypeController.cs
Normal file
176
Core.Inventory.DAL.API/Controllers/TagTypeController.cs
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
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 TagType authentication.
|
||||||
|
/// </summary>
|
||||||
|
[ApiVersion(MimeTypes.ApplicationVersion)]
|
||||||
|
[Route("api/v{api-version:apiVersion}/[controller]")]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[ApiController]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class TagTypeController(ITagTypeProvider service) : ControllerBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the TagTypes.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="IEnumerable{TagTypeAdapter}"/> found entities.</returns>
|
||||||
|
/// <response code="200">The tagTypes found.</response>
|
||||||
|
/// <response code="404">The tagTypes not found error.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpGet]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<TagTypeAdapter>), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetAllTagTypesAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.GetAllTagTypes(cancellationToken).ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the TagTypes by TagType identifiers.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="TagTypes">The list of TagType identifiers.</param>
|
||||||
|
/// <returns>The <see cref="IEnumerable{TagTypeAdapter}"/> found entities.</returns>
|
||||||
|
/// <response code="200">The TagTypes found.</response>
|
||||||
|
/// <response code="404">The TagTypes not found error.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpPost]
|
||||||
|
[Route("GetTagTypeList")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<TagTypeAdapter>), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetAllTagTypesByList([FromBody] string[] tagTypes, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (tagTypes == null || !tagTypes.Any())
|
||||||
|
{
|
||||||
|
return BadRequest("TagType identifiers are required.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await service.GetAllTagTypesByList(tagTypes, cancellationToken).ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the TagType by identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The TagType identifier.</param>
|
||||||
|
/// <returns>The <see cref="TagTypeAdapter"/> found entity.</returns>
|
||||||
|
/// <response code="200">The TagType found.</response>
|
||||||
|
/// <response code="404">The TagType not found error.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpGet]
|
||||||
|
[Route("{id}")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(TagTypeAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetTagTypeByIdAsync([FromRoute] string id, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.GetTagTypeById(id, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
|
{
|
||||||
|
return NotFound("Entity not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new TagType.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="newTagType">The TagType to be added.</param>
|
||||||
|
/// <returns>The <see cref="TagTypeAdapter"/> created entity.</returns>
|
||||||
|
/// <response code="201">The TagType created.</response>
|
||||||
|
/// <response code="422">The TagType could not be created.</response>
|
||||||
|
/// <response code="500">The service internal e|ror.</response>
|
||||||
|
[HttpPost]
|
||||||
|
[ProducesResponseType(typeof(TagTypeAdapter), StatusCodes.Status201Created)]
|
||||||
|
public async Task<IActionResult> CreateTagTypeAsync([FromBody] TagTypeRequest newTagType, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.CreateTagType(newTagType, cancellationToken).ConfigureAwait(false);
|
||||||
|
return Created("CreatedWithIdAsync", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a full TagType by identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The TagType to update.</param>
|
||||||
|
/// <param name="id">The TagType identifier.</param>
|
||||||
|
/// <returns>The <see cref="TagTypeAdapter"/> updated entity.</returns>
|
||||||
|
/// <response code="200">The TagType updated.</response>
|
||||||
|
/// <response code="404">The TagType not found.</response>
|
||||||
|
/// <response code="422">The TagType could not be updated.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpPut]
|
||||||
|
[Route("{id}")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(TagTypeAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> UpdateTagTypeAsync([FromRoute] string id, TagTypeAdapter entity, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (id != entity.Id?.ToString())
|
||||||
|
{
|
||||||
|
return BadRequest("TagType ID mismatch");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await service.UpdateTagType(entity, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the status of the TagType.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The TagType identifier.</param>
|
||||||
|
/// <param name="newStatus">The new status of the TagType.</param>
|
||||||
|
/// <returns>The <see cref="TagTypeAdapter"/> updated entity.</returns>
|
||||||
|
/// <response code="200">The TagType updates.</response>
|
||||||
|
/// <response code="404">The TagType not found.</response>
|
||||||
|
/// <response code="422">The TagType could not be deleted.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpPatch]
|
||||||
|
[Route("{id}/{newStatus}/ChangeStatus")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(TagTypeAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> ChangeTagTypeStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.ChangeTagTypeStatus(id, newStatus, cancellationToken).ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a TagType by its MongoDB identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The TagType MongoDB identifier.</param>
|
||||||
|
/// <returns>The result of the delete operation.</returns>
|
||||||
|
/// <response code="200">The TagType deleted successfully.</response>
|
||||||
|
/// <response code="404">The TagType not found.</response>
|
||||||
|
/// <response code="500">The service internal error.</response>
|
||||||
|
[HttpDelete]
|
||||||
|
[Route("{id}")]
|
||||||
|
[Consumes(MimeTypes.ApplicationJson)]
|
||||||
|
[Produces(MimeTypes.ApplicationJson)]
|
||||||
|
[ProducesResponseType(typeof(TagTypeAdapter), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> DeleteTagType([FromRoute] string id, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await service.DeleteTagType(id, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (result is null) return NotFound("TagType not found");
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
|
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
|
||||||
<PackageReference Include="Core.Blueprint.Logging" Version="1.0.1" />
|
<PackageReference Include="Core.Blueprint.Logging" Version="1.0.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
"LocalAudience": "InventotyLocal"
|
"LocalAudience": "InventotyLocal"
|
||||||
},
|
},
|
||||||
"DetailedErrors": true,
|
"DetailedErrors": true,
|
||||||
"UseRedisCache": true,
|
"UseRedisCache": false,
|
||||||
"CacheSettings": {
|
"CacheSettings": {
|
||||||
"DefaultCacheDurationInMinutes": 3
|
"DefaultCacheDurationInMinutes": 3
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -76,6 +76,14 @@ namespace Core.Inventory.Domain.Contexts.Inventory.Request
|
|||||||
[BsonRepresentation(BsonType.String)]
|
[BsonRepresentation(BsonType.String)]
|
||||||
[JsonPropertyName("variantIds")]
|
[JsonPropertyName("variantIds")]
|
||||||
public List<string>? VariantIds { get; set; }
|
public List<string>? VariantIds { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the icon of the FurnitureBase.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("icon")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("icon")]
|
||||||
|
public string Icon { get; set; } = null!;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -49,5 +49,13 @@ namespace Core.Inventory.Domain.Contexts.Inventory.Request
|
|||||||
[BsonRepresentation(BsonType.String)]
|
[BsonRepresentation(BsonType.String)]
|
||||||
[JsonPropertyName("line")]
|
[JsonPropertyName("line")]
|
||||||
public string? Line { get; set; }
|
public string? Line { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the icon of the FurnitureVariant.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("icon")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("icon")]
|
||||||
|
public string Icon { get; set; } = null!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
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 adding product.
|
||||||
|
/// </summary>
|
||||||
|
public class ProductRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the tenantId of the product.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("tenantId")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("tenantId")]
|
||||||
|
public string TenantId { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the name of the product.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("productName")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("productName")]
|
||||||
|
public string ProductName { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the description of the product.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("description")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("description")]
|
||||||
|
public string Description { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the productStatus of the product.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("productStatus")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("productStatus")]
|
||||||
|
public string ProductStatus { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the list of Tag Ids associated with this product.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("tagIds")]
|
||||||
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
|
[JsonPropertyName("tagIds")]
|
||||||
|
public List<string> TagIds { get; set; } = new List<string>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
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 adding TagOverride.
|
||||||
|
/// </summary>
|
||||||
|
public class TagOverrideRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the tenantId of the TagOverride.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("tenantId")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("tenantId")]
|
||||||
|
public string TenantId { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the baseTagId of the TagOverride.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("baseTagId")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("baseTagId")]
|
||||||
|
public string BaseTagId { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the overrideTagId of the TagOverride.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("overrideTagId")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("overrideTagId")]
|
||||||
|
public string OverrideTagId { get; set; } = null!;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
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 adding Tag.
|
||||||
|
/// </summary>
|
||||||
|
public class TagRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the tenantId of the Tag.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("tenantId")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("tenantId")]
|
||||||
|
public string TenantId { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the name of the Tag.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("tagName")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("tagName")]
|
||||||
|
public string TagName { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the typeId of the Tag.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("typeId")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("typeId")]
|
||||||
|
public string TypeId { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the parentTagId of the Tag.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("parentTagId")]
|
||||||
|
[JsonPropertyName("parentTagId")]
|
||||||
|
public string[] ParentTagId { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the slug of the Tag.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("slug")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("slug")]
|
||||||
|
public string Slug { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the displayOrder of the Tag.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("displayOrder")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("displayOrder")]
|
||||||
|
public int DisplayOrder { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the icon of the Tag.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("icon")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("icon")]
|
||||||
|
public string Icon { get; set; } = null!;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
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 adding tagType.
|
||||||
|
/// </summary>
|
||||||
|
public class TagTypeRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the tenantId of the tagType.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("tenantId")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("tenantId")]
|
||||||
|
public string TenantId { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the typeName of the tagType.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("typeName")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("typeName")]
|
||||||
|
public string TypeName { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the level of the tagType.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("level")]
|
||||||
|
[BsonRepresentation(BsonType.Int32)]
|
||||||
|
[JsonPropertyName("level")]
|
||||||
|
public int Level { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the parentTypeId of the tagType.
|
||||||
|
/// </summary>
|
||||||
|
[BsonElement("parentTypeId")]
|
||||||
|
[BsonRepresentation(BsonType.String)]
|
||||||
|
[JsonPropertyName("parentTypeId")]
|
||||||
|
public string ParentTypeId { get; set; } = null!;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="BuildingBlocks.Library" Version="1.0.0" />
|
<PackageReference Include="Lib.Architecture.BuildingBlocks" Version="1.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
85
Core.Inventory.Provider/Contracts/IProductProvider.cs
Normal file
85
Core.Inventory.Provider/Contracts/IProductProvider.cs
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
using Core.Adapters.Lib.Inventory;
|
||||||
|
using Core.Blueprint.Mongo;
|
||||||
|
using Core.Inventory.Domain.Contexts.Inventory.Request;
|
||||||
|
|
||||||
|
namespace Core.Inventory.Provider.Contracts
|
||||||
|
{
|
||||||
|
public interface IProductProvider
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new Product.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The Product to be created.</param>
|
||||||
|
/// <returns>A <see cref="{Task{ProductAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<ProductAdapter> CreateProduct(ProductRequest newProduct, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a Product by identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The Product identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{ProductAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<ProductAdapter> GetProductById(string _id, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the products.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A <see cref="{Task{IEnumerable{ProductAdapter}}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<IEnumerable<ProductAdapter>> GetAllProducts(CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the products by products identifier list.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="products">The list of products identifiers.</param>
|
||||||
|
/// <returns>A <see cref="Task{IEnumerable{ProductAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<IEnumerable<ProductAdapter>> GetAllProductsByList(string[] products, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the status of the product.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The product identifier.</param>
|
||||||
|
/// <param name="newStatus">The new status of the product.</param>
|
||||||
|
/// <returns>The <see cref="ProductAdapter"/> updated entity.</returns>
|
||||||
|
/// <returns>A <see cref="{Task{ProductAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<ProductAdapter> ChangeProductStatus(string id, ProductStatus newStatus, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a Product by id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The Product to be updated.</param>
|
||||||
|
/// <param name="id">The Product identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{ProductAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<ProductAdapter> UpdateProduct(ProductAdapter entity, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a tag to the product.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="productId">The ID of the product.</param>
|
||||||
|
/// <param name="tagId">The ID of the tag to add.</param>
|
||||||
|
/// <returns>A <see cref="{Task{ProductAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<ProductAdapter> AddTagToProduct(string productId, string tagId, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a tag from the product.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="productId">The ID of the product.</param>
|
||||||
|
/// <param name="tagId">The ID of the tag to remove.</param>
|
||||||
|
/// <returns>A <see cref="{Task{ProductAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<ProductAdapter> RemoveTagFromProduct(string productId, string tagId, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a Product by its MongoDB identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="productId">The Product MongoDB identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{bool}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<bool> DeleteProduct(string productId, CancellationToken cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
67
Core.Inventory.Provider/Contracts/ITagOverrideProvider.cs
Normal file
67
Core.Inventory.Provider/Contracts/ITagOverrideProvider.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
using Core.Adapters.Lib;
|
||||||
|
using Core.Blueprint.Mongo;
|
||||||
|
using Core.Inventory.Domain.Contexts.Inventory.Request;
|
||||||
|
|
||||||
|
namespace Core.Inventory.Provider.Contracts
|
||||||
|
{
|
||||||
|
public interface ITagOverrideProvider
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new TagOverride.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The TagOverride to be created.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagOverrideAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<TagOverrideAdapter> CreateTagOverride(TagOverrideRequest newTagOverride, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets an TagOverride by identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The TagOverride identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagOverrideAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<TagOverrideAdapter> GetTagOverrideById(string _id, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the TagOverrides.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A <see cref="{Task{IEnumerbale{TagOverrideAdapter}}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<IEnumerable<TagOverrideAdapter>> GetAllTagOverrides(CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the TagOverrides by TagOverrides identifier list.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="TagOverrides">The list of TagOverrides identifiers.</param>
|
||||||
|
/// <returns>A <see cref="Task{IEnumerable{TagOverrideAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<IEnumerable<TagOverrideAdapter>> GetAllTagOverridesByList(string[] tagOverrides, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the status of the TagOverride.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The TagOverride identifier.</param>
|
||||||
|
/// <param name="newStatus">The new status of the TagOverride.</param>
|
||||||
|
/// <returns>The <see cref="TagOverrideAdapter"/> updated entity.</returns>
|
||||||
|
/// <returns>A <see cref="{Task{TagOverrideAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<TagOverrideAdapter> ChangeTagOverrideStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a TagOverride by id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The TagOverride to be updated.</param>
|
||||||
|
/// <param name="id">The TagOverride identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagOverrideAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<TagOverrideAdapter> UpdateTagOverride(TagOverrideAdapter entity, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a TagOverride by its MongoDB identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tagOverrideId">The TagOverride MongoDB identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagOverrideAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<TagOverrideAdapter> DeleteTagOverride(string tagOverrideId, CancellationToken cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
83
Core.Inventory.Provider/Contracts/ITagProvider.cs
Normal file
83
Core.Inventory.Provider/Contracts/ITagProvider.cs
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
using Core.Adapters.Lib;
|
||||||
|
using Core.Blueprint.Mongo;
|
||||||
|
using Core.Inventory.Domain.Contexts.Inventory.Request;
|
||||||
|
|
||||||
|
namespace Core.Inventory.Provider.Contracts
|
||||||
|
{
|
||||||
|
public interface ITagProvider
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new Tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The Tag to be created.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<TagAdapter> CreateTag(TagRequest newTag, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets an Tag by identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The Tag identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<TagAdapter> GetTagById(string _id, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the Tags.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A <see cref="{Task{IEnumerbale{TagAdapter}}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<IEnumerable<TagAdapter>> GetAllTags(CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the Tags by Tags identifier list.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Tags">The list of Tags identifiers.</param>
|
||||||
|
/// <returns>A <see cref="Task{IEnumerable{TagAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<IEnumerable<TagAdapter>> GetAllTagsByList(string[] Tags, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the status of the Tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The Tag identifier.</param>
|
||||||
|
/// <param name="newStatus">The new status of the Tag.</param>
|
||||||
|
/// <returns>The <see cref="TagAdapter"/> updated entity.</returns>
|
||||||
|
/// <returns>A <see cref="{Task{TagAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<TagAdapter> ChangeTagStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a Tag by id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The Tag to be updated.</param>
|
||||||
|
/// <param name="id">The Tag identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<TagAdapter> UpdateTag(TagAdapter entity, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a parentTag to the tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tagId">The identifier of the tag to whom the parentTag will be added.</param>
|
||||||
|
/// <param name="parentTagId">The identifier of the parentTag to add.</param>
|
||||||
|
/// <returns>A <see cref="Task{TagAdapter}"/> representing the asynchronous operation, with the updated tag object.</returns>
|
||||||
|
ValueTask<TagAdapter> AddParentTag(string tagId, string parentTagId, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a parentTag from the tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tagId">The identifier of the tag to whom the parentTag will be added.</param>
|
||||||
|
/// <param name="parentTagId">The identifier of the parentTag to add.</param>
|
||||||
|
/// <returns>A <see cref="Task{TagAdapter}"/> representing the asynchronous operation, with the updated tag object.</returns>
|
||||||
|
ValueTask<TagAdapter> RemoveParentTag(string tagId, string parentTagId, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a Tag by its MongoDB identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="TagId">The Tag MongoDB identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<TagAdapter> DeleteTag(string tagId, CancellationToken cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
67
Core.Inventory.Provider/Contracts/ITagTypeProvider.cs
Normal file
67
Core.Inventory.Provider/Contracts/ITagTypeProvider.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
using Core.Adapters.Lib;
|
||||||
|
using Core.Blueprint.Mongo;
|
||||||
|
using Core.Inventory.Domain.Contexts.Inventory.Request;
|
||||||
|
|
||||||
|
namespace Core.Inventory.Provider.Contracts
|
||||||
|
{
|
||||||
|
public interface ITagTypeProvider
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new TagType.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The TagType to be created.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagTypeAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<TagTypeAdapter> CreateTagType(TagTypeRequest newTagType, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets an TagType by identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The TagType identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagTypeAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<TagTypeAdapter> GetTagTypeById(string _id, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the tagTypes.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A <see cref="{Task{IEnumerbale{TagTypeAdapter}}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<IEnumerable<TagTypeAdapter>> GetAllTagTypes(CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the tagTypes by tagTypes identifier list.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tagTypes">The list of tagTypes identifiers.</param>
|
||||||
|
/// <returns>A <see cref="Task{IEnumerable{TagTypeAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<IEnumerable<TagTypeAdapter>> GetAllTagTypesByList(string[] TagTypes, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the status of the tagType.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The tagType identifier.</param>
|
||||||
|
/// <param name="newStatus">The new status of the tagType.</param>
|
||||||
|
/// <returns>The <see cref="TagTypeAdapter"/> updated entity.</returns>
|
||||||
|
/// <returns>A <see cref="{Task{TagTypeAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<TagTypeAdapter> ChangeTagTypeStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a TagType by id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The TagType to be updated.</param>
|
||||||
|
/// <param name="id">The TagType identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagTypeAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<TagTypeAdapter> UpdateTagType(TagTypeAdapter entity, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a TagType by its MongoDB identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tagTypeId">The TagType MongoDB identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagTypeAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
ValueTask<TagTypeAdapter> DeleteTagType(string tagTypeId, CancellationToken cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,9 +7,9 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Adapters.Lib" Version="1.0.8" />
|
<PackageReference Include="Core.Adapters.Lib" Version="1.0.1" />
|
||||||
<PackageReference Include="Core.Blueprint.Mongo" Version="1.0.0" />
|
<PackageReference Include="Core.Blueprint.Mongo" Version="1.0.0" />
|
||||||
<PackageReference Include="Core.Blueprint.Redis" Version="1.0.2" />
|
<PackageReference Include="Core.Blueprint.Redis" Version="1.0.0" />
|
||||||
<PackageReference Include="Mapster" Version="7.4.0" />
|
<PackageReference Include="Mapster" Version="7.4.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ namespace Core.Inventory.Provider.Providers.Inventory
|
|||||||
if (cachedData.Any()) return cachedData;
|
if (cachedData.Any()) return cachedData;
|
||||||
|
|
||||||
var data = await repository.AsQueryable();
|
var data = await repository.AsQueryable();
|
||||||
await cacheProvider.SetAsync(cacheKey, data);
|
await cacheProvider.SetAsync(cacheKey, data, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ namespace Core.Inventory.Provider.Providers.Inventory
|
|||||||
if (cached is not null) return cached;
|
if (cached is not null) return cached;
|
||||||
|
|
||||||
var result = await repository.FindByIdAsync(mongoId);
|
var result = await repository.FindByIdAsync(mongoId);
|
||||||
await cacheProvider.SetAsync(cacheKey, result);
|
await cacheProvider.SetAsync(cacheKey, result, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ namespace Core.Inventory.Provider.Providers.Inventory
|
|||||||
var variants = await repository.FilterByMongoFilterAsync(filter);
|
var variants = await repository.FilterByMongoFilterAsync(filter);
|
||||||
|
|
||||||
if (variants is not null && variants.Any())
|
if (variants is not null && variants.Any())
|
||||||
await cacheProvider.SetAsync(cacheKey, variants);
|
await cacheProvider.SetAsync(cacheKey, variants, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
|
|
||||||
return variants ?? [];
|
return variants ?? [];
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ namespace Core.Inventory.Provider.Providers.Inventory
|
|||||||
if (cached is not null) return cached;
|
if (cached is not null) return cached;
|
||||||
|
|
||||||
var result = await repository.FindByIdAsync(mongoId);
|
var result = await repository.FindByIdAsync(mongoId);
|
||||||
await cacheProvider.SetAsync(cacheKey, result);
|
await cacheProvider.SetAsync(cacheKey, result, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ namespace Core.Inventory.Provider.Providers.Inventory
|
|||||||
var variants = await repository.FilterByMongoFilterAsync(filter);
|
var variants = await repository.FilterByMongoFilterAsync(filter);
|
||||||
|
|
||||||
if (variants is not null && variants.Any())
|
if (variants is not null && variants.Any())
|
||||||
await cacheProvider.SetAsync(cacheKey, variants);
|
await cacheProvider.SetAsync(cacheKey, variants, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
|
|
||||||
return variants ?? [];
|
return variants ?? [];
|
||||||
}
|
}
|
||||||
@@ -157,7 +157,7 @@ namespace Core.Inventory.Provider.Providers.Inventory
|
|||||||
if (cachedData.Any()) return cachedData;
|
if (cachedData.Any()) return cachedData;
|
||||||
|
|
||||||
var data = await repository.AsQueryable();
|
var data = await repository.AsQueryable();
|
||||||
await cacheProvider.SetAsync(cacheKey, data);
|
await cacheProvider.SetAsync(cacheKey, data, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
213
Core.Inventory.Provider/Providers/Inventory/ProductProvider.cs
Normal file
213
Core.Inventory.Provider/Providers/Inventory/ProductProvider.cs
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
using Core.Adapters.Lib.Inventory;
|
||||||
|
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;
|
||||||
|
using MongoDB.Bson;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
|
||||||
|
namespace Core.Inventory.Provider.Providers.Inventory
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Handles all services and business rules related to <see cref="ProductAdapter"/>.
|
||||||
|
/// </summary>
|
||||||
|
public class ProductProvider : IProductProvider
|
||||||
|
{
|
||||||
|
private readonly CollectionRepository<ProductAdapter> repository;
|
||||||
|
private readonly CacheSettings cacheSettings;
|
||||||
|
private readonly IRedisCacheProvider cacheProvider;
|
||||||
|
|
||||||
|
public ProductProvider(CollectionRepository<ProductAdapter> repository,
|
||||||
|
IRedisCacheProvider cacheProvider,
|
||||||
|
IOptions<CacheSettings> cacheSettings)
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
this.repository.CollectionInitialization();
|
||||||
|
this.cacheSettings = cacheSettings.Value;
|
||||||
|
this.cacheProvider = cacheProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new Product.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The Product to be created.</param>
|
||||||
|
/// <returns>A <see cref="{Task{ProductAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<ProductAdapter> CreateProduct(ProductRequest newProduct, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var productCollection = newProduct.Adapt<ProductAdapter>();
|
||||||
|
|
||||||
|
await repository.InsertOneAsync(productCollection);
|
||||||
|
|
||||||
|
return productCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a Product by identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The Product identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{ProductAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<ProductAdapter> GetProductById(string _id, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetProductById", _id);
|
||||||
|
var cachedData = await cacheProvider.GetAsync<ProductAdapter>(cacheKey);
|
||||||
|
|
||||||
|
if (cachedData is not null) { return cachedData; }
|
||||||
|
|
||||||
|
var product = await repository.FindByIdAsync(_id);
|
||||||
|
|
||||||
|
await cacheProvider.SetAsync(cacheKey, product, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
|
|
||||||
|
return product;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the Products.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A <see cref="{Task{IEnumerable{ProductAdapter}}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<IEnumerable<ProductAdapter>> GetAllProducts(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetProducts");
|
||||||
|
var cachedData = await cacheProvider.GetAsync<IEnumerable<ProductAdapter>>(cacheKey) ?? [];
|
||||||
|
|
||||||
|
if (cachedData.Any()) return cachedData;
|
||||||
|
|
||||||
|
var products = await repository.AsQueryable();
|
||||||
|
|
||||||
|
await cacheProvider.SetAsync(cacheKey, products, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
|
|
||||||
|
return products;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the Products by Products identifier list.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="products">The list of Products identifiers.</param>
|
||||||
|
/// <returns>A <see cref="Task{IEnumerable{ProductAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<IEnumerable<ProductAdapter>> GetAllProductsByList(string[] products, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllProductsByList", products);
|
||||||
|
|
||||||
|
var cachedData = await cacheProvider.GetAsync<IEnumerable<ProductAdapter>>(cacheKey) ?? [];
|
||||||
|
|
||||||
|
if (cachedData.Any()) return cachedData;
|
||||||
|
|
||||||
|
var builder = Builders<ProductAdapter>.Filter;
|
||||||
|
var filters = new List<FilterDefinition<ProductAdapter>>();
|
||||||
|
|
||||||
|
if (products != null || !products.Any())
|
||||||
|
{
|
||||||
|
filters.Add(builder.In(x => x._Id, products));
|
||||||
|
}
|
||||||
|
|
||||||
|
var finalFilter = filters.Count != 0 ? builder.And(filters) : builder.Empty;
|
||||||
|
|
||||||
|
var productsList = await repository.FilterByMongoFilterAsync(finalFilter);
|
||||||
|
|
||||||
|
await cacheProvider.SetAsync(cacheKey, productsList, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
|
|
||||||
|
return productsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the status of the Product.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The Product identifier.</param>
|
||||||
|
/// <param name="newStatus">The new status of the Product.</param>
|
||||||
|
/// <returns>A <see cref="{Task{ProductAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<ProductAdapter> ChangeProductStatus(string id, ProductStatus newStatus, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var entity = await repository.FindByIdAsync(id);
|
||||||
|
entity.ProductStatus = newStatus;
|
||||||
|
|
||||||
|
await repository.ReplaceOneAsync(entity);
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a Product by id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The Product to be updated.</param>
|
||||||
|
/// <param name="id">The Product identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{ProductAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<ProductAdapter> UpdateProduct(ProductAdapter entity, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await repository.ReplaceOneAsync(entity);
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a tag to the product.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="productId">The ID of the product.</param>
|
||||||
|
/// <param name="tagId">The ID of the tag to add.</param>
|
||||||
|
/// <returns>A <see cref="{Task{ProductAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<ProductAdapter> AddTagToProduct(string productId, string tagId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var product = await repository.FindByIdAsync(productId);
|
||||||
|
|
||||||
|
if (product != null)
|
||||||
|
{
|
||||||
|
var objectId = ObjectId.Parse(tagId);
|
||||||
|
if (!product.TagIds.Contains(objectId))
|
||||||
|
{
|
||||||
|
product.TagIds.Add(objectId);
|
||||||
|
await repository.ReplaceOneAsync(product);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return product;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a tag from the product.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="productId">The ID of the product.</param>
|
||||||
|
/// <param name="tagId">The ID of the tag to remove.</param>
|
||||||
|
/// <returns>A <see cref="{Task{ProductAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<ProductAdapter> RemoveTagFromProduct(string productId, string tagId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var product = await repository.FindByIdAsync(productId);
|
||||||
|
|
||||||
|
if (product != null)
|
||||||
|
{
|
||||||
|
var objectId = ObjectId.Parse(tagId);
|
||||||
|
product.TagIds.Remove(objectId);
|
||||||
|
await repository.ReplaceOneAsync(product);
|
||||||
|
}
|
||||||
|
|
||||||
|
return product;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a Product by its MongoDB identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="productId">The Product MongoDB identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{bool}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<bool> DeleteProduct(string productId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await repository.DeleteByIdAsync(productId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
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;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
|
||||||
|
namespace Core.Inventory.Provider.Providers.Inventory
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Handles all services and business rules related to <see cref="TagOverrideAdapter"/>.
|
||||||
|
/// </summary>
|
||||||
|
public class TagOverrideProvider : ITagOverrideProvider
|
||||||
|
{
|
||||||
|
private readonly CollectionRepository<TagOverrideAdapter> repository;
|
||||||
|
private readonly CacheSettings cacheSettings;
|
||||||
|
private readonly IRedisCacheProvider cacheProvider;
|
||||||
|
|
||||||
|
public TagOverrideProvider(CollectionRepository<TagOverrideAdapter> repository,
|
||||||
|
IRedisCacheProvider cacheProvider,
|
||||||
|
IOptions<CacheSettings> cacheSettings)
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
this.repository.CollectionInitialization();
|
||||||
|
this.cacheSettings = cacheSettings.Value;
|
||||||
|
this.cacheProvider = cacheProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new TagOverride.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The TagOverride to be created.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagOverrideAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<TagOverrideAdapter> CreateTagOverride(TagOverrideRequest newTagOverride, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var tagOverrideCollection = newTagOverride.Adapt<TagOverrideAdapter>();
|
||||||
|
|
||||||
|
await repository.InsertOneAsync(tagOverrideCollection);
|
||||||
|
|
||||||
|
return tagOverrideCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets an TagOverride by identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The TagOverride identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagOverrideAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>0
|
||||||
|
public async ValueTask<TagOverrideAdapter> GetTagOverrideById(string _id, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetTagOverrideById", _id);
|
||||||
|
var cachedData = await cacheProvider.GetAsync<TagOverrideAdapter>(cacheKey);
|
||||||
|
|
||||||
|
if (cachedData is not null) { return cachedData; }
|
||||||
|
|
||||||
|
var TagOverride = await repository.FindByIdAsync(_id);
|
||||||
|
|
||||||
|
await cacheProvider.SetAsync(cacheKey, TagOverride, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
|
|
||||||
|
return TagOverride;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the TagOverrides.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A <see cref="{Task{IEnumerbale{TagOverrideAdapter}}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<IEnumerable<TagOverrideAdapter>> GetAllTagOverrides(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetTagOverrides");
|
||||||
|
var cachedData = await cacheProvider.GetAsync<IEnumerable<TagOverrideAdapter>>(cacheKey) ?? [];
|
||||||
|
|
||||||
|
if (cachedData.Any()) return cachedData;
|
||||||
|
|
||||||
|
var TagOverrides = await repository.AsQueryable();
|
||||||
|
|
||||||
|
await cacheProvider.SetAsync(cacheKey, TagOverrides, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
|
|
||||||
|
return TagOverrides;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the TagOverrides by TagOverrides identifier list.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="TagOverrides">The list of TagOverrides identifiers.</param>
|
||||||
|
/// <returns>A <see cref="Task{IEnumerable{TagOverrideAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<IEnumerable<TagOverrideAdapter>> GetAllTagOverridesByList(string[] tagOverrides, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllTagOverridesByList", tagOverrides);
|
||||||
|
|
||||||
|
var cachedData = await cacheProvider.GetAsync<IEnumerable<TagOverrideAdapter>>(cacheKey) ?? [];
|
||||||
|
|
||||||
|
if (cachedData.Any()) return cachedData;
|
||||||
|
|
||||||
|
var builder = Builders<TagOverrideAdapter>.Filter;
|
||||||
|
var filters = new List<FilterDefinition<TagOverrideAdapter>>();
|
||||||
|
|
||||||
|
if (tagOverrides != null || !tagOverrides.Any())
|
||||||
|
{
|
||||||
|
filters.Add(builder.In(x => x._Id, tagOverrides));
|
||||||
|
}
|
||||||
|
|
||||||
|
var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty;
|
||||||
|
|
||||||
|
var TagOverridesList = await repository.FilterByMongoFilterAsync(finalFilter);
|
||||||
|
|
||||||
|
await cacheProvider.SetAsync(cacheKey, TagOverridesList, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
|
|
||||||
|
return TagOverridesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the status of the TagOverride.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The TagOverride identifier.</param>
|
||||||
|
/// <param name="newStatus">The new status of the TagOverride.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagOverrideAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<TagOverrideAdapter> ChangeTagOverrideStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var entity = await repository.FindByIdAsync(id);
|
||||||
|
entity.Status = newStatus;
|
||||||
|
|
||||||
|
await repository.ReplaceOneAsync(entity);
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a TagOverride by id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The TagOverride to be updated.</param>
|
||||||
|
/// <param name="id">The TagOverride identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagOverrideAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<TagOverrideAdapter> UpdateTagOverride(TagOverrideAdapter entity, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await repository.ReplaceOneAsync(entity);
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a TagOverride by its MongoDB identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tagOverrideId">The TagOverride MongoDB identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagOverrideAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<TagOverrideAdapter> DeleteTagOverride(string tagOverrideId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var entity = await repository.DeleteOneAsync(doc => doc._Id == tagOverrideId);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
211
Core.Inventory.Provider/Providers/Inventory/TagProvider.cs
Normal file
211
Core.Inventory.Provider/Providers/Inventory/TagProvider.cs
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
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;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
|
||||||
|
namespace Core.Inventory.Provider.Providers.Inventory
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Handles all services and business rules related to <see cref="TagAdapter"/>.
|
||||||
|
/// </summary>
|
||||||
|
public class TagProvider : ITagProvider
|
||||||
|
{
|
||||||
|
private readonly CollectionRepository<TagAdapter> repository;
|
||||||
|
private readonly CacheSettings cacheSettings;
|
||||||
|
private readonly IRedisCacheProvider cacheProvider;
|
||||||
|
|
||||||
|
public TagProvider(CollectionRepository<TagAdapter> repository,
|
||||||
|
IRedisCacheProvider cacheProvider,
|
||||||
|
IOptions<CacheSettings> cacheSettings)
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
this.repository.CollectionInitialization();
|
||||||
|
this.cacheSettings = cacheSettings.Value;
|
||||||
|
this.cacheProvider = cacheProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new Tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The Tag to be created.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<TagAdapter> CreateTag(TagRequest newTag, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var tagCollection = newTag.Adapt<TagAdapter>();
|
||||||
|
|
||||||
|
await repository.InsertOneAsync(tagCollection);
|
||||||
|
|
||||||
|
return tagCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets an Tag by identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The Tag identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>0
|
||||||
|
public async ValueTask<TagAdapter> GetTagById(string _id, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetTagById", _id);
|
||||||
|
var cachedData = await cacheProvider.GetAsync<TagAdapter>(cacheKey);
|
||||||
|
|
||||||
|
if (cachedData is not null) { return cachedData; }
|
||||||
|
|
||||||
|
var tag = await repository.FindByIdAsync(_id);
|
||||||
|
|
||||||
|
await cacheProvider.SetAsync(cacheKey, tag, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
|
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the Tags.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A <see cref="{Task{IEnumerbale{TagAdapter}}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<IEnumerable<TagAdapter>> GetAllTags(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetTags");
|
||||||
|
var cachedData = await cacheProvider.GetAsync<IEnumerable<TagAdapter>>(cacheKey) ?? [];
|
||||||
|
|
||||||
|
if (cachedData.Any()) return cachedData;
|
||||||
|
|
||||||
|
var tags = await repository.AsQueryable();
|
||||||
|
|
||||||
|
await cacheProvider.SetAsync(cacheKey, tags, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
|
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the Tags by Tags identifier list.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Tags">The list of Tags identifiers.</param>
|
||||||
|
/// <returns>A <see cref="Task{IEnumerable{TagAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<IEnumerable<TagAdapter>> GetAllTagsByList(string[] tags, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllTagsByList", tags);
|
||||||
|
|
||||||
|
var cachedData = await cacheProvider.GetAsync<IEnumerable<TagAdapter>>(cacheKey) ?? [];
|
||||||
|
|
||||||
|
if (cachedData.Any()) return cachedData;
|
||||||
|
|
||||||
|
var builder = Builders<TagAdapter>.Filter;
|
||||||
|
var filters = new List<FilterDefinition<TagAdapter>>();
|
||||||
|
|
||||||
|
if (tags != null || !tags.Any())
|
||||||
|
{
|
||||||
|
filters.Add(builder.In(x => x._Id, tags));
|
||||||
|
}
|
||||||
|
|
||||||
|
var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty;
|
||||||
|
|
||||||
|
var TagsList = await repository.FilterByMongoFilterAsync(finalFilter);
|
||||||
|
|
||||||
|
await cacheProvider.SetAsync(cacheKey, TagsList, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
|
|
||||||
|
return TagsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the status of the Tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The Tag identifier.</param>
|
||||||
|
/// <param name="newStatus">The new status of the Tag.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<TagAdapter> ChangeTagStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var entity = await repository.FindByIdAsync(id);
|
||||||
|
entity.Status = newStatus;
|
||||||
|
|
||||||
|
await repository.ReplaceOneAsync(entity);
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a Tag by id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The Tag to be updated.</param>
|
||||||
|
/// <param name="id">The Tag identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<TagAdapter> UpdateTag(TagAdapter entity, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await repository.ReplaceOneAsync(entity);
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a parentTag to the tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tagId">The identifier of the tag to whom the parentTag will be added.</param>
|
||||||
|
/// <param name="parentTagId">The identifier of the parentTag to add.</param>
|
||||||
|
/// <returns>A <see cref="Task{TagAdapter}"/> representing the asynchronous operation, with the updated tag object.</returns>
|
||||||
|
public async ValueTask<TagAdapter> AddParentTag(string tagId, string parentTagId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var tag = await repository.FindOneAsync(
|
||||||
|
u => u._Id == tagId &&
|
||||||
|
u.Status == StatusEnum.Active);
|
||||||
|
|
||||||
|
var updatedParentTags = tag.ParentTagId.Append(parentTagId).Distinct().ToArray();
|
||||||
|
tag.ParentTagId = updatedParentTags;
|
||||||
|
|
||||||
|
await repository.ReplaceOneAsync(tag);
|
||||||
|
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove a parentTag to the tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tagId">The identifier of the tag to whom the parentTag will be removed.</param>
|
||||||
|
/// <param name="parentTagId">The identifier of the parentTag to add.</param>
|
||||||
|
/// <returns>A <see cref="Task{TagAdapter}"/> representing the asynchronous operation, with the updated tag object.</returns>
|
||||||
|
public async ValueTask<TagAdapter> RemoveParentTag(string tagId, string parentTagId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var tag = await repository.FindOneAsync(
|
||||||
|
u => u._Id == tagId &&
|
||||||
|
u.Status == StatusEnum.Active);
|
||||||
|
|
||||||
|
var updatedParentTags = tag.ParentTagId
|
||||||
|
?.Where(c => c != parentTagId)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
tag.ParentTagId = updatedParentTags;
|
||||||
|
|
||||||
|
await repository.ReplaceOneAsync(tag);
|
||||||
|
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a Tag by its MongoDB identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tagId">The Tag MongoDB identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<TagAdapter> DeleteTag(string tagId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var entity = await repository.DeleteOneAsync(doc => doc._Id == tagId);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
168
Core.Inventory.Provider/Providers/Inventory/TagTypeProvider.cs
Normal file
168
Core.Inventory.Provider/Providers/Inventory/TagTypeProvider.cs
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
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;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
|
||||||
|
namespace Core.Inventory.Provider.Providers.Inventory
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Handles all services and business rules related to <see cref="TagTypeAdapter"/>.
|
||||||
|
/// </summary>
|
||||||
|
public class TagTypeProvider : ITagTypeProvider
|
||||||
|
{
|
||||||
|
private readonly CollectionRepository<TagTypeAdapter> repository;
|
||||||
|
private readonly CacheSettings cacheSettings;
|
||||||
|
private readonly IRedisCacheProvider cacheProvider;
|
||||||
|
|
||||||
|
public TagTypeProvider(CollectionRepository<TagTypeAdapter> repository,
|
||||||
|
IRedisCacheProvider cacheProvider,
|
||||||
|
IOptions<CacheSettings> cacheSettings)
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
this.repository.CollectionInitialization();
|
||||||
|
this.cacheSettings = cacheSettings.Value;
|
||||||
|
this.cacheProvider = cacheProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new TagType.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The TagType to be created.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagTypeAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<TagTypeAdapter> CreateTagType(TagTypeRequest newTagType, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var tagTypeCollection = newTagType.Adapt<TagTypeAdapter>();
|
||||||
|
|
||||||
|
await repository.InsertOneAsync(tagTypeCollection);
|
||||||
|
|
||||||
|
return tagTypeCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets an TagType by identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The TagType identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagTypeAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>0
|
||||||
|
public async ValueTask<TagTypeAdapter> GetTagTypeById(string _id, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetTagTypeById", _id);
|
||||||
|
var cachedData = await cacheProvider.GetAsync<TagTypeAdapter>(cacheKey);
|
||||||
|
|
||||||
|
if (cachedData is not null) { return cachedData; }
|
||||||
|
|
||||||
|
var tagType = await repository.FindByIdAsync(_id);
|
||||||
|
|
||||||
|
await cacheProvider.SetAsync(cacheKey, tagType, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
|
|
||||||
|
return tagType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the TagTypes.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A <see cref="{Task{IEnumerbale{TagTypeAdapter}}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<IEnumerable<TagTypeAdapter>> GetAllTagTypes(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetTagTypes");
|
||||||
|
var cachedData = await cacheProvider.GetAsync<IEnumerable<TagTypeAdapter>>(cacheKey) ?? [];
|
||||||
|
|
||||||
|
if (cachedData.Any()) return cachedData;
|
||||||
|
|
||||||
|
var tagTypes = await repository.AsQueryable();
|
||||||
|
|
||||||
|
await cacheProvider.SetAsync(cacheKey, tagTypes, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
|
|
||||||
|
return tagTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all the TagTypes by TagTypes identifier list.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="TagTypes">The list of TagTypes identifiers.</param>
|
||||||
|
/// <returns>A <see cref="Task{IEnumerable{TagTypeAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<IEnumerable<TagTypeAdapter>> GetAllTagTypesByList(string[] tagTypes, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllTagTypesByList", tagTypes);
|
||||||
|
|
||||||
|
var cachedData = await cacheProvider.GetAsync<IEnumerable<TagTypeAdapter>>(cacheKey) ?? [];
|
||||||
|
|
||||||
|
if (cachedData.Any()) return cachedData;
|
||||||
|
|
||||||
|
var builder = Builders<TagTypeAdapter>.Filter;
|
||||||
|
var filters = new List<FilterDefinition<TagTypeAdapter>>();
|
||||||
|
|
||||||
|
if (tagTypes != null || !tagTypes.Any())
|
||||||
|
{
|
||||||
|
filters.Add(builder.In(x => x._Id, tagTypes));
|
||||||
|
}
|
||||||
|
|
||||||
|
var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty;
|
||||||
|
|
||||||
|
var tagTypesList = await repository.FilterByMongoFilterAsync(finalFilter);
|
||||||
|
|
||||||
|
await cacheProvider.SetAsync(cacheKey, tagTypesList, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes));
|
||||||
|
|
||||||
|
return tagTypesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the status of the TagType.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The TagType identifier.</param>
|
||||||
|
/// <param name="newStatus">The new status of the TagType.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagTypeAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<TagTypeAdapter> ChangeTagTypeStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var entity = await repository.FindByIdAsync(id);
|
||||||
|
entity.Status = newStatus;
|
||||||
|
|
||||||
|
await repository.ReplaceOneAsync(entity);
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a TagType by id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The TagType to be updated.</param>
|
||||||
|
/// <param name="id">The TagType identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagTypeAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<TagTypeAdapter> UpdateTagType(TagTypeAdapter entity, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await repository.ReplaceOneAsync(entity);
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a TagType by its MongoDB identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tagTypeId">The TagType MongoDB identifier.</param>
|
||||||
|
/// <returns>A <see cref="{Task{TagTypeAdapter}}"/> representing
|
||||||
|
/// the asynchronous execution of the service.</returns>
|
||||||
|
public async ValueTask<TagTypeAdapter> DeleteTagType(string tagTypeId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var entity = await repository.DeleteOneAsync(doc => doc._Id == tagTypeId);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Core.Adapters.Lib;
|
using Core.Adapters.Lib.Inventory;
|
||||||
|
using Core.Adapters.Lib;
|
||||||
using Core.Blueprint.Mongo;
|
using Core.Blueprint.Mongo;
|
||||||
using Core.Inventory.Provider.Contracts;
|
using Core.Inventory.Provider.Contracts;
|
||||||
using Core.Inventory.Provider.Providers.Inventory;
|
using Core.Inventory.Provider.Providers.Inventory;
|
||||||
@@ -17,6 +18,18 @@ namespace Core.Inventory.Provider
|
|||||||
services.AddScoped<IFurnitureVariantProvider, FurnitureVariantProvider>();
|
services.AddScoped<IFurnitureVariantProvider, FurnitureVariantProvider>();
|
||||||
services.AddScoped<CollectionRepository<FurnitureVariant>>();
|
services.AddScoped<CollectionRepository<FurnitureVariant>>();
|
||||||
|
|
||||||
|
services.AddScoped<ITagTypeProvider, TagTypeProvider>();
|
||||||
|
services.AddScoped<CollectionRepository<TagTypeAdapter>>();
|
||||||
|
|
||||||
|
services.AddScoped<ITagProvider, TagProvider>();
|
||||||
|
services.AddScoped<CollectionRepository<TagAdapter>>();
|
||||||
|
|
||||||
|
services.AddScoped<ITagOverrideProvider, TagOverrideProvider>();
|
||||||
|
services.AddScoped<CollectionRepository<TagOverrideAdapter>>();
|
||||||
|
|
||||||
|
services.AddScoped<IProductProvider, ProductProvider>();
|
||||||
|
services.AddScoped<CollectionRepository<ProductAdapter>>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
32
Dockerfile
Normal file
32
Dockerfile
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# ===== Build stage =====
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
# Copia nuget.config de la raíz (con BaGet + nuget.org)
|
||||||
|
COPY nuget.config ./
|
||||||
|
|
||||||
|
# Copia SOLO los .csproj que DAL necesita (para cache de restore)
|
||||||
|
COPY Core.Inventory.DAL.API/Core.Inventory.DAL.API.csproj Core.Inventory.DAL.API/
|
||||||
|
COPY Core.Inventory.Domain/Core.Inventory.Domain.csproj Core.Inventory.Domain/
|
||||||
|
COPY Core.Inventory.Provider/Core.Inventory.Provider.csproj Core.Inventory.Provider/
|
||||||
|
|
||||||
|
# Restaura usando nuget.config
|
||||||
|
RUN dotnet restore Core.Inventory.DAL.API/Core.Inventory.DAL.API.csproj --configfile ./nuget.config
|
||||||
|
|
||||||
|
# Copia el resto del código
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Publica artefactos listos para runtime
|
||||||
|
RUN dotnet publish Core.Inventory.DAL.API/Core.Inventory.DAL.API.csproj \
|
||||||
|
-c Release -o /app/out /p:UseAppHost=false
|
||||||
|
|
||||||
|
# ===== Runtime stage =====
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=build /app/out .
|
||||||
|
|
||||||
|
# Configuración básica
|
||||||
|
ENV ASPNETCORE_URLS=http://+:8080
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
ENTRYPOINT ["dotnet", "Core.Inventory.DAL.API.dll"]
|
||||||
9
nuget.config
Normal file
9
nuget.config
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<packageSources>
|
||||||
|
<!-- Tu BaGet primero -->
|
||||||
|
<add key="BaGet" value="https://nuget.dream-views.com/v3/index.json" protocolVersion="3" />
|
||||||
|
<!-- NuGet oficial como fallback (si quieres) -->
|
||||||
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||||
|
</packageSources>
|
||||||
|
</configuration>
|
||||||
Reference in New Issue
Block a user