49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// Профиль пользователя
|
|
/// </summary>
|
|
[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;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Профиль текущего пользователя
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet(ApiRoutes.UserProfile.Get)]
|
|
public async Task<IActionResult> Get()
|
|
{
|
|
var user = await authService.GetCurrentUserAsync();
|
|
|
|
if (user == null)
|
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при получении текущего пользователя" } }));
|
|
|
|
var response = mapper.Map<UserProfileResponse>(user);
|
|
|
|
return Ok(new Response<UserProfileResponse>(response, true));
|
|
}
|
|
}
|
|
}
|