From a6673d15de14eacb5eaa1cd5adc4b9c1e3426091 Mon Sep 17 00:00:00 2001 From: 101 Date: Tue, 2 Apr 2024 18:46:51 +0900 Subject: [PATCH] refactor UserFilter --- .../daemawiki/domain/common/UserFilter.java | 27 +++------------ .../domain/common/UserFilterImpl.java | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+), 23 deletions(-) create mode 100644 daemawiki-service/src/main/java/org/daemawiki/domain/common/UserFilterImpl.java diff --git a/daemawiki-service/src/main/java/org/daemawiki/domain/common/UserFilter.java b/daemawiki-service/src/main/java/org/daemawiki/domain/common/UserFilter.java index 57d0ecf8..54de41c7 100644 --- a/daemawiki-service/src/main/java/org/daemawiki/domain/common/UserFilter.java +++ b/daemawiki-service/src/main/java/org/daemawiki/domain/common/UserFilter.java @@ -2,30 +2,11 @@ import org.daemawiki.domain.document.model.DefaultDocument; import org.daemawiki.domain.user.model.User; -import org.daemawiki.exception.h400.VersionMismatchException; -import org.daemawiki.exception.h403.NoEditPermissionUserException; -import org.springframework.stereotype.Component; -import java.util.Objects; +public interface UserFilter { -@Component -public class UserFilter { - - public void userPermissionAndDocumentVersionCheck(DefaultDocument document, String userEmail, Integer requestVersion) { - userPermissionCheck(document, userEmail); - if (!Objects.equals(document.getVersion(), requestVersion)) { - throw VersionMismatchException.EXCEPTION; - } - } - - public void userPermissionCheck(DefaultDocument document, String userEmail) { - if (document.getEditor().hasEditPermission(userEmail)) { - throw NoEditPermissionUserException.EXCEPTION; - } - } - - public void checkUserAndDocument(User user, DefaultDocument document, Integer version) { - userPermissionAndDocumentVersionCheck(document, user.getEmail(), version); - } + void userPermissionAndDocumentVersionCheck(DefaultDocument document, String userEmail, Integer requestVersion); + void userPermissionCheck(DefaultDocument document, String userEmail); + void checkUserAndDocument(User user, DefaultDocument document, Integer version); } diff --git a/daemawiki-service/src/main/java/org/daemawiki/domain/common/UserFilterImpl.java b/daemawiki-service/src/main/java/org/daemawiki/domain/common/UserFilterImpl.java new file mode 100644 index 00000000..4ea29e2b --- /dev/null +++ b/daemawiki-service/src/main/java/org/daemawiki/domain/common/UserFilterImpl.java @@ -0,0 +1,34 @@ +package org.daemawiki.domain.common; + +import org.daemawiki.domain.document.model.DefaultDocument; +import org.daemawiki.domain.user.model.User; +import org.daemawiki.exception.h400.VersionMismatchException; +import org.daemawiki.exception.h403.NoEditPermissionUserException; +import org.springframework.stereotype.Component; + +import java.util.Objects; + +@Component +public class UserFilterImpl implements UserFilter { + + @Override + public void userPermissionAndDocumentVersionCheck(DefaultDocument document, String userEmail, Integer requestVersion) { + userPermissionCheck(document, userEmail); + if (!Objects.equals(document.getVersion(), requestVersion)) { + throw VersionMismatchException.EXCEPTION; + } + } + + @Override + public void userPermissionCheck(DefaultDocument document, String userEmail) { + if (document.getEditor().hasEditPermission(userEmail)) { + throw NoEditPermissionUserException.EXCEPTION; + } + } + + @Override + public void checkUserAndDocument(User user, DefaultDocument document, Integer version) { + userPermissionAndDocumentVersionCheck(document, user.getEmail(), version); + } + +}