-
Notifications
You must be signed in to change notification settings - Fork 0
/
relation_service.go
112 lines (97 loc) · 2.7 KB
/
relation_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Code generated by hertz generator.
package tiktokapi
import (
"context"
"github.com/PICOF/simple-tiktok/cmd/api/biz/rpc/relation"
tiktokapi "github.com/PICOF/simple-tiktok/cmd/api/biz/model/tiktokapi"
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/protocol/consts"
)
// FollowAction .
// @router /douyin/relation/action/ [POST]
func FollowAction(ctx context.Context, c *app.RequestContext) {
var err error
var req tiktokapi.FollowRequest
err = c.BindAndValidate(&req)
if err != nil {
c.String(consts.StatusBadRequest, err.Error())
return
}
userId := c.GetInt64("user_id")
resp, err := relation.FollowAction(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)
}
}
// GetFollowList .
// @router /douyin/relation/follow/list/ [GET]
func GetFollowList(ctx context.Context, c *app.RequestContext) {
var err error
var req tiktokapi.RelationListRequest
err = c.BindAndValidate(&req)
if err != nil {
c.String(consts.StatusBadRequest, err.Error())
return
}
userId := c.GetInt64("user_id")
resp, err := relation.GetFollowList(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)
}
}
// GetFollowerList .
// @router /douyin/relation/follower/list/ [GET]
func GetFollowerList(ctx context.Context, c *app.RequestContext) {
var err error
var req tiktokapi.RelationListRequest
err = c.BindAndValidate(&req)
if err != nil {
c.String(consts.StatusBadRequest, err.Error())
return
}
userId := c.GetInt64("user_id")
resp, err := relation.GetFollowerList(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)
}
}
// GetFriendList .
// @router /douyin/relation/friend/list/ [GET]
func GetFriendList(ctx context.Context, c *app.RequestContext) {
var err error
var req tiktokapi.RelationListRequest
err = c.BindAndValidate(&req)
if err != nil {
c.String(consts.StatusBadRequest, err.Error())
return
}
userId := c.GetInt64("user_id")
resp, err := relation.GetFriendList(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)
}
}