using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using PARR.API.Contracts.V1;
using PARR.API.Contracts.V1.Responses;
using PARR.API.Contracts.V1.Responses.Base;
using PARR.API.Controllers.V1.Base;
using PARR.API.Services.Interfaces;
namespace PARR.API.Controllers.V1
{
///
/// Профиль пользователя
///
[Authorize]
public class UserProfileController : BaseApiController
{
private readonly IAuthService authService;
private readonly IMapper mapper;
public UserProfileController(
IAuthService authService,
IMapper mapper
)
{
this.authService = authService;
this.mapper = mapper;
}
///
/// Профиль текущего пользователя
///
///
[HttpGet(ApiRoutes.UserProfile.Get)]
public async Task Get()
{
var user = await authService.GetCurrentUserAsync();
if (user == null)
return BadRequest(new Response(false, new List { new ErrorModel { Message = "Ошибка при получении текущего пользователя" } }));
var response = mapper.Map(user);
return Ok(new Response(response, true));
}
}
}