-
Notifications
You must be signed in to change notification settings - Fork 0
add-bookings. Изменить сохранение данных в БД. Добавить функционал "Бронирование" и "Комментарии" #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ронирование" и "Комментарии"
| public class BookingDtoRequest { | ||
|
|
||
| @NotNull(message = "Дата начала бронирования не может быть пустой") | ||
| private LocalDateTime start; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
добавь еще аннотацию @FutureOrPresent
| @NotNull(message = "Дата начала бронирования не может быть пустой") | ||
| private LocalDateTime start; | ||
| @NotNull(message = "Дата окончания бронирования не может быть пустой") | ||
| private LocalDateTime end; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а сюда @future
| Booking booking = getBookingWithCheck(bookingId); | ||
| checkBookingUserForGet(userId, booking.getBooker().getId(), booking.getItem().getOwner().getId()); | ||
| return BookingMapper.toBookingDtoResponse( | ||
| getBookingWithCheck(bookingId), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
зачем еще раз запрашивать бронь из БД, когда она уже записана в booking
| Booking booking = getBookingWithCheck(bookingId); | ||
| checkBookingUser(userId, booking.getItem().getOwner().getId()); | ||
| userService.getUserWithCheck(userId); | ||
| if (approved) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
еще нужно проверить, что текущий статус заявки WAITING
| ItemMapper.toItemDto(booking.getItem())); | ||
| } | ||
|
|
||
| public Booking getBookingWithCheck(Long bookingId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это должен быть внутренний метод класса
| if (start.isBefore(LocalDateTime.now())) { | ||
| throw new ValidationException("Дата начала бронирования не может быть раньше текущего времени"); | ||
| } | ||
| if (end.isBefore(LocalDateTime.now())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
аналогично
| if (start.isEqual(end)) { | ||
| throw new ValidationException("Дата начала и дата окончания бронирования не могут быть равны"); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
еще нужно проверить, что start раньше, чем end
| @AllArgsConstructor | ||
| public class CommentDto { | ||
| private Long id; | ||
| private String text; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
|
|
||
| @Override | ||
| public List<ItemDto> getItemsByUserId(Long userId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ответ метода нужно обогатить данными по бронированиям. Но не нужно в потоке/цикле обращаться в БД для каждой вещи. Нужно в BookingRepository заготовить метод, который на вход получит список вещей и вернет список подтвержденных отсортированных по дате старта броней. Пробежаться по этому списку и собрать из нее мапу Map<Item.id, List броней>. Далее перебирая вещи пользователя, данные по бронированию брать из мапы.
| User author = userService.getUserWithCheck(userId); | ||
| Item item = getItemWithCheck(itemId); | ||
| Comment comment = ItemMapper.toComment(commentDto, author, item); | ||
| comment.setItem(item); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
эти три действия уже сделал ItemMapper.toComment()
… проверку статуса у апи подтверждения брони. Обогатить ответ для апи по получению списка вещей у пользователя. Небольшие корректировки кода.
| .toList()); | ||
| return itemsByUserId.stream() | ||
| .map(ItemMapper::toItemDto) | ||
| .peek(item -> item.setBookings(bookingsByIdItem.get(item.getId()))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
нужны не все бронирования, а последнее и ближайшее следующее, т.е. использовать для ответа ItemByIdDto
…сив бронирований на последнее завершенное и первое ближайшее бронирование.
No description provided.