Add TagOverride CRUD
This commit is contained in:
@@ -150,21 +150,21 @@ namespace Core.Inventory.BFF.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> UpdateTagService(UpdateTagRequest newTag, CancellationToken cancellationToken)
|
||||
public async Task<IActionResult> UpdateTagService(UpdateTagRequest tag, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation($"{nameof(UpdateTagService)} - Request received - Payload: {JsonSerializer.Serialize(newTag)}");
|
||||
logger.LogInformation($"{nameof(UpdateTagService)} - Request received - Payload: {JsonSerializer.Serialize(tag)}");
|
||||
|
||||
if (newTag == null) return BadRequest("Invalid Tag object");
|
||||
if (tag == null) return BadRequest("Invalid Tag object");
|
||||
|
||||
if (string.IsNullOrEmpty(newTag.TagName)) return BadRequest("Invalid Tag name");
|
||||
if (string.IsNullOrEmpty(tag.TagName)) return BadRequest("Invalid Tag name");
|
||||
|
||||
return await Handle(() => inventoryServiceClient.UpdateTagService(newTag, cancellationToken)).ConfigureAwait(false);
|
||||
return await Handle(() => inventoryServiceClient.UpdateTagService(tag, cancellationToken)).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"{nameof(UpdateTagService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newTag)}");
|
||||
logger.LogError($"{nameof(UpdateTagService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(tag)}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
207
Core.Inventory.BFF.API/Controllers/TagOverrideController.cs
Normal file
207
Core.Inventory.BFF.API/Controllers/TagOverrideController.cs
Normal file
@@ -0,0 +1,207 @@
|
||||
using Asp.Versioning;
|
||||
using Core.Adapters.Lib;
|
||||
using Core.Inventory.External.Clients.Inventory;
|
||||
using Core.Inventory.External.Clients.Inventory.Requests.TagOverride;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Core.Inventory.BFF.API.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles all requests for TagOverride authentication.
|
||||
/// </summary>
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Consumes("application/json")]
|
||||
[Produces("application/json")]
|
||||
[ApiController]
|
||||
[AllowAnonymous]
|
||||
public class TagOverrideController(IInventoryServiceClient inventoryServiceClient, ILogger<TagOverrideController> logger) : BaseController(logger)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all the TagOverrides.
|
||||
/// </summary>
|
||||
[HttpGet("GetAll")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> GetAllTagOverridesService(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation($"{nameof(GetAllTagOverridesService)} - Request received - Payload: ");
|
||||
|
||||
return await Handle(() => inventoryServiceClient.GetAllTagOverridesService(new GetAllTagOverridesRequest { }, cancellationToken)).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"{nameof(GetAllTagOverridesService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the TagOverrides by TagOverride identifiers.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the list of TagOverride identifiers.</param>
|
||||
/// <param name="cancellationToken">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>The <see cref="IActionResult"/> representing the result of the service call.</returns>
|
||||
/// <response code="200">The TagOverrides found.</response>
|
||||
/// <response code="204">No content if no TagOverrides are found.</response>
|
||||
/// <response code="400">Bad request if the TagOverride identifiers are missing or invalid.</response>
|
||||
/// <response code="401">Unauthorized if the user is not authenticated.</response>
|
||||
/// <response code="500">Internal server error if an unexpected error occurs.</response>
|
||||
[HttpPost("GetAllByList")]
|
||||
[ProducesResponseType(typeof(IEnumerable<TagOverrideAdapter>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> GetAllTagOverridesByListAsync([FromBody] GetAllTagOverridesByListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation($"{nameof(GetAllTagOverridesByListAsync)} - Request received - Payload: {request}");
|
||||
|
||||
if (request == null || request.TagOverrides == null || !request.TagOverrides.Any())
|
||||
{
|
||||
return BadRequest("TagOverride identifiers are required.");
|
||||
}
|
||||
|
||||
return await Handle(() => inventoryServiceClient.GetAllTagOverridesByListService(request, cancellationToken)).ConfigureAwait(false);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"{nameof(GetAllTagOverridesByListAsync)} - An error occurred - {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload: {request}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "Internal server error");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new TagOverride.
|
||||
/// </summary>
|
||||
[HttpPost("Create")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> CreateTagOverrideService(CreateTagOverrideRequest newTagOverride, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation($"{nameof(CreateTagOverrideService)} - Request received - Payload: {JsonSerializer.Serialize(newTagOverride)}");
|
||||
|
||||
if (newTagOverride == null) return BadRequest("Invalid TagOverride object");
|
||||
|
||||
if (string.IsNullOrEmpty(newTagOverride.BaseTagId)) return BadRequest("Invalid TagOverride BaseTagId");
|
||||
|
||||
if (string.IsNullOrEmpty(newTagOverride.OverrideTagId)) return BadRequest("Invalid TagOverride OverrideTagId");
|
||||
|
||||
return await Handle(() => inventoryServiceClient.CreateTagOverrideService(newTagOverride, cancellationToken)).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"{nameof(CreateTagOverrideService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newTagOverride)}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the TagOverride by identifier.
|
||||
/// </summary>
|
||||
[HttpPost("GetById")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> GetTagOverrideByIdService(GetTagOverrideRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation($"{nameof(GetTagOverrideByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
|
||||
|
||||
if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid TagOverride identifier");
|
||||
|
||||
return await Handle(() => inventoryServiceClient.GetTagOverrideByIdService(request, cancellationToken)).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"{nameof(GetTagOverrideByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a full TagOverride by identifier.
|
||||
/// </summary>
|
||||
[HttpPut("Update")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> UpdateTagOverrideService(UpdateTagOverrideRequest tagOverride, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation($"{nameof(UpdateTagOverrideService)} - Request received - Payload: {JsonSerializer.Serialize(tagOverride)}");
|
||||
|
||||
if (tagOverride == null) return BadRequest("Invalid TagOverride object");
|
||||
|
||||
if (string.IsNullOrEmpty(tagOverride.BaseTagId)) return BadRequest("Invalid TagOverride BaseTagId");
|
||||
|
||||
if (string.IsNullOrEmpty(tagOverride.OverrideTagId)) return BadRequest("Invalid TagOverride OverrideTagId");
|
||||
|
||||
return await Handle(() => inventoryServiceClient.UpdateTagOverrideService(tagOverride, cancellationToken)).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"{nameof(UpdateTagOverrideService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(tagOverride)}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the status of the TagOverride.
|
||||
/// </summary>
|
||||
[HttpPatch]
|
||||
[Route("ChangeStatus")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> ChangeTagOverrideStatusService([FromBody] ChangeTagOverrideStatusRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation($"{nameof(ChangeTagOverrideStatusService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
|
||||
|
||||
if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid TagOverride identifier"); }
|
||||
|
||||
return await Handle(() => inventoryServiceClient.ChangeTagOverrideStatusService(request, cancellationToken)).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"{nameof(ChangeTagOverrideStatusService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -150,21 +150,21 @@ namespace Core.Inventory.BFF.API.Controllers
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)]
|
||||
[ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> UpdateTagTypeService(UpdateTagTypeRequest newTagType, CancellationToken cancellationToken)
|
||||
public async Task<IActionResult> UpdateTagTypeService(UpdateTagTypeRequest tagType, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation($"{nameof(UpdateTagTypeService)} - Request received - Payload: {JsonSerializer.Serialize(newTagType)}");
|
||||
logger.LogInformation($"{nameof(UpdateTagTypeService)} - Request received - Payload: {JsonSerializer.Serialize(tagType)}");
|
||||
|
||||
if (newTagType == null) return BadRequest("Invalid TagType object");
|
||||
if (tagType == null) return BadRequest("Invalid TagType object");
|
||||
|
||||
if (string.IsNullOrEmpty(newTagType.TypeName)) return BadRequest("Invalid TagType name");
|
||||
if (string.IsNullOrEmpty(tagType.TypeName)) return BadRequest("Invalid TagType name");
|
||||
|
||||
return await Handle(() => inventoryServiceClient.UpdateTagTypeService(newTagType, cancellationToken)).ConfigureAwait(false);
|
||||
return await Handle(() => inventoryServiceClient.UpdateTagTypeService(tagType, cancellationToken)).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"{nameof(UpdateTagTypeService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newTagType)}");
|
||||
logger.LogError($"{nameof(UpdateTagTypeService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(tagType)}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using Core.Adapters.Lib.Inventory;
|
||||
using Core.Inventory.External.Clients.Inventory.Requests.Base;
|
||||
using Core.Inventory.External.Clients.Inventory.Requests.Product;
|
||||
using Core.Inventory.External.Clients.Inventory.Requests.Tag;
|
||||
using Core.Inventory.External.Clients.Inventory.Requests.TagOverride;
|
||||
using Core.Inventory.External.Clients.Inventory.Requests.TagType;
|
||||
using Core.Inventory.External.Clients.Inventory.Requests.Variant;
|
||||
using Refit;
|
||||
@@ -105,6 +106,28 @@ namespace Core.Inventory.External.Clients.Inventory
|
||||
|
||||
#endregion
|
||||
|
||||
#region TagOverride
|
||||
|
||||
[Post("/api/v1/TagOverride/Create")]
|
||||
Task<ApiResponse<TagOverrideAdapter>> CreateTagOverrideService([Header("TrackingId")][Body] CreateTagOverrideRequest request, CancellationToken cancellationToken = default);
|
||||
|
||||
[Post("/api/v1/TagOverride/GetById")]
|
||||
Task<ApiResponse<TagOverrideAdapter>> GetTagOverrideByIdService([Header("TrackingId")][Body] GetTagOverrideRequest request, CancellationToken cancellationToken = default);
|
||||
|
||||
[Get("/api/v1/TagOverride/GetAll")]
|
||||
Task<ApiResponse<IEnumerable<TagOverrideAdapter>>> GetAllTagOverridesService([Header("TrackingId")][Body] GetAllTagOverridesRequest request, CancellationToken cancellationToken = default);
|
||||
|
||||
[Post("/api/v1/TagOverride/GetTagOverrideList")]
|
||||
Task<ApiResponse<IEnumerable<TagOverrideAdapter>>> GetAllTagOverridesByListService([Header("TrackingId")][Body] GetAllTagOverridesByListRequest request, CancellationToken cancellationToken = default);
|
||||
|
||||
[Put("/api/v1/TagOverride/Update")]
|
||||
Task<ApiResponse<TagOverrideAdapter>> UpdateTagOverrideService([Header("TrackingId")][Body] UpdateTagOverrideRequest request, CancellationToken cancellationToken = default);
|
||||
|
||||
[Patch("/api/v1/TagOverride/ChangeStatus")]
|
||||
Task<ApiResponse<TagOverrideAdapter>> ChangeTagOverrideStatusService([Header("TrackingId")][Body] ChangeTagOverrideStatusRequest request, CancellationToken cancellationToken = default);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Product
|
||||
|
||||
[Post("/api/v1/Product/Create")]
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
using Core.Blueprint.Mongo;
|
||||
|
||||
namespace Core.Inventory.External.Clients.Inventory.Requests.TagOverride
|
||||
{
|
||||
public class ChangeTagOverrideStatusRequest
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public StatusEnum Status { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Core.Inventory.External.Clients.Inventory.Requests.TagOverride
|
||||
{
|
||||
public class CreateTagOverrideRequest
|
||||
{
|
||||
public string TenantId { get; set; } = null!;
|
||||
public string BaseTagId { get; set; } = null!;
|
||||
public string OverrideTagId { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Core.Inventory.External.Clients.Inventory.Requests.TagOverride
|
||||
{
|
||||
public class GetAllTagOverridesByListRequest
|
||||
{
|
||||
public string[] TagOverrides { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Core.Inventory.External.Clients.Inventory.Requests.TagOverride
|
||||
{
|
||||
public class GetAllTagOverridesRequest
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Core.Inventory.External.Clients.Inventory.Requests.TagOverride
|
||||
{
|
||||
public class GetTagOverrideRequest
|
||||
{
|
||||
public string Id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Core.Blueprint.Mongo;
|
||||
|
||||
namespace Core.Inventory.External.Clients.Inventory.Requests.TagOverride
|
||||
{
|
||||
public class UpdateTagOverrideRequest
|
||||
{
|
||||
public string Id { get; set; } = null!;
|
||||
public string TenantId { get; set; } = null!;
|
||||
public string BaseTagId { get; set; } = null!;
|
||||
public string OverrideTagId { get; set; } = null!;
|
||||
public StatusEnum Status { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user