Refactor: Remove deprecated gRPC service files and implement new API structure

- Deleted old gRPC service definitions in `game_grpc.pb.go` and `public.go`.
- Added new API server implementations for objectstory, player, and shop services.
- Introduced configuration files for new APIs in `etc/*.yaml`.
- Created main entry points for each service in `objectstory.go`, `player.go`, and `shop.go`.
- Removed unused user update handler and user API files.
- Added utility functions for context management and HTTP header parsing.
- Introduced PostgreSQL backup configuration in `backup/postgreSql.yaml`.
This commit is contained in:
wwweww
2026-02-28 18:35:56 +08:00
parent d2f33b4b96
commit 19cc7a778c
349 changed files with 42548 additions and 1453 deletions
@@ -0,0 +1,57 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"juwan-backend/common/utils/contextj"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 发表评论
func NewCreateCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateCommentLogic {
return &CreateCommentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CreateCommentLogic) CreateComment(req *types.CreateCommentReq) (resp *types.Comment, err error) {
uid, err := contextj.UserIDFrom(l.ctx)
if err != nil {
return nil, err
}
_, err = l.svcCtx.CommunityRpc.AddComments(l.ctx, &communitypb.AddCommentsReq{
PostId: req.PostId,
AuthorId: uid,
Content: req.Content,
})
if err != nil {
return nil, err
}
comments, err := l.svcCtx.CommunityRpc.SearchComments(l.ctx, &communitypb.SearchCommentsReq{
Page: 0,
Limit: 1,
PostId: req.PostId,
AuthorId: uid,
})
if err != nil || len(comments.GetComments()) == 0 {
return nil, err
}
out := mapComment(l.ctx, l.svcCtx, comments.GetComments()[len(comments.GetComments())-1], false)
return &out, nil
}
@@ -0,0 +1,65 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"strconv"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"juwan-backend/common/utils/contextj"
"github.com/zeromicro/go-zero/core/logx"
)
type CreatePostLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 发布帖子
func NewCreatePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreatePostLogic {
return &CreatePostLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CreatePostLogic) CreatePost(req *types.CreatePostReq) (resp *types.Post, err error) {
uid, err := contextj.UserIDFrom(l.ctx)
if err != nil {
return nil, err
}
linkedOrderID := int64(0)
if req.LinkedOrderId != "" {
linkedOrderID, _ = strconv.ParseInt(req.LinkedOrderId, 10, 64)
}
_, err = l.svcCtx.CommunityRpc.AddPosts(l.ctx, &communitypb.AddPostsReq{
AuthorId: uid,
AuthorRole: "consumer",
Title: req.Title,
Content: req.Content,
Images: req.Images,
Tags: req.Tags,
LinkedOrderId: linkedOrderID,
})
if err != nil {
return nil, err
}
posts, err := l.svcCtx.CommunityRpc.SearchPosts(l.ctx, &communitypb.SearchPostsReq{
Page: 0,
Limit: 1,
AuthorId: &uid,
})
if err != nil || len(posts.GetPosts()) == 0 {
return nil, err
}
out := mapPost(l.ctx, l.svcCtx, posts.GetPosts()[0], false)
return &out, nil
}
@@ -0,0 +1,45 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type GetPostLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 获取帖子详情
func NewGetPostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPostLogic {
return &GetPostLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetPostLogic) GetPost(req *types.PathId) (resp *types.Post, err error) {
out, err := l.svcCtx.CommunityRpc.GetPostsById(l.ctx, &communitypb.GetPostsByIdReq{Id: req.Id})
if err != nil {
return nil, err
}
uid := currentUserIDOrZero(l.ctx)
liked := false
if uid > 0 {
likes, e := l.svcCtx.CommunityRpc.SearchPostLikes(l.ctx, &communitypb.SearchPostLikesReq{Page: 0, Limit: 1, PostId: &req.Id, UserId: &uid})
liked = e == nil && len(likes.GetPostLikes()) > 0
}
post := mapPost(l.ctx, l.svcCtx, out.GetPosts(), liked)
return &post, nil
}
@@ -0,0 +1,69 @@
package community
import (
"context"
"strconv"
"time"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"juwan-backend/app/users/rpc/usercenter"
"juwan-backend/common/utils/contextj"
)
func currentUserIDOrZero(ctx context.Context) int64 {
uid, err := contextj.UserIDFrom(ctx)
if err != nil {
return 0
}
return uid
}
func buildUserProfile(ctx context.Context, svcCtx *svc.ServiceContext, userID int64) types.UserProfile {
if userID <= 0 {
return types.UserProfile{}
}
resp, err := svcCtx.UserRpc.GetUsersById(ctx, &usercenter.GetUsersByIdReq{Id: userID})
if err != nil || resp == nil || resp.Users == nil {
id := strconv.FormatInt(userID, 10)
return types.UserProfile{Id: id, Username: id, Nickname: "用户" + id, CreatedAt: time.Now().UTC().Format(time.RFC3339)}
}
u := resp.Users
return types.UserProfile{
Id: strconv.FormatInt(u.GetId(), 10),
Username: u.GetUsername(),
Nickname: u.GetNickname(),
Avatar: u.GetAvatar(),
Role: u.GetCurrentRole(),
Phone: u.GetPhone(),
Bio: u.GetBio(),
CreatedAt: time.Unix(u.GetCreatedAt(), 0).UTC().Format(time.RFC3339),
}
}
func mapPost(ctx context.Context, svcCtx *svc.ServiceContext, p *communitypb.Posts, liked bool) types.Post {
return types.Post{
Id: p.GetId(),
Title: p.GetTitle(),
Content: p.GetContent(),
Images: append([]string(nil), p.GetImages()...),
Tags: append([]string(nil), p.GetTags()...),
LikeCount: p.GetLikeCount(),
CommentCount: p.GetCommentCount(),
Liked: liked,
Author: buildUserProfile(ctx, svcCtx, p.GetAuthorId()),
CreatedAt: time.Unix(p.GetCreatedAt(), 0).UTC().Format(time.RFC3339),
}
}
func mapComment(ctx context.Context, svcCtx *svc.ServiceContext, c *communitypb.Comments, liked bool) types.Comment {
return types.Comment{
Id: c.GetId(),
Content: c.GetContent(),
Author: buildUserProfile(ctx, svcCtx, c.GetAuthorId()),
LikeCount: c.GetLikeCount(),
Liked: liked,
CreatedAt: time.Unix(c.GetCreatedAt(), 0).UTC().Format(time.RFC3339),
}
}
@@ -0,0 +1,43 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"juwan-backend/common/utils/contextj"
"github.com/zeromicro/go-zero/core/logx"
)
type LikeCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 点赞评论
func NewLikeCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LikeCommentLogic {
return &LikeCommentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *LikeCommentLogic) LikeComment(req *types.PathId) (resp *types.EmptyResp, err error) {
uid, err := contextj.UserIDFrom(l.ctx)
if err != nil {
return nil, err
}
_, err = l.svcCtx.CommunityRpc.AddCommentLikes(l.ctx, &communitypb.AddCommentLikesReq{CommentId: req.Id, UserId: uid})
if err != nil {
return nil, err
}
return &types.EmptyResp{}, nil
}
@@ -0,0 +1,43 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"juwan-backend/common/utils/contextj"
"github.com/zeromicro/go-zero/core/logx"
)
type LikePostLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 点赞帖子
func NewLikePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LikePostLogic {
return &LikePostLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *LikePostLogic) LikePost(req *types.PathId) (resp *types.EmptyResp, err error) {
uid, err := contextj.UserIDFrom(l.ctx)
if err != nil {
return nil, err
}
_, err = l.svcCtx.CommunityRpc.AddPostLikes(l.ctx, &communitypb.AddPostLikesReq{PostId: req.Id, UserId: uid})
if err != nil {
return nil, err
}
return &types.EmptyResp{}, nil
}
@@ -0,0 +1,55 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type ListCommentsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 获取帖子评论
func NewListCommentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListCommentsLogic {
return &ListCommentsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListCommentsLogic) ListComments(req *types.ListCommentsReq) (resp *types.CommentListResp, err error) {
if req.Limit <= 0 {
req.Limit = 20
}
out, err := l.svcCtx.CommunityRpc.SearchComments(l.ctx, &communitypb.SearchCommentsReq{
Page: req.Offset,
Limit: req.Limit,
PostId: req.Id,
})
if err != nil {
return nil, err
}
uid := currentUserIDOrZero(l.ctx)
items := make([]types.Comment, 0, len(out.GetComments()))
for _, c := range out.GetComments() {
liked := false
if uid > 0 {
likes, e := l.svcCtx.CommunityRpc.SearchCommentLikes(l.ctx, &communitypb.SearchCommentLikesReq{Page: 0, Limit: 1, CommentId: c.Id, UserId: uid})
liked = e == nil && len(likes.GetCommentLikes()) > 0
}
items = append(items, mapComment(l.ctx, l.svcCtx, c, liked))
}
return &types.CommentListResp{Items: items, Meta: types.PageMeta{Total: int64(len(items)), Offset: req.Offset, Limit: req.Limit}}, nil
}
@@ -0,0 +1,56 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"strings"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type ListPostsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 获取帖子列表
func NewListPostsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListPostsLogic {
return &ListPostsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListPostsLogic) ListPosts(req *types.PostListReq) (resp *types.PostListResp, err error) {
if req.Limit <= 0 {
req.Limit = 20
}
in := &communitypb.SearchPostsReq{Page: req.Offset, Limit: req.Limit}
if req.Tags != "" {
in.Tags = strings.Split(req.Tags, ",")
}
posts, err := l.svcCtx.CommunityRpc.SearchPosts(l.ctx, in)
if err != nil {
return nil, err
}
uid := currentUserIDOrZero(l.ctx)
items := make([]types.Post, 0, len(posts.GetPosts()))
for _, p := range posts.GetPosts() {
liked := false
if uid > 0 {
likes, e := l.svcCtx.CommunityRpc.SearchPostLikes(l.ctx, &communitypb.SearchPostLikesReq{Page: 0, Limit: 1, PostId: &p.Id, UserId: &uid})
liked = e == nil && len(likes.GetPostLikes()) > 0
}
items = append(items, mapPost(l.ctx, l.svcCtx, p, liked))
}
return &types.PostListResp{Items: items, Meta: types.PageMeta{Total: int64(len(items)), Offset: req.Offset, Limit: req.Limit}}, nil
}
@@ -0,0 +1,52 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type ListUserPostsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 获取用户帖子
func NewListUserPostsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListUserPostsLogic {
return &ListUserPostsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListUserPostsLogic) ListUserPosts(req *types.ListCommentsReq) (resp *types.PostListResp, err error) {
if req.Limit <= 0 {
req.Limit = 20
}
authorID := req.Id
out, err := l.svcCtx.CommunityRpc.SearchPosts(l.ctx, &communitypb.SearchPostsReq{Page: req.Offset, Limit: req.Limit, AuthorId: &authorID})
if err != nil {
return nil, err
}
uid := currentUserIDOrZero(l.ctx)
items := make([]types.Post, 0, len(out.GetPosts()))
for _, p := range out.GetPosts() {
liked := false
if uid > 0 {
likes, e := l.svcCtx.CommunityRpc.SearchPostLikes(l.ctx, &communitypb.SearchPostLikesReq{Page: 0, Limit: 1, PostId: &p.Id, UserId: &uid})
liked = e == nil && len(likes.GetPostLikes()) > 0
}
items = append(items, mapPost(l.ctx, l.svcCtx, p, liked))
}
return &types.PostListResp{Items: items, Meta: types.PageMeta{Total: int64(len(items)), Offset: req.Offset, Limit: req.Limit}}, nil
}
@@ -0,0 +1,39 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type PinPostLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 置顶帖子
func NewPinPostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PinPostLogic {
return &PinPostLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *PinPostLogic) PinPost(req *types.PathId) (resp *types.EmptyResp, err error) {
t := true
_, err = l.svcCtx.CommunityRpc.UpdatePosts(l.ctx, &communitypb.UpdatePostsReq{Id: req.Id, Pinned: &t})
if err != nil {
return nil, err
}
return &types.EmptyResp{}, nil
}
@@ -0,0 +1,43 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"juwan-backend/common/utils/contextj"
"github.com/zeromicro/go-zero/core/logx"
)
type UnlikeCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 取消点赞评论
func NewUnlikeCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UnlikeCommentLogic {
return &UnlikeCommentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UnlikeCommentLogic) UnlikeComment(req *types.PathId) (resp *types.EmptyResp, err error) {
uid, err := contextj.UserIDFrom(l.ctx)
if err != nil {
return nil, err
}
_, err = l.svcCtx.CommunityRpc.DelCommentLikes(l.ctx, &communitypb.DelCommentLikesReq{Id: req.Id, UserId: &uid})
if err != nil {
return nil, err
}
return &types.EmptyResp{}, nil
}
@@ -0,0 +1,43 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"juwan-backend/common/utils/contextj"
"github.com/zeromicro/go-zero/core/logx"
)
type UnlikePostLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 取消点赞帖子
func NewUnlikePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UnlikePostLogic {
return &UnlikePostLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UnlikePostLogic) UnlikePost(req *types.PathId) (resp *types.EmptyResp, err error) {
uid, err := contextj.UserIDFrom(l.ctx)
if err != nil {
return nil, err
}
_, err = l.svcCtx.CommunityRpc.DelPostLikes(l.ctx, &communitypb.DelPostLikesReq{Id: req.Id, UserId: &uid})
if err != nil {
return nil, err
}
return &types.EmptyResp{}, nil
}
@@ -0,0 +1,39 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type UnpinPostLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 取消置顶
func NewUnpinPostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UnpinPostLogic {
return &UnpinPostLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UnpinPostLogic) UnpinPost(req *types.PathId) (resp *types.EmptyResp, err error) {
f := false
_, err = l.svcCtx.CommunityRpc.UpdatePosts(l.ctx, &communitypb.UpdatePostsReq{Id: req.Id, Pinned: &f})
if err != nil {
return nil, err
}
return &types.EmptyResp{}, nil
}