19cc7a778c
- 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`.
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
// 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
|
|
|
|
}
|