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,67 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/community/rpc/internal/svc"
|
||||
"juwan-backend/app/community/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddPostsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAddPostsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddPostsLogic {
|
||||
return &AddPostsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------posts-----------------------
|
||||
func (l *AddPostsLogic) AddPosts(in *pb.AddPostsReq) (*pb.AddPostsResp, error) {
|
||||
if in.GetAuthorId() <= 0 {
|
||||
return nil, errors.New("authorId is required")
|
||||
}
|
||||
if in.GetTitle() == "" {
|
||||
return nil, errors.New("title is required")
|
||||
}
|
||||
if in.GetContent() == "" {
|
||||
return nil, errors.New("content is required")
|
||||
}
|
||||
|
||||
store := l.svcCtx.Store
|
||||
store.Mu.Lock()
|
||||
defer store.Mu.Unlock()
|
||||
|
||||
now := nowUnix(in.GetCreatedAt())
|
||||
post := &pb.Posts{
|
||||
Id: store.NextPost(),
|
||||
AuthorId: in.GetAuthorId(),
|
||||
AuthorRole: in.GetAuthorRole(),
|
||||
Title: in.GetTitle(),
|
||||
Content: in.GetContent(),
|
||||
Images: append([]string(nil), in.GetImages()...),
|
||||
Tags: append([]string(nil), in.GetTags()...),
|
||||
LinkedOrderId: in.GetLinkedOrderId(),
|
||||
QuotedPostId: in.GetQuotedPostId(),
|
||||
LikeCount: 0,
|
||||
CommentCount: 0,
|
||||
Pinned: in.GetPinned(),
|
||||
SearchText: in.GetTitle() + " " + in.GetContent(),
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
if post.AuthorRole == "" {
|
||||
post.AuthorRole = "consumer"
|
||||
}
|
||||
store.Posts[post.Id] = post
|
||||
|
||||
return &pb.AddPostsResp{}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user