Files
juwan-backend/app/community/rpc/internal/logic/addPostLikesLogic.go
T
wwweww 19cc7a778c 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`.
2026-02-28 18:35:56 +08:00

57 lines
1.3 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 AddPostLikesLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAddPostLikesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddPostLikesLogic {
return &AddPostLikesLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// -----------------------postLikes-----------------------
func (l *AddPostLikesLogic) AddPostLikes(in *pb.AddPostLikesReq) (*pb.AddPostLikesResp, error) {
// todo: add your logic here and delete this line
if in.GetPostId() <= 0 || in.GetUserId() <= 0 {
return nil, errors.New("postId and userId are 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")
}
key := postLikeKey(in.GetPostId(), in.GetUserId())
if _, exists := store.PostLikes[key]; exists {
return &pb.AddPostLikesResp{}, nil
}
store.PostLikes[key] = &pb.PostLikes{
PostId: in.GetPostId(),
UserId: in.GetUserId(),
CreatedAt: nowUnix(in.GetCreatedAt()),
}
post.LikeCount++
return &pb.AddPostLikesResp{}, nil
}