diff --git a/src/main/java/com/mju/management/domain/post/infrastructure/PostRepository.java b/src/main/java/com/mju/management/domain/post/infrastructure/PostRepository.java index 79b4d41..ab6b6e6 100644 --- a/src/main/java/com/mju/management/domain/post/infrastructure/PostRepository.java +++ b/src/main/java/com/mju/management/domain/post/infrastructure/PostRepository.java @@ -14,5 +14,6 @@ public interface PostRepository extends JpaRepository { List findByCategoryAndProject(Category getCategory, Project project); List findByCategoryAndProject(Category getCategory, Project project, Pageable pageable); + List findByProject(Project project); } diff --git a/src/main/java/com/mju/management/domain/project/contoller/ProjectController.java b/src/main/java/com/mju/management/domain/project/contoller/ProjectController.java index 146399a..243ca7e 100644 --- a/src/main/java/com/mju/management/domain/project/contoller/ProjectController.java +++ b/src/main/java/com/mju/management/domain/project/contoller/ProjectController.java @@ -1,5 +1,6 @@ package com.mju.management.domain.project.contoller; +import com.mju.management.domain.post.model.dto.request.RetrieveDetailPostRequestDto; import com.mju.management.domain.project.dto.response.GetProjectListResponseDto; import com.mju.management.domain.project.dto.response.GetProjectResponseDto; import com.mju.management.domain.project.service.ProjectService; @@ -53,6 +54,13 @@ public CommonResult getProject(@PathVariable Long projectId) { return responseService.getSingleResult(project); } + // 프로젝트 별 파일리스트 조회 + @Operation(summary = "프로젝트 별 파일 리스트 조회") + @GetMapping("/{projectId}/files") + public CommonResult getProjectFiles(@PathVariable Long projectId) { + return responseService.getListResult(projectService.getProjectFiles(projectId)); + } + //프로젝트 수정 @Operation(summary = "프로젝트 수정") @PutMapping("/{projectId}") diff --git a/src/main/java/com/mju/management/domain/project/service/ProjectService.java b/src/main/java/com/mju/management/domain/project/service/ProjectService.java index 6a5d042..53180aa 100644 --- a/src/main/java/com/mju/management/domain/project/service/ProjectService.java +++ b/src/main/java/com/mju/management/domain/project/service/ProjectService.java @@ -1,5 +1,6 @@ package com.mju.management.domain.project.service; +import com.mju.management.domain.post.domain.PostFile; import com.mju.management.domain.project.dto.reqeust.CreateProjectRequestDto; import com.mju.management.domain.project.dto.response.GetProjectListResponseDto; import com.mju.management.domain.project.dto.response.GetProjectResponseDto; @@ -16,4 +17,5 @@ public interface ProjectService { void updateProject(Long projectIndex, CreateProjectRequestDto createProjectRequestDto); void finishProject(Long projectIndex); + List getProjectFiles(Long projectId); } diff --git a/src/main/java/com/mju/management/domain/project/service/ProjectServiceImpl.java b/src/main/java/com/mju/management/domain/project/service/ProjectServiceImpl.java index 3c150cf..1614d4d 100644 --- a/src/main/java/com/mju/management/domain/project/service/ProjectServiceImpl.java +++ b/src/main/java/com/mju/management/domain/project/service/ProjectServiceImpl.java @@ -1,5 +1,9 @@ package com.mju.management.domain.project.service; +import com.mju.management.domain.post.domain.Post; +import com.mju.management.domain.post.domain.PostFile; +import com.mju.management.domain.post.infrastructure.PostFileRepository; +import com.mju.management.domain.post.infrastructure.PostRepository; import com.mju.management.domain.project.dto.response.GetProjectListResponseDto; import com.mju.management.domain.project.dto.response.GetProjectResponseDto; import com.mju.management.domain.project.dto.response.GetProjectUserResponseDto; @@ -19,6 +23,7 @@ import java.time.LocalDate; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -27,6 +32,8 @@ public class ProjectServiceImpl implements ProjectService{ private final ProjectRepository projectRepository; private final UserServiceImpl userService; + private final PostRepository postRepository; + private final PostFileRepository postFileRepository; @Override @Transactional @@ -126,6 +133,22 @@ public void finishProject(Long projectId) { } + @Override + public List getProjectFiles(Long projectId) { + Project project = projectRepository.findByIdWithProjectUserList(projectId) + .orElseThrow(()->new NonExistentException(ExceptionList.NON_EXISTENT_PROJECT)); + if(!project.isLeaderOrMember(JwtContextHolder.getUserId())) + throw new UnauthorizedAccessException(ExceptionList.UNAUTHORIZED_ACCESS); +// List getProjectUserResponseDtoList = +// getProjectUserResponseDtoList(project.getProjectUserList()); + List posts = postRepository.findByProject(project); + List project_files = new ArrayList<>(); + for(Post post : posts){ + project_files.addAll(postFileRepository.findByPostId(post.getId())); + } + return project_files; + } + public void validateProjectPeriod(CreateProjectRequestDto createProjectRequestDto){ LocalDate startDate = createProjectRequestDto.startDateAsLocalDateType(); LocalDate endDate = createProjectRequestDto.finishDateAsLocalDateType();