Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
eb9d302
Initial commit
Slavakorgg May 24, 2025
d159e3a
Первая реализация тз 14ого спринта.
slavakorg May 29, 2025
0f29b95
test fix
slavakorg May 29, 2025
7fb13ac
Вторая реализация тз 14ого спринта.
slavakorg May 29, 2025
db85e7b
fix tests
slavakorg May 29, 2025
e1d0985
исправление названия метода getUser
slavakorg May 30, 2025
5f03df9
Первая реализация тз 15ого спринта.
slavakorg Jun 16, 2025
f066e62
test fix
slavakorg Jun 16, 2025
6f2b2e7
test fix
slavakorg Jun 16, 2025
b650960
test fix
slavakorg Jun 16, 2025
2f65090
Вторая реализация тз 15ого спринта
slavakorg Jun 16, 2025
1b8299c
fix tests
slavakorg Jun 16, 2025
06b4e26
Первая реализация тз 16ого спринта (без тестов).
slavakorg Jul 1, 2025
9ec298e
Первая реализация тз 16ого спринта (без тестов).
slavakorg Jul 1, 2025
3760f4a
test fix
slavakorg Jul 1, 2025
26675c0
test fix
slavakorg Jul 1, 2025
572b45a
test fix
slavakorg Jul 1, 2025
4162502
test fix
slavakorg Jul 1, 2025
21fb8df
Реализация тз 16 спринта
slavakorg Jul 1, 2025
9b55131
Реализация тз 16 спринта
slavakorg Jul 1, 2025
131a8e6
Trigger rebuild after cleanup
slavakorg Jul 1, 2025
50307ba
Реализация тз 16 спринта
slavakorg Jul 1, 2025
5025cc5
Реализация тз 16 спринта
slavakorg Jul 1, 2025
18cc06d
Merge branch 'add-item-requests-and-gateway' of github.com:Slavakorgg…
slavakorg Jul 1, 2025
ccc7c2a
Реализация тз 16 спринта
slavakorg Jul 1, 2025
516019d
Реализация тз 16 спринта
slavakorg Jul 1, 2025
91905c7
fix test
slavakorg Jul 1, 2025
fd52f46
fix test
slavakorg Jul 1, 2025
f0e59c1
fix test
slavakorg Jul 1, 2025
b817d83
fix test
slavakorg Jul 1, 2025
ae1f5ce
fix test
slavakorg Jul 1, 2025
0b7d594
fix test
slavakorg Jul 1, 2025
1b8e0bf
fix test
slavakorg Jul 1, 2025
6e32280
fix test
slavakorg Jul 1, 2025
af5ce70
fix test
slavakorg Jul 1, 2025
dca923a
fix test
slavakorg Jul 1, 2025
23d80e5
fix test
slavakorg Jul 1, 2025
6f0db52
fix test
slavakorg Jul 1, 2025
ca77afe
fix test
slavakorg Jul 1, 2025
8f21fd7
fix test
slavakorg Jul 1, 2025
9f73d06
fix test
slavakorg Jul 1, 2025
7b8fa91
fix test
slavakorg Jul 1, 2025
54568f6
fix test
slavakorg Jul 1, 2025
ea02fc7
fix test
slavakorg Jul 1, 2025
435e606
fix test
slavakorg Jul 1, 2025
4d077d8
fix test
slavakorg Jul 1, 2025
f99cacb
fix test
slavakorg Jul 1, 2025
c3edd96
fix test
slavakorg Jul 1, 2025
1641438
fix test
slavakorg Jul 1, 2025
87320ba
fix test
slavakorg Jul 1, 2025
38ba2b2
fix test
slavakorg Jul 2, 2025
7cb741d
fix test
slavakorg Jul 2, 2025
1a1c27d
fix test
slavakorg Jul 2, 2025
35c3f48
fix test
slavakorg Jul 2, 2025
024abab
fix test
slavakorg Jul 2, 2025
68451ab
Вторая реализация тз 16ого спринта. Добавление конфигураций клиентам
slavakorg Jul 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
/target/


### STS ###
.apt_generated
Expand All @@ -18,6 +20,7 @@ target/
*.iws
*.iml
*.ipr
*.class

### NetBeans ###
/nbproject/private/
Expand Down
15 changes: 15 additions & 0 deletions .run/ShareItGateway.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="ShareItGateway" type="Application" factoryName="Application" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="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>
15 changes: 15 additions & 0 deletions .run/ShareItServer.run.xml
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>
39 changes: 39 additions & 0 deletions docker-compose.yml
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/shareit
- SPRING_DATASOURCE_USERNAME=shareit
- SPRING_DATASOURCE_PASSWORD=shareit

db:
image: postgres:16.1
container_name: postgres
ports:
- "6541:5432"
environment:
- POSTGRES_PASSWORD=shareit
- POSTGRES_USER=shareit
- POSTGRES_DB=shareit
healthcheck:
test: pg_isready -q -d $$POSTGRES_DB -U $$POSTGRES_USER
timeout: 5s
interval: 5s
retries: 10
5 changes: 5 additions & 0 deletions gateway/Dockerfile
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"]
70 changes: 70 additions & 0 deletions gateway/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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.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>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.practicum.shareit.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);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ru.practicum.shareit.practicum.shareit.booking;


import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import ru.practicum.shareit.practicum.shareit.booking.dto.BookItemRequestDto;
import ru.practicum.shareit.practicum.shareit.booking.dto.BookingState;
import ru.practicum.shareit.practicum.shareit.booking.dto.NewBookingDto;
import ru.practicum.shareit.practicum.shareit.client.BaseClient;

import java.util.Map;


public class BookingClient extends BaseClient {

public BookingClient(RestTemplate restTemplate) {
super(restTemplate);
}

public ResponseEntity<Object> getBookings(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> bookItem(long userId, BookItemRequestDto requestDto) {
return post("", userId, requestDto);
}

public ResponseEntity<Object> getBooking(long userId, Long bookingId) {
return get("/" + bookingId, userId);
}

public ResponseEntity<Object> create(NewBookingDto newBookingDto, long userId) {
return post("", userId, newBookingDto);
}


public ResponseEntity<Object> approveBooking(long userId, long bookingId, boolean approved) {
Map<String, Object> uriVariables = Map.of("bookingId", bookingId, "approved", approved);
return patch("/" + bookingId + "?approved=" + approved, userId, approved);
}

public ResponseEntity<Object> findById(long userId, long bookingId) {
return get("/" + bookingId, userId);
}

public ResponseEntity<Object> findByBooker(long userId, BookingState state) {
Map<String, Object> parameters = Map.of(
"state", state.name()
);
return get("?state={state}", userId, parameters);
}

public ResponseEntity<Object> findByOwner(long userId, BookingState state) {
Map<String, Object> parameters = Map.of(
"state", state.name()
);
return get("/owner", userId, parameters);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ru.practicum.shareit.practicum.shareit.booking;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriBuilderFactory;

@Configuration
public class BookingClientConfig {
@Value("${shareit-server.url}")
private String serverUrl;

@Bean
public RestTemplate bookingRestTemplate(RestTemplateBuilder builder) {
return builder
.uriTemplateHandler(new DefaultUriBuilderFactory(serverUrl + "/bookings"))
.requestFactory(() -> new HttpComponentsClientHttpRequestFactory())
.build();
}

@Bean
public BookingClient bookingClient(RestTemplate bookingRestTemplate) {
return new BookingClient(bookingRestTemplate);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package ru.practicum.shareit.practicum.shareit.booking;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import ru.practicum.shareit.practicum.shareit.booking.dto.BookingState;
import ru.practicum.shareit.practicum.shareit.booking.dto.NewBookingDto;


/**
* TODO Sprint add-bookings.
*/
@RestController
@RequestMapping(path = "/bookings")
@RequiredArgsConstructor
@Validated
public class BookingController {
private final BookingClient bookingClient;

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public ResponseEntity<Object> create(@RequestBody @Valid NewBookingDto newBookingDto, @RequestHeader("X-Sharer-User-Id") @NotNull long userId) {
return bookingClient.create(newBookingDto, userId);
}

@PatchMapping("/{bookingId}")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<Object> approveBooking(@RequestHeader("X-Sharer-User-Id") long userId, @PathVariable Long bookingId, @RequestParam Boolean approved) {
return bookingClient.approveBooking(userId, bookingId, approved);
}

@GetMapping
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<Object> findByBooker(@RequestHeader("X-Sharer-User-Id") @NotNull long userId,
@RequestParam(defaultValue = "ALL") BookingState state) {
return bookingClient.findByBooker(userId, state);
}

@GetMapping("/owner")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<Object> findByOwner(@RequestHeader("X-Sharer-User-Id") @NotNull long userId,
@RequestParam(defaultValue = "ALL") BookingState state) {
return bookingClient.findByOwner(userId, state);
}

@GetMapping("/{bookingId}")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<Object> findById(@RequestHeader("X-Sharer-User-Id") @NotNull long userId, @PathVariable @NotNull long bookingId) {
return bookingClient.findById(userId, bookingId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ru.practicum.shareit.practicum.shareit.booking;

public enum BookingStatus {
WAITING, APPROVED, REJECTED, CANCELED
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ru.practicum.shareit.practicum.shareit.booking.dto;

import jakarta.validation.constraints.Future;
import jakarta.validation.constraints.FutureOrPresent;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class BookItemRequestDto {
private long itemId;
@FutureOrPresent
private LocalDateTime start;
@Future
private LocalDateTime end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ru.practicum.shareit.practicum.shareit.booking.dto;

import lombok.Builder;
import lombok.Data;
import ru.practicum.shareit.practicum.shareit.booking.BookingStatus;
import ru.practicum.shareit.practicum.shareit.item.dto.ItemDto;
import ru.practicum.shareit.practicum.shareit.user.dto.UserDto;

import java.time.LocalDateTime;

/**
* TODO Sprint add-bookings.
*/
@Data
@Builder
public class BookingDto {
private Long id;
private LocalDateTime start;
private LocalDateTime end;
private ItemDto item;
private UserDto booker;
private BookingStatus status;
}
Loading