-
Notifications
You must be signed in to change notification settings - Fork 0
/
favorite_pack.go
52 lines (47 loc) · 1.51 KB
/
favorite_pack.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
package pack
import (
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/protocol/consts"
"github.com/cloudwego/kitex/pkg/klog"
"github.com/xiaohei366/TinyTiktok/kitex_gen/FavoriteServer"
"github.com/xiaohei366/TinyTiktok/pkg/errno"
"reflect"
)
// 点赞列表的报文格式
type FavoriteListResponse struct {
StatusCode int32 `json:"status_code"`
StatusMsg string `json:"status_msg"`
VideoList []*FavoriteServer.Video `json:"video_list"`
}
// 点赞/取消赞的报文格式
type FavoriteActionResponse struct {
StatusCode int32 `json:"status_code"`
StatusMsg string `json:"status_msg"`
}
// 点赞/取消点赞操作的响应报文
func SendFavoriteActionResponse(c *app.RequestContext, resp interface{}) {
switch value := resp.(type) {
case error:
Err := errno.ConvertErr(value)
c.JSON(consts.StatusOK, FavoriteActionResponse{
StatusCode: Err.ErrCode,
StatusMsg: Err.ErrMsg,
})
case *FavoriteServer.DouyinFavoriteActionResponse:
c.JSON(consts.StatusOK, FavoriteActionResponse{
StatusCode: value.BaseResp.StatusCode,
StatusMsg: value.BaseResp.StatusMsg,
})
default:
klog.Error("响应报文传入未知类型%v", reflect.TypeOf(resp))
}
}
// 发送点赞列表的响应报文
func SendFavoriteListResponse(c *app.RequestContext, err error, videoList []*FavoriteServer.Video) {
Err := errno.ConvertErr(err)
c.JSON(consts.StatusOK, FavoriteListResponse{
StatusCode: Err.ErrCode,
StatusMsg: Err.ErrMsg,
VideoList: videoList,
})
}