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:
wwweww
2026-02-28 18:35:56 +08:00
parent d2f33b4b96
commit 19cc7a778c
349 changed files with 42548 additions and 1453 deletions
+34
View File
@@ -0,0 +1,34 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package main
import (
"flag"
"fmt"
"juwan-backend/app/community/api/internal/config"
"juwan-backend/app/community/api/internal/handler"
"juwan-backend/app/community/api/internal/svc"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
)
var configFile = flag.String("f", "etc/community-api.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
server := rest.MustNewServer(c.RestConf)
defer server.Stop()
ctx := svc.NewServiceContext(c)
handler.RegisterHandlers(server, ctx)
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
server.Start()
}
+16
View File
@@ -0,0 +1,16 @@
Name: community-api
Host: 0.0.0.0
Port: 8888
Prometheus:
Host: 0.0.0.0
Port: 4001
Path: /metrics
# k8s://juwan/<service name>:8080
CommunityRpcConf:
Target: k8s://juwan/community-rpc-svc.juwan:8080
UsercenterRpcConf:
Target: k8s://juwan/users-rpc-svc.juwan:8080
@@ -0,0 +1,15 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package config
import (
"github.com/zeromicro/go-zero/rest"
"github.com/zeromicro/go-zero/zrpc"
)
type Config struct {
rest.RestConf
CommunityRpcConf zrpc.RpcClientConf
UsercenterRpcConf zrpc.RpcClientConf
}
@@ -0,0 +1,37 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"net/http"
"juwan-backend/app/community/api/internal/logic/community"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)
// 发表评论
func CreateCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
types.PathId
types.CreateCommentReq
}
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
req.CreateCommentReq.PostId = req.PathId.Id
l := community.NewCreateCommentLogic(r.Context(), svcCtx)
resp, err := l.CreateComment(&req.CreateCommentReq)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
@@ -0,0 +1,32 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/community/api/internal/logic/community"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
)
// 发布帖子
func CreatePostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CreatePostReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := community.NewCreatePostLogic(r.Context(), svcCtx)
resp, err := l.CreatePost(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
@@ -0,0 +1,32 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/community/api/internal/logic/community"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
)
// 获取帖子详情
func GetPostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PathId
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := community.NewGetPostLogic(r.Context(), svcCtx)
resp, err := l.GetPost(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
@@ -0,0 +1,32 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/community/api/internal/logic/community"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
)
// 点赞评论
func LikeCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PathId
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := community.NewLikeCommentLogic(r.Context(), svcCtx)
resp, err := l.LikeComment(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
@@ -0,0 +1,32 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/community/api/internal/logic/community"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
)
// 点赞帖子
func LikePostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PathId
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := community.NewLikePostLogic(r.Context(), svcCtx)
resp, err := l.LikePost(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
@@ -0,0 +1,32 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/community/api/internal/logic/community"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
)
// 获取帖子评论
func ListCommentsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ListCommentsReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := community.NewListCommentsLogic(r.Context(), svcCtx)
resp, err := l.ListComments(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
@@ -0,0 +1,32 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/community/api/internal/logic/community"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
)
// 获取帖子列表
func ListPostsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PostListReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := community.NewListPostsLogic(r.Context(), svcCtx)
resp, err := l.ListPosts(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
@@ -0,0 +1,32 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/community/api/internal/logic/community"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
)
// 获取用户帖子
func ListUserPostsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ListCommentsReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := community.NewListUserPostsLogic(r.Context(), svcCtx)
resp, err := l.ListUserPosts(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
@@ -0,0 +1,32 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/community/api/internal/logic/community"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
)
// 置顶帖子
func PinPostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PathId
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := community.NewPinPostLogic(r.Context(), svcCtx)
resp, err := l.PinPost(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
@@ -0,0 +1,32 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/community/api/internal/logic/community"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
)
// 取消点赞评论
func UnlikeCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PathId
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := community.NewUnlikeCommentLogic(r.Context(), svcCtx)
resp, err := l.UnlikeComment(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
@@ -0,0 +1,32 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/community/api/internal/logic/community"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
)
// 取消点赞帖子
func UnlikePostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PathId
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := community.NewUnlikePostLogic(r.Context(), svcCtx)
resp, err := l.UnlikePost(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
@@ -0,0 +1,32 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/community/api/internal/logic/community"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
)
// 取消置顶
func UnpinPostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PathId
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := community.NewUnpinPostLogic(r.Context(), svcCtx)
resp, err := l.UnpinPost(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
@@ -0,0 +1,99 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.9.2
package handler
import (
"net/http"
community "juwan-backend/app/community/api/internal/handler/community"
"juwan-backend/app/community/api/internal/svc"
"github.com/zeromicro/go-zero/rest"
)
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
// 获取帖子列表
Method: http.MethodGet,
Path: "/posts",
Handler: community.ListPostsHandler(serverCtx),
},
{
// 获取帖子详情
Method: http.MethodGet,
Path: "/posts/:id",
Handler: community.GetPostHandler(serverCtx),
},
{
// 获取帖子评论
Method: http.MethodGet,
Path: "/posts/:id/comments",
Handler: community.ListCommentsHandler(serverCtx),
},
{
// 获取用户帖子
Method: http.MethodGet,
Path: "/users/:id/posts",
Handler: community.ListUserPostsHandler(serverCtx),
},
},
rest.WithPrefix("/api/v1"),
)
server.AddRoutes(
[]rest.Route{
{
// 点赞评论
Method: http.MethodPost,
Path: "/comments/:id/like",
Handler: community.LikeCommentHandler(serverCtx),
},
{
// 取消点赞评论
Method: http.MethodDelete,
Path: "/comments/:id/like",
Handler: community.UnlikeCommentHandler(serverCtx),
},
{
// 发布帖子
Method: http.MethodPost,
Path: "/posts",
Handler: community.CreatePostHandler(serverCtx),
},
{
// 发表评论
Method: http.MethodPost,
Path: "/posts/:id/comments",
Handler: community.CreateCommentHandler(serverCtx),
},
{
// 点赞帖子
Method: http.MethodPost,
Path: "/posts/:id/like",
Handler: community.LikePostHandler(serverCtx),
},
{
// 取消点赞帖子
Method: http.MethodDelete,
Path: "/posts/:id/like",
Handler: community.UnlikePostHandler(serverCtx),
},
{
// 置顶帖子
Method: http.MethodPost,
Path: "/posts/:id/pin",
Handler: community.PinPostHandler(serverCtx),
},
{
// 取消置顶
Method: http.MethodDelete,
Path: "/posts/:id/pin",
Handler: community.UnpinPostHandler(serverCtx),
},
},
rest.WithPrefix("/api/v1"),
)
}
@@ -0,0 +1,57 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"juwan-backend/common/utils/contextj"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 发表评论
func NewCreateCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateCommentLogic {
return &CreateCommentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CreateCommentLogic) CreateComment(req *types.CreateCommentReq) (resp *types.Comment, err error) {
uid, err := contextj.UserIDFrom(l.ctx)
if err != nil {
return nil, err
}
_, err = l.svcCtx.CommunityRpc.AddComments(l.ctx, &communitypb.AddCommentsReq{
PostId: req.PostId,
AuthorId: uid,
Content: req.Content,
})
if err != nil {
return nil, err
}
comments, err := l.svcCtx.CommunityRpc.SearchComments(l.ctx, &communitypb.SearchCommentsReq{
Page: 0,
Limit: 1,
PostId: req.PostId,
AuthorId: uid,
})
if err != nil || len(comments.GetComments()) == 0 {
return nil, err
}
out := mapComment(l.ctx, l.svcCtx, comments.GetComments()[len(comments.GetComments())-1], false)
return &out, nil
}
@@ -0,0 +1,65 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"strconv"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"juwan-backend/common/utils/contextj"
"github.com/zeromicro/go-zero/core/logx"
)
type CreatePostLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 发布帖子
func NewCreatePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreatePostLogic {
return &CreatePostLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CreatePostLogic) CreatePost(req *types.CreatePostReq) (resp *types.Post, err error) {
uid, err := contextj.UserIDFrom(l.ctx)
if err != nil {
return nil, err
}
linkedOrderID := int64(0)
if req.LinkedOrderId != "" {
linkedOrderID, _ = strconv.ParseInt(req.LinkedOrderId, 10, 64)
}
_, err = l.svcCtx.CommunityRpc.AddPosts(l.ctx, &communitypb.AddPostsReq{
AuthorId: uid,
AuthorRole: "consumer",
Title: req.Title,
Content: req.Content,
Images: req.Images,
Tags: req.Tags,
LinkedOrderId: linkedOrderID,
})
if err != nil {
return nil, err
}
posts, err := l.svcCtx.CommunityRpc.SearchPosts(l.ctx, &communitypb.SearchPostsReq{
Page: 0,
Limit: 1,
AuthorId: &uid,
})
if err != nil || len(posts.GetPosts()) == 0 {
return nil, err
}
out := mapPost(l.ctx, l.svcCtx, posts.GetPosts()[0], false)
return &out, nil
}
@@ -0,0 +1,45 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"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 GetPostLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 获取帖子详情
func NewGetPostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPostLogic {
return &GetPostLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetPostLogic) GetPost(req *types.PathId) (resp *types.Post, err error) {
out, err := l.svcCtx.CommunityRpc.GetPostsById(l.ctx, &communitypb.GetPostsByIdReq{Id: req.Id})
if err != nil {
return nil, err
}
uid := currentUserIDOrZero(l.ctx)
liked := false
if uid > 0 {
likes, e := l.svcCtx.CommunityRpc.SearchPostLikes(l.ctx, &communitypb.SearchPostLikesReq{Page: 0, Limit: 1, PostId: &req.Id, UserId: &uid})
liked = e == nil && len(likes.GetPostLikes()) > 0
}
post := mapPost(l.ctx, l.svcCtx, out.GetPosts(), liked)
return &post, nil
}
@@ -0,0 +1,69 @@
package community
import (
"context"
"strconv"
"time"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"juwan-backend/app/users/rpc/usercenter"
"juwan-backend/common/utils/contextj"
)
func currentUserIDOrZero(ctx context.Context) int64 {
uid, err := contextj.UserIDFrom(ctx)
if err != nil {
return 0
}
return uid
}
func buildUserProfile(ctx context.Context, svcCtx *svc.ServiceContext, userID int64) types.UserProfile {
if userID <= 0 {
return types.UserProfile{}
}
resp, err := svcCtx.UserRpc.GetUsersById(ctx, &usercenter.GetUsersByIdReq{Id: userID})
if err != nil || resp == nil || resp.Users == nil {
id := strconv.FormatInt(userID, 10)
return types.UserProfile{Id: id, Username: id, Nickname: "用户" + id, CreatedAt: time.Now().UTC().Format(time.RFC3339)}
}
u := resp.Users
return types.UserProfile{
Id: strconv.FormatInt(u.GetId(), 10),
Username: u.GetUsername(),
Nickname: u.GetNickname(),
Avatar: u.GetAvatar(),
Role: u.GetCurrentRole(),
Phone: u.GetPhone(),
Bio: u.GetBio(),
CreatedAt: time.Unix(u.GetCreatedAt(), 0).UTC().Format(time.RFC3339),
}
}
func mapPost(ctx context.Context, svcCtx *svc.ServiceContext, p *communitypb.Posts, liked bool) types.Post {
return types.Post{
Id: p.GetId(),
Title: p.GetTitle(),
Content: p.GetContent(),
Images: append([]string(nil), p.GetImages()...),
Tags: append([]string(nil), p.GetTags()...),
LikeCount: p.GetLikeCount(),
CommentCount: p.GetCommentCount(),
Liked: liked,
Author: buildUserProfile(ctx, svcCtx, p.GetAuthorId()),
CreatedAt: time.Unix(p.GetCreatedAt(), 0).UTC().Format(time.RFC3339),
}
}
func mapComment(ctx context.Context, svcCtx *svc.ServiceContext, c *communitypb.Comments, liked bool) types.Comment {
return types.Comment{
Id: c.GetId(),
Content: c.GetContent(),
Author: buildUserProfile(ctx, svcCtx, c.GetAuthorId()),
LikeCount: c.GetLikeCount(),
Liked: liked,
CreatedAt: time.Unix(c.GetCreatedAt(), 0).UTC().Format(time.RFC3339),
}
}
@@ -0,0 +1,43 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"juwan-backend/common/utils/contextj"
"github.com/zeromicro/go-zero/core/logx"
)
type LikeCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 点赞评论
func NewLikeCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LikeCommentLogic {
return &LikeCommentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *LikeCommentLogic) LikeComment(req *types.PathId) (resp *types.EmptyResp, err error) {
uid, err := contextj.UserIDFrom(l.ctx)
if err != nil {
return nil, err
}
_, err = l.svcCtx.CommunityRpc.AddCommentLikes(l.ctx, &communitypb.AddCommentLikesReq{CommentId: req.Id, UserId: uid})
if err != nil {
return nil, err
}
return &types.EmptyResp{}, nil
}
@@ -0,0 +1,43 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"juwan-backend/common/utils/contextj"
"github.com/zeromicro/go-zero/core/logx"
)
type LikePostLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 点赞帖子
func NewLikePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LikePostLogic {
return &LikePostLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *LikePostLogic) LikePost(req *types.PathId) (resp *types.EmptyResp, err error) {
uid, err := contextj.UserIDFrom(l.ctx)
if err != nil {
return nil, err
}
_, err = l.svcCtx.CommunityRpc.AddPostLikes(l.ctx, &communitypb.AddPostLikesReq{PostId: req.Id, UserId: uid})
if err != nil {
return nil, err
}
return &types.EmptyResp{}, nil
}
@@ -0,0 +1,55 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"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 ListCommentsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 获取帖子评论
func NewListCommentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListCommentsLogic {
return &ListCommentsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListCommentsLogic) ListComments(req *types.ListCommentsReq) (resp *types.CommentListResp, err error) {
if req.Limit <= 0 {
req.Limit = 20
}
out, err := l.svcCtx.CommunityRpc.SearchComments(l.ctx, &communitypb.SearchCommentsReq{
Page: req.Offset,
Limit: req.Limit,
PostId: req.Id,
})
if err != nil {
return nil, err
}
uid := currentUserIDOrZero(l.ctx)
items := make([]types.Comment, 0, len(out.GetComments()))
for _, c := range out.GetComments() {
liked := false
if uid > 0 {
likes, e := l.svcCtx.CommunityRpc.SearchCommentLikes(l.ctx, &communitypb.SearchCommentLikesReq{Page: 0, Limit: 1, CommentId: c.Id, UserId: uid})
liked = e == nil && len(likes.GetCommentLikes()) > 0
}
items = append(items, mapComment(l.ctx, l.svcCtx, c, liked))
}
return &types.CommentListResp{Items: items, Meta: types.PageMeta{Total: int64(len(items)), Offset: req.Offset, Limit: req.Limit}}, nil
}
@@ -0,0 +1,56 @@
// 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
}
@@ -0,0 +1,52 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"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 ListUserPostsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 获取用户帖子
func NewListUserPostsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListUserPostsLogic {
return &ListUserPostsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListUserPostsLogic) ListUserPosts(req *types.ListCommentsReq) (resp *types.PostListResp, err error) {
if req.Limit <= 0 {
req.Limit = 20
}
authorID := req.Id
out, err := l.svcCtx.CommunityRpc.SearchPosts(l.ctx, &communitypb.SearchPostsReq{Page: req.Offset, Limit: req.Limit, AuthorId: &authorID})
if err != nil {
return nil, err
}
uid := currentUserIDOrZero(l.ctx)
items := make([]types.Post, 0, len(out.GetPosts()))
for _, p := range out.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
}
@@ -0,0 +1,39 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"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 PinPostLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 置顶帖子
func NewPinPostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PinPostLogic {
return &PinPostLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *PinPostLogic) PinPost(req *types.PathId) (resp *types.EmptyResp, err error) {
t := true
_, err = l.svcCtx.CommunityRpc.UpdatePosts(l.ctx, &communitypb.UpdatePostsReq{Id: req.Id, Pinned: &t})
if err != nil {
return nil, err
}
return &types.EmptyResp{}, nil
}
@@ -0,0 +1,43 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"juwan-backend/common/utils/contextj"
"github.com/zeromicro/go-zero/core/logx"
)
type UnlikeCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 取消点赞评论
func NewUnlikeCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UnlikeCommentLogic {
return &UnlikeCommentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UnlikeCommentLogic) UnlikeComment(req *types.PathId) (resp *types.EmptyResp, err error) {
uid, err := contextj.UserIDFrom(l.ctx)
if err != nil {
return nil, err
}
_, err = l.svcCtx.CommunityRpc.DelCommentLikes(l.ctx, &communitypb.DelCommentLikesReq{Id: req.Id, UserId: &uid})
if err != nil {
return nil, err
}
return &types.EmptyResp{}, nil
}
@@ -0,0 +1,43 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"juwan-backend/app/community/api/internal/svc"
"juwan-backend/app/community/api/internal/types"
communitypb "juwan-backend/app/community/rpc/pb"
"juwan-backend/common/utils/contextj"
"github.com/zeromicro/go-zero/core/logx"
)
type UnlikePostLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 取消点赞帖子
func NewUnlikePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UnlikePostLogic {
return &UnlikePostLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UnlikePostLogic) UnlikePost(req *types.PathId) (resp *types.EmptyResp, err error) {
uid, err := contextj.UserIDFrom(l.ctx)
if err != nil {
return nil, err
}
_, err = l.svcCtx.CommunityRpc.DelPostLikes(l.ctx, &communitypb.DelPostLikesReq{Id: req.Id, UserId: &uid})
if err != nil {
return nil, err
}
return &types.EmptyResp{}, nil
}
@@ -0,0 +1,39 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package community
import (
"context"
"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 UnpinPostLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 取消置顶
func NewUnpinPostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UnpinPostLogic {
return &UnpinPostLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UnpinPostLogic) UnpinPost(req *types.PathId) (resp *types.EmptyResp, err error) {
f := false
_, err = l.svcCtx.CommunityRpc.UpdatePosts(l.ctx, &communitypb.UpdatePostsReq{Id: req.Id, Pinned: &f})
if err != nil {
return nil, err
}
return &types.EmptyResp{}, nil
}
@@ -0,0 +1,26 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package svc
import (
"juwan-backend/app/community/api/internal/config"
"juwan-backend/app/community/rpc/communityservice"
"juwan-backend/app/users/rpc/usercenter"
"github.com/zeromicro/go-zero/zrpc"
)
type ServiceContext struct {
Config config.Config
CommunityRpc communityservice.CommunityService
UserRpc usercenter.Usercenter
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
CommunityRpc: communityservice.NewCommunityService(zrpc.MustNewClient(c.CommunityRpcConf)),
UserRpc: usercenter.NewUsercenter(zrpc.MustNewClient(c.UsercenterRpcConf)),
}
}
+97
View File
@@ -0,0 +1,97 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.9.2
package types
type Comment struct {
Id int64 `json:"id"`
Content string `json:"content"`
Author UserProfile `json:"author"`
LikeCount int64 `json:"likeCount"`
Liked bool `json:"liked"`
CreatedAt string `json:"createdAt"`
}
type CommentListResp struct {
Items []Comment `json:"items"`
Meta PageMeta `json:"meta"`
}
type CreateCommentReq struct {
PostId int64 `json:"-"`
Content string `json:"content"`
}
type CreatePostReq struct {
Title string `json:"title"`
Content string `json:"content"`
Images []string `json:"images"`
Tags []string `json:"tags"`
LinkedOrderId string `json:"linkedOrderId,optional"`
}
type EmptyResp struct {
}
type ListCommentsReq struct {
PathId
PageReq
}
type PageMeta struct {
Total int64 `json:"total"`
Offset int64 `json:"offset"`
Limit int64 `json:"limit"`
}
type PageReq struct {
Offset int64 `form:"offset,default=0"`
Limit int64 `form:"limit,default=20"`
}
type PathId struct {
Id int64 `path:"id"`
}
type Post struct {
Id int64 `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
Images []string `json:"images"`
Tags []string `json:"tags"`
LikeCount int64 `json:"likeCount"`
CommentCount int64 `json:"commentCount"`
Liked bool `json:"liked"`
Author UserProfile `json:"author"`
CreatedAt string `json:"createdAt"`
}
type PostListReq struct {
PageReq
Tags string `form:"tags,optional"`
SortBy string `form:"sortBy,optional"`
}
type PostListResp struct {
Items []Post `json:"items"`
Meta PageMeta `json:"meta"`
}
type SimpleUser struct {
Id string `json:"id"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
}
type UserProfile struct {
Id string `json:"id"`
Username string `json:"username"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
Role string `json:"role"` // consumer, player, owner, admin
VerifiedRoles []string `json:"verifiedRoles"`
VerificationStatus map[string]string `json:"verificationStatus"`
Phone string `json:"phone,optional"`
Bio string `json:"bio,optional"`
CreatedAt string `json:"createdAt"`
}
@@ -0,0 +1,202 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.9.2
// Source: community.proto
package communityservice
import (
"context"
"juwan-backend/app/community/rpc/pb"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
)
type (
AddCommentLikesReq = pb.AddCommentLikesReq
AddCommentLikesResp = pb.AddCommentLikesResp
AddCommentsReq = pb.AddCommentsReq
AddCommentsResp = pb.AddCommentsResp
AddPostLikesReq = pb.AddPostLikesReq
AddPostLikesResp = pb.AddPostLikesResp
AddPostsReq = pb.AddPostsReq
AddPostsResp = pb.AddPostsResp
CommentLikes = pb.CommentLikes
Comments = pb.Comments
DelCommentLikesReq = pb.DelCommentLikesReq
DelCommentLikesResp = pb.DelCommentLikesResp
DelCommentsReq = pb.DelCommentsReq
DelCommentsResp = pb.DelCommentsResp
DelPostLikesReq = pb.DelPostLikesReq
DelPostLikesResp = pb.DelPostLikesResp
DelPostsReq = pb.DelPostsReq
DelPostsResp = pb.DelPostsResp
GetCommentLikesByIdReq = pb.GetCommentLikesByIdReq
GetCommentLikesByIdResp = pb.GetCommentLikesByIdResp
GetCommentsByIdReq = pb.GetCommentsByIdReq
GetCommentsByIdResp = pb.GetCommentsByIdResp
GetPostLikesByIdReq = pb.GetPostLikesByIdReq
GetPostLikesByIdResp = pb.GetPostLikesByIdResp
GetPostsByIdReq = pb.GetPostsByIdReq
GetPostsByIdResp = pb.GetPostsByIdResp
PostLikes = pb.PostLikes
Posts = pb.Posts
SearchCommentLikesReq = pb.SearchCommentLikesReq
SearchCommentLikesResp = pb.SearchCommentLikesResp
SearchCommentsReq = pb.SearchCommentsReq
SearchCommentsResp = pb.SearchCommentsResp
SearchPostLikesReq = pb.SearchPostLikesReq
SearchPostLikesResp = pb.SearchPostLikesResp
SearchPostsReq = pb.SearchPostsReq
SearchPostsResp = pb.SearchPostsResp
UpdateCommentLikesReq = pb.UpdateCommentLikesReq
UpdateCommentLikesResp = pb.UpdateCommentLikesResp
UpdateCommentsReq = pb.UpdateCommentsReq
UpdateCommentsResp = pb.UpdateCommentsResp
UpdatePostLikesReq = pb.UpdatePostLikesReq
UpdatePostLikesResp = pb.UpdatePostLikesResp
UpdatePostsReq = pb.UpdatePostsReq
UpdatePostsResp = pb.UpdatePostsResp
CommunityService interface {
// -----------------------commentLikes-----------------------
AddCommentLikes(ctx context.Context, in *AddCommentLikesReq, opts ...grpc.CallOption) (*AddCommentLikesResp, error)
UpdateCommentLikes(ctx context.Context, in *UpdateCommentLikesReq, opts ...grpc.CallOption) (*UpdateCommentLikesResp, error)
DelCommentLikes(ctx context.Context, in *DelCommentLikesReq, opts ...grpc.CallOption) (*DelCommentLikesResp, error)
GetCommentLikesById(ctx context.Context, in *GetCommentLikesByIdReq, opts ...grpc.CallOption) (*GetCommentLikesByIdResp, error)
SearchCommentLikes(ctx context.Context, in *SearchCommentLikesReq, opts ...grpc.CallOption) (*SearchCommentLikesResp, error)
// -----------------------comments-----------------------
AddComments(ctx context.Context, in *AddCommentsReq, opts ...grpc.CallOption) (*AddCommentsResp, error)
UpdateComments(ctx context.Context, in *UpdateCommentsReq, opts ...grpc.CallOption) (*UpdateCommentsResp, error)
DelComments(ctx context.Context, in *DelCommentsReq, opts ...grpc.CallOption) (*DelCommentsResp, error)
GetCommentsById(ctx context.Context, in *GetCommentsByIdReq, opts ...grpc.CallOption) (*GetCommentsByIdResp, error)
SearchComments(ctx context.Context, in *SearchCommentsReq, opts ...grpc.CallOption) (*SearchCommentsResp, error)
// -----------------------postLikes-----------------------
AddPostLikes(ctx context.Context, in *AddPostLikesReq, opts ...grpc.CallOption) (*AddPostLikesResp, error)
UpdatePostLikes(ctx context.Context, in *UpdatePostLikesReq, opts ...grpc.CallOption) (*UpdatePostLikesResp, error)
DelPostLikes(ctx context.Context, in *DelPostLikesReq, opts ...grpc.CallOption) (*DelPostLikesResp, error)
GetPostLikesById(ctx context.Context, in *GetPostLikesByIdReq, opts ...grpc.CallOption) (*GetPostLikesByIdResp, error)
SearchPostLikes(ctx context.Context, in *SearchPostLikesReq, opts ...grpc.CallOption) (*SearchPostLikesResp, error)
// -----------------------posts-----------------------
AddPosts(ctx context.Context, in *AddPostsReq, opts ...grpc.CallOption) (*AddPostsResp, error)
UpdatePosts(ctx context.Context, in *UpdatePostsReq, opts ...grpc.CallOption) (*UpdatePostsResp, error)
DelPosts(ctx context.Context, in *DelPostsReq, opts ...grpc.CallOption) (*DelPostsResp, error)
GetPostsById(ctx context.Context, in *GetPostsByIdReq, opts ...grpc.CallOption) (*GetPostsByIdResp, error)
SearchPosts(ctx context.Context, in *SearchPostsReq, opts ...grpc.CallOption) (*SearchPostsResp, error)
}
defaultCommunityService struct {
cli zrpc.Client
}
)
func NewCommunityService(cli zrpc.Client) CommunityService {
return &defaultCommunityService{
cli: cli,
}
}
// -----------------------commentLikes-----------------------
func (m *defaultCommunityService) AddCommentLikes(ctx context.Context, in *AddCommentLikesReq, opts ...grpc.CallOption) (*AddCommentLikesResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.AddCommentLikes(ctx, in, opts...)
}
func (m *defaultCommunityService) UpdateCommentLikes(ctx context.Context, in *UpdateCommentLikesReq, opts ...grpc.CallOption) (*UpdateCommentLikesResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.UpdateCommentLikes(ctx, in, opts...)
}
func (m *defaultCommunityService) DelCommentLikes(ctx context.Context, in *DelCommentLikesReq, opts ...grpc.CallOption) (*DelCommentLikesResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.DelCommentLikes(ctx, in, opts...)
}
func (m *defaultCommunityService) GetCommentLikesById(ctx context.Context, in *GetCommentLikesByIdReq, opts ...grpc.CallOption) (*GetCommentLikesByIdResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.GetCommentLikesById(ctx, in, opts...)
}
func (m *defaultCommunityService) SearchCommentLikes(ctx context.Context, in *SearchCommentLikesReq, opts ...grpc.CallOption) (*SearchCommentLikesResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.SearchCommentLikes(ctx, in, opts...)
}
// -----------------------comments-----------------------
func (m *defaultCommunityService) AddComments(ctx context.Context, in *AddCommentsReq, opts ...grpc.CallOption) (*AddCommentsResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.AddComments(ctx, in, opts...)
}
func (m *defaultCommunityService) UpdateComments(ctx context.Context, in *UpdateCommentsReq, opts ...grpc.CallOption) (*UpdateCommentsResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.UpdateComments(ctx, in, opts...)
}
func (m *defaultCommunityService) DelComments(ctx context.Context, in *DelCommentsReq, opts ...grpc.CallOption) (*DelCommentsResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.DelComments(ctx, in, opts...)
}
func (m *defaultCommunityService) GetCommentsById(ctx context.Context, in *GetCommentsByIdReq, opts ...grpc.CallOption) (*GetCommentsByIdResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.GetCommentsById(ctx, in, opts...)
}
func (m *defaultCommunityService) SearchComments(ctx context.Context, in *SearchCommentsReq, opts ...grpc.CallOption) (*SearchCommentsResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.SearchComments(ctx, in, opts...)
}
// -----------------------postLikes-----------------------
func (m *defaultCommunityService) AddPostLikes(ctx context.Context, in *AddPostLikesReq, opts ...grpc.CallOption) (*AddPostLikesResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.AddPostLikes(ctx, in, opts...)
}
func (m *defaultCommunityService) UpdatePostLikes(ctx context.Context, in *UpdatePostLikesReq, opts ...grpc.CallOption) (*UpdatePostLikesResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.UpdatePostLikes(ctx, in, opts...)
}
func (m *defaultCommunityService) DelPostLikes(ctx context.Context, in *DelPostLikesReq, opts ...grpc.CallOption) (*DelPostLikesResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.DelPostLikes(ctx, in, opts...)
}
func (m *defaultCommunityService) GetPostLikesById(ctx context.Context, in *GetPostLikesByIdReq, opts ...grpc.CallOption) (*GetPostLikesByIdResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.GetPostLikesById(ctx, in, opts...)
}
func (m *defaultCommunityService) SearchPostLikes(ctx context.Context, in *SearchPostLikesReq, opts ...grpc.CallOption) (*SearchPostLikesResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.SearchPostLikes(ctx, in, opts...)
}
// -----------------------posts-----------------------
func (m *defaultCommunityService) AddPosts(ctx context.Context, in *AddPostsReq, opts ...grpc.CallOption) (*AddPostsResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.AddPosts(ctx, in, opts...)
}
func (m *defaultCommunityService) UpdatePosts(ctx context.Context, in *UpdatePostsReq, opts ...grpc.CallOption) (*UpdatePostsResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.UpdatePosts(ctx, in, opts...)
}
func (m *defaultCommunityService) DelPosts(ctx context.Context, in *DelPostsReq, opts ...grpc.CallOption) (*DelPostsResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.DelPosts(ctx, in, opts...)
}
func (m *defaultCommunityService) GetPostsById(ctx context.Context, in *GetPostsByIdReq, opts ...grpc.CallOption) (*GetPostsByIdResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.GetPostsById(ctx, in, opts...)
}
func (m *defaultCommunityService) SearchPosts(ctx context.Context, in *SearchPostsReq, opts ...grpc.CallOption) (*SearchPostsResp, error) {
client := pb.NewCommunityServiceClient(m.cli.Conn())
return client.SearchPosts(ctx, in, opts...)
}
+38
View File
@@ -0,0 +1,38 @@
Name: pb.rpc
ListenOn: 0.0.0.0:8080
Prometheus:
Host: 0.0.0.0
Port: 4001
Path: /metrics
# tcd:
# Hosts:
# - 127.0.0.1:2379
# Key: pb.rpc
# Target: k8s://juwan/<service name>.<namespace>:8080
SnowflakeRpcConf:
Target: k8s://juwan/snowflake-svc:8080
DB:
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
Slave: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-ro.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
CacheConf:
- Host: "${REDIS_M_HOST}"
Type: node
Pass: "${REDIS_PASSWORD}"
User: "default"
- Host: "${REDIS_S_HOST}"
Type: node
Pass: "${REDIS_PASSWORD}"
User: "default"
Log:
Level: info
@@ -0,0 +1,17 @@
package config
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/zrpc"
)
type Config struct {
zrpc.RpcServerConf
SnowflakeRpcConf zrpc.RpcClientConf
DB struct {
Master string
Slaves string
}
CacheConf cache.CacheConf
}
@@ -0,0 +1,55 @@
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 AddCommentLikesLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAddCommentLikesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddCommentLikesLogic {
return &AddCommentLikesLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// -----------------------commentLikes-----------------------
func (l *AddCommentLikesLogic) AddCommentLikes(in *pb.AddCommentLikesReq) (*pb.AddCommentLikesResp, error) {
if in.GetCommentId() <= 0 || in.GetUserId() <= 0 {
return nil, errors.New("commentId and userId are required")
}
store := l.svcCtx.Store
store.Mu.Lock()
defer store.Mu.Unlock()
comment, ok := store.Comments[in.GetCommentId()]
if !ok || comment.GetDeletedAt() > 0 {
return nil, errors.New("comment not found")
}
key := commentLikeKey(in.GetCommentId(), in.GetUserId())
if _, exists := store.CommentLikes[key]; exists {
return &pb.AddCommentLikesResp{}, nil
}
store.CommentLikes[key] = &pb.CommentLikes{
CommentId: in.GetCommentId(),
UserId: in.GetUserId(),
CreatedAt: nowUnix(in.GetCreatedAt()),
}
comment.LikeCount++
return &pb.AddCommentLikesResp{}, nil
}
@@ -0,0 +1,62 @@
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
}
@@ -0,0 +1,56 @@
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
}
@@ -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
}
@@ -0,0 +1,65 @@
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 DelCommentLikesLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDelCommentLikesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelCommentLikesLogic {
return &DelCommentLikesLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *DelCommentLikesLogic) DelCommentLikes(in *pb.DelCommentLikesReq) (*pb.DelCommentLikesResp, error) {
if in.GetId() <= 0 {
return nil, errors.New("id is required")
}
store := l.svcCtx.Store
store.Mu.Lock()
defer store.Mu.Unlock()
if in.UserId != nil && in.GetUserId() > 0 {
key := commentLikeKey(in.GetId(), in.GetUserId())
if _, ok := store.CommentLikes[key]; ok {
delete(store.CommentLikes, key)
if comment, ok := store.Comments[in.GetId()]; ok && comment.LikeCount > 0 {
comment.LikeCount--
}
}
return &pb.DelCommentLikesResp{}, nil
}
removed := int64(0)
for key, like := range store.CommentLikes {
if like.GetCommentId() == in.GetId() {
delete(store.CommentLikes, key)
removed++
}
}
if removed > 0 {
if comment, ok := store.Comments[in.GetId()]; ok {
if comment.LikeCount >= removed {
comment.LikeCount -= removed
} else {
comment.LikeCount = 0
}
}
}
return &pb.DelCommentLikesResp{}, nil
}
@@ -0,0 +1,50 @@
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 DelCommentsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDelCommentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelCommentsLogic {
return &DelCommentsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *DelCommentsLogic) DelComments(in *pb.DelCommentsReq) (*pb.DelCommentsResp, error) {
if in.GetId() <= 0 {
return nil, errors.New("id is required")
}
store := l.svcCtx.Store
store.Mu.Lock()
defer store.Mu.Unlock()
comment, ok := store.Comments[in.GetId()]
if !ok {
return &pb.DelCommentsResp{}, nil
}
if comment.GetDeletedAt() == 0 {
now := nowUnix(0)
comment.DeletedAt = now
if post, ok := store.Posts[comment.GetPostId()]; ok && post.GetDeletedAt() == 0 && post.CommentCount > 0 {
post.CommentCount--
post.UpdatedAt = now
}
}
return &pb.DelCommentsResp{}, nil
}
@@ -0,0 +1,65 @@
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 DelPostLikesLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDelPostLikesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelPostLikesLogic {
return &DelPostLikesLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *DelPostLikesLogic) DelPostLikes(in *pb.DelPostLikesReq) (*pb.DelPostLikesResp, error) {
if in.GetId() <= 0 {
return nil, errors.New("id is required")
}
store := l.svcCtx.Store
store.Mu.Lock()
defer store.Mu.Unlock()
if in.UserId != nil && in.GetUserId() > 0 {
key := postLikeKey(in.GetId(), in.GetUserId())
if _, ok := store.PostLikes[key]; ok {
delete(store.PostLikes, key)
if post, ok := store.Posts[in.GetId()]; ok && post.LikeCount > 0 {
post.LikeCount--
}
}
return &pb.DelPostLikesResp{}, nil
}
removed := int64(0)
for key, like := range store.PostLikes {
if like.GetPostId() == in.GetId() {
delete(store.PostLikes, key)
removed++
}
}
if removed > 0 {
if post, ok := store.Posts[in.GetId()]; ok {
if post.LikeCount >= removed {
post.LikeCount -= removed
} else {
post.LikeCount = 0
}
}
}
return &pb.DelPostLikesResp{}, nil
}
@@ -0,0 +1,45 @@
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 DelPostsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDelPostsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelPostsLogic {
return &DelPostsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *DelPostsLogic) DelPosts(in *pb.DelPostsReq) (*pb.DelPostsResp, 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 {
return &pb.DelPostsResp{}, nil
}
now := nowUnix(0)
post.DeletedAt = now
post.UpdatedAt = now
return &pb.DelPostsResp{}, nil
}
@@ -0,0 +1,44 @@
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 GetCommentLikesByIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetCommentLikesByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCommentLikesByIdLogic {
return &GetCommentLikesByIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetCommentLikesByIdLogic) GetCommentLikesById(in *pb.GetCommentLikesByIdReq) (*pb.GetCommentLikesByIdResp, error) {
if in.GetId() <= 0 {
return nil, errors.New("id is required")
}
store := l.svcCtx.Store
store.Mu.RLock()
defer store.Mu.RUnlock()
for _, like := range store.CommentLikes {
if like.GetCommentId() == in.GetId() {
cp := *like
return &pb.GetCommentLikesByIdResp{CommentLikes: &cp}, nil
}
}
return nil, errors.New("comment like not found")
}
@@ -0,0 +1,43 @@
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 GetCommentsByIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetCommentsByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCommentsByIdLogic {
return &GetCommentsByIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetCommentsByIdLogic) GetCommentsById(in *pb.GetCommentsByIdReq) (*pb.GetCommentsByIdResp, error) {
if in.GetId() <= 0 {
return nil, errors.New("id is required")
}
store := l.svcCtx.Store
store.Mu.RLock()
defer store.Mu.RUnlock()
comment, ok := store.Comments[in.GetId()]
if !ok || comment.GetDeletedAt() > 0 {
return nil, errors.New("comment not found")
}
out := *comment
return &pb.GetCommentsByIdResp{Comments: &out}, nil
}
@@ -0,0 +1,44 @@
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 GetPostLikesByIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetPostLikesByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPostLikesByIdLogic {
return &GetPostLikesByIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetPostLikesByIdLogic) GetPostLikesById(in *pb.GetPostLikesByIdReq) (*pb.GetPostLikesByIdResp, error) {
if in.GetId() <= 0 {
return nil, errors.New("id is required")
}
store := l.svcCtx.Store
store.Mu.RLock()
defer store.Mu.RUnlock()
for _, like := range store.PostLikes {
if like.GetPostId() == in.GetId() {
cp := *like
return &pb.GetPostLikesByIdResp{PostLikes: &cp}, nil
}
}
return nil, errors.New("post like not found")
}
@@ -0,0 +1,46 @@
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 GetPostsByIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetPostsByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPostsByIdLogic {
return &GetPostsByIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetPostsByIdLogic) GetPostsById(in *pb.GetPostsByIdReq) (*pb.GetPostsByIdResp, error) {
if in.GetId() <= 0 {
return nil, errors.New("id is required")
}
store := l.svcCtx.Store
store.Mu.RLock()
defer store.Mu.RUnlock()
post, ok := store.Posts[in.GetId()]
if !ok || post.GetDeletedAt() > 0 {
return nil, errors.New("post not found")
}
out := *post
out.Images = append([]string(nil), post.Images...)
out.Tags = append([]string(nil), post.Tags...)
return &pb.GetPostsByIdResp{Posts: &out}, nil
}
@@ -0,0 +1,45 @@
package logic
import (
"sort"
"strconv"
"time"
"juwan-backend/app/community/rpc/pb"
)
func nowUnix(in int64) int64 {
if in > 0 {
return in
}
return time.Now().Unix()
}
func postLikeKey(postID, userID int64) string {
return strconv.FormatInt(postID, 10) + ":" + strconv.FormatInt(userID, 10)
}
func commentLikeKey(commentID, userID int64) string {
return strconv.FormatInt(commentID, 10) + ":" + strconv.FormatInt(userID, 10)
}
func sortPostsDesc(posts []*pb.Posts) {
sort.Slice(posts, func(i, j int) bool {
if posts[i].Pinned != posts[j].Pinned {
return posts[i].Pinned
}
if posts[i].CreatedAt == posts[j].CreatedAt {
return posts[i].Id > posts[j].Id
}
return posts[i].CreatedAt > posts[j].CreatedAt
})
}
func sortCommentsAsc(comments []*pb.Comments) {
sort.Slice(comments, func(i, j int) bool {
if comments[i].CreatedAt == comments[j].CreatedAt {
return comments[i].Id < comments[j].Id
}
return comments[i].CreatedAt < comments[j].CreatedAt
})
}
@@ -0,0 +1,61 @@
package logic
import (
"context"
"juwan-backend/app/community/rpc/internal/svc"
"juwan-backend/app/community/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type SearchCommentLikesLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewSearchCommentLikesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchCommentLikesLogic {
return &SearchCommentLikesLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *SearchCommentLikesLogic) SearchCommentLikes(in *pb.SearchCommentLikesReq) (*pb.SearchCommentLikesResp, error) {
limit := in.GetLimit()
if limit <= 0 {
limit = 20
}
offset := in.GetPage()
if offset < 0 {
offset = 0
}
store := l.svcCtx.Store
store.Mu.RLock()
defer store.Mu.RUnlock()
filtered := make([]*pb.CommentLikes, 0, len(store.CommentLikes))
for _, like := range store.CommentLikes {
if in.GetCommentId() > 0 && like.GetCommentId() != in.GetCommentId() {
continue
}
if in.GetUserId() > 0 && like.GetUserId() != in.GetUserId() {
continue
}
cp := *like
filtered = append(filtered, &cp)
}
if offset >= int64(len(filtered)) {
return &pb.SearchCommentLikesResp{CommentLikes: []*pb.CommentLikes{}}, nil
}
end := offset + limit
if end > int64(len(filtered)) {
end = int64(len(filtered))
}
return &pb.SearchCommentLikesResp{CommentLikes: filtered[offset:end]}, nil
}
@@ -0,0 +1,76 @@
package logic
import (
"context"
"strings"
"juwan-backend/app/community/rpc/internal/svc"
"juwan-backend/app/community/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type SearchCommentsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewSearchCommentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchCommentsLogic {
return &SearchCommentsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *SearchCommentsLogic) SearchComments(in *pb.SearchCommentsReq) (*pb.SearchCommentsResp, error) {
limit := in.GetLimit()
if limit <= 0 {
limit = 20
}
offset := in.GetPage()
if offset < 0 {
offset = 0
}
store := l.svcCtx.Store
store.Mu.RLock()
defer store.Mu.RUnlock()
filtered := make([]*pb.Comments, 0, len(store.Comments))
for _, c := range store.Comments {
if c.GetDeletedAt() > 0 {
continue
}
if in.GetId() > 0 && c.GetId() != in.GetId() {
continue
}
if in.GetPostId() > 0 && c.GetPostId() != in.GetPostId() {
continue
}
if in.GetAuthorId() > 0 && c.GetAuthorId() != in.GetAuthorId() {
continue
}
if in.Content != nil && !strings.Contains(strings.ToLower(c.GetContent()), strings.ToLower(in.GetContent())) {
continue
}
if in.LikeCount != nil && c.GetLikeCount() != in.GetLikeCount() {
continue
}
cc := *c
filtered = append(filtered, &cc)
}
sortCommentsAsc(filtered)
if offset >= int64(len(filtered)) {
return &pb.SearchCommentsResp{Comments: []*pb.Comments{}}, nil
}
end := offset + limit
if end > int64(len(filtered)) {
end = int64(len(filtered))
}
return &pb.SearchCommentsResp{Comments: filtered[offset:end]}, nil
}
@@ -0,0 +1,61 @@
package logic
import (
"context"
"juwan-backend/app/community/rpc/internal/svc"
"juwan-backend/app/community/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type SearchPostLikesLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewSearchPostLikesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchPostLikesLogic {
return &SearchPostLikesLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *SearchPostLikesLogic) SearchPostLikes(in *pb.SearchPostLikesReq) (*pb.SearchPostLikesResp, error) {
limit := in.GetLimit()
if limit <= 0 {
limit = 20
}
offset := in.GetPage()
if offset < 0 {
offset = 0
}
store := l.svcCtx.Store
store.Mu.RLock()
defer store.Mu.RUnlock()
filtered := make([]*pb.PostLikes, 0, len(store.PostLikes))
for _, like := range store.PostLikes {
if in.PostId != nil && like.GetPostId() != in.GetPostId() {
continue
}
if in.UserId != nil && like.GetUserId() != in.GetUserId() {
continue
}
cp := *like
filtered = append(filtered, &cp)
}
if offset >= int64(len(filtered)) {
return &pb.SearchPostLikesResp{PostLikes: []*pb.PostLikes{}}, nil
}
end := offset + limit
if end > int64(len(filtered)) {
end = int64(len(filtered))
}
return &pb.SearchPostLikesResp{PostLikes: filtered[offset:end]}, nil
}
@@ -0,0 +1,96 @@
package logic
import (
"context"
"strings"
"juwan-backend/app/community/rpc/internal/svc"
"juwan-backend/app/community/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type SearchPostsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewSearchPostsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchPostsLogic {
return &SearchPostsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *SearchPostsLogic) SearchPosts(in *pb.SearchPostsReq) (*pb.SearchPostsResp, error) {
limit := in.GetLimit()
if limit <= 0 {
limit = 20
}
offset := in.GetPage()
if offset < 0 {
offset = 0
}
store := l.svcCtx.Store
store.Mu.RLock()
defer store.Mu.RUnlock()
filtered := make([]*pb.Posts, 0, len(store.Posts))
for _, p := range store.Posts {
if p.GetDeletedAt() > 0 {
continue
}
if in.GetId() > 0 && p.GetId() != in.GetId() {
continue
}
if in.AuthorId != nil && p.GetAuthorId() != in.GetAuthorId() {
continue
}
if in.AuthorRole != nil && p.GetAuthorRole() != in.GetAuthorRole() {
continue
}
if in.Title != nil && !strings.Contains(strings.ToLower(p.GetTitle()), strings.ToLower(in.GetTitle())) {
continue
}
if in.Content != nil && !strings.Contains(strings.ToLower(p.GetContent()), strings.ToLower(in.GetContent())) {
continue
}
if len(in.GetTags()) > 0 {
match := false
for _, t := range in.GetTags() {
for _, pt := range p.GetTags() {
if t == pt {
match = true
break
}
}
if match {
break
}
}
if !match {
continue
}
}
cp := *p
cp.Images = append([]string(nil), p.Images...)
cp.Tags = append([]string(nil), p.Tags...)
filtered = append(filtered, &cp)
}
sortPostsDesc(filtered)
if offset >= int64(len(filtered)) {
return &pb.SearchPostsResp{Posts: []*pb.Posts{}}, nil
}
end := offset + limit
if end > int64(len(filtered)) {
end = int64(len(filtered))
}
return &pb.SearchPostsResp{Posts: filtered[offset:end]}, nil
}
@@ -0,0 +1,47 @@
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 UpdateCommentLikesLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateCommentLikesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateCommentLikesLogic {
return &UpdateCommentLikesLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UpdateCommentLikesLogic) UpdateCommentLikes(in *pb.UpdateCommentLikesReq) (*pb.UpdateCommentLikesResp, error) {
if in.GetCommentId() <= 0 || in.GetUserId() <= 0 {
return nil, errors.New("commentId and userId are required")
}
store := l.svcCtx.Store
store.Mu.Lock()
defer store.Mu.Unlock()
if _, ok := store.Comments[in.GetCommentId()]; !ok {
return nil, errors.New("comment not found")
}
key := commentLikeKey(in.GetCommentId(), in.GetUserId())
store.CommentLikes[key] = &pb.CommentLikes{
CommentId: in.GetCommentId(),
UserId: in.GetUserId(),
CreatedAt: nowUnix(in.GetCreatedAt()),
}
return &pb.UpdateCommentLikesResp{}, nil
}
@@ -0,0 +1,61 @@
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 UpdateCommentsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateCommentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateCommentsLogic {
return &UpdateCommentsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UpdateCommentsLogic) UpdateComments(in *pb.UpdateCommentsReq) (*pb.UpdateCommentsResp, error) {
if in.GetId() <= 0 {
return nil, errors.New("id is required")
}
store := l.svcCtx.Store
store.Mu.Lock()
defer store.Mu.Unlock()
comment, ok := store.Comments[in.GetId()]
if !ok || comment.GetDeletedAt() > 0 {
return nil, errors.New("comment not found")
}
if in.GetPostId() > 0 {
comment.PostId = in.GetPostId()
}
if in.GetAuthorId() > 0 {
comment.AuthorId = in.GetAuthorId()
}
if in.GetContent() != "" {
comment.Content = in.GetContent()
}
if in.GetLikeCount() > 0 {
comment.LikeCount = in.GetLikeCount()
}
if in.GetDeletedAt() > 0 {
comment.DeletedAt = in.GetDeletedAt()
}
if in.GetCreatedAt() > 0 {
comment.CreatedAt = in.GetCreatedAt()
}
return &pb.UpdateCommentsResp{}, nil
}
@@ -0,0 +1,49 @@
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 UpdatePostLikesLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdatePostLikesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePostLikesLogic {
return &UpdatePostLikesLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UpdatePostLikesLogic) UpdatePostLikes(in *pb.UpdatePostLikesReq) (*pb.UpdatePostLikesResp, error) {
if in.PostId == nil || in.UserId == nil {
return nil, errors.New("postId and userId are required")
}
postID := in.GetPostId()
userID := in.GetUserId()
store := l.svcCtx.Store
store.Mu.Lock()
defer store.Mu.Unlock()
if _, ok := store.Posts[postID]; !ok {
return nil, errors.New("post not found")
}
key := postLikeKey(postID, userID)
store.PostLikes[key] = &pb.PostLikes{
PostId: postID,
UserId: userID,
CreatedAt: nowUnix(in.GetCreatedAt()),
}
return &pb.UpdatePostLikesResp{}, nil
}
@@ -0,0 +1,86 @@
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
}
@@ -0,0 +1,128 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.9.2
// Source: community.proto
package server
import (
"context"
"juwan-backend/app/community/rpc/internal/logic"
"juwan-backend/app/community/rpc/internal/svc"
"juwan-backend/app/community/rpc/pb"
)
type CommunityServiceServer struct {
svcCtx *svc.ServiceContext
pb.UnimplementedCommunityServiceServer
}
func NewCommunityServiceServer(svcCtx *svc.ServiceContext) *CommunityServiceServer {
return &CommunityServiceServer{
svcCtx: svcCtx,
}
}
// -----------------------commentLikes-----------------------
func (s *CommunityServiceServer) AddCommentLikes(ctx context.Context, in *pb.AddCommentLikesReq) (*pb.AddCommentLikesResp, error) {
l := logic.NewAddCommentLikesLogic(ctx, s.svcCtx)
return l.AddCommentLikes(in)
}
func (s *CommunityServiceServer) UpdateCommentLikes(ctx context.Context, in *pb.UpdateCommentLikesReq) (*pb.UpdateCommentLikesResp, error) {
l := logic.NewUpdateCommentLikesLogic(ctx, s.svcCtx)
return l.UpdateCommentLikes(in)
}
func (s *CommunityServiceServer) DelCommentLikes(ctx context.Context, in *pb.DelCommentLikesReq) (*pb.DelCommentLikesResp, error) {
l := logic.NewDelCommentLikesLogic(ctx, s.svcCtx)
return l.DelCommentLikes(in)
}
func (s *CommunityServiceServer) GetCommentLikesById(ctx context.Context, in *pb.GetCommentLikesByIdReq) (*pb.GetCommentLikesByIdResp, error) {
l := logic.NewGetCommentLikesByIdLogic(ctx, s.svcCtx)
return l.GetCommentLikesById(in)
}
func (s *CommunityServiceServer) SearchCommentLikes(ctx context.Context, in *pb.SearchCommentLikesReq) (*pb.SearchCommentLikesResp, error) {
l := logic.NewSearchCommentLikesLogic(ctx, s.svcCtx)
return l.SearchCommentLikes(in)
}
// -----------------------comments-----------------------
func (s *CommunityServiceServer) AddComments(ctx context.Context, in *pb.AddCommentsReq) (*pb.AddCommentsResp, error) {
l := logic.NewAddCommentsLogic(ctx, s.svcCtx)
return l.AddComments(in)
}
func (s *CommunityServiceServer) UpdateComments(ctx context.Context, in *pb.UpdateCommentsReq) (*pb.UpdateCommentsResp, error) {
l := logic.NewUpdateCommentsLogic(ctx, s.svcCtx)
return l.UpdateComments(in)
}
func (s *CommunityServiceServer) DelComments(ctx context.Context, in *pb.DelCommentsReq) (*pb.DelCommentsResp, error) {
l := logic.NewDelCommentsLogic(ctx, s.svcCtx)
return l.DelComments(in)
}
func (s *CommunityServiceServer) GetCommentsById(ctx context.Context, in *pb.GetCommentsByIdReq) (*pb.GetCommentsByIdResp, error) {
l := logic.NewGetCommentsByIdLogic(ctx, s.svcCtx)
return l.GetCommentsById(in)
}
func (s *CommunityServiceServer) SearchComments(ctx context.Context, in *pb.SearchCommentsReq) (*pb.SearchCommentsResp, error) {
l := logic.NewSearchCommentsLogic(ctx, s.svcCtx)
return l.SearchComments(in)
}
// -----------------------postLikes-----------------------
func (s *CommunityServiceServer) AddPostLikes(ctx context.Context, in *pb.AddPostLikesReq) (*pb.AddPostLikesResp, error) {
l := logic.NewAddPostLikesLogic(ctx, s.svcCtx)
return l.AddPostLikes(in)
}
func (s *CommunityServiceServer) UpdatePostLikes(ctx context.Context, in *pb.UpdatePostLikesReq) (*pb.UpdatePostLikesResp, error) {
l := logic.NewUpdatePostLikesLogic(ctx, s.svcCtx)
return l.UpdatePostLikes(in)
}
func (s *CommunityServiceServer) DelPostLikes(ctx context.Context, in *pb.DelPostLikesReq) (*pb.DelPostLikesResp, error) {
l := logic.NewDelPostLikesLogic(ctx, s.svcCtx)
return l.DelPostLikes(in)
}
func (s *CommunityServiceServer) GetPostLikesById(ctx context.Context, in *pb.GetPostLikesByIdReq) (*pb.GetPostLikesByIdResp, error) {
l := logic.NewGetPostLikesByIdLogic(ctx, s.svcCtx)
return l.GetPostLikesById(in)
}
func (s *CommunityServiceServer) SearchPostLikes(ctx context.Context, in *pb.SearchPostLikesReq) (*pb.SearchPostLikesResp, error) {
l := logic.NewSearchPostLikesLogic(ctx, s.svcCtx)
return l.SearchPostLikes(in)
}
// -----------------------posts-----------------------
func (s *CommunityServiceServer) AddPosts(ctx context.Context, in *pb.AddPostsReq) (*pb.AddPostsResp, error) {
l := logic.NewAddPostsLogic(ctx, s.svcCtx)
return l.AddPosts(in)
}
func (s *CommunityServiceServer) UpdatePosts(ctx context.Context, in *pb.UpdatePostsReq) (*pb.UpdatePostsResp, error) {
l := logic.NewUpdatePostsLogic(ctx, s.svcCtx)
return l.UpdatePosts(in)
}
func (s *CommunityServiceServer) DelPosts(ctx context.Context, in *pb.DelPostsReq) (*pb.DelPostsResp, error) {
l := logic.NewDelPostsLogic(ctx, s.svcCtx)
return l.DelPosts(in)
}
func (s *CommunityServiceServer) GetPostsById(ctx context.Context, in *pb.GetPostsByIdReq) (*pb.GetPostsByIdResp, error) {
l := logic.NewGetPostsByIdLogic(ctx, s.svcCtx)
return l.GetPostsById(in)
}
func (s *CommunityServiceServer) SearchPosts(ctx context.Context, in *pb.SearchPostsReq) (*pb.SearchPostsResp, error) {
l := logic.NewSearchPostsLogic(ctx, s.svcCtx)
return l.SearchPosts(in)
}
@@ -0,0 +1,15 @@
package svc
import "juwan-backend/app/community/rpc/internal/config"
type ServiceContext struct {
Config config.Config
Store *CommunityStore
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
Store: NewCommunityStore(),
}
}
+40
View File
@@ -0,0 +1,40 @@
package svc
import (
"sync"
"juwan-backend/app/community/rpc/pb"
)
type CommunityStore struct {
Mu sync.RWMutex
nextPostID int64
nextCommentID int64
Posts map[int64]*pb.Posts
Comments map[int64]*pb.Comments
PostLikes map[string]*pb.PostLikes
CommentLikes map[string]*pb.CommentLikes
}
func NewCommunityStore() *CommunityStore {
return &CommunityStore{
nextPostID: 1000,
nextCommentID: 1000,
Posts: make(map[int64]*pb.Posts),
Comments: make(map[int64]*pb.Comments),
PostLikes: make(map[string]*pb.PostLikes),
CommentLikes: make(map[string]*pb.CommentLikes),
}
}
func (s *CommunityStore) NextPost() int64 {
s.nextPostID++
return s.nextPostID
}
func (s *CommunityStore) NextComment() int64 {
s.nextCommentID++
return s.nextCommentID
}
+39
View File
@@ -0,0 +1,39 @@
package main
import (
"flag"
"fmt"
"juwan-backend/app/community/rpc/internal/config"
"juwan-backend/app/community/rpc/internal/server"
"juwan-backend/app/community/rpc/internal/svc"
"juwan-backend/app/community/rpc/pb"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
var configFile = flag.String("f", "etc/pb.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
ctx := svc.NewServiceContext(c)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
pb.RegisterCommunityServiceServer(grpcServer, server.NewCommunityServiceServer(ctx))
if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer)
}
})
defer s.Stop()
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
s.Start()
}
File diff suppressed because it is too large Load Diff
+851
View File
@@ -0,0 +1,851 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.6.1
// - protoc v5.29.6
// source: community.proto
package pb
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
CommunityService_AddCommentLikes_FullMethodName = "/pb.communityService/AddCommentLikes"
CommunityService_UpdateCommentLikes_FullMethodName = "/pb.communityService/UpdateCommentLikes"
CommunityService_DelCommentLikes_FullMethodName = "/pb.communityService/DelCommentLikes"
CommunityService_GetCommentLikesById_FullMethodName = "/pb.communityService/GetCommentLikesById"
CommunityService_SearchCommentLikes_FullMethodName = "/pb.communityService/SearchCommentLikes"
CommunityService_AddComments_FullMethodName = "/pb.communityService/AddComments"
CommunityService_UpdateComments_FullMethodName = "/pb.communityService/UpdateComments"
CommunityService_DelComments_FullMethodName = "/pb.communityService/DelComments"
CommunityService_GetCommentsById_FullMethodName = "/pb.communityService/GetCommentsById"
CommunityService_SearchComments_FullMethodName = "/pb.communityService/SearchComments"
CommunityService_AddPostLikes_FullMethodName = "/pb.communityService/AddPostLikes"
CommunityService_UpdatePostLikes_FullMethodName = "/pb.communityService/UpdatePostLikes"
CommunityService_DelPostLikes_FullMethodName = "/pb.communityService/DelPostLikes"
CommunityService_GetPostLikesById_FullMethodName = "/pb.communityService/GetPostLikesById"
CommunityService_SearchPostLikes_FullMethodName = "/pb.communityService/SearchPostLikes"
CommunityService_AddPosts_FullMethodName = "/pb.communityService/AddPosts"
CommunityService_UpdatePosts_FullMethodName = "/pb.communityService/UpdatePosts"
CommunityService_DelPosts_FullMethodName = "/pb.communityService/DelPosts"
CommunityService_GetPostsById_FullMethodName = "/pb.communityService/GetPostsById"
CommunityService_SearchPosts_FullMethodName = "/pb.communityService/SearchPosts"
)
// CommunityServiceClient is the client API for CommunityService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type CommunityServiceClient interface {
// -----------------------commentLikes-----------------------
AddCommentLikes(ctx context.Context, in *AddCommentLikesReq, opts ...grpc.CallOption) (*AddCommentLikesResp, error)
UpdateCommentLikes(ctx context.Context, in *UpdateCommentLikesReq, opts ...grpc.CallOption) (*UpdateCommentLikesResp, error)
DelCommentLikes(ctx context.Context, in *DelCommentLikesReq, opts ...grpc.CallOption) (*DelCommentLikesResp, error)
GetCommentLikesById(ctx context.Context, in *GetCommentLikesByIdReq, opts ...grpc.CallOption) (*GetCommentLikesByIdResp, error)
SearchCommentLikes(ctx context.Context, in *SearchCommentLikesReq, opts ...grpc.CallOption) (*SearchCommentLikesResp, error)
// -----------------------comments-----------------------
AddComments(ctx context.Context, in *AddCommentsReq, opts ...grpc.CallOption) (*AddCommentsResp, error)
UpdateComments(ctx context.Context, in *UpdateCommentsReq, opts ...grpc.CallOption) (*UpdateCommentsResp, error)
DelComments(ctx context.Context, in *DelCommentsReq, opts ...grpc.CallOption) (*DelCommentsResp, error)
GetCommentsById(ctx context.Context, in *GetCommentsByIdReq, opts ...grpc.CallOption) (*GetCommentsByIdResp, error)
SearchComments(ctx context.Context, in *SearchCommentsReq, opts ...grpc.CallOption) (*SearchCommentsResp, error)
// -----------------------postLikes-----------------------
AddPostLikes(ctx context.Context, in *AddPostLikesReq, opts ...grpc.CallOption) (*AddPostLikesResp, error)
UpdatePostLikes(ctx context.Context, in *UpdatePostLikesReq, opts ...grpc.CallOption) (*UpdatePostLikesResp, error)
DelPostLikes(ctx context.Context, in *DelPostLikesReq, opts ...grpc.CallOption) (*DelPostLikesResp, error)
GetPostLikesById(ctx context.Context, in *GetPostLikesByIdReq, opts ...grpc.CallOption) (*GetPostLikesByIdResp, error)
SearchPostLikes(ctx context.Context, in *SearchPostLikesReq, opts ...grpc.CallOption) (*SearchPostLikesResp, error)
// -----------------------posts-----------------------
AddPosts(ctx context.Context, in *AddPostsReq, opts ...grpc.CallOption) (*AddPostsResp, error)
UpdatePosts(ctx context.Context, in *UpdatePostsReq, opts ...grpc.CallOption) (*UpdatePostsResp, error)
DelPosts(ctx context.Context, in *DelPostsReq, opts ...grpc.CallOption) (*DelPostsResp, error)
GetPostsById(ctx context.Context, in *GetPostsByIdReq, opts ...grpc.CallOption) (*GetPostsByIdResp, error)
SearchPosts(ctx context.Context, in *SearchPostsReq, opts ...grpc.CallOption) (*SearchPostsResp, error)
}
type communityServiceClient struct {
cc grpc.ClientConnInterface
}
func NewCommunityServiceClient(cc grpc.ClientConnInterface) CommunityServiceClient {
return &communityServiceClient{cc}
}
func (c *communityServiceClient) AddCommentLikes(ctx context.Context, in *AddCommentLikesReq, opts ...grpc.CallOption) (*AddCommentLikesResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(AddCommentLikesResp)
err := c.cc.Invoke(ctx, CommunityService_AddCommentLikes_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) UpdateCommentLikes(ctx context.Context, in *UpdateCommentLikesReq, opts ...grpc.CallOption) (*UpdateCommentLikesResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(UpdateCommentLikesResp)
err := c.cc.Invoke(ctx, CommunityService_UpdateCommentLikes_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) DelCommentLikes(ctx context.Context, in *DelCommentLikesReq, opts ...grpc.CallOption) (*DelCommentLikesResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(DelCommentLikesResp)
err := c.cc.Invoke(ctx, CommunityService_DelCommentLikes_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) GetCommentLikesById(ctx context.Context, in *GetCommentLikesByIdReq, opts ...grpc.CallOption) (*GetCommentLikesByIdResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetCommentLikesByIdResp)
err := c.cc.Invoke(ctx, CommunityService_GetCommentLikesById_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) SearchCommentLikes(ctx context.Context, in *SearchCommentLikesReq, opts ...grpc.CallOption) (*SearchCommentLikesResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(SearchCommentLikesResp)
err := c.cc.Invoke(ctx, CommunityService_SearchCommentLikes_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) AddComments(ctx context.Context, in *AddCommentsReq, opts ...grpc.CallOption) (*AddCommentsResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(AddCommentsResp)
err := c.cc.Invoke(ctx, CommunityService_AddComments_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) UpdateComments(ctx context.Context, in *UpdateCommentsReq, opts ...grpc.CallOption) (*UpdateCommentsResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(UpdateCommentsResp)
err := c.cc.Invoke(ctx, CommunityService_UpdateComments_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) DelComments(ctx context.Context, in *DelCommentsReq, opts ...grpc.CallOption) (*DelCommentsResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(DelCommentsResp)
err := c.cc.Invoke(ctx, CommunityService_DelComments_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) GetCommentsById(ctx context.Context, in *GetCommentsByIdReq, opts ...grpc.CallOption) (*GetCommentsByIdResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetCommentsByIdResp)
err := c.cc.Invoke(ctx, CommunityService_GetCommentsById_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) SearchComments(ctx context.Context, in *SearchCommentsReq, opts ...grpc.CallOption) (*SearchCommentsResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(SearchCommentsResp)
err := c.cc.Invoke(ctx, CommunityService_SearchComments_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) AddPostLikes(ctx context.Context, in *AddPostLikesReq, opts ...grpc.CallOption) (*AddPostLikesResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(AddPostLikesResp)
err := c.cc.Invoke(ctx, CommunityService_AddPostLikes_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) UpdatePostLikes(ctx context.Context, in *UpdatePostLikesReq, opts ...grpc.CallOption) (*UpdatePostLikesResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(UpdatePostLikesResp)
err := c.cc.Invoke(ctx, CommunityService_UpdatePostLikes_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) DelPostLikes(ctx context.Context, in *DelPostLikesReq, opts ...grpc.CallOption) (*DelPostLikesResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(DelPostLikesResp)
err := c.cc.Invoke(ctx, CommunityService_DelPostLikes_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) GetPostLikesById(ctx context.Context, in *GetPostLikesByIdReq, opts ...grpc.CallOption) (*GetPostLikesByIdResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetPostLikesByIdResp)
err := c.cc.Invoke(ctx, CommunityService_GetPostLikesById_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) SearchPostLikes(ctx context.Context, in *SearchPostLikesReq, opts ...grpc.CallOption) (*SearchPostLikesResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(SearchPostLikesResp)
err := c.cc.Invoke(ctx, CommunityService_SearchPostLikes_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) AddPosts(ctx context.Context, in *AddPostsReq, opts ...grpc.CallOption) (*AddPostsResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(AddPostsResp)
err := c.cc.Invoke(ctx, CommunityService_AddPosts_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) UpdatePosts(ctx context.Context, in *UpdatePostsReq, opts ...grpc.CallOption) (*UpdatePostsResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(UpdatePostsResp)
err := c.cc.Invoke(ctx, CommunityService_UpdatePosts_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) DelPosts(ctx context.Context, in *DelPostsReq, opts ...grpc.CallOption) (*DelPostsResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(DelPostsResp)
err := c.cc.Invoke(ctx, CommunityService_DelPosts_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) GetPostsById(ctx context.Context, in *GetPostsByIdReq, opts ...grpc.CallOption) (*GetPostsByIdResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetPostsByIdResp)
err := c.cc.Invoke(ctx, CommunityService_GetPostsById_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *communityServiceClient) SearchPosts(ctx context.Context, in *SearchPostsReq, opts ...grpc.CallOption) (*SearchPostsResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(SearchPostsResp)
err := c.cc.Invoke(ctx, CommunityService_SearchPosts_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// CommunityServiceServer is the server API for CommunityService service.
// All implementations must embed UnimplementedCommunityServiceServer
// for forward compatibility.
type CommunityServiceServer interface {
// -----------------------commentLikes-----------------------
AddCommentLikes(context.Context, *AddCommentLikesReq) (*AddCommentLikesResp, error)
UpdateCommentLikes(context.Context, *UpdateCommentLikesReq) (*UpdateCommentLikesResp, error)
DelCommentLikes(context.Context, *DelCommentLikesReq) (*DelCommentLikesResp, error)
GetCommentLikesById(context.Context, *GetCommentLikesByIdReq) (*GetCommentLikesByIdResp, error)
SearchCommentLikes(context.Context, *SearchCommentLikesReq) (*SearchCommentLikesResp, error)
// -----------------------comments-----------------------
AddComments(context.Context, *AddCommentsReq) (*AddCommentsResp, error)
UpdateComments(context.Context, *UpdateCommentsReq) (*UpdateCommentsResp, error)
DelComments(context.Context, *DelCommentsReq) (*DelCommentsResp, error)
GetCommentsById(context.Context, *GetCommentsByIdReq) (*GetCommentsByIdResp, error)
SearchComments(context.Context, *SearchCommentsReq) (*SearchCommentsResp, error)
// -----------------------postLikes-----------------------
AddPostLikes(context.Context, *AddPostLikesReq) (*AddPostLikesResp, error)
UpdatePostLikes(context.Context, *UpdatePostLikesReq) (*UpdatePostLikesResp, error)
DelPostLikes(context.Context, *DelPostLikesReq) (*DelPostLikesResp, error)
GetPostLikesById(context.Context, *GetPostLikesByIdReq) (*GetPostLikesByIdResp, error)
SearchPostLikes(context.Context, *SearchPostLikesReq) (*SearchPostLikesResp, error)
// -----------------------posts-----------------------
AddPosts(context.Context, *AddPostsReq) (*AddPostsResp, error)
UpdatePosts(context.Context, *UpdatePostsReq) (*UpdatePostsResp, error)
DelPosts(context.Context, *DelPostsReq) (*DelPostsResp, error)
GetPostsById(context.Context, *GetPostsByIdReq) (*GetPostsByIdResp, error)
SearchPosts(context.Context, *SearchPostsReq) (*SearchPostsResp, error)
mustEmbedUnimplementedCommunityServiceServer()
}
// UnimplementedCommunityServiceServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedCommunityServiceServer struct{}
func (UnimplementedCommunityServiceServer) AddCommentLikes(context.Context, *AddCommentLikesReq) (*AddCommentLikesResp, error) {
return nil, status.Error(codes.Unimplemented, "method AddCommentLikes not implemented")
}
func (UnimplementedCommunityServiceServer) UpdateCommentLikes(context.Context, *UpdateCommentLikesReq) (*UpdateCommentLikesResp, error) {
return nil, status.Error(codes.Unimplemented, "method UpdateCommentLikes not implemented")
}
func (UnimplementedCommunityServiceServer) DelCommentLikes(context.Context, *DelCommentLikesReq) (*DelCommentLikesResp, error) {
return nil, status.Error(codes.Unimplemented, "method DelCommentLikes not implemented")
}
func (UnimplementedCommunityServiceServer) GetCommentLikesById(context.Context, *GetCommentLikesByIdReq) (*GetCommentLikesByIdResp, error) {
return nil, status.Error(codes.Unimplemented, "method GetCommentLikesById not implemented")
}
func (UnimplementedCommunityServiceServer) SearchCommentLikes(context.Context, *SearchCommentLikesReq) (*SearchCommentLikesResp, error) {
return nil, status.Error(codes.Unimplemented, "method SearchCommentLikes not implemented")
}
func (UnimplementedCommunityServiceServer) AddComments(context.Context, *AddCommentsReq) (*AddCommentsResp, error) {
return nil, status.Error(codes.Unimplemented, "method AddComments not implemented")
}
func (UnimplementedCommunityServiceServer) UpdateComments(context.Context, *UpdateCommentsReq) (*UpdateCommentsResp, error) {
return nil, status.Error(codes.Unimplemented, "method UpdateComments not implemented")
}
func (UnimplementedCommunityServiceServer) DelComments(context.Context, *DelCommentsReq) (*DelCommentsResp, error) {
return nil, status.Error(codes.Unimplemented, "method DelComments not implemented")
}
func (UnimplementedCommunityServiceServer) GetCommentsById(context.Context, *GetCommentsByIdReq) (*GetCommentsByIdResp, error) {
return nil, status.Error(codes.Unimplemented, "method GetCommentsById not implemented")
}
func (UnimplementedCommunityServiceServer) SearchComments(context.Context, *SearchCommentsReq) (*SearchCommentsResp, error) {
return nil, status.Error(codes.Unimplemented, "method SearchComments not implemented")
}
func (UnimplementedCommunityServiceServer) AddPostLikes(context.Context, *AddPostLikesReq) (*AddPostLikesResp, error) {
return nil, status.Error(codes.Unimplemented, "method AddPostLikes not implemented")
}
func (UnimplementedCommunityServiceServer) UpdatePostLikes(context.Context, *UpdatePostLikesReq) (*UpdatePostLikesResp, error) {
return nil, status.Error(codes.Unimplemented, "method UpdatePostLikes not implemented")
}
func (UnimplementedCommunityServiceServer) DelPostLikes(context.Context, *DelPostLikesReq) (*DelPostLikesResp, error) {
return nil, status.Error(codes.Unimplemented, "method DelPostLikes not implemented")
}
func (UnimplementedCommunityServiceServer) GetPostLikesById(context.Context, *GetPostLikesByIdReq) (*GetPostLikesByIdResp, error) {
return nil, status.Error(codes.Unimplemented, "method GetPostLikesById not implemented")
}
func (UnimplementedCommunityServiceServer) SearchPostLikes(context.Context, *SearchPostLikesReq) (*SearchPostLikesResp, error) {
return nil, status.Error(codes.Unimplemented, "method SearchPostLikes not implemented")
}
func (UnimplementedCommunityServiceServer) AddPosts(context.Context, *AddPostsReq) (*AddPostsResp, error) {
return nil, status.Error(codes.Unimplemented, "method AddPosts not implemented")
}
func (UnimplementedCommunityServiceServer) UpdatePosts(context.Context, *UpdatePostsReq) (*UpdatePostsResp, error) {
return nil, status.Error(codes.Unimplemented, "method UpdatePosts not implemented")
}
func (UnimplementedCommunityServiceServer) DelPosts(context.Context, *DelPostsReq) (*DelPostsResp, error) {
return nil, status.Error(codes.Unimplemented, "method DelPosts not implemented")
}
func (UnimplementedCommunityServiceServer) GetPostsById(context.Context, *GetPostsByIdReq) (*GetPostsByIdResp, error) {
return nil, status.Error(codes.Unimplemented, "method GetPostsById not implemented")
}
func (UnimplementedCommunityServiceServer) SearchPosts(context.Context, *SearchPostsReq) (*SearchPostsResp, error) {
return nil, status.Error(codes.Unimplemented, "method SearchPosts not implemented")
}
func (UnimplementedCommunityServiceServer) mustEmbedUnimplementedCommunityServiceServer() {}
func (UnimplementedCommunityServiceServer) testEmbeddedByValue() {}
// UnsafeCommunityServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to CommunityServiceServer will
// result in compilation errors.
type UnsafeCommunityServiceServer interface {
mustEmbedUnimplementedCommunityServiceServer()
}
func RegisterCommunityServiceServer(s grpc.ServiceRegistrar, srv CommunityServiceServer) {
// If the following call panics, it indicates UnimplementedCommunityServiceServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&CommunityService_ServiceDesc, srv)
}
func _CommunityService_AddCommentLikes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(AddCommentLikesReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).AddCommentLikes(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_AddCommentLikes_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).AddCommentLikes(ctx, req.(*AddCommentLikesReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_UpdateCommentLikes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdateCommentLikesReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).UpdateCommentLikes(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_UpdateCommentLikes_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).UpdateCommentLikes(ctx, req.(*UpdateCommentLikesReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_DelCommentLikes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DelCommentLikesReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).DelCommentLikes(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_DelCommentLikes_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).DelCommentLikes(ctx, req.(*DelCommentLikesReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_GetCommentLikesById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetCommentLikesByIdReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).GetCommentLikesById(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_GetCommentLikesById_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).GetCommentLikesById(ctx, req.(*GetCommentLikesByIdReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_SearchCommentLikes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SearchCommentLikesReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).SearchCommentLikes(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_SearchCommentLikes_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).SearchCommentLikes(ctx, req.(*SearchCommentLikesReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_AddComments_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(AddCommentsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).AddComments(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_AddComments_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).AddComments(ctx, req.(*AddCommentsReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_UpdateComments_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdateCommentsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).UpdateComments(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_UpdateComments_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).UpdateComments(ctx, req.(*UpdateCommentsReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_DelComments_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DelCommentsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).DelComments(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_DelComments_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).DelComments(ctx, req.(*DelCommentsReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_GetCommentsById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetCommentsByIdReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).GetCommentsById(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_GetCommentsById_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).GetCommentsById(ctx, req.(*GetCommentsByIdReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_SearchComments_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SearchCommentsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).SearchComments(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_SearchComments_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).SearchComments(ctx, req.(*SearchCommentsReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_AddPostLikes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(AddPostLikesReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).AddPostLikes(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_AddPostLikes_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).AddPostLikes(ctx, req.(*AddPostLikesReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_UpdatePostLikes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdatePostLikesReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).UpdatePostLikes(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_UpdatePostLikes_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).UpdatePostLikes(ctx, req.(*UpdatePostLikesReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_DelPostLikes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DelPostLikesReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).DelPostLikes(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_DelPostLikes_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).DelPostLikes(ctx, req.(*DelPostLikesReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_GetPostLikesById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetPostLikesByIdReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).GetPostLikesById(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_GetPostLikesById_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).GetPostLikesById(ctx, req.(*GetPostLikesByIdReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_SearchPostLikes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SearchPostLikesReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).SearchPostLikes(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_SearchPostLikes_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).SearchPostLikes(ctx, req.(*SearchPostLikesReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_AddPosts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(AddPostsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).AddPosts(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_AddPosts_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).AddPosts(ctx, req.(*AddPostsReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_UpdatePosts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdatePostsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).UpdatePosts(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_UpdatePosts_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).UpdatePosts(ctx, req.(*UpdatePostsReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_DelPosts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DelPostsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).DelPosts(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_DelPosts_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).DelPosts(ctx, req.(*DelPostsReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_GetPostsById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetPostsByIdReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).GetPostsById(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_GetPostsById_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).GetPostsById(ctx, req.(*GetPostsByIdReq))
}
return interceptor(ctx, in, info, handler)
}
func _CommunityService_SearchPosts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SearchPostsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CommunityServiceServer).SearchPosts(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CommunityService_SearchPosts_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CommunityServiceServer).SearchPosts(ctx, req.(*SearchPostsReq))
}
return interceptor(ctx, in, info, handler)
}
// CommunityService_ServiceDesc is the grpc.ServiceDesc for CommunityService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var CommunityService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "pb.communityService",
HandlerType: (*CommunityServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "AddCommentLikes",
Handler: _CommunityService_AddCommentLikes_Handler,
},
{
MethodName: "UpdateCommentLikes",
Handler: _CommunityService_UpdateCommentLikes_Handler,
},
{
MethodName: "DelCommentLikes",
Handler: _CommunityService_DelCommentLikes_Handler,
},
{
MethodName: "GetCommentLikesById",
Handler: _CommunityService_GetCommentLikesById_Handler,
},
{
MethodName: "SearchCommentLikes",
Handler: _CommunityService_SearchCommentLikes_Handler,
},
{
MethodName: "AddComments",
Handler: _CommunityService_AddComments_Handler,
},
{
MethodName: "UpdateComments",
Handler: _CommunityService_UpdateComments_Handler,
},
{
MethodName: "DelComments",
Handler: _CommunityService_DelComments_Handler,
},
{
MethodName: "GetCommentsById",
Handler: _CommunityService_GetCommentsById_Handler,
},
{
MethodName: "SearchComments",
Handler: _CommunityService_SearchComments_Handler,
},
{
MethodName: "AddPostLikes",
Handler: _CommunityService_AddPostLikes_Handler,
},
{
MethodName: "UpdatePostLikes",
Handler: _CommunityService_UpdatePostLikes_Handler,
},
{
MethodName: "DelPostLikes",
Handler: _CommunityService_DelPostLikes_Handler,
},
{
MethodName: "GetPostLikesById",
Handler: _CommunityService_GetPostLikesById_Handler,
},
{
MethodName: "SearchPostLikes",
Handler: _CommunityService_SearchPostLikes_Handler,
},
{
MethodName: "AddPosts",
Handler: _CommunityService_AddPosts_Handler,
},
{
MethodName: "UpdatePosts",
Handler: _CommunityService_UpdatePosts_Handler,
},
{
MethodName: "DelPosts",
Handler: _CommunityService_DelPosts_Handler,
},
{
MethodName: "GetPostsById",
Handler: _CommunityService_GetPostsById_Handler,
},
{
MethodName: "SearchPosts",
Handler: _CommunityService_SearchPosts_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "community.proto",
}