/
catalog.go
78 lines (72 loc) · 1.79 KB
/
catalog.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
70
71
72
73
74
75
76
77
78
package service
import (
"context"
v1 "github.com/jackycsl/catalog/api/bff/admin/v1"
"github.com/jackycsl/catalog/bff/admin/internal/biz"
)
func (s *ShopAdmin) ListGame(ctx context.Context, req *v1.ListGameReq) (*v1.ListGameReply, error) {
rv, err := s.cc.ListGame(ctx, req.PageNum, req.PageSize)
if err != nil {
return nil, err
}
reply := &v1.ListGameReply{
Results: make([]*v1.ListGameReply_Game, 0),
}
for _, x := range rv {
item := &v1.ListGameReply_Game{
Id: x.Id,
Name: x.Name,
Description: x.Description,
Count: x.Count,
}
reply.Results = append(reply.Results, item)
}
return reply, nil
}
func (s *ShopAdmin) GetGame(ctx context.Context, req *v1.GetGameReq) (*v1.GetGameReply, error) {
x, err := s.cc.GetGame(ctx, req.Id)
if err != nil {
return nil, err
}
reply := &v1.GetGameReply{
Id: x.Id,
Name: x.Name,
Description: x.Description,
Count: x.Count,
}
return reply, nil
}
func (s *ShopAdmin) CreateGame(ctx context.Context, req *v1.CreateGameReq) (*v1.CreateGameReply, error) {
x, err := s.cc.CreateGame(ctx, &biz.Game{
Name: req.Name,
Description: req.Description,
Count: req.Count,
})
if err != nil {
return nil, err
}
reply := &v1.CreateGameReply{
Name: x.Name,
Description: x.Description,
Count: x.Count,
}
return reply, nil
}
func (s *ShopAdmin) UpdateGame(ctx context.Context, req *v1.UpdateGameReq) (*v1.UpdateGameReply, error) {
x, err := s.cc.UpdateGame(ctx, &biz.Game{
Id: req.Id,
Name: req.Name,
Description: req.Description,
Count: req.Count,
})
if err != nil {
return nil, err
}
reply := &v1.UpdateGameReply{
Id: x.Id,
Name: x.Name,
Description: x.Description,
Count: x.Count,
}
return reply, nil
}