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

Commit

Permalink
refactor UpdateDocument.java
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Mar 16, 2024
1 parent d02f427 commit 0a01cc6
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.example.daemawiki.domain.common.UserFilter;
import com.example.daemawiki.domain.document.component.UpdateDocumentComponent;
import com.example.daemawiki.domain.document.component.UpdateDocumentEditorAndUpdatedDate;
import com.example.daemawiki.domain.document.component.facade.DocumentFacade;
import com.example.daemawiki.domain.document.dto.request.SaveDocumentRequest;
import com.example.daemawiki.domain.document.model.DefaultDocument;
Expand All @@ -17,6 +16,7 @@
import com.example.daemawiki.global.exception.h500.ExecuteFailedException;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import reactor.util.function.Tuple2;

@Service
public class UpdateDocument {
Expand All @@ -39,17 +39,18 @@ public UpdateDocument(DocumentFacade documentFacade, UserFacade userFacade, GetD
public Mono<Void> execute(SaveDocumentRequest request, String documentId) {
return userFacade.currentUser()
.zipWith(documentFacade.findDocumentById(documentId))
.map(tuple -> {
userFilter.userPermissionAndDocumentVersionCheck(tuple.getT2(), tuple.getT1().getEmail(), request.version());
return tuple;
})
.map(tuple -> setDocument(tuple.getT2(), tuple.getT1(), request))
.map(tuple -> checkPermissionAndUpdateDocument(tuple, request))
.flatMap(document -> documentFacade.saveDocument(document)
.then(createRevision(document)))
.onErrorMap(this::mapException);
}

private DefaultDocument setDocument(DefaultDocument document, User user, SaveDocumentRequest request) {
private DefaultDocument checkPermissionAndUpdateDocument(Tuple2<User, DefaultDocument> tuple, SaveDocumentRequest request) {
DefaultDocument document = tuple.getT2();
User user = tuple.getT1();

userFilter.userPermissionAndDocumentVersionCheck(document, user.getEmail(), request.version());

document.update(request.title(),
getDocumentType.execute(request.type().toLowerCase()),
request.groups());
Expand Down

0 comments on commit 0a01cc6

Please sign in to comment.