CourseWork/University/UniversityRestApi/Controllers/AttestationController.cs
2024-05-28 00:44:31 +04:00

75 lines
2.2 KiB
C#

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]
public List<AttestationViewModel>? GetAttestations(int userId)
{
try
{
return _logic.ReadList(new AttestationSearchModel { UserId = userId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения аттестаций пользователя id={Id}", userId);
throw;
}
}
[HttpPost]
public void CreateAttestation(AttestationBindingModel model)
{
try
{
_logic.CreateAttestation(model);
} catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания аттестации");
throw;
}
}
[HttpPut]
public void UpdateAttestation(AttestationBindingModel model)
{
try
{
_logic.UpdateAttestation(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления аттестации");
throw;
}
}
[HttpDelete]
public void DeleteAttestation(AttestationBindingModel model)
{
try
{
_logic.DeleteAttestation(model);
}
catch(Exception ex)
{
_logger.LogError(ex, "Ошибка удаления аттестации");
throw;
}
}
}
}