Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
nicknaz committed Jun 29, 2023
1 parent abecedc commit 4b47c9a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import ru.practicum.shareit.user.repository.UserRepositoryJPA;

import javax.transaction.Transactional;
import javax.validation.ValidationException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -48,7 +47,7 @@ public BookingDto create(BookingDtoRequest bookingDto, Long bookerId) {
}

if (!item.getAvailable()) {
throw new ValidationException("Предмет не доступен для бронирования!");
throw new InvalidDateException("Предмет не доступен для бронирования!");
}

if (bookingDto.getStart().isAfter(bookingDto.getEnd())
Expand All @@ -74,7 +73,7 @@ public BookingDto changeStatus(Long ownerId, Long bookingId, boolean approved) {
}

if (booking.getStatus() == BookingStatus.APPROVED) {
throw new ValidationException("Бронь уже подтверждена!");
throw new InvalidDateException("Бронь уже подтверждена!");
}

booking.setStatus(approved ? BookingStatus.APPROVED : BookingStatus.REJECTED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.validation.ValidationException;
import java.util.Map;

@RestControllerAdvice
Expand All @@ -20,13 +19,6 @@ public Map<String, String> objectNotFoundedException(final NotFoundedException e
return Map.of("exception", e.getMessage());
}

@ExceptionHandler(ValidationException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public Map<String, String> handleException(final Exception e) {
log.debug("Получен статус 400 Bad Request {}", e.getMessage(), e);
return Map.of("exception", e.getMessage());
}

@ExceptionHandler(InvalidDateException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public Map<String, String> dateException(final Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ru.practicum.shareit.booking.BookingStatus;
import ru.practicum.shareit.booking.dto.BookingDtoForItem;
import ru.practicum.shareit.booking.repository.BookingRepositoryJPA;
import ru.practicum.shareit.exception.InvalidDateException;
import ru.practicum.shareit.exception.NotFoundedException;
import ru.practicum.shareit.item.dto.CommentDto;
import ru.practicum.shareit.item.dto.ItemDto;
Expand All @@ -21,7 +22,6 @@
import ru.practicum.shareit.user.repository.UserRepositoryJPA;

import javax.transaction.Transactional;
import javax.validation.ValidationException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -163,7 +163,7 @@ public Comment createComment(Long userId, Long itemId, CommentDto commentDto) {
itemId, BookingStatus.REJECTED, LocalDateTime.now(), PageRequest.of(0, 10));

if (bookingList.size() == 0) {
throw new ValidationException("Вы не можете оставлять комментарии под этим предметом," +
throw new InvalidDateException("Вы не можете оставлять комментарии под этим предметом," +
" так как не бронировали ее");
}

Expand Down

0 comments on commit 4b47c9a

Please sign in to comment.