Skip to content

Commit

Permalink
[api-server-v1] feat: 페이지 권한 조회 API 추가 (프론트 요청)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdtknight committed Oct 5, 2023
1 parent 4d8fda5 commit ad44838
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -121,13 +120,25 @@ public ApiResponse.Result<SharePageDetailResponseDTO> 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<SharePagePrivilegeResponseDTO> 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<SharePagePrivilegeDTO> modifyPrivilege(
@AuthenticationPrincipal CustomUserDetails loginUser,
@RequestBody SharePagePrivilegeDTO sharePagePrivilegeDTO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ad44838

Please sign in to comment.