This repository has been archived by the owner on Nov 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mono.when을 사용해 독립적, 병렬적으로 실행하도록 구현
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
src/main/java/com/example/daemawiki/domain/user/dto/UpdateClubRequest.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,6 @@ | ||
package com.example.daemawiki.domain.user.dto; | ||
|
||
public record UpdateClubRequest( | ||
String club | ||
) { | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/example/daemawiki/domain/user/service/UpdateClub.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,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<Void> execute(UpdateClubRequest request) { | ||
Mono<User> userMono = userFacade.currentUser() | ||
.doOnNext(user -> user.getDetail().setClub(request.club())) | ||
.flatMap(userRepository::save); | ||
|
||
Mono<DefaultDocument> 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(); | ||
} | ||
|
||
} |