Skip to content

Commit 493c741

Browse files
committed
fix3
1 parent 26fc904 commit 493c741

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ public CompilationDto updateCompilation(Long compId, UpdateCompilationRequest re
5555
compilation.setEvents(events);
5656
}
5757
compilation = compilationRepository.save(compilation);
58-
Set<EventShortDto> eventShortDtos = compilation.getEvents().stream()
58+
Set<Event> events = compilation.getEvents();
59+
if (events == null) {
60+
events = Set.of();
61+
}
62+
Set<EventShortDto> eventShortDtos = events.stream()
5963
.map(event -> EventMapper.toEventShortDto(event, 0L, 0L))
6064
.collect(Collectors.toSet());
6165
return CompilationMapper.toCompilationDto(compilation, eventShortDtos);

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import ru.practicum.statistics.dto.ViewStats;
2121

2222
import java.time.LocalDateTime;
23-
import java.time.format.DateTimeFormatter;
2423
import java.util.*;
2524
import java.util.stream.Collectors;
2625

@@ -31,15 +30,19 @@ public class PublicEventServiceImpl implements PublicEventService {
3130
private final EventRepository eventRepository;
3231
private final StatsClient statsClient;
3332

34-
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
35-
private static final LocalDateTime STATS_START = LocalDateTime.of(2000, 1, 1, 0, 0, 0);
36-
3733
@Override
3834
@Transactional(readOnly = true)
3935
public List<EventShortDto> getEvents(String text, List<Long> categories, Boolean paid,
4036
LocalDateTime rangeStart, LocalDateTime rangeEnd,
4137
Boolean onlyAvailable, SortType sort,
4238
int from, int size, HttpServletRequest request) {
39+
if (size <= 0) {
40+
size = 10;
41+
}
42+
if (from < 0) {
43+
from = 0;
44+
}
45+
4346
sendHit(request);
4447

4548
LocalDateTime now = LocalDateTime.now();
@@ -119,7 +122,7 @@ private Map<Long, Long> getViewsMap(List<Event> events) {
119122
.collect(Collectors.toList());
120123
try {
121124
LocalDateTime start = LocalDateTime.of(2000, 1, 1, 0, 0, 0);
122-
LocalDateTime end = LocalDateTime.now().plusSeconds(10);
125+
LocalDateTime end = LocalDateTime.now().plusMinutes(5);
123126
List<ViewStats> stats = statsClient.getStats(start, end, uris, false);
124127
return stats.stream()
125128
.collect(Collectors.toMap(

0 commit comments

Comments
 (0)