2024-04-29 19:06:11 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using UniversityContracts.BindingModels;
|
|
|
|
|
using UniversityContracts.BusinessLogicsContracts;
|
|
|
|
|
using UniversityContracts.SearchModels;
|
|
|
|
|
using UniversityContracts.ViewModels;
|
|
|
|
|
using UniversityDataModels.Enums;
|
|
|
|
|
|
|
|
|
|
namespace UniversityRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class AttestationController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IAttestationLogic _logic;
|
|
|
|
|
public AttestationController(IAttestationLogic logic, ILogger<AttestationController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logic = logic;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2024-05-28 00:44:23 +04:00
|
|
|
|
public List<AttestationViewModel>? GetAttestations(int userId)
|
2024-04-29 19:06:11 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-28 00:44:23 +04:00
|
|
|
|
return _logic.ReadList(new AttestationSearchModel { UserId = userId });
|
2024-04-29 19:06:11 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-05-28 00:44:23 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка получения аттестаций пользователя id={Id}", userId);
|
2024-04-29 19:06:11 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-29 21:59:17 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public AttestationViewModel? GetAttestation(int userId, int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _logic.ReadElement(new AttestationSearchModel { UserId = userId, Id = id });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения аттестаций пользователя id={Id}", userId);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-29 19:06:11 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateAttestation(AttestationBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.CreateAttestation(model);
|
|
|
|
|
} catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания аттестации");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-29 21:59:17 +04:00
|
|
|
|
[HttpPost]
|
2024-04-29 19:06:11 +04:00
|
|
|
|
public void UpdateAttestation(AttestationBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.UpdateAttestation(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка обновления аттестации");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-29 21:59:17 +04:00
|
|
|
|
[HttpPost]
|
2024-04-29 19:06:11 +04:00
|
|
|
|
public void DeleteAttestation(AttestationBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.DeleteAttestation(model);
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления аттестации");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|