From 693bcc13d03cc2fd44e75a3fe229f9680702162f Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:47:01 +0900 Subject: [PATCH 01/19] =?UTF-8?q?fix:=20=EB=A1=9C=EB=93=9C=EB=A7=B5=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=9D=B4=EB=A6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dump.rdb | Bin 0 -> 307 bytes .../com/example/tily/comment/CommentService.java | 2 +- .../java/com/example/tily/roadmap/Roadmap.java | 1 + .../example/tily/roadmap/RoadmapController.java | 12 ++++++------ .../com/example/tily/roadmap/RoadmapResponse.java | 1 + .../com/example/tily/roadmap/RoadmapService.java | 14 ++++---------- .../tily/roadmap/relation/UserRoadmap.java | 1 + .../com/example/tily/step/StepRepository.java | 4 ---- .../java/com/example/tily/step/StepResponse.java | 1 + .../tily/step/reference/ReferenceRepository.java | 1 + .../tily/step/reference/ReferenceRequest.java | 1 + 11 files changed, 17 insertions(+), 21 deletions(-) create mode 100644 dump.rdb diff --git a/dump.rdb b/dump.rdb new file mode 100644 index 0000000000000000000000000000000000000000..1fe5f01b625937770878233d8d06ee8749cdbcad GIT binary patch literal 307 zcmXAhL2iOT007a%#P-%(KLG&@q1>cma95C61uYlD%C@`6N)#mEsY!p)cl6Lp6XU6W z=mYwI9-3g&R@385CUes@z(^D&sXANZkfwZ&*9}#W1-Ux^7l>x*u3a_e8D)6?T3EPh zZc-fb472^i#|2k4gXE4!L5g?W4|k~5zMuBt<7J)WxLv*dhD#{osZJdV`<^tURtFMf z&QA>7ty|a>YQizvh7)j-36hoN&{RmsywYNW9F0H z>b7h{FYIwwc8pjP?wyQu@@!GU*_9ahN{uKfL?_U^#HY literal 0 HcmV?d00001 diff --git a/src/main/java/com/example/tily/comment/CommentService.java b/src/main/java/com/example/tily/comment/CommentService.java index 5763c3b1..c69fc429 100644 --- a/src/main/java/com/example/tily/comment/CommentService.java +++ b/src/main/java/com/example/tily/comment/CommentService.java @@ -19,6 +19,7 @@ @RequiredArgsConstructor @Service public class CommentService { + private final RoadmapRepository roadmapRepository; private final StepRepository stepRepository; private final TilRepository tilRepository; @@ -55,7 +56,6 @@ public CommentResponse.CreateCommentDTO createComment(CommentRequest.CreateComme @Transactional public void updateComment(CommentRequest.UpdateCommentDTO requestDTO, Long commentId, User user) { - Comment comment = commentRepository.findById(commentId) .orElseThrow(() -> new CustomException(ExceptionCode.COMMENT_NOT_FOUND)); diff --git a/src/main/java/com/example/tily/roadmap/Roadmap.java b/src/main/java/com/example/tily/roadmap/Roadmap.java index c402d197..edc49683 100644 --- a/src/main/java/com/example/tily/roadmap/Roadmap.java +++ b/src/main/java/com/example/tily/roadmap/Roadmap.java @@ -21,6 +21,7 @@ @SQLDelete(sql = "UPDATE roadmap_tb SET is_deleted = true WHERE id = ?") @Where(clause = "is_deleted = false") public class Roadmap extends BaseTimeEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; diff --git a/src/main/java/com/example/tily/roadmap/RoadmapController.java b/src/main/java/com/example/tily/roadmap/RoadmapController.java index 37b60627..fc8c4055 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapController.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapController.java @@ -36,18 +36,18 @@ public ResponseEntity createTilyRoadmap(@RequestBody @Valid RoadmapRequest.Cr // 틸리, 그룹 로드맵 정보 조회하기 @GetMapping("/roadmaps/{id}") - public ResponseEntity findGroupRoadmap(@PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){ + public ResponseEntity findRoadmap(@PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){ User user = Optional.ofNullable(userDetails).map(CustomUserDetails::getUser).orElse(null); - RoadmapResponse.FindGroupRoadmapDTO responseDTO = roadmapService.findGroupRoadmap(id, user); + RoadmapResponse.FindGroupRoadmapDTO responseDTO = roadmapService.findRoadmap(id, user); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } // 그룹 로드맵 정보 수정하기 @PatchMapping("/roadmaps/{id}") - public ResponseEntity updateGroupRoadmap(@RequestBody @Valid RoadmapRequest.UpdateGroupRoadmapDTO requestDTO, Errors errors, - @PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){ - roadmapService.updateGroupRoadmap(id, requestDTO, userDetails.getUser()); + public ResponseEntity updateRoadmap(@RequestBody @Valid RoadmapRequest.UpdateGroupRoadmapDTO requestDTO, Errors errors, + @PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){ + roadmapService.updateRoadmap(id, requestDTO, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(null)); } @@ -136,7 +136,7 @@ public ResponseEntity rejectApplication(@PathVariable Long groupId, @PathVari return ResponseEntity.ok().body(ApiUtils.success(null)); } - // 그룹 로드맵 삭제 + // 로드맵 삭제 @DeleteMapping("/roadmaps/{id}") public ResponseEntity deleteRoadmap(@PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){ roadmapService.deleteRoadmap(id, userDetails.getUser()); diff --git a/src/main/java/com/example/tily/roadmap/RoadmapResponse.java b/src/main/java/com/example/tily/roadmap/RoadmapResponse.java index a144a88a..1a6b7f28 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapResponse.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapResponse.java @@ -13,6 +13,7 @@ public class RoadmapResponse { + public record CreateRoadmapDTO(Long id) { public CreateRoadmapDTO(Roadmap roadmap) { this(roadmap.getId()); diff --git a/src/main/java/com/example/tily/roadmap/RoadmapService.java b/src/main/java/com/example/tily/roadmap/RoadmapService.java index f3b02231..6d42c58e 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapService.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapService.java @@ -20,9 +20,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; import java.util.*; import java.util.stream.Collectors; @@ -30,6 +27,7 @@ @RequiredArgsConstructor @Service public class RoadmapService { + private final RoadmapRepository roadmapRepository; private final StepRepository stepRepository; private final ReferenceRepository referenceRepository; @@ -38,10 +36,9 @@ public class RoadmapService { private final UserStepRepository userStepRepository; private final CommentRepository commentRepository; - // 로드맵 생성하기 + // 로드맵 생성하기(개인, 그룹) @Transactional public RoadmapResponse.CreateRoadmapDTO createRoadmap(RoadmapRequest.CreateRoadmapDTO requestDTO, User user){ - Roadmap roadmap = Roadmap.builder() .creator(user) .category(Category.getCategory(requestDTO.category())) @@ -70,7 +67,6 @@ public RoadmapResponse.CreateRoadmapDTO createRoadmap(RoadmapRequest.CreateRoadm // 틸리 로드맵 생성하기 - 임시 api @Transactional public RoadmapResponse.CreateRoadmapDTO createTilyRoadmap(RoadmapRequest.CreateTilyRoadmapDTO requestDTO, User user){ - Roadmap roadmap = Roadmap.builder() .creator(user) .category(Category.CATEGORY_TILY) @@ -138,7 +134,7 @@ public RoadmapResponse.CreateRoadmapDTO createTilyRoadmap(RoadmapRequest.CreateT } // 로드맵 정보 조회하기 - public RoadmapResponse.FindGroupRoadmapDTO findGroupRoadmap(Long id, User user){ + public RoadmapResponse.FindGroupRoadmapDTO findRoadmap(Long id, User user){ Roadmap roadmap = roadmapRepository.findById(id) .orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); @@ -194,7 +190,7 @@ else if(reference.getCategory().equals("web")){ // 그룹 로드맵 정보 수정하기 @Transactional - public void updateGroupRoadmap(Long id, RoadmapRequest.UpdateGroupRoadmapDTO requestDTO, User user){ + public void updateRoadmap(Long id, RoadmapRequest.UpdateGroupRoadmapDTO requestDTO, User user){ checkMasterAndManagerPermission(id ,user); Roadmap roadmap = roadmapRepository.findById(id) @@ -206,7 +202,6 @@ public void updateGroupRoadmap(Long id, RoadmapRequest.UpdateGroupRoadmapDTO req // 내가 속한 로드맵 전체 목록 조회하기 public RoadmapResponse.FindAllMyRoadmapDTO findAllMyRoadmaps(User user) { - List roadmaps = userRoadmapRepository.findByUserIdAndIsAccept(user.getId(), true); // 내가 속한 로드맵 조회 List categories = roadmaps.stream() @@ -230,7 +225,6 @@ public RoadmapResponse.FindAllMyRoadmapDTO findAllMyRoadmaps(User user) { // 로드맵 조회하기 public RoadmapResponse.FindRoadmapByQueryDTO findAll(String category, String name, int page, int size) { - // 생성일자를 기준으로 내림차순 Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "createdDate")); diff --git a/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java b/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java index baf1dc9b..973a69c9 100644 --- a/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java +++ b/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java @@ -19,6 +19,7 @@ @SQLDelete(sql = "UPDATE user_roadmap_tb SET is_deleted = true WHERE id = ?") @Where(clause = "is_deleted = false") public class UserRoadmap extends BaseTimeEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; diff --git a/src/main/java/com/example/tily/step/StepRepository.java b/src/main/java/com/example/tily/step/StepRepository.java index dd9fce5d..fc17be9e 100644 --- a/src/main/java/com/example/tily/step/StepRepository.java +++ b/src/main/java/com/example/tily/step/StepRepository.java @@ -9,10 +9,6 @@ import java.util.Optional; public interface StepRepository extends JpaRepository { - //List findByRoadmapId(Long id); - - //@Query("select s from Step s join fetch s.roadmap where s.id=:id") - //Optional findById(Long id); @Query("select s from Step s join fetch s.roadmap where s.id=:stepId") Optional findById(@Param("stepId") Long stepId); diff --git a/src/main/java/com/example/tily/step/StepResponse.java b/src/main/java/com/example/tily/step/StepResponse.java index 051fbef0..833d008d 100644 --- a/src/main/java/com/example/tily/step/StepResponse.java +++ b/src/main/java/com/example/tily/step/StepResponse.java @@ -6,6 +6,7 @@ public class StepResponse { + public record CreateStepDTO(Long id) { public CreateStepDTO(Step step) { this(step.getId()); diff --git a/src/main/java/com/example/tily/step/reference/ReferenceRepository.java b/src/main/java/com/example/tily/step/reference/ReferenceRepository.java index 36e0bf4e..9414ef60 100644 --- a/src/main/java/com/example/tily/step/reference/ReferenceRepository.java +++ b/src/main/java/com/example/tily/step/reference/ReferenceRepository.java @@ -7,6 +7,7 @@ import java.util.List; public interface ReferenceRepository extends JpaRepository { + List findByStepId(Long stepId); @Modifying diff --git a/src/main/java/com/example/tily/step/reference/ReferenceRequest.java b/src/main/java/com/example/tily/step/reference/ReferenceRequest.java index c7f5fac1..875f5a27 100644 --- a/src/main/java/com/example/tily/step/reference/ReferenceRequest.java +++ b/src/main/java/com/example/tily/step/reference/ReferenceRequest.java @@ -3,6 +3,7 @@ import java.time.LocalDateTime; public class ReferenceRequest { + public record FindReferenceDTO(Long stepId){ } From c443270c983fbc80c3db9330819dc40fd4f99a48 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Thu, 9 Nov 2023 16:00:43 +0900 Subject: [PATCH 02/19] =?UTF-8?q?fix:=20roadmap=20request=20DTO=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tily/roadmap/RoadmapController.java | 26 +++++++++---------- .../example/tily/roadmap/RoadmapResponse.java | 4 +-- .../example/tily/roadmap/RoadmapService.java | 8 +++--- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/example/tily/roadmap/RoadmapController.java b/src/main/java/com/example/tily/roadmap/RoadmapController.java index fc8c4055..aa487b05 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapController.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapController.java @@ -34,16 +34,16 @@ public ResponseEntity createTilyRoadmap(@RequestBody @Valid RoadmapRequest.Cr return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } - // 틸리, 그룹 로드맵 정보 조회하기 + // 로드맵 정보 조회하기 (틸리, 그룹) @GetMapping("/roadmaps/{id}") public ResponseEntity findRoadmap(@PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){ User user = Optional.ofNullable(userDetails).map(CustomUserDetails::getUser).orElse(null); - RoadmapResponse.FindGroupRoadmapDTO responseDTO = roadmapService.findRoadmap(id, user); + RoadmapResponse.FindRoadmapDTO responseDTO = roadmapService.findRoadmap(id, user); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } - // 그룹 로드맵 정보 수정하기 + // 로드맵 정보 수정하기 @PatchMapping("/roadmaps/{id}") public ResponseEntity updateRoadmap(@RequestBody @Valid RoadmapRequest.UpdateGroupRoadmapDTO requestDTO, Errors errors, @PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){ @@ -51,6 +51,13 @@ public ResponseEntity updateRoadmap(@RequestBody @Valid RoadmapRequest.Update return ResponseEntity.ok().body(ApiUtils.success(null)); } + // 로드맵 삭제 + @DeleteMapping("/roadmaps/{id}") + public ResponseEntity deleteRoadmap(@PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){ + roadmapService.deleteRoadmap(id, userDetails.getUser()); + return ResponseEntity.ok().body(ApiUtils.success(null)); + } + // 내가 속한 로드맵 전체 목록 조회하기 @GetMapping("/roadmaps/my") public ResponseEntity findAllMyRoadmaps(@AuthenticationPrincipal CustomUserDetails userDetails) { @@ -84,7 +91,7 @@ public ResponseEntity applyTilyRoadmap(@PathVariable("tilyId") Long tilyId, @ return ResponseEntity.ok().body(ApiUtils.success(null)); } - // 참가 코드로 로드맵 참여하기 + // 참가 코드로 그룹 로드맵 참여하기 @PostMapping("/roadmaps/groups/participate") public ResponseEntity participateRoadmap(@RequestBody @Valid RoadmapRequest.ParticipateRoadmapDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails){ @@ -92,14 +99,14 @@ public ResponseEntity participateRoadmap(@RequestBody @Valid RoadmapRequest.P return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } - // 로드맵의 구성원 전체 조회하기 + // 그룹 로드맵의 구성원 전체 조회하기 @GetMapping("/roadmaps/groups/{groupId}/members") public ResponseEntity findRoadmapMembers(@PathVariable Long groupId, @AuthenticationPrincipal CustomUserDetails userDetails){ RoadmapResponse.FindRoadmapMembersDTO responseDTO = roadmapService.findRoadmapMembers(groupId, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } - // 로드맵의 구성원 역할 바꾸기 + // 그룹 로드맵의 구성원 역할 바꾸기 @PatchMapping("/roadmaps/groups/{groupId}/members/{memberId}") public ResponseEntity changeMemberRole(@RequestBody @Valid RoadmapRequest.ChangeMemberRoleDTO requestDTO, Errors errors, @PathVariable Long groupId, @PathVariable Long memberId, @@ -135,11 +142,4 @@ public ResponseEntity rejectApplication(@PathVariable Long groupId, @PathVari roadmapService.rejectApplication(groupId, memberId, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(null)); } - - // 로드맵 삭제 - @DeleteMapping("/roadmaps/{id}") - public ResponseEntity deleteRoadmap(@PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){ - roadmapService.deleteRoadmap(id, userDetails.getUser()); - return ResponseEntity.ok().body(ApiUtils.success(null)); - } } \ No newline at end of file diff --git a/src/main/java/com/example/tily/roadmap/RoadmapResponse.java b/src/main/java/com/example/tily/roadmap/RoadmapResponse.java index 1a6b7f28..f627aded 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapResponse.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapResponse.java @@ -20,8 +20,8 @@ public CreateRoadmapDTO(Roadmap roadmap) { } } - public record FindGroupRoadmapDTO(Creator creator, String name, String description, String myRole, Long recentTilId, Long recentStepId, boolean isPublic, boolean isRecruit, String code, String category, List steps) { - public FindGroupRoadmapDTO(Roadmap roadmap, List steps, User user, Long recentTilId, Long recentStepId, String myRole) { + public record FindRoadmapDTO(Creator creator, String name, String description, String myRole, Long recentTilId, Long recentStepId, boolean isPublic, boolean isRecruit, String code, String category, List steps) { + public FindRoadmapDTO(Roadmap roadmap, List steps, User user, Long recentTilId, Long recentStepId, String myRole) { this(new Creator(user.getName(), user.getImage()), roadmap.getName(), roadmap.getDescription(), myRole, recentTilId, recentStepId, roadmap.isPublic(), roadmap.isRecruit(), roadmap.getCode(), roadmap.getCategory().getValue(), steps); } diff --git a/src/main/java/com/example/tily/roadmap/RoadmapService.java b/src/main/java/com/example/tily/roadmap/RoadmapService.java index 6d42c58e..d81078f6 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapService.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapService.java @@ -134,7 +134,7 @@ public RoadmapResponse.CreateRoadmapDTO createTilyRoadmap(RoadmapRequest.CreateT } // 로드맵 정보 조회하기 - public RoadmapResponse.FindGroupRoadmapDTO findRoadmap(Long id, User user){ + public RoadmapResponse.FindRoadmapDTO findRoadmap(Long id, User user){ Roadmap roadmap = roadmapRepository.findById(id) .orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); @@ -162,8 +162,8 @@ else if(reference.getCategory().equals("web")){ webMap.put(step.getId(), webList); } - List steps = stepList.stream() - .map(step -> new RoadmapResponse.FindGroupRoadmapDTO.StepDTO(step + List steps = stepList.stream() + .map(step -> new RoadmapResponse.FindRoadmapDTO.StepDTO(step , youtubeMap.get(step.getId()).stream() .map(RoadmapResponse.ReferenceDTOs.ReferenceDTO::new).collect(Collectors.toList()) , webMap.get(step.getId()).stream() @@ -185,7 +185,7 @@ else if(reference.getCategory().equals("web")){ } } - return new RoadmapResponse.FindGroupRoadmapDTO(roadmap, steps, roadmap.getCreator(), recentTilId, recentStepId, myRole); + return new RoadmapResponse.FindRoadmapDTO(roadmap, steps, roadmap.getCreator(), recentTilId, recentStepId, myRole); } // 그룹 로드맵 정보 수정하기 From 2798a2062244e523066c15c609796d776615a420 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Thu, 9 Nov 2023 16:09:02 +0900 Subject: [PATCH 03/19] =?UTF-8?q?fix:=20roadmap=20response=20DTO=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dump.rdb | Bin 307 -> 0 bytes .../java/com/example/tily/roadmap/Roadmap.java | 5 +---- .../example/tily/roadmap/RoadmapController.java | 2 +- .../example/tily/roadmap/RoadmapRequest.java | 16 +--------------- .../example/tily/roadmap/RoadmapService.java | 2 +- .../tily/roadmap/RoadmapControllerTest.java | 14 ++++++-------- 6 files changed, 10 insertions(+), 29 deletions(-) delete mode 100644 dump.rdb diff --git a/dump.rdb b/dump.rdb deleted file mode 100644 index 1fe5f01b625937770878233d8d06ee8749cdbcad..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 307 zcmXAhL2iOT007a%#P-%(KLG&@q1>cma95C61uYlD%C@`6N)#mEsY!p)cl6Lp6XU6W z=mYwI9-3g&R@385CUes@z(^D&sXANZkfwZ&*9}#W1-Ux^7l>x*u3a_e8D)6?T3EPh zZc-fb472^i#|2k4gXE4!L5g?W4|k~5zMuBt<7J)WxLv*dhD#{osZJdV`<^tURtFMf z&QA>7ty|a>YQizvh7)j-36hoN&{RmsywYNW9F0H z>b7h{FYIwwc8pjP?wyQu@@!GU*_9ahN{uKfL?_U^#HY diff --git a/src/main/java/com/example/tily/roadmap/Roadmap.java b/src/main/java/com/example/tily/roadmap/Roadmap.java index edc49683..41c3d029 100644 --- a/src/main/java/com/example/tily/roadmap/Roadmap.java +++ b/src/main/java/com/example/tily/roadmap/Roadmap.java @@ -1,7 +1,6 @@ package com.example.tily.roadmap; import com.example.tily.BaseTimeEntity; -import com.example.tily.roadmap.relation.UserRoadmap; import com.example.tily.user.User; import lombok.AccessLevel; import lombok.Builder; @@ -11,8 +10,6 @@ import org.hibernate.annotations.Where; import javax.persistence.*; -import java.util.ArrayList; -import java.util.List; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -76,7 +73,7 @@ public Roadmap(Long id, User creator, Category category, String name, String des this.image = image; } - public void update(RoadmapRequest.UpdateGroupRoadmapDTO roadmap){ + public void update(RoadmapRequest.UpdateRoadmapDTO roadmap){ this.name = roadmap.name(); this.description = roadmap.description(); this.isPublic = roadmap.isPublic(); diff --git a/src/main/java/com/example/tily/roadmap/RoadmapController.java b/src/main/java/com/example/tily/roadmap/RoadmapController.java index aa487b05..1331f0a8 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapController.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapController.java @@ -45,7 +45,7 @@ public ResponseEntity findRoadmap(@PathVariable Long id, @AuthenticationPrinc // 로드맵 정보 수정하기 @PatchMapping("/roadmaps/{id}") - public ResponseEntity updateRoadmap(@RequestBody @Valid RoadmapRequest.UpdateGroupRoadmapDTO requestDTO, Errors errors, + public ResponseEntity updateRoadmap(@RequestBody @Valid RoadmapRequest.UpdateRoadmapDTO requestDTO, Errors errors, @PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){ roadmapService.updateRoadmap(id, requestDTO, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(null)); diff --git a/src/main/java/com/example/tily/roadmap/RoadmapRequest.java b/src/main/java/com/example/tily/roadmap/RoadmapRequest.java index 68f3e02c..1a26bbe9 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapRequest.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapRequest.java @@ -1,27 +1,13 @@ package com.example.tily.roadmap; -import com.example.tily.roadmap.relation.GroupRole; - import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import java.time.LocalDateTime; import java.util.List; public class RoadmapRequest { - public record CreateIndividualRoadmapDTO( - @NotBlank(message = "이름을 입력해주세요.") - @Size(min=2, max=20, message = "이름은 2자에서 20자 이내여야 합니다.") - String name - ) { } - public record CreateGroupRoadmapDTO( - String name, - String description, - boolean isPublic - ) { } - public record CreateRoadmapDTO ( String category, @NotBlank(message = "이름을 입력해주세요.") @@ -36,7 +22,7 @@ public record CreateTilyRoadmapDTO( List steps ) { } - public record UpdateGroupRoadmapDTO( + public record UpdateRoadmapDTO( String name, String description, boolean isPublic, diff --git a/src/main/java/com/example/tily/roadmap/RoadmapService.java b/src/main/java/com/example/tily/roadmap/RoadmapService.java index d81078f6..c0f611e0 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapService.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapService.java @@ -190,7 +190,7 @@ else if(reference.getCategory().equals("web")){ // 그룹 로드맵 정보 수정하기 @Transactional - public void updateRoadmap(Long id, RoadmapRequest.UpdateGroupRoadmapDTO requestDTO, User user){ + public void updateRoadmap(Long id, RoadmapRequest.UpdateRoadmapDTO requestDTO, User user){ checkMasterAndManagerPermission(id ,user); Roadmap roadmap = roadmapRepository.findById(id) diff --git a/src/test/java/com/example/tily/roadmap/RoadmapControllerTest.java b/src/test/java/com/example/tily/roadmap/RoadmapControllerTest.java index 37c9b884..e6a15997 100644 --- a/src/test/java/com/example/tily/roadmap/RoadmapControllerTest.java +++ b/src/test/java/com/example/tily/roadmap/RoadmapControllerTest.java @@ -12,8 +12,6 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; -import java.time.LocalDate; -import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -38,7 +36,7 @@ public void roadmap_individual_create_success_test() throws Exception { // given String name = "hong"; - RoadmapRequest.CreateIndividualRoadmapDTO requestDTO = new RoadmapRequest.CreateIndividualRoadmapDTO(name); + RoadmapRequest.CreateRoadmapDTO requestDTO = new RoadmapRequest.CreateRoadmapDTO(name); String requestBody = om.writeValueAsString(requestDTO); @@ -60,7 +58,7 @@ public void roadmap_individual_create_fail_test() throws Exception { // given String name = ""; - RoadmapRequest.CreateIndividualRoadmapDTO requestDTO = new RoadmapRequest.CreateIndividualRoadmapDTO(name); + RoadmapRequest.CreateRoadmapDTO requestDTO = new RoadmapRequest.CreateRoadmapDTO(name); String requestBody = om.writeValueAsString(requestDTO); @@ -108,7 +106,7 @@ public void roadmap_group_create_success_test() throws Exception { // 로드맵 RoadmapRequest.RoadmapDTO roadmap = new RoadmapRequest.RoadmapDTO("운영체제(OS) 스터디", "면접 대비를 위한 CS 스터디 모임입니다!", null, true, null); - RoadmapRequest.CreateGroupRoadmapDTO requestDTO = new RoadmapRequest.CreateGroupRoadmapDTO(roadmap, steps); + RoadmapRequest.CreateRoadmapDTO requestDTO = new RoadmapRequest.CreateRoadmapDTO(roadmap, steps); String requestBody = om.writeValueAsString(requestDTO); @@ -157,7 +155,7 @@ public void roadmap_group_create_fail_test() throws Exception { // 로드맵 RoadmapRequest.RoadmapDTO roadmap = new RoadmapRequest.RoadmapDTO(null, "면접 대비를 위한 CS 스터디 모임입니다!", null, true, null); - RoadmapRequest.CreateGroupRoadmapDTO requestDTO = new RoadmapRequest.CreateGroupRoadmapDTO(roadmap, steps); + RoadmapRequest.CreateRoadmapDTO requestDTO = new RoadmapRequest.CreateRoadmapDTO(roadmap, steps); String requestBody = om.writeValueAsString(requestDTO); @@ -244,7 +242,7 @@ public void roadmap_group_update_success_test() throws Exception { // 로드맵 RoadmapRequest.RoadmapDTO roadmap = new RoadmapRequest.RoadmapDTO("new JAVA - 생활 코딩", "새로운 버젼 입니다", "modifiedCode1234", false, true); - RoadmapRequest.UpdateGroupRoadmapDTO requestDTO = new RoadmapRequest.UpdateGroupRoadmapDTO(roadmap, steps); + RoadmapRequest.UpdateRoadmapDTO requestDTO = new RoadmapRequest.UpdateRoadmapDTO(null,"새로운 버젼 입니다", true, true ); String requestBody = om.writeValueAsString(requestDTO); @@ -290,7 +288,7 @@ public void roadmap_group_update_fail_test() throws Exception { // 로드맵 RoadmapRequest.RoadmapDTO roadmap = new RoadmapRequest.RoadmapDTO(null, "새로운 버젼 입니다", "modifiedCode1234", false, true); - RoadmapRequest.UpdateGroupRoadmapDTO requestDTO = new RoadmapRequest.UpdateGroupRoadmapDTO(roadmap, steps); + RoadmapRequest.UpdateRoadmapDTO requestDTO = new RoadmapRequest.UpdateRoadmapDTO(null,"새로운 버젼 입니다", true, true ); String requestBody = om.writeValueAsString(requestDTO); From ad8948438858a58b5776931d66af70f3314a1009 Mon Sep 17 00:00:00 2001 From: suuding Date: Thu, 9 Nov 2023 17:44:40 +0900 Subject: [PATCH 04/19] =?UTF-8?q?feat=20:=20reference=20api=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tily/step/reference/ReferenceController.java | 6 +++--- .../example/tily/step/reference/ReferenceRequest.java | 10 +++++----- .../example/tily/step/reference/ReferenceService.java | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/example/tily/step/reference/ReferenceController.java b/src/main/java/com/example/tily/step/reference/ReferenceController.java index aebf0291..1a8b2de2 100644 --- a/src/main/java/com/example/tily/step/reference/ReferenceController.java +++ b/src/main/java/com/example/tily/step/reference/ReferenceController.java @@ -27,10 +27,10 @@ public ResponseEntity createReference(@RequestBody @Valid ReferenceRequest.Cr } // step의 참고자료 목록 조회 - @GetMapping("/references") - public ResponseEntity findReference(@RequestBody @Valid ReferenceRequest.FindReferenceDTO requestDTO, + @GetMapping("/steps/{stepId}/references") + public ResponseEntity findReference(@PathVariable("stepId") Long stepId, @AuthenticationPrincipal CustomUserDetails userDetails){ - StepResponse.FindReferenceDTO responseDTO = referenceService.findReference(requestDTO, userDetails.getUser()); + StepResponse.FindReferenceDTO responseDTO = referenceService.findReference(stepId, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } diff --git a/src/main/java/com/example/tily/step/reference/ReferenceRequest.java b/src/main/java/com/example/tily/step/reference/ReferenceRequest.java index c7f5fac1..671fd168 100644 --- a/src/main/java/com/example/tily/step/reference/ReferenceRequest.java +++ b/src/main/java/com/example/tily/step/reference/ReferenceRequest.java @@ -3,9 +3,9 @@ import java.time.LocalDateTime; public class ReferenceRequest { - public record FindReferenceDTO(Long stepId){ - } - - public record CreateReferenceDTO(Long stepId, String category, String link) { - } + public record CreateReferenceDTO( + Long stepId, + String category, + String link + ) { } } diff --git a/src/main/java/com/example/tily/step/reference/ReferenceService.java b/src/main/java/com/example/tily/step/reference/ReferenceService.java index ae1158ef..6ec6f95d 100644 --- a/src/main/java/com/example/tily/step/reference/ReferenceService.java +++ b/src/main/java/com/example/tily/step/reference/ReferenceService.java @@ -43,8 +43,8 @@ public void createReference(ReferenceRequest.CreateReferenceDTO requestDTO, User } // step의 참고자료 목록 조회하기 - public StepResponse.FindReferenceDTO findReference(ReferenceRequest.FindReferenceDTO requestDTO, User user){ - Long stepId = requestDTO.stepId(); + public StepResponse.FindReferenceDTO findReference(Long stepId, User user){ + Step step = getStepById(stepId); List references = referenceRepository.findByStepId(stepId); From 9727763b0be781be66325426daca030d07e4570c Mon Sep 17 00:00:00 2001 From: suuding Date: Thu, 9 Nov 2023 17:45:05 +0900 Subject: [PATCH 05/19] =?UTF-8?q?fix=20:=20code,=20isPublic=20=EA=B0=92=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/roadmap/RoadmapService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/tily/roadmap/RoadmapService.java b/src/main/java/com/example/tily/roadmap/RoadmapService.java index f3b02231..7165ee3f 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapService.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapService.java @@ -49,8 +49,8 @@ public RoadmapResponse.CreateRoadmapDTO createRoadmap(RoadmapRequest.CreateRoadm .description(requestDTO.description()) .isPublic(requestDTO.isPublic()) // 공개여부 .currentNum(1L) - .code(requestDTO.category().equals(Category.CATEGORY_TILY.getValue()) ? generateRandomCode() : null) - .isRecruit(requestDTO.category().equals(Category.CATEGORY_TILY.getValue())) // 모집여부 + .code(requestDTO.category().equals(Category.CATEGORY_GROUP.getValue()) ? generateRandomCode() : null) + .isRecruit(!requestDTO.category().equals(Category.CATEGORY_INDIVIDUAL.getValue())) // 모집여부 .stepNum(0) .build(); roadmapRepository.save(roadmap); From 7a22948333cec0a2a33d297baa896bc559adec97 Mon Sep 17 00:00:00 2001 From: suuding Date: Thu, 9 Nov 2023 17:45:40 +0900 Subject: [PATCH 06/19] =?UTF-8?q?fix=20:=20=EB=A1=9C=EB=93=9C=EB=A7=B5?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EA=B5=AC=EC=84=B1=EC=9B=90=20=EA=B0=95?= =?UTF-8?q?=ED=87=B4=EC=8B=9C=20isAccept=EB=8F=84=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/tily/roadmap/RoadmapService.java | 2 +- .../com/example/tily/roadmap/relation/UserRoadmap.java | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/tily/roadmap/RoadmapService.java b/src/main/java/com/example/tily/roadmap/RoadmapService.java index 7165ee3f..30cc8370 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapService.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapService.java @@ -376,7 +376,7 @@ public void dismissMember(Long groupsId, Long membersId, User user){ if (role.equals(GroupRole.ROLE_MANAGER.getValue()) & userRoadmap.getRole().equals(GroupRole.ROLE_MASTER.getValue())) throw new CustomException(ExceptionCode.ROADMAP_DISMISS_FORBIDDEN); - userRoadmap.updateRole(GroupRole.ROLE_NONE.getValue()); + userRoadmap.updateRoleAndIsAccept(GroupRole.ROLE_NONE.getValue(), false); } public RoadmapResponse.FindAppliedUsersDTO findAppliedUsers(Long groupsId, User user){ diff --git a/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java b/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java index baf1dc9b..32d49116 100644 --- a/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java +++ b/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java @@ -56,7 +56,14 @@ public UserRoadmap(Roadmap roadmap, User user, String content, boolean isAccept, this.progress = progress; } - public void updateRole(String role) { this.role = role; } + public void updateRole(String role) { + this.role = role; + } + + public void updateRoleAndIsAccept(String role, boolean isAccept) { + this.role = role; + this.isAccept = isAccept; + } public void updateIsAccept(boolean isAccept) { this.isAccept = isAccept; } From fb1e7d256949e6dee5d7f67be9db0c19d615349b Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Thu, 9 Nov 2023 18:40:06 +0900 Subject: [PATCH 07/19] =?UTF-8?q?fix:=20=EC=A3=BC=EC=84=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/tily/roadmap/RoadmapController.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/tily/roadmap/RoadmapController.java b/src/main/java/com/example/tily/roadmap/RoadmapController.java index 1331f0a8..ccbeac5f 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapController.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapController.java @@ -115,28 +115,28 @@ public ResponseEntity changeMemberRole(@RequestBody @Valid RoadmapRequest.Cha return ResponseEntity.ok().body(ApiUtils.success(null)); } - // 로드맵의 구성원 강퇴하기 + // 그룹 로드맵의 구성원 강퇴하기 @DeleteMapping("/roadmaps/groups/{groupId}/members/{memberId}") public ResponseEntity dismissMember(@PathVariable Long groupId, @PathVariable Long memberId, @AuthenticationPrincipal CustomUserDetails userDetails){ roadmapService.dismissMember(groupId, memberId, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(null)); } - // 로드맵에 신청한 사람들 목록 조회하기 + // 그룹 로드맵에 신청한 사람들 목록 조회하기 @GetMapping("/roadmaps/groups/{groupId}/members/apply") public ResponseEntity findAppliedUsers(@PathVariable Long groupId, @AuthenticationPrincipal CustomUserDetails userDetails){ RoadmapResponse.FindAppliedUsersDTO responseDTO = roadmapService.findAppliedUsers(groupId, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } - // 로드맵 참여 신청 승인 + // 그룹 로드맵 참여 신청 승인 @PostMapping("/roadmaps/groups/{groupId}/members/{memberId}/accept") public ResponseEntity acceptApplication(@PathVariable Long groupId, @PathVariable Long memberId, @AuthenticationPrincipal CustomUserDetails userDetails){ roadmapService.acceptApplication(groupId, memberId, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(null)); } - // 로드맵 참여 신청 거절 + // 그룹 로드맵 참여 신청 거절 @DeleteMapping("/roadmaps/groups/{groupId}/members/{memberId}/reject") public ResponseEntity rejectApplication(@PathVariable Long groupId, @PathVariable Long memberId, @AuthenticationPrincipal CustomUserDetails userDetails){ roadmapService.rejectApplication(groupId, memberId, userDetails.getUser()); From 4444a6c7c23b74c54d46b8601fac8e1c1e21c34f Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Thu, 9 Nov 2023 19:43:11 +0900 Subject: [PATCH 08/19] =?UTF-8?q?fix:=20DTO=20=EB=9D=84=EC=96=B4=EC=93=B0?= =?UTF-8?q?=EA=B8=B0=20=EC=BB=A8=EB=B2=A4=EC=85=98=20=EB=A7=9E=EC=B6=94?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/tily/alarm/AlarmRequest.java | 1 - .../com/example/tily/alarm/AlarmResponse.java | 8 +- .../example/tily/comment/CommentRequest.java | 5 +- .../example/tily/roadmap/RoadmapResponse.java | 118 +++++++++++++++--- .../com/example/tily/step/StepResponse.java | 25 +++- .../com/example/tily/til/TilResponse.java | 38 +++++- .../com/example/tily/user/UserResponse.java | 10 +- 7 files changed, 167 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/example/tily/alarm/AlarmRequest.java b/src/main/java/com/example/tily/alarm/AlarmRequest.java index 0fe3ee75..a5639a21 100644 --- a/src/main/java/com/example/tily/alarm/AlarmRequest.java +++ b/src/main/java/com/example/tily/alarm/AlarmRequest.java @@ -5,7 +5,6 @@ public class AlarmRequest { public record ReadAlarmDTO(List alarms) { - public record AlarmDTO(Long id) { } } diff --git a/src/main/java/com/example/tily/alarm/AlarmResponse.java b/src/main/java/com/example/tily/alarm/AlarmResponse.java index 620fe6b2..c9550223 100644 --- a/src/main/java/com/example/tily/alarm/AlarmResponse.java +++ b/src/main/java/com/example/tily/alarm/AlarmResponse.java @@ -10,7 +10,8 @@ public class AlarmResponse { public record RoadmapDTO(Long id, String name) { public RoadmapDTO(Roadmap roadmap) { - this(roadmap.getId(), roadmap.getName()); + this(roadmap.getId(), roadmap.getName() + ); } } @@ -41,10 +42,11 @@ public AlarmDTO(Alarm alarm){ alarm.getCreatedDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), new RoadmapDTO(alarm.getTil().getRoadmap()), new StepDTO(alarm.getTil().getStep()), - new SenderDTO(alarm.getComment().getWriter())); + new SenderDTO(alarm.getComment().getWriter()) + ); } } - public record FindAllDTO(List alarms) { + public record FindAllDTO(List alarms) { } } diff --git a/src/main/java/com/example/tily/comment/CommentRequest.java b/src/main/java/com/example/tily/comment/CommentRequest.java index 229dbd9c..1472dd70 100644 --- a/src/main/java/com/example/tily/comment/CommentRequest.java +++ b/src/main/java/com/example/tily/comment/CommentRequest.java @@ -4,7 +4,10 @@ public class CommentRequest { - public record CreateCommentDTO(Long roadmapId, Long stepId, Long tilId, @NotBlank(message = "댓글 내용을 입력해주세요.") String content) { + public record CreateCommentDTO(Long roadmapId, + Long stepId, + Long tilId, + @NotBlank(message = "댓글 내용을 입력해주세요.") String content) { } public record UpdateCommentDTO(@NotBlank(message = "댓글 내용을 입력해주세요.") String content) { diff --git a/src/main/java/com/example/tily/roadmap/RoadmapResponse.java b/src/main/java/com/example/tily/roadmap/RoadmapResponse.java index f627aded..2fc6e2eb 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapResponse.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapResponse.java @@ -20,17 +20,45 @@ public CreateRoadmapDTO(Roadmap roadmap) { } } - public record FindRoadmapDTO(Creator creator, String name, String description, String myRole, Long recentTilId, Long recentStepId, boolean isPublic, boolean isRecruit, String code, String category, List steps) { + public record FindRoadmapDTO(Creator creator, + String name, + String description, + String myRole, + Long recentTilId, + Long recentStepId, + boolean isPublic, + boolean isRecruit, + String code, + String category, + List steps) { public FindRoadmapDTO(Roadmap roadmap, List steps, User user, Long recentTilId, Long recentStepId, String myRole) { - this(new Creator(user.getName(), user.getImage()), roadmap.getName(), roadmap.getDescription(), myRole, recentTilId, recentStepId, roadmap.isPublic(), roadmap.isRecruit(), roadmap.getCode(), roadmap.getCategory().getValue(), steps); + this(new Creator(user.getName(), + user.getImage()), + roadmap.getName(), + roadmap.getDescription(), + myRole, + recentTilId, + recentStepId, + roadmap.isPublic(), + roadmap.isRecruit(), + roadmap.getCode(), + roadmap.getCategory().getValue(), + steps); } public record Creator(String name, String image) {} - public record StepDTO(Long id, String title, String description, String dueDate, ReferenceDTOs references) { + public record StepDTO(Long id, + String title, + String description, + String dueDate, + ReferenceDTOs references) { public StepDTO(Step step, List youtubeList, List webList) { - this(step.getId(), step.getTitle(), step.getDescription(), step.getDueDate()!=null ? DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(step.getDueDate()) : null, new ReferenceDTOs(youtubeList, webList)); + this(step.getId(), + step.getTitle(), + step.getDescription(), + step.getDueDate()!=null ? DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(step.getDueDate()) : null, new ReferenceDTOs(youtubeList, webList)); } } } @@ -53,32 +81,64 @@ public CategoryDTO(Roadmap roadmap) { public record RoadmapDTO(List tilys, List groups) {} } - public record TilyDTO (Long id, String name, String image, int stepNum, String description) { + public record TilyDTO (Long id, + String name, + String image, + int stepNum, + String description) { public TilyDTO(Roadmap roadmap) { - this(roadmap.getId(), roadmap.getName(), roadmap.getImage(), roadmap.getStepNum(), roadmap.getDescription()); + this(roadmap.getId(), + roadmap.getName(), + roadmap.getImage(), + roadmap.getStepNum(), + roadmap.getDescription()); } } - public record GroupDTO (Long id, String name, int stepNum, Creator creator, boolean isManager, String description) { + public record GroupDTO (Long id, String name, + int stepNum, Creator creator, + boolean isManager, + String description) { public GroupDTO(Roadmap roadmap, boolean isManager) { - this(roadmap.getId(), roadmap.getName(), roadmap.getStepNum(), new Creator(roadmap.getCreator()), isManager, roadmap.getDescription()); + this(roadmap.getId(), + roadmap.getName(), + roadmap.getStepNum(), + new Creator(roadmap.getCreator()), + isManager, + roadmap.getDescription()); } - public record Creator(Long id, String name, String image) { + public record Creator(Long id, + String name, + String image) { public Creator(User user) { - this(user.getId(), user.getName(), user.getImage()); + this(user.getId(), + user.getName(), + user.getImage()); } } } - public record FindRoadmapByQueryDTO (String category, List roadmaps, boolean hasNext) { + public record FindRoadmapByQueryDTO (String category, + List roadmaps, + boolean hasNext) { public FindRoadmapByQueryDTO(Category category, List roadmaps, boolean hasNext) { - this(category.getValue(), roadmaps, hasNext); + this(category.getValue(), + roadmaps, + hasNext); } - public record RoadmapDTO (Long id, String name, String description, int stepNum, GroupDTO.Creator creator) { + public record RoadmapDTO (Long id, + String name, + String description, + int stepNum, + GroupDTO.Creator creator) { public RoadmapDTO(Roadmap roadmap) { - this(roadmap.getId(), roadmap.getName(), roadmap.getDescription(), roadmap.getStepNum(), new GroupDTO.Creator(roadmap.getCreator())); + this(roadmap.getId(), + roadmap.getName(), + roadmap.getDescription(), + roadmap.getStepNum(), + new GroupDTO.Creator(roadmap.getCreator())); } } } @@ -90,23 +150,43 @@ public ParticipateRoadmapDTO(Roadmap roadmap) { } public record FindRoadmapMembersDTO(String myRole, List users) { - public record UserDTO(Long id, String name, String image, String role) { + public record UserDTO(Long id, + String name, + String image, + String role) { public UserDTO(User user, String role) { - this(user.getId(), user.getName(), user.getImage(), role); + this(user.getId(), + user.getName(), + user.getImage(), + role); } } } public record FindAppliedUsersDTO(List users) { - public record UserDTO(Long id, String name, String image, LocalDate date, String content) { + public record UserDTO(Long id, + String name, + String image, + LocalDate date, + String content) { public UserDTO(User user, UserRoadmap userRoadmap) { - this(user.getId(), user.getName(), user.getImage(), userRoadmap.getCreatedDate().toLocalDate(), userRoadmap.getContent()); + this(user.getId(), + user.getName(), + user.getImage(), + userRoadmap.getCreatedDate().toLocalDate(), + userRoadmap.getContent()); } } } public record FindTilOfStepDTO(List members) { - public record MemberDTO(Long tilId, Long userId, String name, String image, String content, LocalDateTime submitDate, Integer commentNum) { + public record MemberDTO(Long tilId, + Long userId, + String name, + String image, + String content, + LocalDateTime submitDate, + Integer commentNum) { public MemberDTO(Til til, User user) { this( diff --git a/src/main/java/com/example/tily/step/StepResponse.java b/src/main/java/com/example/tily/step/StepResponse.java index 833d008d..9afdb218 100644 --- a/src/main/java/com/example/tily/step/StepResponse.java +++ b/src/main/java/com/example/tily/step/StepResponse.java @@ -13,9 +13,15 @@ public CreateStepDTO(Step step) { } } - public record FindReferenceDTO(Long id, String description, List youtubes, List webs) { + public record FindReferenceDTO(Long id, + String description, + List youtubes, + List webs) { public FindReferenceDTO(Step step, List youtubeDTOs, List webDTOs) { - this(step.getId(), step.getDescription(), youtubeDTOs, webDTOs); + this(step.getId(), + step.getDescription(), + youtubeDTOs, + webDTOs); } public record YoutubeDTO(Long id, String link) {} @@ -23,11 +29,18 @@ public record YoutubeDTO(Long id, String link) {} public record WebDTO(Long id, String link) {} } - public record FindAllStepDTO(List steps, int progress, String myRole) { - - public record StepDTO(Long id, String title, boolean isSubmit, Long tilId) { + public record FindAllStepDTO(List steps, + int progress, + String myRole) { + public record StepDTO(Long id, + String title, + boolean isSubmit, + Long tilId) { public StepDTO(Step step, Til til) { - this(step.getId(), step.getTitle(), til==null ? false : (til.getSubmitContent()!=null), til==null ? null : til.getId()); + this(step.getId(), + step.getTitle(), + til==null ? false : (til.getSubmitContent()!=null), + til==null ? null : til.getId()); } } } diff --git a/src/main/java/com/example/tily/til/TilResponse.java b/src/main/java/com/example/tily/til/TilResponse.java index 79e41187..718cbc59 100644 --- a/src/main/java/com/example/tily/til/TilResponse.java +++ b/src/main/java/com/example/tily/til/TilResponse.java @@ -22,9 +22,20 @@ public CreateTilDTO(Til til) { } } - public record ViewDTO(String content, String submitContent, boolean isPersonal, boolean isSubmit, String roadmapName, StepDTO step, List comments) { + public record ViewDTO(String content, + String submitContent, + boolean isPersonal, + boolean isSubmit, + String roadmapName, + StepDTO step, + List comments) { public ViewDTO(Step step, Til til, boolean isSubmit, List comments) { - this(til.getContent(), til.getSubmitContent(), til.isPersonal(), isSubmit, step.getRoadmap().getName(), new StepDTO(step), comments); + this(til.getContent(), + til.getSubmitContent(), + til.isPersonal(), + isSubmit, + step.getRoadmap().getName(), + new StepDTO(step), comments); } public record StepDTO(Long id, String title) { @@ -33,9 +44,18 @@ public StepDTO(Step step) { } } - public record CommentDTO(Long id, String content, String name, String image, boolean isOwner, String createDate) { + public record CommentDTO(Long id, + String content, + String name, + String image, + boolean isOwner, + String createDate) { public CommentDTO(Comment comment, boolean isOwner) { - this(comment.getId(), comment.getContent(), comment.getWriter().getName(), comment.getWriter().getImage(), isOwner, + this(comment.getId(), + comment.getContent(), + comment.getWriter().getName(), + comment.getWriter().getImage(), + isOwner, comment.getCreatedDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); } } @@ -43,9 +63,15 @@ public CommentDTO(Comment comment, boolean isOwner) { public record FindAllDTO(List tils, boolean hasNext) {} - public record TilDTO(Long id, String createDate, StepDTO step, RoadmapDTO roadmap) { + public record TilDTO(Long id, + String createDate, + StepDTO step, + RoadmapDTO roadmap) { public TilDTO(Til til, Step step, Roadmap roadmap) { - this(til.getId(), til.getCreatedDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), new StepDTO(step), new RoadmapDTO(roadmap)); + this(til.getId(), + til.getCreatedDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), + new StepDTO(step), + new RoadmapDTO(roadmap)); } public record StepDTO(Long id, String title) { diff --git a/src/main/java/com/example/tily/user/UserResponse.java b/src/main/java/com/example/tily/user/UserResponse.java index 687902cd..acd40a62 100644 --- a/src/main/java/com/example/tily/user/UserResponse.java +++ b/src/main/java/com/example/tily/user/UserResponse.java @@ -14,9 +14,15 @@ public record ViewGardensDTO(List gardens) { public record GardenDTO(String day, int value) {} } - public record UserDTO(Long id, String name, String email, String image) { + public record UserDTO(Long id, + String name, + String email, + String image) { public UserDTO(User user) { - this(user.getId(), user.getName(), user.getEmail(), user.getImage()); + this(user.getId(), + user.getName(), + user.getEmail(), + user.getImage()); } } } From 3936f37228414d98eb20b11ab51e78079ffabfea Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Thu, 9 Nov 2023 19:46:52 +0900 Subject: [PATCH 09/19] =?UTF-8?q?fix:=20builder=20=EB=9D=84=EC=96=B4?= =?UTF-8?q?=EC=93=B0=EA=B8=B0=20=EC=BB=A8=EB=B2=A4=EC=85=98=20=EB=A7=9E?= =?UTF-8?q?=EC=B6=94=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/tily/comment/CommentService.java | 15 +++++++++++++-- .../com/example/tily/roadmap/RoadmapService.java | 12 ++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/tily/comment/CommentService.java b/src/main/java/com/example/tily/comment/CommentService.java index c69fc429..c0494e0a 100644 --- a/src/main/java/com/example/tily/comment/CommentService.java +++ b/src/main/java/com/example/tily/comment/CommentService.java @@ -44,11 +44,22 @@ public CommentResponse.CreateCommentDTO createComment(CommentRequest.CreateComme String content = requestDTO.content(); - Comment comment = Comment.builder().roadmap(roadmap).step(step).writer(user).til(til).content(content).build(); + Comment comment = Comment.builder(). + roadmap(roadmap). + step(step). + writer(user). + til(til). + content(content). + build(); commentRepository.save(comment); // 댓글 작성하면 알림 생성 - Alarm alarm = Alarm.builder().til(til).receiver(til.getWriter()).comment(comment).isRead(false).build(); + Alarm alarm = Alarm.builder(). + til(til). + receiver(til.getWriter()). + comment(comment). + isRead(false). + build(); alarmRepository.save(alarm); return new CommentResponse.CreateCommentDTO(comment); diff --git a/src/main/java/com/example/tily/roadmap/RoadmapService.java b/src/main/java/com/example/tily/roadmap/RoadmapService.java index 36b94b5f..2430a714 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapService.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapService.java @@ -107,14 +107,22 @@ public RoadmapResponse.CreateRoadmapDTO createTilyRoadmap(RoadmapRequest.CreateT // (1) youtube List youtubeDTOs = referenceDTOs.youtube(); for(RoadmapRequest.ReferenceDTO youtubeDTO : youtubeDTOs){ - Reference reference = Reference.builder().step(step).category("youtube").link(youtubeDTO.link()).build(); + Reference reference = Reference.builder(). + step(step). + category("youtube"). + link(youtubeDTO.link()). + build(); references.add(reference); } // (2) reference List webDTOs = referenceDTOs.web(); for(RoadmapRequest.ReferenceDTO webDTO : webDTOs){ - Reference reference = Reference.builder().step(step).category("web").link(webDTO.link()).build(); + Reference reference = Reference.builder(). + step(step). + category("web"). + link(webDTO.link()). + build(); references.add(reference); } From 7f2362a23ef93e334703c8c1e388aad808c27d59 Mon Sep 17 00:00:00 2001 From: suuding Date: Fri, 10 Nov 2023 00:21:13 +0900 Subject: [PATCH 10/19] =?UTF-8?q?=20fix=20:=20=EB=8C=93=EA=B8=80=20?= =?UTF-8?q?=EC=88=98=20=EC=A6=9D=EA=B0=80=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/comment/CommentService.java | 3 +++ src/main/java/com/example/tily/til/Til.java | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/main/java/com/example/tily/comment/CommentService.java b/src/main/java/com/example/tily/comment/CommentService.java index 5763c3b1..239e51a2 100644 --- a/src/main/java/com/example/tily/comment/CommentService.java +++ b/src/main/java/com/example/tily/comment/CommentService.java @@ -50,6 +50,9 @@ public CommentResponse.CreateCommentDTO createComment(CommentRequest.CreateComme Alarm alarm = Alarm.builder().til(til).receiver(til.getWriter()).comment(comment).isRead(false).build(); alarmRepository.save(alarm); + // til내 댓글 갯수 증가 + til.addCommentNum(); + return new CommentResponse.CreateCommentDTO(comment); } diff --git a/src/main/java/com/example/tily/til/Til.java b/src/main/java/com/example/tily/til/Til.java index 634e742f..0bfa3075 100644 --- a/src/main/java/com/example/tily/til/Til.java +++ b/src/main/java/com/example/tily/til/Til.java @@ -78,6 +78,10 @@ public void updateTitle (String title) { this.title = title; } + public void addCommentNum () { + this.commentNum++; + } + public void submitTil(String submitContent) { this.content = submitContent; this.submitContent = submitContent; From 42d134e959e2507b5eecee231d0694074ba04a7a Mon Sep 17 00:00:00 2001 From: suuding Date: Fri, 10 Nov 2023 00:21:37 +0900 Subject: [PATCH 11/19] =?UTF-8?q?fix=20:=20step=20=EC=88=98=20=EC=A6=9D?= =?UTF-8?q?=EA=B0=80=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/roadmap/Roadmap.java | 4 ++++ src/main/java/com/example/tily/roadmap/RoadmapController.java | 4 ++-- src/main/java/com/example/tily/step/StepService.java | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/tily/roadmap/Roadmap.java b/src/main/java/com/example/tily/roadmap/Roadmap.java index c402d197..d2c37929 100644 --- a/src/main/java/com/example/tily/roadmap/Roadmap.java +++ b/src/main/java/com/example/tily/roadmap/Roadmap.java @@ -82,5 +82,9 @@ public void update(RoadmapRequest.UpdateGroupRoadmapDTO roadmap){ this.isRecruit = roadmap.isRecruit(); } + public void addStepNum() { + this.stepNum++; + } + public void updateImage (String image) {this.image = image; } } \ No newline at end of file diff --git a/src/main/java/com/example/tily/roadmap/RoadmapController.java b/src/main/java/com/example/tily/roadmap/RoadmapController.java index 37b60627..9b4bf763 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapController.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapController.java @@ -21,7 +21,7 @@ public class RoadmapController { // 로드맵 생성하기 @PostMapping("/roadmaps") public ResponseEntity createRoadmap(@RequestBody @Valid RoadmapRequest.CreateRoadmapDTO requestDTO, Errors errors, - @AuthenticationPrincipal CustomUserDetails userDetails){ + @AuthenticationPrincipal CustomUserDetails userDetails){ RoadmapResponse.CreateRoadmapDTO responseDTO = roadmapService.createRoadmap(requestDTO, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } @@ -29,7 +29,7 @@ public ResponseEntity createRoadmap(@RequestBody @Valid RoadmapRequest.Create // 틸리 로드맵 생성하기 - 임시 api @PostMapping("/roadmaps/tily") public ResponseEntity createTilyRoadmap(@RequestBody @Valid RoadmapRequest.CreateTilyRoadmapDTO requestDTO, Errors errors, - @AuthenticationPrincipal CustomUserDetails userDetails){ + @AuthenticationPrincipal CustomUserDetails userDetails){ RoadmapResponse.CreateRoadmapDTO responseDTO = roadmapService.createTilyRoadmap(requestDTO, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index 9b4a9294..ba07c27f 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -67,6 +67,8 @@ public StepResponse.CreateStepDTO createStep(StepRequest.CreateStepDTO requestDT userStepRepository.save(userStep); } + roadmap.addStepNum(); + return new StepResponse.CreateStepDTO(step); } From dd13b4d58d06773d68750edc8a7fb17beaec228a Mon Sep 17 00:00:00 2001 From: suuding Date: Fri, 10 Nov 2023 01:43:22 +0900 Subject: [PATCH 12/19] =?UTF-8?q?fix=20:=20til=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20DTO=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/til/TilResponse.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/tily/til/TilResponse.java b/src/main/java/com/example/tily/til/TilResponse.java index 79e41187..4961f533 100644 --- a/src/main/java/com/example/tily/til/TilResponse.java +++ b/src/main/java/com/example/tily/til/TilResponse.java @@ -54,9 +54,9 @@ public StepDTO(Step step) { } } - public record RoadmapDTO(Long id, String name) { + public record RoadmapDTO(Long id, String name, String category) { public RoadmapDTO(Roadmap roadmap) { - this(roadmap.getId(), roadmap.getName()); + this(roadmap.getId(), roadmap.getName(), roadmap.getCategory().getValue()); } } } From ced5ee6870da3539efae668c765fc0209d713973 Mon Sep 17 00:00:00 2001 From: suuding Date: Fri, 10 Nov 2023 01:54:03 +0900 Subject: [PATCH 13/19] =?UTF-8?q?fix=20:=20=EC=83=9D=EC=84=B1=EB=82=A0?= =?UTF-8?q?=EC=A7=9C=209=EC=8B=9C=EA=B0=84=20=EB=8D=94=ED=95=B4=EC=84=9C?= =?UTF-8?q?=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/step/StepService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index ba07c27f..9ca5412e 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -52,7 +52,7 @@ public StepResponse.CreateStepDTO createStep(StepRequest.CreateStepDTO requestDT .roadmap(roadmap) .title(requestDTO.title()) .description(requestDTO.description()) - .dueDate(requestDTO.dueDate()) + .dueDate(requestDTO.dueDate()!=null ? requestDTO.dueDate().plusHours(9) : null) .build(); // 개인 로드맵이므로 description, dueDate 는 null stepRepository.save(step); @@ -89,7 +89,7 @@ public void updateStep(Long stepId, StepRequest.UpdateStepDTO requestDTO, User u if (til != null) til.updateTitle(requestDTO.title()); step.updateTitle(requestDTO.title()); } else { // 그룹 로드맵일 때 - step.update(requestDTO.title(), requestDTO.description(), requestDTO.dueDate()); + step.update(requestDTO.title(), requestDTO.description(), requestDTO.dueDate()!=null ? requestDTO.dueDate().plusHours(9) : null); } } From c3201bda30cd9db3c998e25381be3bb2ac327700 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Fri, 10 Nov 2023 13:35:04 +0900 Subject: [PATCH 14/19] =?UTF-8?q?feat:=20reference=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EA=B6=8C=ED=95=9C=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/tily/step/reference/ReferenceService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/tily/step/reference/ReferenceService.java b/src/main/java/com/example/tily/step/reference/ReferenceService.java index 6ec6f95d..6f729011 100644 --- a/src/main/java/com/example/tily/step/reference/ReferenceService.java +++ b/src/main/java/com/example/tily/step/reference/ReferenceService.java @@ -33,6 +33,8 @@ public void createReference(ReferenceRequest.CreateReferenceDTO requestDTO, User Long stepId = requestDTO.stepId(); Step step = getStepById(stepId); + checkMasterAndManagerPermission(step.getRoadmap().getId(), user); // 생성자 혹 매니저만 생성 가능 + Reference reference = Reference.builder() .step(step) .category(requestDTO.category()) @@ -44,7 +46,6 @@ public void createReference(ReferenceRequest.CreateReferenceDTO requestDTO, User // step의 참고자료 목록 조회하기 public StepResponse.FindReferenceDTO findReference(Long stepId, User user){ - Step step = getStepById(stepId); List references = referenceRepository.findByStepId(stepId); @@ -70,7 +71,7 @@ else if(category.equals("web")) public void deleteReference(Long referenceId, User user){ Reference reference = getReferenceById(referenceId); - checkMasterAndManagerPermission(reference.getStep().getRoadmap().getId(), user); // 매니저급만 삭제 가능 + checkMasterAndManagerPermission(reference.getStep().getRoadmap().getId(), user); // 생성자 혹 매니저만 삭제 가능 referenceRepository.softDeleteReferenceById(referenceId); } From 0d36a31e34ba8485e0044b06a537e8c0a672735d Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Fri, 10 Nov 2023 13:57:31 +0900 Subject: [PATCH 15/19] =?UTF-8?q?fix:=20=ED=9A=8C=EC=9B=90=ED=83=88?= =?UTF-8?q?=ED=87=B4=EC=8B=9C=20=EC=95=8C=EB=9E=8C=EB=8F=84=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/tily/alarm/AlarmRepository.java | 3 ++ .../tily/comment/CommentRepository.java | 6 ++++ .../com/example/tily/user/UserService.java | 31 +++++++++++++------ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/example/tily/alarm/AlarmRepository.java b/src/main/java/com/example/tily/alarm/AlarmRepository.java index 1ab6ad12..cac1b4d4 100644 --- a/src/main/java/com/example/tily/alarm/AlarmRepository.java +++ b/src/main/java/com/example/tily/alarm/AlarmRepository.java @@ -16,4 +16,7 @@ public interface AlarmRepository extends JpaRepository { List findAllByReceiverId(@Param("receiverId") Long receiverId, Sort sort); void deleteByCommentId(Long commentId); + + @Query("delete from Alarm a where a.comment.id in :commentIds") + void deleteAlarmsByCommentIds(List commentIds); } diff --git a/src/main/java/com/example/tily/comment/CommentRepository.java b/src/main/java/com/example/tily/comment/CommentRepository.java index 44a96fc5..3d114a5f 100644 --- a/src/main/java/com/example/tily/comment/CommentRepository.java +++ b/src/main/java/com/example/tily/comment/CommentRepository.java @@ -12,10 +12,16 @@ public interface CommentRepository extends JpaRepository { @Query("select c from Comment c join fetch c.writer where c.til.id=:tilId") List findByTilId(@Param("tilId") Long tilId); + List findByUserId(Long userId); + @Modifying @Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.id = :commentId") void softDeleteCommentById(Long commentId); + @Modifying + @Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.id IN :commentIds") + void softDeleteCommentsByIds(List commentIds); + @Modifying @Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.til.id = :tilId") void softDeleteCommentsByTilId(Long tilId); diff --git a/src/main/java/com/example/tily/user/UserService.java b/src/main/java/com/example/tily/user/UserService.java index 25b1b44b..1b50049d 100644 --- a/src/main/java/com/example/tily/user/UserService.java +++ b/src/main/java/com/example/tily/user/UserService.java @@ -5,6 +5,8 @@ import com.auth0.jwt.interfaces.DecodedJWT; import com.example.tily._core.security.JWTProvider; import com.example.tily._core.utils.RedisUtils; +import com.example.tily.alarm.AlarmRepository; +import com.example.tily.comment.Comment; import com.example.tily.comment.CommentRepository; import com.example.tily.roadmap.Category; import com.example.tily.roadmap.Roadmap; @@ -47,6 +49,7 @@ public class UserService { private final CommentRepository commentRepository; private final StepRepository stepRepository; private final ReferenceRepository referenceRepository; + private final AlarmRepository alarmRepository; private String defaultImage = "user/profile-user.jpg"; @@ -183,17 +186,25 @@ public UserResponse.ViewGardensDTO viewGardens(User user) { // 회원 탈퇴하기 public void withdrawMembership(User user){ // 1. 유저가 작성한 Comment들 삭제 + List comments = getCommentByUserId(user.getId()); + List commentIds = comments.stream() + .map(Comment::getId) + .collect(Collectors.toList()); + + commentRepository.softDeleteCommentsByIds(commentIds); + + // 2. Comment들과 관련된 Alarm 삭제 + alarmRepository.deleteAlarmsByCommentIds(commentIds); + + // 3. 유저가 작성한 Til 삭제 List tils = getTilByUserId(user.getId()); List tilIds = tils.stream() .map(Til::getId) .collect(Collectors.toList()); - commentRepository.softDeleteCommentsByTilIds(tilIds); - - // 2. 유저가 작성한 Til 삭제 tilRepository.softDeleteTilsByTilIds(tilIds); - // 3. UserStep들을 삭제 + // 4. UserStep들을 삭제 List userSteps = getUserStepByUserId(user.getId()); List userStepIds = userSteps.stream() .map(UserStep::getId) @@ -201,7 +212,7 @@ public void withdrawMembership(User user){ userStepRepository.softDeleteUserStepByUserStepIds(userStepIds); - // 4. 유저가 만든 Step들을 삭제 + // 5. 유저가 만든 Step들을 삭제 List steps = userSteps.stream() .map(userStep -> userStep.getStep()) .collect(Collectors.toList()); @@ -212,10 +223,10 @@ public void withdrawMembership(User user){ stepRepository.softDeleteStepByStepIds(stepIds); - // 5. 유저가 작성한 Reference들을 삭제 + // 6. 유저가 작성한 Reference들을 삭제 referenceRepository.softDeleteReferenceByStepIds(stepIds); - // 6. UserRoadmap 삭제 + // 7. UserRoadmap 삭제 List userRoadmaps = getUserRoadmapByUserId(user.getId()); List userRoadmapIds = userRoadmaps.stream() .map(UserRoadmap::getId) @@ -223,7 +234,7 @@ public void withdrawMembership(User user){ userRoadmapRepository.softDeleteUserRoadmapByUserRoadmapIds(userRoadmapIds); - // 7. 유저가 만든 로드맵 삭제 + // 8. 유저가 만든 로드맵 삭제 List roadmaps = userRoadmaps.stream() .map(userRoadmap -> userRoadmap.getRoadmap()) .filter(roadmap -> roadmap.getCreator().getId().equals(user.getId())) @@ -235,7 +246,7 @@ public void withdrawMembership(User user){ roadmapRepository.softDeleteRoadmapByRoadmapIds(roadmapIds); - // 8. 유저 삭제 + // 9. 유저 삭제 userRepository.softDeleteUserById(user.getId()); } @@ -324,4 +335,6 @@ private List getUserStepByUserId(Long userId) { private List getTilByUserId(Long userId){ return tilRepository.findByWriterId(userId); } + + private List getCommentByUserId(Long userId){return commentRepository.findByUserId(userId);} } From 1ccf0453f15a3af4cbf0e821804aa6d9ba355df8 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Fri, 10 Nov 2023 14:21:52 +0900 Subject: [PATCH 16/19] =?UTF-8?q?fix:=20=EB=A1=9C=EB=93=9C=EB=A7=B5?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=EC=8B=9C=20=EC=95=8C=EB=9E=8C=EB=8F=84=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/tily/alarm/AlarmRepository.java | 2 +- .../tily/comment/CommentRepository.java | 3 ++ .../example/tily/roadmap/RoadmapService.java | 35 +++++++++++++------ .../com/example/tily/user/UserService.java | 3 +- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/example/tily/alarm/AlarmRepository.java b/src/main/java/com/example/tily/alarm/AlarmRepository.java index cac1b4d4..0bf527be 100644 --- a/src/main/java/com/example/tily/alarm/AlarmRepository.java +++ b/src/main/java/com/example/tily/alarm/AlarmRepository.java @@ -18,5 +18,5 @@ public interface AlarmRepository extends JpaRepository { void deleteByCommentId(Long commentId); @Query("delete from Alarm a where a.comment.id in :commentIds") - void deleteAlarmsByCommentIds(List commentIds); + void deleteByCommentIds(List commentIds); } diff --git a/src/main/java/com/example/tily/comment/CommentRepository.java b/src/main/java/com/example/tily/comment/CommentRepository.java index 3d114a5f..9ddd1770 100644 --- a/src/main/java/com/example/tily/comment/CommentRepository.java +++ b/src/main/java/com/example/tily/comment/CommentRepository.java @@ -14,6 +14,9 @@ public interface CommentRepository extends JpaRepository { List findByUserId(Long userId); + @Query("select c from Comment c where c.til.id in :tilIds") + List findByTilIds(@Param("tilIds") List tilIds); + @Modifying @Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.id = :commentId") void softDeleteCommentById(Long commentId); diff --git a/src/main/java/com/example/tily/roadmap/RoadmapService.java b/src/main/java/com/example/tily/roadmap/RoadmapService.java index 2430a714..1797d807 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapService.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapService.java @@ -2,6 +2,8 @@ import com.example.tily._core.errors.exception.CustomException; import com.example.tily._core.errors.exception.ExceptionCode; +import com.example.tily.alarm.AlarmRepository; +import com.example.tily.comment.Comment; import com.example.tily.comment.CommentRepository; import com.example.tily.roadmap.relation.GroupRole; import com.example.tily.roadmap.relation.UserRoadmap; @@ -35,6 +37,7 @@ public class RoadmapService { private final UserRoadmapRepository userRoadmapRepository; private final UserStepRepository userStepRepository; private final CommentRepository commentRepository; + private final AlarmRepository alarmRepository; // 로드맵 생성하기(개인, 그룹) @Transactional @@ -429,22 +432,28 @@ public void rejectApplication(Long groupId, Long memberId, User user){ @Transactional public void deleteRoadmap(Long roadmapId, User user){ - Roadmap roadmap = getRoadmapById(roadmapId); - checkMasterAndManagerPermission(roadmapId, user); - // 1. Til과 연관된 Comment들을 삭제한다. + // 1. Til을 삭제한다. List tils = getTilsByRoadmapId(roadmapId); List tilIds = tils.stream() .map(Til::getId) .collect(Collectors.toList()); - commentRepository.softDeleteCommentsByTilIds(tilIds); - - // 2. Til을 삭제한다. tilRepository.softDeleteTilsByTilIds(tilIds); - // 3. Reference들을 삭제한다 + // 2. Til과 연관된 Comment들을 삭제한다. + List comments = getCommentsByTilIds(tilIds); + List commentIds = comments.stream() + .map(Comment::getId) + .collect(Collectors.toList()); + + commentRepository.softDeleteCommentsByIds(commentIds); + + // 3. Comment와 관련된 알람을 삭제한다. + alarmRepository.deleteByCommentIds(commentIds); + + // 4. Reference들을 삭제한다. List steps = getStepsByRoadmapId(roadmapId); List stepIds = steps.stream() .map(Step::getId) @@ -452,16 +461,16 @@ public void deleteRoadmap(Long roadmapId, User user){ referenceRepository.softDeleteReferenceByStepIds(stepIds); - // 4. Step들을 삭제한다. + // 5. Step들을 삭제한다. stepRepository.softDeleteStepByStepIds(stepIds); - // 5. UserStep들을 삭제한다. + // 6. UserStep들을 삭제한다. userStepRepository.softDeleteUserStepByStepIds(stepIds); - // 6. UserRoadmap을 삭제한다 + // 7. UserRoadmap을 삭제한다 userRoadmapRepository.softDeleteUserRoadmapByRoadmapId(roadmapId); - // 7. Roadmap을 삭제한다 + // 8. Roadmap을 삭제한다 roadmapRepository.softDeleteRoadmapById(roadmapId); } @@ -527,6 +536,10 @@ private List getTilsByRoadmapId(Long roadmapId){ return tilRepository.findByRoadmapId(roadmapId); } + private List getCommentsByTilIds( List tilIds){ + return commentRepository.findByTilIds(tilIds); + } + // 해당 로드맵에 속하지 않은 user private UserRoadmap getUserNotBelongRoadmap(Long roadmapId, Long userId) { return userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptFalse(roadmapId, userId).orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_FOUND)); diff --git a/src/main/java/com/example/tily/user/UserService.java b/src/main/java/com/example/tily/user/UserService.java index 1b50049d..535d285a 100644 --- a/src/main/java/com/example/tily/user/UserService.java +++ b/src/main/java/com/example/tily/user/UserService.java @@ -8,7 +8,6 @@ import com.example.tily.alarm.AlarmRepository; import com.example.tily.comment.Comment; import com.example.tily.comment.CommentRepository; -import com.example.tily.roadmap.Category; import com.example.tily.roadmap.Roadmap; import com.example.tily.roadmap.RoadmapRepository; import com.example.tily.roadmap.relation.UserRoadmap; @@ -194,7 +193,7 @@ public void withdrawMembership(User user){ commentRepository.softDeleteCommentsByIds(commentIds); // 2. Comment들과 관련된 Alarm 삭제 - alarmRepository.deleteAlarmsByCommentIds(commentIds); + alarmRepository.deleteByCommentIds(commentIds); // 3. 유저가 작성한 Til 삭제 List tils = getTilByUserId(user.getId()); From 1b94067db37e1b269372e024d8e25485d4a9dda2 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Fri, 10 Nov 2023 14:37:45 +0900 Subject: [PATCH 17/19] =?UTF-8?q?fix:=20=EC=88=98=EC=A0=95/=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20JPA=20=ED=95=A8=EC=88=98=EC=97=90=20@Modifing=20?= =?UTF-8?q?=EB=AA=A8=EB=91=90=20=EB=B6=99=EC=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/alarm/AlarmRepository.java | 3 +++ src/main/java/com/example/tily/comment/CommentRepository.java | 4 ++-- src/main/java/com/example/tily/user/UserService.java | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/tily/alarm/AlarmRepository.java b/src/main/java/com/example/tily/alarm/AlarmRepository.java index 0bf527be..80c731e6 100644 --- a/src/main/java/com/example/tily/alarm/AlarmRepository.java +++ b/src/main/java/com/example/tily/alarm/AlarmRepository.java @@ -2,6 +2,7 @@ import org.springframework.data.domain.Sort; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -15,8 +16,10 @@ public interface AlarmRepository extends JpaRepository { "where a.receiver.id=:receiverId and a.comment.writer.id!=:receiverId") List findAllByReceiverId(@Param("receiverId") Long receiverId, Sort sort); + @Modifying void deleteByCommentId(Long commentId); + @Modifying @Query("delete from Alarm a where a.comment.id in :commentIds") void deleteByCommentIds(List commentIds); } diff --git a/src/main/java/com/example/tily/comment/CommentRepository.java b/src/main/java/com/example/tily/comment/CommentRepository.java index 9ddd1770..785678e4 100644 --- a/src/main/java/com/example/tily/comment/CommentRepository.java +++ b/src/main/java/com/example/tily/comment/CommentRepository.java @@ -8,11 +8,11 @@ import java.util.List; public interface CommentRepository extends JpaRepository { - + @Modifying @Query("select c from Comment c join fetch c.writer where c.til.id=:tilId") List findByTilId(@Param("tilId") Long tilId); - List findByUserId(Long userId); + List findByWriterId(Long writerId); @Query("select c from Comment c where c.til.id in :tilIds") List findByTilIds(@Param("tilIds") List tilIds); diff --git a/src/main/java/com/example/tily/user/UserService.java b/src/main/java/com/example/tily/user/UserService.java index 535d285a..275fae6d 100644 --- a/src/main/java/com/example/tily/user/UserService.java +++ b/src/main/java/com/example/tily/user/UserService.java @@ -335,5 +335,5 @@ private List getTilByUserId(Long userId){ return tilRepository.findByWriterId(userId); } - private List getCommentByUserId(Long userId){return commentRepository.findByUserId(userId);} + private List getCommentByUserId(Long userId){return commentRepository.findByWriterId(userId);} } From 6d492ac8e641d0d6a9a41a661510522dc9c50b43 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Fri, 10 Nov 2023 14:45:37 +0900 Subject: [PATCH 18/19] =?UTF-8?q?fix:=20=EC=8A=A4=ED=85=9D=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=EC=8B=9C=20=EC=95=8C=EB=9E=8C=EB=8F=84=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/tily/step/StepService.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index 9ca5412e..fffac82e 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -2,6 +2,8 @@ import com.example.tily._core.errors.exception.ExceptionCode; import com.example.tily._core.errors.exception.CustomException; +import com.example.tily.alarm.AlarmRepository; +import com.example.tily.comment.Comment; import com.example.tily.roadmap.Category; import com.example.tily.comment.CommentRepository; import com.example.tily.roadmap.Roadmap; @@ -34,6 +36,7 @@ public class StepService { private final UserStepRepository userStepRepository; private final CommentRepository commentRepository; private final ReferenceRepository referenceRepository; + private final AlarmRepository alarmRepository; // step 생성하기 @Transactional @@ -121,24 +124,32 @@ public void deleteStep(Long stepId, User user){ checkMasterAndManagerPermission(step.getRoadmap().getId(), user); // 매니저급만 삭제 가능 + // 1. Til을 삭제한다. List tils = getTisByStepId(stepId); List tilIds = tils.stream() .map(Til::getId) .collect(Collectors.toList()); - // 1. Til과 연관된 Comment들을 삭제한다. - commentRepository.softDeleteCommentsByTilIds(tilIds); - - // 2. Til들을 삭제한다 tilRepository.softDeleteTilsByTilIds(tilIds); - // 3. Reference들을 삭제한다. + // 2. Til과 연관된 Comment들을 삭제한다. + List comments = getCommentsByTilIds(tilIds); + List commentIds = comments.stream() + .map(Comment::getId) + .collect(Collectors.toList()); + + commentRepository.softDeleteCommentsByIds(commentIds); + + // 3. Comment와 관련된 알람을 삭제한다. + alarmRepository.deleteByCommentIds(commentIds); + + // 4. Reference들을 삭제한다. referenceRepository.softDeleteReferenceByStepId(stepId); - // 4. UserStep을 삭제한다 + // 5. UserStep을 삭제한다 userStepRepository.softDeleteUserStepByStepId(stepId); - // 5. Step을 삭제한다 + // 6. Step을 삭제한다 stepRepository.softDeleteStepById(stepId); } @@ -164,6 +175,10 @@ private List getTisByStepId(Long stepId){ return tilRepository.findByStepId(stepId); } + private List getCommentsByTilIds( List tilIds){ + return commentRepository.findByTilIds(tilIds); + } + // 해당 로드맵에 속한 user private UserRoadmap getUserBelongRoadmap(Long roadmapId, Long userId) { return userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(roadmapId, userId) From 541584574285cfeb3fa35ccb151f7904d6e0533b Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Fri, 10 Nov 2023 15:02:08 +0900 Subject: [PATCH 19/19] =?UTF-8?q?fix:=20=ED=8B=B8=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=EC=8B=9C=20=EC=95=8C=EB=9E=8C=EB=8F=84=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dump.rdb | Bin 0 -> 307 bytes .../java/com/example/tily/step/StepService.java | 5 ++--- .../java/com/example/tily/til/TilService.java | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 dump.rdb diff --git a/dump.rdb b/dump.rdb new file mode 100644 index 0000000000000000000000000000000000000000..9b39316ae5dc8735b1526abd6c7141cd2b12776b GIT binary patch literal 307 zcmXAhO-{l<07eT53A!_J;U#F=lG1huwgjjAR%mP37^WRz>I{_*Ak!1LbLGk#cnU&X zcmmJC(o}<%xcC;|%geiNT3{$ivYeeHD8#I?MoCE%6;a7f{{h5HwykHSV2LT(y}ox* zR$eg_Rw$yohy9t5l_&9C1x^^+3J2l4Q20U5Z%-FRK@hgZ`Um2+gl-zRkL|W6JGf)o zGuR4_AGoQz>0;Xub14mdaD*{b)Vb4AXCd`?hxXQR2pE{#YuIveKWZ>Q$vuc-o`(p! z%EM8!+O--y-==2~L!6JjRbrVI(x%g@7msMl2P83#D3T+TPN{xL77KqgCP0Z70SuPh o@&|G=t|hAK-s+meYo-R^#FL1ga_o+oFB^})FXx{J<;&jx0gm)=W&i*H literal 0 HcmV?d00001 diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index fffac82e..9b738c65 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -11,7 +11,6 @@ import com.example.tily.roadmap.relation.GroupRole; import com.example.tily.roadmap.relation.UserRoadmap; import com.example.tily.roadmap.relation.UserRoadmapRepository; -import com.example.tily.step.reference.Reference; import com.example.tily.step.reference.ReferenceRepository; import com.example.tily.step.relation.UserStep; import com.example.tily.step.relation.UserStepRepository; @@ -125,7 +124,7 @@ public void deleteStep(Long stepId, User user){ checkMasterAndManagerPermission(step.getRoadmap().getId(), user); // 매니저급만 삭제 가능 // 1. Til을 삭제한다. - List tils = getTisByStepId(stepId); + List tils = getTilsByStepId(stepId); List tilIds = tils.stream() .map(Til::getId) .collect(Collectors.toList()); @@ -171,7 +170,7 @@ private Roadmap getRoadmapById(Long roadmapId) { return roadmapRepository.findById(roadmapId).orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); } - private List getTisByStepId(Long stepId){ + private List getTilsByStepId(Long stepId){ return tilRepository.findByStepId(stepId); } diff --git a/src/main/java/com/example/tily/til/TilService.java b/src/main/java/com/example/tily/til/TilService.java index 620bfd87..7cf29d02 100644 --- a/src/main/java/com/example/tily/til/TilService.java +++ b/src/main/java/com/example/tily/til/TilService.java @@ -3,6 +3,7 @@ import com.example.tily._core.errors.exception.ExceptionCode; import com.example.tily._core.errors.exception.CustomException; +import com.example.tily.alarm.AlarmRepository; import com.example.tily.comment.Comment; import com.example.tily.comment.CommentRepository; import com.example.tily.roadmap.Category; @@ -44,6 +45,7 @@ public class TilService { private final CommentRepository commentRepository; private final UserStepRepository userStepRepository; private final UserRoadmapRepository userRoadmapRepository; + private final AlarmRepository alarmRepository; // til 생성하기 @Transactional @@ -149,15 +151,22 @@ public void submitTil(TilRequest.SubmitTilDTO requestDTO, Long tilId, User user) @Transactional public void deleteTil(Long tilId, User user) { - Til til = getTilById(tilId); checkTilWriterEqualUser(til, user); // 1. Til과 연관된 Comment들을 삭제한다. - commentRepository.softDeleteCommentsByTilId(tilId); + List comments = commentRepository.findByTilId(tilId); + List commentIds = comments.stream() + .map(Comment::getId) + .collect(Collectors.toList()); + + commentRepository.softDeleteCommentsByIds(commentIds); + + // 2. Comment들과 관련된 Alarm 삭제 + alarmRepository.deleteByCommentIds(commentIds); - // 2. Til을 삭제한다. + // 3. Til을 삭제한다. tilRepository.softDeleteTilById(tilId); }