refact program.cs vineyardController, service e repo

This commit is contained in:
Riccardo Usardi committed 2025-07-11 10:18:01 +02:00
1 parent a373201ca4
commit 3a1a0ca7ef
17 files changed
+769 -306

No files matched your search

@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using uWine.Core.Domain.Entities;
using uWine.Core.Domain.Repositories;
namespace uWine.Core.Infrastructure.Services
{
public class VineyardService
{
public IVineyardRepository _vineyardRepository;
public CoordinatesService _coordinatesService;
public VineyardService(IVineyardRepository vineyardRepository, CoordinatesService coordinatesService)
{
_vineyardRepository = vineyardRepository;
_coordinatesService = coordinatesService;
}
public void Insert(Vineyard vineyard, int ownerId)
{
if (vineyard == null)
{
throw new ArgumentNullException(nameof(vineyard), "Vineyard cannot be null");
}
_vineyardRepository.Insert(vineyard, ownerId);
if (vineyard.Area != null || vineyard.Area.Count >0)
{
_coordinatesService.SaveArea(vineyard.Id, vineyard.Area);
}
}
public List<Vineyard> User(int userId)
{
if (userId <= 0)
{
throw new ArgumentException("User ID must be greater than zero.", nameof(userId));
}
var vineyards = _vineyardRepository.GetUserVineyards(userId);
if (vineyards == null || !vineyards.Any())
{
return new List<Vineyard>();
}
foreach (var vineyard in vineyards)
{
vineyard.Area = _coordinatesService.GetArea(vineyard.Id);
}
return vineyards;
}
public List<Vineyard> Owner(int ownerId)
{
if (ownerId <= 0)
{
throw new ArgumentException("Owner ID must be greater than zero.", nameof(ownerId));
}
var vineyards = _vineyardRepository.GetOwnerVineyards(ownerId);
if (vineyards == null || !vineyards.Any())
{
return new List<Vineyard>();
}
foreach (var vineyard in vineyards)
{
vineyard.Area = _coordinatesService.GetArea(vineyard.Id);
}
return vineyards;
}
}
}