2024-08-13 12:29:01 +01:00
|
|
|
|
using API.Models;
|
|
|
|
|
using API.Persistence.Repositories;
|
2024-08-16 11:53:39 +01:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-08-13 12:29:01 +01:00
|
|
|
|
using Microsoft.VisualStudio.Web.CodeGenerators.Mvc.Templates.BlazorIdentity.Pages.Manage;
|
|
|
|
|
|
|
|
|
|
namespace API.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)
|
2024-08-13 12:29:01 +01:00
|
|
|
|
{
|
|
|
|
|
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" });
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-13 12:29:01 +01:00
|
|
|
|
UserDTO userDTO = new UserDTO
|
|
|
|
|
{
|
|
|
|
|
Id = user.Id,
|
|
|
|
|
Email = user.Email,
|
|
|
|
|
Username = user.Username
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return userDTO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|