-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 친구가 당일 미션을 완료하지 않은 경우 재촉하기 (#309)
* feat: 미션 캘린더 조회 시 오늘 미션 완료했는지 여부 UrgingStatus 필드 추가 * move: 패키지 이동 * move: PushNotificationConstants 패키지 이동 * feat: 친구가 당일 미션을 완료하지 않은 경우 재촉하기 기능 구현 * test: 미션 재촉하기 테스트 코드 작성 * style: spotless * refactor: memberId 비교 equals로 변경 * style: 출력문 제거 * fix: Long 비교 equals로 변경 * style: spotless
- Loading branch information
Showing
15 changed files
with
371 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/depromeet/domain/missionRecord/dto/response/UrgingStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.depromeet.domain.missionRecord.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum UrgingStatus { | ||
URGING, | ||
NONE, | ||
; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/depromeet/domain/notification/api/PushController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.depromeet.domain.notification.api; | ||
|
||
import com.depromeet.domain.notification.application.PushService; | ||
import com.depromeet.domain.notification.dto.request.PushUrgingSendRequest; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Tag(name = "7. [알림]", description = "알림 관련 API") | ||
@RestController | ||
@RequestMapping("/notifications") | ||
@RequiredArgsConstructor | ||
public class PushController { | ||
private final PushService pushService; | ||
|
||
@Operation(summary = "재촉하기", description = "당일 미션을 완료하지 않은 친구에게 재촉하기 Push Message를 발송합니다.") | ||
@PostMapping("/urging") | ||
public void urgingSend(@Valid @RequestBody PushUrgingSendRequest request) { | ||
pushService.sendUrgingPush(request); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...promeet/global/config/fcm/FcmService.java → .../notification/application/FcmService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/com/depromeet/domain/notification/application/PushService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.depromeet.domain.notification.application; | ||
|
||
import static com.depromeet.global.common.constants.PushNotificationConstants.PUSH_URGING_TITLE; | ||
|
||
import com.depromeet.domain.member.domain.Member; | ||
import com.depromeet.domain.mission.dao.MissionRepository; | ||
import com.depromeet.domain.mission.domain.Mission; | ||
import com.depromeet.domain.notification.dao.NotificationRepository; | ||
import com.depromeet.domain.notification.domain.Notification; | ||
import com.depromeet.domain.notification.domain.NotificationType; | ||
import com.depromeet.domain.notification.dto.request.PushUrgingSendRequest; | ||
import com.depromeet.global.common.constants.PushNotificationConstants; | ||
import com.depromeet.global.error.exception.CustomException; | ||
import com.depromeet.global.error.exception.ErrorCode; | ||
import com.depromeet.global.util.MemberUtil; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class PushService { | ||
private final MemberUtil memberUtil; | ||
private final FcmService fcmService; | ||
private final MissionRepository missionRepository; | ||
private final NotificationRepository notificationRepository; | ||
|
||
public void sendUrgingPush(PushUrgingSendRequest request) { | ||
final Member currentMember = memberUtil.getCurrentMember(); | ||
final Mission mission = | ||
missionRepository | ||
.findById(request.missionId()) | ||
.orElseThrow(() -> new CustomException(ErrorCode.MISSION_NOT_FOUND)); | ||
final Member targetMember = mission.getMember(); | ||
|
||
validateSelfSending(currentMember.getId(), targetMember.getId()); | ||
validateMissionNotCompletedToday(mission); | ||
|
||
fcmService.sendMessageSync( | ||
targetMember.getFcmInfo().getFcmToken(), | ||
PUSH_URGING_TITLE, | ||
String.format( | ||
PushNotificationConstants.PUSH_URGING_CONTENT, | ||
currentMember.getProfile().getNickname(), | ||
mission.getName())); | ||
Notification notification = | ||
Notification.createNotification( | ||
NotificationType.MISSION_URGING, currentMember, targetMember); | ||
notificationRepository.save(notification); | ||
} | ||
|
||
private void validateMissionNotCompletedToday(Mission mission) { | ||
if (mission.isCompletedMissionToday()) { | ||
throw new CustomException(ErrorCode.TODAY_COMPLETED_MISSION_SENDING_NOT_ALLOWED); | ||
} | ||
} | ||
|
||
private void validateSelfSending(Long currentMemberId, Long targetMemberId) { | ||
if (currentMemberId.equals(targetMemberId)) { | ||
throw new CustomException(ErrorCode.SELF_SENDING_NOT_ALLOWED); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/java/com/depromeet/domain/notification/dto/request/PushUrgingSendRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.depromeet.domain.notification.dto.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record PushUrgingSendRequest( | ||
@NotNull(message = "missionId는 null일 수 없습니다.") Long missionId) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...epromeet/global/config/fcm/FcmConfig.java → ...depromeet/infra/config/fcm/FcmConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.