Package com.alpaca.mapper.impl
Class UserMapperImpl
java.lang.Object
com.alpaca.mapper.impl.UserMapperImpl
- All Implemented Interfaces:
GenericMapper<User,
,UserResponseDTO, UserRequestDTO> IUserMapper
Implementation of the
IUserMapper
interface responsible for mapping between User
entities and their corresponding request and response DTOs.
This mapper delegates nested object transformations to other mappers:
IRoleMapper
for mapping user roles.IProfileMapper
for mapping the user profile.IAdvertiserMapper
for mapping advertiser-related data.
Additionally, it uses the IRoleService
to retrieve role entities based on IDs provided
in the request DTO.
Key responsibilities:
- Convert
User
entities intoUserResponseDTO
objects. - Convert
UserRequestDTO
objects intoUser
entities. - Transform collections of
User
entities into lists ofUserResponseDTO
. - Handle null and empty inputs gracefully by returning safe defaults.
This class is annotated with Component
to enable Spring's dependency injection and
uses Lombok's RequiredArgsConstructor
for constructor-based injection (if required in
future).
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final IAdvertiserMapper
private final IProfileMapper
private final IRoleMapper
private final IRoleService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiontoEntity
(UserRequestDTO requestDTO) Converts aUserRequestDTO
into aUser
entity.toListResponseDTO
(Collection<User> entities) Converts a collection ofUser
entities into a list ofUserResponseDTO
.toResponseDTO
(User entity) Converts aUser
entity into aUserResponseDTO
.Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.alpaca.mapper.GenericMapper
toPageResponseDTO
-
Field Details
-
roleMapper
-
profileMapper
-
IAdvertiserMapper
-
roleService
-
-
Constructor Details
-
UserMapperImpl
public UserMapperImpl()
-
-
Method Details
-
toResponseDTO
Converts aUser
entity into aUserResponseDTO
.- Specified by:
toResponseDTO
in interfaceGenericMapper<User,
UserResponseDTO, UserRequestDTO> - Parameters:
entity
- the user entity to convert, may benull
.- Returns:
- the corresponding response DTO, or
null
if the input isnull
.
-
toEntity
Converts aUserRequestDTO
into aUser
entity.Roles are resolved using the
IRoleService
to fetch the corresponding entities.- Specified by:
toEntity
in interfaceGenericMapper<User,
UserResponseDTO, UserRequestDTO> - Parameters:
requestDTO
- the request DTO containing user input data, may benull
.- Returns:
- the corresponding
User
entity, ornull
if the input isnull
.
-
toListResponseDTO
Converts a collection ofUser
entities into a list ofUserResponseDTO
.- Specified by:
toListResponseDTO
in interfaceGenericMapper<User,
UserResponseDTO, UserRequestDTO> - Parameters:
entities
- the collection of user entities, may benull
or empty.- Returns:
- a list of response DTOs, or an empty list if the input is
null
or empty.
-