diff --git a/biz/handler/core/feed_server.go b/biz/handler/core/feed_server.go index 7721923..c43a721 100755 --- a/biz/handler/core/feed_server.go +++ b/biz/handler/core/feed_server.go @@ -26,13 +26,9 @@ func FeedMethod(ctx context.Context, c *app.RequestContext) { // TODO : 记录ip地址和注册api调用次数,限制统一设备短时间太多的请求,预防爬虫。 redis - msgsucceed := "获取视频流成功" - msgFailed := "获取视频流失败" - resp := new(core.FeedResp) // 字段处理 - // 目前该api无需token,后续增加登录定制化内容则需根据token获取其他参数 var currentUserId int64 if req.Token != nil { // 可选字段,需要验证是否存在,判断对应指针是否存在 _, currentUserId, err = tools.ValidateToken(*req.Token) // @@ -52,6 +48,7 @@ func FeedMethod(ctx context.Context, c *app.RequestContext) { // 缓存未命中,去后端调api resultList, nextTime, err := kitex_server.GetFeed(latestTime, currentUserId, 30) if err != nil { + msgFailed := "获取视频流失败" + err.Error() resp.StatusCode = 1 resp.StatusMsg = &msgFailed c.JSON(consts.StatusOK, resp) @@ -60,6 +57,7 @@ func FeedMethod(ctx context.Context, c *app.RequestContext) { resp.VideoList = resultList + msgsucceed := "获取视频流成功" resp.StatusMsg = &msgsucceed resp.NextTime = nextTime / 1e6 diff --git a/biz/handler/core/publish_action_server.go b/biz/handler/core/publish_action_server.go index 6acb056..bbb2b73 100755 --- a/biz/handler/core/publish_action_server.go +++ b/biz/handler/core/publish_action_server.go @@ -51,11 +51,9 @@ func PublishActionMethod(ctx context.Context, c *app.RequestContext) { return } - msgsucceed := "视频上传成功" - msgFailed := "视频上传失败" - fileHeader, err := c.Request.FormFile("data") if err != nil { + msgFailed := "视频上传失败" resp.StatusCode = 1 resp.StatusMsg = &msgFailed c.JSON(consts.StatusOK, resp) @@ -78,6 +76,7 @@ func PublishActionMethod(ctx context.Context, c *app.RequestContext) { err = tools.SaveFile(&file, filepath) if err != nil { + msgFailed := "服务器文件存储出错" resp.StatusCode = 1 resp.StatusMsg = &msgFailed c.JSON(consts.StatusOK, resp) @@ -87,6 +86,7 @@ func PublishActionMethod(ctx context.Context, c *app.RequestContext) { // TODO: 当前文件类型是写死的,后续需要优化 videourl, coverurl, err := minio_server.UploadMP4VideoToDouYin(filename, filepath, 1) if err != nil { + msgFailed := "视频上传minio服务失败" resp.StatusCode = 1 resp.StatusMsg = &msgFailed c.JSON(consts.StatusOK, resp) @@ -95,11 +95,13 @@ func PublishActionMethod(ctx context.Context, c *app.RequestContext) { err = kitex_server.CreateVideo(title, videourl, coverurl, authorId) if err != nil { + msgFailed := "视频信息创建失败" resp.StatusCode = 1 resp.StatusMsg = &msgFailed c.JSON(consts.StatusOK, resp) return } + msgsucceed := "视频上传成功" resp.StatusMsg = &msgsucceed c.JSON(consts.StatusOK, resp) } diff --git a/biz/handler/core/register_server.go b/biz/handler/core/register_server.go index 6deee27..d0607a4 100755 --- a/biz/handler/core/register_server.go +++ b/biz/handler/core/register_server.go @@ -4,6 +4,7 @@ package core import ( "context" + "log" core "github.com/ClubWeGo/douyin/biz/model/core" "github.com/ClubWeGo/douyin/kitex_server" @@ -40,22 +41,23 @@ func RegisterMethod(ctx context.Context, c *app.RequestContext) { return } - msgsucceed := "注册成功" - msgFailed := "注册失败" - // 题目要求的基础注册功能 // userid, err := kitex_server.RegisterUser(req.Username, *req.Password) // 附带个人设置的注册功能 + log.Println(111) var testBackgroundImage = "http://" + minio_server.GlobalConfig.Endpoint + "/douyin/" + "backgroud.jpg" var testAvatar = "http://" + minio_server.GlobalConfig.Endpoint + "/douyin/" + "0019534761_20.jpg" userid, err := kitex_server.RegisterUserALL(req.Username, *req.Password, nil, nil, &testBackgroundImage, &testAvatar) + log.Println(122) if err != nil { + msgFailed := "注册失败" resp.StatusCode = 1 resp.StatusMsg = &msgFailed c.JSON(consts.StatusOK, resp) return } + msgsucceed := "注册成功" resp.StatusMsg = &msgsucceed resp.Token = tools.GenerateToken(userid) resp.UserID = userid diff --git a/biz/handler/core/user_info_server.go b/biz/handler/core/user_info_server.go index c0cc31d..f4f4472 100755 --- a/biz/handler/core/user_info_server.go +++ b/biz/handler/core/user_info_server.go @@ -24,9 +24,6 @@ func UserInfoMethod(ctx context.Context, c *app.RequestContext) { return } - msgsucceed := "获取用户信息成功" - msgFailed := "获取用户信息失败" - resp := new(core.UserInfoResp) ifValid, currentUserId, err := tools.ValidateToken(req.Token) @@ -64,6 +61,7 @@ func UserInfoMethod(ctx context.Context, c *app.RequestContext) { errSlice := <-respLatestAuthorMapError for _, errItem := range errSlice { if errItem != nil { + msgFailed := "获取用户信息失败" + errItem.Error() resp.StatusCode = 1 resp.StatusMsg = &msgFailed c.JSON(consts.StatusOK, resp) @@ -71,6 +69,7 @@ func UserInfoMethod(ctx context.Context, c *app.RequestContext) { } } + msgsucceed := "获取用户信息成功" user := AuthorMap[req.UserID] resp.StatusMsg = &msgsucceed resp.User = &user diff --git a/kitex_server/userservice.go b/kitex_server/userservice.go index 22b8527..f43926d 100755 --- a/kitex_server/userservice.go +++ b/kitex_server/userservice.go @@ -142,6 +142,13 @@ func GetUserLatestMap(idSet []int64, currentUser int64, respUserMap chan map[int // 更新数据 for id, user := range AuthorMap { + favoriteCountMap := FavoriteCountMap[id] + var totalFavourited int64 + var favoriteCount int64 + if len(favoriteCountMap) == 2 { // 服务失效时,会越界 + totalFavourited = favoriteCountMap[0] + favoriteCount = favoriteCountMap[1] + } AuthorMap[id] = core.User{ ID: user.ID, Name: user.Name, @@ -151,9 +158,9 @@ func GetUserLatestMap(idSet []int64, currentUser int64, respUserMap chan map[int Avatar: user.Avatar, BackgroundImage: user.BackgroundImage, Signature: user.Signature, - TotalFavourited: strconv.FormatInt(FavoriteCountMap[id][1], 10), // TODO: 从获取的数据中拿 - WorkCount: VideoCountMap[id].Count, // 最新的count数据 - FavoriteCount: FavoriteCountMap[id][0], // TODO: 从获取的数据中拿 + TotalFavourited: strconv.FormatInt(totalFavourited, 10), // TODO: 从获取的数据中拿 + WorkCount: VideoCountMap[id].Count, // 最新的count数据 + FavoriteCount: favoriteCount, // TODO: 从获取的数据中拿 } } @@ -191,10 +198,12 @@ func RegisterUserALL(username, password string, email, signature, backgroundImag BackgroundImage: backgroundImage, Avatar: avatar, } + println(211) r, err := Userclient.CreateUserMethod(context.Background(), &usermicro.CreateUserReq{ Newuser_: &newUser, Password: password, // 此处传输明文,加密由user微服务进行 }) + println(222) if err != nil { return 0, err }