forked from suyuan32/simple-admin-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_api_by_id_logic.go
50 lines (42 loc) · 1.26 KB
/
get_api_by_id_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
package api
import (
"context"
"github.com/huuhoait/simple-admin-common/i18n"
"github.com/huuhoait/simple-admin-core/api/internal/svc"
"github.com/huuhoait/simple-admin-core/api/internal/types"
"github.com/huuhoait/simple-admin-core/rpc/types/core"
"github.com/zeromicro/go-zero/core/logx"
)
type GetApiByIdLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetApiByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetApiByIdLogic {
return &GetApiByIdLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetApiByIdLogic) GetApiById(req *types.IDReq) (resp *types.ApiInfoResp, err error) {
data, err := l.svcCtx.CoreRpc.GetApiById(l.ctx, &core.IDReq{Id: req.Id})
if err != nil {
return nil, err
}
return &types.ApiInfoResp{
BaseDataInfo: types.BaseDataInfo{
Code: 0,
Msg: l.svcCtx.Trans.Trans(l.ctx, i18n.Success),
},
Data: types.ApiInfo{
BaseIDInfo: types.BaseIDInfo{Id: data.Id, CreatedAt: data.CreatedAt, UpdatedAt: data.UpdatedAt},
Trans: l.svcCtx.Trans.Trans(l.ctx, *data.Description),
Path: data.Path,
Description: data.Description,
Group: data.ApiGroup,
Method: data.Method,
IsRequired: data.IsRequired,
},
}, nil
}