add-bookings#3
Conversation
Попытка пофиксить Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.2.5:test
Попытка пофиксить Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.2.5:test
Попытка 3 пофиксить Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.2.5:test
Попытка 4 пофиксить Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.2.5:test
Попытка 5 пофиксить Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.2.5:test
Попытка 6 пофиксить Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.2.5:test
Попытка 7 пофиксить Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.2.5:test
| Long id; | ||
|
|
||
| @NotNull(groups = Marker.OnCreate.class, message = "Дата начала бронирования - обязательна") | ||
| @FutureOrPresentWithTolerance( |
There was a problem hiding this comment.
а для чего нужно было изобретать свой велосипед, когда уже есть @FutureOrPresent
There was a problem hiding this comment.
С дефолтным ложные срабатывания из-за микросекунд
| @Override | ||
| public BookingDto approveBooking(long userId, long bookingId, boolean approved) { | ||
| checkUser(userId); | ||
| Booking booking = getBooking(bookingId); |
There was a problem hiding this comment.
еще нужно проверить, что текущий статус заявки WAITING
| @NotBlank | ||
| String text; | ||
|
|
||
| public static CommentDto from(@NonNull Comment comment) { |
|
|
||
| return ItemMapper.toItemDtoWithComments( | ||
| item, | ||
| getLastBookingDate(bookings), |
There was a problem hiding this comment.
поскольку вещь по id может любой пользователь, то добавлять данные по бронированию только в случае, если запрос сделал собственник вещи
| .collect(Collectors.toMap(Item::getId, Function.identity())); | ||
| List<Booking> bookings = bookingRepository.findAllBookingByItemIdIn(items.keySet()); | ||
|
|
||
| return items.values().stream() |
There was a problem hiding this comment.
в этом методе ответ так же нужно обогащать комментариями
| booking.getEnd().isBefore(LocalDateTime.now())) | ||
| ) { | ||
| throw new ParameterNotValidException( | ||
| "userId", "Комментарии доступны только тем, кто уже по пользовался вешью" |
| ); | ||
| } | ||
| return CommentDto.from(commentRepository.save( | ||
| new Comment(null, item, user, LocalDateTime.now(), text.trim()) |
There was a problem hiding this comment.
создание Comment тоже в CommentMapper
|
|
||
| private LocalDateTime getLastBookingDate(@NonNull List<Booking> bookings) { | ||
| return bookings.stream() | ||
| .filter(booking -> Duration.between(booking.getStart(), booking.getEnd()).toMinutes() > 30) |
There was a problem hiding this comment.
на чем основано это условие про 30 минут?
There was a problem hiding this comment.
Это помогало пройти тесты
| .filter(ldt -> ldt.isBefore(LocalDateTime.now()) || | ||
| ldt.isEqual(LocalDateTime.now())) | ||
| .sorted() | ||
| .findFirst().orElse(null); |
There was a problem hiding this comment.
я не очень понимаю почему ты берешь первую запись. Под условие
.filter(ldt -> ldt.isBefore(LocalDateTime.now()) || ldt.isEqual(LocalDateTime.now()))
подпадают все бронирования до настоящего момента. Далее они сортируются и первым элементом будет самая ранняя дата. А нужно самая последняя перед моментом "сейчас"
|
|
||
| private LocalDateTime getNextBookingDate(@NonNull List<Booking> bookings) { | ||
| return bookings.stream() | ||
| .filter(booking -> Duration.between(booking.getStart(), booking.getEnd()).toMinutes() > 30) |
| rounding = TimeRoundingStrategy.TRUNCATE_TO_SECONDS, | ||
| message = "Дата начала не может быть в прошлом" | ||
| ) | ||
| // @FutureOrPresent(message = "Дата начала не может быть в прошлом") |
| getLastBookingDate(bookings), | ||
| getNextBookingDate(bookings) | ||
| getNextBookingDate(bookings), | ||
| getCommentDtos(item.getId()) |
There was a problem hiding this comment.
обогащать нужно без DDOSа на БД. Сделай по аналогии с бронированиями
| } | ||
| return CommentDto.from(commentRepository.save( | ||
| return CommentMapper.toDto(commentRepository.save( | ||
| new Comment(null, item, user, LocalDateTime.now(), text.trim()) |
There was a problem hiding this comment.
нужно также создание Comment из CommentDto перенести в CommentMapper
No description provided.