SmsController.java
1.56 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
package com.ecommerce.notification.controller;
import com.ecommerce.notification.model.dto.SmsRequest;
import com.ecommerce.notification.service.SmsService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/api/sms")
@RequiredArgsConstructor
public class SmsController {
private final SmsService smsService;
@PostMapping("/send")
public ResponseEntity<Map<String, Object>> sendSms(@Valid @RequestBody SmsRequest request) {
boolean success = smsService.sendSms(request);
Map<String, Object> response = new HashMap<>();
response.put("success", success);
response.put("message", success ? "SMS sent successfully" : "Failed to send SMS");
response.put("to", request.getTo());
return ResponseEntity.ok(response);
}
@GetMapping("/test")
public ResponseEntity<Map<String, String>> testSms() {
SmsRequest request = new SmsRequest();
request.setTo("+1234567890");
request.setMessage("Test SMS from Notification Service");
boolean success = smsService.sendSms(request);
Map<String, String> response = new HashMap<>();
response.put("status", success ? "SUCCESS" : "FAILED");
response.put("message", success ? "Test SMS sent successfully" : "Failed to send test SMS");
return ResponseEntity.ok(response);
}
}