Add TagType CRUD
This commit is contained in:
203
Core.Inventory.BFF.API/Controllers/TagTypeController.cs
Normal file
203
Core.Inventory.BFF.API/Controllers/TagTypeController.cs
Normal file
@@ -0,0 +1,203 @@
|
||||
using Asp.Versioning;
|
||||
using Core.Adapters.Lib;
|
||||
using Core.Inventory.External.Clients.Inventory;
|
||||
using Core.Inventory.External.Clients.Inventory.Requests.TagType;
|
||||
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 TagType authentication.
|
||||
/// </summary>
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Consumes("application/json")]
|
||||
[Produces("application/json")]
|
||||
[ApiController]
|
||||
[AllowAnonymous]
|
||||
public class TagTypeController(IInventoryServiceClient inventoryServiceClient, ILogger<TagTypeController> logger) : BaseController(logger)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all the TagTypes.
|
||||
/// </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> GetAllTagTypesService(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation($"{nameof(GetAllTagTypesService)} - Request received - Payload: ");
|
||||
|
||||
return await Handle(() => inventoryServiceClient.GetAllTagTypesService(new GetAllTagTypesRequest { }, cancellationToken)).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"{nameof(GetAllTagTypesService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the TagTypes by TagType identifiers.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the list of TagType 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 TagTypes found.</response>
|
||||
/// <response code="204">No content if no TagTypes are found.</response>
|
||||
/// <response code="400">Bad request if the TagType 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<TagTypeAdapter>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> GetAllTagTypesByListAsync([FromBody] GetAllTagTypesByListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation($"{nameof(GetAllTagTypesByListAsync)} - Request received - Payload: {request}");
|
||||
|
||||
if (request == null || request.TagTypes == null || !request.TagTypes.Any())
|
||||
{
|
||||
return BadRequest("TagType identifiers are required.");
|
||||
}
|
||||
|
||||
return await Handle(() => inventoryServiceClient.GetAllTagTypesByListService(request, cancellationToken)).ConfigureAwait(false);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"{nameof(GetAllTagTypesByListAsync)} - An error occurred - {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload: {request}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "Internal server error");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new TagType.
|
||||
/// </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> CreateTagTypeService(CreateTagTypeRequest newTagType, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation($"{nameof(CreateTagTypeService)} - Request received - Payload: {JsonSerializer.Serialize(newTagType)}");
|
||||
|
||||
if (newTagType == null) return BadRequest("Invalid TagType object");
|
||||
|
||||
if (string.IsNullOrEmpty(newTagType.TypeName)) return BadRequest("Invalid TagType name");
|
||||
|
||||
return await Handle(() => inventoryServiceClient.CreateTagTypeService(newTagType, cancellationToken)).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"{nameof(CreateTagTypeService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newTagType)}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the TagType 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> GetTagTypeByIdService(GetTagTypeRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation($"{nameof(GetTagTypeByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
|
||||
|
||||
if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid TagType identifier");
|
||||
|
||||
return await Handle(() => inventoryServiceClient.GetTagTypeByIdService(request, cancellationToken)).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"{nameof(GetTagTypeByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a full TagType 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> UpdateTagTypeService(UpdateTagTypeRequest newTagType, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation($"{nameof(UpdateTagTypeService)} - Request received - Payload: {JsonSerializer.Serialize(newTagType)}");
|
||||
|
||||
if (newTagType == null) return BadRequest("Invalid TagType object");
|
||||
|
||||
if (string.IsNullOrEmpty(newTagType.TypeName)) return BadRequest("Invalid TagType name");
|
||||
|
||||
return await Handle(() => inventoryServiceClient.UpdateTagTypeService(newTagType, cancellationToken)).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"{nameof(UpdateTagTypeService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newTagType)}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the status of the TagType.
|
||||
/// </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> ChangeTagTypeStatusService([FromBody] ChangeTagTypeStatusRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation($"{nameof(ChangeTagTypeStatusService)} - Request received - Payload: {JsonSerializer.Serialize(request)}");
|
||||
|
||||
if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid TagType identifier"); }
|
||||
|
||||
return await Handle(() => inventoryServiceClient.ChangeTagTypeStatusService(request, cancellationToken)).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"{nameof(ChangeTagTypeStatusService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Core.Adapters.Lib;
|
||||
using Core.Inventory.External.Clients.Inventory.Requests.Base;
|
||||
using Core.Inventory.External.Clients.Inventory.Requests.TagType;
|
||||
using Core.Inventory.External.Clients.Inventory.Requests.Variant;
|
||||
using Refit;
|
||||
|
||||
@@ -50,5 +51,27 @@ namespace Core.Inventory.External.Clients.Inventory
|
||||
Task<ApiResponse<IEnumerable<FurnitureVariant>>> GetAllVariantsAsync([Header("TrackingId")] string trackingId, CancellationToken cancellationToken = default);
|
||||
|
||||
#endregion
|
||||
|
||||
#region TagType
|
||||
|
||||
[Post("/api/v1/TagType/Create")]
|
||||
Task<ApiResponse<TagTypeAdapter>> CreateTagTypeService([Header("TrackingId")][Body] CreateTagTypeRequest request, CancellationToken cancellationToken = default);
|
||||
|
||||
[Post("/api/v1/TagType/GetById")]
|
||||
Task<ApiResponse<TagTypeAdapter>> GetTagTypeByIdService([Header("TrackingId")][Body] GetTagTypeRequest request, CancellationToken cancellationToken = default);
|
||||
|
||||
[Get("/api/v1/TagType/GetAll")]
|
||||
Task<ApiResponse<IEnumerable<TagTypeAdapter>>> GetAllTagTypesService([Header("TrackingId")][Body] GetAllTagTypesRequest request, CancellationToken cancellationToken = default);
|
||||
|
||||
[Post("/api/v1/TagType/GetTagTypeList")]
|
||||
Task<ApiResponse<IEnumerable<TagTypeAdapter>>> GetAllTagTypesByListService([Header("TrackingId")][Body] GetAllTagTypesByListRequest request, CancellationToken cancellationToken = default);
|
||||
|
||||
[Put("/api/v1/TagType/Update")]
|
||||
Task<ApiResponse<TagTypeAdapter>> UpdateTagTypeService([Header("TrackingId")][Body] UpdateTagTypeRequest request, CancellationToken cancellationToken = default);
|
||||
|
||||
[Patch("/api/v1/TagType/ChangeStatus")]
|
||||
Task<ApiResponse<TagTypeAdapter>> ChangeTagTypeStatusService([Header("TrackingId")][Body] ChangeTagTypeStatusRequest request, CancellationToken cancellationToken = default);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
using Core.Blueprint.Mongo;
|
||||
|
||||
namespace Core.Inventory.External.Clients.Inventory.Requests.TagType
|
||||
{
|
||||
public class ChangeTagTypeStatusRequest
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public StatusEnum Status { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Core.Inventory.External.Clients.Inventory.Requests.TagType
|
||||
{
|
||||
public class CreateTagTypeRequest
|
||||
{
|
||||
public string TenantId { get; set; } = null!;
|
||||
public string TypeName { get; set; } = null!;
|
||||
public int Level { get; set; }
|
||||
public string ParentTypeId { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Core.Inventory.External.Clients.Inventory.Requests.TagType
|
||||
{
|
||||
public class GetAllTagTypesByListRequest
|
||||
{
|
||||
public string[] TagTypes { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Core.Inventory.External.Clients.Inventory.Requests.TagType
|
||||
{
|
||||
public class GetAllTagTypesRequest
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Core.Inventory.External.Clients.Inventory.Requests.TagType
|
||||
{
|
||||
public class GetTagTypeRequest
|
||||
{
|
||||
public string Id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Core.Blueprint.Mongo;
|
||||
|
||||
namespace Core.Inventory.External.Clients.Inventory.Requests.TagType
|
||||
{
|
||||
public class UpdateTagTypeRequest
|
||||
{
|
||||
public string Id { get; set; } = null!;
|
||||
public string TenantId { get; set; } = null!;
|
||||
public string TypeName { get; set; } = null!;
|
||||
public int Level { get; set; }
|
||||
public string ParentTypeId { get; set; } = null!;
|
||||
public StatusEnum Status { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Adapters.Lib" Version="1.0.6" />
|
||||
<PackageReference Include="Adapters.Lib" Version="1.0.9" />
|
||||
<PackageReference Include="BuildingBlocks.Library" Version="1.0.0" />
|
||||
<PackageReference Include="Refit" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user