Get Ticket Dto Mapper
In this lesson we'll implement the DTOs and mappers that we need for the list tickets endpoint.
Creating the List Ticket Response DTOs
We'll start by creating two Data Transfer Objects (DTOs) to represent ticket information when listing tickets.
The first DTO, ListTicketResponseDto, will contain the main ticket information:
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ListTicketResponseDto {
private UUID id;
private TicketStatusEnum status;
private ListTicketTicketTypeResponseDto ticketType;
}The second DTO, ListTicketTicketTypeResponseDto, will contain information about the ticket type:
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ListTicketTicketTypeResponseDto {
private UUID id;
private String name;
private Double price;
}Implementing the Ticket Mapper
Now we'll create a mapper to convert between our entities and DTOs.
The TicketMapper interface uses MapStruct to handle the conversion:
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface TicketMapper {
ListTicketTicketTypeResponseDto toListTicketTicketTypeResponseDto(TicketType ticketType);
ListTicketResponseDto toListTicketResponseDto(Ticket ticket);
}The mapper includes two methods:
toListTicketTicketTypeResponseDtoconverts aTicketTypeentity to its DTO representationtoListTicketResponseDtoconverts aTicketentity to its DTO representation
Summary
- Created
ListTicketResponseDtoandListTicketTicketTypeResponseDtoclasses - Created
TicketMapperwith mapper methods