2024-12-13 04:12:54 +04:00

124 lines
3.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using CandidateReviewContracts.BindingModels;
using CandidateReviewContracts.BusinessLogicsContracts;
using CandidateReviewContracts.SearchModels;
using CandidateReviewContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace CandidateReviewRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class VacancyController : Controller
{
private readonly ILogger _logger;
private readonly IVacancyLogic _logic;
public VacancyController(IVacancyLogic logic, ILogger<VacancyController> logger)
{
_logger = logger;
_logic = logic;
}
[HttpGet]
public VacancyViewModel? Details(int id)
{
try
{
return _logic.ReadElement(new VacancySearchModel
{
Id = id
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения вакансии");
throw;
}
}
[HttpGet]
public List<VacancyViewModel>? Search(string? tags)
{
try
{
if (!string.IsNullOrEmpty(tags))
{
return _logic.ReadList(new VacancySearchModel
{
Tags = tags,
Status = CandidateReviewDataModels.Enums.VacancyStatusEnum.Открыта
});
}
return new List<VacancyViewModel>();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения вакансий");
throw;
}
}
[HttpGet]
public List<VacancyViewModel>? List(int? companyId)
{
try
{
if (companyId.HasValue)
{
return _logic.ReadList(new VacancySearchModel
{
CompanyId = companyId
});
}
else return new List<VacancyViewModel>();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения вакансий");
throw;
}
}
[HttpPost]
public void Create(VacancyBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания вакансии");
throw;
}
}
[HttpPost]
public void Update(VacancyBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления вакансии");
throw;
}
}
[HttpPost]
public void Delete(VacancyBindingModel model)
{
try
{
_logic.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления вакансии");
throw;
}
}
}
}