59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
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 });
|
|
}
|
|
}
|
|
}
|
|
}
|