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:

  1. Gets the authenticated user's ID from the JWT token
  2. Uses the TicketService to find the ticket for that user
  3. Maps the ticket to a DTO if found
  4. Returns HTTP 200 with the ticket data if found, or HTTP 404 if not found

Summary

  • Implemented the get ticket endpoint
© 2026 Devtiro Ltd. All rights reserved