Skip to content

Этап 2: Декомпозиция монолита на микросервисы#3

Merged
impatient0 merged 25 commits intomainfrom
microservices
Sep 16, 2025
Merged

Этап 2: Декомпозиция монолита на микросервисы#3
impatient0 merged 25 commits intomainfrom
microservices

Conversation

@impatient0
Copy link
Owner

Данный PR реализует второй этап дипломного проекта — полную декомпозицию монолитного сервиса main-service на независимые микросервисы.

Основные изменения:

  • Выделены новые микросервисы, каждый со своей базой данных и зоной ответственности:

    • event-service (бывший main-service, отвечает за события, категории и подборки)
    • user-service (управление пользователями)
    • request-service (управление заявками на участие)
    • comment-service (управление комментариями)
  • Реализовано межсервисное взаимодействие:

    • Все прямые JPA-связи и зависимости между доменами заменены на вызовы через OpenFeign.
    • Для решения проблемы N+1 реализованы эндпоинты для пакетной загрузки данных.
    • Создан общий модуль interaction-api, содержащий DTO и интерфейсы клиентов, который выступает в роли единого контракта для сервисов.
  • Обновлена инфраструктура:

    • Маршрутизация в gateway-server полностью перенастроена для работы с новыми сервисами.
    • docker-compose.yml обновлен для запуска всего стека микросервисов.

Внешний API-контракт приложения остался без изменений.

Copy link

@kesch9 kesch9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Несколько комментариев

public List<Compilation> findAll(Optional<Boolean> pinned, int from, int size) {
Pageable pageable = PageRequest.of(from / size, size);

if (pinned.isPresent()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно переписать через map

return pinned.map(aBoolean -> jpaCompilationRepository.findByPinned(aBoolean, pageable).getContent())
                .orElseGet(() -> jpaCompilationRepository.findAll(pageable).getContent());

import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно удалить лишний импорт


import feign.codec.ErrorDecoder;
import org.springframework.context.annotation.Bean;
import ru.practicum.explorewithme.api.client.event.EventClientErrorDecoder;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

также лишний импорт


ParticipationRequest save(ParticipationRequest request);

List<ParticipationRequest> saveAll(Iterable<ParticipationRequest> requests);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В методах save и saveAll можно не возвращать значение, они не используются

* Efficiently rejects all PENDING requests for a given event.
* This is useful when an event's participant limit is reached.
*/
void rejectAllPendingRequestsForEvent(Long eventId);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не нашел, чтобы этот метод использовался

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, я добавил его, чтобы оптимизировать взаимодействие с БД, но забыл переписать под него логику в самом сервисе...


public interface SearchParamsWithDateRange {
public LocalDateTime getRangeStart();
public LocalDateTime getRangeEnd();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В интерфейсах писать public не нужно

postgres.yml Outdated
@@ -0,0 +1,18 @@
services:
postgres:
image: postgres:16.1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А нужен отдельный yml для postgres, возможно в проекте этот файл лишний

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, логичнее использовать для БД сервис из основного compose.yaml. Удалил postgres.yml

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Наверно не запушили правки, т.к. postgres.yml всё ещё есть

Copy link

@kesch9 kesch9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve

postgres.yml Outdated
@@ -0,0 +1,18 @@
services:
postgres:
image: postgres:16.1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Наверно не запушили правки, т.к. postgres.yml всё ещё есть

@impatient0 impatient0 merged commit 004f7e6 into main Sep 16, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants