forked from slavaxom9k/PIBD-23_Fomichev_V.S._MagicCarpet
правки правки....
This commit is contained in:
@@ -16,17 +16,17 @@ namespace MagicCarpetBusinessLogic.Implementations;
|
||||
|
||||
public class AgencyBusinessLogicContract(IAgencyStorageContract agencyStorageContract, ILogger logger) : IAgencyBusinessLogicContract
|
||||
{
|
||||
private readonly IAgencyStorageContract _AgencyStorageContract = agencyStorageContract;
|
||||
private readonly IAgencyStorageContract _agencyStorageContract = agencyStorageContract;
|
||||
private readonly ILogger _logger = logger;
|
||||
public List<AgencyDataModel> GetAllComponents()
|
||||
public List<AgencyDataModel> GetAllAgencies()
|
||||
{
|
||||
_logger.LogInformation("GetAllComponents");
|
||||
return _AgencyStorageContract.GetList() ?? throw new NullListException();
|
||||
_logger.LogInformation("GetAllTours");
|
||||
return _agencyStorageContract.GetList() ?? throw new NullListException();
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public AgencyDataModel GetTourByData(string data)
|
||||
public AgencyDataModel GetAgencyByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
@@ -37,28 +37,28 @@ public class AgencyBusinessLogicContract(IAgencyStorageContract agencyStorageCon
|
||||
{
|
||||
throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _AgencyStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
return _agencyStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
|
||||
return new("", TourType.None, 0, []);
|
||||
}
|
||||
|
||||
public void InsertTour(AgencyDataModel AgencyDataModel)
|
||||
public void InsertAgency(AgencyDataModel AgencyDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(AgencyDataModel));
|
||||
ArgumentNullException.ThrowIfNull(AgencyDataModel);
|
||||
AgencyDataModel.Validate();
|
||||
_AgencyStorageContract.AddElement(AgencyDataModel);
|
||||
_agencyStorageContract.AddElement(AgencyDataModel);
|
||||
}
|
||||
|
||||
public void UpdateTour(AgencyDataModel AgencyDataModel)
|
||||
public void UpdateAgency(AgencyDataModel AgencyDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(AgencyDataModel));
|
||||
ArgumentNullException.ThrowIfNull(AgencyDataModel);
|
||||
AgencyDataModel.Validate();
|
||||
_AgencyStorageContract.UpdElement(AgencyDataModel);
|
||||
_agencyStorageContract.UpdElement(AgencyDataModel);
|
||||
}
|
||||
|
||||
public void DeleteTour(string id)
|
||||
public void DeleteAgency(string id)
|
||||
{
|
||||
logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
@@ -69,6 +69,6 @@ public class AgencyBusinessLogicContract(IAgencyStorageContract agencyStorageCon
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_AgencyStorageContract.DelElement(id);
|
||||
_agencyStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,20 +16,39 @@ namespace MagicCarpetBusinessLogic.Implementations;
|
||||
|
||||
public class SuppliesBusinessLogicContract(ISuppliesStorageContract suppliesStorageContract, ILogger logger) : ISuppliesBusinessLogicContract
|
||||
{
|
||||
private readonly ISuppliesStorageContract _suppliesStorageContract = suppliesStorageContract;
|
||||
private readonly ILogger _logger = logger;
|
||||
|
||||
public List<SuppliesDataModel> GetAllTours()
|
||||
private readonly ISuppliesStorageContract _supplyStorageContract = suppliesStorageContract;
|
||||
public List<SuppliesDataModel> GetAllSuppliesByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllTours");
|
||||
return _suppliesStorageContract.GetList() ?? throw new NullListException();
|
||||
|
||||
return [];
|
||||
_logger.LogInformation("GetAllSupplies params: {fromDate}, {toDate}", fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _supplyStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public SuppliesDataModel GetTourByData(string data)
|
||||
public List<SuppliesDataModel> GetAllSuppliesByCocktailByPeriod(string tourId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
_logger.LogInformation("GetAllSupplies params: {cocktailId}, {fromDate}, {toDate}", tourId, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
if (tourId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tourId));
|
||||
}
|
||||
if (!tourId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field tourId is not a unique identifier.");
|
||||
}
|
||||
return _supplyStorageContract.GetList(fromDate, toDate, tourId: tourId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public SuppliesDataModel GetSupplyByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get supply by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
@@ -38,25 +57,22 @@ public class SuppliesBusinessLogicContract(ISuppliesStorageContract suppliesStor
|
||||
{
|
||||
throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _suppliesStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
|
||||
return new("", TourType.None, DateTime.UtcNow, 0, []);
|
||||
return _supplyStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertTour(SuppliesDataModel suppliesDataModel)
|
||||
public void InsertSupply(SuppliesDataModel supplyDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(suppliesDataModel));
|
||||
ArgumentNullException.ThrowIfNull(suppliesDataModel);
|
||||
suppliesDataModel.Validate();
|
||||
_suppliesStorageContract.AddElement(suppliesDataModel);
|
||||
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(supplyDataModel));
|
||||
ArgumentNullException.ThrowIfNull(supplyDataModel);
|
||||
supplyDataModel.Validate();
|
||||
_supplyStorageContract.AddElement(supplyDataModel);
|
||||
}
|
||||
|
||||
public void UpdateTour(SuppliesDataModel suppliesDataModel)
|
||||
public void UpdateSupply(SuppliesDataModel supplyDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(suppliesDataModel));
|
||||
ArgumentNullException.ThrowIfNull(suppliesDataModel);
|
||||
suppliesDataModel.Validate();
|
||||
_suppliesStorageContract.UpdElement(suppliesDataModel);
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(supplyDataModel));
|
||||
ArgumentNullException.ThrowIfNull(supplyDataModel);
|
||||
supplyDataModel.Validate();
|
||||
_supplyStorageContract.UpdElement(supplyDataModel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ namespace MagicCarpetContracts.BusinessLogicContracts;
|
||||
|
||||
public interface IAgencyBusinessLogicContract
|
||||
{
|
||||
List<AgencyDataModel> GetAllTours();
|
||||
AgencyDataModel GetTourByData(string data);
|
||||
void InsertTour(AgencyDataModel agencyDataModel);
|
||||
void UpdateTour(AgencyDataModel agencyDataModel);
|
||||
void DeleteTour(string id);
|
||||
List<AgencyDataModel> GetAllAgencies();
|
||||
AgencyDataModel GetAgencyByData(string data);
|
||||
void InsertAgency(AgencyDataModel agencyDataModel);
|
||||
void UpdateAgency(AgencyDataModel agencyDataModel);
|
||||
void DeleteAgency(string id);
|
||||
}
|
||||
|
||||
@@ -9,8 +9,13 @@ namespace MagicCarpetContracts.BusinessLogicContracts;
|
||||
|
||||
public interface ISuppliesBusinessLogicContract
|
||||
{
|
||||
List<SuppliesDataModel> GetAllTours();
|
||||
SuppliesDataModel GetTourByData(string data);
|
||||
void InsertTour(SuppliesDataModel componentDataModel);
|
||||
void UpdateTour(SuppliesDataModel componentDataModel);
|
||||
List<SuppliesDataModel> GetAllSuppliesByPeriod(DateTime fromDate, DateTime toDate);
|
||||
|
||||
List<SuppliesDataModel> GetAllSuppliesByCocktailByPeriod(string tourId, DateTime fromDate, DateTime toDate);
|
||||
|
||||
SuppliesDataModel GetSupplyByData(string data);
|
||||
|
||||
void InsertSupply(SuppliesDataModel supplyDataModel);
|
||||
|
||||
void UpdateSupply(SuppliesDataModel supplyDataModel);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ namespace MagicCarpetContracts.StoragesContracts;
|
||||
public interface IAgencyStorageContract
|
||||
{
|
||||
List<AgencyDataModel> GetList();
|
||||
AgencyDataModel GetElementById(string id);
|
||||
AgencyDataModel? GetElementById(string id);
|
||||
AgencyDataModel? GetElementByName(string name);
|
||||
void AddElement(AgencyDataModel agencyDataModel);
|
||||
void UpdElement(AgencyDataModel agencyDataModel);
|
||||
void DelElement(string id);
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace MagicCarpetContracts.StoragesContracts;
|
||||
|
||||
public interface ISuppliesStorageContract
|
||||
{
|
||||
List<SuppliesDataModel> GetList(DateTime? startDate = null);
|
||||
List<SuppliesDataModel> GetList(DateTime? startDate = null, DateTime? endDate = null, string? tourId = null);
|
||||
SuppliesDataModel GetElementById(string id);
|
||||
void AddElement(SuppliesDataModel suppliesDataModel);
|
||||
void UpdElement(SuppliesDataModel suppliesDataModel);
|
||||
|
||||
@@ -15,7 +15,7 @@ using System.Threading.Tasks;
|
||||
namespace MagicCarpetTests.BusinessLogicContractsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class AgnecyBusinessLogicContractTests
|
||||
internal class AgnecyBusinessLogicContractTests
|
||||
{
|
||||
private IAgencyBusinessLogicContract _agencyBusinessLogicContract;
|
||||
private Mock<IAgencyStorageContract> _agencyStorageContract;
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Threading.Tasks;
|
||||
namespace MagicCarpetTests.BusinessLogicContractsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SuppliesBusinessLogicContractTests
|
||||
internal class SuppliesBusinessLogicContractTests
|
||||
{
|
||||
private SuppliesBusinessLogicContract _suppliesBusinessLogicContract;
|
||||
private Mock<ISuppliesStorageContract> _suppliesStorageContract;
|
||||
|
||||
Reference in New Issue
Block a user