Skip to content

Commit b8356de

Browse files
authored
{refactor} 코드 리팩토링
{refactor} 코드 리팩토링
2 parents 40db15f + 582b1d0 commit b8356de

26 files changed

Lines changed: 293 additions & 379 deletions

MathCaptain/weakness/src/main/java/MathCaptain/weakness/Group/controller/GroupController.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import MathCaptain.weakness.Group.dto.response.GroupMemberListResponseDto;
88
import MathCaptain.weakness.Group.dto.response.GroupResponseDto;
99
import MathCaptain.weakness.Group.dto.response.RelationResponseDto;
10+
import MathCaptain.weakness.Group.enums.RequestStatus;
1011
import MathCaptain.weakness.Group.service.GroupJoinService;
1112
import MathCaptain.weakness.Notification.service.NotificationService;
1213
import MathCaptain.weakness.User.domain.UserDetailsImpl;
@@ -29,6 +30,10 @@
2930
@RequiredArgsConstructor
3031
public class GroupController {
3132

33+
public static final RequestStatus ACCEPTED = RequestStatus.ACCEPTED;
34+
public static final RequestStatus REJECTED = RequestStatus.REJECTED;
35+
public static final RequestStatus CANCELED = RequestStatus.CANCELED;
36+
3237
private final GroupService groupService;
3338
private final RelationService relationService;
3439
private final GroupJoinService groupJoinService;
@@ -67,8 +72,8 @@ public ApiResponse<GroupResponseDto> updateGroup(@Valid @PathVariable Long group
6772
public ApiResponse<?> joinGroup(@Valid @PathVariable Long groupId,
6873
@LoginUser Users loginUser,
6974
@RequestBody GroupJoinRequestDto groupJoinRequestDto) {
70-
Long groupJoinId = groupJoinService.joinGroupRequest(groupId, loginUser, groupJoinRequestDto);
71-
notificationService.notifyGroupJoinRequest(groupId, loginUser, groupJoinId);
75+
groupJoinService.joinGroupRequest(groupId, loginUser, groupJoinRequestDto);
76+
notificationService.notifyGroupJoinRequest(groupId, loginUser);
7277
return ApiResponse.ok("그룹 가입 요청이 완료되었습니다.");
7378
}
7479

@@ -82,25 +87,26 @@ public ApiResponse<?> deleteGroup(@PathVariable Long groupId) {
8287
/// 그룹 가입
8388

8489
// 그룹 가입 요청 수락
85-
@PostMapping("/group/join/accept/{groupId}/{joinRequestId}")
86-
public ApiResponse<?> acceptJoinRequest(@PathVariable Long groupId, @PathVariable Long joinRequestId) {
87-
groupJoinService.acceptJoinRequest(groupId, joinRequestId);
88-
notificationService.notifyGroupJoinResult(groupId, joinRequestId);
90+
@PostMapping("/group/join/accept/{groupId}")
91+
public ApiResponse<?> acceptJoinRequest(@PathVariable Long groupId, @LoginUser Users loginUser) {
92+
groupJoinService.changeStatus(groupId, loginUser, ACCEPTED);
93+
notificationService.notifyGroupJoinResult(groupId, loginUser);
8994
return ApiResponse.ok("그룹 가입 요청이 수락되었습니다.");
9095
}
9196

9297
// 그룹 가입 요청 거절
93-
@PostMapping("/group/join/reject/{groupId}/{joinRequestId}")
94-
public ApiResponse<?> rejectJoinRequest(@PathVariable("groupId") Long groupId, @PathVariable("joinRequestId") Long joinRequestId) {
95-
groupJoinService.rejectJoinRequest(joinRequestId);
96-
notificationService.notifyGroupJoinResult(groupId, joinRequestId);
98+
@PostMapping("/group/join/reject/{groupId}")
99+
public ApiResponse<?> rejectJoinRequest(@PathVariable Long groupId, @LoginUser Users loginUser) {
100+
groupJoinService.changeStatus(groupId, loginUser, REJECTED);
101+
notificationService.notifyGroupJoinResult(groupId, loginUser);
97102
return ApiResponse.ok("그룹 가입 요청이 거절되었습니다.");
98103
}
99104

100105
// 그룹 가입 요청 취소
101-
@DeleteMapping("/group/join/cancel/{joinRequestId}")
102-
public ApiResponse<?> cancelJoinRequest(@PathVariable Long joinRequestId) {
103-
return groupJoinService.cancelJoinRequest(joinRequestId);
106+
@DeleteMapping("/group/join/cancel/{groupId}")
107+
public ApiResponse<?> cancelJoinRequest(@PathVariable Long groupId, @LoginUser Users loginUser) {
108+
groupJoinService.changeStatus(groupId, loginUser, CANCELED);
109+
return ApiResponse.ok("그룹 가입 요청이 취소되었습니다.");
104110
}
105111

106112
// 그룹 가입 요청 조회

MathCaptain/weakness/src/main/java/MathCaptain/weakness/Group/domain/Group.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ public class Group {
2929
@Column(name = "group_id")
3030
private Long id;
3131

32-
@ManyToOne(fetch = FetchType.LAZY)
33-
@JoinColumn(name = "leader")
34-
private Users leader;
35-
36-
@OneToMany(fetch = FetchType.LAZY, mappedBy = "joinGroup", cascade = CascadeType.REMOVE)
32+
@OneToMany(fetch = FetchType.LAZY, mappedBy = "group", cascade = CascadeType.REMOVE)
3733
@Column(name = "members")
3834
private List<RelationBetweenUserAndGroup> relationBetweenUserAndGroup;
3935

@@ -66,7 +62,7 @@ public class Group {
6662
@CollectionTable(name = "group_weekly_goal_achieve", joinColumns = @JoinColumn(name = "group_id"))
6763
@MapKeyColumn(name = "day_of_week") // 요일을 키로 사용
6864
@Column(name = "goal_count") // 카운트를 값으로 사용
69-
private Map<DayOfWeek, Integer> weeklyGoalAchieve;
65+
private Map<DayOfWeek, Integer> weeklyGoalAchieveMap;
7066

7167
@OneToMany(mappedBy = "recruitGroup")
7268
private List<Recruitment> recruitments;
@@ -75,11 +71,11 @@ public class Group {
7571
protected void onCreate() {
7672
this.createDate = LocalDate.now();
7773

78-
if (this.weeklyGoalAchieve == null) {
79-
this.weeklyGoalAchieve = new EnumMap<>(DayOfWeek.class);
74+
if (this.weeklyGoalAchieveMap == null) {
75+
this.weeklyGoalAchieveMap = new EnumMap<>(DayOfWeek.class);
8076
}
8177
for (DayOfWeek dayOfWeek : DayOfWeek.values()) {
82-
weeklyGoalAchieve.put(dayOfWeek, 0);
78+
weeklyGoalAchieveMap.put(dayOfWeek, 0);
8379
}
8480
}
8581

@@ -127,8 +123,8 @@ public void updateGroupRanking(int groupRanking) {
127123
this.groupRanking = groupRanking;
128124
}
129125

130-
public void updateWeeklyGoalAchieve(DayOfWeek dayOfWeek, int goalCount) {
131-
weeklyGoalAchieve.put(dayOfWeek, goalCount);
126+
public void updateWeeklyGoalAchieveMap(DayOfWeek dayOfWeek, int goalCount) {
127+
weeklyGoalAchieveMap.put(dayOfWeek, goalCount);
132128
}
133129

134130
public void updateGroup(GroupUpdateRequestDto requestDto) {
@@ -143,13 +139,13 @@ public boolean checkJoin(int dailyGoal, int weeklyGoal) {
143139
return dailyGoal >= minDailyHours && weeklyGoal >= minWeeklyDays;
144140
}
145141

146-
public void increaseWeeklyGoalAchieve(DayOfWeek day) {
147-
weeklyGoalAchieve.put(day, weeklyGoalAchieve.get(day) + 1);
142+
public void increaseWeeklyGoalAchieveMap(DayOfWeek day) {
143+
weeklyGoalAchieveMap.put(day, weeklyGoalAchieveMap.get(day) + 1);
148144
}
149145

150-
public void resetWeeklyGoalAchieve() {
146+
public void resetWeeklyGoalAchieveMap() {
151147
for (DayOfWeek dayOfWeek : DayOfWeek.values()) {
152-
weeklyGoalAchieve.put(dayOfWeek, 0);
148+
weeklyGoalAchieveMap.put(dayOfWeek, 0);
153149
}
154150
}
155151

MathCaptain/weakness/src/main/java/MathCaptain/weakness/Group/domain/GroupJoin.java

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
package MathCaptain.weakness.Group.domain;
22

33
import MathCaptain.weakness.Group.enums.GroupRole;
4+
import MathCaptain.weakness.Group.enums.RequestStatus;
45
import MathCaptain.weakness.User.domain.Users;
56
import jakarta.persistence.*;
6-
import jakarta.validation.constraints.NotNull;
7-
import lombok.AllArgsConstructor;
8-
import lombok.Builder;
9-
import lombok.Getter;
10-
import lombok.NoArgsConstructor;
7+
import lombok.*;
118
import org.hibernate.validator.constraints.Range;
129

13-
import java.time.DayOfWeek;
1410
import java.time.LocalDate;
15-
import java.time.LocalDateTime;
1611

1712
@Entity
1813
@Getter
1914
@Builder
20-
@NoArgsConstructor
15+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
2116
@AllArgsConstructor
2217
@Table(name = "RELATION_BETWEEN_USER_AND_GROUP")
2318
public class RelationBetweenUserAndGroup {
@@ -28,20 +23,22 @@ public class RelationBetweenUserAndGroup {
2823
private Long id;
2924

3025
@ManyToOne(cascade = CascadeType.REMOVE)
31-
@JoinColumn(name = "member")
26+
@JoinColumn(name = "member", referencedColumnName = "user_id")
3227
private Users member;
3328

29+
@ManyToOne(cascade = CascadeType.REMOVE)
30+
@JoinColumn(name = "members")
31+
private Group group;
32+
3433
@Enumerated(EnumType.STRING)
3534
@Column(nullable = false)
3635
private GroupRole groupRole;
3736

38-
@ManyToOne(cascade = CascadeType.REMOVE)
39-
@JoinColumn(name = "joinGroup")
40-
private Group joinGroup;
41-
4237
@Column(nullable = false)
4338
private LocalDate joinDate;
4439

40+
private RequestStatus requestStatus;
41+
4542
@Column(nullable = false)
4643
@Range(min = 0, max = 24)
4744
private int personalDailyGoal;
@@ -54,14 +51,10 @@ public class RelationBetweenUserAndGroup {
5451
@Range(min = 0, max = 1440)
5552
private Long personalDailyGoalAchieve;
5653

57-
// 주간 인증 수행 시간
54+
// 주간 인증 수행 일수
5855
@Range(min = 0, max = 7)
5956
private int personalWeeklyGoalAchieve;
6057

61-
private Boolean isWeeklyGoalAchieved;
62-
63-
private Boolean isDailyGoalAchieved;
64-
6558
// 주간 목표 달성 연속 횟수
6659
@Range(min = 0)
6760
private int weeklyGoalAchieveStreak;
@@ -77,19 +70,27 @@ protected void onPrePersist() {
7770
this.joinDate = LocalDate.now(); // joinDate의 기본값 설정 (필요 시)
7871
}
7972

80-
if (this.isWeeklyGoalAchieved == null) {
81-
this.isWeeklyGoalAchieved = false;
82-
}
73+
this.requestStatus = RequestStatus.WAITING;
8374

84-
if (this.isDailyGoalAchieved == null) {
85-
this.isDailyGoalAchieved = false;
86-
}
8775
this.personalWeeklyGoalAchieve = 0;
8876
this.weeklyGoalAchieveStreak = 0;
8977
this.personalDailyGoalAchieve = 0L;
9078

9179
}
9280

81+
public void subtractPoint(Long point) {
82+
this.member.subtractPoint(point);
83+
this.group.subtractPoint(point);
84+
}
85+
86+
public boolean isDailyGoalAchieved() {
87+
return this.personalDailyGoalAchieve >= this.personalDailyGoal;
88+
}
89+
90+
public boolean isWeeklyGoalAchieved() {
91+
return this.personalWeeklyGoalAchieve >= this.personalWeeklyGoal;
92+
}
93+
9394
// 일간 목표 업데이트
9495
public void updatePersonalDailyGoalAchieved(Long personalDailyGoalAchieved) {
9596
this.personalDailyGoalAchieve = personalDailyGoalAchieved;
@@ -115,26 +116,13 @@ public void resetPersonalWeeklyGoalAchieve() {
115116
this.personalWeeklyGoalAchieve = 0;
116117
}
117118

118-
// 주간 목표 달성 여부 초기화
119-
public void resetIsWeeklyGoalAchieved() {
120-
this.isWeeklyGoalAchieved = false;
121-
}
122-
123-
// 일간 목표 달성 여부 초기화
124-
public void resetIsDailyGoalAchieved() {
125-
this.isDailyGoalAchieved = false;
126-
}
127-
128119
// 주간 목표 달성 연속 횟수 초기화
129120
public void resetWeeklyGoalAchieveStreak() {
130121
this.weeklyGoalAchieveStreak = 0;
131122
}
132123

133-
public boolean isWeeklyGoalAchieved() {
134-
return this.isWeeklyGoalAchieved;
124+
public void updateRequestStatus(RequestStatus requestStatus) {
125+
this.requestStatus = requestStatus;
135126
}
136127

137-
public boolean isDailyGoalAchieved() {
138-
return this.isDailyGoalAchieved;
139-
}
140128
}

MathCaptain/weakness/src/main/java/MathCaptain/weakness/Group/dto/response/GroupMemberListResponseDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ public class GroupMemberListResponseDto {
3131

3232
private int currentProgress;
3333

34-
private Boolean isAchieveWeeklyGoal;
34+
private Boolean isWeeklyGoalAchieved;
3535
}

MathCaptain/weakness/src/main/java/MathCaptain/weakness/Group/repository/GroupJoinRepository.java

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

0 commit comments

Comments
 (0)