forked from suyuan32/simple-admin-core
/
create_oauth_provider_logic.go
47 lines (38 loc) · 1.26 KB
/
create_oauth_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
46
47
package oauthprovider
import (
"context"
"github.com/huuhoait/simple-admin-common/i18n"
"github.com/huuhoait/simple-admin-core/rpc/internal/svc"
"github.com/huuhoait/simple-admin-core/rpc/internal/utils/errorhandler"
"github.com/huuhoait/simple-admin-core/rpc/types/core"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateOauthProviderLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCreateOauthProviderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOauthProviderLogic {
return &CreateOauthProviderLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *CreateOauthProviderLogic) CreateOauthProvider(in *core.OauthProviderInfo) (*core.BaseIDResp, error) {
result, err := l.svcCtx.DB.OauthProvider.Create().
SetNotNilName(in.Name).
SetNotNilClientID(in.ClientId).
SetNotNilClientSecret(in.ClientSecret).
SetNotNilRedirectURL(in.RedirectUrl).
SetNotNilScopes(in.Scopes).
SetNotNilAuthURL(in.AuthUrl).
SetNotNilTokenURL(in.TokenUrl).
SetNotNilAuthStyle(in.AuthStyle).
SetNotNilInfoURL(in.InfoUrl).
Save(l.ctx)
if err != nil {
return nil, errorhandler.DefaultEntError(l.Logger, err, in)
}
return &core.BaseIDResp{Id: result.ID, Msg: i18n.CreateSuccess}, nil
}