From 822ec27a497e31ba14b0c0bc4ddd54fff9888a6c Mon Sep 17 00:00:00 2001 From: Jeyong Date: Sat, 29 Mar 2025 17:04:56 +0900 Subject: [PATCH 01/12] =?UTF-8?q?[refactor]=20=EB=B9=8C=EB=8D=94=20?= =?UTF-8?q?=ED=8C=A8=ED=84=B4=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Notification/entity/Notification.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Notification/entity/Notification.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Notification/entity/Notification.java index a8e2d04..641e9b9 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Notification/entity/Notification.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Notification/entity/Notification.java @@ -1,20 +1,16 @@ package MathCaptain.weakness.domain.Notification.entity; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import java.time.LocalDateTime; +import java.util.Map; @Entity @Getter -@Builder -@AllArgsConstructor -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) @EntityListeners(AuditingEntityListener.class) public class Notification { @@ -22,12 +18,27 @@ public class Notification { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(nullable = false) private String sender; @CreatedDate private LocalDateTime createdAt; + @Column(nullable = false) private String contents; - + @Builder + private Notification(String sender, LocalDateTime createdAt, String contents) { + this.sender = sender; + this.createdAt = createdAt; + this.contents = contents; + } + + public static Notification of(Map eventData) { + return Notification.builder() + .sender(eventData.get("sender")) + .createdAt(LocalDateTime.parse(eventData.get("createdAt"))) + .contents(eventData.get("message")) + .build(); + } } From f4214aed0eabf08805121174b812d2d5ba1f0324 Mon Sep 17 00:00:00 2001 From: Jeyong Date: Sat, 29 Mar 2025 17:05:11 +0900 Subject: [PATCH 02/12] =?UTF-8?q?[refactor]=20=EB=B9=8C=EB=8D=94=20?= =?UTF-8?q?=ED=8C=A8=ED=84=B4=20=EC=A0=81=EC=9A=A9=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/NotificationService.java | 88 ++++++++----------- 1 file changed, 39 insertions(+), 49 deletions(-) diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Notification/service/NotificationService.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Notification/service/NotificationService.java index f6c00d6..8b373c1 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Notification/service/NotificationService.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Notification/service/NotificationService.java @@ -43,9 +43,7 @@ public SseEmitter subscribe(Long userId) { } catch (IOException e) { e.printStackTrace(); } - NotificationController.sseEmitters.put(userId, sseEmitter); - sseEmitter.onCompletion(() -> NotificationController.sseEmitters.remove(userId)); sseEmitter.onTimeout(() -> NotificationController.sseEmitters.remove(userId)); sseEmitter.onError((e) -> NotificationController.sseEmitters.remove(userId)); @@ -54,29 +52,22 @@ public SseEmitter subscribe(Long userId) { } public void notifyComment(Long recruitmentId, Long commentId) { - Recruitment recruitment = recruitmentRepository.findById(recruitmentId) - .orElseThrow(() -> new IllegalArgumentException("해당 모집글이 존재하지 않습니다.")); - - Comment comment = commentRepository.findById(commentId) - .orElseThrow(() -> new IllegalArgumentException("해당 댓글이 존재하지 않습니다.")); + Recruitment recruitment = findRecruitmentBy(recruitmentId); + Comment comment = findCommentBy(commentId); Long userId = recruitment.getAuthor().getUserId(); if (NotificationController.sseEmitters.containsKey(userId)) { SseEmitter sseEmitter = NotificationController.sseEmitters.get(userId); try { Map eventData = buildNotificationData("댓글이 달렸습니다.", comment.getAuthor().getNickname(), comment.getCommentTime().toString(), comment.getContent()); - sseEmitter.send(SseEmitter.event().name("addComment").data(eventData)); - - notificationRepository.save(buildNotification(eventData)); - + Notification notification = Notification.of(eventData); + notificationRepository.save(notification); // 알림 개수 증가 notificationCounts.put(userId, notificationCounts.getOrDefault(userId, 0) + 1); - // 현재 알림 개수 전송 sseEmitter.send(SseEmitter.event().name("notificationCount").data(notificationCounts.get(userId))); - } catch (IOException e) { NotificationController.sseEmitters.remove(userId); } @@ -85,30 +76,22 @@ public void notifyComment(Long recruitmentId, Long commentId) { public void notifyGroupJoinRequest(Long groupId, Users user) { - Group group = groupRepository.findById(groupId) - .orElseThrow(() -> new IllegalArgumentException("해당 그룹이 존재하지 않습니다.")); - - Users leader = relationRepository.findLeaderByGroup(group) - .orElseThrow(() -> new IllegalArgumentException("해당 그룹의 리더가 존재하지 않습니다.")); - + Group group = findGroupBy(groupId); + Users leader = findLeaderBy(group); Long leaderId = leader.getUserId(); if (NotificationController.sseEmitters.containsKey(leaderId)) { SseEmitter sseEmitter = NotificationController.sseEmitters.get(leaderId); try { Map eventData = buildNotificationData("그룹 가입 요청이 있습니다.", user.getNickname(), LocalDateTime.now().toString(), "가입 요청"); - sseEmitter.send(SseEmitter.event().name("groupJoinRequest").data(eventData)); - // DB 저장 - notificationRepository.save(buildNotification(eventData)); - + Notification notification = Notification.of(eventData); + notificationRepository.save(notification); // 알림 개수 증가 updateNotificationCount(leaderId); - // 현재 알림 개수 전송 sseEmitter.send(SseEmitter.event().name("notificationCount").data(notificationCounts.get(leaderId))); - } catch (IOException e) { NotificationController.sseEmitters.remove(leaderId); } @@ -117,30 +100,22 @@ public void notifyGroupJoinRequest(Long groupId, Users user) { } public void notifyGroupJoinResult(Long groupId, Users user) { - Group group = groupRepository.findById(groupId) - .orElseThrow(() -> new IllegalArgumentException("해당 그룹이 존재하지 않습니다.")); - - RelationBetweenUserAndGroup relation = relationRepository.findByMemberAndGroup(user, group) - .orElseThrow(() -> new IllegalArgumentException("해당 관계가 존재하지 않습니다.")); - + Group group = findGroupBy(groupId); + RelationBetweenUserAndGroup relation = findRelationBy(user, group); Long userId = user.getUserId(); if (NotificationController.sseEmitters.containsKey(userId)) { SseEmitter sseEmitter = NotificationController.sseEmitters.get(userId); try { Map eventData = buildNotificationData("그룹 가입 요청 결과가 도착했습니다.", group.getName(), LocalDateTime.now().toString(), relation.getRequestStatus().toString()); - sseEmitter.send(SseEmitter.event().name("groupJoinResult").data(eventData)); - // DB 저장 - notificationRepository.save(buildNotification(eventData)); - + Notification notification = Notification.of(eventData); + notificationRepository.save(notification); // 알림 개수 증가 updateNotificationCount(userId); - // 현재 알림 개수 전송 sseEmitter.send(SseEmitter.event().name("notificationCount").data(notificationCounts.get(userId))); - } catch (IOException e) { NotificationController.sseEmitters.remove(userId); } @@ -148,13 +123,9 @@ public void notifyGroupJoinResult(Long groupId, Users user) { } public ApiResponse deleteNotification(Users loginUser, Long notificationId) { - Notification notification = notificationRepository.findById(notificationId) - .orElseThrow(() -> new IllegalArgumentException("알림을 찾을 수 없습니다.")); - + Notification notification = findNotificationBy(notificationId); Long userId = loginUser.getUserId(); - notificationRepository.delete(notification); - // 알림 개수 감소 if (notificationCounts.containsKey(userId)) { int currentCount = notificationCounts.get(userId); @@ -170,7 +141,6 @@ public ApiResponse deleteNotification(Users loginUser, Long notificationId) { } catch (IOException e) { e.printStackTrace(); } - return ApiResponse.ok("알림이 삭제되었습니다."); } @@ -187,15 +157,35 @@ private void updateNotificationCount(Long userId) { notificationCounts.put(userId, notificationCounts.getOrDefault(userId, 0) + 1); } - private Notification buildNotification(Map eventData) { - return Notification.builder() - .sender(eventData.get("sender")) - .createdAt(LocalDateTime.parse(eventData.get("createdAt"))) - .contents(eventData.get("message")) - .build(); + private Comment findCommentBy(Long commentId) { + return commentRepository.findById(commentId) + .orElseThrow(() -> new IllegalArgumentException("해당 댓글이 존재하지 않습니다.")); } + private Recruitment findRecruitmentBy(Long recruitmentId) { + return recruitmentRepository.findById(recruitmentId) + .orElseThrow(() -> new IllegalArgumentException("해당 모집글이 존재하지 않습니다.")); + } + private Notification findNotificationBy(Long notificationId) { + return notificationRepository.findById(notificationId) + .orElseThrow(() -> new IllegalArgumentException("알림을 찾을 수 없습니다.")); + } + + private RelationBetweenUserAndGroup findRelationBy(Users user, Group group) { + return relationRepository.findByMemberAndGroup(user, group) + .orElseThrow(() -> new IllegalArgumentException("해당 관계가 존재하지 않습니다.")); + } + + private Group findGroupBy(Long groupId) { + return groupRepository.findById(groupId) + .orElseThrow(() -> new IllegalArgumentException("해당 그룹이 존재하지 않습니다.")); + } + + private Users findLeaderBy(Group group) { + return relationRepository.findLeaderByGroup(group) + .orElseThrow(() -> new IllegalArgumentException("해당 그룹의 리더가 존재하지 않습니다.")); + } // 알림 삭제 // public MsgResponseDto deleteNotification(Long id) throws IOException { From 6165cd778e29f5d46510dd3fcfa9bdb5cf7378be Mon Sep 17 00:00:00 2001 From: Jeyong Date: Sat, 29 Mar 2025 17:05:25 +0900 Subject: [PATCH 03/12] =?UTF-8?q?[refactor]=20=EC=BA=A1=EC=8A=90=ED=99=94?= =?UTF-8?q?=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EB=82=B4=EB=B6=80=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/RelationBetweenUserAndGroup.java | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Group/entity/RelationBetweenUserAndGroup.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Group/entity/RelationBetweenUserAndGroup.java index e60cd89..de68e28 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Group/entity/RelationBetweenUserAndGroup.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Group/entity/RelationBetweenUserAndGroup.java @@ -11,6 +11,7 @@ import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import java.time.DayOfWeek; import java.time.LocalDate; @Entity @@ -76,9 +77,9 @@ private RelationBetweenUserAndGroup(Users member, Group group, GroupRole groupRo this.weeklyGoalAchieveStreak = 0; } - public static RelationBetweenUserAndGroup of(Users leader, Group group, int dailyGoal, int weeklyGoal) { + public static RelationBetweenUserAndGroup of(Users member, Group group, int dailyGoal, int weeklyGoal) { return RelationBetweenUserAndGroup.builder() - .member(leader) + .member(member) .groupRole(GroupRole.MEMBER) .group(group) .personalDailyGoal(dailyGoal) @@ -86,9 +87,9 @@ public static RelationBetweenUserAndGroup of(Users leader, Group group, int dail .build(); } - public static RelationBetweenUserAndGroup of(Users member, Group group, GroupCreateRequest groupCreateRequest) { + public static RelationBetweenUserAndGroup of(Users leader, Group group, GroupCreateRequest groupCreateRequest) { return RelationBetweenUserAndGroup.builder() - .member(member) + .member(leader) .groupRole(GroupRole.LEADER) .group(group) .personalDailyGoal(groupCreateRequest.getPersonalDailyGoal()) @@ -125,18 +126,18 @@ public void updatePersonalDailyGoalAchieved(Long personalDailyGoalAchieved) { } // 주간 목표 업데이트 - public void updatePersonalWeeklyGoalAchieved(int personalWeeklyGoalAchieve) { - this.personalWeeklyGoalAchieve = personalWeeklyGoalAchieve; + public void updatePersonalWeeklyGoalAchieved() { + this.personalWeeklyGoalAchieve += 1; } // 주간 목표 달성 연속 횟수 업데이트 - public void updateWeeklyGoalAchieveStreak(int weeklyGoalAchieveStreak) { - this.weeklyGoalAchieveStreak = weeklyGoalAchieveStreak; + public void updateWeeklyGoalAchieveStreak() { + this.weeklyGoalAchieveStreak += 1; } // 일간 목표 초기화 public void resetPersonalDailyGoalAchieve() { - this.personalDailyGoalAchieve = (Long) 0L; + this.personalDailyGoalAchieve = 0L; } // 주간 목표 초기화 @@ -153,4 +154,24 @@ public void updateRequestStatus(RequestStatus requestStatus) { this.requestStatus = requestStatus; } + public void addPoint(Long point) { + this.group.addPoint(point); + this.member.addPoint(point); + } + + public int weeklyAchieveBase() { + return this.getWeeklyGoalAchieveStreak() + this.getPersonalWeeklyGoal(); + } + + public void increaseWeeklyGroupCountOf(DayOfWeek dayOfWeek) { + this.group.increaseWeeklyGoalAchieveMap(dayOfWeek); + } + + public Long remainingDailyGoalMinutes() { + return Math.max(this.getPersonalDailyGoal() * 60L - this.getPersonalDailyGoalAchieve(), 0L); + } + + public int remainingWeeklyGoalDays() { + return Math.max(this.getPersonalWeeklyGoal() - this.getPersonalWeeklyGoalAchieve(), 0); + } } From 532312cacc938ee8c2b6ae4bc92ac7801577b2d0 Mon Sep 17 00:00:00 2001 From: Jeyong Date: Sat, 29 Mar 2025 17:05:44 +0900 Subject: [PATCH 04/12] =?UTF-8?q?[refactor]=20=EB=B9=8C=EB=8D=94=20?= =?UTF-8?q?=ED=8C=A8=ED=84=B4=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/GroupRankingResponse.java | 34 +++++++++++++++++++ .../dto/response/GroupRankingResponseDto.java | 18 ---------- 2 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Ranking/dto/response/GroupRankingResponse.java delete mode 100644 MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Ranking/dto/response/GroupRankingResponseDto.java diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Ranking/dto/response/GroupRankingResponse.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Ranking/dto/response/GroupRankingResponse.java new file mode 100644 index 0000000..8cefaa8 --- /dev/null +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Ranking/dto/response/GroupRankingResponse.java @@ -0,0 +1,34 @@ +package MathCaptain.weakness.domain.Ranking.dto.response; + +import MathCaptain.weakness.domain.Group.entity.Group; +import lombok.*; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class GroupRankingResponse { + + private Long groupId; + + private String groupName; + + private Long groupPoint; + + private int ranking; + + @Builder + private GroupRankingResponse(Long groupId, String groupName, Long groupPoint, int ranking) { + this.groupId = groupId; + this.groupName = groupName; + this.groupPoint = groupPoint; + this.ranking = ranking; + } + + public static GroupRankingResponse of(Group group) { + return GroupRankingResponse.builder() + .groupId(group.getId()) + .groupName(group.getName()) + .groupPoint(group.getGroupPoint()) + .ranking(group.getGroupRanking()) + .build(); + } +} \ No newline at end of file diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Ranking/dto/response/GroupRankingResponseDto.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Ranking/dto/response/GroupRankingResponseDto.java deleted file mode 100644 index 351416f..0000000 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Ranking/dto/response/GroupRankingResponseDto.java +++ /dev/null @@ -1,18 +0,0 @@ -package MathCaptain.weakness.domain.Ranking.dto.response; - -import lombok.Builder; -import lombok.Data; - -@Data -@Builder -public class GroupRankingResponseDto { - - private Long groupId; - - private String groupName; - - private Long groupPoint; - - private int ranking; - -} \ No newline at end of file From 9e2084d37c6c59712ca0c512a702e2631de4c5d3 Mon Sep 17 00:00:00 2001 From: Jeyong Date: Sat, 29 Mar 2025 17:06:16 +0900 Subject: [PATCH 05/12] =?UTF-8?q?[refactor]=20=EB=B9=8C=EB=8D=94=20?= =?UTF-8?q?=ED=8C=A8=ED=84=B4=20=EC=A0=81=EC=9A=A9=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EA=B3=BC=20DTO=20=EB=84=A4=EC=9D=B4=EB=B0=8D?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ranking/controller/RankingController.java | 4 ++-- .../domain/Ranking/service/RankingService.java | 16 +++------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Ranking/controller/RankingController.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Ranking/controller/RankingController.java index 75b2ab3..97391a8 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Ranking/controller/RankingController.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Ranking/controller/RankingController.java @@ -1,6 +1,6 @@ package MathCaptain.weakness.domain.Ranking.controller; -import MathCaptain.weakness.domain.Ranking.dto.response.GroupRankingResponseDto; +import MathCaptain.weakness.domain.Ranking.dto.response.GroupRankingResponse; import MathCaptain.weakness.domain.Ranking.service.RankingService; import MathCaptain.weakness.global.Api.ApiResponse; import lombok.RequiredArgsConstructor; @@ -19,7 +19,7 @@ public class RankingController { // 그룹 랭킹 조회 @GetMapping("/{page}") - public ApiResponse> getGroupRankings( + public ApiResponse> getGroupRankings( @PathVariable("page") int page) { // 페이지 번호를 기반으로 Pageable 생성 Pageable pageable = PageRequest.of(page - 1, 10, Sort.by(Sort.Direction.DESC, "groupPoint")); diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Ranking/service/RankingService.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Ranking/service/RankingService.java index 59846b9..30bbbe4 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Ranking/service/RankingService.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Ranking/service/RankingService.java @@ -2,7 +2,7 @@ import MathCaptain.weakness.domain.Group.entity.Group; import MathCaptain.weakness.domain.Group.repository.GroupRepository; -import MathCaptain.weakness.domain.Ranking.dto.response.GroupRankingResponseDto; +import MathCaptain.weakness.domain.Ranking.dto.response.GroupRankingResponse; import lombok.Builder; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; @@ -20,7 +20,7 @@ public class RankingService { private final GroupRepository groupRepository; - public Page getGroupRankings(Pageable pageable) { + public Page getGroupRankings(Pageable pageable) { // Repository 호출하여 페이징된 데이터 가져오기 Page groupPage = groupRepository.findAllOrderByGroupPoint(pageable); @@ -34,16 +34,6 @@ public Page getGroupRankings(Pageable pageable) { }); // 변경 사항을 데이터베이스에 반영 - return groupPage.map(RankingService::buildGroupRankingResponse); + return groupPage.map(GroupRankingResponse::of); } - - private static GroupRankingResponseDto buildGroupRankingResponse(Group group) { - return GroupRankingResponseDto.builder() - .groupId(group.getId()) - .groupName(group.getName()) - .groupPoint(group.getGroupPoint()) - .ranking(group.getGroupRanking()) - .build(); - } - } \ No newline at end of file From bc536e4dcd6307c1d41b0d120473468f8e138068 Mon Sep 17 00:00:00 2001 From: Jeyong Date: Sat, 29 Mar 2025 17:06:45 +0900 Subject: [PATCH 06/12] =?UTF-8?q?[refactor]=20DTO=20=EB=B9=8C=EB=8D=94=20?= =?UTF-8?q?=ED=8C=A8=ED=84=B4=20=EC=A0=81=EC=9A=A9=20=EB=B0=8F=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Record/controller/RecordController.java | 7 +- ...dRequestDto.java => recordEndRequest.java} | 13 ++-- .../dto/response/RecordSummaryResponse.java | 67 +++++++++++++++++++ .../response/recordSummaryResponseDto.java | 38 ----------- 4 files changed, 75 insertions(+), 50 deletions(-) rename MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/dto/request/{recordEndRequestDto.java => recordEndRequest.java} (53%) create mode 100644 MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/dto/response/RecordSummaryResponse.java delete mode 100644 MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/dto/response/recordSummaryResponseDto.java diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/controller/RecordController.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/controller/RecordController.java index 7e9478d..941b85d 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/controller/RecordController.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/controller/RecordController.java @@ -1,11 +1,12 @@ package MathCaptain.weakness.domain.Record.controller; -import MathCaptain.weakness.domain.Record.dto.request.recordEndRequestDto; -import MathCaptain.weakness.domain.Record.dto.response.recordSummaryResponseDto; +import MathCaptain.weakness.domain.Record.dto.request.recordEndRequest; +import MathCaptain.weakness.domain.Record.dto.response.RecordSummaryResponse; import MathCaptain.weakness.domain.Record.service.RecordService; import MathCaptain.weakness.domain.User.entity.Users; import MathCaptain.weakness.global.Api.ApiResponse; import MathCaptain.weakness.global.annotation.LoginUser; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; @@ -17,7 +18,7 @@ public class RecordController { private final RecordService recordService; @PostMapping("/end/{groupId}") - public ApiResponse endActivity(@LoginUser Users loginUser, @PathVariable Long groupId, @RequestBody recordEndRequestDto requestDto) { + public ApiResponse endActivity(@Valid @LoginUser Users loginUser, @PathVariable Long groupId, @RequestBody recordEndRequest requestDto) { return ApiResponse.ok(recordService.endActivity(loginUser, groupId, requestDto)); } } diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/dto/request/recordEndRequestDto.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/dto/request/recordEndRequest.java similarity index 53% rename from MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/dto/request/recordEndRequestDto.java rename to MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/dto/request/recordEndRequest.java index 292ea28..8f9fb22 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/dto/request/recordEndRequestDto.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/dto/request/recordEndRequest.java @@ -1,17 +1,12 @@ package MathCaptain.weakness.domain.Record.dto.request; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import java.time.LocalDateTime; -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class recordEndRequestDto { +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class recordEndRequest { // 수행 시간 (분) private Long activityTime; diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/dto/response/RecordSummaryResponse.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/dto/response/RecordSummaryResponse.java new file mode 100644 index 0000000..f4bd114 --- /dev/null +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/dto/response/RecordSummaryResponse.java @@ -0,0 +1,67 @@ +package MathCaptain.weakness.domain.Record.dto.response; + +import MathCaptain.weakness.domain.Group.entity.RelationBetweenUserAndGroup; +import MathCaptain.weakness.domain.Record.entity.ActivityRecord; +import lombok.*; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class RecordSummaryResponse { + + // 유저 이름 + private String userName; + + // 그룹 이름 + private String groupName; + + // 수행 시간 + private Long durationInMinutes; + + // 일간 목표 달성 여부 + private boolean dailyGoalAchieved; + + // 주간 목표 달성 여부 + private boolean weeklyGoalAchieved; + + // 일간 목표 달성까지 남은 시간 (분) (달성시 0) + private Long remainingDailyGoalMinutes; + + // 주간 목표 달성까지 남은 일 수 (일) (달성시 0) + private int remainingWeeklyGoalDays; + + // 사용자가 설정한 일간 목표 + private Long personalDailyGoal; + + // 사용자가 설정한 주간 목표 + private int personalWeeklyGoal; + + @Builder + private RecordSummaryResponse(String userName, String groupName, Long durationInMinutes, + boolean dailyGoalAchieved, boolean weeklyGoalAchieved, + Long remainingDailyGoalMinutes, int remainingWeeklyGoalDays, + Long personalDailyGoal, int personalWeeklyGoal) { + this.userName = userName; + this.groupName = groupName; + this.durationInMinutes = durationInMinutes; + this.dailyGoalAchieved = dailyGoalAchieved; + this.weeklyGoalAchieved = weeklyGoalAchieved; + this.remainingDailyGoalMinutes = remainingDailyGoalMinutes; + this.remainingWeeklyGoalDays = remainingWeeklyGoalDays; + this.personalDailyGoal = personalDailyGoal; + this.personalWeeklyGoal = personalWeeklyGoal; + } + + public static RecordSummaryResponse of(ActivityRecord record, RelationBetweenUserAndGroup relation) { + return RecordSummaryResponse.builder() + .userName(record.getUser().getName()) + .groupName(record.getGroup().getName()) + .durationInMinutes(record.getDurationInMinutes()) + .dailyGoalAchieved(record.isDailyGoalAchieved()) + .weeklyGoalAchieved(record.isWeeklyGoalAchieved()) + .remainingDailyGoalMinutes(relation.remainingDailyGoalMinutes()) + .remainingWeeklyGoalDays(relation.remainingWeeklyGoalDays()) + .personalDailyGoal(relation.getPersonalDailyGoal() * 60L) + .personalWeeklyGoal(relation.getPersonalWeeklyGoal()) + .build(); + } +} diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/dto/response/recordSummaryResponseDto.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/dto/response/recordSummaryResponseDto.java deleted file mode 100644 index 8b4f178..0000000 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/dto/response/recordSummaryResponseDto.java +++ /dev/null @@ -1,38 +0,0 @@ -package MathCaptain.weakness.domain.Record.dto.response; - -import lombok.Builder; -import lombok.Data; - -import java.time.Duration; - -@Data -@Builder -public class recordSummaryResponseDto { - - // 유저 이름 - private String userName; - - // 그룹 이름 - private String groupName; - - // 수행 시간 - private Long durationInMinutes; - - // 일간 목표 달성 여부 - private boolean dailyGoalAchieved; - - // 주간 목표 달성 여부 - private boolean weeklyGoalAchieved; - - // 일간 목표 달성까지 남은 시간 (분) (달성시 0) - private Long remainingDailyGoalMinutes; - - // 주간 목표 달성까지 남은 일 수 (일) (달성시 0) - private int remainingWeeklyGoalDays; - - // 사용자가 설정한 일간 목표 - private Long personalDailyGoal; - - // 사용자가 설정한 주간 목표 - private int personalWeeklyGoal; -} From e1dff8765e88e5ca335360428e9be9683eceb390 Mon Sep 17 00:00:00 2001 From: Jeyong Date: Sat, 29 Mar 2025 17:07:02 +0900 Subject: [PATCH 07/12] =?UTF-8?q?[refactor]=20=EB=B9=8C=EB=8D=94=20?= =?UTF-8?q?=ED=8C=A8=ED=84=B4=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/Record/entity/ActivityRecord.java | 62 ++++++++++++------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/entity/ActivityRecord.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/entity/ActivityRecord.java index e182944..16f7cdd 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/entity/ActivityRecord.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/entity/ActivityRecord.java @@ -1,12 +1,11 @@ package MathCaptain.weakness.domain.Record.entity; import MathCaptain.weakness.domain.Group.entity.Group; +import MathCaptain.weakness.domain.Group.entity.RelationBetweenUserAndGroup; +import MathCaptain.weakness.domain.Record.dto.request.recordEndRequest; import MathCaptain.weakness.domain.User.entity.Users; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import org.hibernate.validator.constraints.Range; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -16,9 +15,7 @@ @Getter @Entity(name = "activity_record") -@NoArgsConstructor -@AllArgsConstructor -@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) @EntityListeners(AuditingEntityListener.class) public class ActivityRecord { @@ -40,38 +37,57 @@ public class ActivityRecord { private LocalDateTime endTime; // 인증 종료 시간 @Range(min = 0) + @Column(nullable = false) private Long durationInMinutes; // 활동 시간 (분) private boolean dailyGoalAchieved; // 일간 목표 달성 여부 private boolean weeklyGoalAchieved; // 주간 목표 달성 여부 + @Column(nullable = false) private DayOfWeek dayOfWeek; // 요일 -// @PrePersist -// public void prePersist() { -// this.dailyGoalAchieved = false; -// this.weeklyGoalAchieved = false; -// this.durationInMinutes = 0L; -// } - - public void updateEndTime(LocalDateTime endTime) { + @Builder + private ActivityRecord(Users user, Group group, LocalDateTime startTime, LocalDateTime endTime, Long durationInMinutes, + boolean dailyGoalAchieved, boolean weeklyGoalAchieved, DayOfWeek dayOfWeek) { + this.user = user; + this.group = group; + this.startTime = startTime; this.endTime = endTime; + this.durationInMinutes = durationInMinutes; + this.dailyGoalAchieved = dailyGoalAchieved; + this.weeklyGoalAchieved = weeklyGoalAchieved; + this.dayOfWeek = dayOfWeek; } - public void updateDailyGoalAchieved(boolean dailyGoalAchieved) { - this.dailyGoalAchieved = dailyGoalAchieved; + public static ActivityRecord of(RelationBetweenUserAndGroup relation, recordEndRequest endRequest, DayOfWeek dayOfWeek) { + return ActivityRecord.builder() + .user(relation.getMember()) + .group(relation.getGroup()) + .startTime(endRequest.getStartTime()) + .endTime(endRequest.getEndTime()) + .durationInMinutes(endRequest.getActivityTime()) + .dayOfWeek(dayOfWeek) + .build(); } - public void updateWeeklyGoalAchieved(boolean weeklyGoalAchieved) { - this.weeklyGoalAchieved = weeklyGoalAchieved; + public static ActivityRecord of(Users user, Group group, LocalDateTime startTime, LocalDateTime endTime, + Long activityTime, DayOfWeek dayOfWeek) { + return ActivityRecord.builder() + .user(user) + .group(group) + .startTime(startTime) + .endTime(endTime) + .durationInMinutes(activityTime) + .dayOfWeek(dayOfWeek) + .build(); } - public void updateDayOfWeek(DayOfWeek dayOfWeek) { - this.dayOfWeek = dayOfWeek; + public void updateDailyGoalAchieved(boolean dailyGoalAchieved) { + this.dailyGoalAchieved = dailyGoalAchieved; } - public void updateDurationInMinutes(Long durationInMinutes) { - this.durationInMinutes = durationInMinutes; + public void updateWeeklyGoalAchieved(boolean weeklyGoalAchieved) { + this.weeklyGoalAchieved = weeklyGoalAchieved; } } From 013d7ff072060f34aa658cc0fa6f6f444b7f240c Mon Sep 17 00:00:00 2001 From: Jeyong Date: Sat, 29 Mar 2025 17:07:19 +0900 Subject: [PATCH 08/12] =?UTF-8?q?[refactor]=20=EB=B9=8C=EB=8D=94=20?= =?UTF-8?q?=ED=8C=A8=ED=84=B4=20=EC=A0=81=EC=9A=A9=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/Record/service/RecordService.java | 131 ++++-------------- 1 file changed, 26 insertions(+), 105 deletions(-) diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/service/RecordService.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/service/RecordService.java index 38df108..967f4a0 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/service/RecordService.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Record/service/RecordService.java @@ -4,8 +4,8 @@ import MathCaptain.weakness.domain.Group.entity.RelationBetweenUserAndGroup; import MathCaptain.weakness.domain.Group.repository.RelationRepository; import MathCaptain.weakness.domain.Record.entity.ActivityRecord; -import MathCaptain.weakness.domain.Record.dto.request.recordEndRequestDto; -import MathCaptain.weakness.domain.Record.dto.response.recordSummaryResponseDto; +import MathCaptain.weakness.domain.Record.dto.request.recordEndRequest; +import MathCaptain.weakness.domain.Record.dto.response.RecordSummaryResponse; import MathCaptain.weakness.domain.Record.repository.RecordRepository; import MathCaptain.weakness.domain.User.entity.Users; import MathCaptain.weakness.global.PointSet; @@ -15,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional; import java.time.DayOfWeek; +import java.time.LocalDate; import java.time.LocalDateTime; import java.time.temporal.TemporalAdjusters; import java.util.*; @@ -35,23 +36,14 @@ public class RecordService { /// 기록 // 기록 저장 - public recordSummaryResponseDto endActivity(Users user, Long groupId, recordEndRequestDto endRequest) { - - // 관계 식별 - RelationBetweenUserAndGroup relation = relationRepository.findByMemberAndGroup_Id(user, groupId) - .orElseThrow(() -> new IllegalArgumentException("해당 관계가 존재하지 않습니다.")); - - ActivityRecord record = buildRecord(user, relation, endRequest); - - // 그룹 식별 - Group group = relation.getGroup(); - - // 목표에 수행 결과 빈영 - updateGoalAchieve(user, relation, record, group); + public RecordSummaryResponse endActivity(Users user, Long groupId, recordEndRequest endRequest) { + RelationBetweenUserAndGroup relation = findRelationByMemberAndGroup(user, groupId); + DayOfWeek nowDay = LocalDate.now().getDayOfWeek(); + ActivityRecord record = ActivityRecord.of(relation, endRequest, nowDay); + updateGoalAchieve(relation, record, nowDay); recordRepository.save(record); - - return buildRecordSummaryResponseDto(record, relation, calculateRemainingDailyGoalMinutes(relation), calculateRemainingWeeklyGoal(relation)); + return RecordSummaryResponse.of(record, relation); } // 주간 목표 달성 여부 조회 @@ -62,75 +54,47 @@ public Map getWeeklyGoalStatus(Users user, Group group, Loca // 활동 기록이 있는 요일 조회 List activeDays = recordRepository.findDaysWithActivity(user, group, startOfWeek, endOfWeek); - // 요일별 활동 기록 여부 맵 생성 return createWeeklyGoalStatusMap(activeDays); } + /// 로직 // 일간 목표 달성 여부 확인 private boolean isDailyGoalAchieved(RelationBetweenUserAndGroup relation) { - return relation.getPersonalDailyGoalAchieve() >= relation.getPersonalDailyGoal(); + return relation.isDailyGoalAchieved(); } - private boolean isWeeklyGoalAchieved(RelationBetweenUserAndGroup relation) { - return relation.getPersonalWeeklyGoalAchieve() >= relation.getPersonalWeeklyGoal(); + return relation.isWeeklyGoalAchieved(); } // 그룹의 요일 목표 수행 카운트 증가 - - public void increaseWeeklyGoalAchieveCount(RelationBetweenUserAndGroup relation, ActivityRecord record) { - // 활동 요일 - DayOfWeek dayOfWeek = record.getDayOfWeek(); - Group group = relation.getGroup(); - group.increaseWeeklyGoalAchieveMap(dayOfWeek); - } - private void addPoint(Users user, Group group, Long point) { - // 개인 포인트 획득 (일간 목표 달성) - user.addPoint(point); - - // 그룹 포인트 획득 (일간 목표 달성) - group.addPoint(point); - } - - private void updateGoalAchieve(Users user, RelationBetweenUserAndGroup relation, ActivityRecord record, Group group) { + private void updateGoalAchieve(RelationBetweenUserAndGroup relation, ActivityRecord record, DayOfWeek nowDay) { // 일간 달성 시간 업데이트 (분) relation.updatePersonalDailyGoalAchieved( Optional.ofNullable(relation.getPersonalDailyGoalAchieve()) .orElse(0L) + record.getDurationInMinutes()); - // 일간 목표 시간 달성시 if (isDailyGoalAchieved(relation)) { - // 일간 목표 달성 성공 업데이트 (기록) record.updateDailyGoalAchieved(true); - - // 그룹의 요일 목표 수행 카운트 증가 (그룹) - increaseWeeklyGoalAchieveCount(relation, record); - - // 일간 목표 달성 포인트 획득 - addPoint(user, group, DAILY_GOAL_ACHIEVE); - - // 주간 목표 + 1 (일간 목표 충족시 업데이트) - relation.updatePersonalWeeklyGoalAchieved(relation.getPersonalWeeklyGoalAchieve() + 1); + relation.increaseWeeklyGroupCountOf(nowDay); + addPoint(relation, DAILY_GOAL_ACHIEVE); + relation.updatePersonalWeeklyGoalAchieved(); } - // 주간 목표 달성시 if (isWeeklyGoalAchieved(relation)) { - // 주간 목표 달성 성공 업데이트 (기록) record.updateWeeklyGoalAchieved(true); - - // 주간 목표 달성 스트릭 업데이트 (관계) - relation.updateWeeklyGoalAchieveStreak(relation.getWeeklyGoalAchieveStreak() + 1); - - // 주간 목표 달성 포인트 계산 - Long weeklyAchievePoint = WEEKLY_GOAL_ACHIEVE_BASE * (relation.getWeeklyGoalAchieveStreak() + relation.getPersonalWeeklyGoal()); - - // 주간 목표 달성 포인트 획득 - addPoint(user, group, weeklyAchievePoint); + relation.updateWeeklyGoalAchieveStreak(); + Long weeklyAchievePoint = WEEKLY_GOAL_ACHIEVE_BASE * relation.weeklyAchieveBase(); + addPoint(relation, weeklyAchievePoint); } } + private void addPoint(RelationBetweenUserAndGroup relation, Long point) { + relation.addPoint(point); + } + private LocalDateTime calculateStartOfWeek(LocalDateTime weekStart) { return weekStart.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); } @@ -139,56 +103,13 @@ private Map createWeeklyGoalStatusMap(List active // 모든 요일을 false로 초기화 Map weeklyGoalStatus = Arrays.stream(DayOfWeek.values()) .collect(Collectors.toMap(day -> day, day -> false, (a, b) -> b, () -> new EnumMap<>(DayOfWeek.class))); - // 활동 기록이 있는 요일을 true로 설정 activeDays.forEach(day -> weeklyGoalStatus.put(day, true)); - return weeklyGoalStatus; } - private void checkRemainRecord(Users user, Group group) { - // 기존 미완료된 활동이 있는지 확인 - Optional existingActivity = recordRepository.findByUserAndGroupAndEndTimeIsNull( - user, group); - - if (existingActivity.isPresent()) { - recordRepository.delete(existingActivity.get()); - log.info("기존 미완료된 활동 삭제"); - } - } - - private Long calculateRemainingDailyGoalMinutes(RelationBetweenUserAndGroup relation) { - return Math.max(relation.getPersonalDailyGoal() * 60L - relation.getPersonalDailyGoalAchieve(), 0L); - } - - private int calculateRemainingWeeklyGoal(RelationBetweenUserAndGroup relation) { - return Math.max(relation.getPersonalWeeklyGoal() - relation.getPersonalWeeklyGoalAchieve(), 0); - } - - /// 빌더 - - private recordSummaryResponseDto buildRecordSummaryResponseDto(ActivityRecord activityRecord, RelationBetweenUserAndGroup relation, Long remainingDailyGoalMinutes, int remainingWeeklyGoal) { - return recordSummaryResponseDto.builder() - .userName(activityRecord.getUser().getName()) - .groupName(activityRecord.getGroup().getName()) - .durationInMinutes(activityRecord.getDurationInMinutes()) - .dailyGoalAchieved(activityRecord.isDailyGoalAchieved()) - .weeklyGoalAchieved(activityRecord.isWeeklyGoalAchieved()) - .remainingDailyGoalMinutes(remainingDailyGoalMinutes) - .remainingWeeklyGoalDays(remainingWeeklyGoal) - .personalDailyGoal(relation.getPersonalDailyGoal() * 60L) - .personalWeeklyGoal(relation.getPersonalWeeklyGoal()) - .build(); - } - - private static ActivityRecord buildRecord(Users user, RelationBetweenUserAndGroup relation, recordEndRequestDto endRequest) { - return ActivityRecord.builder() - .user(user) - .group(relation.getGroup()) - .startTime(endRequest.getStartTime()) - .endTime(endRequest.getEndTime()) - .durationInMinutes(endRequest.getActivityTime()) - .dayOfWeek(LocalDateTime.now().getDayOfWeek()) - .build(); + private RelationBetweenUserAndGroup findRelationByMemberAndGroup(Users user, Long groupId) { + return relationRepository.findByMemberAndGroup_Id(user, groupId) + .orElseThrow(() -> new IllegalArgumentException("해당 관계가 존재하지 않습니다.")); } } From 13de9269da0a0aac9a8f73540c46791b31371389 Mon Sep 17 00:00:00 2001 From: Jeyong Date: Sat, 29 Mar 2025 17:07:41 +0900 Subject: [PATCH 09/12] =?UTF-8?q?[refactor]=20DTO=20=EB=B9=8C=EB=8D=94=20?= =?UTF-8?q?=ED=8C=A8=ED=84=B4=20=EC=A0=81=EC=9A=A9=20=EB=B0=8F=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/RecruitmentController.java | 46 +++++++------- ...uestDto.java => CreateCommentRequest.java} | 10 ++- ...Dto.java => CreateRecruitmentRequest.java} | 18 ++++-- ...uestDto.java => UpdateCommentRequest.java} | 12 ++-- ...Dto.java => UpdateRecruitmentRequest.java} | 13 ++-- .../dto/response/CommentResponse.java | 41 +++++++++++++ .../dto/response/CommentResponseDto.java | 21 ------- .../dto/response/CommentSuccessDto.java | 13 ---- .../dto/response/CommentSuccessResponse.java | 26 ++++++++ .../response/RecruitmentCreateResponse.java | 25 ++++++++ .../RecruitmentCreateResponseDto.java | 15 ----- .../response/RecruitmentDetailResponse.java | 61 +++++++++++++++++++ .../RecruitmentDetailResponseDto.java | 32 ---------- .../dto/response/RecruitmentResponse.java | 56 +++++++++++++++++ .../dto/response/RecruitmentResponseDto.java | 29 --------- .../dto/response/RecruitmentSuccessDto.java | 12 ---- 16 files changed, 257 insertions(+), 173 deletions(-) rename MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/{CreateCommentRequestDto.java => CreateCommentRequest.java} (68%) rename MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/{CreateRecruitmentRequestDto.java => CreateRecruitmentRequest.java} (58%) rename MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/{UpdateCommentRequestDto.java => UpdateCommentRequest.java} (60%) rename MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/{UpdateRecruitmentRequestDto.java => UpdateRecruitmentRequest.java} (82%) create mode 100644 MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentResponse.java delete mode 100644 MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentResponseDto.java delete mode 100644 MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentSuccessDto.java create mode 100644 MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentSuccessResponse.java create mode 100644 MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentCreateResponse.java delete mode 100644 MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentCreateResponseDto.java create mode 100644 MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentDetailResponse.java delete mode 100644 MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentDetailResponseDto.java create mode 100644 MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentResponse.java delete mode 100644 MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentResponseDto.java delete mode 100644 MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentSuccessDto.java diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/controller/RecruitmentController.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/controller/RecruitmentController.java index 9d114d3..88a54bf 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/controller/RecruitmentController.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/controller/RecruitmentController.java @@ -1,10 +1,10 @@ package MathCaptain.weakness.domain.Recruitment.controller; import MathCaptain.weakness.domain.Notification.service.NotificationService; -import MathCaptain.weakness.domain.Recruitment.dto.request.CreateCommentRequestDto; -import MathCaptain.weakness.domain.Recruitment.dto.request.CreateRecruitmentRequestDto; -import MathCaptain.weakness.domain.Recruitment.dto.request.UpdateCommentRequestDto; -import MathCaptain.weakness.domain.Recruitment.dto.request.UpdateRecruitmentRequestDto; +import MathCaptain.weakness.domain.Recruitment.dto.request.CreateCommentRequest; +import MathCaptain.weakness.domain.Recruitment.dto.request.CreateRecruitmentRequest; +import MathCaptain.weakness.domain.Recruitment.dto.request.UpdateCommentRequest; +import MathCaptain.weakness.domain.Recruitment.dto.request.UpdateRecruitmentRequest; import MathCaptain.weakness.domain.Recruitment.dto.response.*; import MathCaptain.weakness.domain.Recruitment.service.CommentService; import MathCaptain.weakness.domain.Recruitment.service.RecruitmentService; @@ -32,61 +32,61 @@ public class RecruitmentController { // 모집글 리스트 조회 @GetMapping - public ApiResponse> recruitmentList() { + public ApiResponse> recruitmentList() { return recruitmentService.getAllRecruitments(); } // 모집글 작성 요청 @GetMapping("/create") - public ApiResponse createRecruitmentPage(@LoginUser Users loginUser) { + public ApiResponse createRecruitmentPage(@LoginUser Users loginUser) { return recruitmentService.createRequest(loginUser); } // 모집글 생성 @PostMapping("/create") - public ApiResponse createRecruitment(@Valid @LoginUser Users loginUser, - @RequestBody CreateRecruitmentRequestDto createRecruitmentRequestDto) { - return recruitmentService.createRecruitment(loginUser, createRecruitmentRequestDto); + public ApiResponse createRecruitment(@Valid @LoginUser Users loginUser, + @RequestBody CreateRecruitmentRequest createRecruitmentRequest) { + return recruitmentService.createRecruitment(loginUser, createRecruitmentRequest); } // 모집글 상세 조회 @GetMapping("/{recruitmentId}") - public ApiResponse recruitmentDetailInfo(@PathVariable Long recruitmentId) { + public ApiResponse recruitmentDetailInfo(@PathVariable Long recruitmentId) { return recruitmentService.getRecruitment(recruitmentId); } // 모집글 수정 @PutMapping("/{recruitmentId}") - public ApiResponse updateRecruitment(@Valid @PathVariable Long recruitmentId, @RequestBody UpdateRecruitmentRequestDto updateRecruitmentRequestDto) { - return recruitmentService.updateRecruitment(recruitmentId, updateRecruitmentRequestDto); + public ApiResponse updateRecruitment(@Valid @PathVariable Long recruitmentId, @RequestBody UpdateRecruitmentRequest updateRecruitmentRequest) { + return recruitmentService.updateRecruitment(recruitmentId, updateRecruitmentRequest); } // 모집글 삭제 @DeleteMapping("/{recruitmentId}") - public ApiResponse deleteRecruitment(@PathVariable Long recruitmentId) { + public ApiResponse deleteRecruitment(@PathVariable Long recruitmentId) { return recruitmentService.deleteRecruitment(recruitmentId); } // 댓글 작성 @PostMapping("/comment/{recruitmentId}") - public ApiResponse createComment(@Valid @PathVariable Long recruitmentId, - @LoginUser Users loginUser, - @RequestBody CreateCommentRequestDto createCommentRequestDto) { - CommentSuccessDto commentSuccessDto = commentService.createComment(loginUser, recruitmentId, createCommentRequestDto); - notificationService.notifyComment(recruitmentId, commentSuccessDto.getCommentId()); - return ApiResponse.ok(commentSuccessDto); + public ApiResponse createComment(@Valid @PathVariable Long recruitmentId, + @LoginUser Users loginUser, + @RequestBody CreateCommentRequest createCommentRequest) { + CommentSuccessResponse commentSuccessResponse = commentService.createComment(loginUser, recruitmentId, createCommentRequest); + notificationService.notifyComment(recruitmentId, commentSuccessResponse.getCommentId()); + return ApiResponse.ok(commentSuccessResponse); } // 댓글 수정 @PutMapping("/comment/{recruitmentId}/{commentId}") - public ApiResponse updateComment(@Valid @PathVariable Long recruitmentId, @PathVariable Long commentId, - @RequestBody UpdateCommentRequestDto updateCommentRequestDto) { - return commentService.updateComment(recruitmentId, commentId, updateCommentRequestDto); + public ApiResponse updateComment(@Valid @PathVariable Long recruitmentId, @PathVariable Long commentId, + @RequestBody UpdateCommentRequest updateCommentRequest) { + return commentService.updateComment(recruitmentId, commentId, updateCommentRequest); } // 댓글 삭제 @DeleteMapping("/comment/{recruitmentId}/{commentId}") - public ApiResponse deleteComment(@PathVariable Long recruitmentId, @PathVariable Long commentId) { + public ApiResponse deleteComment(@PathVariable Long recruitmentId, @PathVariable Long commentId) { return commentService.deleteComment(recruitmentId, commentId); } diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/CreateCommentRequestDto.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/CreateCommentRequest.java similarity index 68% rename from MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/CreateCommentRequestDto.java rename to MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/CreateCommentRequest.java index 62bb70c..8778898 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/CreateCommentRequestDto.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/CreateCommentRequest.java @@ -2,13 +2,11 @@ import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; -@Data -@NoArgsConstructor -public class CreateCommentRequestDto { +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class CreateCommentRequest { @NotNull(message = "내용을 입력해주세요!") @NotEmpty(message = "내용을 입력해주세요!") diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/CreateRecruitmentRequestDto.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/CreateRecruitmentRequest.java similarity index 58% rename from MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/CreateRecruitmentRequestDto.java rename to MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/CreateRecruitmentRequest.java index e066410..34fcee2 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/CreateRecruitmentRequestDto.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/CreateRecruitmentRequest.java @@ -3,12 +3,11 @@ import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; -import lombok.Builder; -import lombok.Data; +import lombok.*; -@Data -@Builder -public class CreateRecruitmentRequestDto { +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class CreateRecruitmentRequest { @NotNull(message = "그룹을 입력해주세요!") @NotEmpty(message = "그룹을 입력해주세요!") @@ -23,4 +22,13 @@ public class CreateRecruitmentRequestDto { @NotEmpty(message = "내용을 입력해주세요!") private String content; + private CreateRecruitmentRequest(Long recruitGroupId, String title, String content) { + this.recruitGroupId = recruitGroupId; + this.title = title; + this.content = content; + } + + public static CreateRecruitmentRequest of(Long recruitGroupId, String title, String content) { + return new CreateRecruitmentRequest(recruitGroupId, title, content); + } } diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/UpdateCommentRequestDto.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/UpdateCommentRequest.java similarity index 60% rename from MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/UpdateCommentRequestDto.java rename to MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/UpdateCommentRequest.java index 9793686..fbe6e24 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/UpdateCommentRequestDto.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/UpdateCommentRequest.java @@ -2,15 +2,11 @@ import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; -@Data -@AllArgsConstructor -@NoArgsConstructor -public class UpdateCommentRequestDto { +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class UpdateCommentRequest { @NotNull(message = "댓글을 작성해주세요") @NotEmpty(message = "댓글을 작성해주세요") diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/UpdateRecruitmentRequestDto.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/UpdateRecruitmentRequest.java similarity index 82% rename from MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/UpdateRecruitmentRequestDto.java rename to MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/UpdateRecruitmentRequest.java index 697240a..459fc97 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/UpdateRecruitmentRequestDto.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/request/UpdateRecruitmentRequest.java @@ -4,16 +4,11 @@ import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; -@Builder -@Data -@AllArgsConstructor -@NoArgsConstructor -public class UpdateRecruitmentRequestDto { +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class UpdateRecruitmentRequest { @NotNull(message = "그룹을 입력해주세요!") @NotEmpty(message = "그룹을 입력해주세요!") diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentResponse.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentResponse.java new file mode 100644 index 0000000..fd254f1 --- /dev/null +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentResponse.java @@ -0,0 +1,41 @@ +package MathCaptain.weakness.domain.Recruitment.dto.response; + +import MathCaptain.weakness.domain.Recruitment.entity.Comment; +import lombok.*; + +import java.time.LocalDateTime; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class CommentResponse { + + private Long commentId; + + private String authorName; + + private String content; + + private LocalDateTime createdAt; + + private LocalDateTime updatedAt; + + @Builder + private CommentResponse(Long commentId, String authorName, String content, LocalDateTime createdAt, LocalDateTime updatedAt) { + this.commentId = commentId; + this.authorName = authorName; + this.content = content; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + + public static CommentResponse of(Comment comment) { + return CommentResponse.builder() + .commentId(comment.getCommentId()) + .authorName(comment.getAuthor().getName()) + .authorName(comment.getAuthor().getName()) + .content(comment.getContent()) + .createdAt(comment.getCommentTime()) + .updatedAt(comment.getLastModifiedTime()) + .build(); + } +} diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentResponseDto.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentResponseDto.java deleted file mode 100644 index 1626d27..0000000 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentResponseDto.java +++ /dev/null @@ -1,21 +0,0 @@ -package MathCaptain.weakness.domain.Recruitment.dto.response; - -import lombok.Builder; -import lombok.Data; - -import java.time.LocalDateTime; - -@Data -@Builder -public class CommentResponseDto { - - private Long commentId; - - private String authorName; - - private String content; - - private LocalDateTime createdAt; - - private LocalDateTime updatedAt; -} diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentSuccessDto.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentSuccessDto.java deleted file mode 100644 index d86e185..0000000 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentSuccessDto.java +++ /dev/null @@ -1,13 +0,0 @@ -package MathCaptain.weakness.domain.Recruitment.dto.response; - -import lombok.Builder; -import lombok.Data; - -@Data -@Builder -public class CommentSuccessDto { - - private Long recruitmentId; - - private Long commentId; -} diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentSuccessResponse.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentSuccessResponse.java new file mode 100644 index 0000000..6d17191 --- /dev/null +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/CommentSuccessResponse.java @@ -0,0 +1,26 @@ +package MathCaptain.weakness.domain.Recruitment.dto.response; + +import MathCaptain.weakness.domain.Recruitment.entity.Comment; +import lombok.*; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class CommentSuccessResponse { + + private Long recruitmentId; + + private Long commentId; + + private CommentSuccessResponse(Long recruitmentId, Long commentId) { + this.recruitmentId = recruitmentId; + this.commentId = commentId; + } + + public static CommentSuccessResponse of(Long recruitmentId, Long commentId) { + return new CommentSuccessResponse(recruitmentId, commentId); + } + + public static CommentSuccessResponse of(Long recruitmentId, Comment comment) { + return new CommentSuccessResponse(recruitmentId, comment.getCommentId()); + } +} diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentCreateResponse.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentCreateResponse.java new file mode 100644 index 0000000..41eef35 --- /dev/null +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentCreateResponse.java @@ -0,0 +1,25 @@ +package MathCaptain.weakness.domain.Recruitment.dto.response; + +import MathCaptain.weakness.domain.Group.entity.RelationBetweenUserAndGroup; +import lombok.*; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class RecruitmentCreateResponse { + + private Long groupId; + + private String leaderName; + + private String groupName; + + private RecruitmentCreateResponse(Long groupId, String leaderName, String groupName) { + this.groupId = groupId; + this.leaderName = leaderName; + this.groupName = groupName; + } + + public static RecruitmentCreateResponse of(RelationBetweenUserAndGroup relation) { + return new RecruitmentCreateResponse(relation.getGroup().getId(), relation.getGroup().getName(), relation.getMember().getName()); + } +} diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentCreateResponseDto.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentCreateResponseDto.java deleted file mode 100644 index 0464db7..0000000 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentCreateResponseDto.java +++ /dev/null @@ -1,15 +0,0 @@ -package MathCaptain.weakness.domain.Recruitment.dto.response; - -import lombok.Builder; -import lombok.Data; - -@Data -@Builder -public class RecruitmentCreateResponseDto { - - private final Long groupId; - - private final String leaderName; - - private final String groupName; -} diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentDetailResponse.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentDetailResponse.java new file mode 100644 index 0000000..34ac28d --- /dev/null +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentDetailResponse.java @@ -0,0 +1,61 @@ +package MathCaptain.weakness.domain.Recruitment.dto.response; + +import MathCaptain.weakness.domain.Group.enums.CategoryStatus; +import MathCaptain.weakness.domain.Recruitment.entity.Recruitment; +import MathCaptain.weakness.domain.Recruitment.enums.RecruitmentStatus; +import lombok.*; + +import java.time.LocalDateTime; +import java.util.List; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class RecruitmentDetailResponse { + + private String authorName; + + private String recruitGroupName; + + private String title; + + private CategoryStatus category; + + private String content; + + private RecruitmentStatus recruitmentStatus; + + private LocalDateTime createdAt; + + private LocalDateTime updatedAt; + + private List comments; + + @Builder + private RecruitmentDetailResponse(String authorName, String recruitGroupName, String title, + CategoryStatus category, String content, RecruitmentStatus recruitmentStatus, + LocalDateTime createdAt, LocalDateTime updatedAt, List comments) { + this.authorName = authorName; + this.recruitGroupName = recruitGroupName; + this.title = title; + this.category = category; + this.content = content; + this.recruitmentStatus = recruitmentStatus; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + this.comments = comments; + } + + public static RecruitmentDetailResponse of(Recruitment recruitment, List comments) { + return RecruitmentDetailResponse.builder() + .authorName(recruitment.getAuthor().getName()) + .recruitGroupName(recruitment.getRecruitGroup().getName()) + .title(recruitment.getTitle()) + .category(recruitment.getCategory()) + .content(recruitment.getContent()) + .recruitmentStatus(recruitment.getRecruitmentStatus()) + .createdAt(recruitment.getPostTime()) + .updatedAt(recruitment.getLastModifiedTime()) + .comments(comments) + .build(); + } +} diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentDetailResponseDto.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentDetailResponseDto.java deleted file mode 100644 index 0b5be20..0000000 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentDetailResponseDto.java +++ /dev/null @@ -1,32 +0,0 @@ -package MathCaptain.weakness.domain.Recruitment.dto.response; - -import MathCaptain.weakness.domain.Group.enums.CategoryStatus; -import MathCaptain.weakness.domain.Recruitment.enums.RecruitmentStatus; -import lombok.Builder; -import lombok.Data; - -import java.time.LocalDateTime; -import java.util.List; - -@Data -@Builder -public class RecruitmentDetailResponseDto { - - private String authorName; - - private String recruitGroupName; - - private String title; - - private CategoryStatus category; - - private String content; - - private RecruitmentStatus recruitmentStatus; - - private LocalDateTime createdAt; - - private LocalDateTime updatedAt; - - private List comments; -} diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentResponse.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentResponse.java new file mode 100644 index 0000000..9f1a96f --- /dev/null +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentResponse.java @@ -0,0 +1,56 @@ +package MathCaptain.weakness.domain.Recruitment.dto.response; + +import MathCaptain.weakness.domain.Group.enums.CategoryStatus; +import MathCaptain.weakness.domain.Recruitment.entity.Recruitment; +import MathCaptain.weakness.domain.Recruitment.enums.RecruitmentStatus; +import lombok.*; + +import java.time.LocalDateTime; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class RecruitmentResponse { + + private String authorName; + + private String recruitGroupName; + + private String title; + + private CategoryStatus category; + + private String content; + + private RecruitmentStatus recruitmentStatus; + + private LocalDateTime createdAt; + + private LocalDateTime updatedAt; + + @Builder + private RecruitmentResponse(String authorName, String recruitGroupName, String title, + CategoryStatus category, String content, RecruitmentStatus recruitmentStatus, + LocalDateTime createdAt, LocalDateTime updatedAt) { + this.authorName = authorName; + this.recruitGroupName = recruitGroupName; + this.title = title; + this.category = category; + this.content = content; + this.recruitmentStatus = recruitmentStatus; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + + public static RecruitmentResponse of(Recruitment recruitment) { + return RecruitmentResponse.builder() + .authorName(recruitment.getAuthor().getName()) + .recruitGroupName(recruitment.getRecruitGroup().getName()) + .title(recruitment.getTitle()) + .category(recruitment.getCategory()) + .content(recruitment.getContent()) + .recruitmentStatus(recruitment.getRecruitmentStatus()) + .createdAt(recruitment.getPostTime()) + .updatedAt(recruitment.getLastModifiedTime()) + .build(); + } +} diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentResponseDto.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentResponseDto.java deleted file mode 100644 index 0c9d3da..0000000 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentResponseDto.java +++ /dev/null @@ -1,29 +0,0 @@ -package MathCaptain.weakness.domain.Recruitment.dto.response; - -import MathCaptain.weakness.domain.Group.enums.CategoryStatus; -import MathCaptain.weakness.domain.Recruitment.enums.RecruitmentStatus; -import lombok.Builder; -import lombok.Data; - -import java.time.LocalDateTime; - -@Builder -@Data -public class RecruitmentResponseDto { - - private String authorName; - - private String recruitGroupName; - - private String title; - - private CategoryStatus category; - - private String content; - - private RecruitmentStatus recruitmentStatus; - - private LocalDateTime createdAt; - - private LocalDateTime updatedAt; -} diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentSuccessDto.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentSuccessDto.java deleted file mode 100644 index 9055d2c..0000000 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/dto/response/RecruitmentSuccessDto.java +++ /dev/null @@ -1,12 +0,0 @@ -package MathCaptain.weakness.domain.Recruitment.dto.response; - -import lombok.Builder; -import lombok.Data; - -@Data -@Builder -public class RecruitmentSuccessDto { - - private Long recruitmentId; - -} From 5f9fe509536eab5755f3d6ffc22cdbb492c3b7ef Mon Sep 17 00:00:00 2001 From: Jeyong Date: Sat, 29 Mar 2025 17:08:04 +0900 Subject: [PATCH 10/12] =?UTF-8?q?[refactor]=20=EB=B9=8C=EB=8D=94=20?= =?UTF-8?q?=ED=8C=A8=ED=84=B4=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/Recruitment/entity/Comment.java | 31 +++++---- .../Recruitment/entity/Recruitment.java | 66 +++++++------------ 2 files changed, 44 insertions(+), 53 deletions(-) diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Comment.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Comment.java index c90df7f..0145c9f 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Comment.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Comment.java @@ -1,6 +1,7 @@ package MathCaptain.weakness.domain.Recruitment.entity; -import MathCaptain.weakness.domain.Recruitment.dto.request.UpdateCommentRequestDto; +import MathCaptain.weakness.domain.Recruitment.dto.request.CreateCommentRequest; +import MathCaptain.weakness.domain.Recruitment.dto.request.UpdateCommentRequest; import MathCaptain.weakness.domain.User.entity.Users; import jakarta.persistence.*; import lombok.*; @@ -12,9 +13,7 @@ @Entity @Getter -@Builder @NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor @EntityListeners(AuditingEntityListener.class) @Table(name = "COMMENT") public class Comment { @@ -41,16 +40,26 @@ public class Comment { @LastModifiedDate private LocalDateTime lastModifiedTime; - //==수정==// - public void updateContent(String content) { - if (content != null && !content.equals(this.content)) { - this.content = content; - this.lastModifiedTime = LocalDateTime.now(); - } + @Builder + private Comment(Recruitment post, Users author, String content) { + this.post = post; + this.author = author; + this.content = content; + this.commentTime = LocalDateTime.now(); + this.lastModifiedTime = LocalDateTime.now(); } - public void updateComment(UpdateCommentRequestDto requestDto) { - updateContent(requestDto.getContent()); + public static Comment of(Recruitment recruitment, Users author, CreateCommentRequest createCommentRequest) { + return new Comment(recruitment, author, createCommentRequest.getContent()); + } + + public static Comment of(Recruitment recruitment, Users author, String content) { + return new Comment(recruitment, author, content); + } + + public void updateComment(UpdateCommentRequest updateRequest) { + this.content = updateRequest.getContent(); + this.lastModifiedTime = LocalDateTime.now(); } public Boolean isBelongToPost(Long recruitmentId) { diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Recruitment.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Recruitment.java index 61236a3..ba71d36 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Recruitment.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/entity/Recruitment.java @@ -2,7 +2,8 @@ import MathCaptain.weakness.domain.Group.entity.Group; import MathCaptain.weakness.domain.Group.enums.CategoryStatus; -import MathCaptain.weakness.domain.Recruitment.dto.request.UpdateRecruitmentRequestDto; +import MathCaptain.weakness.domain.Recruitment.dto.request.CreateRecruitmentRequest; +import MathCaptain.weakness.domain.Recruitment.dto.request.UpdateRecruitmentRequest; import MathCaptain.weakness.domain.Recruitment.enums.RecruitmentStatus; import MathCaptain.weakness.domain.User.entity.Users; import jakarta.persistence.*; @@ -17,9 +18,7 @@ @Entity @Getter -@Builder @NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor @EntityListeners(AuditingEntityListener.class) public class Recruitment { @@ -62,52 +61,35 @@ public class Recruitment { @LastModifiedDate private LocalDateTime lastModifiedTime; - // 기본값 설정 - @PrePersist - protected void onCreate() { - this.postTime = LocalDateTime.now(); - this.lastModifiedTime = LocalDateTime.now(); + @Builder + private Recruitment(Users author, Group recruitGroup, CategoryStatus category, String title, String content, List comments) { + this.author = author; + this.recruitGroup = recruitGroup; + this.category = category; + this.title = title; + this.content = content; this.recruitmentStatus = RecruitmentStatus.RECRUITING; this.interestCount = 0L; - } - - //== 수정 로직 ==// - @PreUpdate - protected void onUpdate() { + this.comments = comments; + this.postTime = LocalDateTime.now(); this.lastModifiedTime = LocalDateTime.now(); } - public void updateTitle(String title) { - if (title != null && !title.equals(this.title)) - { - this.title = title; - updateLastModifiedTime(); - } + public static Recruitment of(Users author, Group group, CreateRecruitmentRequest createRecruitmentRequest) { + return Recruitment.builder() + .author(author) + .recruitGroup(group) + .title(createRecruitmentRequest.getTitle()) + .content(createRecruitmentRequest.getContent()) + .category(group.getCategory()) + .build(); } - public void updateContent(String content) { - if (content != null && !content.equals(this.content)) - { - this.content = content; - updateLastModifiedTime(); - } - } - - public void updateRecruitmentStatus(RecruitmentStatus recruitmentStatus) { - if (recruitmentStatus != null && !recruitmentStatus.equals(this.recruitmentStatus)) - { - this.recruitmentStatus = recruitmentStatus; - updateLastModifiedTime(); - } - } - - private void updateLastModifiedTime() { + //== 수정 로직 ==// + public void updateRecruitment(UpdateRecruitmentRequest requestDto) { + this.title = requestDto.getTitle(); + this.content = requestDto.getContent(); + this.recruitmentStatus = requestDto.getRecruitmentStatus(); this.lastModifiedTime = LocalDateTime.now(); } - - public void updateRecruitment(UpdateRecruitmentRequestDto requestDto) { - updateTitle(requestDto.getTitle()); - updateContent(requestDto.getContent()); - updateRecruitmentStatus(requestDto.getRecruitmentStatus()); - } } From b61e43331c5796bd477756943fdb157a2a795bee Mon Sep 17 00:00:00 2001 From: Jeyong Date: Sat, 29 Mar 2025 17:08:25 +0900 Subject: [PATCH 11/12] =?UTF-8?q?[refactor]=20=EB=B9=8C=EB=8D=94=20?= =?UTF-8?q?=ED=8C=A8=ED=84=B4=20=EC=A0=81=EC=9A=A9=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Recruitment/service/CommentService.java | 100 +++++--------- .../service/RecruitmentService.java | 123 +++++------------- 2 files changed, 63 insertions(+), 160 deletions(-) diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/service/CommentService.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/service/CommentService.java index c7f6a52..5b476b4 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/service/CommentService.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/service/CommentService.java @@ -2,10 +2,10 @@ import MathCaptain.weakness.domain.Recruitment.entity.Comment; import MathCaptain.weakness.domain.Recruitment.entity.Recruitment; -import MathCaptain.weakness.domain.Recruitment.dto.request.CreateCommentRequestDto; -import MathCaptain.weakness.domain.Recruitment.dto.request.UpdateCommentRequestDto; -import MathCaptain.weakness.domain.Recruitment.dto.response.CommentResponseDto; -import MathCaptain.weakness.domain.Recruitment.dto.response.CommentSuccessDto; +import MathCaptain.weakness.domain.Recruitment.dto.request.CreateCommentRequest; +import MathCaptain.weakness.domain.Recruitment.dto.request.UpdateCommentRequest; +import MathCaptain.weakness.domain.Recruitment.dto.response.CommentResponse; +import MathCaptain.weakness.domain.Recruitment.dto.response.CommentSuccessResponse; import MathCaptain.weakness.domain.Recruitment.repository.CommentRepository; import MathCaptain.weakness.domain.Recruitment.repository.RecruitmentRepository; import MathCaptain.weakness.domain.User.entity.Users; @@ -29,87 +29,49 @@ public class CommentService { /// 댓글 CRUD // 댓글 생성 - public CommentSuccessDto createComment(Users user, Long recruitmentId, CreateCommentRequestDto createCommentRequestDto) { - - Recruitment recruitment = recruitmentRepository.findById(recruitmentId) - .orElseThrow(() -> new IllegalArgumentException("해당 모집글이 없습니다.")); - - String content = createCommentRequestDto.getContent(); - - Comment comment = Comment.builder() - .post(recruitment) - .author(user) - .content(content) - .build(); - + public CommentSuccessResponse createComment(Users user, Long recruitmentId, CreateCommentRequest createCommentRequest) { + Recruitment recruitment = findRecruitmentBy(recruitmentId); + Comment comment = Comment.of(recruitment, user, createCommentRequest); commentRepository.save(comment); - - return CommentSuccessDto.builder() - .commentId(comment.getCommentId()) - .recruitmentId(recruitmentId) - .build(); + return CommentSuccessResponse.of(recruitmentId, comment); } // 댓글 수정 - public ApiResponse updateComment(Long recruitmentId, Long commentId, UpdateCommentRequestDto updateCommentRequestDto) { - - Comment comment = commentRepository.findById(commentId) - .orElseThrow(() -> new IllegalArgumentException("해당 댓글이 없습니다.")); - - if (comment.isBelongToPost(recruitmentId)) { - throw new IllegalArgumentException("해당 댓글이 해당 모집글에 속해있지 않습니다."); - } - - comment.updateComment(updateCommentRequestDto); - - return ApiResponse.ok(CommentSuccessDto.builder() - .commentId(commentId) - .recruitmentId(recruitmentId) - .build()); + public ApiResponse updateComment(Long recruitmentId, Long commentId, UpdateCommentRequest updateCommentRequest) { + Comment comment = findCommentBy(commentId, recruitmentId); + comment.updateComment(updateCommentRequest); + return ApiResponse.ok(CommentSuccessResponse.of(recruitmentId, commentId)); } // 댓글 삭제 - - public ApiResponse deleteComment(Long recruitmentId, Long commentId) { - Comment comment = commentRepository.findById(commentId) - .orElseThrow(() -> new IllegalArgumentException("해당 댓글이 없습니다.")); - - if (comment.isBelongToPost(recruitmentId)) { - throw new IllegalArgumentException("해당 댓글이 해당 모집글에 속해있지 않습니다."); - } - + public ApiResponse deleteComment(Long recruitmentId, Long commentId) { + Comment comment = findCommentBy(commentId, recruitmentId); commentRepository.delete(comment); - - return ApiResponse.ok(CommentSuccessDto.builder() - .commentId(commentId) - .recruitmentId(recruitmentId) - .build()); + return ApiResponse.ok(CommentSuccessResponse.of(recruitmentId, commentId)); } - // 댓글 조회 - - public List getComments(Long recruitmentId) { - Recruitment recruitment = recruitmentRepository.findById(recruitmentId) - .orElseThrow(() -> new IllegalArgumentException("해당 모집글이 없습니다.")); + // 댓글 조회 + public List getComments(Long recruitmentId) { + Recruitment recruitment = findRecruitmentBy(recruitmentId); List commentList = commentRepository.findAllByPost(recruitment); - return commentList.stream() - .map(this::buildCommentResponseDto) + .map(CommentResponse::of) .toList(); } - /// 빌더 - - private CommentResponseDto buildCommentResponseDto(Comment comment) { - return CommentResponseDto.builder() - .commentId(comment.getCommentId()) - .authorName(comment.getAuthor().getName()) - .authorName(comment.getAuthor().getName()) - .content(comment.getContent()) - .createdAt(comment.getCommentTime()) - .updatedAt(comment.getLastModifiedTime()) - .build(); + private Recruitment findRecruitmentBy(Long recruitmentId) { + return recruitmentRepository.findById(recruitmentId) + .orElseThrow(() -> new IllegalArgumentException("해당 모집글이 없습니다.")); } + private Comment findCommentBy(Long commentId, Long recruitmentId) { + Comment comment = commentRepository.findById(commentId) + .orElseThrow(() -> new IllegalArgumentException("해당 댓글이 없습니다.")); + if (comment.isBelongToPost(recruitmentId)) { + throw new IllegalArgumentException("해당 댓글이 해당 모집글에 속해있지 않습니다."); + } + + return comment; + } } diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/service/RecruitmentService.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/service/RecruitmentService.java index d34a79e..7e339a0 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/service/RecruitmentService.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/domain/Recruitment/service/RecruitmentService.java @@ -7,9 +7,8 @@ import MathCaptain.weakness.domain.Group.repository.RelationRepository; import MathCaptain.weakness.domain.Recruitment.dto.response.*; import MathCaptain.weakness.domain.Recruitment.entity.Recruitment; -import MathCaptain.weakness.domain.Recruitment.dto.request.CreateRecruitmentRequestDto; -import MathCaptain.weakness.domain.Recruitment.dto.request.UpdateRecruitmentRequestDto; -import MathCaptain.weakness.domain.Recruitment.dto.response.*; +import MathCaptain.weakness.domain.Recruitment.dto.request.CreateRecruitmentRequest; +import MathCaptain.weakness.domain.Recruitment.dto.request.UpdateRecruitmentRequest; import MathCaptain.weakness.domain.Recruitment.repository.RecruitmentRepository; import MathCaptain.weakness.domain.User.entity.Users; import MathCaptain.weakness.global.Api.ApiResponse; @@ -19,7 +18,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.time.LocalDateTime; import java.util.List; @Service @@ -35,117 +33,60 @@ public class RecruitmentService { /// 모집 CRUD // 모집글 작성 요청 (그룹 정보 반환) - public ApiResponse createRequest(Users user) { - - RelationBetweenUserAndGroup relation = relationRepository.findByMemberAndGroupRole(user, GroupRole.LEADER) - .orElseThrow(() -> new IllegalArgumentException("그룹장만 모집글을 작성할 수 있습니다.")); - - return ApiResponse.ok(RecruitmentCreateResponseDto.builder() - .groupId(relation.getGroup().getId()) - .groupName(relation.getGroup().getName()) - .leaderName(relation.getMember().getName()) - .build()); + public ApiResponse createRequest(Users user) { + RelationBetweenUserAndGroup relation = findLeaderRelationBy(user); + return ApiResponse.ok(RecruitmentCreateResponse.of(relation)); } // 모집글 생성 - public ApiResponsecreateRecruitment(Users author, CreateRecruitmentRequestDto createRecruitmentRequestDto) { - - Recruitment recruitment = buildRecruitment(author, createRecruitmentRequestDto); - - return ApiResponse.ok(RecruitmentSuccessDto.builder() - .recruitmentId(recruitmentRepository.save(recruitment).getPostId()) - .build()); + public ApiResponsecreateRecruitment(Users author, CreateRecruitmentRequest createRecruitmentRequest) { + Group group = getGroupBy(createRecruitmentRequest); + Recruitment recruitment = Recruitment.of(author, group, createRecruitmentRequest); + Long recruitmentId = recruitmentRepository.save(recruitment).getPostId(); + return ApiResponse.ok(recruitmentId); } // 모집글 조회 - public ApiResponse getRecruitment(Long recruitmentId) { - Recruitment recruitment = recruitmentRepository.findById(recruitmentId). - orElseThrow(() -> new ResourceNotFoundException("해당 모집글이 없습니다.")); - - List comments = commentService.getComments(recruitmentId); - - return ApiResponse.ok(buildRecruitmentDetailResponseDto(recruitment, comments)); + public ApiResponse getRecruitment(Long recruitmentId) { + Recruitment recruitment = findRecruitmentBy(recruitmentId); + List comments = commentService.getComments(recruitmentId); + return ApiResponse.ok(RecruitmentDetailResponse.of(recruitment, comments)); } // 모집글 수정 - public ApiResponse updateRecruitment(Long recruitmentId, UpdateRecruitmentRequestDto updateRecruitmentRequestDto) { - - Recruitment recruitment = recruitmentRepository.findById(recruitmentId). - orElseThrow(() -> new ResourceNotFoundException("해당 모집글이 없습니다.")); - - recruitment.updateRecruitment(updateRecruitmentRequestDto); - - log.info("모집글 수정 완료, 모집글 ID : {}", recruitmentId); - - return ApiResponse.ok(RecruitmentSuccessDto.builder() - .recruitmentId(recruitmentId) - .build()); + public ApiResponse updateRecruitment(Long recruitmentId, UpdateRecruitmentRequest updateRecruitmentRequest) { + Recruitment recruitment = findRecruitmentBy(recruitmentId); + recruitment.updateRecruitment(updateRecruitmentRequest); + return ApiResponse.ok(recruitmentId); } - public ApiResponse deleteRecruitment(Long recruitmentId) { - Recruitment recruitment = recruitmentRepository.findById(recruitmentId) - .orElseThrow(() -> new ResourceNotFoundException("해당 모집글이 없습니다.")); - + public ApiResponse deleteRecruitment(Long recruitmentId) { + Recruitment recruitment = findRecruitmentBy(recruitmentId); recruitmentRepository.delete(recruitment); - - return ApiResponse.ok(RecruitmentSuccessDto.builder() - .recruitmentId(recruitmentId) - .build()); + return ApiResponse.ok(recruitmentId); } // 모집글 전체 조회 - public ApiResponse> getAllRecruitments() { + public ApiResponse> getAllRecruitments() { List recruitments = recruitmentRepository.findAll(); - return ApiResponse.ok(recruitments.stream() - .map(this::buildRecruitmentResponseDto) + .map(RecruitmentResponse::of) .toList()); } - /// 빌드 - - private RecruitmentResponseDto buildRecruitmentResponseDto(Recruitment recruitment) { - return RecruitmentResponseDto.builder() - .authorName(recruitment.getAuthor().getName()) - .recruitGroupName(recruitment.getRecruitGroup().getName()) - .title(recruitment.getTitle()) - .category(recruitment.getCategory()) - .content(recruitment.getContent()) - .recruitmentStatus(recruitment.getRecruitmentStatus()) - .createdAt(recruitment.getPostTime()) - .updatedAt(recruitment.getLastModifiedTime()) - .build(); + private Group getGroupBy(CreateRecruitmentRequest createRecruitmentRequest) { + return groupRepository.findById(createRecruitmentRequest.getRecruitGroupId()). + orElseThrow(() -> new ResourceNotFoundException("해당 그룹이 없습니다.")); } - private RecruitmentDetailResponseDto buildRecruitmentDetailResponseDto(Recruitment recruitment, List comments) { - - - return RecruitmentDetailResponseDto.builder() - .authorName(recruitment.getAuthor().getName()) - .recruitGroupName(recruitment.getRecruitGroup().getName()) - .title(recruitment.getTitle()) - .category(recruitment.getCategory()) - .content(recruitment.getContent()) - .recruitmentStatus(recruitment.getRecruitmentStatus()) - .createdAt(recruitment.getPostTime()) - .updatedAt(recruitment.getLastModifiedTime()) - .comments(comments) - .build(); + private RelationBetweenUserAndGroup findLeaderRelationBy(Users user) { + return relationRepository.findByMemberAndGroupRole(user, GroupRole.LEADER) + .orElseThrow(() -> new IllegalArgumentException("그룹장만 모집글을 작성할 수 있습니다.")); } - private Recruitment buildRecruitment(Users author, CreateRecruitmentRequestDto createRecruitmentRequestDto) { - - Group relatedGroup = groupRepository.findById(createRecruitmentRequestDto.getRecruitGroupId()). - orElseThrow(() -> new ResourceNotFoundException("해당 그룹이 없습니다.")); - - return Recruitment.builder() - .author(author) - .recruitGroup(relatedGroup) - .title(createRecruitmentRequestDto.getTitle()) - .content(createRecruitmentRequestDto.getContent()) - .category(relatedGroup.getCategory()) - .lastModifiedTime(LocalDateTime.now()) - .build(); + private Recruitment findRecruitmentBy(Long recruitmentId) { + return recruitmentRepository.findById(recruitmentId). + orElseThrow(() -> new ResourceNotFoundException("해당 모집글이 없습니다.")); } } From 9aae871488dcd866117fb506e60df243d3217221 Mon Sep 17 00:00:00 2001 From: Jeyong Date: Sat, 29 Mar 2025 17:08:41 +0900 Subject: [PATCH 12/12] =?UTF-8?q?[refactor]=20=EB=B3=80=EA=B2=BD=EB=90=9C?= =?UTF-8?q?=20=EB=B9=8C=EB=8D=94=20=ED=8C=A8=ED=84=B4=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=97=90=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/MathCaptain/weakness/TestInit.java | 93 +++++++------------ 1 file changed, 32 insertions(+), 61 deletions(-) diff --git a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/TestInit.java b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/TestInit.java index 90cd8ed..e8195b6 100644 --- a/MathCaptain/weakness/src/main/java/MathCaptain/weakness/TestInit.java +++ b/MathCaptain/weakness/src/main/java/MathCaptain/weakness/TestInit.java @@ -9,6 +9,7 @@ import MathCaptain.weakness.domain.Group.repository.RelationRepository; import MathCaptain.weakness.domain.Record.entity.ActivityRecord; import MathCaptain.weakness.domain.Record.repository.RecordRepository; +import MathCaptain.weakness.domain.Recruitment.dto.request.CreateRecruitmentRequest; import MathCaptain.weakness.domain.Recruitment.entity.Comment; import MathCaptain.weakness.domain.Recruitment.entity.Recruitment; import MathCaptain.weakness.domain.Recruitment.enums.RecruitmentStatus; @@ -90,7 +91,7 @@ public void init() { userRepository.save(user); } - log.info("======== 👤테스트 유저 생성 완료 ========="); + log.info("======== 👤테스트 유저 데이터 생성 완료 ========="); Users leader = userRepository.findByUserId(1L) .orElseThrow(() -> new IllegalArgumentException("해당 유저가 없습니다.")); @@ -122,79 +123,41 @@ public void init() { group3.updateWeeklyGoalAchieveMap(DayOfWeek.SUNDAY, 0); groupRepository.save(group3); - log.info("======== 👥 테스트 그룹 생성 완료 ========="); - - RelationBetweenUserAndGroup join1 = RelationBetweenUserAndGroup.builder() - .member(users1) - .groupRole(GroupRole.LEADER) - .group(group1) - .personalDailyGoal(2) - .personalWeeklyGoal(3) - .build(); - - RelationBetweenUserAndGroup join2 = RelationBetweenUserAndGroup.builder() - .member(users2) - .groupRole(GroupRole.LEADER) - .group(group2) - .personalDailyGoal(2) - .personalWeeklyGoal(3) - .build(); - - RelationBetweenUserAndGroup join3 = RelationBetweenUserAndGroup.builder() - .member(users3) - .groupRole(GroupRole.LEADER) - .group(group3) - .personalDailyGoal(2) - .personalWeeklyGoal(3) - .build(); + log.info("======== 👥 테스트 그룹 데이터 생성 완료 ========="); + + RelationBetweenUserAndGroup join1 = RelationBetweenUserAndGroup.of(users1, group1, groupCreateRequest1); + RelationBetweenUserAndGroup join2 = RelationBetweenUserAndGroup.of(users2, group2, groupCreateRequest2); + RelationBetweenUserAndGroup join3 = RelationBetweenUserAndGroup.of(users3, group3, groupCreateRequest3); relationRepository.save(join1); relationRepository.save(join2); relationRepository.save(join3); for (int i = 4; i <= 12; i++) { - RelationBetweenUserAndGroup join = RelationBetweenUserAndGroup.builder() - .member(userRepository.findByUserId((long) i) - .orElseThrow(() -> new IllegalArgumentException("해당 유저가 없습니다.")) - ) - .groupRole(GroupRole.MEMBER) - .group(group3) - .personalDailyGoal(3) - .personalWeeklyGoal(5) - .build(); + Users member = userRepository.findByUserId((long) i) + .orElseThrow(() -> new IllegalArgumentException("해당 유저가 없습니다.")); + RelationBetweenUserAndGroup join = RelationBetweenUserAndGroup.of(member, group3, 3, 5); relationRepository.save(join); } - /// 테스트 모집글 생성 - Recruitment recruitment = Recruitment.builder() - .postId(1L) - .author(users1) - .recruitGroup(group1) - .category(CategoryStatus.STUDY) - .title("testRecruitment") - .content("testContent") - .recruitmentStatus(RecruitmentStatus.RECRUITING) - .build(); + log.info("======== 👥 테스트 관계 데이터 생성 완료 ========="); + CreateRecruitmentRequest createRecruitmentRequest = CreateRecruitmentRequest.of(group1.getId(), "testRecruitment", "testContent"); + Recruitment recruitment = Recruitment.of(users1, group1, createRecruitmentRequest); recruitmentRepository.save(recruitment); + log.info("======== 🔖테스트 모집글 생성 완료 ========="); /// 테스트 댓글 생성 - Comment comment = Comment.builder() - .commentId(1L) - .author(users1) - .post(recruitment) - .content("testComment") - .build(); - + Comment comment = Comment.of(recruitment, users1, "testComment"); commentRepository.save(comment); + log.info("======== 💬테스트 댓글 생성 완료 ========="); // ActivityRecord 생성 (currentProgress 설정: 10 이하로 조정) // 이번 주의 시작과 끝 시간 계산 LocalDateTime startOfWeek = LocalDateTime.now().with(java.time.temporal.TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); - LocalDateTime endOfWeek = startOfWeek.plusWeeks(1); // User ID: 4 -> currentProgress: 5 createActivityRecords(userRepository.findByUserId(4L).orElseThrow(() -> new IllegalArgumentException("해당 유저가 없습니다.")), group3, startOfWeek, 5); @@ -217,14 +180,22 @@ public void init() { // Helper 메서드: ActivityRecord 생성 (이번 주 내에서만 생성되도록 수정) private void createActivityRecords(Users user, Group group, LocalDateTime startOfWeek, int recordCount) { for (int i = 0; i < recordCount; i++) { - ActivityRecord record = ActivityRecord.builder() - .user(user) - .group(group) - // 이번 주 내에서만 startTime 설정 - .startTime(startOfWeek.plusDays(i % 7)) // 월요일부터 시작해서 순차적으로 날짜 설정 - .dailyGoalAchieved(true) // 일간 목표 달성 여부 설정 - .weeklyGoalAchieved(false) // 주간 목표는 기본값으로 false - .build(); + // 시작 시간은 주어진 startOfWeek에서 i일을 더한 값 + LocalDateTime startTime = startOfWeek.plusDays(i % 7); + + // 종료 시간은 시작 시간에서 1시간을 더한 값으로 설정 (예시) + LocalDateTime endTime = startTime.plusHours(1); + + // 활동 시간은 60분으로 설정 (예시) + Long activityTime = 60L; + + // 요일은 시작 시간의 DayOfWeek를 사용 + DayOfWeek dayOfWeek = startTime.getDayOfWeek(); + + // ActivityRecord 객체 생성 + ActivityRecord record = ActivityRecord.of(user, group, startTime, endTime, activityTime, dayOfWeek); + + // 저장소에 저장 recordRepository.save(record); } }