2025-02-18 11:19:18 +03:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using PapaCarloContracts.BusinessLogicContracts;
|
2025-02-17 14:16:47 +03:00
|
|
|
|
using PapaCarloContracts.DataModels;
|
2025-02-18 11:19:18 +03:00
|
|
|
|
using PapaCarloContracts.Exceptions;
|
|
|
|
|
using PapaCarloContracts.Extensions;
|
2025-02-18 10:55:27 +03:00
|
|
|
|
using PapaCarloContracts.StoragesContracts;
|
2025-02-17 14:16:47 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2025-02-18 11:19:18 +03:00
|
|
|
|
using System.Text.Json;
|
2025-02-17 14:16:47 +03:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace PapaCarloBusinessLogic.Implementations
|
|
|
|
|
{
|
2025-02-18 11:19:18 +03:00
|
|
|
|
internal class BlankBusinessLogicContract(IBlankStorageContract blankStorageContract, ILogger logger) : IBlankBusinessLogicContract
|
2025-02-17 14:16:47 +03:00
|
|
|
|
{
|
2025-02-18 11:19:18 +03:00
|
|
|
|
private readonly ILogger _logger = logger;
|
|
|
|
|
private IBlankStorageContract _blankStorageContract = blankStorageContract;
|
|
|
|
|
|
2025-02-17 14:16:47 +03:00
|
|
|
|
public void DeleteBlank(string id)
|
|
|
|
|
{
|
2025-02-18 11:19:18 +03:00
|
|
|
|
_logger.LogInformation("Delete by id: {id}", id);
|
|
|
|
|
if (id.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(id));
|
|
|
|
|
}
|
|
|
|
|
if (!id.IsGuid())
|
|
|
|
|
{
|
|
|
|
|
throw new ValidationException("Id is not a unique identifier");
|
|
|
|
|
}
|
|
|
|
|
_blankStorageContract.DelElement(id);
|
2025-02-17 14:16:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<BlankDataModel> GetAllBlanks()
|
|
|
|
|
{
|
2025-02-18 11:19:18 +03:00
|
|
|
|
_logger.LogInformation("GetAllBlanks");
|
|
|
|
|
return _blankStorageContract.GetList() ?? throw new NullListException();
|
2025-02-17 14:16:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BlankDataModel GetBlankByData(string data)
|
|
|
|
|
{
|
2025-02-18 11:19:18 +03:00
|
|
|
|
_logger.LogInformation("Get element by data {data}", data);
|
|
|
|
|
if (data.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(data));
|
|
|
|
|
}
|
|
|
|
|
if (data.IsGuid())
|
|
|
|
|
{
|
|
|
|
|
return _blankStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
|
|
|
|
}
|
|
|
|
|
return _blankStorageContract.GetElementByName(data) ?? throw new ElementNotFoundException(data);
|
2025-02-17 14:16:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void InsertBlank(BlankDataModel blankDataModel)
|
|
|
|
|
{
|
2025-02-18 11:19:18 +03:00
|
|
|
|
_logger.LogInformation("New data:{json}", JsonSerializer.Serialize(blankDataModel));
|
|
|
|
|
ArgumentNullException.ThrowIfNull(blankDataModel);
|
|
|
|
|
blankDataModel.Validate();
|
|
|
|
|
_blankStorageContract.AddElement(blankDataModel);
|
2025-02-17 14:16:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateBlank(BlankDataModel blankDataModel)
|
|
|
|
|
{
|
2025-02-18 11:19:18 +03:00
|
|
|
|
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(blankDataModel));
|
|
|
|
|
ArgumentNullException.ThrowIfNull(blankDataModel);
|
|
|
|
|
blankDataModel.Validate();
|
|
|
|
|
_blankStorageContract.UpdElement(blankDataModel);
|
2025-02-17 14:16:47 +03:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|