skantravels/services/AuthorizationService/Application/Users/Queries/QueryUserById.cs

38 lines
998 B
C#
Raw Normal View History

2024-08-15 14:21:17 +01:00
using AuthorizationService.Models;
using AuthorizationService.Persistence.Repositories;
2024-08-16 11:53:39 +01:00
using Microsoft.AspNetCore.Mvc;
using Microsoft.VisualStudio.Web.CodeGenerators.Mvc.Templates.BlazorIdentity.Pages.Manage;
2024-08-15 14:21:17 +01:00
namespace AuthorizationService.Application.Users.Queries
{
public class QueryUserById
{
private readonly IUserRepository _repository;
public QueryUserById(IUserRepository repository)
{
_repository = repository;
}
2024-08-16 11:53:39 +01:00
public async Task<ActionResult<UserDTO>> Handle(string id)
{
User user = await _repository.QueryUserByIdAsync(id);
2024-08-16 11:53:39 +01:00
if (user == null)
{
return new ConflictObjectResult(new { message = "No user on given Id" });
}
UserDTO userDTO = new UserDTO
{
Id = user.Id,
Email = user.Email,
Username = user.Username
};
return userDTO;
}
}
}