Validate Ticket Dto Mapper
In this lesson, we're going to create the DTOs and mappers that we need in order to implement our validate ticket endpoint.
Creating the Request DTO
The TicketValidationRequestDto is a simple data class that carries validation request information.
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TicketValidationRequestDto {
private UUID id;
private TicketValidationMethod method;
}The class has two fields:
- An
idfield of typeUUIDwhich can represent either a QR code ID or a ticket ID - A
methodfield of typeTicketValidationMethodenum to specify the validation method
Creating the Response DTO
The TicketValidationResponseDto represents the result of a ticket validation attempt.
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TicketValidationResponseDto {
private UUID ticketId;
private TicketValidationStatusEnum status;
}This class contains:
- A
ticketIdfield to identify the validated ticket - A
statusfield usingTicketValidationStatusEnumto indicate the validation result
Implementing the Mapper
The TicketValidationMapper interface handles the conversion between domain objects and DTOs.
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface TicketValidationMapper {
@Mapping(target = "ticketId", source = "ticket.id")
TicketValidationResponseDto toTicketValidationResponseDto(TicketValidation ticketValidation);
}The mapper has a single method that:
- Takes a
TicketValidationdomain object as input - Maps it to a
TicketValidationResponseDto - Uses
@Mappingto specify that theticketIdfield should come fromticket.id
Summary
- Added
TicketValidationRequestDtoandTicketValidationResponseDtoDTO classes - Added the mapping method
toTicketValidationResponseDtotoTicketValidationMapper