forked from suyuan32/simple-admin-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_email_provider_list_logic.go
69 lines (61 loc) · 1.77 KB
/
get_email_provider_list_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package emailprovider
import (
"context"
"github.com/huuhoait/simple-admin-common/i18n"
"github.com/zeromicro/go-zero/core/errorx"
"github.com/huuhoait/simple-admin-core/api/internal/svc"
"github.com/huuhoait/simple-admin-core/api/internal/types"
"github.com/huuhoait/simple-admin-message-center/types/mcms"
"github.com/zeromicro/go-zero/core/logx"
)
type GetEmailProviderListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetEmailProviderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetEmailProviderListLogic {
return &GetEmailProviderListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetEmailProviderListLogic) GetEmailProviderList(req *types.EmailProviderListReq) (resp *types.EmailProviderListResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
data, err := l.svcCtx.McmsRpc.GetEmailProviderList(l.ctx,
&mcms.EmailProviderListReq{
Page: req.Page,
PageSize: req.PageSize,
Name: req.Name,
EmailAddr: req.EmailAddr,
})
if err != nil {
return nil, err
}
resp = &types.EmailProviderListResp{}
resp.Msg = l.svcCtx.Trans.Trans(l.ctx, i18n.Success)
resp.Data.Total = data.GetTotal()
for _, v := range data.Data {
resp.Data.Data = append(resp.Data.Data,
types.EmailProviderInfo{
BaseIDInfo: types.BaseIDInfo{
Id: v.Id,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
},
Name: v.Name,
AuthType: v.AuthType,
EmailAddr: v.EmailAddr,
Password: v.Password,
HostName: v.HostName,
Identify: v.Identify,
Secret: v.Secret,
Port: v.Port,
Tls: v.Tls,
IsDefault: v.IsDefault,
})
}
return resp, nil
}