diff --git a/src/main/java/wowmarket/wow_server/detail/project/controller/ProjectController.java b/src/main/java/wowmarket/wow_server/detail/project/controller/ProjectController.java index 37ed0c0..3075a83 100644 --- a/src/main/java/wowmarket/wow_server/detail/project/controller/ProjectController.java +++ b/src/main/java/wowmarket/wow_server/detail/project/controller/ProjectController.java @@ -23,8 +23,8 @@ public class ProjectController { //주문폼: 상세 정보 조회 @GetMapping("/{project_id}") - public ProjectInfoResponseDto getProjectInfo(@PathVariable Long project_id) { - return projectService.getProjectInfo(project_id); + public ProjectInfoResponseDto getProjectInfo(@PathVariable Long project_id, @AuthenticationPrincipal User user) { + return projectService.getProjectInfo(project_id, user); } //주문폼: 굿즈 소개(이미지 3개) 조회 @@ -56,12 +56,4 @@ public ResponseEntity createDemandForm(@PathVariable Long project_id, @RequestBo public ResponseEntity likeProject(@PathVariable Long project_id, @AuthenticationPrincipal User user) { return projectService.likeProject(project_id, user); } - - @DeleteMapping("/{project_id}/unlike") - public ResponseEntity unlikeProject(@PathVariable Long project_id, @AuthenticationPrincipal User user) { - return projectService.unLikeProject(project_id, user); - } - - - } \ No newline at end of file diff --git a/src/main/java/wowmarket/wow_server/detail/project/dto/ProjectInfoResponseDto.java b/src/main/java/wowmarket/wow_server/detail/project/dto/ProjectInfoResponseDto.java index e489792..f878835 100644 --- a/src/main/java/wowmarket/wow_server/detail/project/dto/ProjectInfoResponseDto.java +++ b/src/main/java/wowmarket/wow_server/detail/project/dto/ProjectInfoResponseDto.java @@ -19,9 +19,10 @@ public class ProjectInfoResponseDto { private int participant_number; //참여인원 private int achieved; //달성률 분자: 모든 주문상세의 '주문개수' 컬럼의 합 private int goal; //달성률 분모: 상품 테이블에서 프로젝트 번호로 조회하여 해당 프로젝트에 들어있는 상품의 목표치의 합 + private boolean isLiked; - public ProjectInfoResponseDto(Project project, int achieved, int goal) { + public ProjectInfoResponseDto(Project project, int achieved, int goal, boolean isLiked) { this.thumbnail = project.getThumbnail(); //대표이미지 this.category = project.getCategory().getName(); //카테고리 this.name = project.getProjectName(); //프로젝트 이름 @@ -33,5 +34,6 @@ public ProjectInfoResponseDto(Project project, int achieved, int goal) { this.participant_number = project.getParticipant_number(); //참여인원 this.achieved = achieved; this.goal = goal; + this.isLiked = isLiked; } } \ No newline at end of file diff --git a/src/main/java/wowmarket/wow_server/detail/project/service/ProjectService.java b/src/main/java/wowmarket/wow_server/detail/project/service/ProjectService.java index 1051be6..238f873 100644 --- a/src/main/java/wowmarket/wow_server/detail/project/service/ProjectService.java +++ b/src/main/java/wowmarket/wow_server/detail/project/service/ProjectService.java @@ -33,11 +33,15 @@ public ProjectImgResponseDto getProjectImg(Long project_id) { } //주문폼: 상세 정보 조회 - public ProjectInfoResponseDto getProjectInfo(Long project_id) { + public ProjectInfoResponseDto getProjectInfo(Long project_id, User user) { + boolean isLiked = false; Project project = projectRepository.findByProject_Id(project_id); projectRepository.updateView(project_id); //상세정보 조회할 때마다 조회수 +1 + if (user != null && likesRepository.findByUserAndProject(user, project_id).isPresent()) { + isLiked = true; + } return new ProjectInfoResponseDto(project, itemRepository.getTotalOrderCountByProject(project), - itemRepository.getTotalGoalByProject(project)); + itemRepository.getTotalGoalByProject(project), isLiked); } @Transactional @@ -50,15 +54,6 @@ public ResponseEntity likeProject(Long projectId, User user) { projectRepository.updateProjectLike(projectId); userRepository.updateProjectLike(user); } else { - throw new ResponseStatusException(HttpStatus.CONFLICT, "이미 like한 프로젝트"); - } - return ResponseEntity.ok().build(); - } - - @Transactional - public ResponseEntity unLikeProject(Long projectId, User user) { - Optional likeExist = likesRepository.findByUserAndProject(user, projectId); - if (likeExist.isPresent()) { if (projectRepository.findById(projectId).get().getLikeCnt() > 0 && user.getProjectLike() > 0) { likesRepository.deleteLikes(likeExist.get().getId()); @@ -67,8 +62,6 @@ public ResponseEntity unLikeProject(Long projectId, User user) { } else { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "like 수가 0이라 unlike할 수 없음"); } - } else { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "like하지 않아서 unlike할 수 없음"); } return ResponseEntity.ok().build(); }