diff --git a/service/src/main/java/greencity/service/EventServiceImpl.java b/service/src/main/java/greencity/service/EventServiceImpl.java index f23e1fd595..78b21c316f 100644 --- a/service/src/main/java/greencity/service/EventServiceImpl.java +++ b/service/src/main/java/greencity/service/EventServiceImpl.java @@ -156,7 +156,7 @@ public PageableAdvancedDto getAllFilteredEvents( User user = modelMapper.map(restClient.findByEmail(principal.getName()), User.class); List allEvents = getAllFilteredEventsAndSortedByIdDesc( eventRepo.findAll(), user.getId(), filterEventDto); - Page eventPage = new PageImpl<>(getEventsForCurrentPage(page, allEvents), page, allEvents.size()); + Page eventPage = new PageImpl<>(allEvents, page, allEvents.size()); return buildPageableAdvancedDto(eventPage); } @@ -165,7 +165,7 @@ public PageableAdvancedDto getAllUserEvents( Pageable page, String email, String userLatitude, String userLongitude, String eventType) { User attender = modelMapper.map(restClient.findByEmail(email), User.class); List events = sortUserEventsByEventType(eventType, attender, userLatitude, userLongitude); - Page eventPage = new PageImpl<>(getEventsForCurrentPage(page, events), page, events.size()); + Page eventPage = new PageImpl<>(events, page, events.size()); return buildPageableAdvancedDto(eventPage, attender.getId()); } @@ -176,12 +176,6 @@ public PageableAdvancedDto getAllFavoriteEventsByUser(Pageable page, S return buildPageableAdvancedDto(events, user.getId()); } - private List getEventsForCurrentPage(Pageable page, List allEvents) { - int startIndex = page.getPageNumber() * page.getPageSize(); - int endIndex = Math.min(startIndex + page.getPageSize(), allEvents.size()); - return allEvents.subList(startIndex, endIndex); - } - private List sortUserEventsByEventType( String eventType, User attender, String userLatitude, String userLongitude) { if (StringUtils.isNotBlank(eventType) && eventType.equalsIgnoreCase("ONLINE")) {