From 2fc095e81b99a646dee2efc5fa7f373fe95cd735 Mon Sep 17 00:00:00 2001 From: 101 Date: Wed, 28 Feb 2024 12:48:48 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit stream api 사용 --- .../document/component/service/UpdateDocument.java | 12 +++--------- .../domain/document/model/DocumentEditor.java | 4 ++++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/example/daemawiki/domain/document/component/service/UpdateDocument.java b/src/main/java/com/example/daemawiki/domain/document/component/service/UpdateDocument.java index a4085133..5cbbed4d 100644 --- a/src/main/java/com/example/daemawiki/domain/document/component/service/UpdateDocument.java +++ b/src/main/java/com/example/daemawiki/domain/document/component/service/UpdateDocument.java @@ -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; @@ -37,14 +36,9 @@ public UpdateDocument(DocumentFacade documentFacade, UserFacade userFacade, Docu public Mono 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()) diff --git a/src/main/java/com/example/daemawiki/domain/document/model/DocumentEditor.java b/src/main/java/com/example/daemawiki/domain/document/model/DocumentEditor.java index 35efee01..c8112a52 100644 --- a/src/main/java/com/example/daemawiki/domain/document/model/DocumentEditor.java +++ b/src/main/java/com/example/daemawiki/domain/document/model/DocumentEditor.java @@ -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)); + } + }