-
Notifications
You must be signed in to change notification settings - Fork 0
Add item requests and gateway #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
59fbc2d
Финальное задание 15го (доработано согласно замечаниям)
NadezhdaTA 87593ca
Финальное задание 15го (доработано согласно замечаниям)
NadezhdaTA dc5746d
Merge remote-tracking branch 'origin/main'
NadezhdaTA 0fbe381
Финальное задание 16го спринта (этап 1)
NadezhdaTA 6125b6b
Финальное задание 16го спринта (этап 1)
NadezhdaTA 3869933
Финальное задание 16го спринта (с тестами)
NadezhdaTA 9a54e31
Merge remote-tracking branch 'origin/add-item-requests-and-gateway' i…
NadezhdaTA 516a69a
Финальное задание 16го спринта (с тестами)
NadezhdaTA 85ce530
Финальное задание 16го спринта (с тестами)
NadezhdaTA 8f7b3ba
Финальное задание 16го спринта (с тестами)
NadezhdaTA 2560fa6
Финальное задание 16го спринта (с тестами)
NadezhdaTA 6c8c8ef
Финальное задание 16го спринта (с тестами)
NadezhdaTA aa13df1
Финальное задание 16го спринта с исправлениями
NadezhdaTA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <component name="ProjectRunConfigurationManager"> | ||
| <configuration default="false" name="ru.practicum.shareit.ShareItGateway" type="Application" factoryName="Application" nameIsGenerated="true"> | ||
| <option name="MAIN_CLASS_NAME" value="ru.practicum.shareit.ru.practicum.shareit.ShareItGateway" /> | ||
| <module name="shareit-gateway" /> | ||
| <extension name="coverage"> | ||
| <pattern> | ||
| <option name="PATTERN" value="ru.practicum.shareit.*" /> | ||
| <option name="ENABLED" value="true" /> | ||
| </pattern> | ||
| </extension> | ||
| <method v="2"> | ||
| <option name="Make" enabled="true" /> | ||
| </method> | ||
| </configuration> | ||
| </component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <component name="ProjectRunConfigurationManager"> | ||
| <configuration default="false" name="ShareItServer" type="Application" factoryName="Application" nameIsGenerated="true"> | ||
| <option name="MAIN_CLASS_NAME" value="ru.practicum.shareit.ShareItServer" /> | ||
| <module name="shareit-server" /> | ||
| <extension name="coverage"> | ||
| <pattern> | ||
| <option name="PATTERN" value="ru.practicum.shareit.*" /> | ||
| <option name="ENABLED" value="true" /> | ||
| </pattern> | ||
| </extension> | ||
| <method v="2"> | ||
| <option name="Make" enabled="true" /> | ||
| </method> | ||
| </configuration> | ||
| </component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| services: | ||
| gateway: | ||
| build: gateway | ||
| image: shareit-gateway | ||
| container_name: shareit-gateway | ||
| ports: | ||
| - "8080:8080" | ||
| depends_on: | ||
| - server | ||
| environment: | ||
| - SHAREIT_SERVER_URL=http://server:9090 | ||
|
|
||
| server: | ||
| build: server | ||
| image: shareit-server | ||
| container_name: shareit-server | ||
| ports: | ||
| - "9090:9090" | ||
| depends_on: | ||
| - db | ||
| environment: | ||
| - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/postgres | ||
| - SPRING_DATASOURCE_USERNAME=user | ||
| - SPRING_DATASOURCE_PASSWORD=12345 | ||
|
|
||
| db: | ||
| image: postgres:16.1 | ||
| container_name: postgres | ||
| ports: | ||
| - "6541:5432" | ||
| environment: | ||
| - POSTGRES_PASSWORD=12345 | ||
| - POSTGRES_USER=user | ||
| - POSTGRES_DB=shareit | ||
| healthcheck: | ||
| test: pg_isready -q -d $$POSTGRES_DB -U $$POSTGRES_USER | ||
| timeout: 5s | ||
| interval: 5s | ||
| retries: 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| FROM eclipse-temurin:21-jre-jammy | ||
| VOLUME /tmp | ||
| ARG JAR_FILE=target/*.jar | ||
| COPY ${JAR_FILE} app.jar | ||
| ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /app.jar"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>ru.practicum</groupId> | ||
| <artifactId>shareit</artifactId> | ||
| <version>0.0.1-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>shareit-gateway</artifactId> | ||
| <version>0.0.1-SNAPSHOT</version> | ||
|
|
||
| <name>ShareIt Gateway</name> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-web</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-validation</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-actuator</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.hibernate.validator</groupId> | ||
| <artifactId>hibernate-validator</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.apache.httpcomponents.client5</groupId> | ||
| <artifactId>httpclient5</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-configuration-processor</artifactId> | ||
| <optional>true</optional> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| <optional>true</optional> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-test</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>ru.practicum</groupId> | ||
| <artifactId>shareit-server</artifactId> | ||
| <version>0.0.1-SNAPSHOT</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-maven-plugin</artifactId> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <configuration> | ||
| <annotationProcessorPaths> | ||
| <path> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| <version>1.18.38</version> | ||
| </path> | ||
| </annotationProcessorPaths> | ||
| </configuration> | ||
| </plugin> | ||
|
|
||
| </plugins> | ||
|
|
||
| </build> | ||
|
|
||
| </project> |
12 changes: 12 additions & 0 deletions
12
gateway/src/main/java/ru/practicum/shareit/ShareItGateway.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
|
|
||
| } |
57 changes: 57 additions & 0 deletions
57
gateway/src/main/java/ru/practicum/shareit/booking/BookingClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package ru.practicum.shareit.booking; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| 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.BookingRequestDto; | ||
| import ru.practicum.shareit.booking.dto.BookingState; | ||
| import ru.practicum.shareit.client.BaseClient; | ||
|
|
||
| @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(() -> new HttpComponentsClientHttpRequestFactory()) | ||
| .build() | ||
| ); | ||
| } | ||
|
|
||
| public ResponseEntity<Object> addBooking(Long userId, BookingRequestDto requestDto) { | ||
| return post("", userId, requestDto); | ||
| } | ||
|
|
||
| public ResponseEntity<Object> getBooking(Long bookingId, Long userId) { | ||
| return get("/" + bookingId, userId); | ||
| } | ||
|
|
||
| public ResponseEntity<Object> bookingApprove(long bookingId, long userId, boolean approved) { | ||
|
|
||
| return patch("/" + bookingId + "?approved=" + approved, userId); | ||
| } | ||
|
|
||
| public ResponseEntity<Object> getBookingsByUser(Long userId, String state) { | ||
| Map<String, Object> parameters = Map.of( | ||
| "state", state | ||
| ); | ||
| return get("", userId, parameters); | ||
| } | ||
|
|
||
| public ResponseEntity<Object> getBookingsByOwner(Long userId, BookingState state) { | ||
| Map<String, Object> parameters = Map.of( | ||
| "state", state | ||
| ); | ||
| return get("/owner", userId, parameters); | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
gateway/src/main/java/ru/practicum/shareit/booking/BookingController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package ru.practicum.shareit.booking; | ||
|
|
||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import ru.practicum.shareit.booking.dto.BookingRequestDto; | ||
| import ru.practicum.shareit.booking.dto.BookingState; | ||
|
|
||
| @RestController | ||
| @RequestMapping(path = "/bookings") | ||
| @RequiredArgsConstructor | ||
| public class BookingController { | ||
| private final BookingClient bookingService; | ||
| public static final String USER_ID = "X-Sharer-User-Id"; | ||
|
|
||
| @PostMapping | ||
| public ResponseEntity<Object> addBooking(@RequestBody @Valid BookingRequestDto booking, | ||
| @RequestHeader(USER_ID) Long bookerId) { | ||
| return bookingService.addBooking(bookerId, booking); | ||
| } | ||
|
|
||
| @PatchMapping("/{bookingId}") | ||
| public ResponseEntity<Object> bookingApprove(@PathVariable Long bookingId, | ||
| @RequestHeader (USER_ID) Long ownerId, | ||
| @RequestParam Boolean approved) { | ||
| return bookingService.bookingApprove(bookingId, ownerId, approved); | ||
| } | ||
|
|
||
| @GetMapping("/{bookingId}") | ||
| public ResponseEntity<Object> getBooking(@PathVariable Long bookingId, | ||
| @RequestHeader(USER_ID) Long userId) { | ||
| return bookingService.getBooking(bookingId, userId); | ||
| } | ||
|
|
||
| @GetMapping | ||
| public ResponseEntity<Object> getBookingsByUser(@RequestHeader (USER_ID) Long userId, | ||
| @RequestParam(name = "state", defaultValue = "all") String state) { | ||
| return bookingService.getBookingsByUser(userId, state); | ||
| } | ||
|
|
||
| @GetMapping("/owner") | ||
| public ResponseEntity<Object> getBookingsByOwner(@RequestHeader (USER_ID) Long userId, | ||
| @RequestParam(name = "state", defaultValue = "all") BookingState state) { | ||
| return bookingService.getBookingsByOwner(userId, state); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
gateway/src/main/java/ru/practicum/shareit/booking/dto/BookingResponseDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package ru.practicum.shareit.booking.dto; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
| import ru.practicum.shareit.item.dto.ItemBookerDto; | ||
| import ru.practicum.shareit.user.dto.UserBookingDto; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Data | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| public class BookingResponseDto { | ||
|
|
||
| @JsonProperty("id") | ||
| private Long bookingId; | ||
|
|
||
| private LocalDateTime start; | ||
|
|
||
| private LocalDateTime end; | ||
|
|
||
| private ItemBookerDto item; | ||
|
|
||
| private UserBookingDto booker; | ||
|
|
||
| private BookingState status; | ||
|
|
||
| } |
36 changes: 36 additions & 0 deletions
36
gateway/src/main/java/ru/practicum/shareit/booking/dto/BookingState.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package ru.practicum.shareit.booking.dto; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| @Getter | ||
| public enum BookingState { | ||
| // Все | ||
| ALL("ALL"), | ||
| // Текущие | ||
| CURRENT("CURRENT"), | ||
| // Будущие | ||
| FUTURE("FUTURE"), | ||
| // Завершенные | ||
| PAST("PAST"), | ||
| // Отклоненные | ||
| REJECTED("REJECTED"), | ||
| // Ожидающие подтверждения | ||
| WAITING("WAITING"),; | ||
|
|
||
| private final String value; | ||
|
|
||
| BookingState(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public static Optional<BookingState> from(String stringState) { | ||
| for (BookingState state : values()) { | ||
| if (state.name().equalsIgnoreCase(stringState)) { | ||
| return Optional.of(state); | ||
| } | ||
| } | ||
| return Optional.empty(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.