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:
@@ -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
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user