Skip to content

add-bookings#3

Merged
AleksOBM merged 12 commits into
mainfrom
add-bookings
Mar 29, 2026
Merged

add-bookings#3
AleksOBM merged 12 commits into
mainfrom
add-bookings

Conversation

@AleksOBM

Copy link
Copy Markdown
Owner

No description provided.

AleksOBM added 10 commits March 22, 2026 23:33
Попытка пофиксить 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(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

а для чего нужно было изобретать свой велосипед, когда уже есть @FutureOrPresent

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

С дефолтным ложные срабатывания из-за микросекунд

@Override
public BookingDto approveBooking(long userId, long bookingId, boolean approved) {
checkUser(userId);
Booking booking = getBooking(bookingId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

еще нужно проверить, что текущий статус заявки WAITING

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Готово

@NotBlank
String text;

public static CommentDto from(@NonNull Comment comment) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

давай этот метод в CommentMapper

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Готово


return ItemMapper.toItemDtoWithComments(
item,
getLastBookingDate(bookings),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

поскольку вещь по id может любой пользователь, то добавлять данные по бронированию только в случае, если запрос сделал собственник вещи

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Готово

.collect(Collectors.toMap(Item::getId, Function.identity()));
List<Booking> bookings = bookingRepository.findAllBookingByItemIdIn(items.keySet());

return items.values().stream()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

в этом методе ответ так же нужно обогащать комментариями

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Готово

booking.getEnd().isBefore(LocalDateTime.now()))
) {
throw new ParameterNotValidException(
"userId", "Комментарии доступны только тем, кто уже по пользовался вешью"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

опечатка в слове "вещью"

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Готово

);
}
return CommentDto.from(commentRepository.save(
new Comment(null, item, user, LocalDateTime.now(), text.trim())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

создание Comment тоже в CommentMapper

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Готово


private LocalDateTime getLastBookingDate(@NonNull List<Booking> bookings) {
return bookings.stream()
.filter(booking -> Duration.between(booking.getStart(), booking.getEnd()).toMinutes() > 30)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

на чем основано это условие про 30 минут?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Это помогало пройти тесты

.filter(ldt -> ldt.isBefore(LocalDateTime.now()) ||
ldt.isEqual(LocalDateTime.now()))
.sorted()
.findFirst().orElse(null);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

я не очень понимаю почему ты берешь первую запись. Под условие
.filter(ldt -> ldt.isBefore(LocalDateTime.now()) || ldt.isEqual(LocalDateTime.now()))
подпадают все бронирования до настоящего момента. Далее они сортируются и первым элементом будет самая ранняя дата. А нужно самая последняя перед моментом "сейчас"

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Готово


private LocalDateTime getNextBookingDate(@NonNull List<Booking> bookings) {
return bookings.stream()
.filter(booking -> Duration.between(booking.getStart(), booking.getEnd()).toMinutes() > 30)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

здесь тот же вопрос

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

убрал

rounding = TimeRoundingStrategy.TRUNCATE_TO_SECONDS,
message = "Дата начала не может быть в прошлом"
)
// @FutureOrPresent(message = "Дата начала не может быть в прошлом")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

убери закомментированный код

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Готово

getLastBookingDate(bookings),
getNextBookingDate(bookings)
getNextBookingDate(bookings),
getCommentDtos(item.getId())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

обогащать нужно без DDOSа на БД. Сделай по аналогии с бронированиями

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Готово

}
return CommentDto.from(commentRepository.save(
return CommentMapper.toDto(commentRepository.save(
new Comment(null, item, user, LocalDateTime.now(), text.trim())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

нужно также создание Comment из CommentDto перенести в CommentMapper

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Готово

@AleksOBM AleksOBM merged commit 1b868e0 into main Mar 29, 2026
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.

2 participants