Get Ticket Endpoint
In this lesson we'll implement the get ticket endpoint.
Implementing the Get Ticket Endpoint
The get ticket endpoint allows users to retrieve detailed information about a specific ticket they have purchased.
Let's add this new endpoint to our TicketController class:
@GetMapping(path = "/{ticketId}")
public ResponseEntity<GetTicketResponseDto> getTicket(
@AuthenticationPrincipal Jwt jwt,
@PathVariable UUID ticketId
) {
return ticketService
.getTicketForUser(parseUserId(jwt), ticketId)
.map(ticketMapper::toGetTicketResponseDto)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}The endpoint follows these steps:
- Gets the authenticated user's ID from the JWT token
- Uses the
TicketServiceto find the ticket for that user - Maps the ticket to a DTO if found
- Returns HTTP 200 with the ticket data if found, or HTTP 404 if not found
Summary
- Implemented the get ticket endpoint