This commit is contained in:
Riccardo Usardi committed 2025-07-20 11:49:20 +02:00
1 parent 3a1a0ca7ef
commit 6bce1d9330
9 files changed
+167 -13

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
using Microsoft.AspNetCore.Mvc;
using uWine.Core.Domain.Entities;
using uWine.Core.Infrastructure.Services;
namespace uWine.Api.Controllers
{
[ApiController]
[Route("/[controller]")]
public class OwnerController : Controller
{
private readonly IConfiguration _configuration;
private readonly OwnerService _ownerService;
public OwnerController(IConfiguration configuration, OwnerService ownerService)
{
_configuration = configuration;
_ownerService = ownerService;
}
[HttpGet("get-owner")]
[ProducesResponseType(typeof(Owner), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public ActionResult Single(int ownerId)
{
{
try
{
var owner = _ownerService.Owner(ownerId);
if (owner == null)
return NotFound(new { status = "Owner not found" });
return Ok(owner);
}
catch
{
return Unauthorized(new { status = 401 });
}
}
}
[HttpPost("save-owner")]
public ActionResult Save(Owner owner)
{
if (owner == null)
return BadRequest("Invalid owner data");
try
{
_ownerService.New(owner);
return Ok();
}
catch (Exception ex)
{
return StatusCode(500, new { error = ex.Message });
}
}
}
}