Skip to content

Commit 26fc904

Browse files
committed
fix2
1 parent 4193b1f commit 26fc904

5 files changed

Lines changed: 28 additions & 7 deletions

File tree

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,12 @@ public CompilationDto updateCompilation(Long compId, UpdateCompilationRequest re
5050
if (request.getPinned() != null) {
5151
compilation.setPinned(request.getPinned());
5252
}
53-
Set<Event> events = compilation.getEvents();
54-
if (request.getEvents() != null) {
55-
events = Set.copyOf(eventRepository.findAllById(request.getEvents()));
53+
if (request.getEvents() != null && !request.getEvents().isEmpty()) {
54+
Set<Event> events = Set.copyOf(eventRepository.findAllById(request.getEvents()));
5655
compilation.setEvents(events);
5756
}
5857
compilation = compilationRepository.save(compilation);
59-
Set<EventShortDto> eventShortDtos = events.stream()
58+
Set<EventShortDto> eventShortDtos = compilation.getEvents().stream()
6059
.map(event -> EventMapper.toEventShortDto(event, 0L, 0L))
6160
.collect(Collectors.toSet());
6261
return CompilationMapper.toCompilationDto(compilation, eventShortDtos);

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,19 @@ public class AdminEventServiceImpl implements AdminEventService {
3030
@Transactional(readOnly = true)
3131
public List<EventFullDto> getEvents(List<Long> users, List<EventState> states, List<Long> categories,
3232
LocalDateTime rangeStart, LocalDateTime rangeEnd, int from, int size) {
33+
if (size <= 0) {
34+
size = 10;
35+
}
36+
if (from < 0) {
37+
from = 0;
38+
}
39+
40+
LocalDateTime start = (rangeStart != null) ? rangeStart : LocalDateTime.of(1970, 1, 1, 0, 0, 0);
41+
LocalDateTime end = (rangeEnd != null) ? rangeEnd : LocalDateTime.of(3000, 1, 1, 0, 0, 0);
42+
3343
PageRequest page = PageRequest.of(from / size, size);
34-
Page<Event> eventsPage = eventRepository.findAllByAdminFilters(users, states, categories, rangeStart, rangeEnd, page);
44+
Page<Event> eventsPage = eventRepository.findAllByAdminFilters(users, states, categories, start, end, page);
45+
3546
return eventsPage.stream()
3647
.map(event -> EventMapper.toEventFullDto(event, 0L, eventRepository.countConfirmedRequests(event.getId())))
3748
.collect(Collectors.toList());

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ private void sendHit(HttpServletRequest request) {
106106
hit.setIp(request.getRemoteAddr());
107107
hit.setTimestamp(LocalDateTime.now());
108108
statsClient.sendHit(hit);
109+
log.info("Хит отправлен: {} {}", hit.getUri(), hit.getIp());
109110
} catch (Exception e) {
110111
log.error("Ошибка при отправке статистики: {}", e.getMessage());
111112
}
@@ -117,7 +118,9 @@ private Map<Long, Long> getViewsMap(List<Event> events) {
117118
.map(event -> "/events/" + event.getId())
118119
.collect(Collectors.toList());
119120
try {
120-
List<ViewStats> stats = statsClient.getStats(STATS_START, LocalDateTime.now().plusDays(1), uris, false);
121+
LocalDateTime start = LocalDateTime.of(2000, 1, 1, 0, 0, 0);
122+
LocalDateTime end = LocalDateTime.now().plusSeconds(10);
123+
List<ViewStats> stats = statsClient.getStats(start, end, uris, false);
121124
return stats.stream()
122125
.collect(Collectors.toMap(
123126
vs -> Long.parseLong(vs.getUri().substring(vs.getUri().lastIndexOf('/') + 1)),

ewm-service/src/main/java/ru/practicum/ewm/exception/ErrorHandler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.springframework.web.bind.annotation.ExceptionHandler;
99
import org.springframework.web.bind.annotation.ResponseStatus;
1010
import org.springframework.web.bind.annotation.RestControllerAdvice;
11+
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
1112

1213
import java.time.LocalDateTime;
1314
import java.time.format.DateTimeFormatter;
@@ -73,4 +74,12 @@ public ApiError handleArithmetic(ArithmeticException e) {
7374
log.error("400 {}", e.getMessage());
7475
return buildApiError(HttpStatus.BAD_REQUEST, "Некорректные параметры пагинации", e.getMessage());
7576
}
77+
78+
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
79+
@ResponseStatus(HttpStatus.BAD_REQUEST)
80+
public ApiError handleMethodArgumentTypeMismatch(MethodArgumentTypeMismatchException e) {
81+
log.error("400 {}", e.getMessage());
82+
return buildApiError(HttpStatus.BAD_REQUEST, "Некорректное значение параметра",
83+
"Параметр '" + e.getName() + "' имеет неверный тип");
84+
}
7685
}

ewm-service/src/main/java/ru/practicum/ewm/request/dto/ParticipationRequestDto.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
@AllArgsConstructor
1414
public class ParticipationRequestDto {
1515
private Long id;
16-
1716
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
1817
private LocalDateTime created;
1918
private Long event;

0 commit comments

Comments
 (0)