mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-15 01:54:43 +00:00
Address PR #310 review feedback on the public profile page
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Domain.Entities;
|
||||
using Domain.Exceptions;
|
||||
using Features.Users.Dtos;
|
||||
using Features.Users.Queries.GetAllUsers;
|
||||
using Features.Users.Queries.GetUserById;
|
||||
using MediatR;
|
||||
@@ -37,4 +38,19 @@ public class UserController(IMediator mediator) : ControllerBase
|
||||
UserAccount user = await mediator.Send(new GetUserByIdQuery(id));
|
||||
return Ok(user);
|
||||
}
|
||||
|
||||
/// <summary>Gets the public profile for the user account with the given ID.</summary>
|
||||
/// <remarks>
|
||||
/// Exposes only the fields that are safe to show on an unauthenticated, public profile page;
|
||||
/// unlike <see cref="GetById"/>, this never returns <c>Email</c> or <c>DateOfBirth</c>.
|
||||
/// </remarks>
|
||||
/// <exception cref="NotFoundException">
|
||||
/// Thrown when no user account exists with the given ID, resulting in a 404 response.
|
||||
/// </exception>
|
||||
[HttpGet("{id:guid}/profile")]
|
||||
public async Task<ActionResult<PublicUserProfileDto>> GetPublicProfile(Guid id)
|
||||
{
|
||||
UserAccount user = await mediator.Send(new GetUserByIdQuery(id));
|
||||
return Ok(user.ToPublicProfileDto());
|
||||
}
|
||||
}
|
||||
|
||||
11
web/backend/Features/Features.Users/Dtos/UserDtoMapper.cs
Normal file
11
web/backend/Features/Features.Users/Dtos/UserDtoMapper.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Domain.Entities;
|
||||
|
||||
namespace Features.Users.Dtos;
|
||||
|
||||
/// <summary>Converts user domain entities into API response models.</summary>
|
||||
public static class UserDtoMapper
|
||||
{
|
||||
/// <summary>Converts a user account into its public-profile representation.</summary>
|
||||
public static PublicUserProfileDto ToPublicProfileDto(this UserAccount user) =>
|
||||
new(user.UserAccountId, user.Username, user.FirstName, user.LastName, user.CreatedAt);
|
||||
}
|
||||
10
web/backend/Features/Features.Users/Dtos/UserDtos.cs
Normal file
10
web/backend/Features/Features.Users/Dtos/UserDtos.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Features.Users.Dtos;
|
||||
|
||||
/// <summary>Represents the subset of a user account that is safe to expose on a public profile.</summary>
|
||||
public record PublicUserProfileDto(
|
||||
Guid UserAccountId,
|
||||
string Username,
|
||||
string FirstName,
|
||||
string LastName,
|
||||
DateTime CreatedAt
|
||||
);
|
||||
Reference in New Issue
Block a user