Interface UserMapper
public interface UserMapper
MapStruct mapper for converting user entities and posts to data transfer objects.
-
Method Summary
Modifier and TypeMethodDescriptiontoUpdateUserResponseDTO(UserEntity userEntity, String profilePictureUrl) Maps user entity and profile picture URL to update response DTO.toUserDTO(UserEntity userEntity, List<PostEntity> posts, String profilePictureUrl) Maps user entity and associated posts to a complete user DTO.toUserEntity(UpdateUserRequestDTO requestDTO, UserEntity userEntity, String passwordHash) Updates user entity with values from request DTO and password hash.toUserEntity(Long id) Creates a user entity with only the ID populated.toUserPostSummaryDto(PostEntity postEntity, String profilePictureUrl) Maps a post entity to a post summary DTO.
-
Method Details
-
toUserDTO
Maps user entity and associated posts to a complete user DTO.- Parameters:
userEntity- user entity with profile informationposts- list of post entities authored by the userprofilePictureUrl- URL of the user's profile picture to include in the post summary- Returns:
- user DTO with profile and post summaries
-
toUserPostSummaryDto
Maps a post entity to a post summary DTO.- Parameters:
postEntity- post entity to mapprofilePictureUrl- URL of the user's profile picture to include in the post summary- Returns:
- post summary DTO
-
toUserEntity
Creates a user entity with only the ID populated.- Parameters:
id- the user ID- Returns:
- user entity with only ID set
-
toUserEntity
UserEntity toUserEntity(UpdateUserRequestDTO requestDTO, UserEntity userEntity, String passwordHash) Updates user entity with values from request DTO and password hash. Uses IGNORE strategy - only non-null fields from requestDTO are applied.- Parameters:
requestDTO- DTO containing fields to update (null fields are ignored)userEntity- existing user entity to update (modified in place)passwordHash- optional new password hash (null if password not changed)- Returns:
- the modified user entity
-
toUpdateUserResponseDTO
Maps user entity and profile picture URL to update response DTO.- Parameters:
userEntity- updated user entityprofilePictureUrl- URL of the user's profile picture- Returns:
- update response DTO with username, bio, and profile picture URL
-