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

Commit

Permalink
리팩토링
Browse files Browse the repository at this point in the history
stream api 사용
  • Loading branch information
ori0o0p committed Feb 28, 2024
1 parent daa36e6 commit 2fc095e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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.Editor;
import com.example.daemawiki.domain.document.model.type.service.GetDocumentType;
import com.example.daemawiki.domain.document.repository.DocumentRepository;
import com.example.daemawiki.domain.revision.component.RevisionComponent;
Expand Down Expand Up @@ -37,14 +36,9 @@ public UpdateDocument(DocumentFacade documentFacade, UserFacade userFacade, Docu
public Mono<Void> execute(SaveDocumentRequest request, String documentId) {
return userFacade.currentUser()
.zipWith(documentFacade.findDocumentById(documentId), (user, document) -> {
if (!document.getEditor()
.getCanEdit()
.contains(Editor.builder()
.email(user.getEmail())
.id(user.getId())
.build())) {
throw NoEditPermissionUserException.EXCEPTION;
}
if (!document.getEditor().canEdit(user.getEmail())) {
throw NoEditPermissionUserException.EXCEPTION;
}

document.getEditor().update(UserDetailResponse.builder()
.id(user.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ public void update(UserDetailResponse updatedUser) {
this.updatedUser = updatedUser;
}

public boolean canEdit(String email) {
return this.canEdit.stream().anyMatch(editor -> editor.email().equals(email));
}

}

0 comments on commit 2fc095e

Please sign in to comment.