-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestNotificationController.java
More file actions
51 lines (38 loc) · 1.93 KB
/
TestNotificationController.java
File metadata and controls
51 lines (38 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.project.controller;
import java.util.Map;
import java.util.UUID;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.project.notification.consumer.NotificationEvent;
import com.project.notification.service.MessageSendService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequiredArgsConstructor
public class TestNotificationController {
private final MessageSendService messageSendService;
/** [테스트용] Kafka 없이 HTTP 요청으로 알림 발송 로직 직접 트리거 */
@PostMapping("/test/send-notification")
public String sendTest(@RequestBody Map<String, Object> request) {
// 1. Postman JSON 데이터를 추출
Long subId = Long.valueOf((Integer) request.get("subId"));
String email = (String) request.get("email");
String phoneNumber = (String) request.get("phoneNumber");
Long templateGroupId = Long.valueOf((Integer) request.get("templateGroupId"));
// variables는 리스트가 포함될 수 있으므로 Object로 캐스팅
Map<String, Object> variables = (Map<String, Object>) request.get("variables");
// 2. 가짜 이벤트 객체(UsageNotificationEvent) 생성
NotificationEvent event =
new NotificationEvent(
UUID.randomUUID(), // 임의의 Event ID 생성
templateGroupId,
new NotificationEvent.SubscriptionInfo(subId, phoneNumber, email),
variables);
log.info("[TEST TRIGGER] subId={}, groupId={}", subId, templateGroupId);
// 3. 서비스 로직 실행 (템플릿 조립 -> Mock Server 전송)
messageSendService.processEvent(event);
return "Test Triggered! EventID: " + event.eventId();
}
}