refact program.cs vineyardController, service e repo
This commit is contained in:
1 parent
a373201ca4
commit
3a1a0ca7ef
17 files changed
+769
-306
No files matched your search
@@ -18,14 +18,14 @@ namespace uWine.Api.Controllers
|
||||
}
|
||||
|
||||
[HttpPost("save-area")]
|
||||
public IActionResult SaveArea([FromBody] Dictionary<int,Coordinates> coordinates, int vineyardId)
|
||||
public IActionResult SaveArea([FromBody] Dictionary<int, Coordinates> coordinates, int vineyardId)
|
||||
{
|
||||
if (coordinates == null)
|
||||
return BadRequest("Invalid coordinates");
|
||||
|
||||
try
|
||||
{
|
||||
_coordinatesService.SaveArea(vineyardId ,coordinates);
|
||||
_coordinatesService.SaveArea(vineyardId, coordinates);
|
||||
return Ok(new { status = "Area set successfully" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -33,5 +33,22 @@ namespace uWine.Api.Controllers
|
||||
return StatusCode(500, new { error = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("get-area")]
|
||||
public IActionResult GetArea(int vineyardId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var area = _coordinatesService.GetArea(vineyardId);
|
||||
if (area == null || area.Count == 0)
|
||||
return NotFound("No area found for the given vineyard ID");
|
||||
|
||||
return Ok(area);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, new { error = ex.Message });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using uWine.Core.Infrastructure.Services;
|
||||
|
||||
namespace uWine.Api.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("/[controller]")]
|
||||
public class VineyardController : Controller
|
||||
{
|
||||
public VineyardService _vineyardService;
|
||||
public VineyardController(VineyardService vineyardService)
|
||||
{
|
||||
_vineyardService = vineyardService;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("get-user-vineyards")]
|
||||
public IActionResult UserVineyards()
|
||||
{
|
||||
try
|
||||
{
|
||||
var UserId = int.Parse(User.FindFirst("userId")?.Value);
|
||||
var list = _vineyardService.User(UserId);
|
||||
|
||||
return Ok(list);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Unauthorized(new { status = 401 });
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("get-owner-vineyards")]
|
||||
public IActionResult OwnerVineyards()
|
||||
{
|
||||
try
|
||||
{
|
||||
var UserId = int.Parse(User.FindFirst("userId")?.Value);
|
||||
var list = _vineyardService.Owner(UserId);
|
||||
|
||||
return Ok(list);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Unauthorized(new { status = 401 });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user