forked from slavaxom9k/PIBD-23_Fomichev_V.S._MagicCarpet
62 lines
2.2 KiB
C#
62 lines
2.2 KiB
C#
using MagicCarpetContracts.BusinessLogicContracts;
|
|
using MagicCarpetContracts.DataModels;
|
|
using MagicCarpetContracts.Enums;
|
|
using MagicCarpetContracts.Exceptions;
|
|
using MagicCarpetContracts.Extensions;
|
|
using MagicCarpetContracts.StoragesContracts;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MagicCarpetBusinessLogic.Implementations;
|
|
|
|
public class SuppliesBusinessLogicContract(ISuppliesStorageContract suppliesStorageContract, ILogger logger) : ISuppliesBusinessLogicContract
|
|
{
|
|
private readonly ISuppliesStorageContract _suppliesStorageContract = suppliesStorageContract;
|
|
private readonly ILogger _logger = logger;
|
|
|
|
public List<SuppliesDataModel> GetAllComponents()
|
|
{
|
|
_logger.LogInformation("GetAllComponents");
|
|
return _suppliesStorageContract.GetList() ?? throw new NullListException();
|
|
|
|
return [];
|
|
}
|
|
|
|
public SuppliesDataModel GetComponentByData(string data)
|
|
{
|
|
_logger.LogInformation("Get element by data: {data}", data);
|
|
if (data.IsEmpty())
|
|
{
|
|
throw new ArgumentNullException(nameof(data));
|
|
}
|
|
if (!data.IsGuid())
|
|
{
|
|
throw new ElementNotFoundException(data);
|
|
}
|
|
return _suppliesStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
|
|
|
return new("", TourType.None, DateTime.UtcNow, 0, []);
|
|
}
|
|
|
|
public void InsertComponent(SuppliesDataModel suppliesDataModel)
|
|
{
|
|
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(suppliesDataModel));
|
|
ArgumentNullException.ThrowIfNull(suppliesDataModel);
|
|
suppliesDataModel.Validate();
|
|
_suppliesStorageContract.AddElement(suppliesDataModel);
|
|
}
|
|
|
|
public void UpdateComponent(SuppliesDataModel suppliesDataModel)
|
|
{
|
|
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(suppliesDataModel));
|
|
ArgumentNullException.ThrowIfNull(suppliesDataModel);
|
|
suppliesDataModel.Validate();
|
|
_suppliesStorageContract.UpdElement(suppliesDataModel);
|
|
}
|
|
}
|