44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using System.Security.Claims;
|
|
using FictionArchive.Service.UserService.Models.DTOs;
|
|
using FictionArchive.Service.UserService.Services;
|
|
using HotChocolate.Authorization;
|
|
using HotChocolate.Data;
|
|
|
|
namespace FictionArchive.Service.UserService.GraphQL;
|
|
|
|
public class Query
|
|
{
|
|
[Authorize]
|
|
[UseProjection]
|
|
[UseFirstOrDefault]
|
|
public IQueryable<UserDto> GetCurrentUser(
|
|
UserServiceDbContext dbContext,
|
|
ClaimsPrincipal claimsPrincipal)
|
|
{
|
|
var oAuthProviderId = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
|
if (string.IsNullOrEmpty(oAuthProviderId))
|
|
{
|
|
return Enumerable.Empty<UserDto>().AsQueryable();
|
|
}
|
|
|
|
return dbContext.Users
|
|
.Where(u => u.OAuthProviderId == oAuthProviderId)
|
|
.Select(u => new UserDto
|
|
{
|
|
Id = u.Id,
|
|
CreatedTime = u.CreatedTime,
|
|
LastUpdatedTime = u.LastUpdatedTime,
|
|
Username = u.Username,
|
|
Email = u.Email,
|
|
Disabled = u.Disabled,
|
|
AvailableInvites = u.AvailableInvites,
|
|
InviterId = u.InviterId,
|
|
InvitedUsers = u.InvitedUsers.Select(iu => new InvitedUserDto
|
|
{
|
|
Username = iu.Username,
|
|
Email = iu.Email
|
|
}).ToList()
|
|
});
|
|
}
|
|
}
|