From ad448380626b44207ac7cba7ba55f6b6a3775d37 Mon Sep 17 00:00:00 2001 From: YongHo Shin Date: Thu, 5 Oct 2023 15:50:59 +0900 Subject: [PATCH] =?UTF-8?q?[api-server-v1]=20feat:=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EA=B6=8C=ED=95=9C=20=EC=A1=B0=ED=9A=8C=20API=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(=ED=94=84=EB=A1=A0=ED=8A=B8=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../page/controller/SharePageController.java | 19 +++++++++++++++---- .../controller/dto/SharePagePrivilegeDTO.java | 8 +++++++- .../dto/SharePagePrivilegeResponseDTO.java | 10 ++++++++++ .../service/SharePagePrivilegeService.java | 16 +++++++++++----- 4 files changed, 43 insertions(+), 10 deletions(-) create mode 100755 api/server-v1/src/main/java/kr/joberchip/server/v1/page/controller/dto/SharePagePrivilegeResponseDTO.java diff --git a/api/server-v1/src/main/java/kr/joberchip/server/v1/page/controller/SharePageController.java b/api/server-v1/src/main/java/kr/joberchip/server/v1/page/controller/SharePageController.java index 22bf55cc..4a901572 100755 --- a/api/server-v1/src/main/java/kr/joberchip/server/v1/page/controller/SharePageController.java +++ b/api/server-v1/src/main/java/kr/joberchip/server/v1/page/controller/SharePageController.java @@ -8,7 +8,6 @@ import kr.joberchip.server.v1._errors.exceptions.ApiClientException; import kr.joberchip.server.v1._utils.ApiResponse; import kr.joberchip.server.v1.page.controller.dto.*; -import kr.joberchip.server.v1.page.repository.SharePageRepository; import kr.joberchip.server.v1.page.service.SharePagePrivilegeService; import kr.joberchip.server.v1.page.service.SharePageService; import lombok.RequiredArgsConstructor; @@ -121,13 +120,25 @@ public ApiResponse.Result modifySharePage( log.info("[SharePageController] SharePageRequestDTO : {}", sharePageModifyDTO); sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId); - SharePageDetailResponseDTO response = - sharePageService.modify(pageId, sharePageModifyDTO); + SharePageDetailResponseDTO response = sharePageService.modify(pageId, sharePageModifyDTO); + + return ApiResponse.success(response); + } + + @GetMapping("/{pageId}/privilege") + public ApiResponse.Result getPrivilege( + @AuthenticationPrincipal CustomUserDetails loginUser, @PathVariable UUID pageId) { + + log.info("[SharePageController] Login User : {}", loginUser); + log.info("[SharePageController] Page Id : {}", pageId); + + SharePagePrivilegeResponseDTO response = + sharePagePrivilegeService.getPrivilege(loginUser.user().getUserId(), pageId); return ApiResponse.success(response); } - @PostMapping("/privilege") + @PutMapping("/{pageId}/privilege") public ApiResponse.Result modifyPrivilege( @AuthenticationPrincipal CustomUserDetails loginUser, @RequestBody SharePagePrivilegeDTO sharePagePrivilegeDTO, diff --git a/api/server-v1/src/main/java/kr/joberchip/server/v1/page/controller/dto/SharePagePrivilegeDTO.java b/api/server-v1/src/main/java/kr/joberchip/server/v1/page/controller/dto/SharePagePrivilegeDTO.java index 069bd4f6..b9279bc1 100755 --- a/api/server-v1/src/main/java/kr/joberchip/server/v1/page/controller/dto/SharePagePrivilegeDTO.java +++ b/api/server-v1/src/main/java/kr/joberchip/server/v1/page/controller/dto/SharePagePrivilegeDTO.java @@ -2,7 +2,6 @@ import java.util.UUID; import javax.validation.constraints.NotBlank; - import kr.joberchip.core.page.SharePagePrivilege; import kr.joberchip.core.page.types.PrivilegeType; @@ -11,4 +10,11 @@ public record SharePagePrivilegeDTO( public SharePagePrivilege toEntity() { return SharePagePrivilege.of(userId, sharePageId, privilegeType); } + + public static SharePagePrivilegeDTO fromEntity(SharePagePrivilege sharePagePrivilege) { + return new SharePagePrivilegeDTO( + sharePagePrivilege.getUserId(), + sharePagePrivilege.getSharePageId(), + sharePagePrivilege.getPrivilegeType()); + } } diff --git a/api/server-v1/src/main/java/kr/joberchip/server/v1/page/controller/dto/SharePagePrivilegeResponseDTO.java b/api/server-v1/src/main/java/kr/joberchip/server/v1/page/controller/dto/SharePagePrivilegeResponseDTO.java new file mode 100755 index 00000000..5d295f65 --- /dev/null +++ b/api/server-v1/src/main/java/kr/joberchip/server/v1/page/controller/dto/SharePagePrivilegeResponseDTO.java @@ -0,0 +1,10 @@ +package kr.joberchip.server.v1.page.controller.dto; + +import kr.joberchip.core.page.SharePagePrivilege; +import kr.joberchip.core.page.types.PrivilegeType; + +public record SharePagePrivilegeResponseDTO(PrivilegeType privilegeType) { + public static SharePagePrivilegeResponseDTO fromEntity(SharePagePrivilege sharePagePrivilege) { + return new SharePagePrivilegeResponseDTO(sharePagePrivilege.getPrivilegeType()); + } +} diff --git a/api/server-v1/src/main/java/kr/joberchip/server/v1/page/service/SharePagePrivilegeService.java b/api/server-v1/src/main/java/kr/joberchip/server/v1/page/service/SharePagePrivilegeService.java index 1f983a9b..debe8030 100644 --- a/api/server-v1/src/main/java/kr/joberchip/server/v1/page/service/SharePagePrivilegeService.java +++ b/api/server-v1/src/main/java/kr/joberchip/server/v1/page/service/SharePagePrivilegeService.java @@ -7,6 +7,7 @@ import kr.joberchip.server.v1._errors.ErrorMessage; import kr.joberchip.server.v1._errors.exceptions.ApiClientException; import kr.joberchip.server.v1.page.controller.dto.SharePagePrivilegeDTO; +import kr.joberchip.server.v1.page.controller.dto.SharePagePrivilegeResponseDTO; import kr.joberchip.server.v1.page.repository.SharePagePrivilegeRepository; import kr.joberchip.server.v1.page.repository.SharePageRepository; import kr.joberchip.server.v1.space.controller.dto.SpaceInviteRequestDTO; @@ -71,11 +72,16 @@ public void modifyPrivilege(SharePagePrivilegeDTO sharePagePrivilegeDTO) { } @Transactional(readOnly = true) - public PrivilegeType getPrivilege(Long userId, UUID pageId) { - return sharePagePrivilegeRepository - .findByUserIdAndSharePageId(userId, pageId) - .orElseThrow(() -> new ApiClientException(ErrorMessage.PRIVILEGE_ENTITY_NOT_FOUND)) - .getPrivilegeType(); + public SharePagePrivilegeResponseDTO getPrivilege(Long userId, UUID pageId) { + if (!sharePageRepository.existsById(pageId)) + throw new ApiClientException(ErrorMessage.SHARE_PAGE_ENTITY_NOT_FOUND); + + SharePagePrivilege sharePagePrivilege = + sharePagePrivilegeRepository.findByUserIdAndSharePageId(userId, pageId).orElse(null); + + return sharePagePrivilege != null + ? SharePagePrivilegeResponseDTO.fromEntity(sharePagePrivilege) + : null; } @Transactional(readOnly = true)