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

Commit

Permalink
refactor AddContentTable.java
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Mar 16, 2024
1 parent d18ec74 commit b376a9a
Showing 1 changed file with 7 additions and 4 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.Comparator;

Expand All @@ -40,10 +41,7 @@ public AddContentTable(DocumentFacade documentFacade, RevisionComponent revision
public Mono<Void> execute(AddContentRequest request, String documentId) {
return userFacade.currentUser()
.zipWith(documentFacade.findDocumentById(documentId))
.map(tuple -> {
userFilter.userPermissionAndDocumentVersionCheck(tuple.getT2(), tuple.getT1().getEmail(), request.version());
return tuple;
})
.flatMap(tuple -> checkUserPermissionAndVersion(tuple, request.version()))
.flatMap(tuple -> {
DefaultDocument document = tuple.getT2();
User user = tuple.getT1();
Expand All @@ -59,6 +57,11 @@ public Mono<Void> execute(AddContentRequest request, String documentId) {
.onErrorMap(this::mapException);
}

private Mono<Tuple2<User, DefaultDocument>> checkUserPermissionAndVersion(Tuple2<User, DefaultDocument> tuple, int version) {
userFilter.userPermissionAndDocumentVersionCheck(tuple.getT2(), tuple.getT1().getEmail(), version);
return Mono.just(tuple);
}

private void setDocumentContent(DefaultDocument document, String index, String title) {
Content newContent = createContent(index, title);
document.getContents().add(newContent);
Expand Down

0 comments on commit b376a9a

Please sign in to comment.