Skip to content

Commit

Permalink
feat: Notification Test - WebpushConfig 링크 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
BambooKim committed May 9, 2023
1 parent 58cb8a1 commit fa1989d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/main/java/grimuri/backend/domain/image/ImageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ImageService {


@Async
public void saveImageWithDiary(ImageRequestDto.Complete request) {
public void saveImageWithDiaryAndNotify(ImageRequestDto.Complete request) {
Diary findDiary = diaryRepository.findById(request.getDiaryId()).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Diary가 존재하지 않습니다.");
});
Expand Down Expand Up @@ -87,10 +87,19 @@ public void notifyImageComplete(List<FCMToken> tokenList, Long diaryId, String d
.setBody("일기 \"" + diaryTitle + "\"의 이미지 생성이 완료되었습니다.")
.build();

WebpushFcmOptions fcmOptions = WebpushFcmOptions.builder()
.setLink("/select/" + diaryId.toString())
.build();

WebpushConfig webpushConfig = WebpushConfig.builder()
.setFcmOptions(fcmOptions)
.build();

MulticastMessage message = MulticastMessage.builder()
.setNotification(notification)
.putData("diaryId", String.valueOf(diaryId))
.putData("diaryTitle", diaryTitle)
.setWebpushConfig(webpushConfig)
.addAllTokens(tokenList.stream().map(FCMToken::getToken).collect(Collectors.toList()))
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ImageControllerImpl implements ImageController {
public ResponseEntity<String> imageGenerateComplete(@RequestBody ImageRequestDto.Complete request) {
log.debug("\tRequest Body: {}", request.toString());

imageService.saveImageWithDiary(request);
imageService.saveImageWithDiaryAndNotify(request);

return ResponseEntity.status(HttpStatus.CREATED).body("Success");
}
Expand Down

0 comments on commit fa1989d

Please sign in to comment.