Skip to content

Commit 6fd9c6d

Browse files
authored
Merge pull request #34 from DMU-NextLevel/refactor/project-all
select project story, notice, community
2 parents 75e3f39 + fe9606a commit 6fd9c6d

File tree

17 files changed

+68
-98
lines changed

17 files changed

+68
-98
lines changed

src/main/java/NextLevel/demo/project/community/controller/ProjectCommunityController.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import NextLevel.demo.common.SuccessResponse;
44
import NextLevel.demo.project.community.dto.request.SaveCommunityDto;
5+
import NextLevel.demo.project.community.dto.response.ResponseCommunityListDto;
56
import NextLevel.demo.project.community.service.ProjectCommunityAskService;
67
import NextLevel.demo.util.jwt.JWTUtil;
78
import jakarta.validation.Valid;
@@ -10,10 +11,7 @@
1011
import org.springframework.http.HttpStatus;
1112
import org.springframework.http.ResponseEntity;
1213
import org.springframework.stereotype.Controller;
13-
import org.springframework.web.bind.annotation.DeleteMapping;
14-
import org.springframework.web.bind.annotation.PathVariable;
15-
import org.springframework.web.bind.annotation.PostMapping;
16-
import org.springframework.web.bind.annotation.RequestBody;
14+
import org.springframework.web.bind.annotation.*;
1715

1816
@Controller
1917
@Slf4j
@@ -22,6 +20,12 @@ public class ProjectCommunityController {
2220

2321
private final ProjectCommunityAskService communityService;
2422

23+
// list
24+
@GetMapping("/public/project/{projectId}/community")
25+
public ResponseEntity getProjectCommunity(@PathVariable Long projectId) {
26+
return ResponseEntity.ok().body(new SuccessResponse("success", new ResponseCommunityListDto(communityService.selectAll(projectId))));
27+
}
28+
2529
// 생성만
2630
@PostMapping("/api1/project/{projectId}/community")
2731
public ResponseEntity<?> saveProjectCommunity(@PathVariable("projectId") Long projectId, @RequestBody @Valid SaveCommunityDto dto) {

src/main/java/NextLevel/demo/project/community/dto/response/ResponseCommunityListDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class ResponseCommunityListDto {
1212
private int communityCount;
1313
private List<ResponseProjectCommunityDto> communities;
1414

15-
public ResponseCommunityListDto (Collection<ProjectCommunityAskEntity> communities) {
15+
public ResponseCommunityListDto (List<ProjectCommunityAskEntity> communities) {
1616
this.communities = communities.stream().map(e->ResponseProjectCommunityDto.of(e)).toList();
1717
this.communityCount = communities.size();
1818
}

src/main/java/NextLevel/demo/project/community/repository/ProjectCommunityAskRepository.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
public interface ProjectCommunityAskRepository extends JpaRepository<ProjectCommunityAskEntity, Long> {
1111

12-
@Query("select ask from ProjectCommunityAskEntity ask left join fetch ask.answer where ask.project.id = :projectId")
13-
List<ProjectCommunityAskEntity> findAllByProjectId(@Param("projectId") Long projectId);
12+
@Query("select ask from ProjectCommunityAskEntity ask left join fetch ask.answer where ask.project.id = :projectId order by ask.createdAt desc")
13+
List<ProjectCommunityAskEntity> findAllByProjectIdOrderByCreatedAt(@Param("projectId") Long projectId);
1414

1515
}

src/main/java/NextLevel/demo/project/community/service/ProjectCommunityAskService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ public void update(SaveCommunityDto dto) {
5050
}
5151

5252
@Transactional
53-
public ResponseCommunityListDto selectAll(Long projectId) {
53+
public List<ProjectCommunityAskEntity> selectAll(Long projectId) {
5454
ProjectEntity project = projectValidateService.getProjectEntity(projectId);
55-
List<ProjectCommunityAskEntity> asks = projectCommunityAskRepository.findAllByProjectId(project.getId());
56-
return new ResponseCommunityListDto(asks);
55+
return projectCommunityAskRepository.findAllByProjectIdOrderByCreatedAt(project.getId());
5756
}
5857

5958
@Transactional

src/main/java/NextLevel/demo/project/notice/controller/ProjectNoticeController.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import NextLevel.demo.common.SuccessResponse;
44
import NextLevel.demo.project.notice.dto.request.SaveProjectNoticeRequestDto;
5+
import NextLevel.demo.project.notice.dto.response.ResponseNoticeListDto;
6+
import NextLevel.demo.project.notice.dto.response.ResponseProjectNoticeDto;
57
import NextLevel.demo.project.notice.service.ProjectNoticeService;
68
import NextLevel.demo.util.jwt.JWTUtil;
79
import jakarta.validation.Valid;
@@ -10,11 +12,7 @@
1012
import org.springframework.http.HttpStatus;
1113
import org.springframework.http.ResponseEntity;
1214
import org.springframework.stereotype.Controller;
13-
import org.springframework.web.bind.annotation.DeleteMapping;
14-
import org.springframework.web.bind.annotation.ModelAttribute;
15-
import org.springframework.web.bind.annotation.PathVariable;
16-
import org.springframework.web.bind.annotation.PostMapping;
17-
import org.springframework.web.bind.annotation.PutMapping;
15+
import org.springframework.web.bind.annotation.*;
1816

1917
@Controller
2018
@Slf4j
@@ -23,6 +21,12 @@ public class ProjectNoticeController {
2321

2422
private final ProjectNoticeService projectNoticeService;
2523

24+
// select notice by project
25+
@GetMapping("/public/project/{projectId}/notice")
26+
public ResponseEntity<?> getProjectNotice(@PathVariable Long projectId) {
27+
return ResponseEntity.ok().body(new SuccessResponse("success", new ResponseNoticeListDto(projectNoticeService.getAllNotice(projectId))));
28+
}
29+
2630
@PostMapping("/api1/project/{projectId}/notice")
2731
public ResponseEntity<?> addProjectNotice(@PathVariable("projectId") long projectId, @ModelAttribute @Valid SaveProjectNoticeRequestDto dto) {
2832
dto.setProjectId(projectId);

src/main/java/NextLevel/demo/project/notice/dto/response/ResponseNoticeListDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class ResponseNoticeListDto {
1111
private int noticeCount;
1212
private List<ResponseProjectNoticeDto> notices;
1313

14-
public ResponseNoticeListDto(Set<ProjectNoticeEntity> entities) {
14+
public ResponseNoticeListDto(List<ProjectNoticeEntity> entities) {
1515
this.notices = entities.stream().map(e->ResponseProjectNoticeDto.of(e)).toList();
1616
this.noticeCount = notices.size();
1717
}

src/main/java/NextLevel/demo/project/notice/repository/ProjectNoticeRepository.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package NextLevel.demo.project.notice.repository;
22

33
import NextLevel.demo.project.notice.entity.ProjectNoticeEntity;
4+
5+
import java.util.List;
46
import java.util.Optional;
57
import org.springframework.data.jpa.repository.JpaRepository;
68
import org.springframework.data.jpa.repository.Query;
@@ -10,4 +12,8 @@ public interface ProjectNoticeRepository extends JpaRepository<ProjectNoticeEnti
1012

1113
@Query("select n from ProjectNoticeEntity n left join fetch n.project where n.id = :noticeId")
1214
Optional<ProjectNoticeEntity> findByIdWithProject(@Param("noticeId") Long noticeId);
15+
16+
@Query("select pn from ProjectNoticeEntity pn where pn.project.id = :projectId order by pn.createdAt desc")
17+
List<ProjectNoticeEntity> findAllByProjectOrderByCreatedAt(@Param("projectId") Long projectId);
18+
1319
}

src/main/java/NextLevel/demo/project/notice/service/ProjectNoticeService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import jakarta.persistence.EntityManager;
1414
import java.nio.file.Path;
1515
import java.util.ArrayList;
16+
import java.util.List;
17+
1618
import lombok.RequiredArgsConstructor;
1719
import lombok.extern.slf4j.Slf4j;
1820
import org.springframework.stereotype.Service;
@@ -27,6 +29,11 @@ public class ProjectNoticeService {
2729
private final ImgServiceImpl imgService;
2830
private final ProjectValidateService projectValidateService;
2931

32+
public List<ProjectNoticeEntity> getAllNotice(Long projectId){
33+
ProjectEntity project = projectValidateService.getProjectEntity(projectId);
34+
return projectNoticeRepository.findAllByProjectOrderByCreatedAt(project.getId());
35+
}
36+
3037
@Transactional
3138
@ImgTransaction
3239
public void saveProjectNotice(SaveProjectNoticeRequestDto dto, ArrayList<Path> imgPaths) {

src/main/java/NextLevel/demo/project/project/controller/ProjectController.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import NextLevel.demo.common.SuccessResponse;
44
import NextLevel.demo.project.project.dto.request.CreateProjectDto;
55
import NextLevel.demo.project.project.dto.request.RequestMainPageProjectListDto;
6-
import NextLevel.demo.project.project.dto.response.ResponseProjectAllDto;
76
import NextLevel.demo.project.project.dto.response.ResponseProjectDetailDto;
87
import NextLevel.demo.project.project.dto.response.ResponseProjectListDto;
98
import NextLevel.demo.project.project.service.ProjectService;
@@ -99,11 +98,4 @@ public ResponseEntity<?> getProjectDetailById(@PathVariable("projectId") @NotNul
9998
return ResponseEntity.status(HttpStatus.OK).body(new SuccessResponse("success" ,dto));
10099
}
101100

102-
@GetMapping("/public/project/{projectId}/all")
103-
public ResponseEntity<?> getProjectNotice(@PathVariable("projectId") Long projectId) {
104-
ResponseProjectAllDto dto = projectService.getProjectCommunityAndNoticeAndStoryDto(projectId);
105-
106-
return ResponseEntity.status(HttpStatus.OK).body(new SuccessResponse("success", dto));
107-
}
108-
109101
}

src/main/java/NextLevel/demo/project/project/dto/response/ResponseProjectAllDto.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)