85 lines
2.2 KiB
C#
85 lines
2.2 KiB
C#
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 UserController : Controller
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IUserLogic _logic;
|
|
public UserController(IUserLogic logic, ILogger<UserController> logger)
|
|
{
|
|
_logger = logger;
|
|
_logic = logic;
|
|
}
|
|
|
|
[HttpGet]
|
|
public UserViewModel? Login(string login, string password)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadElement(new UserSearchModel
|
|
{
|
|
Email = login,
|
|
Password = password
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public UserViewModel? Profile(int id)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadElement(new UserSearchModel
|
|
{
|
|
Id = id
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения данных");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Register(UserBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка регистрации");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Update(UserBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Update(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка обновления данных");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|