CourseWork/University/UniversityRestApi/Controllers/AttestationController.cs

75 lines
2.2 KiB
C#
Raw Normal View History

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)
{
try
{
2024-05-28 00:44:23 +04:00
return _logic.ReadList(new AttestationSearchModel { UserId = userId });
}
catch (Exception ex)
{
2024-05-28 00:44:23 +04:00
_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;
}
}
}
}