generated from yandex-praktikum/java-shareit
-
Notifications
You must be signed in to change notification settings - Fork 0
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
refactor: docker-compose.yml #56
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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,33 @@ | ||
version: '3.8' | ||
services: | ||
gateway: | ||
build: ./gateway | ||
container_name: gateway_container | ||
ports: | ||
- "8080:8080" | ||
depends_on: | ||
- server | ||
environment: | ||
- SHAREIT_SERVER_URL=http://server:9090 | ||
|
||
server: | ||
build: ./server | ||
container_name: server_container | ||
ports: | ||
- "9090:9090" | ||
depends_on: | ||
- db | ||
environment: | ||
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/shareit | ||
|
||
db: | ||
image: postgres:13.7-alpine | ||
container_name: data_base | ||
ports: | ||
- "6541:5432" | ||
environment: | ||
- POSTGRES_DB=shareit | ||
- POSTGRES_USER=andersen | ||
- POSTGRES_PASSWORD=andersen | ||
- DB_HOST=db | ||
- DB_PORT=5432 |
This file contains 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 target/*.jar app.jar | ||
ENTRYPOINT ["java","-jar","/app.jar"] |
This file contains 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,65 @@ | ||
<?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> | ||
|
||
<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> |
11 changes: 11 additions & 0 deletions
11
gateway/src/main/java/ru/practicum/shareit/ShareitGateway.java
This file contains 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,11 @@ | ||
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); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
gateway/src/main/java/ru/practicum/shareit/booking/BookingClient.java
This file contains 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,61 @@ | ||
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<Object> postBooking(long userId, BookItemRequestDto bookItemRequestDto) { | ||
return post("", userId, bookItemRequestDto); | ||
} | ||
|
||
public ResponseEntity<Object> confirmationOrRejectionBooking(long bookingId, long userId, String bookingStatus) { | ||
Map<String, Object> parameters = Map.of( | ||
"approved", bookingStatus); | ||
|
||
return patch("/" + bookingId + "?approved={approved}", userId, parameters); | ||
} | ||
|
||
public ResponseEntity<Object> getBookingById(long userId, long bookingId) { | ||
return get("/" + bookingId, userId); | ||
} | ||
|
||
public ResponseEntity<Object> getAllBookingCurrentUser(long userId, BookingState state, Integer from, Integer size) { | ||
Map<String, Object> parameters = Map.of( | ||
"state", state.name(), | ||
"from", from, | ||
"size", size | ||
); | ||
return get("?state={state}&from={from}&size={size}", userId, parameters); | ||
} | ||
|
||
public ResponseEntity<Object> getAllBookingCurrentOwner(long userId, BookingState state, Integer from, Integer size) { | ||
Map<String, Object> parameters = Map.of( | ||
"state", state.name(), | ||
"from", from, | ||
"size", size); | ||
return get("/owner?state={state}&from={from}&size={size}", userId, parameters); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
gateway/src/main/java/ru/practicum/shareit/booking/BookingController.java
This file contains 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,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 ru.practicum.shareit.exception.UnavailableStateException; | ||
|
||
import javax.validation.constraints.Positive; | ||
import javax.validation.constraints.PositiveOrZero; | ||
|
||
@Controller | ||
@RequestMapping(path = "/bookings") | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@Validated | ||
public class BookingController { | ||
private final BookingClient bookingClient; | ||
|
||
@PostMapping | ||
public ResponseEntity<Object> postBooking(@RequestBody BookItemRequestDto bookItemRequestDto, | ||
@RequestHeader("X-Sharer-User-Id") int userId) { | ||
return bookingClient.postBooking(userId, bookItemRequestDto); | ||
} | ||
|
||
@PatchMapping("/{bookingId}") | ||
public ResponseEntity<Object> confirmationOrRejectionBooking(@PathVariable int bookingId, | ||
@RequestHeader("X-Sharer-User-Id") int userId, | ||
@RequestParam(name = "approved") | ||
String bookingStatus) { | ||
|
||
return bookingClient.confirmationOrRejectionBooking(bookingId, userId, bookingStatus); | ||
} | ||
|
||
@GetMapping("/{bookingId}") | ||
public ResponseEntity<Object> getBookingById(@RequestHeader("X-Sharer-User-Id") int userId, | ||
@PathVariable int bookingId) { | ||
return bookingClient.getBookingById(userId, bookingId); | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<Object> getAllBookingCurrentUser(@RequestHeader("X-Sharer-User-Id") 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 UnavailableStateException("Unknown state: UNSUPPORTED_STATUS")); | ||
log.info("Get booking with state {}, userId={}, from={}, size={}", stateParam, userId, from, size); | ||
return bookingClient.getAllBookingCurrentUser(userId, state, from, size); | ||
} | ||
|
||
@GetMapping("/owner") | ||
public ResponseEntity<Object> getAllBookingCurrentOwner(@RequestHeader("X-Sharer-User-Id") 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 UnavailableStateException("Unknown state: UNSUPPORTED_STATUS")); | ||
return bookingClient.getAllBookingCurrentOwner(userId, state, from, size); | ||
} | ||
} |
File renamed without changes.
28 changes: 28 additions & 0 deletions
28
gateway/src/main/java/ru/practicum/shareit/booking/dto/BookItemRequestDto.java
This file contains 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,28 @@ | ||
package ru.practicum.shareit.booking.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import ru.practicum.shareit.booking.BookingStatus; | ||
import ru.practicum.shareit.item.dto.ItemRequestDto; | ||
import ru.practicum.shareit.user.dto.UserRequestDto; | ||
|
||
import javax.validation.constraints.Future; | ||
import javax.validation.constraints.FutureOrPresent; | ||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class BookItemRequestDto { | ||
private int id; | ||
private long itemId; | ||
@FutureOrPresent | ||
private LocalDateTime start; | ||
@Future | ||
private LocalDateTime end; | ||
private UserRequestDto booker; | ||
private ItemRequestDto item; | ||
private BookingStatus status; | ||
int bookerId; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. private |
||
} |
21 changes: 21 additions & 0 deletions
21
gateway/src/main/java/ru/practicum/shareit/booking/dto/BookingState.java
This file contains 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,21 @@ | ||
package ru.practicum.shareit.booking.dto; | ||
|
||
import java.util.Optional; | ||
|
||
public enum BookingState { | ||
ALL, | ||
CURRENT, | ||
FUTURE, | ||
PAST, | ||
REJECTED, | ||
WAITING; | ||
|
||
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.
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 и так далее