Dtos Mappers
In this lesson, we'll implement the DTOs and mappers needed for displaying published events on the attendee landing page.
Implement the DTO
Let's create the ListPublishedEventResponseDto class:
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ListPublishedEventResponseDto {
private UUID id;
private String name;
private LocalDateTime start;
private LocalDateTime end;
private String venue;
}This DTO includes only the fields needed for the event cards on the landing page: the event's ID, name, start and end times, and venue.
Adding the Mapper Method
Now we'll add a method to our EventMapper interface to convert Event entities to our new DTO:
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface EventMapper {
// ... existing methods ...
ListPublishedEventResponseDto toListPublishedEventResponseDto(Event event);
}The MapStruct library will automatically generate the implementation because our DTO field names match the Event entity's field names.
Summary
- Created the
ListPublishedEventResponseDtoclass - Added the
toListPublishedEventResponseDtomethod to theEventMapperinterface