Skip to content

Commit 97ddb74

Browse files
committed
fix4
1 parent 493c741 commit 97ddb74

4 files changed

Lines changed: 9 additions & 13 deletions

File tree

ewm-service/src/main/java/ru/practicum/ewm/compilation/repository/CompilationRepository.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public interface CompilationRepository extends JpaRepository<Compilation, Long>
1717
@EntityGraph(attributePaths = {"events"})
1818
Page<Compilation> findByPinned(boolean pinned, Pageable pageable);
1919

20+
@Override
2021
@EntityGraph(attributePaths = {"events"})
2122
Optional<Compilation> findById(Long id);
2223
}

ewm-service/src/main/java/ru/practicum/ewm/compilation/service/CompilationServiceImpl.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public CompilationDto createCompilation(NewCompilationDto dto) {
3838
.collect(Collectors.toSet());
3939
return CompilationMapper.toCompilationDto(compilation, eventShortDtos);
4040
}
41-
4241
@Override
4342
@Transactional
4443
public CompilationDto updateCompilation(Long compId, UpdateCompilationRequest request) {
@@ -55,11 +54,7 @@ public CompilationDto updateCompilation(Long compId, UpdateCompilationRequest re
5554
compilation.setEvents(events);
5655
}
5756
compilation = compilationRepository.save(compilation);
58-
Set<Event> events = compilation.getEvents();
59-
if (events == null) {
60-
events = Set.of();
61-
}
62-
Set<EventShortDto> eventShortDtos = events.stream()
57+
Set<EventShortDto> eventShortDtos = compilation.getEvents().stream()
6358
.map(event -> EventMapper.toEventShortDto(event, 0L, 0L))
6459
.collect(Collectors.toSet());
6560
return CompilationMapper.toCompilationDto(compilation, eventShortDtos);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Page<Event> findAllByAdminFilters(@Param("users") List<Long> users,
3636
"LEFT JOIN FETCH e.category " +
3737
"LEFT JOIN FETCH e.initiator " +
3838
"WHERE e.state = 'PUBLISHED' " +
39-
"AND (:text IS NULL OR LOWER(e.annotation) LIKE LOWER(CONCAT('%', :text, '%')) OR LOWER(e.description) LIKE LOWER(CONCAT('%', :text, '%'))) " +
39+
"AND (:text IS NULL OR (LOWER(e.annotation) LIKE LOWER(CONCAT('%', :text, '%')) OR LOWER(e.description) LIKE LOWER(CONCAT('%', :text, '%')))) " +
4040
"AND (:categories IS NULL OR e.category.id IN :categories) " +
4141
"AND (:paid IS NULL OR e.paid = :paid) " +
4242
"AND e.eventDate BETWEEN :rangeStart AND :rangeEnd")

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public List<EventShortDto> getEvents(String text, List<Long> categories, Boolean
3636
LocalDateTime rangeStart, LocalDateTime rangeEnd,
3737
Boolean onlyAvailable, SortType sort,
3838
int from, int size, HttpServletRequest request) {
39-
if (size <= 0) {
40-
size = 10;
41-
}
42-
if (from < 0) {
43-
from = 0;
39+
if (size <= 0) size = 10;
40+
if (from < 0) from = 0;
41+
42+
if (rangeStart != null && rangeEnd != null && rangeStart.isAfter(rangeEnd)) {
43+
throw new IllegalArgumentException("Дата начала не может быть позже даты окончания");
4444
}
4545

4646
sendHit(request);
@@ -122,7 +122,7 @@ private Map<Long, Long> getViewsMap(List<Event> events) {
122122
.collect(Collectors.toList());
123123
try {
124124
LocalDateTime start = LocalDateTime.of(2000, 1, 1, 0, 0, 0);
125-
LocalDateTime end = LocalDateTime.now().plusMinutes(5);
125+
LocalDateTime end = LocalDateTime.now().plusDays(1);
126126
List<ViewStats> stats = statsClient.getStats(start, end, uris, false);
127127
return stats.stream()
128128
.collect(Collectors.toMap(

0 commit comments

Comments
 (0)