Skip to content

Commit 1fb4b1c

Browse files
committed
fix15
1 parent ebf3282 commit 1fb4b1c

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

ewm-service/src/main/java/ru/practicum/ewm/event/repository/EventRepository.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,21 @@ Page<Event> findAllByAdminFilters(@Param("users") List<Long> users,
3131
@Param("rangeEnd") LocalDateTime rangeEnd,
3232
Pageable pageable);
3333

34-
@Query(value = "SELECT DISTINCT e.* FROM events e " +
35-
"LEFT JOIN categories c ON c.id = e.category_id " +
36-
"LEFT JOIN users u ON u.id = e.initiator_id " +
34+
@Query("SELECT DISTINCT e FROM Event e " +
35+
"LEFT JOIN FETCH e.category " +
36+
"LEFT JOIN FETCH e.initiator " +
3737
"WHERE e.state = 'PUBLISHED' " +
38-
"AND (:text IS NULL OR (LOWER(e.annotation::text) LIKE LOWER(CONCAT('%', :text, '%')) " +
39-
"OR LOWER(e.description::text) LIKE LOWER(CONCAT('%', :text, '%')))) " +
40-
"AND (:categories IS NULL OR e.category_id IN (:categories)) " +
38+
"AND (:text IS NULL OR LOWER(e.annotation) LIKE LOWER(CONCAT('%', :text, '%')) OR LOWER(e.description) LIKE LOWER(CONCAT('%', :text, '%'))) " +
39+
"AND (:categories IS NULL OR e.category.id IN :categories) " +
4140
"AND (:paid IS NULL OR e.paid = :paid) " +
42-
"AND (:rangeStart IS NULL OR e.event_date >= :rangeStart) " +
43-
"AND (:rangeEnd IS NULL OR e.event_date <= :rangeEnd) " +
44-
"OFFSET :offset ROWS FETCH NEXT :size ROWS ONLY", nativeQuery = true)
45-
List<Event> findPublishedEventsWithFilters(@Param("text") String text,
41+
"AND (:rangeStart IS NULL OR e.eventDate >= :rangeStart) " +
42+
"AND (:rangeEnd IS NULL OR e.eventDate <= :rangeEnd)")
43+
Page<Event> findPublishedEventsWithFilters(@Param("text") String text,
4644
@Param("categories") List<Long> categories,
4745
@Param("paid") Boolean paid,
4846
@Param("rangeStart") LocalDateTime rangeStart,
4947
@Param("rangeEnd") LocalDateTime rangeEnd,
50-
@Param("offset") int offset,
51-
@Param("size") int size);
48+
Pageable pageable);
5249

5350
@Query("SELECT COUNT(r) FROM Request r WHERE r.event.id = :eventId AND r.status = 'CONFIRMED'")
5451
Long countConfirmedRequests(@Param("eventId") Long eventId);

ewm-service/src/main/java/ru/practicum/ewm/event/service/EventServiceImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import lombok.extern.slf4j.Slf4j;
66
import org.springframework.data.domain.Page;
77
import org.springframework.data.domain.PageRequest;
8+
import org.springframework.data.domain.Pageable;
89
import org.springframework.stereotype.Service;
910
import org.springframework.transaction.annotation.Transactional;
1011
import ru.practicum.ewm.category.model.Category;
@@ -194,9 +195,11 @@ public List<EventShortDto> getEventsForPublic(PublicEventSearchParams params, Ht
194195

195196
statsClient.sendHit(request);
196197

197-
List<Event> events = eventRepository.findPublishedEventsWithFilters(
198+
Pageable pageable = PageRequest.of(from / size, size);
199+
Page<Event> eventPage = eventRepository.findPublishedEventsWithFilters(
198200
params.getText(), params.getCategories(), params.getPaid(),
199-
rangeStart, rangeEnd, from, size);
201+
rangeStart, rangeEnd, pageable);
202+
List<Event> events = eventPage.getContent();
200203

201204
Map<Long, Long> confirmedRequestsMap = getConfirmedRequestsMap(events);
202205

0 commit comments

Comments
 (0)