Create Dto Classes
In this lesson, we'll implement the Data Transfer Objects (DTOs) needed to implement our get event endpoint.
Create the DTOs
We'll create two DTOs - one for the event details and another for its ticket types.
Let's start with the ticket type DTO:
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GetEventDetailsTicketTypesResponseDto {
private UUID id;
private String name;
private Double price;
private String description;
private Integer totalAvailable;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
}Next, let's create the event details DTO:
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GetEventDetailsResponseDto {
private UUID id;
private String name;
private LocalDateTime start;
private LocalDateTime end;
private String venue;
private LocalDateTime salesStart;
private LocalDateTime salesEnd;
private EventStatusEnum status;
private List<GetEventDetailsTicketTypesResponseDto> ticketTypes = new ArrayList<>();
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
}Adding Mapper Methods
We need to add methods to our EventMapper interface to convert our entities to these DTOs:
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface EventMapper {
// ... existing methods ...
GetEventDetailsTicketTypesResponseDto toGetEventDetailsTicketTypesResponseDto(TicketType ticketType);
GetEventDetailsResponseDto toGetEventDetailsResponseDto(Event event);
}Summary
- Created
GetEventDetailsResponseDtoto represent complete event information - Created
GetEventDetailsTicketTypeResponseDtoto represent ticket type details - Added mapper methods to convert entities to DTOs