List Published Events Service

In this lesson, we'll implement the list published events service layer.

Service Layer Implementation

Let's add the listPublishedEvents method to our EventService interface:

public interface EventService { // ... existing methods ... Page<Event> listPublishedEvents(Pageable pageable); }

Next, we'll implement the method in our EventServiceImpl class:

@Override public Page<Event> listPublishedEvents(Pageable pageable) { // Use the repository to find events with PUBLISHED status return eventRepository.findByStatus(EventStatusEnum.PUBLISHED, pageable); }

Repository Layer Implementation

To support our service layer, we need to add a method to our EventRepository interface that can find events by their status:

@Repository public interface EventRepository extends JpaRepository<Event, UUID> { // ... existing methods ... // Find events by their status (e.g., PUBLISHED) Page<Event> findByStatus(EventStatusEnum status, Pageable pageable); }

The findByStatus method follows Spring Data JPA's method naming convention, which automatically generates the correct query based on the method name.

Summary

  • Added the findByStatus method to the EventRepository interface
  • Added the listPublishedEvents method to the EventService interface
  • Implemented the listPublishedEvents method in the EventServiceImpl class
© 2026 Devtiro Ltd. All rights reserved