-
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.
Merge pull request #260 from Modagbul/main
- Loading branch information
Showing
9 changed files
with
165 additions
and
4 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
...in/java/com/moing/backend/domain/member/application/service/UpdateRemindAlarmUseCase.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,85 @@ | ||
package com.moing.backend.domain.member.application.service; | ||
|
||
import com.moing.backend.domain.history.application.dto.response.MemberIdAndToken; | ||
import com.moing.backend.domain.history.application.mapper.AlarmHistoryMapper; | ||
import com.moing.backend.domain.history.application.service.SaveMultiAlarmHistoryUseCase; | ||
import com.moing.backend.domain.history.domain.entity.AlarmType; | ||
import com.moing.backend.domain.history.domain.entity.PagePath; | ||
import com.moing.backend.domain.member.domain.entity.Member; | ||
import com.moing.backend.domain.member.domain.service.MemberGetService; | ||
import com.moing.backend.domain.mission.application.service.SendMissionStartAlarmUseCase; | ||
import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; | ||
import com.moing.backend.global.config.fcm.dto.request.MultiRequest; | ||
import com.moing.backend.global.config.fcm.service.MultiMessageSender; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.scheduling.annotation.EnableAsync; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.transaction.Transactional; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.moing.backend.global.config.fcm.constant.RemindMissionTitle.REMIND_ON_MONDAY_MESSAGE; | ||
import static com.moing.backend.global.config.fcm.constant.RemindMissionTitle.REMIND_ON_MONDAY_TITLE; | ||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class UpdateRemindAlarmUseCase { | ||
|
||
private final MemberGetService memberGetService; | ||
private final SaveMultiAlarmHistoryUseCase saveMultiAlarmHistoryUseCase; | ||
private final MultiMessageSender multiMessageSender; | ||
|
||
String REMIND_NAME = "미션 리마인드"; | ||
|
||
|
||
public Boolean sendUpdateAppPushAlarm() { | ||
|
||
String title = "MOING 업데이트 소식"; | ||
String message = "이제 누구나 미션을 만들 수 있어요. 지금 업데이트하고 다른 소식도 확인해보세요!"; | ||
|
||
List<Member> allMemberOfPushAlarm = memberGetService.getAllMemberOfPushAlarm(); | ||
|
||
Optional<List<MemberIdAndToken>> memberIdAndTokens = mapToMemberAndToken(allMemberOfPushAlarm); | ||
Optional<List<MemberIdAndToken>> pushMemberIdAndToken = isPushMemberIdAndToken(allMemberOfPushAlarm); | ||
|
||
if (pushMemberIdAndToken.isPresent() && !pushMemberIdAndToken.get().isEmpty()) { | ||
multiMessageSender.send(new MultiRequest(pushMemberIdAndToken.get(), title, message, "", REMIND_NAME, AlarmType.REMIND, PagePath.MISSION_ALL_PTAH.getValue())); | ||
} | ||
if (memberIdAndTokens.isPresent() && !memberIdAndTokens.get().isEmpty()) { | ||
saveMultiAlarmHistoryUseCase.saveAlarmHistories(AlarmHistoryMapper.getMemberIds(memberIdAndTokens.get()), "", title, message, REMIND_NAME, AlarmType.REMIND, PagePath.MISSION_ALL_PTAH.getValue()); | ||
} | ||
return true; | ||
|
||
|
||
} | ||
|
||
public Optional<List<MemberIdAndToken>> mapToMemberAndToken(List<Member> members) { | ||
return Optional.of(members.stream() | ||
.map(member -> MemberIdAndToken.builder() | ||
.fcmToken(member.getFcmToken()) | ||
.memberId(member.getMemberId()) | ||
.build()) | ||
.collect(Collectors.toList())); | ||
} | ||
public Optional<List<MemberIdAndToken>> isPushMemberIdAndToken(List<Member> members) { | ||
return Optional.of(members.stream() | ||
.map(member -> { | ||
if (member.isRemindPush() && !member.isSignOut()) { | ||
return MemberIdAndToken.builder() | ||
.fcmToken(member.getFcmToken()) | ||
.memberId(member.getMemberId()) | ||
.build(); | ||
} | ||
return null; | ||
}) | ||
.filter(Objects::nonNull) | ||
.collect(Collectors.toList())); | ||
} | ||
|
||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/moing/backend/domain/member/exception/NotFoundRemindAlarmException.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,11 @@ | ||
package com.moing.backend.domain.member.exception; | ||
|
||
import com.moing.backend.global.response.ErrorCode; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public class NotFoundRemindAlarmException extends MemberException { | ||
public NotFoundRemindAlarmException() { | ||
super(ErrorCode.NOT_FOUND_ALL_MEMBER, | ||
HttpStatus.NOT_FOUND); | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
...st/java/com/moing/backend/domain/member/domain/repository/MemberCustomRepositoryTest.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,35 @@ | ||
//package com.moing.backend.domain.member.domain.repository; | ||
// | ||
//import com.moing.backend.domain.member.domain.entity.Member; | ||
//import org.junit.jupiter.api.Test; | ||
//import org.springframework.beans.factory.annotation.Autowired; | ||
//import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | ||
//import org.springframework.boot.test.context.SpringBootTest; | ||
//import org.springframework.test.context.ActiveProfiles; | ||
//import org.springframework.transaction.annotation.Transactional; | ||
// | ||
//import javax.persistence.EntityManager; | ||
// | ||
//import java.util.List; | ||
// | ||
//import static org.junit.jupiter.api.Assertions.*; | ||
//@SpringBootTest | ||
//@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) | ||
//@ActiveProfiles("dev") | ||
//@Transactional | ||
//class MemberCustomRepositoryTest { | ||
// | ||
// @Autowired | ||
// EntityManager em; | ||
// | ||
// @Autowired | ||
// private MemberRepository memberRepository; | ||
// @Test | ||
// void findAllMemberOnPushAlarm() { | ||
// List<Member> members = memberRepository.findAllMemberOnPushAlarm().orElseThrow(); | ||
// for (Member member : members) { | ||
// System.out.println(member.getNickName()); | ||
// } | ||
// | ||
// } | ||
//} |