-
-
Notifications
You must be signed in to change notification settings - Fork 253
/
create_sms_provider_logic.go
45 lines (39 loc) · 1.21 KB
/
create_sms_provider_logic.go
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
package smsprovider
import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/zeromicro/go-zero/core/errorx"
"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
"github.com/suyuan32/simple-admin-message-center/types/mcms"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateSmsProviderLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCreateSmsProviderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateSmsProviderLogic {
return &CreateSmsProviderLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CreateSmsProviderLogic) CreateSmsProvider(req *types.SmsProviderInfo) (resp *types.BaseMsgResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
data, err := l.svcCtx.McmsRpc.CreateSmsProvider(l.ctx,
&mcms.SmsProviderInfo{
Name: req.Name,
SecretId: req.SecretId,
SecretKey: req.SecretKey,
Region: req.Region,
IsDefault: req.IsDefault,
})
if err != nil {
return nil, err
}
return &types.BaseMsgResp{Msg: l.svcCtx.Trans.Trans(l.ctx, data.Msg)}, nil
}