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`.
63 lines
1.4 KiB
Go
63 lines
1.4 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 AddCommentsLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewAddCommentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddCommentsLogic {
|
|
return &AddCommentsLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
// -----------------------comments-----------------------
|
|
func (l *AddCommentsLogic) AddComments(in *pb.AddCommentsReq) (*pb.AddCommentsResp, error) {
|
|
if in.GetPostId() <= 0 {
|
|
return nil, errors.New("postId is required")
|
|
}
|
|
if in.GetAuthorId() <= 0 {
|
|
return nil, errors.New("authorId is required")
|
|
}
|
|
if in.GetContent() == "" {
|
|
return nil, errors.New("content is required")
|
|
}
|
|
|
|
store := l.svcCtx.Store
|
|
store.Mu.Lock()
|
|
defer store.Mu.Unlock()
|
|
|
|
post, ok := store.Posts[in.GetPostId()]
|
|
if !ok || post.GetDeletedAt() > 0 {
|
|
return nil, errors.New("post not found")
|
|
}
|
|
|
|
now := nowUnix(in.GetCreatedAt())
|
|
comment := &pb.Comments{
|
|
Id: store.NextComment(),
|
|
PostId: in.GetPostId(),
|
|
AuthorId: in.GetAuthorId(),
|
|
Content: in.GetContent(),
|
|
LikeCount: 0,
|
|
CreatedAt: now,
|
|
}
|
|
store.Comments[comment.Id] = comment
|
|
post.CommentCount++
|
|
post.UpdatedAt = now
|
|
|
|
return &pb.AddCommentsResp{}, nil
|
|
}
|