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`.
87 lines
1.8 KiB
Go
87 lines
1.8 KiB
Go
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 UpdatePostsLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewUpdatePostsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePostsLogic {
|
|
return &UpdatePostsLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *UpdatePostsLogic) UpdatePosts(in *pb.UpdatePostsReq) (*pb.UpdatePostsResp, error) {
|
|
if in.GetId() <= 0 {
|
|
return nil, errors.New("id is required")
|
|
}
|
|
|
|
store := l.svcCtx.Store
|
|
store.Mu.Lock()
|
|
defer store.Mu.Unlock()
|
|
|
|
post, ok := store.Posts[in.GetId()]
|
|
if !ok || post.GetDeletedAt() > 0 {
|
|
return nil, errors.New("post not found")
|
|
}
|
|
|
|
if in.AuthorId != nil {
|
|
post.AuthorId = in.GetAuthorId()
|
|
}
|
|
if in.AuthorRole != nil {
|
|
post.AuthorRole = in.GetAuthorRole()
|
|
}
|
|
if in.Title != nil {
|
|
post.Title = in.GetTitle()
|
|
}
|
|
if in.Content != nil {
|
|
post.Content = in.GetContent()
|
|
}
|
|
if len(in.Images) > 0 {
|
|
post.Images = append([]string(nil), in.GetImages()...)
|
|
}
|
|
if len(in.Tags) > 0 {
|
|
post.Tags = append([]string(nil), in.GetTags()...)
|
|
}
|
|
if in.LinkedOrderId != nil {
|
|
post.LinkedOrderId = in.GetLinkedOrderId()
|
|
}
|
|
if in.QuotedPostId != nil {
|
|
post.QuotedPostId = in.GetQuotedPostId()
|
|
}
|
|
if in.LikeCount != nil {
|
|
post.LikeCount = in.GetLikeCount()
|
|
}
|
|
if in.CommentCount != nil {
|
|
post.CommentCount = in.GetCommentCount()
|
|
}
|
|
if in.Pinned != nil {
|
|
post.Pinned = in.GetPinned()
|
|
}
|
|
if in.SearchText != nil {
|
|
post.SearchText = in.GetSearchText()
|
|
}
|
|
if in.DeletedAt != nil {
|
|
post.DeletedAt = in.GetDeletedAt()
|
|
}
|
|
if in.CreatedAt != nil {
|
|
post.CreatedAt = in.GetCreatedAt()
|
|
}
|
|
post.UpdatedAt = nowUnix(in.GetUpdatedAt())
|
|
|
|
return &pb.UpdatePostsResp{}, nil
|
|
}
|