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")]
|
2024-11-17 12:59:08 +01:00
|
|
|
public class MeController : ApiController
|
2024-11-17 10:31:01 +01:00
|
|
|
{
|
|
|
|
private readonly IIdentityProvider _identityProvider;
|
|
|
|
private readonly IUserService _userService;
|
|
|
|
|
|
|
|
/// <summary>
|
2024-11-17 12:59:08 +01:00
|
|
|
/// 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>
|
2024-11-17 12:59:08 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|