45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using Galaeth.Core.Dtos;
|
|
using Galaeth.Services.Interfaces;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Galaeth.ApiServer.Controllers;
|
|
|
|
/// <summary>
|
|
/// Api methods for the requesting authorised user.
|
|
/// </summary>
|
|
[ApiController]
|
|
[Authorize]
|
|
[Route("v1/me")]
|
|
public class MeController : ApiController
|
|
{
|
|
private readonly IIdentityProvider _identityProvider;
|
|
private readonly IUserService _userService;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="MeController"/> class.
|
|
/// </summary>
|
|
/// <param name="identityProvider">Instance of <see cref="IIdentityProvider"/>.</param>
|
|
/// <param name="userService">Instance of <see cref="IUserService"/>.</param>
|
|
public MeController(
|
|
IIdentityProvider identityProvider,
|
|
IUserService userService)
|
|
{
|
|
_identityProvider = identityProvider;
|
|
_userService = userService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the requesting user information and return it.
|
|
/// </summary>
|
|
/// <returns>Instance of <see cref="UserDto"/>.</returns>
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetMe()
|
|
{
|
|
var userId = _identityProvider.GetRequestingUserId();
|
|
var user = await _userService.FindById(userId);
|
|
|
|
return SuccessResult(user);
|
|
}
|
|
}
|