generated from yandex-praktikum/java-shareit
-
Notifications
You must be signed in to change notification settings - Fork 0
Add docker #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
Open
boltaevt
wants to merge
7
commits into
main
Choose a base branch
from
add-docker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add docker #5
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e0a40e2
sprint 16 implemented
boltaevt 6753771
changes
boltaevt 6d362cb
changed gitIgnore file
boltaevt 6028f31
changes to gitIgnore file
boltaevt da0fc14
again
boltaevt fb4253b
again
boltaevt ce85218
Remove all .DS_Store files
boltaevt 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 |
|---|---|---|
|
|
@@ -31,3 +31,9 @@ build/ | |
|
|
||
| ### VS Code ### | ||
| .vscode/ | ||
|
|
||
| *.DS_Store | ||
|
|
||
| *.class | ||
| *.jar | ||
| .DS_Store | ||
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,45 @@ | ||
| version: '3.8' | ||
| services: | ||
| gateway: | ||
| build: | ||
| context: . | ||
| dockerfile: gateway/Dockerfile | ||
| image: shared-gateway | ||
| container_name: shareit-gateway | ||
| ports: | ||
| - "8080:8080" | ||
| depends_on: | ||
| - server | ||
| environment: | ||
| - SHAREIT_SERVER_URL=http://server:9090 | ||
|
|
||
| server: | ||
| build: | ||
| context: . | ||
| dockerfile: server/Dockerfile | ||
| image: shared-server | ||
| container_name: shareit-server | ||
| expose: | ||
| - 9090 | ||
| ports: | ||
| - "9090:9090" | ||
| depends_on: | ||
| - db | ||
| environment: | ||
| - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/shareit | ||
| - SPRING_DATASOURCE_USERNAME=root | ||
| - SPRING_DATASOURCE_PASSWORD=root | ||
| - SPRING_JPA_HIBERNATE_DDL_AUTO=update | ||
| command: -p 9090 | ||
|
|
||
| db: | ||
| image: postgres:13.7-alpine | ||
| container_name: database | ||
| ports: | ||
| - "6541:5432" | ||
| volumes: | ||
| - ./server/resources:/schema.sql | ||
| environment: | ||
| - POSTGRES_PASSWORD=root | ||
| - POSTGRES_USER=root | ||
| - POSTGRES_DB=shareit | ||
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,3 @@ | ||
| FROM amazoncorretto:11 | ||
| COPY gateway/target/*.jar app.jar | ||
| ENTRYPOINT ["java","-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,71 @@ | ||
| <?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 https://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> | ||
|
|
||
| <properties> | ||
| <maven.compiler.source>11</maven.compiler.source> | ||
| <maven.compiler.target>11</maven.compiler.target> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| </properties> | ||
|
|
||
| <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.apache.httpcomponents</groupId> | ||
| <artifactId>httpclient</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> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-maven-plugin</artifactId> | ||
| </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); | ||
| } | ||
|
|
||
| } |
66 changes: 66 additions & 0 deletions
66
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,66 @@ | ||
| 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.bind.annotation.*; | ||
| import org.springframework.web.util.DefaultUriBuilderFactory; | ||
| import ru.practicum.shareit.booking.dto.BookingShortDto; | ||
| 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<Object> createBooking(BookingShortDto bookingShortDto, Long userId) { | ||
| return post("", userId, bookingShortDto); | ||
| } | ||
|
|
||
| public ResponseEntity<Object> approveBooking(Long bookingId, Boolean approved, Long userId) { | ||
| Map<String, Object> parameters = Map.of( | ||
| "approved", approved.toString() | ||
| ); | ||
| return patch("/" + bookingId + "?approved={approved}", userId, parameters, null); | ||
| } | ||
|
|
||
| public ResponseEntity<Object> getBooking(Long bookingId, Long userId) { | ||
| return get("/" + bookingId, userId); | ||
| } | ||
|
|
||
| @GetMapping | ||
| public ResponseEntity<Object> getAllBookings(Long userId, BookingState state, Long from, Long size) { | ||
| Map<String, Object> parameters = Map.of( | ||
| "state", state, | ||
| "from", from, | ||
| "size", size | ||
| ); | ||
| return get("?state={state}&from={from}&size={size}", userId, parameters); | ||
| } | ||
|
|
||
| @GetMapping("/owner") | ||
| public ResponseEntity<Object> getOwnerBookings(Long userId, BookingState state, Long from, Long size) { | ||
|
|
||
| Map<String, Object> parameters = Map.of( | ||
| "state", state, | ||
| "from", from, | ||
| "size", size | ||
| ); | ||
| return get("/owner?state={state}&from={from}&size={size}", userId, parameters); | ||
| } | ||
| } |
68 changes: 68 additions & 0 deletions
68
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,68 @@ | ||
| package ru.practicum.shareit.booking; | ||
|
|
||
| import lombok.SneakyThrows; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.core.MethodParameter; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.validation.BeanPropertyBindingResult; | ||
| import org.springframework.validation.annotation.Validated; | ||
| import org.springframework.web.bind.MethodArgumentNotValidException; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import ru.practicum.shareit.booking.dto.BookingShortDto; | ||
| import ru.practicum.shareit.booking.dto.BookingState; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/bookings") | ||
| @Validated | ||
| @Slf4j | ||
| public class BookingController { | ||
| private final BookingClient bookingClient; | ||
|
|
||
| @Autowired | ||
| public BookingController(BookingClient bookingClient) { | ||
| this.bookingClient = bookingClient; | ||
| } | ||
|
|
||
| @SneakyThrows | ||
| @PostMapping | ||
| public ResponseEntity<Object> createBooking(@Validated @RequestBody BookingShortDto bookingShortDto, | ||
| @RequestHeader("X-Sharer-User-Id") Long userId) { | ||
| if (bookingShortDto.getStart().equals(bookingShortDto.getEnd()) | ||
| || bookingShortDto.getStart().isAfter(bookingShortDto.getEnd())) { | ||
| throw new MethodArgumentNotValidException(new MethodParameter( | ||
| this.getClass().getDeclaredMethod("createBooking", BookingShortDto.class, Long.class), 0), new BeanPropertyBindingResult(bookingShortDto, "bookingShortDto")); | ||
| } | ||
|
|
||
| return bookingClient.createBooking(bookingShortDto, userId); | ||
| } | ||
|
|
||
| @PatchMapping("/{bookingId}") | ||
| public ResponseEntity<Object> approveBooking(@PathVariable Long bookingId, | ||
| @RequestParam(name = "approved") Boolean approved, | ||
| @RequestHeader("X-Sharer-User-Id") Long userId) { | ||
| return bookingClient.approveBooking(bookingId, approved, userId); | ||
| } | ||
|
|
||
| @GetMapping("/{bookingId}") | ||
| public ResponseEntity<Object> getBooking(@PathVariable Long bookingId, | ||
| @RequestHeader("X-Sharer-User-Id") Long userId) { | ||
| return bookingClient.getBooking(bookingId, userId); | ||
| } | ||
|
|
||
| @GetMapping | ||
| public ResponseEntity<Object> getAllBookings(@RequestHeader("X-Sharer-User-Id") Long userId, | ||
| @RequestParam(name = "state", defaultValue = "ALL") BookingState state, | ||
| @RequestParam(name = "from", defaultValue = "0") Long from, | ||
| @RequestParam(name = "size", defaultValue = "20") Long size) { | ||
| return bookingClient.getAllBookings(userId, state, from, size); | ||
| } | ||
|
|
||
| @GetMapping("/owner") | ||
| public ResponseEntity<Object> getOwnerBookings(@RequestHeader("X-Sharer-User-Id") Long userId, | ||
| @RequestParam(name = "state", defaultValue = "ALL") BookingState state, | ||
| @RequestParam(name = "from", defaultValue = "0") Long from, | ||
| @RequestParam(name = "size", defaultValue = "20") Long size) { | ||
| return bookingClient.getOwnerBookings(userId, state, from, size); | ||
| } | ||
| } |
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
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
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,10 @@ | ||
| package ru.practicum.shareit.booking.dto; | ||
|
|
||
| public enum BookingState { | ||
| CURRENT, | ||
| PAST, | ||
| FUTURE, | ||
| ALL, | ||
| REJECTED, | ||
| WAITING | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Здорово выполнили с docker-compose, но название сервиса базы я бы переименовал в postgres, т.к. у вас может быть ещё один сервис базы mongo и так далее