Skip to content

Conversation

@walder86
Copy link
Owner

No description provided.

public class BookingDtoRequest {

@NotNull(message = "Дата начала бронирования не может быть пустой")
private LocalDateTime start;

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;

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),

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) {

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) {

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())) {

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("Дата начала и дата окончания бронирования не могут быть равны");
}
}

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

добавь аннотацию @notblank и в контроллере на поле в методе @Valid



@Override
public List<ItemDto> getItemsByUserId(Long userId) {

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);

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())))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужны не все бронирования, а последнее и ближайшее следующее, т.е. использовать для ответа ItemByIdDto

…сив бронирований на последнее завершенное и первое ближайшее бронирование.
@walder86 walder86 merged commit dc386cf into main Aug 23, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants