Skip to content

Commit

Permalink
Merge pull request #110 from Modagbul/feat/alarm_minsu
Browse files Browse the repository at this point in the history
Feat/alarm minsu
  • Loading branch information
seungueonn authored Dec 4, 2023
2 parents 012f30d + 1c16c6a commit dd626ac
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import com.moing.backend.domain.mission.domain.entity.Mission;
import com.moing.backend.domain.team.domain.entity.Team;
import com.moing.backend.domain.teamMember.domain.service.TeamMemberGetService;
import com.moing.backend.global.config.fcm.dto.event.FcmEvent;
import com.moing.backend.global.config.fcm.dto.request.MultiRequest;
import com.moing.backend.global.config.fcm.service.FcmService;
import com.moing.backend.global.response.BaseServiceResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.EventListener;
import java.util.List;
import java.util.Optional;

Expand All @@ -24,20 +27,16 @@
public class SendMissionCreateAlarmUseCase {

private final TeamMemberGetService teamMemberGetService;
private final FcmService fcmService;
private final ApplicationEventPublisher eventPublisher;

public void sendNewMissionUploadAlarm(Member member, Mission mission) {
Team team = mission.getTeam();
Optional<List<String>> fcmTokensExceptMe = teamMemberGetService.getFcmTokensExceptMe(team.getTeamId(), member.getMemberId());

String title = team.getName() + " " + NEW_SINGLE_MISSION_COMING.getTitle();
String message = mission.getTitle();

Optional<List<String>> fcmTokens = teamMemberGetService.getFcmTokensExceptMe(team.getTeamId(), member.getMemberId());
if (fcmTokens.isPresent() && !fcmTokens.get().isEmpty()) {
MultiRequest toMultiRequest = new MultiRequest(fcmTokens.get(), title, message);
fcmService.sendMultipleDevices(toMultiRequest);

eventPublisher.publishEvent(new FcmEvent(title, message, fcmTokens.get()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
public interface TeamMemberCustomRepository {
List<Long> findMemberIdsByTeamId(Long teamId);
Optional<List<String>> findFcmTokensByTeamIdAndMemberId(Long teamId, Long memberId);
Optional<List<String>> findFcmTokensByTeamId(Long teamId);
List<TeamMemberInfo> findTeamMemberInfoByTeamId(Long teamId);
List<TeamMember> findTeamMemberByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,8 @@ public Optional<List<String>> findFcmTokensByTeamIdAndMemberId(Long teamId, Long
.from(teamMember)
.where(teamMember.team.teamId.eq(teamId)
.and(teamMember.member.isNewUploadPush.eq(true))
.and(teamMember.member.memberId.ne(memberId)))
.fetch();

return result.isEmpty() ? Optional.empty() : Optional.of(result);
}

@Override
public Optional<List<String>> findFcmTokensByTeamId(Long teamId) {
List<String> result = queryFactory.select(teamMember.member.fcmToken)
.from(teamMember)
.where(teamMember.team.teamId.eq(teamId)
.and(teamMember.member.isNewUploadPush.eq(true)))
.and(teamMember.member.memberId.ne(memberId))
.and(teamMember.isDeleted.eq(false)))
.fetch();

return result.isEmpty() ? Optional.empty() : Optional.of(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ public Optional<List<String>> getFcmTokensExceptMe(Long teamId, Long memberId) {
return teamMemberRepository.findFcmTokensByTeamIdAndMemberId(teamId, memberId);
}

public Optional<List<String>> getFcmTokens(Long teamId) {
return teamMemberRepository.findFcmTokensByTeamId(teamId);
}

public List<TeamMemberInfo> getTeamMemberInfo(Long teamId){
return teamMemberRepository.findTeamMemberInfoByTeamId(teamId);
}
Expand Down

0 comments on commit dd626ac

Please sign in to comment.