Skip to content

Commit

Permalink
Merge pull request #105 from Begin-Vegan/develop
Browse files Browse the repository at this point in the history
[DEPLOY]
  • Loading branch information
jisujeong0 authored Sep 27, 2024
2 parents e30af43 + c144c3a commit 0f78553
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public ResponseEntity<?> addSignUpUserInfo(UserPrincipal userPrincipal, AddUserI

// ์›ฐ์ปด ๋ฉ”์„ธ์ง€ ์ „์†ก
String msg = "๋น„๊ธด, ๋น„๊ฑด์— ์˜ค์‹  ๊ฒƒ์„ ํ™˜์˜ํ•ด์š”. ๋น„๊ฑฐ๋„ˆ์˜ ์—ฌ์ •์œผ๋กœ ํ•จ๊ป˜ ๋– ๋‚˜์š”!";
FcmSendDto fcmSendDto = fcmService.makeFcmSendDto(user, AlarmType.INFORMATION, null, msg, null, null);
FcmSendDto fcmSendDto = fcmService.makeFcmSendDto(user.getFcmToken(), AlarmType.INFORMATION, null, msg, null, null);
fcmService.sendMessageTo(fcmSendDto);

return ResponseEntity.ok(apiResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public class FcmService {

@Transactional
public ResponseEntity<?> sendMessageTo(FcmSendDto fcmSendDto) throws IOException {
User user = validateUserById(fcmSendDto.getUserId());
String msg = "๋ฉ”์„ธ์ง€ ์ „์†ก์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค(FCM ํ† ํฐ์ด ์กด์žฌํ•˜์ง€ ์•Š์Œ)";
String fcmToken = fcmSendDto.getToken();
User user = validateUserByToken(fcmToken);

String fcmToken = user.getFcmToken();
String msg = "๋ฉ”์„ธ์ง€ ์ „์†ก์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค(FCM ํ† ํฐ์ด ์กด์žฌํ•˜์ง€ ์•Š์Œ)";
if (fcmToken != null) {
if (user.getAlarmSetting()) {
sendCombinedMessage(fcmToken, fcmSendDto);
Expand Down Expand Up @@ -179,11 +179,10 @@ private String getAccessToken() throws IOException {
return googleCredentials.getAccessToken().getTokenValue();
}

public FcmSendDto makeFcmSendDto(User user, AlarmType alarmType, Long itemId, String body, MessageType messageType, UserLevel userLevel) {
public FcmSendDto makeFcmSendDto(String token, AlarmType alarmType, Long itemId, String body, MessageType messageType, UserLevel userLevel) {
return FcmSendDto.builder()
.userId(user.getId())
.token(token)
.alarmType(alarmType)

.itemId(itemId)
.title("๋น„๊ธด, ๋น„๊ฑด")
.body(body)
Expand All @@ -194,7 +193,7 @@ public FcmSendDto makeFcmSendDto(User user, AlarmType alarmType, Long itemId, St

@Transactional
public void saveAlarmHistory(FcmSendDto fcmSendDto) {
User user = validateUserById(fcmSendDto.getUserId());
User user = validateUserByToken(fcmSendDto.getToken());

Alarm alarm = Alarm.builder()
.alarmType(fcmSendDto.getAlarmType())
Expand All @@ -206,8 +205,8 @@ public void saveAlarmHistory(FcmSendDto fcmSendDto) {
alarmRepository.save(alarm);
}

private User validateUserById(Long userId) {
Optional<User> findUser = userRepository.findById(userId);
private User validateUserByToken(String token) {
Optional<User> findUser = userRepository.findByFcmToken(token);
DefaultAssert.isTrue(findUser.isPresent(), "์œ ์ € ์ •๋ณด๊ฐ€ ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.");
return findUser.get();
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/beginvegan/domain/fcm/dto/FcmSendDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class FcmSendDto {

@Schema(type = "Long", example = "1", description = "์œ ์ €์˜ ๊ณ ์œ  id์ž…๋‹ˆ๋‹ค.")
private Long userId;
@Schema(type = "String", example = "dNFDkmL3R04:APA91bH5XrLbje0cbjkPv8jSDFg9v4hdOcf6rLtWfFzCqH8zqG7NhrS8Dp", description = "์œ ์ €์˜ fcmToken์ž…๋‹ˆ๋‹ค.")
private String token;

@Schema(type = "String", example = "๋น„๊ธด, ๋น„๊ฑด", description = "์•Œ๋ฆผ์˜ ์ œ๋ชฉ์ž…๋‹ˆ๋‹ค.")
private String title;
Expand All @@ -40,8 +40,8 @@ public class FcmSendDto {
private UserLevel userLevel;

@Builder
public FcmSendDto(Long userId, String title, String body, AlarmType alarmType, Long itemId, MessageType messageType, UserLevel userLevel) {
this.userId = userId;
public FcmSendDto(String token, String title, String body, AlarmType alarmType, Long itemId, MessageType messageType, UserLevel userLevel) {
this.token = token;
this.title = title;
this.body = body;
this.alarmType = alarmType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public ResponseEntity<?> recommendReviews(UserPrincipal userPrincipal, Long revi
userService.checkUserLevel(user);
// ํ‘ธ์‹œ์•Œ๋ฆผ
String msg = "'" + user.getNickname() + "'" + "๋‹˜์˜ ๋ฆฌ๋ทฐ๊ฐ€ ์ถ”์ฒœ์„ ๋ฐ›์•˜์–ด์š”.";
FcmSendDto fcmSendDto = fcmService.makeFcmSendDto(review.getUser(), AlarmType.MAP, reviewId, msg, MessageType.REVIEW_RECOMMEND, null);
FcmSendDto fcmSendDto = fcmService.makeFcmSendDto(review.getUser().getFcmToken(), AlarmType.MAP, reviewId, msg, MessageType.REVIEW_RECOMMEND, null);
fcmService.sendMessageTo(fcmSendDto);
}
}
Expand Down Expand Up @@ -307,7 +307,7 @@ public ResponseEntity<?> reportReview(UserPrincipal userPrincipal, Long reviewId

// ํ‘ธ์‹œ์•Œ๋ฆผ ์ƒ์„ฑ
String msg = "๋ฆฌ๋ทฐ ์‹ ๊ณ ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์ ‘์ˆ˜๋˜์—ˆ์–ด์š”. ์šด์˜์ž์˜ ๊ฒ€ํ†  ํ›„ ์กฐ์น˜๋ฅผ ์ทจํ•  ์˜ˆ์ •์ด์—์š”.";
FcmSendDto fcmSendDto = fcmService.makeFcmSendDto(user, AlarmType.MAP, reviewId, msg, MessageType.REVIEW_REPORT, null);
FcmSendDto fcmSendDto = fcmService.makeFcmSendDto(user.getFcmToken(), AlarmType.MAP, reviewId, msg, MessageType.REVIEW_REPORT, null);
fcmService.sendMessageTo(fcmSendDto);

ApiResponse apiResponse = ApiResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public void checkUserLevel(User user) throws IOException {
if (originalLevel != newLevel) {
if (newLevel.getOrder() > originalLevel.getOrder()) {
String msg = "๋‚˜๋งŒ์˜ ์‹๋ฌผ์ด ์„ฑ์žฅํ–ˆ์–ด์š”. mypage์—์„œ ํ™•์ธํ•ด ๋ณด์„ธ์š”!";
FcmSendDto fcmSendDto = fcmService.makeFcmSendDto(user, AlarmType.MYPAGE, null, msg, MessageType.LEVEL_UP, newLevel);
FcmSendDto fcmSendDto = fcmService.makeFcmSendDto(user.getFcmToken(), AlarmType.MYPAGE, null, msg, MessageType.LEVEL_UP, newLevel);
fcmService.sendMessageTo(fcmSendDto);
}
user.updateUserLevel(newLevel);
Expand Down

0 comments on commit 0f78553

Please sign in to comment.