From 87318ee22b4abcd714c906605b8ec4a9509ab7a9 Mon Sep 17 00:00:00 2001 From: 101 Date: Sun, 25 Feb 2024 21:39:52 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EB=8F=99=EC=95=84?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=94=EA=B0=80=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mono.when을 사용해 독립적, 병렬적으로 실행하도록 구현 --- .../domain/user/dto/UpdateClubRequest.java | 6 +++ .../domain/user/service/UpdateClub.java | 42 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/main/java/com/example/daemawiki/domain/user/dto/UpdateClubRequest.java create mode 100644 src/main/java/com/example/daemawiki/domain/user/service/UpdateClub.java diff --git a/src/main/java/com/example/daemawiki/domain/user/dto/UpdateClubRequest.java b/src/main/java/com/example/daemawiki/domain/user/dto/UpdateClubRequest.java new file mode 100644 index 00000000..b6bd9134 --- /dev/null +++ b/src/main/java/com/example/daemawiki/domain/user/dto/UpdateClubRequest.java @@ -0,0 +1,6 @@ +package com.example.daemawiki.domain.user.dto; + +public record UpdateClubRequest( + String club +) { +} diff --git a/src/main/java/com/example/daemawiki/domain/user/service/UpdateClub.java b/src/main/java/com/example/daemawiki/domain/user/service/UpdateClub.java new file mode 100644 index 00000000..f3e8bd4a --- /dev/null +++ b/src/main/java/com/example/daemawiki/domain/user/service/UpdateClub.java @@ -0,0 +1,42 @@ +package com.example.daemawiki.domain.user.service; + +import com.example.daemawiki.domain.document.component.facade.DocumentFacade; +import com.example.daemawiki.domain.document.model.DefaultDocument; +import com.example.daemawiki.domain.document.repository.DocumentRepository; +import com.example.daemawiki.domain.user.dto.UpdateClubRequest; +import com.example.daemawiki.domain.user.model.User; +import com.example.daemawiki.domain.user.repository.UserRepository; +import com.example.daemawiki.domain.user.service.facade.UserFacade; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; + +import java.util.Arrays; + +@Service +public class UpdateClub { + private final UserFacade userFacade; + private final DocumentFacade documentFacade; + private final UserRepository userRepository; + private final DocumentRepository documentRepository; + + public UpdateClub(UserFacade userFacade, DocumentFacade documentFacade, UserRepository userRepository, DocumentRepository documentRepository) { + this.userFacade = userFacade; + this.documentFacade = documentFacade; + this.userRepository = userRepository; + this.documentRepository = documentRepository; + } + + public Mono execute(UpdateClubRequest request) { + Mono userMono = userFacade.currentUser() + .doOnNext(user -> user.getDetail().setClub(request.club())) + .flatMap(userRepository::save); + + Mono documentMono = userMono + .flatMap(user -> documentFacade.findDocumentById(user.getDocumentId())) + .doOnNext(document -> document.getGroups().add(Arrays.asList("동아리", request.club()))) + .flatMap(documentRepository::save); + + return Mono.when(userMono, documentMono).then(); + } + +}