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

@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using NetTopologySuite.Geometries;
using uWine.Core.Domain.Entities;
using uWine.Core.Infrastructure.Services;
namespace uWine.Api.Controllers
@@ -31,6 +33,9 @@ namespace uWine.Api.Controllers
}
[HttpGet("get-owner-vineyards")]
[ProducesResponseType(typeof(List<Vineyard>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult OwnerVineyards()
{
try
@@ -45,5 +50,29 @@ namespace uWine.Api.Controllers
return Unauthorized(new { status = 401 });
}
}
[HttpPost("new-vineyard")]
[ProducesResponseType(typeof(Vineyard), StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public IActionResult NewVineyard([FromBody] Vineyard vineyard)
{
if (vineyard == null || string.IsNullOrEmpty(vineyard.Name))
{
return BadRequest("Invalid vineyard data.");
}
try
{
var UserId = int.Parse(User.FindFirst("userId")?.Value);
vineyard.UserId = UserId;
var createdVineyard = _vineyardService.New(vineyard);
return CreatedAtAction(nameof(NewVineyard), new { id = createdVineyard.Id }, createdVineyard);
}
catch (Exception ex)
{
return BadRequest($"Error creating vineyard: {ex.Message}");
}
}
}
}