-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish_service.go
68 lines (61 loc) · 1.66 KB
/
publish_service.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
// Code generated by hertz generator.
package tiktokapi
import (
"context"
tiktokapi "github.com/PICOF/simple-tiktok/cmd/api/biz/model/tiktokapi"
"github.com/PICOF/simple-tiktok/cmd/api/biz/rpc/publish"
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/protocol/consts"
)
// PublishAction .
// @router /douyin/publish/action/ [POST]
func PublishAction(ctx context.Context, c *app.RequestContext) {
var err error
var req tiktokapi.PublishRequest
err = c.BindAndValidate(&req)
if err != nil {
c.String(consts.StatusBadRequest, err.Error())
return
}
data, exist := c.Get("data")
if !exist {
msg := "数据上传出错"
c.JSON(consts.StatusInternalServerError, tiktokapi.LoginResponse{
StatusCode: -1,
StatusMsg: &msg,
})
}
req.Data = data.([]byte)
resp, err := publish.Publish(ctx, &req, c.GetInt64("user_id"))
if err != nil && resp == nil {
msg := "请求远程服务时出错"
c.JSON(consts.StatusInternalServerError, tiktokapi.LoginResponse{
StatusCode: -1,
StatusMsg: &msg,
})
} else {
c.JSON(consts.StatusOK, resp)
}
}
// GetPublishList .
// @router /douyin/publish/list/ [GET]
func GetPublishList(ctx context.Context, c *app.RequestContext) {
var err error
var req tiktokapi.PublishListRequest
err = c.BindAndValidate(&req)
if err != nil {
c.String(consts.StatusBadRequest, err.Error())
return
}
userId := c.GetInt64("user_id")
resp, err := publish.GetPublishList(ctx, &req, userId)
if err != nil && resp == nil {
msg := "请求远程服务时出错"
c.JSON(consts.StatusInternalServerError, tiktokapi.LoginResponse{
StatusCode: -1,
StatusMsg: &msg,
})
} else {
c.JSON(consts.StatusOK, resp)
}
}