Get Published Event Endpoint

In this lesson, we'll implement the get published event details endpoint.

Implementing the Get Published Event Endpoint

We'll add a new endpoint to our PublishedEventController class that retrieves the details of a specific published event.

@GetMapping(path = "/{eventId}") public ResponseEntity<GetPublishedEventDetailsResponseDto> getPublishedEventDetails( @PathVariable UUID eventId ) { return eventService.getPublishedEvent(eventId) .map(eventMapper::toGetPublishedEventDetailsResponseDto) .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); }

Let's break down what this code does:

  • The @GetMapping annotation with a path variable defines the URL pattern for this endpoint
  • The method takes an eventId parameter that is extracted from the URL path
  • It calls the eventService.getPublishedEvent() method to fetch the event details
  • The result is mapped to our DTO using the eventMapper
  • If an event is found, it returns a 200 OK response with the event details
  • If no event is found, it returns a 404 Not Found response

Configuring Security

We need to ensure this endpoint is publicly accessible. Let's update the security configuration:

.requestMatchers(HttpMethod.GET, "/api/v1/published-events/**").permitAll()

This configuration uses a wildcard (**) to match any path after /api/v1/published-events/, including our new endpoint that includes the event ID.

Summary

  • Implemented the get published event endpoint
  • Updated SecurityConfig to make calls to make the get published event endpoint public
© 2026 Devtiro Ltd. All rights reserved