galaeth-draft/Galaeth.ApiServer/Controllers/MeController.cs

45 lines
1.3 KiB
C#
Raw Permalink Normal View History

2024-11-17 10:31:01 +01:00
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
2024-11-17 10:31:01 +01:00
{
private readonly IIdentityProvider _identityProvider;
private readonly IUserService _userService;
/// <summary>
/// Initializes a new instance of the <see cref="MeController"/> class.
2024-11-17 10:31:01 +01:00
/// </summary>
/// <param name="identityProvider">Instance of <see cref="IIdentityProvider"/>.</param>
/// <param name="userService">Instance of <see cref="IUserService"/>.</param>
public MeController(
2024-11-17 10:31:01 +01:00
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);
}
}