huangguangrong 9 сар өмнө
parent
commit
3262d78627

+ 12 - 12
api/slow_wild.api

@@ -322,9 +322,9 @@ type (
 		Total int64         `json:"total"`
 		Total int64         `json:"total"`
 	}
 	}
 	GetReplyListReq {
 	GetReplyListReq {
-		Page      int32 `from:"page,default=1"`
-		PageSize  int32 `from:"page_size,default=10"`
-		CommentId int64 `from:"comment_id"`
+		Page      int32 `form:"page,default=1"`
+		PageSize  int32 `form:"page_size,default=10"`
+		CommentId int64 `form:"comment_id"`
 	}
 	}
 	GetReplyListRsp {
 	GetReplyListRsp {
 		List  []RepliesItem `json:"list"`
 		List  []RepliesItem `json:"list"`
@@ -351,27 +351,27 @@ type (
 		Success bool `json:"success"`
 		Success bool `json:"success"`
 	}
 	}
 	GetUserPostListReq {
 	GetUserPostListReq {
-		Page        int64 `from:"page,default=1"`
-		PageSize    int64 `from:"page_size,default=10"`
-		QueryUserId int64 `from:"query_user_id"`
+		Page        int64 `form:"page,default=1"`
+		PageSize    int64 `form:"page_size,default=10"`
+		QueryUserId int64 `form:"query_user_id"`
 	}
 	}
 	GetUserPostListRsp {
 	GetUserPostListRsp {
 		List  []GetPostListItem `json:"list"`
 		List  []GetPostListItem `json:"list"`
 		Total int64             `json:"total"`
 		Total int64             `json:"total"`
 	}
 	}
 	GetUserPostCollectionListReq {
 	GetUserPostCollectionListReq {
-		Page        int64 `from:"page,default=1"`
-		PageSize    int64 `from:"page_size,default=10"`
-		QueryUserId int64 `from:"query_user_id"`
+		Page        int64 `form:"page,default=1"`
+		PageSize    int64 `form:"page_size,default=10"`
+		QueryUserId int64 `form:"query_user_id"`
 	}
 	}
 	GetUserPostCollectionListRsp {
 	GetUserPostCollectionListRsp {
 		List  []GetPostListItem `json:"list"`
 		List  []GetPostListItem `json:"list"`
 		Total int64             `json:"total"`
 		Total int64             `json:"total"`
 	}
 	}
 	GetUserPostLikeListReq {
 	GetUserPostLikeListReq {
-		Page        int64 `from:"page,default=1"`
-		PageSize    int64 `from:"page_size,default=10"`
-		QueryUserId int64 `from:"query_user_id"`
+		Page        int64 `form:"page,default=1"`
+		PageSize    int64 `form:"page_size,default=10"`
+		QueryUserId int64 `form:"query_user_id"`
 	}
 	}
 	GetUserPostLikeListRsp {
 	GetUserPostLikeListRsp {
 		List  []GetPostListItem `json:"list"`
 		List  []GetPostListItem `json:"list"`

+ 29 - 0
apps/internal/handler/routes.go

@@ -13,11 +13,13 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	server.AddRoutes(
 	server.AddRoutes(
 		[]rest.Route{
 		[]rest.Route{
 			{
 			{
+				// 登录方法
 				Method:  http.MethodPost,
 				Method:  http.MethodPost,
 				Path:    "/user/login",
 				Path:    "/user/login",
 				Handler: loginHandler(serverCtx),
 				Handler: loginHandler(serverCtx),
 			},
 			},
 			{
 			{
+				// 用户注册
 				Method:  http.MethodPost,
 				Method:  http.MethodPost,
 				Path:    "/user/register",
 				Path:    "/user/register",
 				Handler: registerHandler(serverCtx),
 				Handler: registerHandler(serverCtx),
@@ -29,41 +31,49 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	server.AddRoutes(
 	server.AddRoutes(
 		[]rest.Route{
 		[]rest.Route{
 			{
 			{
+				// 获取粉丝
 				Method:  http.MethodGet,
 				Method:  http.MethodGet,
 				Path:    "/user/fans",
 				Path:    "/user/fans",
 				Handler: getFansHandler(serverCtx),
 				Handler: getFansHandler(serverCtx),
 			},
 			},
 			{
 			{
+				// 查询用户
 				Method:  http.MethodPost,
 				Method:  http.MethodPost,
 				Path:    "/user/find",
 				Path:    "/user/find",
 				Handler: findUserHandler(serverCtx),
 				Handler: findUserHandler(serverCtx),
 			},
 			},
 			{
 			{
+				// 关注用户
 				Method:  http.MethodPost,
 				Method:  http.MethodPost,
 				Path:    "/user/follow",
 				Path:    "/user/follow",
 				Handler: followUserHandler(serverCtx),
 				Handler: followUserHandler(serverCtx),
 			},
 			},
 			{
 			{
+				// 获取关注列表
 				Method:  http.MethodGet,
 				Method:  http.MethodGet,
 				Path:    "/user/follows",
 				Path:    "/user/follows",
 				Handler: getFollowsHandler(serverCtx),
 				Handler: getFollowsHandler(serverCtx),
 			},
 			},
 			{
 			{
+				// 获取用户信息
 				Method:  http.MethodGet,
 				Method:  http.MethodGet,
 				Path:    "/user/info",
 				Path:    "/user/info",
 				Handler: getUserInfoHandler(serverCtx),
 				Handler: getUserInfoHandler(serverCtx),
 			},
 			},
 			{
 			{
+				// 获取用户信息
 				Method:  http.MethodGet,
 				Method:  http.MethodGet,
 				Path:    "/user/profile",
 				Path:    "/user/profile",
 				Handler: getUserProfileHandler(serverCtx),
 				Handler: getUserProfileHandler(serverCtx),
 			},
 			},
 			{
 			{
+				// 搜索用户
 				Method:  http.MethodGet,
 				Method:  http.MethodGet,
 				Path:    "/user/search",
 				Path:    "/user/search",
 				Handler: searchUsernameHandler(serverCtx),
 				Handler: searchUsernameHandler(serverCtx),
 			},
 			},
 			{
 			{
+				// 取消关注用户
 				Method:  http.MethodPost,
 				Method:  http.MethodPost,
 				Path:    "/user/unfollow",
 				Path:    "/user/unfollow",
 				Handler: unfollowUserHandler(serverCtx),
 				Handler: unfollowUserHandler(serverCtx),
@@ -76,46 +86,55 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	server.AddRoutes(
 	server.AddRoutes(
 		[]rest.Route{
 		[]rest.Route{
 			{
 			{
+				// 评论删除
 				Method:  http.MethodPost,
 				Method:  http.MethodPost,
 				Path:    "/comment/delete",
 				Path:    "/comment/delete",
 				Handler: commentDeleteHandler(serverCtx),
 				Handler: commentDeleteHandler(serverCtx),
 			},
 			},
 			{
 			{
+				// 帖子收藏
 				Method:  http.MethodPost,
 				Method:  http.MethodPost,
 				Path:    "/post/collection",
 				Path:    "/post/collection",
 				Handler: postCollectionHandler(serverCtx),
 				Handler: postCollectionHandler(serverCtx),
 			},
 			},
 			{
 			{
+				// 发布评论
 				Method:  http.MethodPost,
 				Method:  http.MethodPost,
 				Path:    "/post/comment",
 				Path:    "/post/comment",
 				Handler: postCommentHandler(serverCtx),
 				Handler: postCommentHandler(serverCtx),
 			},
 			},
 			{
 			{
+				// 评论点赞
 				Method:  http.MethodPost,
 				Method:  http.MethodPost,
 				Path:    "/post/comment/upvote",
 				Path:    "/post/comment/upvote",
 				Handler: postCommentUpvoteHandler(serverCtx),
 				Handler: postCommentUpvoteHandler(serverCtx),
 			},
 			},
 			{
 			{
+				// 创建帖子
 				Method:  http.MethodPost,
 				Method:  http.MethodPost,
 				Path:    "/post/create",
 				Path:    "/post/create",
 				Handler: createPostHandler(serverCtx),
 				Handler: createPostHandler(serverCtx),
 			},
 			},
 			{
 			{
+				// 帖子删除
 				Method:  http.MethodPost,
 				Method:  http.MethodPost,
 				Path:    "/post/delete",
 				Path:    "/post/delete",
 				Handler: postDeleteHandler(serverCtx),
 				Handler: postDeleteHandler(serverCtx),
 			},
 			},
 			{
 			{
+				// 回复评论
 				Method:  http.MethodPost,
 				Method:  http.MethodPost,
 				Path:    "/post/reply",
 				Path:    "/post/reply",
 				Handler: postReplyHandler(serverCtx),
 				Handler: postReplyHandler(serverCtx),
 			},
 			},
 			{
 			{
+				// 帖子分享
 				Method:  http.MethodPost,
 				Method:  http.MethodPost,
 				Path:    "/post/share",
 				Path:    "/post/share",
 				Handler: postShareHandler(serverCtx),
 				Handler: postShareHandler(serverCtx),
 			},
 			},
 			{
 			{
+				// 帖子点赞
 				Method:  http.MethodPost,
 				Method:  http.MethodPost,
 				Path:    "/post/upvote",
 				Path:    "/post/upvote",
 				Handler: postUpvoteHandler(serverCtx),
 				Handler: postUpvoteHandler(serverCtx),
@@ -130,46 +149,55 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 			[]rest.Middleware{serverCtx.OptionalJwtMiddleware},
 			[]rest.Middleware{serverCtx.OptionalJwtMiddleware},
 			[]rest.Route{
 			[]rest.Route{
 				{
 				{
+					// 获取帖子详情
 					Method:  http.MethodGet,
 					Method:  http.MethodGet,
 					Path:    "/post",
 					Path:    "/post",
 					Handler: getPostHandler(serverCtx),
 					Handler: getPostHandler(serverCtx),
 				},
 				},
 				{
 				{
+					// 获取评论列表
 					Method:  http.MethodGet,
 					Method:  http.MethodGet,
 					Path:    "/post/comment/list",
 					Path:    "/post/comment/list",
 					Handler: getPostCommentListHandler(serverCtx),
 					Handler: getPostCommentListHandler(serverCtx),
 				},
 				},
 				{
 				{
+					// 获取帖子列表
 					Method:  http.MethodGet,
 					Method:  http.MethodGet,
 					Path:    "/post/list",
 					Path:    "/post/list",
 					Handler: getPostListHandler(serverCtx),
 					Handler: getPostListHandler(serverCtx),
 				},
 				},
 				{
 				{
+					// 获取回复列表
 					Method:  http.MethodGet,
 					Method:  http.MethodGet,
 					Path:    "/post/reply/list",
 					Path:    "/post/reply/list",
 					Handler: getReplyListHandler(serverCtx),
 					Handler: getReplyListHandler(serverCtx),
 				},
 				},
 				{
 				{
+					// 获取话题详情
 					Method:  http.MethodGet,
 					Method:  http.MethodGet,
 					Path:    "/tag",
 					Path:    "/tag",
 					Handler: getTagHandler(serverCtx),
 					Handler: getTagHandler(serverCtx),
 				},
 				},
 				{
 				{
+					// 获取话题列表
 					Method:  http.MethodGet,
 					Method:  http.MethodGet,
 					Path:    "/tag/list",
 					Path:    "/tag/list",
 					Handler: getTagListHandler(serverCtx),
 					Handler: getTagListHandler(serverCtx),
 				},
 				},
 				{
 				{
+					// 获取用户收藏的帖子列表
 					Method:  http.MethodGet,
 					Method:  http.MethodGet,
 					Path:    "/user/post/collection/list",
 					Path:    "/user/post/collection/list",
 					Handler: getUserPostCollectionListHandler(serverCtx),
 					Handler: getUserPostCollectionListHandler(serverCtx),
 				},
 				},
 				{
 				{
+					// 获取用户点赞的帖子列表
 					Method:  http.MethodGet,
 					Method:  http.MethodGet,
 					Path:    "/user/post/like/list",
 					Path:    "/user/post/like/list",
 					Handler: getUserPostLikeListHandler(serverCtx),
 					Handler: getUserPostLikeListHandler(serverCtx),
 				},
 				},
 				{
 				{
+					// 获取用户发布的帖子列表
 					Method:  http.MethodGet,
 					Method:  http.MethodGet,
 					Path:    "/user/post/list",
 					Path:    "/user/post/list",
 					Handler: getUserPostListHandler(serverCtx),
 					Handler: getUserPostListHandler(serverCtx),
@@ -182,6 +210,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	server.AddRoutes(
 	server.AddRoutes(
 		[]rest.Route{
 		[]rest.Route{
 			{
 			{
+				// 上传文件
 				Method:  http.MethodPost,
 				Method:  http.MethodPost,
 				Path:    "/attachment/upload",
 				Path:    "/attachment/upload",
 				Handler: attachmentUploadHandler(serverCtx),
 				Handler: attachmentUploadHandler(serverCtx),

+ 4 - 1
apps/internal/logic/getuserpostcollectionlistlogic.go

@@ -35,6 +35,9 @@ func (l *GetUserPostCollectionListLogic) GetUserPostCollectionList(req *types.Ge
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
-	resp.Data = rpcResp
+	resp.Data = map[string]interface{}{
+		"list":  rpcResp.GetList(),
+		"total": rpcResp.GetTotal(),
+	}
 	return
 	return
 }
 }

+ 4 - 1
apps/internal/logic/getuserpostlikelistlogic.go

@@ -35,6 +35,9 @@ func (l *GetUserPostLikeListLogic) GetUserPostLikeList(req *types.GetUserPostLik
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
-	resp.Data = rpcResp
+	resp.Data = map[string]interface{}{
+		"list":  rpcResp.GetList(),
+		"total": rpcResp.GetTotal(),
+	}
 	return
 	return
 }
 }

+ 4 - 1
apps/internal/logic/getuserpostlistlogic.go

@@ -35,6 +35,9 @@ func (l *GetUserPostListLogic) GetUserPostList(req *types.GetUserPostListReq) (r
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
-	resp.Data = rpcResp
+	resp.Data = map[string]interface{}{
+		"list":  rpcResp.GetList(),
+		"total": rpcResp.GetTotal(),
+	}
 	return
 	return
 }
 }

+ 5 - 1
apps/internal/logic/getuserprofilelogic.go

@@ -2,11 +2,14 @@ package logic
 
 
 import (
 import (
 	"context"
 	"context"
+	"encoding/json"
 
 
+	"slow_wild_api/apps/internal/constants"
 	"slow_wild_api/apps/internal/svc"
 	"slow_wild_api/apps/internal/svc"
 	"slow_wild_api/apps/internal/types"
 	"slow_wild_api/apps/internal/types"
 
 
 	"git.banshen.xyz/huangguangrong/slow_wild_protobuff/slowwild/slowwildserver"
 	"git.banshen.xyz/huangguangrong/slow_wild_protobuff/slowwild/slowwildserver"
+	"github.com/spf13/cast"
 	"github.com/zeromicro/go-zero/core/logx"
 	"github.com/zeromicro/go-zero/core/logx"
 )
 )
 
 
@@ -27,8 +30,9 @@ func NewGetUserProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
 
 
 func (l *GetUserProfileLogic) GetUserProfile(req *types.GetUserProfileReq) (resp *types.BaseReturnData, err error) {
 func (l *GetUserProfileLogic) GetUserProfile(req *types.GetUserProfileReq) (resp *types.BaseReturnData, err error) {
 	resp = &types.BaseReturnData{}
 	resp = &types.BaseReturnData{}
+	userId := l.ctx.Value(constants.UserIdKey).(json.Number)
 	rpcResp, err := l.svcCtx.SlowWildPb.GetUserProfile(l.ctx, &slowwildserver.GetUserProfileReq{
 	rpcResp, err := l.svcCtx.SlowWildPb.GetUserProfile(l.ctx, &slowwildserver.GetUserProfileReq{
-		UserId: req.UserId,
+		UserId: cast.ToInt64(userId),
 	})
 	})
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err

+ 12 - 12
apps/internal/types/types.go

@@ -174,9 +174,9 @@ type GetPostRsp struct {
 }
 }
 
 
 type GetReplyListReq struct {
 type GetReplyListReq struct {
-	Page      int32 `from:"page,default=1"`
-	PageSize  int32 `from:"page_size,default=10"`
-	CommentId int64 `from:"comment_id"`
+	Page      int32 `form:"page,default=1"`
+	PageSize  int32 `form:"page_size,default=10"`
+	CommentId int64 `form:"comment_id"`
 }
 }
 
 
 type GetReplyListRsp struct {
 type GetReplyListRsp struct {
@@ -224,9 +224,9 @@ type GetUserInfoResp struct {
 }
 }
 
 
 type GetUserPostCollectionListReq struct {
 type GetUserPostCollectionListReq struct {
-	Page        int64 `from:"page,default=1"`
-	PageSize    int64 `from:"page_size,default=10"`
-	QueryUserId int64 `from:"query_user_id"`
+	Page        int64 `form:"page,default=1"`
+	PageSize    int64 `form:"page_size,default=10"`
+	QueryUserId int64 `form:"query_user_id"`
 }
 }
 
 
 type GetUserPostCollectionListRsp struct {
 type GetUserPostCollectionListRsp struct {
@@ -235,9 +235,9 @@ type GetUserPostCollectionListRsp struct {
 }
 }
 
 
 type GetUserPostLikeListReq struct {
 type GetUserPostLikeListReq struct {
-	Page        int64 `from:"page,default=1"`
-	PageSize    int64 `from:"page_size,default=10"`
-	QueryUserId int64 `from:"query_user_id"`
+	Page        int64 `form:"page,default=1"`
+	PageSize    int64 `form:"page_size,default=10"`
+	QueryUserId int64 `form:"query_user_id"`
 }
 }
 
 
 type GetUserPostLikeListRsp struct {
 type GetUserPostLikeListRsp struct {
@@ -246,9 +246,9 @@ type GetUserPostLikeListRsp struct {
 }
 }
 
 
 type GetUserPostListReq struct {
 type GetUserPostListReq struct {
-	Page        int64 `from:"page,default=1"`
-	PageSize    int64 `from:"page_size,default=10"`
-	QueryUserId int64 `from:"query_user_id"`
+	Page        int64 `form:"page,default=1"`
+	PageSize    int64 `form:"page_size,default=10"`
+	QueryUserId int64 `form:"query_user_id"`
 }
 }
 
 
 type GetUserPostListRsp struct {
 type GetUserPostListRsp struct {

+ 1 - 0
go.mod

@@ -57,6 +57,7 @@ require (
 	github.com/prometheus/procfs v0.15.1 // indirect
 	github.com/prometheus/procfs v0.15.1 // indirect
 	github.com/redis/go-redis/v9 v9.7.1 // indirect
 	github.com/redis/go-redis/v9 v9.7.1 // indirect
 	github.com/spaolacci/murmur3 v1.1.0 // indirect
 	github.com/spaolacci/murmur3 v1.1.0 // indirect
+	github.com/spf13/cast v1.7.1
 	github.com/tencentyun/cos-go-sdk-v5 v0.7.62
 	github.com/tencentyun/cos-go-sdk-v5 v0.7.62
 	go.etcd.io/etcd/api/v3 v3.5.15 // indirect
 	go.etcd.io/etcd/api/v3 v3.5.15 // indirect
 	go.etcd.io/etcd/client/pkg/v3 v3.5.15 // indirect
 	go.etcd.io/etcd/client/pkg/v3 v3.5.15 // indirect

+ 2 - 0
go.sum

@@ -140,6 +140,8 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR
 github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
 github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
 github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
 github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
 github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
 github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
+github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
+github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
 github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
 github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
 github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
 github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=