Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
refactor UpdateInfo.java
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Mar 16, 2024
1 parent 3a8fdd3 commit 3a0313f
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.example.daemawiki.global.exception.h500.ExecuteFailedException;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import reactor.util.function.Tuple2;

import java.util.List;

Expand All @@ -39,25 +40,24 @@ public UpdateInfo(DocumentFacade documentFacade, DocumentRepository documentRepo
public Mono<Void> execute(UpdateInfoRequest request) {
return userFacade.currentUser()
.zipWith(documentFacade.findDocumentById(request.documentId()))
.map(tuple -> {
userFilter.userPermissionAndDocumentVersionCheck(tuple.getT2(), tuple.getT1().getEmail(), request.version());
return tuple;
})
.flatMap(tuple -> {
DefaultDocument document = tuple.getT2();
User user = tuple.getT1();
.flatMap(tuple -> checkPermissionAndUpdateDocument(tuple, request))
.onErrorMap(this::mapException);
}

setDocument(document, user, request.subTitle(), request.details());
private Mono<Void> checkPermissionAndUpdateDocument(Tuple2<User, DefaultDocument> tuple, UpdateInfoRequest request) {
userFilter.userPermissionAndDocumentVersionCheck(tuple.getT2(), tuple.getT1().getEmail(), request.version());

return documentRepository.save(document)
.then(createRevision(document));
})
.onErrorMap(this::mapException);
DefaultDocument document = tuple.getT2();
User user = tuple.getT1();

setDocument(document, user, request.subTitle(), request.details());

return documentRepository.save(document)
.then(createRevision(document));
}

private void setDocument(DefaultDocument document, User user, String subTitle, List<Detail> details) {
document.getEditor().setUpdatedUser(UserDetailResponse.create(user));

document.getInfo().update(subTitle, details);
document.increaseVersion();
}
Expand Down

0 comments on commit 3a0313f

Please sign in to comment.