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:
IRoleMapperfor mapping user roles.IProfileMapperfor mapping the user profile.IAdvertiserMapperfor mapping advertiser-related data.
Additionally, it uses the IRoleService to retrieve role entities based on IDs provided
in the request DTO.
Key responsibilities:
- Convert
Userentities intoUserResponseDTOobjects. - Convert
UserRequestDTOobjects intoUserentities. - Transform collections of
Userentities 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 IAdvertiserMapperprivate final IProfileMapperprivate final IRoleMapperprivate final IRoleService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiontoEntity(UserRequestDTO requestDTO) Converts aUserRequestDTOinto aUserentity.toListResponseDTO(Collection<User> entities) Converts a collection ofUserentities into a list ofUserResponseDTO.toResponseDTO(User entity) Converts aUserentity into aUserResponseDTO.Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.alpaca.mapper.GenericMapper
toPageResponseDTO
-
Field Details
-
roleMapper
-
profileMapper
-
IAdvertiserMapper
-
roleService
-
-
Constructor Details
-
UserMapperImpl
public UserMapperImpl()
-
-
Method Details
-
toResponseDTO
Converts aUserentity into aUserResponseDTO.- Specified by:
toResponseDTOin interfaceGenericMapper<User,UserResponseDTO, UserRequestDTO> - Parameters:
entity- the user entity to convert, may benull.- Returns:
- the corresponding response DTO, or
nullif the input isnull.
-
toEntity
Converts aUserRequestDTOinto aUserentity.Roles are resolved using the
IRoleServiceto fetch the corresponding entities.- Specified by:
toEntityin interfaceGenericMapper<User,UserResponseDTO, UserRequestDTO> - Parameters:
requestDTO- the request DTO containing user input data, may benull.- Returns:
- the corresponding
Userentity, ornullif the input isnull.
-
toListResponseDTO
Converts a collection ofUserentities into a list ofUserResponseDTO.- Specified by:
toListResponseDTOin interfaceGenericMapper<User,UserResponseDTO, UserRequestDTO> - Parameters:
entities- the collection of user entities, may benullor empty.- Returns:
- a list of response DTOs, or an empty list if the input is
nullor empty.
-