Add TagType CRUD

This commit is contained in:
Oscar Morales
2025-07-31 19:07:22 -06:00
parent e191851982
commit 54dd38cfd6
6 changed files with 410 additions and 1 deletions

View File

@@ -0,0 +1,154 @@
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);
}
}
}