Skip to content

Commit 2e198eb

Browse files
Merge pull request #252 from prgrms-web-devcourse-final-project/develop
[EA3-68] chore: develop → main 브랜치 머지
2 parents 3bbf952 + 7ebd7ad commit 2e198eb

File tree

15 files changed

+401
-72
lines changed

15 files changed

+401
-72
lines changed

src/main/java/grep/neogulcoder/domain/alram/controller/AlarmController.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
import grep.neogulcoder.domain.alram.service.AlarmService;
55
import grep.neogulcoder.global.auth.Principal;
66
import grep.neogulcoder.global.response.ApiResponse;
7-
import java.util.List;
87
import lombok.RequiredArgsConstructor;
98
import org.springframework.security.core.annotation.AuthenticationPrincipal;
10-
import org.springframework.web.bind.annotation.GetMapping;
11-
import org.springframework.web.bind.annotation.PathVariable;
12-
import org.springframework.web.bind.annotation.PostMapping;
13-
import org.springframework.web.bind.annotation.RequestMapping;
14-
import org.springframework.web.bind.annotation.RestController;
9+
import org.springframework.web.bind.annotation.*;
10+
11+
import java.util.List;
1512

1613
@RestController
1714
@RequiredArgsConstructor
@@ -27,7 +24,7 @@ public ApiResponse<List<AlarmResponse>> getAllAlarms(@AuthenticationPrincipal Pr
2724

2825
@GetMapping("/unchecked/my")
2926
public ApiResponse<List<AlarmResponse>> getAllUncheckedAlarm(
30-
@AuthenticationPrincipal Principal userDetails) {
27+
@AuthenticationPrincipal Principal userDetails) {
3128
return ApiResponse.success(alarmService.getAllUncheckedAlarms(userDetails.getUserId()));
3229
}
3330

@@ -39,8 +36,8 @@ public ApiResponse<Void> checkAlarm(@AuthenticationPrincipal Principal userDetai
3936

4037
@PostMapping("/choose/{alarmId}/response")
4138
public ApiResponse<Void> respondToInvite(@AuthenticationPrincipal Principal principal,
42-
@PathVariable Long alarmId,
43-
boolean accepted) {
39+
@PathVariable Long alarmId,
40+
boolean accepted) {
4441
if (accepted) {
4542
alarmService.acceptInvite(principal.getUserId(), alarmId);
4643
} else {

src/main/java/grep/neogulcoder/domain/alram/service/AlarmService.java

Lines changed: 114 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import grep.neogulcoder.domain.alram.repository.AlarmRepository;
77
import grep.neogulcoder.domain.alram.type.AlarmType;
88
import grep.neogulcoder.domain.alram.type.DomainType;
9+
import grep.neogulcoder.domain.recruitment.comment.event.RecruitmentPostCommentEvent;
910
import grep.neogulcoder.domain.recruitment.post.RecruitmentPost;
1011
import grep.neogulcoder.domain.recruitment.post.repository.RecruitmentPostRepository;
1112
import grep.neogulcoder.domain.study.Study;
@@ -21,19 +22,26 @@
2122
import grep.neogulcoder.domain.studyapplication.event.ApplicationEvent;
2223
import grep.neogulcoder.domain.studyapplication.event.ApplicationStatusChangedEvent;
2324
import grep.neogulcoder.domain.studyapplication.repository.ApplicationRepository;
25+
import grep.neogulcoder.domain.studypost.StudyPost;
26+
import grep.neogulcoder.domain.studypost.StudyPostErrorCode;
27+
import grep.neogulcoder.domain.studypost.comment.event.StudyPostCommentEvent;
28+
import grep.neogulcoder.domain.studypost.repository.StudyPostRepository;
2429
import grep.neogulcoder.domain.timevote.event.TimeVotePeriodCreatedEvent;
2530
import grep.neogulcoder.global.exception.business.BusinessException;
2631
import grep.neogulcoder.global.exception.business.NotFoundException;
2732
import grep.neogulcoder.global.provider.finder.MessageFinder;
28-
import java.util.List;
2933
import lombok.RequiredArgsConstructor;
3034
import org.springframework.context.event.EventListener;
3135
import org.springframework.stereotype.Service;
3236
import org.springframework.transaction.annotation.Transactional;
3337

34-
import static grep.neogulcoder.domain.study.exception.code.StudyErrorCode.*;
35-
import static grep.neogulcoder.domain.studyapplication.exception.code.ApplicationErrorCode.*;
36-
import static grep.neogulcoder.domain.recruitment.RecruitmentErrorCode.*;
38+
import java.util.List;
39+
40+
import static grep.neogulcoder.domain.recruitment.RecruitmentErrorCode.NOT_FOUND;
41+
import static grep.neogulcoder.domain.study.exception.code.StudyErrorCode.STUDY_LEADER_NOT_FOUND;
42+
import static grep.neogulcoder.domain.study.exception.code.StudyErrorCode.STUDY_NOT_FOUND;
43+
import static grep.neogulcoder.domain.studyapplication.exception.code.ApplicationErrorCode.APPLICATION_NOT_FOUND;
44+
import static grep.neogulcoder.domain.studyapplication.exception.code.ApplicationErrorCode.APPLICATION_PARTICIPANT_LIMIT_EXCEEDED;
3745

3846
@Service
3947
@RequiredArgsConstructor
@@ -43,61 +51,62 @@ public class AlarmService {
4351
private final AlarmRepository alarmRepository;
4452
private final MessageFinder messageFinder;
4553
private final StudyRepository studyRepository;
54+
private final StudyPostRepository studyPostRepository;
4655
private final StudyMemberQueryRepository studyMemberQueryRepository;
4756
private final StudyMemberRepository studyMemberRepository;
4857
private final RecruitmentPostRepository recruitmentPostRepository;
4958
private final ApplicationRepository applicationRepository;
5059

5160
@Transactional
5261
public void saveAlarm(Long receiverId, AlarmType alarmType, DomainType domainType,
53-
Long domainId) {
62+
Long domainId) {
5463
String message = messageFinder.findMessage(alarmType, domainType, domainId);
5564
alarmRepository.save(Alarm.init(alarmType, receiverId, domainType, domainId, message));
5665
}
5766

5867
public List<AlarmResponse> getAllUncheckedAlarms(Long receiverUserId) {
5968
return alarmRepository.findAllByReceiverUserIdAndCheckedFalse(receiverUserId).stream()
60-
.map(alarm -> AlarmResponse.toResponse(
61-
alarm.getId(),
62-
alarm.getReceiverUserId(),
63-
alarm.getAlarmType(),
64-
alarm.getDomainType(),
65-
alarm.getDomainId(),
66-
alarm.getMessage(),
67-
alarm.isChecked(),
68-
alarm.getCreatedDate()))
69-
.toList();
69+
.map(alarm -> AlarmResponse.toResponse(
70+
alarm.getId(),
71+
alarm.getReceiverUserId(),
72+
alarm.getAlarmType(),
73+
alarm.getDomainType(),
74+
alarm.getDomainId(),
75+
alarm.getMessage(),
76+
alarm.isChecked(),
77+
alarm.getCreatedDate()))
78+
.toList();
7079
}
7180

7281
public List<AlarmResponse> getAllAlarms(Long receiverUserId) {
7382
return alarmRepository.findAllByReceiverUserId(receiverUserId).stream()
74-
.map(alarm -> AlarmResponse.toResponse(
75-
alarm.getId(),
76-
alarm.getReceiverUserId(),
77-
alarm.getAlarmType(),
78-
alarm.getDomainType(),
79-
alarm.getDomainId(),
80-
alarm.getMessage(),
81-
alarm.isChecked(),
82-
alarm.getCreatedDate()))
83-
.toList();
83+
.map(alarm -> AlarmResponse.toResponse(
84+
alarm.getId(),
85+
alarm.getReceiverUserId(),
86+
alarm.getAlarmType(),
87+
alarm.getDomainType(),
88+
alarm.getDomainId(),
89+
alarm.getMessage(),
90+
alarm.isChecked(),
91+
alarm.getCreatedDate()))
92+
.toList();
8493
}
8594

8695
@Transactional
8796
public void checkAllAlarmWithoutInvite(Long receiverUserId) {
8897
List<Alarm> alarms = alarmRepository.findAllByReceiverUserIdAndCheckedFalse(receiverUserId);
8998
alarms.stream()
90-
.filter(alarm -> alarm.getAlarmType() != AlarmType.INVITE)
91-
.forEach(Alarm::checkAlarm);
99+
.filter(alarm -> alarm.getAlarmType() != AlarmType.INVITE)
100+
.forEach(Alarm::checkAlarm);
92101
}
93102

94103
@EventListener
95104
public void handleStudyInviteEvent(StudyInviteEvent event) {
96105
saveAlarm(
97-
event.targetUserId(),
98-
AlarmType.INVITE,
99-
DomainType.STUDY,
100-
event.studyId()
106+
event.targetUserId(),
107+
AlarmType.INVITE,
108+
DomainType.STUDY,
109+
event.studyId()
101110
);
102111
}
103112

@@ -122,15 +131,15 @@ public void rejectInvite(Long alarmId) {
122131
@EventListener
123132
public void handleStudyExtendEvent(StudyExtendEvent event) {
124133
List<StudyMember> members = studyMemberRepository.findAllByStudyIdAndActivatedTrue(
125-
event.studyId());
134+
event.studyId());
126135

127136
for (StudyMember member : members) {
128137
if (!member.isLeader()) {
129138
saveAlarm(
130-
member.getUserId(),
131-
AlarmType.STUDY_EXTEND,
132-
DomainType.STUDY,
133-
event.studyId()
139+
member.getUserId(),
140+
AlarmType.STUDY_EXTEND,
141+
DomainType.STUDY,
142+
event.studyId()
134143
);
135144
}
136145
}
@@ -139,29 +148,29 @@ public void handleStudyExtendEvent(StudyExtendEvent event) {
139148
@EventListener
140149
public void handleStudyExtensionReminderEvent(StudyExtensionReminderEvent event) {
141150
StudyMember leader = studyMemberRepository.findByStudyIdAndRoleAndActivatedTrue(
142-
event.studyId(), StudyMemberRole.LEADER)
143-
.orElseThrow(() -> new BusinessException(STUDY_LEADER_NOT_FOUND));
151+
event.studyId(), StudyMemberRole.LEADER)
152+
.orElseThrow(() -> new BusinessException(STUDY_LEADER_NOT_FOUND));
144153

145154
saveAlarm(
146-
leader.getUserId(),
147-
AlarmType.STUDY_EXTENSION_REMINDER,
148-
DomainType.STUDY,
149-
event.studyId()
155+
leader.getUserId(),
156+
AlarmType.STUDY_EXTENSION_REMINDER,
157+
DomainType.STUDY,
158+
event.studyId()
150159
);
151160
}
152161

153162
@EventListener
154163
public void handleTimeVotePeriodCreatedEvent(TimeVotePeriodCreatedEvent event) {
155164
List<StudyMember> members = studyMemberRepository.findAllByStudyIdAndActivatedTrue(
156-
event.studyId());
165+
event.studyId());
157166

158167
for (StudyMember member : members) {
159168
if (!member.getUserId().equals(event.excludedUserId())) {
160169
saveAlarm(
161-
member.getUserId(),
162-
AlarmType.TIME_VOTE_REQUEST,
163-
DomainType.TIME_VOTE,
164-
event.studyId()
170+
member.getUserId(),
171+
AlarmType.TIME_VOTE_REQUEST,
172+
DomainType.TIME_VOTE,
173+
event.studyId()
165174
);
166175
}
167176
}
@@ -170,37 +179,83 @@ public void handleTimeVotePeriodCreatedEvent(TimeVotePeriodCreatedEvent event) {
170179
@EventListener
171180
public void handleApplicationEvent(ApplicationEvent event) {
172181
RecruitmentPost recruitmentPost = recruitmentPostRepository.findByIdAndActivatedTrue(event.recruitmentPostId())
173-
.orElseThrow(() -> new BusinessException(NOT_FOUND));
182+
.orElseThrow(() -> new BusinessException(NOT_FOUND));
174183

175184
saveAlarm(
176-
recruitmentPost.getUserId(),
177-
AlarmType.STUDY_APPLICATION,
178-
DomainType.RECRUITMENT_POST,
179-
event.recruitmentPostId()
185+
recruitmentPost.getUserId(),
186+
AlarmType.STUDY_APPLICATION,
187+
DomainType.RECRUITMENT_POST,
188+
event.recruitmentPostId()
180189
);
181190
}
182191

183192
@EventListener
184193
public void handleApplicationStatusChangedEvent(ApplicationStatusChangedEvent event) {
185194
StudyApplication application = applicationRepository.findByIdAndActivatedTrue(event.applicationId())
186-
.orElseThrow(() -> new BusinessException(APPLICATION_NOT_FOUND));
195+
.orElseThrow(() -> new BusinessException(APPLICATION_NOT_FOUND));
187196

188197
saveAlarm(
189-
application.getUserId(),
190-
event.alarmType(),
191-
DomainType.STUDY_APPLICATION,
192-
application.getId()
198+
application.getUserId(),
199+
event.alarmType(),
200+
DomainType.STUDY_APPLICATION,
201+
application.getId()
202+
);
203+
}
204+
205+
@Transactional
206+
@EventListener
207+
public void handleRecruitmentPostCommentEvent(RecruitmentPostCommentEvent event) {
208+
RecruitmentPost recruitmentPost = recruitmentPostRepository.findById(event.getPostId())
209+
.orElseThrow(() -> new NotFoundException(NOT_FOUND));
210+
211+
String message = messageFinder.findMessage(
212+
AlarmType.RECRUITMENT_POST_COMMENT,
213+
DomainType.RECRUITMENT_POST,
214+
recruitmentPost.getId()
215+
);
216+
217+
alarmRepository.save(
218+
Alarm.init(
219+
AlarmType.RECRUITMENT_POST_COMMENT,
220+
event.getTargetUserId(),
221+
DomainType.RECRUITMENT_POST,
222+
event.getPostId(),
223+
message
224+
)
225+
);
226+
}
227+
228+
@Transactional
229+
@EventListener
230+
public void handleStudyPostCommentEvent(StudyPostCommentEvent event) {
231+
StudyPost studyPost = studyPostRepository.findById(event.getPostId())
232+
.orElseThrow(() -> new NotFoundException(StudyPostErrorCode.NOT_FOUND_POST));
233+
234+
String message = messageFinder.findMessage(
235+
AlarmType.STUDY_POST_COMMENT,
236+
DomainType.STUDY_POST,
237+
studyPost.getId()
238+
);
239+
240+
alarmRepository.save(
241+
Alarm.init(
242+
AlarmType.STUDY_POST_COMMENT,
243+
event.getTargetUserId(),
244+
DomainType.STUDY_POST,
245+
event.getPostId(),
246+
message
247+
)
193248
);
194249
}
195250

196251
private Alarm findValidAlarm(Long alarmId) {
197252
return alarmRepository.findById(alarmId)
198-
.orElseThrow(() -> new NotFoundException(AlarmErrorCode.ALARM_NOT_FOUND));
253+
.orElseThrow(() -> new NotFoundException(AlarmErrorCode.ALARM_NOT_FOUND));
199254
}
200255

201256
private Study findValidStudy(Long studyId) {
202257
return studyRepository.findById(studyId)
203-
.orElseThrow(() -> new NotFoundException(STUDY_NOT_FOUND));
258+
.orElseThrow(() -> new NotFoundException(STUDY_NOT_FOUND));
204259
}
205260

206261
private void validateParticipantStudyLimit(Long userId) {

src/main/java/grep/neogulcoder/domain/alram/type/AlarmType.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ public enum AlarmType {
44
INVITE,
55
STUDY_EXTEND,
66
STUDY_EXTENSION_REMINDER,
7+
STUDY_POST_COMMENT,
78
TIME_VOTE_REQUEST,
89
STUDY_APPLICATION,
910
STUDY_APPLICATION_APPROVED,
10-
STUDY_APPLICATION_REJECTED
11+
STUDY_APPLICATION_REJECTED,
12+
RECRUITMENT_POST_COMMENT
1113
}

src/main/java/grep/neogulcoder/domain/alram/type/DomainType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
public enum DomainType {
44
STUDY,
5+
STUDY_POST,
56
TIME_VOTE,
67
RECRUITMENT_POST,
78
STUDY_APPLICATION

src/main/java/grep/neogulcoder/domain/recruitment/comment/controller/dto/request/RecruitmentCommentSaveRequest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public class RecruitmentCommentSaveRequest {
1414
private RecruitmentCommentSaveRequest() {
1515
}
1616

17+
public RecruitmentCommentSaveRequest(String content) {
18+
this.content = content;
19+
}
20+
1721
public RecruitmentPostComment toEntity(RecruitmentPost post, long userId) {
1822
return RecruitmentPostComment.builder()
1923
.recruitmentPost(post)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package grep.neogulcoder.domain.recruitment.comment.event;
2+
3+
import lombok.Getter;
4+
5+
@Getter
6+
public class RecruitmentPostCommentEvent {
7+
8+
private long targetUserId;
9+
private long postId;
10+
11+
public RecruitmentPostCommentEvent(long targetUserId, long postId) {
12+
this.targetUserId = targetUserId;
13+
this.postId = postId;
14+
}
15+
}

0 commit comments

Comments
 (0)