SmsTemplateController.java
3.16 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.diligrp.assistant.sms.controller;
import com.diligrp.assistant.shared.domain.Message;
import com.diligrp.assistant.shared.util.AssertUtils;
import com.diligrp.assistant.sms.Constants;
import com.diligrp.assistant.sms.SmsProperties;
import com.diligrp.assistant.sms.domain.SmsAccessToken;
import com.diligrp.assistant.sms.domain.SmsTemplateDTO;
import com.diligrp.assistant.sms.service.SmsTemplateService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/sms/template")
public class SmsTemplateController {
@Resource
private SmsProperties smsProperties;
@Resource
private SmsTemplateService smsTemplateService;
@RequestMapping(value = "/create.do")
public Message<String> create(@RequestBody SmsTemplateDTO request, @RequestHeader(Constants.HEADER_AUTHORIZATION) String authorization) {
SmsAccessToken.of(authorization, smsProperties.getPublicKey());
AssertUtils.notNull(request.getPipeline(), "pipeline missed");
AssertUtils.notNull(request.getType(), "type missed");
AssertUtils.notEmpty(request.getName(), "name missed");
AssertUtils.notEmpty(request.getContent(), "content missed");
String templateId = smsTemplateService.createSmsTemplate(request);
return Message.success(templateId);
}
@RequestMapping(value = "/modify.do")
public Message<?> modify(@RequestBody SmsTemplateDTO request, @RequestHeader(Constants.HEADER_AUTHORIZATION) String authorization) {
SmsAccessToken.of(authorization, smsProperties.getPublicKey());
AssertUtils.notEmpty(request.getTemplateId(), "templateId missed");
smsTemplateService.modifySmsTemplate(request);
return Message.success();
}
@RequestMapping(value = "/approve.do")
public Message<?> approve(@RequestParam("templateId") String templateId, @RequestHeader(Constants.HEADER_AUTHORIZATION) String authorization) {
SmsAccessToken.of(authorization, smsProperties.getPublicKey());
smsTemplateService.approveSmsTemplate(templateId);
return Message.success();
}
@RequestMapping(value = "/disable.do")
public Message<?> disable(@RequestParam("templateId") String templateId, @RequestHeader(Constants.HEADER_AUTHORIZATION) String authorization) {
SmsAccessToken.of(authorization, smsProperties.getPublicKey());
smsTemplateService.disableSmsTemplate(templateId);
return Message.success();
}
@RequestMapping(value = "/enable.do")
public Message<?> enable(@RequestParam("templateId") String templateId, @RequestHeader(Constants.HEADER_AUTHORIZATION) String authorization) {
SmsAccessToken.of(authorization, smsProperties.getPublicKey());
smsTemplateService.enableSmsTemplate(templateId);
return Message.success();
}
@RequestMapping(value = "/delete.do")
public Message<?> delete(@RequestParam("templateId") String templateId, @RequestHeader(Constants.HEADER_AUTHORIZATION) String authorization) {
SmsAccessToken.of(authorization, smsProperties.getPublicKey());
smsTemplateService.deleteSmsTemplate(templateId);
return Message.success();
}
}