-
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 #29 from Modagbul/feat/alarm_minsu
Feat/alarm : 알람 기능
- Loading branch information
Showing
26 changed files
with
524 additions
and
17 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
42 changes: 42 additions & 0 deletions
42
src/main/java/com/moing/backend/domain/board/application/service/SendBoardAlarmUserCase.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,42 @@ | ||
package com.moing.backend.domain.board.application.service; | ||
|
||
import com.moing.backend.domain.board.domain.entity.Board; | ||
import com.moing.backend.domain.member.domain.entity.Member; | ||
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.request.MultiRequest; | ||
import com.moing.backend.global.config.fcm.service.FcmService; | ||
import com.moing.backend.global.response.BaseServiceResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.transaction.Transactional; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static com.moing.backend.global.config.fcm.constant.NewUploadTitle.UPLOAD_NOTICE_NEW_TITLE; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class SendBoardAlarmUserCase { | ||
|
||
private final TeamMemberGetService teamMemberGetService; | ||
private final FcmService fcmService; | ||
|
||
public void sendNewUploadAlarm(BaseServiceResponse baseServiceResponse, Board board) { | ||
Member member = baseServiceResponse.getMember(); | ||
Team team = baseServiceResponse.getTeam(); | ||
|
||
if (board.isNotice() && member.isNewUploadPush()) { | ||
String title = team.getName() + " " + UPLOAD_NOTICE_NEW_TITLE.getTitle(); | ||
String message = board.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); | ||
} | ||
} | ||
} | ||
} | ||
|
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
43 changes: 43 additions & 0 deletions
43
src/main/java/com/moing/backend/domain/team/application/service/SendTeamAlarmUserCase.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,43 @@ | ||
package com.moing.backend.domain.team.application.service; | ||
|
||
import com.moing.backend.domain.teamMember.domain.service.TeamMemberGetService; | ||
import com.moing.backend.global.config.fcm.dto.request.MultiRequest; | ||
import com.moing.backend.global.config.fcm.service.FcmService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.transaction.Transactional; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static com.moing.backend.global.config.fcm.constant.NewUploadTitle.UPLOAD_NOTICE_NEW_TITLE; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class SendTeamAlarmUserCase { | ||
private final TeamMemberGetService teamMemberGetService; | ||
private final FcmService fcmService; | ||
|
||
public void sendApprovalAlarm(Long teamId) { | ||
//TODO: 승인, 반려 문구 constant로 | ||
String title = "소모임 승인 안내"; | ||
String message = "소모임이 승인되었습니다."; | ||
sendAlarm(teamId, title, message); | ||
} | ||
|
||
public void sendRejectionAlarm(Long teamId) { | ||
String title = "소모임 반려 안내"; | ||
String message = "소모임이 반려되었습니다."; | ||
sendAlarm(teamId, title, message); | ||
} | ||
|
||
private void sendAlarm(Long teamId, String title, String message) { | ||
Optional<List<String>> fcmTokens = teamMemberGetService.getFcmTokens(teamId); | ||
if(fcmTokens.isPresent() && !fcmTokens.get().isEmpty()) { | ||
MultiRequest toMultiRequest = new MultiRequest(fcmTokens.get(), title, message); | ||
fcmService.sendMultipleDevices(toMultiRequest); | ||
} | ||
} | ||
} | ||
|
33 changes: 30 additions & 3 deletions
33
src/main/java/com/moing/backend/domain/team/presentation/AdminTeamController.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 |
---|---|---|
@@ -1,18 +1,45 @@ | ||
package com.moing.backend.domain.team.presentation; | ||
|
||
import com.moing.backend.domain.team.application.service.CreateTeamUserCase; | ||
import com.moing.backend.domain.team.application.service.SendTeamAlarmUserCase; | ||
import com.moing.backend.global.response.SuccessResponse; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import static com.moing.backend.domain.team.presentation.constant.TeamResponseMessage.*; | ||
|
||
@RestController | ||
@AllArgsConstructor | ||
@RequestMapping("/api/admin/team") | ||
public class AdminTeamController { | ||
|
||
//TODO 소모임 승인, 반려하기 | ||
|
||
private final CreateTeamUserCase createTeamService; | ||
private final SendTeamAlarmUserCase sendTeamAlarmUserCase; | ||
|
||
/** | ||
* 소모임 승인 알림 보내기 | ||
* [POST] api/admin/team/approval/{teamId} | ||
* 작성자 : 김민수 | ||
*/ | ||
|
||
@PostMapping("/approval/{teamId}") | ||
public ResponseEntity<SuccessResponse> sendApproveAlarm(@PathVariable Long teamId) { | ||
this.sendTeamAlarmUserCase.sendApprovalAlarm(teamId); | ||
return ResponseEntity.ok(SuccessResponse.create(SEND_APPROVAL_ALARM_SUCCESS.getMessage())); | ||
} | ||
|
||
/** | ||
* 소모임 반려 알림 보내기 | ||
* [POST] api/admin/team/rejection/{teamId} | ||
* 작성자: 김민수 | ||
*/ | ||
@PostMapping("/rejection/{teamId}") | ||
public ResponseEntity<SuccessResponse> sendRejectionAlarm(@PathVariable Long teamId){ | ||
this.sendTeamAlarmUserCase.sendRejectionAlarm(teamId); | ||
return ResponseEntity.ok(SuccessResponse.create(SEND_REJECTION_ALARM_SUCCESS.getMessage())); | ||
} | ||
|
||
} |
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
3 changes: 3 additions & 0 deletions
3
...ava/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepository.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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
package com.moing.backend.domain.teamMember.domain.repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface TeamMemberCustomRepository { | ||
List<Long> findMemberIdsByTeamId(Long teamId); | ||
Optional<List<String>> findFcmTokensByTeamIdAndMemberId(Long teamId, Long memberId); | ||
Optional<List<String>> findFcmTokensByTeamId(Long teamId); | ||
} |
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
59 changes: 59 additions & 0 deletions
59
src/main/java/com/moing/backend/global/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.moing.backend.global.config.fcm; | ||
|
||
import com.google.auth.oauth2.GoogleCredentials; | ||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.FirebaseOptions; | ||
import com.google.firebase.messaging.FirebaseMessaging; | ||
import com.moing.backend.global.config.fcm.exception.InitializeException; | ||
import com.moing.backend.global.config.fcm.exception.MessagingException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
|
||
@Configuration | ||
@Slf4j | ||
public class FcmConfig { | ||
|
||
|
||
@Value("${firebase.config.path}") | ||
private String firebaseConfigPath; | ||
|
||
@Value("${firebase.config.projectId}") | ||
private String projectId; | ||
|
||
@Bean | ||
public FirebaseApp firebaseApp() { | ||
try { | ||
FileInputStream serviceAccount = new FileInputStream(firebaseConfigPath); | ||
|
||
FirebaseOptions options = FirebaseOptions.builder() | ||
.setCredentials(GoogleCredentials.fromStream(serviceAccount)) | ||
.setProjectId(projectId) | ||
.build(); | ||
|
||
return FirebaseApp.initializeApp(options); | ||
} catch (FileNotFoundException e) { | ||
throw new IllegalStateException("파일을 찾을 수 없습니다." + e.getMessage()); | ||
} catch (IOException e) { | ||
throw new InitializeException(); | ||
} | ||
} | ||
|
||
@Bean | ||
public FirebaseMessaging firebaseMessaging() { | ||
try { | ||
return FirebaseMessaging.getInstance(firebaseApp()); | ||
} catch (IllegalStateException e) { | ||
throw new MessagingException("FirebaseApp 초기화에 실패하였습니다." + e.getMessage()); | ||
} catch (NullPointerException e) { | ||
throw new IllegalStateException("FirebaseApp을 불러오는데 실패하였습니다." + e.getMessage()); | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException("firebaseConfigPath를 읽어오는데 실패하였습니다." + e.getMessage()); | ||
} | ||
} | ||
} |
Oops, something went wrong.