diff --git a/src/TeamUp.Api/Endpoints/UserAccess/GetMyProfileEndpoint.cs b/src/TeamUp.Api/Endpoints/UserAccess/GetUserDetailsEndpoint.cs similarity index 78% rename from src/TeamUp.Api/Endpoints/UserAccess/GetMyProfileEndpoint.cs rename to src/TeamUp.Api/Endpoints/UserAccess/GetUserDetailsEndpoint.cs index b604531..0d1cd26 100644 --- a/src/TeamUp.Api/Endpoints/UserAccess/GetMyProfileEndpoint.cs +++ b/src/TeamUp.Api/Endpoints/UserAccess/GetUserDetailsEndpoint.cs @@ -8,19 +8,19 @@ namespace TeamUp.Api.Endpoints.UserAccess; -public sealed class GetMyProfileEndpoint : IEndpointGroup +public sealed class GetUserDetailsEndpoint : IEndpointGroup { public void MapEndpoints(RouteGroupBuilder group) { - group.MapGet("/my-profile", GetMyProfileAsync) + group.MapGet("/", GetUserDetailsAsync) .Produces(StatusCodes.Status200OK) .ProducesProblem(StatusCodes.Status401Unauthorized) - .WithName(nameof(GetMyProfileEndpoint)) + .WithName(nameof(GetUserDetailsEndpoint)) .MapToApiVersion(1) .RequireAuthorization(); } - private async Task GetMyProfileAsync( + private async Task GetUserDetailsAsync( [FromServices] ISender sender, [FromServices] IHttpContextAccessor httpContextAccessor, CancellationToken ct) diff --git a/src/TeamUp.Api/Endpoints/UserAccess/RegisterUserEndpoint.cs b/src/TeamUp.Api/Endpoints/UserAccess/RegisterUserEndpoint.cs index 548de90..f0edc8d 100644 --- a/src/TeamUp.Api/Endpoints/UserAccess/RegisterUserEndpoint.cs +++ b/src/TeamUp.Api/Endpoints/UserAccess/RegisterUserEndpoint.cs @@ -30,7 +30,7 @@ private async Task RegisterUserAsync( var command = mapper.ToCommand(request); var result = await sender.Send(command, ct); return result.Match( - userId => TypedResults.Created(linkGenerator.GetPathByName(nameof(GetMyProfileEndpoint)), userId) + userId => TypedResults.Created(linkGenerator.GetPathByName(nameof(GetUserDetailsEndpoint)), userId) ); } } diff --git a/src/TeamUp.Api/Endpoints/UserAccessEndpointGroup.cs b/src/TeamUp.Api/Endpoints/UserAccessEndpointGroup.cs index dec9a81..435b118 100644 --- a/src/TeamUp.Api/Endpoints/UserAccessEndpointGroup.cs +++ b/src/TeamUp.Api/Endpoints/UserAccessEndpointGroup.cs @@ -10,6 +10,6 @@ public void MapEndpoints(RouteGroupBuilder group) group.MapEndpoint() .MapEndpoint() .MapEndpoint() - .MapEndpoint(); + .MapEndpoint(); } } diff --git a/src/TeamUp.Application/Invitations/GetTeamInvitations/GetTeamInvitationsQueryHandler.cs b/src/TeamUp.Application/Invitations/GetTeamInvitations/GetTeamInvitationsQueryHandler.cs index 6c971e1..1cee0ff 100644 --- a/src/TeamUp.Application/Invitations/GetTeamInvitations/GetTeamInvitationsQueryHandler.cs +++ b/src/TeamUp.Application/Invitations/GetTeamInvitations/GetTeamInvitationsQueryHandler.cs @@ -19,12 +19,14 @@ public GetTeamInvitationsQueryHandler(IAppQueryContext appQueryContext) public async Task>> Handle(GetTeamInvitationsQuery request, CancellationToken ct) { var teamWithInitiator = await _appQueryContext.Teams - .Where(team => team.Id == request.TeamId) .Select(team => new { - Initiaotor = team.Members.FirstOrDefault(member => member.UserId == request.InitiatorId), + team.Id, + Initiaotor = team.Members + .Select(member => new { member.UserId, member.Role }) + .FirstOrDefault(member => member.UserId == request.InitiatorId), }) - .FirstOrDefaultAsync(ct); + .FirstOrDefaultAsync(team => team.Id == request.TeamId, ct); return await teamWithInitiator .EnsureNotNull(TeamErrors.TeamNotFound) @@ -33,10 +35,18 @@ public async Task>> Handle(GetTeamInvitation .ThenAsync(team => { return _appQueryContext.Invitations + .Select(invitation => new + { + invitation.TeamId, + invitation.CreatedUtc, + _appQueryContext.Users + .Select(user => new { user.Id, user.Email }) + .First(user => user.Id == invitation.RecipientId).Email, + }) .Where(invitation => invitation.TeamId == request.TeamId) .Select(invitation => new TeamInvitationResponse { - Email = _appQueryContext.Users.First(user => user.Id == invitation.RecipientId).Email, + Email = invitation.Email, CreatedUtc = invitation.CreatedUtc }) .ToListAsync(ct); diff --git a/src/TeamUp.Application/Users/GetUserDetail/GetUserDetailsQueryHandler.cs b/src/TeamUp.Application/Users/GetUserDetail/GetUserDetailsQueryHandler.cs index 2a9ad0a..89342a3 100644 --- a/src/TeamUp.Application/Users/GetUserDetail/GetUserDetailsQueryHandler.cs +++ b/src/TeamUp.Application/Users/GetUserDetail/GetUserDetailsQueryHandler.cs @@ -10,19 +10,22 @@ namespace TeamUp.Application.Users.GetUserDetail; internal sealed class GetUserDetailsQueryHandler : IQueryHandler> { private readonly IAppQueryContext _queryContext; - private readonly UserMapper _mapper; - public GetUserDetailsQueryHandler(IAppQueryContext queryContext, UserMapper mapper) + public GetUserDetailsQueryHandler(IAppQueryContext queryContext) { _queryContext = queryContext; - _mapper = mapper; } public async Task> Handle(GetUserDetailsQuery request, CancellationToken ct) { var user = await _queryContext.Users .Where(user => user.Id == request.UserId) - .Select(user => _mapper.ToResponse(user)) + .Select(user => new UserResponse + { + Email = user.Email, + Name = user.Name, + Status = user.Status + }) .FirstOrDefaultAsync(ct); return user.EnsureNotNull(UserErrors.UserNotFound); diff --git a/src/TeamUp.Application/Users/UserMapper.cs b/src/TeamUp.Application/Users/UserMapper.cs index 9ed9ad0..019056d 100644 --- a/src/TeamUp.Application/Users/UserMapper.cs +++ b/src/TeamUp.Application/Users/UserMapper.cs @@ -3,7 +3,6 @@ using TeamUp.Application.Users.Login; using TeamUp.Application.Users.Register; using TeamUp.Contracts.Users; -using TeamUp.Domain.Aggregates.Users; namespace TeamUp.Application.Users; @@ -13,6 +12,4 @@ public sealed partial class UserMapper public partial RegisterUserCommand ToCommand(RegisterUserRequest request); public partial LoginCommand ToCommand(LoginRequest request); - - public partial UserResponse ToResponse(User user); } diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/GetMyProfileTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/GetUserDetailsTests.cs similarity index 73% rename from tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/GetMyProfileTests.cs rename to tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/GetUserDetailsTests.cs index 125990e..7c53f6a 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/GetMyProfileTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/GetUserDetailsTests.cs @@ -2,16 +2,16 @@ namespace TeamUp.EndToEndTests.EndpointTests.UserAccess; -public sealed class GetMyProfileTests : BaseUserAccessTests +public sealed class GetUserDetailsTests : BaseUserAccessTests { - public GetMyProfileTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } + public GetUserDetailsTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { } [Fact] public async Task GetMyProfile_WhenUnauthenticated_Should_ResultInUnauthorized() { //arrange //act - var response = await Client.GetAsync("/api/v1/users/my-profile"); + var response = await Client.GetAsync("/api/v1/users"); //assert response.Should().Be401Unauthorized(); @@ -32,7 +32,7 @@ await UseDbContextAsync(dbContext => Authenticate(user); //act - var response = await Client.GetAsync("/api/v1/users/my-profile"); + var response = await Client.GetAsync("/api/v1/users"); //assert response.Should().Be200Ok();