Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9060d32
Сделан GET endpoint для ItemRequests
zephyr0021 Jun 26, 2025
a73e088
Сделан POST эндпоинт создания ItemRequest
zephyr0021 Jun 27, 2025
ac96996
Добавил в items опцию ответа на запрос
zephyr0021 Jun 27, 2025
203fcb5
Перенес архитектуру в многомодульный проект
zephyr0021 Jun 30, 2025
17dafe2
Поправил ошибку
zephyr0021 Jul 1, 2025
aff6f2d
Настроил клиент для User
zephyr0021 Jul 1, 2025
619dfd5
Доделал модуль gateway полностью
zephyr0021 Jul 3, 2025
e167cf2
fix checkstyle
zephyr0021 Jul 3, 2025
b2fa391
подготовка тестов контроллеров gateway
zephyr0021 Jul 4, 2025
33b4bdb
написаны тесты для usercontroller
zephyr0021 Jul 7, 2025
1c06de5
Написаны тесты для gateway: user, item, booking
zephyr0021 Jul 7, 2025
98bce08
Написаны все тесты для gateway
zephyr0021 Jul 7, 2025
32788aa
Покрытие тестов > 90%
zephyr0021 Jul 7, 2025
306119e
checkstyle fix
zephyr0021 Jul 7, 2025
e8d2869
checkstyle fix
zephyr0021 Jul 7, 2025
6e4a243
Написаны тесты для userController - server
zephyr0021 Jul 8, 2025
91ec206
Написаны тесты для userService - server
zephyr0021 Jul 8, 2025
b8eccc6
Написаны тесты на package User
zephyr0021 Jul 9, 2025
058305c
Написаны тесты для itemService
zephyr0021 Jul 13, 2025
8ad7fd2
fix
zephyr0021 Jul 13, 2025
b7b2d1d
дописаны тесты для items
zephyr0021 Jul 14, 2025
17c0719
дописаны тесты для bookings
zephyr0021 Jul 15, 2025
0269e3d
Написаны тесты itemrequest controller и model
zephyr0021 Jul 16, 2025
147a254
написаны все тесты
zephyr0021 Jul 16, 2025
b6356ba
написаны все тесты + переключил тестовую бд на постгрес + докер
zephyr0021 Jul 17, 2025
77a8f4c
checkstyle fix
zephyr0021 Jul 17, 2025
a0eba7d
Поменял часовой пояс
zephyr0021 Jul 17, 2025
b54c59e
fix test
zephyr0021 Jul 17, 2025
ae927e3
checkstyle fix
zephyr0021 Jul 17, 2025
f7fe1d1
Перевел тесты на embedded postgres БД
zephyr0021 Jul 17, 2025
5575823
rename modules and directories
zephyr0021 Jul 17, 2025
7b9377d
поменял временную зону
zephyr0021 Jul 17, 2025
04190fb
health-check modules
zephyr0021 Jul 17, 2025
dc64c7f
init schema
zephyr0021 Jul 17, 2025
2ce32db
переключил на h2
zephyr0021 Jul 18, 2025
3a1aa0d
правки по ревью
zephyr0021 Jul 18, 2025
e2f9635
убрал embedded из Pom
zephyr0021 Jul 18, 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
62 changes: 62 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
services:
gateway:
build: gateway
image: gateway
container_name: gateway
ports:
- "8080:8080"
depends_on:
- server
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:8080/" ]
interval: 10s
timeout: 5s
retries: 5
environment:
- SHAREIT_SERVER_URL=http://server:9090

server:
build: server
image: server
container_name: server
ports:
- "9090:9090"
depends_on:
- db
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:9090/" ]
interval: 10s
timeout: 5s
retries: 5
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/shareit
- SPRING_DATASOURCE_USERNAME=dbuser
- SPRING_DATASOURCE_PASSWORD=12345

db:
image: postgres:16.1
container_name: postgres
ports:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=12345
- POSTGRES_USER=dbuser
- POSTGRES_DB=shareit
healthcheck:
test: pg_isready -q -d $$POSTGRES_DB -U $$POSTGRES_USER
timeout: 5s
interval: 5s
retries: 10

db-init:
image: postgres:16.1
container_name: db-init
depends_on:
db:
condition: service_healthy
entrypoint:
- bash
- -c
- |
set -e
psql postgresql://dbuser:12345@db:5432/shareit -v ON_ERROR_STOP=1
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>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>
12 changes: 12 additions & 0 deletions gateway/src/main/java/ru/practicum/shareit/ShareItGateway.java
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);
}

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import ru.practicum.shareit.booking.dto.BookingState;
import ru.practicum.shareit.booking.dto.NewBookingRequestDto;
import ru.practicum.shareit.client.BaseClient;

@Service
public class BookingClient extends BaseClient {
private static final String API_PREFIX = "/bookings";

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

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

public ResponseEntity<Object> getBookingByBooker(Long userId, BookingState state) {
return get(API_PREFIX + "?state=" + state, userId);
}

public ResponseEntity<Object> getBookingByOwner(Long userId, BookingState state) {
return get(API_PREFIX + "/owner?state=" + state, userId);
}

public ResponseEntity<Object> createBooking(NewBookingRequestDto request, Long userId) {
return post(API_PREFIX, userId, request);
}

public ResponseEntity<Object> approveBooking(Long id, Long userId, Boolean approved) {
return patch(API_PREFIX + "/" + id + "?approved=" + approved, userId, null);
}

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

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

@RestController
@RequestMapping("/bookings")
@RequiredArgsConstructor
public class BookingController {
private final BookingClient bookingClient;

@GetMapping("/{id}")
public ResponseEntity<Object> getBooking(@RequestHeader("X-Sharer-User-Id") Long userId, @PathVariable Long id) {
return bookingClient.getBooking(id, userId);
}

@GetMapping
public ResponseEntity<Object> getBookingsByBooker(
@RequestHeader("X-Sharer-User-Id") Long userId,
@RequestParam(defaultValue = "ALL", required = false) BookingState state
) {
return bookingClient.getBookingByBooker(userId, state);
}

@GetMapping("/owner")
public ResponseEntity<Object> getBookingsByOwner(
@RequestHeader("X-Sharer-User-Id") Long userId,
@RequestParam(defaultValue = "ALL", required = false) BookingState state
) {
return bookingClient.getBookingByOwner(userId, state);
}

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public ResponseEntity<Object> createBooking(@RequestHeader("X-Sharer-User-Id") Long userId,
@Valid @RequestBody NewBookingRequestDto request) {
return bookingClient.createBooking(request, userId);
}

@PatchMapping("/{bookingId}")
public ResponseEntity<Object> approveBooking(@RequestHeader("X-Sharer-User-Id") Long userId,
@PathVariable Long bookingId,
@RequestParam Boolean approved) {
return bookingClient.approveBooking(bookingId, userId, approved);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ru.practicum.shareit.booking.dto;

public enum BookingState {
ALL,
WAITING,
REJECTED,
CURRENT,
PAST,
FUTURE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ru.practicum.shareit.booking.dto;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import jakarta.validation.constraints.Future;
import jakarta.validation.constraints.FutureOrPresent;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import ru.practicum.shareit.serializer.OffsetDateTimeFromLocalDateTimeDeserializer;
import ru.practicum.shareit.serializer.OffsetDateTimeToLocalDateTimeSerializer;

import java.time.OffsetDateTime;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class NewBookingRequestDto {
@NotNull
private Long itemId;
@FutureOrPresent
@NotNull
@JsonDeserialize(using = OffsetDateTimeFromLocalDateTimeDeserializer.class)
@JsonSerialize(using = OffsetDateTimeToLocalDateTimeSerializer.class)
private OffsetDateTime start;
@Future
@NotNull
@JsonDeserialize(using = OffsetDateTimeFromLocalDateTimeDeserializer.class)
@JsonSerialize(using = OffsetDateTimeToLocalDateTimeSerializer.class)
private OffsetDateTime end;
}
Loading