Package com.alpaca.mapper
Interface GenericMapper<T,ResponseDTO,RequestDTO>
- All Known Subinterfaces:
IAdvertiserMapper
,IPermissionMapper
,IProfileMapper
,IRoleMapper
,IUserMapper
- All Known Implementing Classes:
AdvertiserMapperImpl
,PermissionMapperImpl
,ProfileMapperImpl
,RoleMapperImpl
,UserMapperImpl
public interface GenericMapper<T,ResponseDTO,RequestDTO>
A generic mapper interface to facilitate conversion between entities, request DTOs, and response
DTOs.
This interface defines methods for:
- Converting a single entity to a response DTO.
- Converting a request DTO to an entity.
- Mapping a collection of entities to a list of response DTOs.
- Converting a Spring Data
Page
of entities into aPage
of response DTOs, handling null or empty cases gracefully.
-
Method Summary
Modifier and TypeMethodDescriptiontoEntity
(RequestDTO requestDTO) Converts a request DTO into an entity instance.toListResponseDTO
(Collection<T> entities) Converts a collection of entities into a list of response DTOs.default org.springframework.data.domain.Page
<ResponseDTO> toPageResponseDTO
(org.springframework.data.domain.Page<T> entities) Converts a paginated list of entities into a paginated list of response DTOs.toResponseDTO
(T entity) Converts an entity instance to its corresponding response DTO.
-
Method Details
-
toResponseDTO
Converts an entity instance to its corresponding response DTO.- Parameters:
entity
- the domain entity- Returns:
- a response DTO representing the entity
-
toEntity
Converts a request DTO into an entity instance.- Parameters:
requestDTO
- the incoming request data- Returns:
- a domain entity constructed from the request DTO
-
toListResponseDTO
Converts a collection of entities into a list of response DTOs.- Parameters:
entities
- a collection of domain entities- Returns:
- a list of corresponding response DTOs
-
toPageResponseDTO
default org.springframework.data.domain.Page<ResponseDTO> toPageResponseDTO(org.springframework.data.domain.Page<T> entities) Converts a paginated list of entities into a paginated list of response DTOs. If the source page is null or empty, returns an empty, unpaged page.- Parameters:
entities
- aPage
of domain entities- Returns:
- a
Page
of response DTOs preserving paging metadata
-