From c0ecf6db8a6b44f9447f589a934c6b9eb54fb9af Mon Sep 17 00:00:00 2001 From: kpetrosyan1 Date: Sat, 6 Apr 2024 20:14:39 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=A2=D0=97=2016?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 36 ++++++ gateway/.gitignore | 38 ++++++ gateway/Dockerfile | 3 + gateway/pom.xml | 65 ++++++++++ .../java/ru/practicum/shareit/Constant.java | 0 .../ru/practicum/shareit/ShareItGateway.java | 12 ++ .../shareit/booking/BookingClient.java | 60 +++++++++ .../shareit/booking/BookingController.java | 70 ++++++++++ .../booking/dto/BookItemRequestDto.java | 24 ++++ .../shareit/booking/dto/BookingState.java | 27 ++++ .../practicum/shareit/client/BaseClient.java | 121 ++++++++++++++++++ .../shareit/exception/ErrorHandler.java | 26 ++++ .../shareit/exception/ErrorResponse.java | 12 ++ .../ru/practicum/shareit/item/ItemClient.java | 66 ++++++++++ .../shareit/item/ItemController.java | 79 ++++++++++++ .../shareit/item/dto/CommentRequestDto.java | 17 +++ .../shareit/item/dto/ItemRequestDto.java | 21 +++ .../shareit/request/ItemRequestClient.java | 48 +++++++ .../request/ItemRequestController.java | 52 ++++++++ .../request/dto/ItemRequestRequestDto.java | 8 +- .../ru/practicum/shareit/user/UserClient.java | 47 +++++++ .../shareit/user/UserController.java | 53 ++++++++ .../shareit/user/dto/UserCreationDto.java | 8 +- .../shareit/user/dto/UserRequestDto.java | 10 +- .../src/main/resources/application.properties | 7 + pom.xml | 102 ++++----------- server/.gitignore | 38 ++++++ server/Dockerfile | 3 + server/pom.xml | 86 +++++++++++++ .../java/ru/practicum/shareit/Constant.java | 5 + .../ru/practicum/shareit/ShareItServer.java | 4 +- .../booking/controller/BookingController.java | 15 +-- .../dto/BookingDtoWithItemAndUser.java | 0 .../shareit/booking/dto/BookingMapper.java | 0 .../booking/dto/BookingRequestDto.java | 8 -- .../booking/dto/BookingResponseDto.java | 0 .../shareit/booking/model/Booking.java | 0 .../shareit/booking/model/BookingStatus.java | 0 .../shareit/booking/model/State.java | 2 +- .../booking/repository/BookingStorage.java | 0 .../booking/service/BookingService.java | 0 .../service/impl/BookingServiceImpl.java | 4 +- .../exception/controller/ErrorHandler.java | 15 ++- .../exceptions/BadRequestException.java | 0 .../exceptions/NotEnoughRightsException.java | 0 .../exceptions/NotFoundException.java | 0 .../exception/model/ErrorResponse.java | 0 .../shareit/item/comment/Comment.java | 0 .../shareit/item/comment/CommentMapper.java | 0 .../item/comment/CommentRequestDto.java | 5 - .../item/comment/CommentResponseDto.java | 0 .../shareit/item/comment/CommentStorage.java | 0 .../item/controller/ItemController.java | 17 +-- .../shareit/item/dto/ItemMapper.java | 0 .../shareit/item/dto/ItemRequestDto.java | 6 - .../shareit/item/dto/ItemResponseDto.java | 0 .../item/dto/ItemResponseDtoWithBookings.java | 0 .../ru/practicum/shareit/item/model/Item.java | 0 .../shareit/item/repository/ItemStorage.java | 0 .../shareit/item/service/ItemService.java | 0 .../item/service/impl/ItemServiceImpl.java | 0 .../controller/ItemRequestController.java | 12 +- .../request/dto/ItemRequestMapper.java | 0 .../request/dto/ItemRequestRequestDto.java | 8 ++ .../request/dto/ItemRequestResponseDto.java | 0 .../shareit/request/model/ItemRequest.java | 0 .../repository/ItemRequestStorage.java | 0 .../request/service/ItemRequestService.java | 0 .../service/impl/ItemRequestServiceImpl.java | 0 .../user/controller/UserController.java | 13 +- .../shareit/user/dto/UserMapper.java | 7 - .../shareit/user/dto/UserRequestDto.java | 9 ++ .../shareit/user/dto/UserResponseDto.java | 0 .../ru/practicum/shareit/user/model/User.java | 0 .../shareit/user/repository/UserStorage.java | 0 .../shareit/user/service/UserService.java | 3 +- .../user/service/impl/UserServiceImpl.java | 5 +- .../src/main/resources/application.properties | 18 +++ {src => server/src}/main/resources/schema.sql | 0 .../ru/practicum/shareit/ShareItTests.java | 0 .../booking/BookingControllerTest.java | 48 ------- .../shareit/booking/BookingServiceTest.java | 0 .../shareit/booking/BookingStorageTest.java | 0 .../shareit/item/ItemControllerTest.java | 48 ------- .../shareit/item/ItemIntegrationTest.java | 0 .../shareit/item/ItemServiceTest.java | 0 .../shareit/item/ItemStorageTest.java | 0 .../request/ItemRequestControllerTest.java | 14 -- .../request/ItemRequestIntegrationTest.java | 0 .../request/ItemRequestServiceTest.java | 0 .../request/ItemRequestStorageTest.java | 0 .../shareit/user/UserControllerTest.java | 36 +----- .../shareit/user/UserIntegrateTest.java | 36 ++++-- .../shareit/user/UserServiceTest.java | 5 +- src/main/resources/application.properties | 20 --- 95 files changed, 1158 insertions(+), 344 deletions(-) create mode 100644 docker-compose.yml create mode 100644 gateway/.gitignore create mode 100644 gateway/Dockerfile create mode 100644 gateway/pom.xml rename {src => gateway/src}/main/java/ru/practicum/shareit/Constant.java (100%) create mode 100644 gateway/src/main/java/ru/practicum/shareit/ShareItGateway.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/booking/BookingClient.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/booking/BookingController.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/booking/dto/BookItemRequestDto.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/booking/dto/BookingState.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/client/BaseClient.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/exception/ErrorHandler.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/exception/ErrorResponse.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/item/ItemClient.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/item/ItemController.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/item/dto/CommentRequestDto.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/request/ItemRequestClient.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/request/ItemRequestController.java rename {src => gateway/src}/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java (76%) create mode 100644 gateway/src/main/java/ru/practicum/shareit/user/UserClient.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/user/UserController.java rename {src => gateway/src}/main/java/ru/practicum/shareit/user/dto/UserCreationDto.java (77%) rename {src => gateway/src}/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java (64%) create mode 100644 gateway/src/main/resources/application.properties create mode 100644 server/.gitignore create mode 100644 server/Dockerfile create mode 100644 server/pom.xml create mode 100644 server/src/main/java/ru/practicum/shareit/Constant.java rename src/main/java/ru/practicum/shareit/ShareItApp.java => server/src/main/java/ru/practicum/shareit/ShareItServer.java (72%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/controller/BookingController.java (85%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/dto/BookingDtoWithItemAndUser.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/dto/BookingMapper.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/dto/BookingRequestDto.java (53%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/dto/BookingResponseDto.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/model/Booking.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/model/BookingStatus.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/model/State.java (90%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/repository/BookingStorage.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/service/BookingService.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/service/impl/BookingServiceImpl.java (98%) rename {src => server/src}/main/java/ru/practicum/shareit/exception/controller/ErrorHandler.java (80%) rename {src => server/src}/main/java/ru/practicum/shareit/exception/exceptions/BadRequestException.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/exception/exceptions/NotEnoughRightsException.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/exception/exceptions/NotFoundException.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/exception/model/ErrorResponse.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/comment/Comment.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/comment/CommentMapper.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/comment/CommentRequestDto.java (51%) rename {src => server/src}/main/java/ru/practicum/shareit/item/comment/CommentResponseDto.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/comment/CommentStorage.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/controller/ItemController.java (86%) rename {src => server/src}/main/java/ru/practicum/shareit/item/dto/ItemMapper.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java (61%) rename {src => server/src}/main/java/ru/practicum/shareit/item/dto/ItemResponseDto.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/dto/ItemResponseDtoWithBookings.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/model/Item.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/repository/ItemStorage.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/service/ItemService.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/service/impl/ItemServiceImpl.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java (84%) rename {src => server/src}/main/java/ru/practicum/shareit/request/dto/ItemRequestMapper.java (100%) create mode 100644 server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java rename {src => server/src}/main/java/ru/practicum/shareit/request/dto/ItemRequestResponseDto.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/request/model/ItemRequest.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/request/repository/ItemRequestStorage.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/request/service/ItemRequestService.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/request/service/impl/ItemRequestServiceImpl.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/user/controller/UserController.java (76%) rename {src => server/src}/main/java/ru/practicum/shareit/user/dto/UserMapper.java (74%) create mode 100644 server/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java rename {src => server/src}/main/java/ru/practicum/shareit/user/dto/UserResponseDto.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/user/model/User.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/user/repository/UserStorage.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/user/service/UserService.java (77%) rename {src => server/src}/main/java/ru/practicum/shareit/user/service/impl/UserServiceImpl.java (94%) create mode 100644 server/src/main/resources/application.properties rename {src => server/src}/main/resources/schema.sql (100%) rename {src => server/src}/test/java/ru/practicum/shareit/ShareItTests.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/booking/BookingControllerTest.java (72%) rename {src => server/src}/test/java/ru/practicum/shareit/booking/BookingServiceTest.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/booking/BookingStorageTest.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/item/ItemControllerTest.java (78%) rename {src => server/src}/test/java/ru/practicum/shareit/item/ItemIntegrationTest.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/item/ItemServiceTest.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/item/ItemStorageTest.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/request/ItemRequestControllerTest.java (87%) rename {src => server/src}/test/java/ru/practicum/shareit/request/ItemRequestIntegrationTest.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/request/ItemRequestServiceTest.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/request/ItemRequestStorageTest.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/user/UserControllerTest.java (76%) rename {src => server/src}/test/java/ru/practicum/shareit/user/UserIntegrateTest.java (70%) rename {src => server/src}/test/java/ru/practicum/shareit/user/UserServiceTest.java (96%) delete mode 100644 src/main/resources/application.properties diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3f13126 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,36 @@ +version: '3.8' +services: + gateway: + build: gateway + image: gateway-image + container_name: gateway-container + ports: + - "8080:8080" + depends_on: + - server + environment: + - SHAREIT_SERVER_URL=http://server:9090 + + server: + build: server + image: server-image + container_name: server-container + ports: + - "9090:9090" + depends_on: + - db + environment: + - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/shareIt + - SPRING_DATASOURCE_USERNAME=root + - SPRING_DATASOURCE_PASSWORD=root + - SPRING_DRIVER_CLASS_NAME=org.postgresql.Driver + + db: + image: postgres:14-alpine + container_name: db-container + ports: + - "6541:5432" + environment: + - POSTGRES_PASSWORD=root + - POSTGRES_USER=root + - POSTGRES_DB=shareIt \ No newline at end of file diff --git a/gateway/.gitignore b/gateway/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/gateway/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/gateway/Dockerfile b/gateway/Dockerfile new file mode 100644 index 0000000..2118327 --- /dev/null +++ b/gateway/Dockerfile @@ -0,0 +1,3 @@ +FROM amazoncorretto:11-alpine-jdk +COPY target/*.jar app.jar +ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file diff --git a/gateway/pom.xml b/gateway/pom.xml new file mode 100644 index 0000000..ce8b4aa --- /dev/null +++ b/gateway/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + ru.practicum + shareit + 0.0.1-SNAPSHOT + + + shareit-gateway + 0.0.1-SNAPSHOT + + ShareIt Gateway + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-validation + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.apache.httpcomponents + httpclient + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + org.projectlombok + lombok + true + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/src/main/java/ru/practicum/shareit/Constant.java b/gateway/src/main/java/ru/practicum/shareit/Constant.java similarity index 100% rename from src/main/java/ru/practicum/shareit/Constant.java rename to gateway/src/main/java/ru/practicum/shareit/Constant.java diff --git a/gateway/src/main/java/ru/practicum/shareit/ShareItGateway.java b/gateway/src/main/java/ru/practicum/shareit/ShareItGateway.java new file mode 100644 index 0000000..0aa75c3 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/ShareItGateway.java @@ -0,0 +1,12 @@ +package ru.practicum.shareit; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ShareItGateway { + public static void main(String[] args) { + SpringApplication.run(ShareItGateway.class, args); + } + +} diff --git a/gateway/src/main/java/ru/practicum/shareit/booking/BookingClient.java b/gateway/src/main/java/ru/practicum/shareit/booking/BookingClient.java new file mode 100644 index 0000000..ec87dab --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/booking/BookingClient.java @@ -0,0 +1,60 @@ +package ru.practicum.shareit.booking; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.stereotype.Service; +import org.springframework.web.util.DefaultUriBuilderFactory; +import ru.practicum.shareit.booking.dto.BookItemRequestDto; +import ru.practicum.shareit.booking.dto.BookingState; +import ru.practicum.shareit.client.BaseClient; + +import java.util.Map; + +@Service +public class BookingClient extends BaseClient { + private static final String API_PREFIX = "/bookings"; + + @Autowired + public BookingClient(@Value("${shareit-server.url}") String serverUrl, RestTemplateBuilder builder) { + super( + builder + .uriTemplateHandler(new DefaultUriBuilderFactory(serverUrl + API_PREFIX)) + .requestFactory(HttpComponentsClientHttpRequestFactory::new) + .build() + ); + } + + public ResponseEntity getBookings(long userId, BookingState state, Integer from, Integer size) { + Map parameters = Map.of( + "state", state.name(), + "from", from, + "size", size + ); + return get("?state={state}&from={from}&size={size}", userId, parameters); + } + + + public ResponseEntity bookItem(long userId, BookItemRequestDto requestDto) { + return post("", userId, requestDto); + } + + public ResponseEntity getBooking(long userId, Long bookingId) { + return get("/" + bookingId, userId); + } + + public ResponseEntity updateBooking(long userId, Long bookingId, Boolean approved) { + return patch("/" + bookingId + "?approved=" + approved, userId); + } + + public ResponseEntity getOwnerBookings(long userId, BookingState state, Integer from, Integer size) { + Map parameters = Map.of( + "state", state.name(), + "from", from, + "size", size + ); + return get("/owner?state={state}&from={from}&size={size}", userId, parameters); + } +} diff --git a/gateway/src/main/java/ru/practicum/shareit/booking/BookingController.java b/gateway/src/main/java/ru/practicum/shareit/booking/BookingController.java new file mode 100644 index 0000000..cf28497 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/booking/BookingController.java @@ -0,0 +1,70 @@ +package ru.practicum.shareit.booking; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import ru.practicum.shareit.booking.dto.BookItemRequestDto; +import ru.practicum.shareit.booking.dto.BookingState; + +import javax.validation.Valid; +import javax.validation.constraints.Positive; +import javax.validation.constraints.PositiveOrZero; + +import static ru.practicum.shareit.Constant.USER_HEADER; + +@Controller +@RequestMapping(path = "/bookings") +@RequiredArgsConstructor +@Slf4j +@Validated +public class BookingController { + private final BookingClient bookingClient; + + @GetMapping + public ResponseEntity getBookings(@RequestHeader(USER_HEADER) long userId, + @RequestParam(name = "state", defaultValue = "all") String stateParam, + @PositiveOrZero @RequestParam (name = "from", defaultValue = "0") Integer from, + @Positive @RequestParam (name = "size", defaultValue = "10") Integer size) { + BookingState state = BookingState.from(stateParam) + .orElseThrow(() -> new IllegalArgumentException("Unknown state: " + stateParam)); + log.info("BOOKING_GATEWAY: Get booking with state {}, userId={}, from={}, size={}", stateParam, userId, from, size); + return bookingClient.getBookings(userId, state, from, size); + } + + @PostMapping + public ResponseEntity bookItem(@RequestHeader(USER_HEADER) long userId, + @RequestBody @Valid BookItemRequestDto requestDto) { + log.info("BOOKING_GATEWAY: Creating booking {}, userId={}", requestDto, userId); + return bookingClient.bookItem(userId, requestDto); + } + + @GetMapping("/{bookingId}") + public ResponseEntity getBooking(@RequestHeader(USER_HEADER) long userId, + @PathVariable Long bookingId) { + log.info("BOOKING_GATEWAY: Get booking {}, userId={}", bookingId, userId); + return bookingClient.getBooking(userId, bookingId); + } + + @PatchMapping("/{bookingId}") + public ResponseEntity updateBooking(@RequestHeader(USER_HEADER) @Positive long userId, + @PathVariable @Positive Long bookingId, + @RequestParam Boolean approved) { + log.info("BOOKING_GATEWAY: Update booking {}, userId={}", bookingId, userId); + return bookingClient.updateBooking(userId, bookingId, approved); + } + + @GetMapping("/owner") + public ResponseEntity getOwnerBookings(@RequestHeader(USER_HEADER) long userId, + @RequestParam(name = "state", defaultValue = "all") String stateParam, + @PositiveOrZero @RequestParam(name = "from", defaultValue = "0") Integer from, + @Positive @RequestParam(name = "size", defaultValue = "10") Integer size) { + log.info("BOOKING_GATEWAY: Get booking with state {}, ownerId={}, from={}, size={}", stateParam, userId, from, size); + BookingState state = BookingState.from(stateParam) + .orElseThrow(() -> new IllegalArgumentException("Unknown state: " + stateParam)); + return bookingClient.getOwnerBookings(userId, state, from, size); + } +} \ No newline at end of file diff --git a/gateway/src/main/java/ru/practicum/shareit/booking/dto/BookItemRequestDto.java b/gateway/src/main/java/ru/practicum/shareit/booking/dto/BookItemRequestDto.java new file mode 100644 index 0000000..3b09d62 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/booking/dto/BookItemRequestDto.java @@ -0,0 +1,24 @@ +package ru.practicum.shareit.booking.dto; + +import java.time.LocalDateTime; + +import javax.validation.constraints.Future; +import javax.validation.constraints.FutureOrPresent; +import javax.validation.constraints.NotNull; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class BookItemRequestDto { + private long itemId; + @NotNull(message = "Дата начала брони не может быть null") + @FutureOrPresent(message = "Дата начала брони не может быть в прошлом") + private LocalDateTime start; + @NotNull(message = "Дата завершения брони не может быть null") + @Future(message = "Дата завершения брони должна быть в будущем") + private LocalDateTime end; +} diff --git a/gateway/src/main/java/ru/practicum/shareit/booking/dto/BookingState.java b/gateway/src/main/java/ru/practicum/shareit/booking/dto/BookingState.java new file mode 100644 index 0000000..7bfa164 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/booking/dto/BookingState.java @@ -0,0 +1,27 @@ +package ru.practicum.shareit.booking.dto; + +import java.util.Optional; + +public enum BookingState { + // Все + ALL, + // Текущие + CURRENT, + // Будущие + FUTURE, + // Завершенные + PAST, + // Отклоненные + REJECTED, + // Ожидающие подтверждения + WAITING; + + public static Optional from(String stringState) { + for (BookingState state : values()) { + if (state.name().equalsIgnoreCase(stringState)) { + return Optional.of(state); + } + } + return Optional.empty(); + } +} diff --git a/gateway/src/main/java/ru/practicum/shareit/client/BaseClient.java b/gateway/src/main/java/ru/practicum/shareit/client/BaseClient.java new file mode 100644 index 0000000..1a2d33a --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/client/BaseClient.java @@ -0,0 +1,121 @@ +package ru.practicum.shareit.client; + +import java.util.List; +import java.util.Map; + +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.lang.Nullable; +import org.springframework.web.client.HttpStatusCodeException; +import org.springframework.web.client.RestTemplate; + +public class BaseClient { + protected final RestTemplate rest; + + public BaseClient(RestTemplate rest) { + this.rest = rest; + } + + protected ResponseEntity get(String path) { + return get(path, null, null); + } + + protected ResponseEntity get(String path, long userId) { + return get(path, userId, null); + } + + protected ResponseEntity get(String path, Long userId, @Nullable Map parameters) { + return makeAndSendRequest(HttpMethod.GET, path, userId, parameters, null); + } + + protected ResponseEntity post(String path, T body) { + return post(path, null, null, body); + } + + protected ResponseEntity post(String path, long userId, T body) { + return post(path, userId, null, body); + } + + protected ResponseEntity post(String path, Long userId, @Nullable Map parameters, T body) { + return makeAndSendRequest(HttpMethod.POST, path, userId, parameters, body); + } + + protected ResponseEntity put(String path, long userId, T body) { + return put(path, userId, null, body); + } + + protected ResponseEntity put(String path, long userId, @Nullable Map parameters, T body) { + return makeAndSendRequest(HttpMethod.PUT, path, userId, parameters, body); + } + + protected ResponseEntity patch(String path, T body) { + return patch(path, null, null, body); + } + + protected ResponseEntity patch(String path, long userId) { + return patch(path, userId, null, null); + } + + protected ResponseEntity patch(String path, long userId, T body) { + return patch(path, userId, null, body); + } + + protected ResponseEntity patch(String path, Long userId, @Nullable Map parameters, T body) { + return makeAndSendRequest(HttpMethod.PATCH, path, userId, parameters, body); + } + + protected ResponseEntity delete(String path) { + return delete(path, null, null); + } + + protected ResponseEntity delete(String path, long userId) { + return delete(path, userId, null); + } + + protected ResponseEntity delete(String path, Long userId, @Nullable Map parameters) { + return makeAndSendRequest(HttpMethod.DELETE, path, userId, parameters, null); + } + + private ResponseEntity makeAndSendRequest(HttpMethod method, String path, Long userId, @Nullable Map parameters, @Nullable T body) { + HttpEntity requestEntity = new HttpEntity<>(body, defaultHeaders(userId)); + + ResponseEntity shareitServerResponse; + try { + if (parameters != null) { + shareitServerResponse = rest.exchange(path, method, requestEntity, Object.class, parameters); + } else { + shareitServerResponse = rest.exchange(path, method, requestEntity, Object.class); + } + } catch (HttpStatusCodeException e) { + return ResponseEntity.status(e.getStatusCode()).body(e.getResponseBodyAsByteArray()); + } + return prepareGatewayResponse(shareitServerResponse); + } + + private HttpHeaders defaultHeaders(Long userId) { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.setAccept(List.of(MediaType.APPLICATION_JSON)); + if (userId != null) { + headers.set("X-Sharer-User-Id", String.valueOf(userId)); + } + return headers; + } + + private static ResponseEntity prepareGatewayResponse(ResponseEntity response) { + if (response.getStatusCode().is2xxSuccessful()) { + return response; + } + + ResponseEntity.BodyBuilder responseBuilder = ResponseEntity.status(response.getStatusCode()); + + if (response.hasBody()) { + return responseBuilder.body(response.getBody()); + } + + return responseBuilder.build(); + } +} diff --git a/gateway/src/main/java/ru/practicum/shareit/exception/ErrorHandler.java b/gateway/src/main/java/ru/practicum/shareit/exception/ErrorHandler.java new file mode 100644 index 0000000..9f48762 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/exception/ErrorHandler.java @@ -0,0 +1,26 @@ +package ru.practicum.shareit.exception; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +@Slf4j +public class ErrorHandler { + @ExceptionHandler + @ResponseStatus(HttpStatus.BAD_REQUEST) + public ErrorResponse handleMethodArgumentNotValidException(final MethodArgumentNotValidException e) { + e.printStackTrace(); + return new ErrorResponse(e.getMessage()); + } + + @ExceptionHandler + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + public ErrorResponse handleException(final Exception e) { + e.printStackTrace(); + return new ErrorResponse(e.getMessage()); + } +} diff --git a/gateway/src/main/java/ru/practicum/shareit/exception/ErrorResponse.java b/gateway/src/main/java/ru/practicum/shareit/exception/ErrorResponse.java new file mode 100644 index 0000000..34057b2 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/exception/ErrorResponse.java @@ -0,0 +1,12 @@ +package ru.practicum.shareit.exception; + +import lombok.Getter; + +@Getter +public class ErrorResponse { + private final String error; + + public ErrorResponse(String error) { + this.error = error; + } +} diff --git a/gateway/src/main/java/ru/practicum/shareit/item/ItemClient.java b/gateway/src/main/java/ru/practicum/shareit/item/ItemClient.java new file mode 100644 index 0000000..a816fc2 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/item/ItemClient.java @@ -0,0 +1,66 @@ +package ru.practicum.shareit.item; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.stereotype.Service; +import org.springframework.web.util.DefaultUriBuilderFactory; +import ru.practicum.shareit.client.BaseClient; +import ru.practicum.shareit.item.dto.CommentRequestDto; +import ru.practicum.shareit.item.dto.ItemRequestDto; + +import java.util.Map; + +@Service +public class ItemClient extends BaseClient { + private static final String API_PREFIX = "/items"; + + @Autowired + public ItemClient(@Value("${shareit-server.url}") String serverUrl, RestTemplateBuilder builder) { + super( + builder + .uriTemplateHandler(new DefaultUriBuilderFactory(serverUrl + API_PREFIX)) + .requestFactory(HttpComponentsClientHttpRequestFactory::new) + .build() + ); + } + + public ResponseEntity addItem(long userId, ItemRequestDto itemRequestDto) { + return post("", userId, itemRequestDto); + } + + public ResponseEntity commentItem(long userId, Long itemId, CommentRequestDto commentRequestDto) { + return post(String.format("/%d/comment", itemId), userId, commentRequestDto); + } + + public ResponseEntity updateItem(long userId, Long itemId, ItemRequestDto itemRequestDto) { + return patch(String.format("/%d", itemId), userId, itemRequestDto); + } + + public ResponseEntity getItem(long userId, Long itemId) { + return get(String.format("/%d", itemId), userId); + } + + public ResponseEntity getOwnerItems(long userId, int from, int size) { + Map parameters = Map.of( + "from", from, + "size", size + ); + return get("?from={from}&size={size}", userId, parameters); + } + + public ResponseEntity search(long userId, String text, int from, int size) { + Map parameters = Map.of( + "text", text, + "from", from, + "size", size + ); + return get("/search?text={text}&from={from}&size={size}", userId, parameters); + } + + public ResponseEntity deleteItem(long userId, Long itemId) { + return delete(String.format("/%d", itemId), userId); + } +} diff --git a/gateway/src/main/java/ru/practicum/shareit/item/ItemController.java b/gateway/src/main/java/ru/practicum/shareit/item/ItemController.java new file mode 100644 index 0000000..0058839 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/item/ItemController.java @@ -0,0 +1,79 @@ +package ru.practicum.shareit.item; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import ru.practicum.shareit.item.dto.CommentRequestDto; +import ru.practicum.shareit.item.dto.ItemRequestDto; + +import javax.validation.Valid; +import javax.validation.constraints.Positive; +import javax.validation.constraints.PositiveOrZero; + +import static ru.practicum.shareit.Constant.USER_HEADER; + +@Controller +@RequestMapping(path = "/items") +@RequiredArgsConstructor +@Slf4j +@Validated +public class ItemController { + private final ItemClient itemClient; + + @PostMapping + public ResponseEntity addItem(@RequestHeader(USER_HEADER) @Positive long userId, + @RequestBody @Valid ItemRequestDto itemRequestDto) { + log.info("ITEM_GATEWAY: add item {} from user userId={}", itemRequestDto, userId); + return itemClient.addItem(userId, itemRequestDto); + } + + @PostMapping("/{itemId}/comment") + public ResponseEntity commentItem(@RequestHeader(USER_HEADER) @Positive long userId, + @PathVariable @Positive Long itemId, + @RequestBody @Valid CommentRequestDto commentRequestDto) { + log.info("ITEM_GATEWAY: add comment {} to item itemId={} from user userId={}", commentRequestDto, itemId, userId); + return itemClient.commentItem(userId, itemId, commentRequestDto); + } + + @PatchMapping("/{itemId}") + public ResponseEntity updateItem(@RequestHeader(USER_HEADER) @Positive long userId, + @PathVariable @Positive Long itemId, + @RequestBody ItemRequestDto itemRequestDto) { + log.info("ITEM_GATEWAY: update item itemId={} from user userId={} by dto {}", itemId, userId, itemRequestDto); + return itemClient.updateItem(userId, itemId, itemRequestDto); + } + + @GetMapping("/{itemId}") + public ResponseEntity getItem(@RequestHeader(USER_HEADER) @Positive long userId, + @PathVariable @Positive Long itemId) { + log.info("ITEM_GATEWAY: get item itemId={} request from user userId={}", itemId, userId); + return itemClient.getItem(userId, itemId); + } + + @GetMapping + public ResponseEntity getOwnerItems(@RequestHeader(USER_HEADER) @Positive long userId, + @RequestParam(defaultValue = "0") @PositiveOrZero int from, + @RequestParam(defaultValue = "10") @PositiveOrZero int size) { + log.info("ITEM_GATEWAY: find owner ownerId={} items, page from={} size={}", userId, from, size); + return itemClient.getOwnerItems(userId, from, size); + } + + @GetMapping("/search") + public ResponseEntity search(@RequestHeader(USER_HEADER) @Positive long userId, + @RequestParam String text, + @RequestParam(defaultValue = "0") @PositiveOrZero int from, + @RequestParam(defaultValue = "10") @PositiveOrZero int size) { + log.info("ITEM_GATEWAY: search items by string {}, page from={} size={}", text, from, size); + return itemClient.search(userId, text, from, size); + } + + @DeleteMapping("/{itemId}") + public ResponseEntity deleteItem(@RequestHeader(USER_HEADER) @Positive long userId, + @PathVariable @Positive Long itemId) { + log.info("ITEM_GATEWAY: delete item itemId={} request from user userId={}", itemId, userId); + return itemClient.deleteItem(userId, itemId); + } +} \ No newline at end of file diff --git a/gateway/src/main/java/ru/practicum/shareit/item/dto/CommentRequestDto.java b/gateway/src/main/java/ru/practicum/shareit/item/dto/CommentRequestDto.java new file mode 100644 index 0000000..f2b64a2 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/item/dto/CommentRequestDto.java @@ -0,0 +1,17 @@ +package ru.practicum.shareit.item.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class CommentRequestDto { + @NotBlank(message = "текст комментария не может быть пустым") + @Size(max = 512, message = "размер комментария не может превышать 512 символов") + private String text; +} diff --git a/gateway/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java b/gateway/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java new file mode 100644 index 0000000..167afe2 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java @@ -0,0 +1,21 @@ +package ru.practicum.shareit.item.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class ItemRequestDto { + @NotBlank(message = "Название вещи не может быть пустым") + private String name; + @NotBlank(message = "Описание вещи не может быть пустым") + private String description; + @NotNull(message = "Необходимо указать доступность вещи для аренды") + private Boolean available; + private Long requestId; +} diff --git a/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestClient.java b/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestClient.java new file mode 100644 index 0000000..5e4ad03 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestClient.java @@ -0,0 +1,48 @@ +package ru.practicum.shareit.request; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.stereotype.Service; +import org.springframework.web.util.DefaultUriBuilderFactory; +import ru.practicum.shareit.client.BaseClient; +import ru.practicum.shareit.request.dto.ItemRequestRequestDto; + +import java.util.Map; + +@Service +public class ItemRequestClient extends BaseClient { + private static final String API_PREFIX = "/requests"; + + @Autowired + public ItemRequestClient(@Value("${shareit-server.url}") String serverUrl, RestTemplateBuilder builder) { + super( + builder + .uriTemplateHandler(new DefaultUriBuilderFactory(serverUrl + API_PREFIX)) + .requestFactory(HttpComponentsClientHttpRequestFactory::new) + .build() + ); + } + + public ResponseEntity addItemRequest(long userId, ItemRequestRequestDto itemRequestRequestDto) { + return post("", userId, itemRequestRequestDto); + } + + public ResponseEntity getRequestsByAuthor(long userId) { + return get("", userId); + } + + public ResponseEntity getItemRequests(long userId, int from, int size) { + Map parameters = Map.of( + "from", from, + "size", size + ); + return get("/all?from={from}&size={size}", userId, parameters); + } + + public ResponseEntity getItemRequest(long userId, Long requestId) { + return get(String.format("/%d", requestId), userId); + } +} \ No newline at end of file diff --git a/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestController.java b/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestController.java new file mode 100644 index 0000000..4992ca1 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestController.java @@ -0,0 +1,52 @@ +package ru.practicum.shareit.request; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import ru.practicum.shareit.request.dto.ItemRequestRequestDto; + +import javax.validation.Valid; +import javax.validation.constraints.Positive; +import javax.validation.constraints.PositiveOrZero; + +import static ru.practicum.shareit.Constant.USER_HEADER; + +@Controller +@RequestMapping(path = "/requests") +@RequiredArgsConstructor +@Slf4j +@Validated +public class ItemRequestController { + private final ItemRequestClient itemRequestClient; + + @PostMapping + public ResponseEntity addItemRequest(@RequestHeader(USER_HEADER) @Positive long userId, + @RequestBody @Valid ItemRequestRequestDto itemRequestRequestDto) { + log.info("ITEM_REQUEST_GATEWAY: add itemRequest {} from user userId={}", itemRequestRequestDto, userId); + return itemRequestClient.addItemRequest(userId, itemRequestRequestDto); + } + + @GetMapping + public ResponseEntity getRequestsByAuthor(@RequestHeader(USER_HEADER) @Positive long userId) { + log.info("ITEM_REQUEST_GATEWAY: get requests by authorId={}", userId); + return itemRequestClient.getRequestsByAuthor(userId); + } + + @GetMapping("/all") + public ResponseEntity getItemRequests(@RequestHeader(USER_HEADER) @Positive long userId, + @RequestParam(defaultValue = "0") @PositiveOrZero int from, + @RequestParam(defaultValue = "10") @Positive int size) { + log.info("ITEM_REQUEST_GATEWAY: get all requests from user userId={}, page from={}, size={}", userId, from, size); + return itemRequestClient.getItemRequests(userId, from, size); + } + + @GetMapping("/{requestId}") + public ResponseEntity getItemRequest(@RequestHeader(USER_HEADER) @Positive long userId, + @PathVariable @Positive Long requestId) { + log.info("ITEM_REQUEST_GATEWAY: get itemRequest by id={} from user userId={}", requestId, userId); + return itemRequestClient.getItemRequest(userId, requestId); + } +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java b/gateway/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java similarity index 76% rename from src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java rename to gateway/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java index 1e4a85d..84e5c25 100644 --- a/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java +++ b/gateway/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java @@ -1,11 +1,15 @@ package ru.practicum.shareit.request.dto; -import lombok.Data; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; import javax.validation.constraints.NotBlank; import javax.validation.constraints.Size; -@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor public class ItemRequestRequestDto { @NotBlank(message = "описание запроса не может быть пустым") @Size(max = 512, message = "Длина описания запроса не может превышать 512 символов") diff --git a/gateway/src/main/java/ru/practicum/shareit/user/UserClient.java b/gateway/src/main/java/ru/practicum/shareit/user/UserClient.java new file mode 100644 index 0000000..ed40677 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/user/UserClient.java @@ -0,0 +1,47 @@ +package ru.practicum.shareit.user; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.stereotype.Service; +import org.springframework.web.util.DefaultUriBuilderFactory; +import ru.practicum.shareit.client.BaseClient; +import ru.practicum.shareit.user.dto.UserCreationDto; +import ru.practicum.shareit.user.dto.UserRequestDto; + +@Service +public class UserClient extends BaseClient { + private static final String API_PREFIX = "/users"; + + @Autowired + public UserClient(@Value("${shareit-server.url}") String serverUrl, RestTemplateBuilder builder) { + super( + builder + .uriTemplateHandler(new DefaultUriBuilderFactory(serverUrl + API_PREFIX)) + .requestFactory(HttpComponentsClientHttpRequestFactory::new) + .build() + ); + } + + public ResponseEntity getUsers() { + return get(""); + } + + public ResponseEntity getUser(long userId) { + return get("/" + userId); + } + + public ResponseEntity addUser(UserCreationDto userCreationDto) { + return post("", userCreationDto); + } + + public ResponseEntity updateUser(UserRequestDto userRequestDto, long userId) { + return patch("/" + userId, userRequestDto); + } + + public ResponseEntity deleteUser(long userId) { + return delete("/" + userId); + } +} diff --git a/gateway/src/main/java/ru/practicum/shareit/user/UserController.java b/gateway/src/main/java/ru/practicum/shareit/user/UserController.java new file mode 100644 index 0000000..5075013 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/user/UserController.java @@ -0,0 +1,53 @@ +package ru.practicum.shareit.user; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import ru.practicum.shareit.user.dto.UserCreationDto; +import ru.practicum.shareit.user.dto.UserRequestDto; + +import javax.validation.Valid; +import javax.validation.constraints.Positive; + +@Controller +@RequestMapping(path = "/users") +@RequiredArgsConstructor +@Slf4j +@Validated +public class UserController { + private final UserClient userClient; + + @GetMapping + public ResponseEntity getUsers() { + log.info("USER_GATEWAY: Get all users"); + return userClient.getUsers(); + } + + @GetMapping("/{userId}") + public ResponseEntity getUser(@PathVariable @Positive long userId) { + log.info("USER_GATEWAY: Get user by userId={}", userId); + return userClient.getUser(userId); + } + + @PostMapping + public ResponseEntity addUser(@RequestBody @Valid UserCreationDto userCreationDto) { + log.info("USER_GATEWAY: Create new user {}", userCreationDto); + return userClient.addUser(userCreationDto); + } + + @PatchMapping("/{userId}") + public ResponseEntity updateUser(@RequestBody @Valid UserRequestDto userRequestDto, + @PathVariable @Positive long userId) { + log.info("USER_GATEWAY: Update user userId={} by data {}", userId, userRequestDto); + return userClient.updateUser(userRequestDto, userId); + } + + @DeleteMapping("/{userId}") + public ResponseEntity deleteUser(@PathVariable @Positive long userId) { + log.info("USER_GATEWAY: delete user userId={}", userId); + return userClient.deleteUser(userId); + } +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/user/dto/UserCreationDto.java b/gateway/src/main/java/ru/practicum/shareit/user/dto/UserCreationDto.java similarity index 77% rename from src/main/java/ru/practicum/shareit/user/dto/UserCreationDto.java rename to gateway/src/main/java/ru/practicum/shareit/user/dto/UserCreationDto.java index c48d19a..f8f9feb 100644 --- a/src/main/java/ru/practicum/shareit/user/dto/UserCreationDto.java +++ b/gateway/src/main/java/ru/practicum/shareit/user/dto/UserCreationDto.java @@ -1,11 +1,15 @@ package ru.practicum.shareit.user.dto; -import lombok.Data; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; import javax.validation.constraints.Email; import javax.validation.constraints.NotBlank; -@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor public class UserCreationDto { @NotBlank(message = "имя пользователя не может быть пустым") private String name; diff --git a/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java b/gateway/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java similarity index 64% rename from src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java rename to gateway/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java index c7dacb7..cf313f1 100644 --- a/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java +++ b/gateway/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java @@ -1,12 +1,16 @@ package ru.practicum.shareit.user.dto; -import lombok.Data; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; import javax.validation.constraints.Email; -@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor public class UserRequestDto { private String name; @Email(message = "передан некорректный формат email") private String email; -} \ No newline at end of file +} diff --git a/gateway/src/main/resources/application.properties b/gateway/src/main/resources/application.properties new file mode 100644 index 0000000..2ee0851 --- /dev/null +++ b/gateway/src/main/resources/application.properties @@ -0,0 +1,7 @@ +logging.level.org.springframework.web.client.RestTemplate=DEBUG +#logging.level.org.apache.http=DEBUG +#logging.level.httpclient.wire=DEBUG + +server.port=8080 + +shareit-server.url=http://localhost:9090 \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3092af6..b2796d9 100644 --- a/pom.xml +++ b/pom.xml @@ -5,89 +5,43 @@ org.springframework.boot spring-boot-starter-parent - 2.7.2 + 2.7.9 ru.practicum shareit + pom 0.0.1-SNAPSHOT ShareIt - 11 + 11 + 11 + UTF-8 - - - org.springframework.boot - spring-boot-starter-web - - - - org.postgresql - postgresql - runtime - - - com.h2database - h2 - runtime - - - org.springframework.boot - spring-boot-configuration-processor - true - - - org.projectlombok - lombok - true - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.boot - spring-boot-starter-validation - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.jeasy - easy-random-core - 5.0.0 - - + + gateway + server + - - - src/main/resources - true - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + org.apache.maven.plugins maven-surefire-plugin @@ -234,17 +188,5 @@ - - coverage - - - - org.jacoco - jacoco-maven-plugin - - - - - - + \ No newline at end of file diff --git a/server/.gitignore b/server/.gitignore new file mode 100644 index 0000000..79f99ea --- /dev/null +++ b/server/.gitignore @@ -0,0 +1,38 @@ +../server1/target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..2118327 --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,3 @@ +FROM amazoncorretto:11-alpine-jdk +COPY target/*.jar app.jar +ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file diff --git a/server/pom.xml b/server/pom.xml new file mode 100644 index 0000000..584f63d --- /dev/null +++ b/server/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + + ru.practicum + shareit + 0.0.1-SNAPSHOT + + + shareit-server + 0.0.1-SNAPSHOT + + ShareIt Server + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.postgresql + postgresql + runtime + + + + com.h2database + h2 + runtime + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + org.projectlombok + lombok + true + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + coverage + + + + org.jacoco + jacoco-maven-plugin + + + + + + + diff --git a/server/src/main/java/ru/practicum/shareit/Constant.java b/server/src/main/java/ru/practicum/shareit/Constant.java new file mode 100644 index 0000000..4486521 --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/Constant.java @@ -0,0 +1,5 @@ +package ru.practicum.shareit; + +public class Constant { + public static final String USER_HEADER = "X-Sharer-User-Id"; +} diff --git a/src/main/java/ru/practicum/shareit/ShareItApp.java b/server/src/main/java/ru/practicum/shareit/ShareItServer.java similarity index 72% rename from src/main/java/ru/practicum/shareit/ShareItApp.java rename to server/src/main/java/ru/practicum/shareit/ShareItServer.java index 0151768..b872e4f 100644 --- a/src/main/java/ru/practicum/shareit/ShareItApp.java +++ b/server/src/main/java/ru/practicum/shareit/ShareItServer.java @@ -4,9 +4,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class ShareItApp { +public class ShareItServer { public static void main(String[] args) { - SpringApplication.run(ShareItApp.class, args); + SpringApplication.run(ShareItServer.class, args); } } \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/booking/controller/BookingController.java b/server/src/main/java/ru/practicum/shareit/booking/controller/BookingController.java similarity index 85% rename from src/main/java/ru/practicum/shareit/booking/controller/BookingController.java rename to server/src/main/java/ru/practicum/shareit/booking/controller/BookingController.java index 6ffb7a9..a7378cb 100644 --- a/src/main/java/ru/practicum/shareit/booking/controller/BookingController.java +++ b/server/src/main/java/ru/practicum/shareit/booking/controller/BookingController.java @@ -2,29 +2,24 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import ru.practicum.shareit.booking.dto.BookingRequestDto; import ru.practicum.shareit.booking.dto.BookingDtoWithItemAndUser; import ru.practicum.shareit.booking.service.BookingService; -import javax.validation.Valid; -import javax.validation.constraints.Positive; -import javax.validation.constraints.PositiveOrZero; import java.util.List; import static ru.practicum.shareit.Constant.USER_HEADER; @RestController @RequiredArgsConstructor -@Validated @Slf4j @RequestMapping(path = "/bookings") public class BookingController { private final BookingService service; @PostMapping - public BookingDtoWithItemAndUser addRequest(@RequestBody @Valid BookingRequestDto bookingRequestDto, + public BookingDtoWithItemAndUser addRequest(@RequestBody BookingRequestDto bookingRequestDto, @RequestHeader(USER_HEADER) Long userId) { log.info("BookingController: обработка запроса на добавление бронирования"); return service.addRequest(bookingRequestDto, userId); @@ -47,8 +42,8 @@ public BookingDtoWithItemAndUser findById(@RequestHeader(USER_HEADER) Long reque @GetMapping public List findAllByUserAndState(@RequestHeader(USER_HEADER) Long requesterId, @RequestParam(defaultValue = "ALL") String state, - @RequestParam(defaultValue = "0") @PositiveOrZero int from, - @RequestParam(defaultValue = "20") @Positive int size) { + @RequestParam(defaultValue = "0") int from, + @RequestParam(defaultValue = "10") int size) { log.info("BookingController: обработка запроса от пользователя {} на поиск бронирований по состоянию {}", requesterId, state); return service.findAllByUserAndState(requesterId, state, from, size); @@ -57,8 +52,8 @@ public List findAllByUserAndState(@RequestHeader(USER @GetMapping("/owner") public List findAllByOwnerAndState(@RequestHeader(USER_HEADER) Long ownerId, @RequestParam(defaultValue = "ALL") String state, - @RequestParam(defaultValue = "0") @PositiveOrZero int from, - @RequestParam(defaultValue = "20") @Positive int size) { + @RequestParam(defaultValue = "0") int from, + @RequestParam(defaultValue = "10") int size) { log.info("BookingController: обработка запроса от пользователя {} на поиск всех бронирований его вещей с " + "состоянием {}", ownerId, state); return service.findAllByOwnerAndState(ownerId, state, from, size); diff --git a/src/main/java/ru/practicum/shareit/booking/dto/BookingDtoWithItemAndUser.java b/server/src/main/java/ru/practicum/shareit/booking/dto/BookingDtoWithItemAndUser.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/dto/BookingDtoWithItemAndUser.java rename to server/src/main/java/ru/practicum/shareit/booking/dto/BookingDtoWithItemAndUser.java diff --git a/src/main/java/ru/practicum/shareit/booking/dto/BookingMapper.java b/server/src/main/java/ru/practicum/shareit/booking/dto/BookingMapper.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/dto/BookingMapper.java rename to server/src/main/java/ru/practicum/shareit/booking/dto/BookingMapper.java diff --git a/src/main/java/ru/practicum/shareit/booking/dto/BookingRequestDto.java b/server/src/main/java/ru/practicum/shareit/booking/dto/BookingRequestDto.java similarity index 53% rename from src/main/java/ru/practicum/shareit/booking/dto/BookingRequestDto.java rename to server/src/main/java/ru/practicum/shareit/booking/dto/BookingRequestDto.java index 8140e2d..67c31cf 100644 --- a/src/main/java/ru/practicum/shareit/booking/dto/BookingRequestDto.java +++ b/server/src/main/java/ru/practicum/shareit/booking/dto/BookingRequestDto.java @@ -2,19 +2,11 @@ import lombok.Data; -import javax.validation.constraints.Future; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Positive; import java.time.LocalDateTime; @Data public class BookingRequestDto { - @Positive private Long itemId; - @Future - @NotNull private LocalDateTime start; - @Future - @NotNull private LocalDateTime end; } \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/booking/dto/BookingResponseDto.java b/server/src/main/java/ru/practicum/shareit/booking/dto/BookingResponseDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/dto/BookingResponseDto.java rename to server/src/main/java/ru/practicum/shareit/booking/dto/BookingResponseDto.java diff --git a/src/main/java/ru/practicum/shareit/booking/model/Booking.java b/server/src/main/java/ru/practicum/shareit/booking/model/Booking.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/model/Booking.java rename to server/src/main/java/ru/practicum/shareit/booking/model/Booking.java diff --git a/src/main/java/ru/practicum/shareit/booking/model/BookingStatus.java b/server/src/main/java/ru/practicum/shareit/booking/model/BookingStatus.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/model/BookingStatus.java rename to server/src/main/java/ru/practicum/shareit/booking/model/BookingStatus.java diff --git a/src/main/java/ru/practicum/shareit/booking/model/State.java b/server/src/main/java/ru/practicum/shareit/booking/model/State.java similarity index 90% rename from src/main/java/ru/practicum/shareit/booking/model/State.java rename to server/src/main/java/ru/practicum/shareit/booking/model/State.java index d97041a..9c41d9f 100644 --- a/src/main/java/ru/practicum/shareit/booking/model/State.java +++ b/server/src/main/java/ru/practicum/shareit/booking/model/State.java @@ -12,7 +12,7 @@ public enum State { WAITING, REJECTED; - public State stringToState(String state) { + public static State stringToState(String state) { log.info("StateEnum: Конвертация строки {} в Enum State", state); try { return valueOf(state); diff --git a/src/main/java/ru/practicum/shareit/booking/repository/BookingStorage.java b/server/src/main/java/ru/practicum/shareit/booking/repository/BookingStorage.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/repository/BookingStorage.java rename to server/src/main/java/ru/practicum/shareit/booking/repository/BookingStorage.java diff --git a/src/main/java/ru/practicum/shareit/booking/service/BookingService.java b/server/src/main/java/ru/practicum/shareit/booking/service/BookingService.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/service/BookingService.java rename to server/src/main/java/ru/practicum/shareit/booking/service/BookingService.java diff --git a/src/main/java/ru/practicum/shareit/booking/service/impl/BookingServiceImpl.java b/server/src/main/java/ru/practicum/shareit/booking/service/impl/BookingServiceImpl.java similarity index 98% rename from src/main/java/ru/practicum/shareit/booking/service/impl/BookingServiceImpl.java rename to server/src/main/java/ru/practicum/shareit/booking/service/impl/BookingServiceImpl.java index 6c7258d..a47bc4e 100644 --- a/src/main/java/ru/practicum/shareit/booking/service/impl/BookingServiceImpl.java +++ b/server/src/main/java/ru/practicum/shareit/booking/service/impl/BookingServiceImpl.java @@ -101,7 +101,7 @@ public List findAllByUserAndState(Long userId, String stateString, userId); userStorage.findById(userId).orElseThrow(() -> new NotFoundException( String.format("Пользователь с id %d не найден", userId))); - State state = State.ALL.stringToState(stateString); + State state = State.stringToState(stateString); PageRequest pageRequest = PageRequest.of((from / size), size, sortStartDesc); List bookings = new ArrayList<>(); switch (state) { @@ -137,7 +137,7 @@ public List findAllByOwnerAndState(Long ownerId, Stri throw new NotFoundException(String.format("У пользователя с id %d нет вещей в собственности", ownerId)); } List bookings = new ArrayList<>(); - State state = State.ALL.stringToState(stateString); + State state = State.stringToState(stateString); PageRequest pageRequest = PageRequest.of((from / size), size, sortStartDesc); switch (state) { case ALL: diff --git a/src/main/java/ru/practicum/shareit/exception/controller/ErrorHandler.java b/server/src/main/java/ru/practicum/shareit/exception/controller/ErrorHandler.java similarity index 80% rename from src/main/java/ru/practicum/shareit/exception/controller/ErrorHandler.java rename to server/src/main/java/ru/practicum/shareit/exception/controller/ErrorHandler.java index 020ba2b..516fe03 100644 --- a/src/main/java/ru/practicum/shareit/exception/controller/ErrorHandler.java +++ b/server/src/main/java/ru/practicum/shareit/exception/controller/ErrorHandler.java @@ -10,29 +10,34 @@ import ru.practicum.shareit.exception.exceptions.NotFoundException; import ru.practicum.shareit.exception.model.ErrorResponse; -import java.util.Arrays; - @RestControllerAdvice @Slf4j public class ErrorHandler { @ExceptionHandler @ResponseStatus(HttpStatus.NOT_FOUND) public ErrorResponse handleNotFoundException(final NotFoundException e) { - log.info(Arrays.toString(e.getStackTrace())); + e.printStackTrace(); return new ErrorResponse(e.getMessage()); } @ExceptionHandler @ResponseStatus(HttpStatus.BAD_REQUEST) public ErrorResponse handleMethodArgumentNotValidException(final MethodArgumentNotValidException e) { - log.info(Arrays.toString(e.getStackTrace())); + e.printStackTrace(); return new ErrorResponse(e.getMessage()); } @ExceptionHandler @ResponseStatus(HttpStatus.BAD_REQUEST) public ErrorResponse handleBadRequestException(final BadRequestException e) { - log.info(Arrays.toString(e.getStackTrace())); + e.printStackTrace(); + return new ErrorResponse(e.getMessage()); + } + + @ExceptionHandler + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + public ErrorResponse handleException(final Exception e) { + e.printStackTrace(); return new ErrorResponse(e.getMessage()); } } \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/exception/exceptions/BadRequestException.java b/server/src/main/java/ru/practicum/shareit/exception/exceptions/BadRequestException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/exceptions/BadRequestException.java rename to server/src/main/java/ru/practicum/shareit/exception/exceptions/BadRequestException.java diff --git a/src/main/java/ru/practicum/shareit/exception/exceptions/NotEnoughRightsException.java b/server/src/main/java/ru/practicum/shareit/exception/exceptions/NotEnoughRightsException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/exceptions/NotEnoughRightsException.java rename to server/src/main/java/ru/practicum/shareit/exception/exceptions/NotEnoughRightsException.java diff --git a/src/main/java/ru/practicum/shareit/exception/exceptions/NotFoundException.java b/server/src/main/java/ru/practicum/shareit/exception/exceptions/NotFoundException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/exceptions/NotFoundException.java rename to server/src/main/java/ru/practicum/shareit/exception/exceptions/NotFoundException.java diff --git a/src/main/java/ru/practicum/shareit/exception/model/ErrorResponse.java b/server/src/main/java/ru/practicum/shareit/exception/model/ErrorResponse.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/model/ErrorResponse.java rename to server/src/main/java/ru/practicum/shareit/exception/model/ErrorResponse.java diff --git a/src/main/java/ru/practicum/shareit/item/comment/Comment.java b/server/src/main/java/ru/practicum/shareit/item/comment/Comment.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/comment/Comment.java rename to server/src/main/java/ru/practicum/shareit/item/comment/Comment.java diff --git a/src/main/java/ru/practicum/shareit/item/comment/CommentMapper.java b/server/src/main/java/ru/practicum/shareit/item/comment/CommentMapper.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/comment/CommentMapper.java rename to server/src/main/java/ru/practicum/shareit/item/comment/CommentMapper.java diff --git a/src/main/java/ru/practicum/shareit/item/comment/CommentRequestDto.java b/server/src/main/java/ru/practicum/shareit/item/comment/CommentRequestDto.java similarity index 51% rename from src/main/java/ru/practicum/shareit/item/comment/CommentRequestDto.java rename to server/src/main/java/ru/practicum/shareit/item/comment/CommentRequestDto.java index 407e340..817ac1c 100644 --- a/src/main/java/ru/practicum/shareit/item/comment/CommentRequestDto.java +++ b/server/src/main/java/ru/practicum/shareit/item/comment/CommentRequestDto.java @@ -2,12 +2,7 @@ import lombok.Data; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; - @Data public class CommentRequestDto { - @NotBlank - @Size(max = 512) private String text; } diff --git a/src/main/java/ru/practicum/shareit/item/comment/CommentResponseDto.java b/server/src/main/java/ru/practicum/shareit/item/comment/CommentResponseDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/comment/CommentResponseDto.java rename to server/src/main/java/ru/practicum/shareit/item/comment/CommentResponseDto.java diff --git a/src/main/java/ru/practicum/shareit/item/comment/CommentStorage.java b/server/src/main/java/ru/practicum/shareit/item/comment/CommentStorage.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/comment/CommentStorage.java rename to server/src/main/java/ru/practicum/shareit/item/comment/CommentStorage.java diff --git a/src/main/java/ru/practicum/shareit/item/controller/ItemController.java b/server/src/main/java/ru/practicum/shareit/item/controller/ItemController.java similarity index 86% rename from src/main/java/ru/practicum/shareit/item/controller/ItemController.java rename to server/src/main/java/ru/practicum/shareit/item/controller/ItemController.java index fba73fa..7b3065b 100644 --- a/src/main/java/ru/practicum/shareit/item/controller/ItemController.java +++ b/server/src/main/java/ru/practicum/shareit/item/controller/ItemController.java @@ -2,7 +2,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import ru.practicum.shareit.item.comment.CommentRequestDto; import ru.practicum.shareit.item.comment.CommentResponseDto; @@ -11,9 +10,6 @@ import ru.practicum.shareit.item.dto.ItemResponseDtoWithBookings; import ru.practicum.shareit.item.service.ItemService; -import javax.validation.Valid; -import javax.validation.constraints.Positive; -import javax.validation.constraints.PositiveOrZero; import java.util.List; import static ru.practicum.shareit.Constant.USER_HEADER; @@ -21,21 +17,20 @@ @RestController @Slf4j @RequiredArgsConstructor -@Validated @RequestMapping("/items") public class ItemController { private final ItemService service; @PostMapping public ItemResponseDto create(@RequestHeader(USER_HEADER) Long userId, - @RequestBody @Valid ItemRequestDto itemRequestDto) { + @RequestBody ItemRequestDto itemRequestDto) { log.info("ItemController: обработка запроса от пользователя " + userId + " на добавление вещи + itemDto.toString()"); return service.create(userId, itemRequestDto); } @PostMapping("/{itemId}/comment") public CommentResponseDto addComment(@RequestHeader(USER_HEADER) Long userId, @PathVariable Long itemId, - @RequestBody @Valid CommentRequestDto commentRequestDto) { + @RequestBody CommentRequestDto commentRequestDto) { log.info("ItemController: обработка запроса от пользователя " + userId + " на добавление комментария " + commentRequestDto.toString() + " к вещи " + itemId); return service.addComment(userId, itemId, commentRequestDto); @@ -57,16 +52,16 @@ public ItemResponseDtoWithBookings findById(@PathVariable Long itemId, @RequestH @GetMapping public List findOwnersItems(@RequestHeader(USER_HEADER) Long userId, - @RequestParam(defaultValue = "0") @PositiveOrZero int from, - @RequestParam(defaultValue = "20") @Positive int size) { + @RequestParam(defaultValue = "0") int from, + @RequestParam(defaultValue = "10") int size) { log.info("ItemController: обработка запроса на поиск вещей пользователя с id {}", userId); return service.findOwnersItems(userId, from, size); } @GetMapping("/search") public List searchItems(@RequestParam String text, - @RequestParam(defaultValue = "0") @PositiveOrZero int from, - @RequestParam(defaultValue = "20") @Positive int size) { + @RequestParam(defaultValue = "0") int from, + @RequestParam(defaultValue = "10") int size) { log.info("ItemController: обработка запроса на поиск вещей, содержащих в названии или описании фрагмент {}", text); return service.searchItems(text, from, size); } diff --git a/src/main/java/ru/practicum/shareit/item/dto/ItemMapper.java b/server/src/main/java/ru/practicum/shareit/item/dto/ItemMapper.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/dto/ItemMapper.java rename to server/src/main/java/ru/practicum/shareit/item/dto/ItemMapper.java diff --git a/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java b/server/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java similarity index 61% rename from src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java rename to server/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java index feb748d..e3d70d5 100644 --- a/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java +++ b/server/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java @@ -2,16 +2,10 @@ import lombok.Data; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; - @Data public class ItemRequestDto { - @NotBlank private String name; - @NotBlank private String description; - @NotNull private Boolean available; private Long requestId; } \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/item/dto/ItemResponseDto.java b/server/src/main/java/ru/practicum/shareit/item/dto/ItemResponseDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/dto/ItemResponseDto.java rename to server/src/main/java/ru/practicum/shareit/item/dto/ItemResponseDto.java diff --git a/src/main/java/ru/practicum/shareit/item/dto/ItemResponseDtoWithBookings.java b/server/src/main/java/ru/practicum/shareit/item/dto/ItemResponseDtoWithBookings.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/dto/ItemResponseDtoWithBookings.java rename to server/src/main/java/ru/practicum/shareit/item/dto/ItemResponseDtoWithBookings.java diff --git a/src/main/java/ru/practicum/shareit/item/model/Item.java b/server/src/main/java/ru/practicum/shareit/item/model/Item.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/model/Item.java rename to server/src/main/java/ru/practicum/shareit/item/model/Item.java diff --git a/src/main/java/ru/practicum/shareit/item/repository/ItemStorage.java b/server/src/main/java/ru/practicum/shareit/item/repository/ItemStorage.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/repository/ItemStorage.java rename to server/src/main/java/ru/practicum/shareit/item/repository/ItemStorage.java diff --git a/src/main/java/ru/practicum/shareit/item/service/ItemService.java b/server/src/main/java/ru/practicum/shareit/item/service/ItemService.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/service/ItemService.java rename to server/src/main/java/ru/practicum/shareit/item/service/ItemService.java diff --git a/src/main/java/ru/practicum/shareit/item/service/impl/ItemServiceImpl.java b/server/src/main/java/ru/practicum/shareit/item/service/impl/ItemServiceImpl.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/service/impl/ItemServiceImpl.java rename to server/src/main/java/ru/practicum/shareit/item/service/impl/ItemServiceImpl.java diff --git a/src/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java b/server/src/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java similarity index 84% rename from src/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java rename to server/src/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java index 718239b..e8afd23 100644 --- a/src/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java +++ b/server/src/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java @@ -2,30 +2,24 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import ru.practicum.shareit.request.dto.ItemRequestRequestDto; import ru.practicum.shareit.request.dto.ItemRequestResponseDto; import ru.practicum.shareit.request.service.ItemRequestService; -import javax.validation.Valid; -import javax.validation.constraints.Positive; -import javax.validation.constraints.PositiveOrZero; - import java.util.List; import static ru.practicum.shareit.Constant.USER_HEADER; @RestController @RequiredArgsConstructor -@Validated @RequestMapping(path = "/requests") @Slf4j public class ItemRequestController { private final ItemRequestService service; @PostMapping - public ItemRequestResponseDto create(@RequestBody @Valid ItemRequestRequestDto itemRequestRequestDto, + public ItemRequestResponseDto create(@RequestBody ItemRequestRequestDto itemRequestRequestDto, @RequestHeader(USER_HEADER) Long userId) { log.info("ItemRequestController: обработка запроса на добавление ItemRequest от пользователя {}", userId); return service.create(itemRequestRequestDto, userId); @@ -38,8 +32,8 @@ public List findByAuthor(@RequestHeader(USER_HEADER) Lon } @GetMapping("/all") - public List findAll(@RequestParam(defaultValue = "0") @PositiveOrZero int from, - @RequestParam(defaultValue = "20") @Positive int size, + public List findAll(@RequestParam(defaultValue = "0") int from, + @RequestParam(defaultValue = "10") int size, @RequestHeader(USER_HEADER) Long userId) { log.info("ItemRequestController: обработка запроса на поиск всех ItemRequest от пользователя {}", userId); return service.findAllRequests(userId, from, size); diff --git a/src/main/java/ru/practicum/shareit/request/dto/ItemRequestMapper.java b/server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestMapper.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/dto/ItemRequestMapper.java rename to server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestMapper.java diff --git a/server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java b/server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java new file mode 100644 index 0000000..f835c89 --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java @@ -0,0 +1,8 @@ +package ru.practicum.shareit.request.dto; + +import lombok.Data; + +@Data +public class ItemRequestRequestDto { + private String description; +} diff --git a/src/main/java/ru/practicum/shareit/request/dto/ItemRequestResponseDto.java b/server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestResponseDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/dto/ItemRequestResponseDto.java rename to server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestResponseDto.java diff --git a/src/main/java/ru/practicum/shareit/request/model/ItemRequest.java b/server/src/main/java/ru/practicum/shareit/request/model/ItemRequest.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/model/ItemRequest.java rename to server/src/main/java/ru/practicum/shareit/request/model/ItemRequest.java diff --git a/src/main/java/ru/practicum/shareit/request/repository/ItemRequestStorage.java b/server/src/main/java/ru/practicum/shareit/request/repository/ItemRequestStorage.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/repository/ItemRequestStorage.java rename to server/src/main/java/ru/practicum/shareit/request/repository/ItemRequestStorage.java diff --git a/src/main/java/ru/practicum/shareit/request/service/ItemRequestService.java b/server/src/main/java/ru/practicum/shareit/request/service/ItemRequestService.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/service/ItemRequestService.java rename to server/src/main/java/ru/practicum/shareit/request/service/ItemRequestService.java diff --git a/src/main/java/ru/practicum/shareit/request/service/impl/ItemRequestServiceImpl.java b/server/src/main/java/ru/practicum/shareit/request/service/impl/ItemRequestServiceImpl.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/service/impl/ItemRequestServiceImpl.java rename to server/src/main/java/ru/practicum/shareit/request/service/impl/ItemRequestServiceImpl.java diff --git a/src/main/java/ru/practicum/shareit/user/controller/UserController.java b/server/src/main/java/ru/practicum/shareit/user/controller/UserController.java similarity index 76% rename from src/main/java/ru/practicum/shareit/user/controller/UserController.java rename to server/src/main/java/ru/practicum/shareit/user/controller/UserController.java index f053e1c..6b25b6c 100644 --- a/src/main/java/ru/practicum/shareit/user/controller/UserController.java +++ b/server/src/main/java/ru/practicum/shareit/user/controller/UserController.java @@ -3,12 +3,10 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; -import ru.practicum.shareit.user.dto.UserCreationDto; import ru.practicum.shareit.user.dto.UserRequestDto; import ru.practicum.shareit.user.dto.UserResponseDto; import ru.practicum.shareit.user.service.UserService; -import javax.validation.Valid; import java.util.List; @RestController @@ -32,19 +30,18 @@ public UserResponseDto findById(@PathVariable Long userId) { } @PostMapping - public UserResponseDto create(@Valid @RequestBody UserCreationDto userCreationDto) { - log.info("UserController: обработка запроса на создание пользователя {}}", userCreationDto.toString()); - return service.create(userCreationDto); + public UserResponseDto create(@RequestBody UserRequestDto userRequestDto) { + log.info("UserController: обработка запроса на создание пользователя {}}", userRequestDto.toString()); + return service.create(userRequestDto); } @PatchMapping("/{userId}") - public UserResponseDto update(@Valid @RequestBody UserRequestDto userRequestDto, - @PathVariable Long userId) { + public UserResponseDto update(@RequestBody UserRequestDto userRequestDto, @PathVariable Long userId) { log.info("UserController: обработка запроса на обновление пользователя с id {}", userId); return service.update(userRequestDto, userId); } - @DeleteMapping("{userId}") + @DeleteMapping("/{userId}") public void delete(@PathVariable Long userId) { log.info("UserController: обработка запроса на удаление пользователя с id {}", userId); service.delete(userId); diff --git a/src/main/java/ru/practicum/shareit/user/dto/UserMapper.java b/server/src/main/java/ru/practicum/shareit/user/dto/UserMapper.java similarity index 74% rename from src/main/java/ru/practicum/shareit/user/dto/UserMapper.java rename to server/src/main/java/ru/practicum/shareit/user/dto/UserMapper.java index 0657d62..9937baf 100644 --- a/src/main/java/ru/practicum/shareit/user/dto/UserMapper.java +++ b/server/src/main/java/ru/practicum/shareit/user/dto/UserMapper.java @@ -20,11 +20,4 @@ public UserResponseDto toUserResponseDto(User user) { userResponseDto.setEmail(user.getEmail()); return userResponseDto; } - - public User fromUserCreationDto(UserCreationDto userCreationDto) { - User user = new User(); - user.setName(userCreationDto.getName()); - user.setEmail(userCreationDto.getEmail()); - return user; - } } \ No newline at end of file diff --git a/server/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java b/server/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java new file mode 100644 index 0000000..97986e3 --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java @@ -0,0 +1,9 @@ +package ru.practicum.shareit.user.dto; + +import lombok.Data; + +@Data +public class UserRequestDto { + private String name; + private String email; +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/user/dto/UserResponseDto.java b/server/src/main/java/ru/practicum/shareit/user/dto/UserResponseDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/user/dto/UserResponseDto.java rename to server/src/main/java/ru/practicum/shareit/user/dto/UserResponseDto.java diff --git a/src/main/java/ru/practicum/shareit/user/model/User.java b/server/src/main/java/ru/practicum/shareit/user/model/User.java similarity index 100% rename from src/main/java/ru/practicum/shareit/user/model/User.java rename to server/src/main/java/ru/practicum/shareit/user/model/User.java diff --git a/src/main/java/ru/practicum/shareit/user/repository/UserStorage.java b/server/src/main/java/ru/practicum/shareit/user/repository/UserStorage.java similarity index 100% rename from src/main/java/ru/practicum/shareit/user/repository/UserStorage.java rename to server/src/main/java/ru/practicum/shareit/user/repository/UserStorage.java diff --git a/src/main/java/ru/practicum/shareit/user/service/UserService.java b/server/src/main/java/ru/practicum/shareit/user/service/UserService.java similarity index 77% rename from src/main/java/ru/practicum/shareit/user/service/UserService.java rename to server/src/main/java/ru/practicum/shareit/user/service/UserService.java index 2da54f0..539198e 100644 --- a/src/main/java/ru/practicum/shareit/user/service/UserService.java +++ b/server/src/main/java/ru/practicum/shareit/user/service/UserService.java @@ -1,6 +1,5 @@ package ru.practicum.shareit.user.service; -import ru.practicum.shareit.user.dto.UserCreationDto; import ru.practicum.shareit.user.dto.UserRequestDto; import ru.practicum.shareit.user.dto.UserResponseDto; @@ -11,7 +10,7 @@ public interface UserService { UserResponseDto findById(Long userId); - UserResponseDto create(UserCreationDto userCreationDto); + UserResponseDto create(UserRequestDto userCreationDto); UserResponseDto update(UserRequestDto userRequestDto, Long userId); diff --git a/src/main/java/ru/practicum/shareit/user/service/impl/UserServiceImpl.java b/server/src/main/java/ru/practicum/shareit/user/service/impl/UserServiceImpl.java similarity index 94% rename from src/main/java/ru/practicum/shareit/user/service/impl/UserServiceImpl.java rename to server/src/main/java/ru/practicum/shareit/user/service/impl/UserServiceImpl.java index c429309..51b6a77 100644 --- a/src/main/java/ru/practicum/shareit/user/service/impl/UserServiceImpl.java +++ b/server/src/main/java/ru/practicum/shareit/user/service/impl/UserServiceImpl.java @@ -5,7 +5,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ru.practicum.shareit.exception.exceptions.NotFoundException; -import ru.practicum.shareit.user.dto.UserCreationDto; import ru.practicum.shareit.user.dto.UserResponseDto; import ru.practicum.shareit.user.model.User; import ru.practicum.shareit.user.repository.UserStorage; @@ -40,9 +39,9 @@ public UserResponseDto findById(Long userId) { @Override @Transactional - public UserResponseDto create(UserCreationDto userCreationDto) { + public UserResponseDto create(UserRequestDto userCreationDto) { log.info("UserService: Происходит обработка запроса на создание пользователя с email {}", userCreationDto.getEmail()); - return UserMapper.toUserResponseDto(storage.save(UserMapper.fromUserCreationDto(userCreationDto))); + return UserMapper.toUserResponseDto(storage.save(UserMapper.toUser(userCreationDto))); } @Override diff --git a/server/src/main/resources/application.properties b/server/src/main/resources/application.properties new file mode 100644 index 0000000..32b2744 --- /dev/null +++ b/server/src/main/resources/application.properties @@ -0,0 +1,18 @@ +server.port=9090 + +spring.jpa.hibernate.ddl-auto=none +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL10Dialect +spring.jpa.properties.hibernate.format_sql=true +spring.sql.init.mode=always + +#--- +spring.datasource.driverClassName=org.postgresql.Driver +spring.datasource.url=jdbc:postgresql://localhost:5432/shareIt +spring.datasource.username=root +spring.datasource.password=root +#--- +spring.config.activate.on-profile=ci,test +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.url=jdbc:h2:mem:shareit +spring.datasource.username=test +spring.datasource.password=test \ No newline at end of file diff --git a/src/main/resources/schema.sql b/server/src/main/resources/schema.sql similarity index 100% rename from src/main/resources/schema.sql rename to server/src/main/resources/schema.sql diff --git a/src/test/java/ru/practicum/shareit/ShareItTests.java b/server/src/test/java/ru/practicum/shareit/ShareItTests.java similarity index 100% rename from src/test/java/ru/practicum/shareit/ShareItTests.java rename to server/src/test/java/ru/practicum/shareit/ShareItTests.java diff --git a/src/test/java/ru/practicum/shareit/booking/BookingControllerTest.java b/server/src/test/java/ru/practicum/shareit/booking/BookingControllerTest.java similarity index 72% rename from src/test/java/ru/practicum/shareit/booking/BookingControllerTest.java rename to server/src/test/java/ru/practicum/shareit/booking/BookingControllerTest.java index c871cbf..7a7a852 100644 --- a/src/test/java/ru/practicum/shareit/booking/BookingControllerTest.java +++ b/server/src/test/java/ru/practicum/shareit/booking/BookingControllerTest.java @@ -55,54 +55,6 @@ void testCreateBooking() throws Exception { .andExpect(jsonPath("$.id", is(responseDto.getId()), Long.class)); } - @Test - void testCreateBookingFailItemId() throws Exception { - BookingRequestDto requestDto = new BookingRequestDto(); - requestDto.setItemId(0L); - requestDto.setStart(LocalDateTime.now().plusDays(2)); - requestDto.setEnd(LocalDateTime.now().plusDays(3)); - - mvc.perform(post("/bookings") - .header(USER_HEADER, "1") - .content(mapper.writeValueAsString(requestDto)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - - @Test - void testCreateBookingFailStartDate() throws Exception { - BookingRequestDto requestDto = new BookingRequestDto(); - requestDto.setItemId(1L); - requestDto.setStart(LocalDateTime.now().minusDays(2)); - requestDto.setEnd(LocalDateTime.now().plusDays(3)); - - mvc.perform(post("/bookings") - .header(USER_HEADER, "1") - .content(mapper.writeValueAsString(requestDto)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - - @Test - void testCreateBookingFailEndDate() throws Exception { - BookingRequestDto requestDto = new BookingRequestDto(); - requestDto.setItemId(1L); - requestDto.setStart(LocalDateTime.now().plusDays(2)); - requestDto.setEnd(null); - - mvc.perform(post("/bookings") - .header(USER_HEADER, "1") - .content(mapper.writeValueAsString(requestDto)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - @Test void testUpdateBooking() throws Exception { BookingDtoWithItemAndUser responseDto = new BookingDtoWithItemAndUser(); diff --git a/src/test/java/ru/practicum/shareit/booking/BookingServiceTest.java b/server/src/test/java/ru/practicum/shareit/booking/BookingServiceTest.java similarity index 100% rename from src/test/java/ru/practicum/shareit/booking/BookingServiceTest.java rename to server/src/test/java/ru/practicum/shareit/booking/BookingServiceTest.java diff --git a/src/test/java/ru/practicum/shareit/booking/BookingStorageTest.java b/server/src/test/java/ru/practicum/shareit/booking/BookingStorageTest.java similarity index 100% rename from src/test/java/ru/practicum/shareit/booking/BookingStorageTest.java rename to server/src/test/java/ru/practicum/shareit/booking/BookingStorageTest.java diff --git a/src/test/java/ru/practicum/shareit/item/ItemControllerTest.java b/server/src/test/java/ru/practicum/shareit/item/ItemControllerTest.java similarity index 78% rename from src/test/java/ru/practicum/shareit/item/ItemControllerTest.java rename to server/src/test/java/ru/practicum/shareit/item/ItemControllerTest.java index 337bfc8..bbbe275 100644 --- a/src/test/java/ru/practicum/shareit/item/ItemControllerTest.java +++ b/server/src/test/java/ru/practicum/shareit/item/ItemControllerTest.java @@ -84,54 +84,6 @@ void testSaveItem() throws Exception { .andExpect(jsonPath("$.available", is(responseDto.getAvailable()))); } - @Test - void testCreateItemFailName() throws Exception { - ItemRequestDto itemRequestDto = new ItemRequestDto(); - itemRequestDto.setName(""); - itemRequestDto.setDescription("item description"); - itemRequestDto.setAvailable(true); - - mvc.perform(post("/items") - .header(USER_HEADER, 1) - .content(mapper.writeValueAsString(itemRequestDto)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - - @Test - void testCreateItemFailDescription() throws Exception { - ItemRequestDto itemRequestDto = new ItemRequestDto(); - itemRequestDto.setName("name"); - itemRequestDto.setDescription(""); - itemRequestDto.setAvailable(true); - - mvc.perform(post("/items") - .header(USER_HEADER, 1) - .content(mapper.writeValueAsString(itemRequestDto)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - - @Test - void testCreateItemFailAvailable() throws Exception { - ItemRequestDto itemRequestDto = new ItemRequestDto(); - itemRequestDto.setName("name"); - itemRequestDto.setDescription("description"); - itemRequestDto.setAvailable(null); - - mvc.perform(post("/items") - .header(USER_HEADER, 1) - .content(mapper.writeValueAsString(itemRequestDto)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - @Test void testUpdateItem() throws Exception { when(itemService.update(anyLong(), anyLong(), any(ItemRequestDto.class))).thenReturn(responseDto); diff --git a/src/test/java/ru/practicum/shareit/item/ItemIntegrationTest.java b/server/src/test/java/ru/practicum/shareit/item/ItemIntegrationTest.java similarity index 100% rename from src/test/java/ru/practicum/shareit/item/ItemIntegrationTest.java rename to server/src/test/java/ru/practicum/shareit/item/ItemIntegrationTest.java diff --git a/src/test/java/ru/practicum/shareit/item/ItemServiceTest.java b/server/src/test/java/ru/practicum/shareit/item/ItemServiceTest.java similarity index 100% rename from src/test/java/ru/practicum/shareit/item/ItemServiceTest.java rename to server/src/test/java/ru/practicum/shareit/item/ItemServiceTest.java diff --git a/src/test/java/ru/practicum/shareit/item/ItemStorageTest.java b/server/src/test/java/ru/practicum/shareit/item/ItemStorageTest.java similarity index 100% rename from src/test/java/ru/practicum/shareit/item/ItemStorageTest.java rename to server/src/test/java/ru/practicum/shareit/item/ItemStorageTest.java diff --git a/src/test/java/ru/practicum/shareit/request/ItemRequestControllerTest.java b/server/src/test/java/ru/practicum/shareit/request/ItemRequestControllerTest.java similarity index 87% rename from src/test/java/ru/practicum/shareit/request/ItemRequestControllerTest.java rename to server/src/test/java/ru/practicum/shareit/request/ItemRequestControllerTest.java index 5412622..ba29b54 100644 --- a/src/test/java/ru/practicum/shareit/request/ItemRequestControllerTest.java +++ b/server/src/test/java/ru/practicum/shareit/request/ItemRequestControllerTest.java @@ -54,20 +54,6 @@ void testCreateItemRequest() throws Exception { .andExpect(jsonPath("$.id", is(responseDto.getId()), Long.class)); } - @Test - void testCreateItemFailDescription() throws Exception { - ItemRequestRequestDto requestDto = new ItemRequestRequestDto(); - requestDto.setDescription(""); - mvc.perform(post("/requests") - .header(USER_HEADER, "1") - .content(mapper.writeValueAsString(requestDto)) - .header("X-Sharer-User-Id", "1") - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - @Test void testFindByAuthor() throws Exception { ItemRequestResponseDto responseDto = new ItemRequestResponseDto(); diff --git a/src/test/java/ru/practicum/shareit/request/ItemRequestIntegrationTest.java b/server/src/test/java/ru/practicum/shareit/request/ItemRequestIntegrationTest.java similarity index 100% rename from src/test/java/ru/practicum/shareit/request/ItemRequestIntegrationTest.java rename to server/src/test/java/ru/practicum/shareit/request/ItemRequestIntegrationTest.java diff --git a/src/test/java/ru/practicum/shareit/request/ItemRequestServiceTest.java b/server/src/test/java/ru/practicum/shareit/request/ItemRequestServiceTest.java similarity index 100% rename from src/test/java/ru/practicum/shareit/request/ItemRequestServiceTest.java rename to server/src/test/java/ru/practicum/shareit/request/ItemRequestServiceTest.java diff --git a/src/test/java/ru/practicum/shareit/request/ItemRequestStorageTest.java b/server/src/test/java/ru/practicum/shareit/request/ItemRequestStorageTest.java similarity index 100% rename from src/test/java/ru/practicum/shareit/request/ItemRequestStorageTest.java rename to server/src/test/java/ru/practicum/shareit/request/ItemRequestStorageTest.java diff --git a/src/test/java/ru/practicum/shareit/user/UserControllerTest.java b/server/src/test/java/ru/practicum/shareit/user/UserControllerTest.java similarity index 76% rename from src/test/java/ru/practicum/shareit/user/UserControllerTest.java rename to server/src/test/java/ru/practicum/shareit/user/UserControllerTest.java index e45c527..6c59193 100644 --- a/src/test/java/ru/practicum/shareit/user/UserControllerTest.java +++ b/server/src/test/java/ru/practicum/shareit/user/UserControllerTest.java @@ -9,7 +9,6 @@ import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import ru.practicum.shareit.user.controller.UserController; -import ru.practicum.shareit.user.dto.UserCreationDto; import ru.practicum.shareit.user.dto.UserRequestDto; import ru.practicum.shareit.user.dto.UserResponseDto; import ru.practicum.shareit.user.service.UserService; @@ -34,16 +33,11 @@ public class UserControllerTest { @MockBean UserService userService; - private static UserCreationDto userCreationDto; private static UserRequestDto userRequestDto; private static UserResponseDto userResponseDto; @BeforeAll public static void setUp() { - userCreationDto = new UserCreationDto(); - userCreationDto.setName("user"); - userCreationDto.setEmail("user@user.com"); - userRequestDto = new UserRequestDto(); userRequestDto.setName("user"); userRequestDto.setEmail("user@user.com"); @@ -56,11 +50,11 @@ public static void setUp() { @Test void testSaveUser() throws Exception { - when(userService.create(any(UserCreationDto.class))) + when(userService.create(any(UserRequestDto.class))) .thenReturn(userResponseDto); mvc.perform(post("/users") - .content(mapper.writeValueAsString(userCreationDto)) + .content(mapper.writeValueAsString(userRequestDto)) .characterEncoding(StandardCharsets.UTF_8) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) @@ -70,32 +64,6 @@ void testSaveUser() throws Exception { .andExpect(jsonPath("$.email", is(userResponseDto.getEmail()))); } - @Test - void testSaveUserFailEmail() throws Exception { - UserCreationDto userCreationDto1 = new UserCreationDto(); - userCreationDto1.setName("name"); - userCreationDto1.setEmail("email"); - mvc.perform(post("/users") - .content(mapper.writeValueAsString(userCreationDto1)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - - @Test - void testSaveUserFailName() throws Exception { - UserCreationDto userCreationDto1 = new UserCreationDto(); - userCreationDto1.setName(""); - userCreationDto1.setEmail("email"); - mvc.perform(post("/users") - .content(mapper.writeValueAsString(userCreationDto1)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - @Test void testUpdateUser() throws Exception { when(userService.update(any(UserRequestDto.class), anyLong())).thenReturn(userResponseDto); diff --git a/src/test/java/ru/practicum/shareit/user/UserIntegrateTest.java b/server/src/test/java/ru/practicum/shareit/user/UserIntegrateTest.java similarity index 70% rename from src/test/java/ru/practicum/shareit/user/UserIntegrateTest.java rename to server/src/test/java/ru/practicum/shareit/user/UserIntegrateTest.java index ac7a936..efa56ab 100644 --- a/src/test/java/ru/practicum/shareit/user/UserIntegrateTest.java +++ b/server/src/test/java/ru/practicum/shareit/user/UserIntegrateTest.java @@ -1,13 +1,11 @@ package ru.practicum.shareit.user; -import org.jeasy.random.EasyRandom; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.test.annotation.DirtiesContext; import ru.practicum.shareit.exception.exceptions.NotFoundException; -import ru.practicum.shareit.user.dto.UserCreationDto; import ru.practicum.shareit.user.dto.UserRequestDto; import ru.practicum.shareit.user.dto.UserResponseDto; import ru.practicum.shareit.user.service.impl.UserServiceImpl; @@ -22,12 +20,10 @@ public class UserIntegrateTest { @Autowired private UserServiceImpl userService; - private final EasyRandom easyRandom = new EasyRandom(); - @Test @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) public void addUser() { - UserCreationDto creationDto = new UserCreationDto(); + UserRequestDto creationDto = new UserRequestDto(); creationDto.setName("user"); creationDto.setEmail("user@user.com"); @@ -44,10 +40,15 @@ public void addUser() { @Test @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) public void findAll() { - UserCreationDto creationDto = easyRandom.nextObject(UserCreationDto.class); + UserRequestDto creationDto = new UserRequestDto(); + creationDto.setName("user"); + creationDto.setEmail("user@user.com"); UserResponseDto user = userService.create(creationDto); assertEquals(1, userService.findAll().size()); - UserResponseDto newUser = userService.create(easyRandom.nextObject(UserCreationDto.class)); + UserRequestDto newCreationDto = new UserRequestDto(); + newCreationDto.setName("newUser"); + newCreationDto.setEmail("newUser@user.com"); + UserResponseDto newUser = userService.create(newCreationDto); List userList = userService.findAll(); assertEquals(2, userList.size()); @@ -60,11 +61,16 @@ public void findAll() { public void testFindById() { assertThrows(NotFoundException.class, () -> userService.findById(1L)); - UserCreationDto creationDto = easyRandom.nextObject(UserCreationDto.class); + UserRequestDto creationDto = new UserRequestDto(); + creationDto.setName("user"); + creationDto.setEmail("user@user.com"); userService.create(creationDto); - UserResponseDto newUser = userService.create(easyRandom.nextObject(UserCreationDto.class)); + UserRequestDto newCreationDto = new UserRequestDto(); + newCreationDto.setName("newUser"); + newCreationDto.setEmail("newUser@user.com"); + UserResponseDto newUser = userService.create(newCreationDto); assertEquals(newUser, userService.findById(newUser.getId())); } @@ -77,7 +83,11 @@ void testUpdate() { assertThrows(NotFoundException.class, () -> userService.update(requestDto, 1L)); - UserResponseDto user = userService.create(easyRandom.nextObject(UserCreationDto.class)); + UserRequestDto creationDto = new UserRequestDto(); + creationDto.setName("user"); + creationDto.setEmail("user@user.com"); + + UserResponseDto user = userService.create(creationDto); UserResponseDto responseDto = userService.update(requestDto, user.getId()); @@ -87,7 +97,11 @@ void testUpdate() { @Test @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) void testDelete() { - UserResponseDto responseDto = userService.create(easyRandom.nextObject(UserCreationDto.class)); + UserRequestDto creationDto = new UserRequestDto(); + creationDto.setName("user"); + creationDto.setEmail("user@user.com"); + + UserResponseDto responseDto = userService.create(creationDto); assertEquals(1, userService.findAll().size()); diff --git a/src/test/java/ru/practicum/shareit/user/UserServiceTest.java b/server/src/test/java/ru/practicum/shareit/user/UserServiceTest.java similarity index 96% rename from src/test/java/ru/practicum/shareit/user/UserServiceTest.java rename to server/src/test/java/ru/practicum/shareit/user/UserServiceTest.java index 8e949bd..3d44419 100644 --- a/src/test/java/ru/practicum/shareit/user/UserServiceTest.java +++ b/server/src/test/java/ru/practicum/shareit/user/UserServiceTest.java @@ -8,7 +8,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.dao.DataIntegrityViolationException; import ru.practicum.shareit.exception.exceptions.NotFoundException; -import ru.practicum.shareit.user.dto.UserCreationDto; import ru.practicum.shareit.user.dto.UserMapper; import ru.practicum.shareit.user.dto.UserRequestDto; import ru.practicum.shareit.user.dto.UserResponseDto; @@ -41,7 +40,7 @@ public void setUp() { @Test void testCreateUser() { - UserCreationDto userDto = new UserCreationDto(); + UserRequestDto userDto = new UserRequestDto(); userDto.setName("user"); userDto.setEmail("user@user.com"); @@ -55,7 +54,7 @@ void testCreateUser() { @Test void testCreateFailDuplicateEmail() { - UserCreationDto userDto = new UserCreationDto(); + UserRequestDto userDto = new UserRequestDto(); userDto.setName("user"); userDto.setEmail("user@user.com"); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 86b493a..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,20 +0,0 @@ -spring.jpa.hibernate.ddl-auto=none -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL10Dialect -spring.jpa.properties.hibernate.format_sql=true -spring.sql.init.mode=always - -logging.level.org.springframework.orm.jpa=INFO -logging.level.org.springframework.transaction=INFO -logging.level.org.springframework.transaction.interceptor=TRACE -logging.level.org.springframework.orm.jpa.JpaTransactionManager=DEBUG - -#spring.datasource.url=jdbc:postgresql://localhost:5432/shareIt -#spring.datasource.driverClassName=org.postgresql.Driver -#spring.datasource.username=root -#spring.datasource.password=root - -spring.config.activate.on-profile=ci,test -spring.datasource.driverClassName=org.h2.Driver -spring.datasource.url=jdbc:h2:mem:shareit -spring.datasource.username=test -spring.datasource.password=test From 2f5b45536f91e8a4f9b82e2b5e206ab56ddfee0f Mon Sep 17 00:00:00 2001 From: kpetrosyan1 Date: Sun, 7 Apr 2024 21:36:15 +0400 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=D0=BF=D1=80=D0=B5=D0=BE=D0=B1?= =?UTF-8?q?=D1=80=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D1=82=D0=B8?= =?UTF-8?q?=D0=BF=D0=BE=20long=20=D0=B2=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=BB=D0=BB=D0=B5=D1=80=D0=B0=D1=85=20gateway=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20=D0=BE=D0=B1=D0=B5?= =?UTF-8?q?=D1=80=D1=82=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shareit/booking/BookingController.java | 10 +++++----- .../ru/practicum/shareit/item/ItemController.java | 14 +++++++------- .../shareit/request/ItemRequestController.java | 8 ++++---- .../ru/practicum/shareit/user/UserController.java | 6 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/gateway/src/main/java/ru/practicum/shareit/booking/BookingController.java b/gateway/src/main/java/ru/practicum/shareit/booking/BookingController.java index cf28497..fadc181 100644 --- a/gateway/src/main/java/ru/practicum/shareit/booking/BookingController.java +++ b/gateway/src/main/java/ru/practicum/shareit/booking/BookingController.java @@ -25,7 +25,7 @@ public class BookingController { private final BookingClient bookingClient; @GetMapping - public ResponseEntity getBookings(@RequestHeader(USER_HEADER) long userId, + public ResponseEntity getBookings(@RequestHeader(USER_HEADER) Long userId, @RequestParam(name = "state", defaultValue = "all") String stateParam, @PositiveOrZero @RequestParam (name = "from", defaultValue = "0") Integer from, @Positive @RequestParam (name = "size", defaultValue = "10") Integer size) { @@ -36,21 +36,21 @@ public ResponseEntity getBookings(@RequestHeader(USER_HEADER) long userI } @PostMapping - public ResponseEntity bookItem(@RequestHeader(USER_HEADER) long userId, + public ResponseEntity bookItem(@RequestHeader(USER_HEADER) Long userId, @RequestBody @Valid BookItemRequestDto requestDto) { log.info("BOOKING_GATEWAY: Creating booking {}, userId={}", requestDto, userId); return bookingClient.bookItem(userId, requestDto); } @GetMapping("/{bookingId}") - public ResponseEntity getBooking(@RequestHeader(USER_HEADER) long userId, + public ResponseEntity getBooking(@RequestHeader(USER_HEADER) Long userId, @PathVariable Long bookingId) { log.info("BOOKING_GATEWAY: Get booking {}, userId={}", bookingId, userId); return bookingClient.getBooking(userId, bookingId); } @PatchMapping("/{bookingId}") - public ResponseEntity updateBooking(@RequestHeader(USER_HEADER) @Positive long userId, + public ResponseEntity updateBooking(@RequestHeader(USER_HEADER) @Positive Long userId, @PathVariable @Positive Long bookingId, @RequestParam Boolean approved) { log.info("BOOKING_GATEWAY: Update booking {}, userId={}", bookingId, userId); @@ -58,7 +58,7 @@ public ResponseEntity updateBooking(@RequestHeader(USER_HEADER) @Positiv } @GetMapping("/owner") - public ResponseEntity getOwnerBookings(@RequestHeader(USER_HEADER) long userId, + public ResponseEntity getOwnerBookings(@RequestHeader(USER_HEADER) Long userId, @RequestParam(name = "state", defaultValue = "all") String stateParam, @PositiveOrZero @RequestParam(name = "from", defaultValue = "0") Integer from, @Positive @RequestParam(name = "size", defaultValue = "10") Integer size) { diff --git a/gateway/src/main/java/ru/practicum/shareit/item/ItemController.java b/gateway/src/main/java/ru/practicum/shareit/item/ItemController.java index 0058839..74f1734 100644 --- a/gateway/src/main/java/ru/practicum/shareit/item/ItemController.java +++ b/gateway/src/main/java/ru/practicum/shareit/item/ItemController.java @@ -24,14 +24,14 @@ public class ItemController { private final ItemClient itemClient; @PostMapping - public ResponseEntity addItem(@RequestHeader(USER_HEADER) @Positive long userId, + public ResponseEntity addItem(@RequestHeader(USER_HEADER) @Positive Long userId, @RequestBody @Valid ItemRequestDto itemRequestDto) { log.info("ITEM_GATEWAY: add item {} from user userId={}", itemRequestDto, userId); return itemClient.addItem(userId, itemRequestDto); } @PostMapping("/{itemId}/comment") - public ResponseEntity commentItem(@RequestHeader(USER_HEADER) @Positive long userId, + public ResponseEntity commentItem(@RequestHeader(USER_HEADER) @Positive Long userId, @PathVariable @Positive Long itemId, @RequestBody @Valid CommentRequestDto commentRequestDto) { log.info("ITEM_GATEWAY: add comment {} to item itemId={} from user userId={}", commentRequestDto, itemId, userId); @@ -39,7 +39,7 @@ public ResponseEntity commentItem(@RequestHeader(USER_HEADER) @Positive } @PatchMapping("/{itemId}") - public ResponseEntity updateItem(@RequestHeader(USER_HEADER) @Positive long userId, + public ResponseEntity updateItem(@RequestHeader(USER_HEADER) @Positive Long userId, @PathVariable @Positive Long itemId, @RequestBody ItemRequestDto itemRequestDto) { log.info("ITEM_GATEWAY: update item itemId={} from user userId={} by dto {}", itemId, userId, itemRequestDto); @@ -47,14 +47,14 @@ public ResponseEntity updateItem(@RequestHeader(USER_HEADER) @Positive l } @GetMapping("/{itemId}") - public ResponseEntity getItem(@RequestHeader(USER_HEADER) @Positive long userId, + public ResponseEntity getItem(@RequestHeader(USER_HEADER) @Positive Long userId, @PathVariable @Positive Long itemId) { log.info("ITEM_GATEWAY: get item itemId={} request from user userId={}", itemId, userId); return itemClient.getItem(userId, itemId); } @GetMapping - public ResponseEntity getOwnerItems(@RequestHeader(USER_HEADER) @Positive long userId, + public ResponseEntity getOwnerItems(@RequestHeader(USER_HEADER) @Positive Long userId, @RequestParam(defaultValue = "0") @PositiveOrZero int from, @RequestParam(defaultValue = "10") @PositiveOrZero int size) { log.info("ITEM_GATEWAY: find owner ownerId={} items, page from={} size={}", userId, from, size); @@ -62,7 +62,7 @@ public ResponseEntity getOwnerItems(@RequestHeader(USER_HEADER) @Positiv } @GetMapping("/search") - public ResponseEntity search(@RequestHeader(USER_HEADER) @Positive long userId, + public ResponseEntity search(@RequestHeader(USER_HEADER) @Positive Long userId, @RequestParam String text, @RequestParam(defaultValue = "0") @PositiveOrZero int from, @RequestParam(defaultValue = "10") @PositiveOrZero int size) { @@ -71,7 +71,7 @@ public ResponseEntity search(@RequestHeader(USER_HEADER) @Positive long } @DeleteMapping("/{itemId}") - public ResponseEntity deleteItem(@RequestHeader(USER_HEADER) @Positive long userId, + public ResponseEntity deleteItem(@RequestHeader(USER_HEADER) @Positive Long userId, @PathVariable @Positive Long itemId) { log.info("ITEM_GATEWAY: delete item itemId={} request from user userId={}", itemId, userId); return itemClient.deleteItem(userId, itemId); diff --git a/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestController.java b/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestController.java index 4992ca1..a1b6f97 100644 --- a/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestController.java +++ b/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestController.java @@ -23,20 +23,20 @@ public class ItemRequestController { private final ItemRequestClient itemRequestClient; @PostMapping - public ResponseEntity addItemRequest(@RequestHeader(USER_HEADER) @Positive long userId, + public ResponseEntity addItemRequest(@RequestHeader(USER_HEADER) @Positive Long userId, @RequestBody @Valid ItemRequestRequestDto itemRequestRequestDto) { log.info("ITEM_REQUEST_GATEWAY: add itemRequest {} from user userId={}", itemRequestRequestDto, userId); return itemRequestClient.addItemRequest(userId, itemRequestRequestDto); } @GetMapping - public ResponseEntity getRequestsByAuthor(@RequestHeader(USER_HEADER) @Positive long userId) { + public ResponseEntity getRequestsByAuthor(@RequestHeader(USER_HEADER) @Positive Long userId) { log.info("ITEM_REQUEST_GATEWAY: get requests by authorId={}", userId); return itemRequestClient.getRequestsByAuthor(userId); } @GetMapping("/all") - public ResponseEntity getItemRequests(@RequestHeader(USER_HEADER) @Positive long userId, + public ResponseEntity getItemRequests(@RequestHeader(USER_HEADER) @Positive Long userId, @RequestParam(defaultValue = "0") @PositiveOrZero int from, @RequestParam(defaultValue = "10") @Positive int size) { log.info("ITEM_REQUEST_GATEWAY: get all requests from user userId={}, page from={}, size={}", userId, from, size); @@ -44,7 +44,7 @@ public ResponseEntity getItemRequests(@RequestHeader(USER_HEADER) @Posit } @GetMapping("/{requestId}") - public ResponseEntity getItemRequest(@RequestHeader(USER_HEADER) @Positive long userId, + public ResponseEntity getItemRequest(@RequestHeader(USER_HEADER) @Positive Long userId, @PathVariable @Positive Long requestId) { log.info("ITEM_REQUEST_GATEWAY: get itemRequest by id={} from user userId={}", requestId, userId); return itemRequestClient.getItemRequest(userId, requestId); diff --git a/gateway/src/main/java/ru/practicum/shareit/user/UserController.java b/gateway/src/main/java/ru/practicum/shareit/user/UserController.java index 5075013..3c8ea40 100644 --- a/gateway/src/main/java/ru/practicum/shareit/user/UserController.java +++ b/gateway/src/main/java/ru/practicum/shareit/user/UserController.java @@ -27,7 +27,7 @@ public ResponseEntity getUsers() { } @GetMapping("/{userId}") - public ResponseEntity getUser(@PathVariable @Positive long userId) { + public ResponseEntity getUser(@PathVariable @Positive Long userId) { log.info("USER_GATEWAY: Get user by userId={}", userId); return userClient.getUser(userId); } @@ -40,13 +40,13 @@ public ResponseEntity addUser(@RequestBody @Valid UserCreationDto userCr @PatchMapping("/{userId}") public ResponseEntity updateUser(@RequestBody @Valid UserRequestDto userRequestDto, - @PathVariable @Positive long userId) { + @PathVariable @Positive Long userId) { log.info("USER_GATEWAY: Update user userId={} by data {}", userId, userRequestDto); return userClient.updateUser(userRequestDto, userId); } @DeleteMapping("/{userId}") - public ResponseEntity deleteUser(@PathVariable @Positive long userId) { + public ResponseEntity deleteUser(@PathVariable @Positive Long userId) { log.info("USER_GATEWAY: delete user userId={}", userId); return userClient.deleteUser(userId); }