Files
PIbd-24_EredavkinRA_TheAvto…/AutoTazBusinessLogic/implementations/DealerBusinessLogicContract.cs
2025-03-13 15:23:49 +04:00

84 lines
2.8 KiB
C#

using AvtoTAZContratcs.BusinessLogicsContracts;
using AvtoTAZContratcs.DataModels;
using AvtoTAZContratcs.Exceptions;
using AvtoTAZContratcs.Extensions;
using AvtoTAZContratcs.StoragesContracts;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text.Json;
namespace AutoTazBusinessLogic.implementations;
internal class DealerBusinessLogicContract(IDealerStorageContact dealerStorageContact, ILogger logger) : IDealerBusinessLogicContract
{
private readonly IDealerStorageContact _dealerStorageContact = dealerStorageContact;
private readonly ILogger _logger = logger;
public List<DealerDataModel> GetAllDealer()
{
_logger.LogInformation("GetAllDealer");
return _dealerStorageContact.GetList() ?? throw new NullListException();
// Заглушка для TDD
// return [];
}
public DealerDataModel GetDealerByData(string data)
{
_logger.LogInformation("Get element by data: {data}", data);
if (data.IsEmpty())
{
throw new ArgumentNullException(nameof(data), "Data cannot be null or empty");
}
DealerDataModel? result;
if (data.IsGuid())
{
result = _dealerStorageContact.GetElementById(data);
}
else
{
result = _dealerStorageContact.GetElementNameDealer(data);
}
return result ?? throw new ElementNotFoundException($"Dealer with data '{data}' not found");
// Заглушка для TDD
// return new DealerDataModel("", "");
}
public void InsertDealer(DealerDataModel dealerDataModel)
{
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(dealerDataModel));
ArgumentNullException.ThrowIfNull(dealerDataModel);
dealerDataModel.Validate();
_dealerStorageContact.AddElement(dealerDataModel);
// Заглушка для TDD
// return;
}
public void UpdateDealer(DealerDataModel dealerDataModel)
{
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(dealerDataModel));
ArgumentNullException.ThrowIfNull(dealerDataModel);
dealerDataModel.Validate();
_dealerStorageContact.UpdElement(dealerDataModel);
// Заглушка для TDD
// return;
}
public void DeleteDealer(string id)
{
_logger.LogInformation("Delete by id: {id}", id);
if (id.IsEmpty())
{
throw new ArgumentNullException(nameof(id), "ID cannot be null or empty");
}
if (!id.IsGuid())
{
throw new ValidationException("Id is not a unique identifier");
}
_dealerStorageContact.DelElement(id);
// Заглушка для TDD
// return;
}
}