Skip to content

Commit

Permalink
test: notification + data 타입 테스트 api 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kimyu0218 committed Dec 8, 2024
1 parent eeea192 commit 9cfb184
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,19 @@ public void sendGroupData(final String title, final String body, final String to
private Data makeData(final String title, final String body, final Long missionId) {
return new Data(title, body, missionId);
}

public void sendNotificationWithData(String title, String body, String topic) {
Notification notification = makeNotification(title, body);
Message message = Message.builder()
.setNotification(notification)
.putData("missionId", TopicGenerator.extractIdentifier(topic))
.setTopic(topic)
.build();

try {
FirebaseMessaging.getInstance().send(message);
} catch (FirebaseMessagingException e) {
throw new BaseException(ErrorCode.FAILED_TO_SEND_GROUP_MESSAGE, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ public class TopicGenerator {
public static String getTopic(Long missionId) {
return TOPIC_PREFIX + missionId;
}

public static String extractIdentifier(String topic) {
return topic.replace(TOPIC_PREFIX, "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface PushMessageSender {
void sendIndividualData(final String title, final String body, final String token, final Long missionId);

void sendGroupData(final String title, final String body, final String topic, final Long missionId);

void sendNotificationWithData(final String title, final String body, final String topic);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.nexters.goalpanzi.presentation.fcmtest;

import com.nexters.goalpanzi.application.firebase.TopicGenerator;
import com.nexters.goalpanzi.infrastructure.firebase.PushMessageSender;
import com.nexters.goalpanzi.infrastructure.firebase.TopicSubscriber;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -57,4 +58,19 @@ ResponseEntity<Void> sendData(

return ResponseEntity.ok().build();
}

@Operation
@GetMapping("notification-with-data")
ResponseEntity<Void> sendNotificationWithData(
@Schema(description = "deviceToken", requiredMode = Schema.RequiredMode.REQUIRED)
@RequestParam final String deviceToken
) {
pushMessageSender.sendNotificationWithData(
"혼합 메시지 테스트",
"notification { title: string, body: string }, data { missionId: string }",
TopicGenerator.getTopic(1L)
);

return ResponseEntity.ok().build();
}
}

0 comments on commit 9cfb184

Please sign in to comment.