From 17180103d5255932b5e4bb637d7758de7bf38241 Mon Sep 17 00:00:00 2001 From: ibaesuyeon Date: Sun, 14 Apr 2024 09:49:42 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit projectId, postJd를 받아 파일리스트 반환 --- .../post/controller/PostController.java | 10 ++++++--- .../domain/post/domain/PostFile.java | 2 ++ .../domain/post/service/PostServiceImpl.java | 21 +++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/mju/management/domain/post/controller/PostController.java b/src/main/java/com/mju/management/domain/post/controller/PostController.java index aa7542b..5d7833e 100644 --- a/src/main/java/com/mju/management/domain/post/controller/PostController.java +++ b/src/main/java/com/mju/management/domain/post/controller/PostController.java @@ -6,6 +6,7 @@ import com.mju.management.domain.post.model.dto.request.UpdatePostRequestDto; import com.mju.management.global.model.Result.CommonResult; import com.mju.management.domain.post.service.PostServiceImpl; +import com.mju.management.global.model.Result.ListResult; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; @@ -35,15 +36,18 @@ public CommonResult createPost(/* @AuthenticationPrincipal User user,*/ return postServiceImpl.createPost(/* user, */ createPostDto.toServiceRequest(), files); } - @Operation(summary = "기획/제작/편집 게시글 상세 조회 API") + @Operation(summary = "기획/제작/편집 게시글 상세 - 내용 조회 API") @GetMapping public CommonResult retrieveDetailPost(/* @AuthenticationPrincipal User user */ @Valid RetrieveDetailPostRequestDto retrieveDetailPostRequestDto ){ - System.out.println("sdfslakfjklafsjlkjflad" + retrieveDetailPostRequestDto); return postServiceImpl.retrieveDetailPost(/* user, */ retrieveDetailPostRequestDto.toServiceRequest()); } - + @Operation(summary = "기획/제작/편집 게시글 상세 조회 - 파일 리스트 조회 API") + @GetMapping("/files") + public CommonResult retrieveDetailPostFiles(@Valid RetrieveDetailPostRequestDto retrieveDetailPostRequestDto ){ + return postServiceImpl.retrieveDetailPostFiles(retrieveDetailPostRequestDto.toServiceRequest()); + } // @ExceptionHandler(MaxUploadSizeExceededException.class) @Operation(summary = "기획/제작/편집 게시글 수정 API") @PutMapping diff --git a/src/main/java/com/mju/management/domain/post/domain/PostFile.java b/src/main/java/com/mju/management/domain/post/domain/PostFile.java index 324f70d..ce14cd3 100644 --- a/src/main/java/com/mju/management/domain/post/domain/PostFile.java +++ b/src/main/java/com/mju/management/domain/post/domain/PostFile.java @@ -1,5 +1,6 @@ package com.mju.management.domain.post.domain; +import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Builder; @@ -25,5 +26,6 @@ public class PostFile { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "post_id") + @JsonIgnore private Post post; } diff --git a/src/main/java/com/mju/management/domain/post/service/PostServiceImpl.java b/src/main/java/com/mju/management/domain/post/service/PostServiceImpl.java index 779aa84..44ecf95 100644 --- a/src/main/java/com/mju/management/domain/post/service/PostServiceImpl.java +++ b/src/main/java/com/mju/management/domain/post/service/PostServiceImpl.java @@ -17,6 +17,7 @@ import com.mju.management.global.model.Exception.ExceptionList; import com.mju.management.global.model.Exception.UnauthorizedAccessException; import com.mju.management.global.model.Result.CommonResult; +import com.mju.management.global.model.Result.ListResult; import com.mju.management.global.service.ResponseService; import com.mju.management.global.service.S3Service; import lombok.RequiredArgsConstructor; @@ -96,6 +97,26 @@ public CommonResult retrieveDetailPost(RetrieveDetailPostRequestServiceDto dto) return responseService.getSingleResult(PostDetailResponse.from(post, userService.getUsername(post.getWriterId()))); } + @Transactional(readOnly = true) + public CommonResult retrieveDetailPostFiles(RetrieveDetailPostRequestServiceDto dto) { + Optional optionalProject = projectRepository.findById(dto.projectId()); +// if (optionalProject.isEmpty()){ +// return responseService.getFailResult(INVALID_PROJECT_ID.getCode(), INVALID_PROJECT_ID.getMessage()); +// } + Project project = optionalProject.get(); + + // 요청자가 해당 프로젝트의 팀원인지 확인 + checkMemberAuthorization(project, JwtContextHolder.getUserId()); + + Optional optionalPost = postRepository.findById(dto.postId()); +// if(optionalPost.isEmpty()){ +// return responseService.getFailResult(INVALID_POST_ID.getCode(), INVALID_POST_ID.getMessage()); +// } + + Post post = optionalPost.get(); + List files = post.getPostFiles(); + return responseService.getListResult(files); + } public CommonResult updatePost(UpdatePostRequestServiceDto dto, List newFiles ) throws IOException{ Optional optionalProject = projectRepository.findById(dto.projectId()); if (optionalProject.isEmpty()){