Refactor: Remove deprecated gRPC service files and implement new API structure
- Deleted old gRPC service definitions in `game_grpc.pb.go` and `public.go`. - Added new API server implementations for objectstory, player, and shop services. - Introduced configuration files for new APIs in `etc/*.yaml`. - Created main entry points for each service in `objectstory.go`, `player.go`, and `shop.go`. - Removed unused user update handler and user API files. - Added utility functions for context management and HTTP header parsing. - Introduced PostgreSQL backup configuration in `backup/postgreSql.yaml`.
This commit is contained in:
@@ -0,0 +1,113 @@
|
|||||||
|
name: build-and-push-harbor
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- master
|
||||||
|
- dev
|
||||||
|
- "feature/**"
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE_NAME: st-1-example
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docker-build-push:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
image_tag: ${{ steps.vars.outputs.short_sha }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set image tags
|
||||||
|
id: vars
|
||||||
|
run: |
|
||||||
|
echo "short_sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "date_tag=$(date +%Y%m%d%H%M%S)" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Login Harbor
|
||||||
|
env:
|
||||||
|
HARBOR_REGISTRY: ${{ secrets.HARBOR_REGISTRY }}
|
||||||
|
HARBOR_USERNAME: ${{ secrets.HARBOR_USERNAME }}
|
||||||
|
HARBOR_PASSWORD: ${{ secrets.HARBOR_PASSWORD }}
|
||||||
|
run: |
|
||||||
|
echo "$HARBOR_PASSWORD" | docker login "$HARBOR_REGISTRY" -u "$HARBOR_USERNAME" --password-stdin
|
||||||
|
|
||||||
|
- name: Build image
|
||||||
|
env:
|
||||||
|
HARBOR_REGISTRY: ${{ secrets.HARBOR_REGISTRY }}
|
||||||
|
HARBOR_PROJECT: ${{ secrets.HARBOR_PROJECT }}
|
||||||
|
run: |
|
||||||
|
IMAGE="$HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME"
|
||||||
|
docker build -f Dockerfile -t "$IMAGE:${{ steps.vars.outputs.short_sha }}" -t "$IMAGE:${{ steps.vars.outputs.date_tag }}" -t "$IMAGE:latest" .
|
||||||
|
|
||||||
|
- name: Push image
|
||||||
|
env:
|
||||||
|
HARBOR_REGISTRY: ${{ secrets.HARBOR_REGISTRY }}
|
||||||
|
HARBOR_PROJECT: ${{ secrets.HARBOR_PROJECT }}
|
||||||
|
run: |
|
||||||
|
IMAGE="$HARBOR_REGISTRY/$HARBOR_PROJECT/$IMAGE_NAME"
|
||||||
|
docker push "$IMAGE:${{ steps.vars.outputs.short_sha }}"
|
||||||
|
docker push "$IMAGE:${{ steps.vars.outputs.date_tag }}"
|
||||||
|
docker push "$IMAGE:latest"
|
||||||
|
|
||||||
|
deploy-server-docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: docker-build-push
|
||||||
|
if: github.ref_name == 'main' || github.ref_name == 'master'
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup SSH key
|
||||||
|
env:
|
||||||
|
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
printf "%s" "$DEPLOY_SSH_KEY" > ~/.ssh/id_rsa
|
||||||
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
|
||||||
|
- name: Add server host key
|
||||||
|
env:
|
||||||
|
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||||
|
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
|
||||||
|
run: |
|
||||||
|
PORT="${DEPLOY_PORT:-22}"
|
||||||
|
ssh-keyscan -p "$PORT" "$DEPLOY_HOST" >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
- name: Upload compose file
|
||||||
|
env:
|
||||||
|
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||||
|
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||||||
|
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
|
||||||
|
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
|
||||||
|
run: |
|
||||||
|
PORT="${DEPLOY_PORT:-22}"
|
||||||
|
TARGET_PATH="${DEPLOY_PATH:-/opt/st-1-example}"
|
||||||
|
ssh -p "$PORT" "$DEPLOY_USER@$DEPLOY_HOST" "mkdir -p $TARGET_PATH"
|
||||||
|
scp -P "$PORT" deploy/docker/docker-compose.yml "$DEPLOY_USER@$DEPLOY_HOST:$TARGET_PATH/docker-compose.yml"
|
||||||
|
|
||||||
|
- name: Deploy on server
|
||||||
|
env:
|
||||||
|
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||||
|
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||||||
|
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
|
||||||
|
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
|
||||||
|
HARBOR_REGISTRY: ${{ secrets.HARBOR_REGISTRY }}
|
||||||
|
HARBOR_PROJECT: ${{ secrets.HARBOR_PROJECT }}
|
||||||
|
HARBOR_USERNAME: ${{ secrets.HARBOR_USERNAME }}
|
||||||
|
HARBOR_PASSWORD: ${{ secrets.HARBOR_PASSWORD }}
|
||||||
|
run: |
|
||||||
|
PORT="${DEPLOY_PORT:-22}"
|
||||||
|
TARGET_PATH="${DEPLOY_PATH:-/opt/st-1-example}"
|
||||||
|
IMAGE_TAG="${{ needs.docker-build-push.outputs.image_tag }}"
|
||||||
|
ssh -p "$PORT" "$DEPLOY_USER@$DEPLOY_HOST" "
|
||||||
|
set -e;
|
||||||
|
cd $TARGET_PATH;
|
||||||
|
echo '$HARBOR_PASSWORD' | docker login '$HARBOR_REGISTRY' -u '$HARBOR_USERNAME' --password-stdin;
|
||||||
|
HARBOR_REGISTRY='$HARBOR_REGISTRY' HARBOR_PROJECT='$HARBOR_PROJECT' IMAGE_NAME='$IMAGE_NAME' IMAGE_TAG='$IMAGE_TAG' docker compose pull;
|
||||||
|
HARBOR_REGISTRY='$HARBOR_REGISTRY' HARBOR_PROJECT='$HARBOR_PROJECT' IMAGE_NAME='$IMAGE_NAME' IMAGE_TAG='$IMAGE_TAG' docker compose up -d;
|
||||||
|
docker image prune -f;
|
||||||
|
"
|
||||||
@@ -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()
|
||||||
|
}
|
||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
-9
@@ -1,28 +1,28 @@
|
|||||||
// Code scaffolded by goctl. Safe to edit.
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
// goctl 1.9.2
|
// goctl 1.9.2
|
||||||
|
|
||||||
package user
|
package community
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"juwan-backend/app/users/api/internal/logic/user"
|
"juwan-backend/app/community/api/internal/logic/community"
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/community/api/internal/svc"
|
||||||
"juwan-backend/app/users/api/internal/types"
|
"juwan-backend/app/community/api/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 修改用户信息
|
// 获取帖子详情
|
||||||
func UpdateUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetPostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.UpdateUserInfoReq
|
var req types.PathId
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := user.NewUpdateUserInfoLogic(r.Context(), svcCtx)
|
l := community.NewGetPostLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.UpdateUserInfo(&req)
|
resp, err := l.GetPost(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
} else {
|
} else {
|
||||||
@@ -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)),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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...)
|
||||||
|
}
|
||||||
@@ -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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -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
@@ -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",
|
||||||
|
}
|
||||||
@@ -57,7 +57,7 @@ func (l *SendVerificationCodeMq) Consume(ctx context.Context, key, value string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
subject := "Your verification code"
|
subject := "Your verification code"
|
||||||
body := fmt.Sprintf("Your verification code is %s. It is valid for %d seconds. Scene: %s. RequestId: %s", code, expireIn, scene, payload.RequestID)
|
body := fmt.Sprintf("你的验证码是 %s. 该验证码有效时间 %d 秒. 用途: %s. 单号: %s", code, expireIn, scene, payload.RequestID)
|
||||||
// logx.Info("Send email to address: %s, subject: %s", emailAddr, subject)
|
// logx.Info("Send email to address: %s, subject: %s", emailAddr, subject)
|
||||||
|
|
||||||
err := l.svcCxt.MailSender.Send(ctx, mailer.Message{
|
err := l.svcCxt.MailSender.Send(ctx, mailer.Message{
|
||||||
|
|||||||
@@ -4,27 +4,29 @@
|
|||||||
package game
|
package game
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"juwan-backend/common/utils/responses"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
"juwan-backend/app/game/api/internal/logic/game"
|
"juwan-backend/app/game/api/internal/logic/game"
|
||||||
"juwan-backend/app/game/api/internal/svc"
|
"juwan-backend/app/game/api/internal/svc"
|
||||||
"juwan-backend/app/game/api/internal/types"
|
"juwan-backend/app/game/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 获取游戏详情
|
// 获取游戏详情
|
||||||
func GetGameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetGameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.EmptyResp
|
var req types.GetGameReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := game.NewGetGameLogic(r.Context(), svcCtx)
|
l := game.NewGetGameLogic(r.Context(), svcCtx)
|
||||||
resp := l.GetGame(&req)
|
resp, err := l.GetGame(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(400, err))
|
||||||
} else {
|
} else {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,16 +27,16 @@ func NewGetGameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGameLo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *GetGameLogic) GetGame(req *types.GetGameReq) (resp *types.Game) {
|
func (l *GetGameLogic) GetGame(req *types.GetGameReq) (resp *types.Game, err error) {
|
||||||
// todo: add your logic here and delete this line
|
// todo: add your logic here and delete this line
|
||||||
game, err := l.svcCtx.GameRpc.GetGamesById(l.ctx, &pb.GetGamesByIdReq{Id: req.Id})
|
game, err := l.svcCtx.GameRpc.GetGamesById(l.ctx, &pb.GetGamesByIdReq{Id: req.Id})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil, err
|
||||||
}
|
}
|
||||||
return &types.Game{
|
return &types.Game{
|
||||||
Id: game.Games.Id,
|
Id: game.Games.Id,
|
||||||
Name: game.Games.Name,
|
Name: game.Games.Name,
|
||||||
Icon: game.Games.Icon,
|
Icon: game.Games.Icon,
|
||||||
Category: game.Games.Category,
|
Category: game.Games.Category,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package game
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"juwan-backend/app/game/rpc/pb"
|
||||||
|
|
||||||
"juwan-backend/app/game/api/internal/svc"
|
"juwan-backend/app/game/api/internal/svc"
|
||||||
"juwan-backend/app/game/api/internal/types"
|
"juwan-backend/app/game/api/internal/types"
|
||||||
@@ -29,6 +30,30 @@ func NewListGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListGam
|
|||||||
|
|
||||||
func (l *ListGamesLogic) ListGames(req *types.PageReq) (resp *types.GameListResp, err error) {
|
func (l *ListGamesLogic) ListGames(req *types.PageReq) (resp *types.GameListResp, err error) {
|
||||||
// todo: add your logic here and delete this line
|
// todo: add your logic here and delete this line
|
||||||
|
all, err := l.svcCtx.GameRpc.SearchGames(l.ctx, &pb.SearchGamesReq{
|
||||||
return
|
Page: req.Offset,
|
||||||
|
Limit: req.Limit,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
list := make([]types.Game, 0, len(all.Games))
|
||||||
|
for _, v := range all.Games {
|
||||||
|
list = append(list, types.Game{
|
||||||
|
Id: v.Id,
|
||||||
|
Name: v.Name,
|
||||||
|
Icon: v.Icon,
|
||||||
|
Category: v.Category,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &types.GameListResp{
|
||||||
|
Items: list,
|
||||||
|
Meta: types.PageMeta{
|
||||||
|
Total: 0,
|
||||||
|
Offset: req.Offset + 1,
|
||||||
|
Limit: 20,
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,19 +5,19 @@ package svc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"juwan-backend/app/game/api/internal/config"
|
"juwan-backend/app/game/api/internal/config"
|
||||||
"juwan-backend/app/game/rpc/gamepublic"
|
"juwan-backend/app/game/rpc/gameservice"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/zrpc"
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
GameRpc gamepublic.GamePublic
|
GameRpc gameservice.GameService
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
GameRpc: gamepublic.NewGamePublic(zrpc.MustNewClient(c.GameRpcConf)),
|
GameRpc: gameservice.NewGameService(zrpc.MustNewClient(c.GameRpcConf)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,19 @@
|
|||||||
Name: pb.rpc
|
Name: pb.rpc
|
||||||
ListenOn: 0.0.0.0:8080
|
ListenOn: 0.0.0.0:8080
|
||||||
|
|
||||||
|
|
||||||
Prometheus:
|
Prometheus:
|
||||||
Host: 0.0.0.0
|
Host: 0.0.0.0
|
||||||
Port: 4001
|
Port: 4001
|
||||||
Path: /metrics
|
Path: /metrics
|
||||||
|
|
||||||
# tcd:
|
|
||||||
# Hosts:
|
|
||||||
# - 127.0.0.1:2379
|
|
||||||
# Key: pb.rpc
|
|
||||||
|
|
||||||
# Target: k8s://juwan/<service name>.<namespace>:8080
|
|
||||||
|
|
||||||
|
|
||||||
#DB:
|
|
||||||
# Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@game-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
|
||||||
# Slave: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@game-db-ro.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
|
||||||
|
|
||||||
DB:
|
DB:
|
||||||
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
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"
|
Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-ro.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
|
||||||
|
|
||||||
|
SnowflakeRpcConf:
|
||||||
|
Target: k8s://juwan/snowflake-svc:8080
|
||||||
|
|
||||||
CacheConf:
|
CacheConf:
|
||||||
- Host: "${REDIS_M_HOST}"
|
- Host: "${REDIS_M_HOST}"
|
||||||
Type: node
|
Type: node
|
||||||
|
|||||||
@@ -1,288 +0,0 @@
|
|||||||
// Code generated by goctl. DO NOT EDIT.
|
|
||||||
// goctl 1.9.2
|
|
||||||
// Source: game.proto
|
|
||||||
|
|
||||||
package gamepublic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"juwan-backend/app/game/rpc/pb"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/zrpc"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
AddGamesReq = pb.AddGamesReq
|
|
||||||
AddGamesResp = pb.AddGamesResp
|
|
||||||
AddPlayerServicesReq = pb.AddPlayerServicesReq
|
|
||||||
AddPlayerServicesResp = pb.AddPlayerServicesResp
|
|
||||||
AddPlayersReq = pb.AddPlayersReq
|
|
||||||
AddPlayersResp = pb.AddPlayersResp
|
|
||||||
AddShopInvitationsReq = pb.AddShopInvitationsReq
|
|
||||||
AddShopInvitationsResp = pb.AddShopInvitationsResp
|
|
||||||
AddShopPlayersReq = pb.AddShopPlayersReq
|
|
||||||
AddShopPlayersResp = pb.AddShopPlayersResp
|
|
||||||
AddShopsReq = pb.AddShopsReq
|
|
||||||
AddShopsResp = pb.AddShopsResp
|
|
||||||
DelGamesReq = pb.DelGamesReq
|
|
||||||
DelGamesResp = pb.DelGamesResp
|
|
||||||
DelPlayerServicesReq = pb.DelPlayerServicesReq
|
|
||||||
DelPlayerServicesResp = pb.DelPlayerServicesResp
|
|
||||||
DelPlayersReq = pb.DelPlayersReq
|
|
||||||
DelPlayersResp = pb.DelPlayersResp
|
|
||||||
DelShopInvitationsReq = pb.DelShopInvitationsReq
|
|
||||||
DelShopInvitationsResp = pb.DelShopInvitationsResp
|
|
||||||
DelShopPlayersReq = pb.DelShopPlayersReq
|
|
||||||
DelShopPlayersResp = pb.DelShopPlayersResp
|
|
||||||
DelShopsReq = pb.DelShopsReq
|
|
||||||
DelShopsResp = pb.DelShopsResp
|
|
||||||
Games = pb.Games
|
|
||||||
GetGamesByIdReq = pb.GetGamesByIdReq
|
|
||||||
GetGamesByIdResp = pb.GetGamesByIdResp
|
|
||||||
GetPlayerServicesByIdReq = pb.GetPlayerServicesByIdReq
|
|
||||||
GetPlayerServicesByIdResp = pb.GetPlayerServicesByIdResp
|
|
||||||
GetPlayersByIdReq = pb.GetPlayersByIdReq
|
|
||||||
GetPlayersByIdResp = pb.GetPlayersByIdResp
|
|
||||||
GetShopInvitationsByIdReq = pb.GetShopInvitationsByIdReq
|
|
||||||
GetShopInvitationsByIdResp = pb.GetShopInvitationsByIdResp
|
|
||||||
GetShopPlayersByIdReq = pb.GetShopPlayersByIdReq
|
|
||||||
GetShopPlayersByIdResp = pb.GetShopPlayersByIdResp
|
|
||||||
GetShopsByIdReq = pb.GetShopsByIdReq
|
|
||||||
GetShopsByIdResp = pb.GetShopsByIdResp
|
|
||||||
PlayerServices = pb.PlayerServices
|
|
||||||
Players = pb.Players
|
|
||||||
SearchGamesReq = pb.SearchGamesReq
|
|
||||||
SearchGamesResp = pb.SearchGamesResp
|
|
||||||
SearchPlayerServicesReq = pb.SearchPlayerServicesReq
|
|
||||||
SearchPlayerServicesResp = pb.SearchPlayerServicesResp
|
|
||||||
SearchPlayersReq = pb.SearchPlayersReq
|
|
||||||
SearchPlayersResp = pb.SearchPlayersResp
|
|
||||||
SearchShopInvitationsReq = pb.SearchShopInvitationsReq
|
|
||||||
SearchShopInvitationsResp = pb.SearchShopInvitationsResp
|
|
||||||
SearchShopPlayersReq = pb.SearchShopPlayersReq
|
|
||||||
SearchShopPlayersResp = pb.SearchShopPlayersResp
|
|
||||||
SearchShopsReq = pb.SearchShopsReq
|
|
||||||
SearchShopsResp = pb.SearchShopsResp
|
|
||||||
ShopInvitations = pb.ShopInvitations
|
|
||||||
ShopPlayers = pb.ShopPlayers
|
|
||||||
Shops = pb.Shops
|
|
||||||
UpdateGamesReq = pb.UpdateGamesReq
|
|
||||||
UpdateGamesResp = pb.UpdateGamesResp
|
|
||||||
UpdatePlayerServicesReq = pb.UpdatePlayerServicesReq
|
|
||||||
UpdatePlayerServicesResp = pb.UpdatePlayerServicesResp
|
|
||||||
UpdatePlayersReq = pb.UpdatePlayersReq
|
|
||||||
UpdatePlayersResp = pb.UpdatePlayersResp
|
|
||||||
UpdateShopInvitationsReq = pb.UpdateShopInvitationsReq
|
|
||||||
UpdateShopInvitationsResp = pb.UpdateShopInvitationsResp
|
|
||||||
UpdateShopPlayersReq = pb.UpdateShopPlayersReq
|
|
||||||
UpdateShopPlayersResp = pb.UpdateShopPlayersResp
|
|
||||||
UpdateShopsReq = pb.UpdateShopsReq
|
|
||||||
UpdateShopsResp = pb.UpdateShopsResp
|
|
||||||
|
|
||||||
GamePublic interface {
|
|
||||||
// -----------------------games-----------------------
|
|
||||||
AddGames(ctx context.Context, in *AddGamesReq, opts ...grpc.CallOption) (*AddGamesResp, error)
|
|
||||||
UpdateGames(ctx context.Context, in *UpdateGamesReq, opts ...grpc.CallOption) (*UpdateGamesResp, error)
|
|
||||||
DelGames(ctx context.Context, in *DelGamesReq, opts ...grpc.CallOption) (*DelGamesResp, error)
|
|
||||||
GetGamesById(ctx context.Context, in *GetGamesByIdReq, opts ...grpc.CallOption) (*GetGamesByIdResp, error)
|
|
||||||
SearchGames(ctx context.Context, in *SearchGamesReq, opts ...grpc.CallOption) (*SearchGamesResp, error)
|
|
||||||
// -----------------------playerServices-----------------------
|
|
||||||
AddPlayerServices(ctx context.Context, in *AddPlayerServicesReq, opts ...grpc.CallOption) (*AddPlayerServicesResp, error)
|
|
||||||
UpdatePlayerServices(ctx context.Context, in *UpdatePlayerServicesReq, opts ...grpc.CallOption) (*UpdatePlayerServicesResp, error)
|
|
||||||
DelPlayerServices(ctx context.Context, in *DelPlayerServicesReq, opts ...grpc.CallOption) (*DelPlayerServicesResp, error)
|
|
||||||
GetPlayerServicesById(ctx context.Context, in *GetPlayerServicesByIdReq, opts ...grpc.CallOption) (*GetPlayerServicesByIdResp, error)
|
|
||||||
SearchPlayerServices(ctx context.Context, in *SearchPlayerServicesReq, opts ...grpc.CallOption) (*SearchPlayerServicesResp, error)
|
|
||||||
// -----------------------players-----------------------
|
|
||||||
AddPlayers(ctx context.Context, in *AddPlayersReq, opts ...grpc.CallOption) (*AddPlayersResp, error)
|
|
||||||
UpdatePlayers(ctx context.Context, in *UpdatePlayersReq, opts ...grpc.CallOption) (*UpdatePlayersResp, error)
|
|
||||||
DelPlayers(ctx context.Context, in *DelPlayersReq, opts ...grpc.CallOption) (*DelPlayersResp, error)
|
|
||||||
GetPlayersById(ctx context.Context, in *GetPlayersByIdReq, opts ...grpc.CallOption) (*GetPlayersByIdResp, error)
|
|
||||||
SearchPlayers(ctx context.Context, in *SearchPlayersReq, opts ...grpc.CallOption) (*SearchPlayersResp, error)
|
|
||||||
// -----------------------shopInvitations-----------------------
|
|
||||||
AddShopInvitations(ctx context.Context, in *AddShopInvitationsReq, opts ...grpc.CallOption) (*AddShopInvitationsResp, error)
|
|
||||||
UpdateShopInvitations(ctx context.Context, in *UpdateShopInvitationsReq, opts ...grpc.CallOption) (*UpdateShopInvitationsResp, error)
|
|
||||||
DelShopInvitations(ctx context.Context, in *DelShopInvitationsReq, opts ...grpc.CallOption) (*DelShopInvitationsResp, error)
|
|
||||||
GetShopInvitationsById(ctx context.Context, in *GetShopInvitationsByIdReq, opts ...grpc.CallOption) (*GetShopInvitationsByIdResp, error)
|
|
||||||
SearchShopInvitations(ctx context.Context, in *SearchShopInvitationsReq, opts ...grpc.CallOption) (*SearchShopInvitationsResp, error)
|
|
||||||
// -----------------------shopPlayers-----------------------
|
|
||||||
AddShopPlayers(ctx context.Context, in *AddShopPlayersReq, opts ...grpc.CallOption) (*AddShopPlayersResp, error)
|
|
||||||
UpdateShopPlayers(ctx context.Context, in *UpdateShopPlayersReq, opts ...grpc.CallOption) (*UpdateShopPlayersResp, error)
|
|
||||||
DelShopPlayers(ctx context.Context, in *DelShopPlayersReq, opts ...grpc.CallOption) (*DelShopPlayersResp, error)
|
|
||||||
GetShopPlayersById(ctx context.Context, in *GetShopPlayersByIdReq, opts ...grpc.CallOption) (*GetShopPlayersByIdResp, error)
|
|
||||||
SearchShopPlayers(ctx context.Context, in *SearchShopPlayersReq, opts ...grpc.CallOption) (*SearchShopPlayersResp, error)
|
|
||||||
// -----------------------shops-----------------------
|
|
||||||
AddShops(ctx context.Context, in *AddShopsReq, opts ...grpc.CallOption) (*AddShopsResp, error)
|
|
||||||
UpdateShops(ctx context.Context, in *UpdateShopsReq, opts ...grpc.CallOption) (*UpdateShopsResp, error)
|
|
||||||
DelShops(ctx context.Context, in *DelShopsReq, opts ...grpc.CallOption) (*DelShopsResp, error)
|
|
||||||
GetShopsById(ctx context.Context, in *GetShopsByIdReq, opts ...grpc.CallOption) (*GetShopsByIdResp, error)
|
|
||||||
SearchShops(ctx context.Context, in *SearchShopsReq, opts ...grpc.CallOption) (*SearchShopsResp, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultGamePublic struct {
|
|
||||||
cli zrpc.Client
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewGamePublic(cli zrpc.Client) GamePublic {
|
|
||||||
return &defaultGamePublic{
|
|
||||||
cli: cli,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------games-----------------------
|
|
||||||
func (m *defaultGamePublic) AddGames(ctx context.Context, in *AddGamesReq, opts ...grpc.CallOption) (*AddGamesResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.AddGames(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) UpdateGames(ctx context.Context, in *UpdateGamesReq, opts ...grpc.CallOption) (*UpdateGamesResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.UpdateGames(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) DelGames(ctx context.Context, in *DelGamesReq, opts ...grpc.CallOption) (*DelGamesResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.DelGames(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) GetGamesById(ctx context.Context, in *GetGamesByIdReq, opts ...grpc.CallOption) (*GetGamesByIdResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.GetGamesById(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) SearchGames(ctx context.Context, in *SearchGamesReq, opts ...grpc.CallOption) (*SearchGamesResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.SearchGames(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------playerServices-----------------------
|
|
||||||
func (m *defaultGamePublic) AddPlayerServices(ctx context.Context, in *AddPlayerServicesReq, opts ...grpc.CallOption) (*AddPlayerServicesResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.AddPlayerServices(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) UpdatePlayerServices(ctx context.Context, in *UpdatePlayerServicesReq, opts ...grpc.CallOption) (*UpdatePlayerServicesResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.UpdatePlayerServices(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) DelPlayerServices(ctx context.Context, in *DelPlayerServicesReq, opts ...grpc.CallOption) (*DelPlayerServicesResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.DelPlayerServices(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) GetPlayerServicesById(ctx context.Context, in *GetPlayerServicesByIdReq, opts ...grpc.CallOption) (*GetPlayerServicesByIdResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.GetPlayerServicesById(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) SearchPlayerServices(ctx context.Context, in *SearchPlayerServicesReq, opts ...grpc.CallOption) (*SearchPlayerServicesResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.SearchPlayerServices(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------players-----------------------
|
|
||||||
func (m *defaultGamePublic) AddPlayers(ctx context.Context, in *AddPlayersReq, opts ...grpc.CallOption) (*AddPlayersResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.AddPlayers(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) UpdatePlayers(ctx context.Context, in *UpdatePlayersReq, opts ...grpc.CallOption) (*UpdatePlayersResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.UpdatePlayers(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) DelPlayers(ctx context.Context, in *DelPlayersReq, opts ...grpc.CallOption) (*DelPlayersResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.DelPlayers(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) GetPlayersById(ctx context.Context, in *GetPlayersByIdReq, opts ...grpc.CallOption) (*GetPlayersByIdResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.GetPlayersById(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) SearchPlayers(ctx context.Context, in *SearchPlayersReq, opts ...grpc.CallOption) (*SearchPlayersResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.SearchPlayers(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------shopInvitations-----------------------
|
|
||||||
func (m *defaultGamePublic) AddShopInvitations(ctx context.Context, in *AddShopInvitationsReq, opts ...grpc.CallOption) (*AddShopInvitationsResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.AddShopInvitations(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) UpdateShopInvitations(ctx context.Context, in *UpdateShopInvitationsReq, opts ...grpc.CallOption) (*UpdateShopInvitationsResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.UpdateShopInvitations(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) DelShopInvitations(ctx context.Context, in *DelShopInvitationsReq, opts ...grpc.CallOption) (*DelShopInvitationsResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.DelShopInvitations(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) GetShopInvitationsById(ctx context.Context, in *GetShopInvitationsByIdReq, opts ...grpc.CallOption) (*GetShopInvitationsByIdResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.GetShopInvitationsById(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) SearchShopInvitations(ctx context.Context, in *SearchShopInvitationsReq, opts ...grpc.CallOption) (*SearchShopInvitationsResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.SearchShopInvitations(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------shopPlayers-----------------------
|
|
||||||
func (m *defaultGamePublic) AddShopPlayers(ctx context.Context, in *AddShopPlayersReq, opts ...grpc.CallOption) (*AddShopPlayersResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.AddShopPlayers(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) UpdateShopPlayers(ctx context.Context, in *UpdateShopPlayersReq, opts ...grpc.CallOption) (*UpdateShopPlayersResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.UpdateShopPlayers(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) DelShopPlayers(ctx context.Context, in *DelShopPlayersReq, opts ...grpc.CallOption) (*DelShopPlayersResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.DelShopPlayers(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) GetShopPlayersById(ctx context.Context, in *GetShopPlayersByIdReq, opts ...grpc.CallOption) (*GetShopPlayersByIdResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.GetShopPlayersById(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) SearchShopPlayers(ctx context.Context, in *SearchShopPlayersReq, opts ...grpc.CallOption) (*SearchShopPlayersResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.SearchShopPlayers(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------shops-----------------------
|
|
||||||
func (m *defaultGamePublic) AddShops(ctx context.Context, in *AddShopsReq, opts ...grpc.CallOption) (*AddShopsResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.AddShops(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) UpdateShops(ctx context.Context, in *UpdateShopsReq, opts ...grpc.CallOption) (*UpdateShopsResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.UpdateShops(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) DelShops(ctx context.Context, in *DelShopsReq, opts ...grpc.CallOption) (*DelShopsResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.DelShops(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) GetShopsById(ctx context.Context, in *GetShopsByIdReq, opts ...grpc.CallOption) (*GetShopsByIdResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.GetShopsById(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultGamePublic) SearchShops(ctx context.Context, in *SearchShopsReq, opts ...grpc.CallOption) (*SearchShopsResp, error) {
|
|
||||||
client := pb.NewGamePublicClient(m.cli.Conn())
|
|
||||||
return client.SearchShops(ctx, in, opts...)
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
// goctl 1.9.2
|
// goctl 1.9.2
|
||||||
// Source: game.proto
|
// Source: game.proto
|
||||||
|
|
||||||
package public
|
package gameservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -26,7 +26,7 @@ type (
|
|||||||
UpdateGamesReq = pb.UpdateGamesReq
|
UpdateGamesReq = pb.UpdateGamesReq
|
||||||
UpdateGamesResp = pb.UpdateGamesResp
|
UpdateGamesResp = pb.UpdateGamesResp
|
||||||
|
|
||||||
Public interface {
|
GameService interface {
|
||||||
// -----------------------games-----------------------
|
// -----------------------games-----------------------
|
||||||
AddGames(ctx context.Context, in *AddGamesReq, opts ...grpc.CallOption) (*AddGamesResp, error)
|
AddGames(ctx context.Context, in *AddGamesReq, opts ...grpc.CallOption) (*AddGamesResp, error)
|
||||||
UpdateGames(ctx context.Context, in *UpdateGamesReq, opts ...grpc.CallOption) (*UpdateGamesResp, error)
|
UpdateGames(ctx context.Context, in *UpdateGamesReq, opts ...grpc.CallOption) (*UpdateGamesResp, error)
|
||||||
@@ -35,39 +35,39 @@ type (
|
|||||||
SearchGames(ctx context.Context, in *SearchGamesReq, opts ...grpc.CallOption) (*SearchGamesResp, error)
|
SearchGames(ctx context.Context, in *SearchGamesReq, opts ...grpc.CallOption) (*SearchGamesResp, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultPublic struct {
|
defaultGameService struct {
|
||||||
cli zrpc.Client
|
cli zrpc.Client
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewPublic(cli zrpc.Client) Public {
|
func NewGameService(cli zrpc.Client) GameService {
|
||||||
return &defaultPublic{
|
return &defaultGameService{
|
||||||
cli: cli,
|
cli: cli,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------games-----------------------
|
// -----------------------games-----------------------
|
||||||
func (m *defaultPublic) AddGames(ctx context.Context, in *AddGamesReq, opts ...grpc.CallOption) (*AddGamesResp, error) {
|
func (m *defaultGameService) AddGames(ctx context.Context, in *AddGamesReq, opts ...grpc.CallOption) (*AddGamesResp, error) {
|
||||||
client := pb.NewPublicClient(m.cli.Conn())
|
client := pb.NewGameServiceClient(m.cli.Conn())
|
||||||
return client.AddGames(ctx, in, opts...)
|
return client.AddGames(ctx, in, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultPublic) UpdateGames(ctx context.Context, in *UpdateGamesReq, opts ...grpc.CallOption) (*UpdateGamesResp, error) {
|
func (m *defaultGameService) UpdateGames(ctx context.Context, in *UpdateGamesReq, opts ...grpc.CallOption) (*UpdateGamesResp, error) {
|
||||||
client := pb.NewPublicClient(m.cli.Conn())
|
client := pb.NewGameServiceClient(m.cli.Conn())
|
||||||
return client.UpdateGames(ctx, in, opts...)
|
return client.UpdateGames(ctx, in, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultPublic) DelGames(ctx context.Context, in *DelGamesReq, opts ...grpc.CallOption) (*DelGamesResp, error) {
|
func (m *defaultGameService) DelGames(ctx context.Context, in *DelGamesReq, opts ...grpc.CallOption) (*DelGamesResp, error) {
|
||||||
client := pb.NewPublicClient(m.cli.Conn())
|
client := pb.NewGameServiceClient(m.cli.Conn())
|
||||||
return client.DelGames(ctx, in, opts...)
|
return client.DelGames(ctx, in, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultPublic) GetGamesById(ctx context.Context, in *GetGamesByIdReq, opts ...grpc.CallOption) (*GetGamesByIdResp, error) {
|
func (m *defaultGameService) GetGamesById(ctx context.Context, in *GetGamesByIdReq, opts ...grpc.CallOption) (*GetGamesByIdResp, error) {
|
||||||
client := pb.NewPublicClient(m.cli.Conn())
|
client := pb.NewGameServiceClient(m.cli.Conn())
|
||||||
return client.GetGamesById(ctx, in, opts...)
|
return client.GetGamesById(ctx, in, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultPublic) SearchGames(ctx context.Context, in *SearchGamesReq, opts ...grpc.CallOption) (*SearchGamesResp, error) {
|
func (m *defaultGameService) SearchGames(ctx context.Context, in *SearchGamesReq, opts ...grpc.CallOption) (*SearchGamesResp, error) {
|
||||||
client := pb.NewPublicClient(m.cli.Conn())
|
client := pb.NewGameServiceClient(m.cli.Conn())
|
||||||
return client.SearchGames(ctx, in, opts...)
|
return client.SearchGames(ctx, in, opts...)
|
||||||
}
|
}
|
||||||
@@ -3,9 +3,6 @@ package logic
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"juwan-backend/app/game/rpc/internal/models/games"
|
|
||||||
"juwan-backend/app/game/rpc/internal/models/predicate"
|
|
||||||
|
|
||||||
"juwan-backend/app/game/rpc/internal/svc"
|
"juwan-backend/app/game/rpc/internal/svc"
|
||||||
"juwan-backend/app/game/rpc/pb"
|
"juwan-backend/app/game/rpc/pb"
|
||||||
|
|
||||||
@@ -28,79 +25,26 @@ func NewSearchGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Searc
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *SearchGamesLogic) SearchGames(in *pb.SearchGamesReq) (*pb.SearchGamesResp, error) {
|
func (l *SearchGamesLogic) SearchGames(in *pb.SearchGamesReq) (*pb.SearchGamesResp, error) {
|
||||||
if in.Limit > 1000 {
|
if in.Page <= 0 || in.Limit <= 0 || in.Page > 1000 || in.Limit > 100 {
|
||||||
return nil, errors.New("limit too large")
|
return nil, errors.New("invalid pagination parameters")
|
||||||
}
|
}
|
||||||
|
all, err := l.svcCtx.GameModelRO.Games.Query().Limit(int(in.Limit)).Offset(int(in.Limit * (in.Page - 1))).All(l.ctx)
|
||||||
preds := make([]predicate.Games, 0, 8)
|
|
||||||
if in.IdOpt != nil {
|
|
||||||
preds = append(preds, games.IDEQ(*in.IdOpt))
|
|
||||||
} else if in.Id != 0 {
|
|
||||||
preds = append(preds, games.IDEQ(in.Id))
|
|
||||||
}
|
|
||||||
if in.NameOpt != nil {
|
|
||||||
if *in.NameOpt != "" {
|
|
||||||
preds = append(preds, games.NameContainsFold(*in.NameOpt))
|
|
||||||
}
|
|
||||||
} else if in.Name != "" {
|
|
||||||
preds = append(preds, games.NameContainsFold(in.Name))
|
|
||||||
}
|
|
||||||
if in.IconOpt != nil {
|
|
||||||
if *in.IconOpt != "" {
|
|
||||||
preds = append(preds, games.IconContainsFold(*in.IconOpt))
|
|
||||||
}
|
|
||||||
} else if in.Icon != "" {
|
|
||||||
preds = append(preds, games.IconContainsFold(in.Icon))
|
|
||||||
}
|
|
||||||
if in.CategoryOpt != nil {
|
|
||||||
if *in.CategoryOpt != "" {
|
|
||||||
preds = append(preds, games.CategoryContainsFold(*in.CategoryOpt))
|
|
||||||
}
|
|
||||||
} else if in.Category != "" {
|
|
||||||
preds = append(preds, games.CategoryContainsFold(in.Category))
|
|
||||||
}
|
|
||||||
if in.SortOrderOpt != nil {
|
|
||||||
preds = append(preds, games.SortOrderEQ(int(*in.SortOrderOpt)))
|
|
||||||
} else if in.SortOrder != 0 {
|
|
||||||
preds = append(preds, games.SortOrderEQ(int(in.SortOrder)))
|
|
||||||
}
|
|
||||||
if in.IsActiveOpt != nil {
|
|
||||||
preds = append(preds, games.IsActiveEQ(*in.IsActiveOpt))
|
|
||||||
} else if in.IsActive {
|
|
||||||
preds = append(preds, games.IsActiveEQ(true))
|
|
||||||
}
|
|
||||||
|
|
||||||
query := l.svcCtx.GameModelRO.Games.Query()
|
|
||||||
if len(preds) > 0 {
|
|
||||||
if in.MatchMode == pb.MatchMode_MATCH_MODE_AND {
|
|
||||||
query = query.Where(games.And(preds...))
|
|
||||||
} else {
|
|
||||||
query = query.Where(games.Or(preds...))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
all, err := query.
|
|
||||||
Offset(int(in.Page * in.Limit)).
|
|
||||||
Limit(int(in.Limit)).
|
|
||||||
All(l.ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Errorf("search games failed, %s", err.Error())
|
logx.Errorf("failed to query games: %v", err)
|
||||||
return nil, errors.New("search games failed")
|
return nil, errors.New("failed to query games")
|
||||||
}
|
}
|
||||||
|
|
||||||
list := make([]*pb.Games, 0, len(all))
|
list := make([]*pb.Games, 0, len(all))
|
||||||
for _, v := range all {
|
for _, v := range all {
|
||||||
temp := &pb.Games{}
|
temp := &pb.Games{}
|
||||||
err = copier.Copy(temp, &v)
|
err := copier.Copy(temp, v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Errorf("search games failed, %s", err.Error())
|
logx.Errorf("failed to copy games: %v", err)
|
||||||
continue
|
return nil, errors.New("failed to copy games")
|
||||||
}
|
}
|
||||||
temp.CreatedAt = v.CreatedAt.Unix()
|
temp.CreatedAt = v.CreatedAt.Unix()
|
||||||
temp.UpdatedAt = v.UpdatedAt.Unix()
|
temp.UpdatedAt = v.UpdatedAt.Unix()
|
||||||
list = append(list, temp)
|
list = append(list, temp)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &pb.SearchGamesResp{
|
return &pb.SearchGamesResp{
|
||||||
Games: list,
|
Games: list,
|
||||||
}, nil
|
}, nil
|
||||||
|
|||||||
@@ -2,9 +2,6 @@ package logic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"juwan-backend/app/game/rpc/internal/svc"
|
"juwan-backend/app/game/rpc/internal/svc"
|
||||||
"juwan-backend/app/game/rpc/pb"
|
"juwan-backend/app/game/rpc/pb"
|
||||||
|
|
||||||
@@ -26,60 +23,6 @@ func NewUpdateGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Updat
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *UpdateGamesLogic) UpdateGames(in *pb.UpdateGamesReq) (*pb.UpdateGamesResp, error) {
|
func (l *UpdateGamesLogic) UpdateGames(in *pb.UpdateGamesReq) (*pb.UpdateGamesResp, error) {
|
||||||
update := l.svcCtx.GameModelRW.Games.UpdateOneID(in.Id)
|
|
||||||
updated := false
|
|
||||||
|
|
||||||
if in.NameOpt != nil {
|
|
||||||
update.SetNillableName(in.NameOpt)
|
|
||||||
updated = true
|
|
||||||
} else if in.Name != "" {
|
|
||||||
update.SetName(in.Name)
|
|
||||||
updated = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if in.IconOpt != nil {
|
|
||||||
update.SetNillableIcon(in.IconOpt)
|
|
||||||
updated = true
|
|
||||||
} else if in.Icon != "" {
|
|
||||||
update.SetIcon(in.Icon)
|
|
||||||
updated = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if in.CategoryOpt != nil {
|
|
||||||
update.SetNillableCategory(in.CategoryOpt)
|
|
||||||
updated = true
|
|
||||||
} else if in.Category != "" {
|
|
||||||
update.SetCategory(in.Category)
|
|
||||||
updated = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if in.SortOrderOpt != nil {
|
|
||||||
sortOrder := int(*in.SortOrderOpt)
|
|
||||||
update.SetNillableSortOrder(&sortOrder)
|
|
||||||
updated = true
|
|
||||||
} else if in.SortOrder != 0 {
|
|
||||||
sortOrder := int(in.SortOrder)
|
|
||||||
update.SetSortOrder(sortOrder)
|
|
||||||
updated = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if in.IsActiveOpt != nil {
|
|
||||||
update.SetNillableIsActive(in.IsActiveOpt)
|
|
||||||
updated = true
|
|
||||||
} else if in.IsActive {
|
|
||||||
update.SetIsActive(true)
|
|
||||||
updated = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if !updated {
|
|
||||||
return nil, errors.New("no fields to update")
|
|
||||||
}
|
|
||||||
|
|
||||||
update.SetUpdatedAt(time.Now())
|
|
||||||
if err := update.Exec(l.ctx); err != nil {
|
|
||||||
logx.WithContext(l.ctx).Errorf("UpdateGamesLogic err: %v", err)
|
|
||||||
return nil, errors.New("update games failed")
|
|
||||||
}
|
|
||||||
|
|
||||||
return &pb.UpdateGamesResp{}, nil
|
return &pb.UpdateGamesResp{}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,341 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/migrate"
|
||||||
|
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/games"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Client is the client that holds all ent builders.
|
||||||
|
type Client struct {
|
||||||
|
config
|
||||||
|
// Schema is the client for creating, migrating and dropping schema.
|
||||||
|
Schema *migrate.Schema
|
||||||
|
// Games is the client for interacting with the Games builders.
|
||||||
|
Games *GamesClient
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient creates a new client configured with the given options.
|
||||||
|
func NewClient(opts ...Option) *Client {
|
||||||
|
client := &Client{config: newConfig(opts...)}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) init() {
|
||||||
|
c.Schema = migrate.NewSchema(c.driver)
|
||||||
|
c.Games = NewGamesClient(c.config)
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// config is the configuration for the client and its builder.
|
||||||
|
config struct {
|
||||||
|
// driver used for executing database requests.
|
||||||
|
driver dialect.Driver
|
||||||
|
// debug enable a debug logging.
|
||||||
|
debug bool
|
||||||
|
// log used for logging on debug mode.
|
||||||
|
log func(...any)
|
||||||
|
// hooks to execute on mutations.
|
||||||
|
hooks *hooks
|
||||||
|
// interceptors to execute on queries.
|
||||||
|
inters *inters
|
||||||
|
}
|
||||||
|
// Option function to configure the client.
|
||||||
|
Option func(*config)
|
||||||
|
)
|
||||||
|
|
||||||
|
// newConfig creates a new config for the client.
|
||||||
|
func newConfig(opts ...Option) config {
|
||||||
|
cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
|
||||||
|
cfg.options(opts...)
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
|
|
||||||
|
// options applies the options on the config object.
|
||||||
|
func (c *config) options(opts ...Option) {
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(c)
|
||||||
|
}
|
||||||
|
if c.debug {
|
||||||
|
c.driver = dialect.Debug(c.driver, c.log)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug enables debug logging on the ent.Driver.
|
||||||
|
func Debug() Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.debug = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log sets the logging function for debug mode.
|
||||||
|
func Log(fn func(...any)) Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.log = fn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Driver configures the client driver.
|
||||||
|
func Driver(driver dialect.Driver) Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.driver = driver
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open opens a database/sql.DB specified by the driver name and
|
||||||
|
// the data source name, and returns a new client attached to it.
|
||||||
|
// Optional parameters can be added for configuring the client.
|
||||||
|
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
|
||||||
|
switch driverName {
|
||||||
|
case dialect.MySQL, dialect.Postgres, dialect.SQLite:
|
||||||
|
drv, err := sql.Open(driverName, dataSourceName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return NewClient(append(options, Driver(drv))...), nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unsupported driver: %q", driverName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrTxStarted is returned when trying to start a new transaction from a transactional client.
|
||||||
|
var ErrTxStarted = errors.New("models: cannot start a transaction within a transaction")
|
||||||
|
|
||||||
|
// Tx returns a new transactional client. The provided context
|
||||||
|
// is used until the transaction is committed or rolled back.
|
||||||
|
func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||||
|
if _, ok := c.driver.(*txDriver); ok {
|
||||||
|
return nil, ErrTxStarted
|
||||||
|
}
|
||||||
|
tx, err := newTx(ctx, c.driver)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("models: starting a transaction: %w", err)
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = tx
|
||||||
|
return &Tx{
|
||||||
|
ctx: ctx,
|
||||||
|
config: cfg,
|
||||||
|
Games: NewGamesClient(cfg),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeginTx returns a transactional client with specified options.
|
||||||
|
func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
|
||||||
|
if _, ok := c.driver.(*txDriver); ok {
|
||||||
|
return nil, errors.New("ent: cannot start a transaction within a transaction")
|
||||||
|
}
|
||||||
|
tx, err := c.driver.(interface {
|
||||||
|
BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
|
||||||
|
}).BeginTx(ctx, opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = &txDriver{tx: tx, drv: c.driver}
|
||||||
|
return &Tx{
|
||||||
|
ctx: ctx,
|
||||||
|
config: cfg,
|
||||||
|
Games: NewGamesClient(cfg),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||||
|
//
|
||||||
|
// client.Debug().
|
||||||
|
// Games.
|
||||||
|
// Query().
|
||||||
|
// Count(ctx)
|
||||||
|
func (c *Client) Debug() *Client {
|
||||||
|
if c.debug {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = dialect.Debug(c.driver, c.log)
|
||||||
|
client := &Client{config: cfg}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close closes the database connection and prevents new queries from starting.
|
||||||
|
func (c *Client) Close() error {
|
||||||
|
return c.driver.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds the mutation hooks to all the entity clients.
|
||||||
|
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||||
|
func (c *Client) Use(hooks ...Hook) {
|
||||||
|
c.Games.Use(hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds the query interceptors to all the entity clients.
|
||||||
|
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||||
|
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.Games.Intercept(interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutate implements the ent.Mutator interface.
|
||||||
|
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
switch m := m.(type) {
|
||||||
|
case *GamesMutation:
|
||||||
|
return c.Games.mutate(ctx, m)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("models: unknown mutation type %T", m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GamesClient is a client for the Games schema.
|
||||||
|
type GamesClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewGamesClient returns a client for the Games from the given config.
|
||||||
|
func NewGamesClient(c config) *GamesClient {
|
||||||
|
return &GamesClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `games.Hooks(f(g(h())))`.
|
||||||
|
func (c *GamesClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.Games = append(c.hooks.Games, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `games.Intercept(f(g(h())))`.
|
||||||
|
func (c *GamesClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.Games = append(c.inters.Games, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a Games entity.
|
||||||
|
func (c *GamesClient) Create() *GamesCreate {
|
||||||
|
mutation := newGamesMutation(c.config, OpCreate)
|
||||||
|
return &GamesCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of Games entities.
|
||||||
|
func (c *GamesClient) CreateBulk(builders ...*GamesCreate) *GamesCreateBulk {
|
||||||
|
return &GamesCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *GamesClient) MapCreateBulk(slice any, setFunc func(*GamesCreate, int)) *GamesCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &GamesCreateBulk{err: fmt.Errorf("calling to GamesClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*GamesCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &GamesCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for Games.
|
||||||
|
func (c *GamesClient) Update() *GamesUpdate {
|
||||||
|
mutation := newGamesMutation(c.config, OpUpdate)
|
||||||
|
return &GamesUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *GamesClient) UpdateOne(_m *Games) *GamesUpdateOne {
|
||||||
|
mutation := newGamesMutation(c.config, OpUpdateOne, withGames(_m))
|
||||||
|
return &GamesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *GamesClient) UpdateOneID(id int64) *GamesUpdateOne {
|
||||||
|
mutation := newGamesMutation(c.config, OpUpdateOne, withGamesID(id))
|
||||||
|
return &GamesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for Games.
|
||||||
|
func (c *GamesClient) Delete() *GamesDelete {
|
||||||
|
mutation := newGamesMutation(c.config, OpDelete)
|
||||||
|
return &GamesDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *GamesClient) DeleteOne(_m *Games) *GamesDeleteOne {
|
||||||
|
return c.DeleteOneID(_m.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *GamesClient) DeleteOneID(id int64) *GamesDeleteOne {
|
||||||
|
builder := c.Delete().Where(games.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &GamesDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for Games.
|
||||||
|
func (c *GamesClient) Query() *GamesQuery {
|
||||||
|
return &GamesQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypeGames},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a Games entity by its id.
|
||||||
|
func (c *GamesClient) Get(ctx context.Context, id int64) (*Games, error) {
|
||||||
|
return c.Query().Where(games.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *GamesClient) GetX(ctx context.Context, id int64) *Games {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *GamesClient) Hooks() []Hook {
|
||||||
|
return c.hooks.Games
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *GamesClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.Games
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *GamesClient) mutate(ctx context.Context, m *GamesMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&GamesCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&GamesUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&GamesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&GamesDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("models: unknown Games mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// hooks and interceptors per client, for fast access.
|
||||||
|
type (
|
||||||
|
hooks struct {
|
||||||
|
Games []ent.Hook
|
||||||
|
}
|
||||||
|
inters struct {
|
||||||
|
Games []ent.Interceptor
|
||||||
|
}
|
||||||
|
)
|
||||||
@@ -0,0 +1,608 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/games"
|
||||||
|
"reflect"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ent aliases to avoid import conflicts in user's code.
|
||||||
|
type (
|
||||||
|
Op = ent.Op
|
||||||
|
Hook = ent.Hook
|
||||||
|
Value = ent.Value
|
||||||
|
Query = ent.Query
|
||||||
|
QueryContext = ent.QueryContext
|
||||||
|
Querier = ent.Querier
|
||||||
|
QuerierFunc = ent.QuerierFunc
|
||||||
|
Interceptor = ent.Interceptor
|
||||||
|
InterceptFunc = ent.InterceptFunc
|
||||||
|
Traverser = ent.Traverser
|
||||||
|
TraverseFunc = ent.TraverseFunc
|
||||||
|
Policy = ent.Policy
|
||||||
|
Mutator = ent.Mutator
|
||||||
|
Mutation = ent.Mutation
|
||||||
|
MutateFunc = ent.MutateFunc
|
||||||
|
)
|
||||||
|
|
||||||
|
type clientCtxKey struct{}
|
||||||
|
|
||||||
|
// FromContext returns a Client stored inside a context, or nil if there isn't one.
|
||||||
|
func FromContext(ctx context.Context) *Client {
|
||||||
|
c, _ := ctx.Value(clientCtxKey{}).(*Client)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewContext returns a new context with the given Client attached.
|
||||||
|
func NewContext(parent context.Context, c *Client) context.Context {
|
||||||
|
return context.WithValue(parent, clientCtxKey{}, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
type txCtxKey struct{}
|
||||||
|
|
||||||
|
// TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
|
||||||
|
func TxFromContext(ctx context.Context) *Tx {
|
||||||
|
tx, _ := ctx.Value(txCtxKey{}).(*Tx)
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTxContext returns a new context with the given Tx attached.
|
||||||
|
func NewTxContext(parent context.Context, tx *Tx) context.Context {
|
||||||
|
return context.WithValue(parent, txCtxKey{}, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OrderFunc applies an ordering on the sql selector.
|
||||||
|
// Deprecated: Use Asc/Desc functions or the package builders instead.
|
||||||
|
type OrderFunc func(*sql.Selector)
|
||||||
|
|
||||||
|
var (
|
||||||
|
initCheck sync.Once
|
||||||
|
columnCheck sql.ColumnCheck
|
||||||
|
)
|
||||||
|
|
||||||
|
// checkColumn checks if the column exists in the given table.
|
||||||
|
func checkColumn(t, c string) error {
|
||||||
|
initCheck.Do(func() {
|
||||||
|
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||||
|
games.Table: games.ValidColumn,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return columnCheck(t, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asc applies the given fields in ASC order.
|
||||||
|
func Asc(fields ...string) func(*sql.Selector) {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
for _, f := range fields {
|
||||||
|
if err := checkColumn(s.TableName(), f); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("models: %w", err)})
|
||||||
|
}
|
||||||
|
s.OrderBy(sql.Asc(s.C(f)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Desc applies the given fields in DESC order.
|
||||||
|
func Desc(fields ...string) func(*sql.Selector) {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
for _, f := range fields {
|
||||||
|
if err := checkColumn(s.TableName(), f); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("models: %w", err)})
|
||||||
|
}
|
||||||
|
s.OrderBy(sql.Desc(s.C(f)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
|
||||||
|
type AggregateFunc func(*sql.Selector) string
|
||||||
|
|
||||||
|
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
|
||||||
|
//
|
||||||
|
// GroupBy(field1, field2).
|
||||||
|
// Aggregate(models.As(models.Sum(field1), "sum_field1"), (models.As(models.Sum(field2), "sum_field2")).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func As(fn AggregateFunc, end string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
return sql.As(fn(s), end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count applies the "count" aggregation function on each group.
|
||||||
|
func Count() AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
return sql.Count("*")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Max applies the "max" aggregation function on the given field of each group.
|
||||||
|
func Max(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Max(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mean applies the "mean" aggregation function on the given field of each group.
|
||||||
|
func Mean(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Avg(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Min applies the "min" aggregation function on the given field of each group.
|
||||||
|
func Min(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Min(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sum applies the "sum" aggregation function on the given field of each group.
|
||||||
|
func Sum(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Sum(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidationError returns when validating a field or edge fails.
|
||||||
|
type ValidationError struct {
|
||||||
|
Name string // Field or edge name.
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *ValidationError) Error() string {
|
||||||
|
return e.err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap implements the errors.Wrapper interface.
|
||||||
|
func (e *ValidationError) Unwrap() error {
|
||||||
|
return e.err
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValidationError returns a boolean indicating whether the error is a validation error.
|
||||||
|
func IsValidationError(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *ValidationError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
|
||||||
|
type NotFoundError struct {
|
||||||
|
label string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotFoundError) Error() string {
|
||||||
|
return "models: " + e.label + " not found"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||||
|
func IsNotFound(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotFoundError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaskNotFound masks not found error.
|
||||||
|
func MaskNotFound(err error) error {
|
||||||
|
if IsNotFound(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
|
||||||
|
type NotSingularError struct {
|
||||||
|
label string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotSingularError) Error() string {
|
||||||
|
return "models: " + e.label + " not singular"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||||
|
func IsNotSingular(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotSingularError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotLoadedError returns when trying to get a node that was not loaded by the query.
|
||||||
|
type NotLoadedError struct {
|
||||||
|
edge string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotLoadedError) Error() string {
|
||||||
|
return "models: " + e.edge + " edge was not loaded"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||||
|
func IsNotLoaded(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotLoadedError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConstraintError returns when trying to create/update one or more entities and
|
||||||
|
// one or more of their constraints failed. For example, violation of edge or
|
||||||
|
// field uniqueness.
|
||||||
|
type ConstraintError struct {
|
||||||
|
msg string
|
||||||
|
wrap error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e ConstraintError) Error() string {
|
||||||
|
return "models: constraint failed: " + e.msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap implements the errors.Wrapper interface.
|
||||||
|
func (e *ConstraintError) Unwrap() error {
|
||||||
|
return e.wrap
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||||
|
func IsConstraintError(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *ConstraintError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// selector embedded by the different Select/GroupBy builders.
|
||||||
|
type selector struct {
|
||||||
|
label string
|
||||||
|
flds *[]string
|
||||||
|
fns []AggregateFunc
|
||||||
|
scan func(context.Context, any) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScanX is like Scan, but panics if an error occurs.
|
||||||
|
func (s *selector) ScanX(ctx context.Context, v any) {
|
||||||
|
if err := s.scan(ctx, v); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Strings(ctx context.Context) ([]string, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("models: Strings is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []string
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringsX is like Strings, but panics if an error occurs.
|
||||||
|
func (s *selector) StringsX(ctx context.Context) []string {
|
||||||
|
v, err := s.Strings(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a single string from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) String(ctx context.Context) (_ string, err error) {
|
||||||
|
var v []string
|
||||||
|
if v, err = s.Strings(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("models: Strings returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringX is like String, but panics if an error occurs.
|
||||||
|
func (s *selector) StringX(ctx context.Context) string {
|
||||||
|
v, err := s.String(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Ints(ctx context.Context) ([]int, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("models: Ints is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []int
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntsX is like Ints, but panics if an error occurs.
|
||||||
|
func (s *selector) IntsX(ctx context.Context) []int {
|
||||||
|
v, err := s.Ints(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int returns a single int from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Int(ctx context.Context) (_ int, err error) {
|
||||||
|
var v []int
|
||||||
|
if v, err = s.Ints(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("models: Ints returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntX is like Int, but panics if an error occurs.
|
||||||
|
func (s *selector) IntX(ctx context.Context) int {
|
||||||
|
v, err := s.Int(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Float64s(ctx context.Context) ([]float64, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("models: Float64s is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []float64
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64sX is like Float64s, but panics if an error occurs.
|
||||||
|
func (s *selector) Float64sX(ctx context.Context) []float64 {
|
||||||
|
v, err := s.Float64s(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Float64(ctx context.Context) (_ float64, err error) {
|
||||||
|
var v []float64
|
||||||
|
if v, err = s.Float64s(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("models: Float64s returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64X is like Float64, but panics if an error occurs.
|
||||||
|
func (s *selector) Float64X(ctx context.Context) float64 {
|
||||||
|
v, err := s.Float64(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Bools(ctx context.Context) ([]bool, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("models: Bools is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []bool
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolsX is like Bools, but panics if an error occurs.
|
||||||
|
func (s *selector) BoolsX(ctx context.Context) []bool {
|
||||||
|
v, err := s.Bools(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Bool(ctx context.Context) (_ bool, err error) {
|
||||||
|
var v []bool
|
||||||
|
if v, err = s.Bools(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("models: Bools returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolX is like Bool, but panics if an error occurs.
|
||||||
|
func (s *selector) BoolX(ctx context.Context) bool {
|
||||||
|
v, err := s.Bool(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// withHooks invokes the builder operation with the given hooks, if any.
|
||||||
|
func withHooks[V Value, M any, PM interface {
|
||||||
|
*M
|
||||||
|
Mutation
|
||||||
|
}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) {
|
||||||
|
if len(hooks) == 0 {
|
||||||
|
return exec(ctx)
|
||||||
|
}
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutationT, ok := any(m).(PM)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
// Set the mutation to the builder.
|
||||||
|
*mutation = *mutationT
|
||||||
|
return exec(ctx)
|
||||||
|
})
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
if hooks[i] == nil {
|
||||||
|
return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = hooks[i](mut)
|
||||||
|
}
|
||||||
|
v, err := mut.Mutate(ctx, mutation)
|
||||||
|
if err != nil {
|
||||||
|
return value, err
|
||||||
|
}
|
||||||
|
nv, ok := v.(V)
|
||||||
|
if !ok {
|
||||||
|
return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation)
|
||||||
|
}
|
||||||
|
return nv, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist.
|
||||||
|
func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context {
|
||||||
|
if ent.QueryFromContext(ctx) == nil {
|
||||||
|
qc.Op = op
|
||||||
|
ctx = ent.NewQueryContext(ctx, qc)
|
||||||
|
}
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
func querierAll[V Value, Q interface {
|
||||||
|
sqlAll(context.Context, ...queryHook) (V, error)
|
||||||
|
}]() Querier {
|
||||||
|
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
return query.sqlAll(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func querierCount[Q interface {
|
||||||
|
sqlCount(context.Context) (int, error)
|
||||||
|
}]() Querier {
|
||||||
|
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
return query.sqlCount(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) {
|
||||||
|
for i := len(inters) - 1; i >= 0; i-- {
|
||||||
|
qr = inters[i].Intercept(qr)
|
||||||
|
}
|
||||||
|
rv, err := qr.Query(ctx, q)
|
||||||
|
if err != nil {
|
||||||
|
return v, err
|
||||||
|
}
|
||||||
|
vt, ok := rv.(V)
|
||||||
|
if !ok {
|
||||||
|
return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v)
|
||||||
|
}
|
||||||
|
return vt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func scanWithInterceptors[Q1 ent.Query, Q2 interface {
|
||||||
|
sqlScan(context.Context, Q1, any) error
|
||||||
|
}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error {
|
||||||
|
rv := reflect.ValueOf(v)
|
||||||
|
var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q1)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
if err := selectOrGroup.sqlScan(ctx, query, v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() {
|
||||||
|
return rv.Elem().Interface(), nil
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
})
|
||||||
|
for i := len(inters) - 1; i >= 0; i-- {
|
||||||
|
qr = inters[i].Intercept(qr)
|
||||||
|
}
|
||||||
|
vv, err := qr.Query(ctx, rootQuery)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
switch rv2 := reflect.ValueOf(vv); {
|
||||||
|
case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer:
|
||||||
|
case rv.Type() == rv2.Type():
|
||||||
|
rv.Elem().Set(rv2.Elem())
|
||||||
|
case rv.Elem().Type() == rv2.Type():
|
||||||
|
rv.Elem().Set(rv2)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// queryHook describes an internal hook for the different sqlAll methods.
|
||||||
|
type queryHook func(context.Context, *sqlgraph.QuerySpec)
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package enttest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/game/rpc/internal/models"
|
||||||
|
// required by schema hooks.
|
||||||
|
_ "juwan-backend/app/game/rpc/internal/models/runtime"
|
||||||
|
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/migrate"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// TestingT is the interface that is shared between
|
||||||
|
// testing.T and testing.B and used by enttest.
|
||||||
|
TestingT interface {
|
||||||
|
FailNow()
|
||||||
|
Error(...any)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Option configures client creation.
|
||||||
|
Option func(*options)
|
||||||
|
|
||||||
|
options struct {
|
||||||
|
opts []models.Option
|
||||||
|
migrateOpts []schema.MigrateOption
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// WithOptions forwards options to client creation.
|
||||||
|
func WithOptions(opts ...models.Option) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.opts = append(o.opts, opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithMigrateOptions forwards options to auto migration.
|
||||||
|
func WithMigrateOptions(opts ...schema.MigrateOption) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.migrateOpts = append(o.migrateOpts, opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newOptions(opts []Option) *options {
|
||||||
|
o := &options{}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(o)
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open calls models.Open and auto-run migration.
|
||||||
|
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *models.Client {
|
||||||
|
o := newOptions(opts)
|
||||||
|
c, err := models.Open(driverName, dataSourceName, o.opts...)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
migrateSchema(t, c, o)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient calls models.NewClient and auto-run migration.
|
||||||
|
func NewClient(t TestingT, opts ...Option) *models.Client {
|
||||||
|
o := newOptions(opts)
|
||||||
|
c := models.NewClient(o.opts...)
|
||||||
|
migrateSchema(t, c, o)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
func migrateSchema(t TestingT, c *models.Client, o *options) {
|
||||||
|
tables, err := schema.CopyTables(migrate.Tables)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,174 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/games"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Games is the model entity for the Games schema.
|
||||||
|
type Games struct {
|
||||||
|
config `json:"-"`
|
||||||
|
// ID of the ent.
|
||||||
|
ID int64 `json:"id,omitempty"`
|
||||||
|
// Name holds the value of the "name" field.
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
// Icon holds the value of the "icon" field.
|
||||||
|
Icon string `json:"icon,omitempty"`
|
||||||
|
// Category holds the value of the "category" field.
|
||||||
|
Category string `json:"category,omitempty"`
|
||||||
|
// SortOrder holds the value of the "sort_order" field.
|
||||||
|
SortOrder int `json:"sort_order,omitempty"`
|
||||||
|
// IsActive holds the value of the "is_active" field.
|
||||||
|
IsActive bool `json:"is_active,omitempty"`
|
||||||
|
// CreatedAt holds the value of the "created_at" field.
|
||||||
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||||
|
selectValues sql.SelectValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*Games) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case games.FieldIsActive:
|
||||||
|
values[i] = new(sql.NullBool)
|
||||||
|
case games.FieldID, games.FieldSortOrder:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case games.FieldName, games.FieldIcon, games.FieldCategory:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case games.FieldCreatedAt, games.FieldUpdatedAt:
|
||||||
|
values[i] = new(sql.NullTime)
|
||||||
|
default:
|
||||||
|
values[i] = new(sql.UnknownType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the Games fields.
|
||||||
|
func (_m *Games) assignValues(columns []string, values []any) error {
|
||||||
|
if m, n := len(values), len(columns); m < n {
|
||||||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||||
|
}
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case games.FieldID:
|
||||||
|
value, ok := values[i].(*sql.NullInt64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||||||
|
}
|
||||||
|
_m.ID = int64(value.Int64)
|
||||||
|
case games.FieldName:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Name = value.String
|
||||||
|
}
|
||||||
|
case games.FieldIcon:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field icon", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Icon = value.String
|
||||||
|
}
|
||||||
|
case games.FieldCategory:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field category", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Category = value.String
|
||||||
|
}
|
||||||
|
case games.FieldSortOrder:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field sort_order", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.SortOrder = int(value.Int64)
|
||||||
|
}
|
||||||
|
case games.FieldIsActive:
|
||||||
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field is_active", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.IsActive = value.Bool
|
||||||
|
}
|
||||||
|
case games.FieldCreatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.CreatedAt = value.Time
|
||||||
|
}
|
||||||
|
case games.FieldUpdatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.UpdatedAt = value.Time
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
_m.selectValues.Set(columns[i], values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the Games.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (_m *Games) Value(name string) (ent.Value, error) {
|
||||||
|
return _m.selectValues.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this Games.
|
||||||
|
// Note that you need to call Games.Unwrap() before calling this method if this Games
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (_m *Games) Update() *GamesUpdateOne {
|
||||||
|
return NewGamesClient(_m.config).UpdateOne(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the Games entity that was returned from a transaction after it was closed,
|
||||||
|
// so that all future queries will be executed through the driver which created the transaction.
|
||||||
|
func (_m *Games) Unwrap() *Games {
|
||||||
|
_tx, ok := _m.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("models: Games is not a transactional entity")
|
||||||
|
}
|
||||||
|
_m.config.driver = _tx.drv
|
||||||
|
return _m
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (_m *Games) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("Games(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||||
|
builder.WriteString("name=")
|
||||||
|
builder.WriteString(_m.Name)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("icon=")
|
||||||
|
builder.WriteString(_m.Icon)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("category=")
|
||||||
|
builder.WriteString(_m.Category)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("sort_order=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.SortOrder))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("is_active=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.IsActive))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("created_at=")
|
||||||
|
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("updated_at=")
|
||||||
|
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// GamesSlice is a parsable slice of Games.
|
||||||
|
type GamesSlice []*Games
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package games
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the games type in the database.
|
||||||
|
Label = "games"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldName holds the string denoting the name field in the database.
|
||||||
|
FieldName = "name"
|
||||||
|
// FieldIcon holds the string denoting the icon field in the database.
|
||||||
|
FieldIcon = "icon"
|
||||||
|
// FieldCategory holds the string denoting the category field in the database.
|
||||||
|
FieldCategory = "category"
|
||||||
|
// FieldSortOrder holds the string denoting the sort_order field in the database.
|
||||||
|
FieldSortOrder = "sort_order"
|
||||||
|
// FieldIsActive holds the string denoting the is_active field in the database.
|
||||||
|
FieldIsActive = "is_active"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// Table holds the table name of the games in the database.
|
||||||
|
Table = "games"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for games fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldName,
|
||||||
|
FieldIcon,
|
||||||
|
FieldCategory,
|
||||||
|
FieldSortOrder,
|
||||||
|
FieldIsActive,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// NameValidator is a validator for the "name" field. It is called by the builders before save.
|
||||||
|
NameValidator func(string) error
|
||||||
|
// CategoryValidator is a validator for the "category" field. It is called by the builders before save.
|
||||||
|
CategoryValidator func(string) error
|
||||||
|
// DefaultSortOrder holds the default value on creation for the "sort_order" field.
|
||||||
|
DefaultSortOrder int
|
||||||
|
// DefaultIsActive holds the default value on creation for the "is_active" field.
|
||||||
|
DefaultIsActive bool
|
||||||
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
|
DefaultCreatedAt func() time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt func() time.Time
|
||||||
|
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||||
|
UpdateDefaultUpdatedAt func() time.Time
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the Games queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByName orders the results by the name field.
|
||||||
|
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByIcon orders the results by the icon field.
|
||||||
|
func ByIcon(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldIcon, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCategory orders the results by the category field.
|
||||||
|
func ByCategory(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCategory, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// BySortOrder orders the results by the sort_order field.
|
||||||
|
func BySortOrder(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldSortOrder, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByIsActive orders the results by the is_active field.
|
||||||
|
func ByIsActive(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldIsActive, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdatedAt orders the results by the updated_at field.
|
||||||
|
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
@@ -0,0 +1,440 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package games
|
||||||
|
|
||||||
|
import (
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/predicate"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int64) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int64) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int64) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int64) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int64) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int64) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int64) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int64) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int64) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||||
|
func Name(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Icon applies equality check predicate on the "icon" field. It's identical to IconEQ.
|
||||||
|
func Icon(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEQ(FieldIcon, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Category applies equality check predicate on the "category" field. It's identical to CategoryEQ.
|
||||||
|
func Category(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEQ(FieldCategory, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SortOrder applies equality check predicate on the "sort_order" field. It's identical to SortOrderEQ.
|
||||||
|
func SortOrder(v int) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEQ(FieldSortOrder, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsActive applies equality check predicate on the "is_active" field. It's identical to IsActiveEQ.
|
||||||
|
func IsActive(v bool) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEQ(FieldIsActive, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
|
func CreatedAt(v time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||||
|
func UpdatedAt(v time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameEQ applies the EQ predicate on the "name" field.
|
||||||
|
func NameEQ(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||||
|
func NameNEQ(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldNEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameIn applies the In predicate on the "name" field.
|
||||||
|
func NameIn(vs ...string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldIn(FieldName, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||||
|
func NameNotIn(vs ...string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldNotIn(FieldName, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameGT applies the GT predicate on the "name" field.
|
||||||
|
func NameGT(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldGT(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameGTE applies the GTE predicate on the "name" field.
|
||||||
|
func NameGTE(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldGTE(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameLT applies the LT predicate on the "name" field.
|
||||||
|
func NameLT(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldLT(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameLTE applies the LTE predicate on the "name" field.
|
||||||
|
func NameLTE(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldLTE(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameContains applies the Contains predicate on the "name" field.
|
||||||
|
func NameContains(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldContains(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||||
|
func NameHasPrefix(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldHasPrefix(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||||
|
func NameHasSuffix(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldHasSuffix(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||||
|
func NameEqualFold(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEqualFold(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||||
|
func NameContainsFold(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldContainsFold(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IconEQ applies the EQ predicate on the "icon" field.
|
||||||
|
func IconEQ(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEQ(FieldIcon, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IconNEQ applies the NEQ predicate on the "icon" field.
|
||||||
|
func IconNEQ(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldNEQ(FieldIcon, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IconIn applies the In predicate on the "icon" field.
|
||||||
|
func IconIn(vs ...string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldIn(FieldIcon, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IconNotIn applies the NotIn predicate on the "icon" field.
|
||||||
|
func IconNotIn(vs ...string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldNotIn(FieldIcon, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IconGT applies the GT predicate on the "icon" field.
|
||||||
|
func IconGT(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldGT(FieldIcon, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IconGTE applies the GTE predicate on the "icon" field.
|
||||||
|
func IconGTE(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldGTE(FieldIcon, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IconLT applies the LT predicate on the "icon" field.
|
||||||
|
func IconLT(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldLT(FieldIcon, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IconLTE applies the LTE predicate on the "icon" field.
|
||||||
|
func IconLTE(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldLTE(FieldIcon, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IconContains applies the Contains predicate on the "icon" field.
|
||||||
|
func IconContains(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldContains(FieldIcon, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IconHasPrefix applies the HasPrefix predicate on the "icon" field.
|
||||||
|
func IconHasPrefix(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldHasPrefix(FieldIcon, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IconHasSuffix applies the HasSuffix predicate on the "icon" field.
|
||||||
|
func IconHasSuffix(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldHasSuffix(FieldIcon, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IconEqualFold applies the EqualFold predicate on the "icon" field.
|
||||||
|
func IconEqualFold(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEqualFold(FieldIcon, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IconContainsFold applies the ContainsFold predicate on the "icon" field.
|
||||||
|
func IconContainsFold(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldContainsFold(FieldIcon, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryEQ applies the EQ predicate on the "category" field.
|
||||||
|
func CategoryEQ(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEQ(FieldCategory, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryNEQ applies the NEQ predicate on the "category" field.
|
||||||
|
func CategoryNEQ(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldNEQ(FieldCategory, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryIn applies the In predicate on the "category" field.
|
||||||
|
func CategoryIn(vs ...string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldIn(FieldCategory, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryNotIn applies the NotIn predicate on the "category" field.
|
||||||
|
func CategoryNotIn(vs ...string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldNotIn(FieldCategory, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryGT applies the GT predicate on the "category" field.
|
||||||
|
func CategoryGT(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldGT(FieldCategory, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryGTE applies the GTE predicate on the "category" field.
|
||||||
|
func CategoryGTE(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldGTE(FieldCategory, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryLT applies the LT predicate on the "category" field.
|
||||||
|
func CategoryLT(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldLT(FieldCategory, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryLTE applies the LTE predicate on the "category" field.
|
||||||
|
func CategoryLTE(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldLTE(FieldCategory, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryContains applies the Contains predicate on the "category" field.
|
||||||
|
func CategoryContains(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldContains(FieldCategory, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryHasPrefix applies the HasPrefix predicate on the "category" field.
|
||||||
|
func CategoryHasPrefix(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldHasPrefix(FieldCategory, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryHasSuffix applies the HasSuffix predicate on the "category" field.
|
||||||
|
func CategoryHasSuffix(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldHasSuffix(FieldCategory, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryEqualFold applies the EqualFold predicate on the "category" field.
|
||||||
|
func CategoryEqualFold(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEqualFold(FieldCategory, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryContainsFold applies the ContainsFold predicate on the "category" field.
|
||||||
|
func CategoryContainsFold(v string) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldContainsFold(FieldCategory, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SortOrderEQ applies the EQ predicate on the "sort_order" field.
|
||||||
|
func SortOrderEQ(v int) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEQ(FieldSortOrder, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SortOrderNEQ applies the NEQ predicate on the "sort_order" field.
|
||||||
|
func SortOrderNEQ(v int) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldNEQ(FieldSortOrder, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SortOrderIn applies the In predicate on the "sort_order" field.
|
||||||
|
func SortOrderIn(vs ...int) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldIn(FieldSortOrder, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SortOrderNotIn applies the NotIn predicate on the "sort_order" field.
|
||||||
|
func SortOrderNotIn(vs ...int) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldNotIn(FieldSortOrder, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SortOrderGT applies the GT predicate on the "sort_order" field.
|
||||||
|
func SortOrderGT(v int) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldGT(FieldSortOrder, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SortOrderGTE applies the GTE predicate on the "sort_order" field.
|
||||||
|
func SortOrderGTE(v int) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldGTE(FieldSortOrder, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SortOrderLT applies the LT predicate on the "sort_order" field.
|
||||||
|
func SortOrderLT(v int) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldLT(FieldSortOrder, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SortOrderLTE applies the LTE predicate on the "sort_order" field.
|
||||||
|
func SortOrderLTE(v int) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldLTE(FieldSortOrder, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsActiveEQ applies the EQ predicate on the "is_active" field.
|
||||||
|
func IsActiveEQ(v bool) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEQ(FieldIsActive, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsActiveNEQ applies the NEQ predicate on the "is_active" field.
|
||||||
|
func IsActiveNEQ(v bool) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldNEQ(FieldIsActive, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsActiveIsNil applies the IsNil predicate on the "is_active" field.
|
||||||
|
func IsActiveIsNil() predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldIsNull(FieldIsActive))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsActiveNotNil applies the NotNil predicate on the "is_active" field.
|
||||||
|
func IsActiveNotNil() predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldNotNull(FieldIsActive))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtEQ(v time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtNEQ(v time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldNEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||||
|
func CreatedAtIn(vs ...time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotIn(vs ...time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||||
|
func CreatedAtGT(v time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldGT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtGTE(v time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldGTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||||
|
func CreatedAtLT(v time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldLT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtLTE(v time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldLTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtEQ(v time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNEQ(v time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIn(vs ...time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotIn(vs ...time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGT(v time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldGT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGTE(v time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldGTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLT(v time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldLT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLTE(v time.Time) predicate.Games {
|
||||||
|
return predicate.Games(sql.FieldLTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.Games) predicate.Games {
|
||||||
|
return predicate.Games(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.Games) predicate.Games {
|
||||||
|
return predicate.Games(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.Games) predicate.Games {
|
||||||
|
return predicate.Games(sql.NotPredicates(p))
|
||||||
|
}
|
||||||
@@ -0,0 +1,335 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/games"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GamesCreate is the builder for creating a Games entity.
|
||||||
|
type GamesCreate struct {
|
||||||
|
config
|
||||||
|
mutation *GamesMutation
|
||||||
|
hooks []Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (_c *GamesCreate) SetName(v string) *GamesCreate {
|
||||||
|
_c.mutation.SetName(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIcon sets the "icon" field.
|
||||||
|
func (_c *GamesCreate) SetIcon(v string) *GamesCreate {
|
||||||
|
_c.mutation.SetIcon(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCategory sets the "category" field.
|
||||||
|
func (_c *GamesCreate) SetCategory(v string) *GamesCreate {
|
||||||
|
_c.mutation.SetCategory(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSortOrder sets the "sort_order" field.
|
||||||
|
func (_c *GamesCreate) SetSortOrder(v int) *GamesCreate {
|
||||||
|
_c.mutation.SetSortOrder(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
|
||||||
|
func (_c *GamesCreate) SetNillableSortOrder(v *int) *GamesCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetSortOrder(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIsActive sets the "is_active" field.
|
||||||
|
func (_c *GamesCreate) SetIsActive(v bool) *GamesCreate {
|
||||||
|
_c.mutation.SetIsActive(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableIsActive sets the "is_active" field if the given value is not nil.
|
||||||
|
func (_c *GamesCreate) SetNillableIsActive(v *bool) *GamesCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetIsActive(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (_c *GamesCreate) SetCreatedAt(v time.Time) *GamesCreate {
|
||||||
|
_c.mutation.SetCreatedAt(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (_c *GamesCreate) SetNillableCreatedAt(v *time.Time) *GamesCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetCreatedAt(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_c *GamesCreate) SetUpdatedAt(v time.Time) *GamesCreate {
|
||||||
|
_c.mutation.SetUpdatedAt(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||||
|
func (_c *GamesCreate) SetNillableUpdatedAt(v *time.Time) *GamesCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetUpdatedAt(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the "id" field.
|
||||||
|
func (_c *GamesCreate) SetID(v int64) *GamesCreate {
|
||||||
|
_c.mutation.SetID(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the GamesMutation object of the builder.
|
||||||
|
func (_c *GamesCreate) Mutation() *GamesMutation {
|
||||||
|
return _c.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Games in the database.
|
||||||
|
func (_c *GamesCreate) Save(ctx context.Context) (*Games, error) {
|
||||||
|
_c.defaults()
|
||||||
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (_c *GamesCreate) SaveX(ctx context.Context) *Games {
|
||||||
|
v, err := _c.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_c *GamesCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := _c.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_c *GamesCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := _c.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (_c *GamesCreate) defaults() {
|
||||||
|
if _, ok := _c.mutation.SortOrder(); !ok {
|
||||||
|
v := games.DefaultSortOrder
|
||||||
|
_c.mutation.SetSortOrder(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.IsActive(); !ok {
|
||||||
|
v := games.DefaultIsActive
|
||||||
|
_c.mutation.SetIsActive(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||||
|
v := games.DefaultCreatedAt()
|
||||||
|
_c.mutation.SetCreatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||||
|
v := games.DefaultUpdatedAt()
|
||||||
|
_c.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_c *GamesCreate) check() error {
|
||||||
|
if _, ok := _c.mutation.Name(); !ok {
|
||||||
|
return &ValidationError{Name: "name", err: errors.New(`models: missing required field "Games.name"`)}
|
||||||
|
}
|
||||||
|
if v, ok := _c.mutation.Name(); ok {
|
||||||
|
if err := games.NameValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "name", err: fmt.Errorf(`models: validator failed for field "Games.name": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.Icon(); !ok {
|
||||||
|
return &ValidationError{Name: "icon", err: errors.New(`models: missing required field "Games.icon"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.Category(); !ok {
|
||||||
|
return &ValidationError{Name: "category", err: errors.New(`models: missing required field "Games.category"`)}
|
||||||
|
}
|
||||||
|
if v, ok := _c.mutation.Category(); ok {
|
||||||
|
if err := games.CategoryValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "category", err: fmt.Errorf(`models: validator failed for field "Games.category": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.SortOrder(); !ok {
|
||||||
|
return &ValidationError{Name: "sort_order", err: errors.New(`models: missing required field "Games.sort_order"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "created_at", err: errors.New(`models: missing required field "Games.created_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "updated_at", err: errors.New(`models: missing required field "Games.updated_at"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_c *GamesCreate) sqlSave(ctx context.Context) (*Games, error) {
|
||||||
|
if err := _c.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_node, _spec := _c.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if _spec.ID.Value != _node.ID {
|
||||||
|
id := _spec.ID.Value.(int64)
|
||||||
|
_node.ID = int64(id)
|
||||||
|
}
|
||||||
|
_c.mutation.id = &_node.ID
|
||||||
|
_c.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_c *GamesCreate) createSpec() (*Games, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &Games{config: _c.config}
|
||||||
|
_spec = sqlgraph.NewCreateSpec(games.Table, sqlgraph.NewFieldSpec(games.FieldID, field.TypeInt64))
|
||||||
|
)
|
||||||
|
if id, ok := _c.mutation.ID(); ok {
|
||||||
|
_node.ID = id
|
||||||
|
_spec.ID.Value = id
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.Name(); ok {
|
||||||
|
_spec.SetField(games.FieldName, field.TypeString, value)
|
||||||
|
_node.Name = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.Icon(); ok {
|
||||||
|
_spec.SetField(games.FieldIcon, field.TypeString, value)
|
||||||
|
_node.Icon = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.Category(); ok {
|
||||||
|
_spec.SetField(games.FieldCategory, field.TypeString, value)
|
||||||
|
_node.Category = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.SortOrder(); ok {
|
||||||
|
_spec.SetField(games.FieldSortOrder, field.TypeInt, value)
|
||||||
|
_node.SortOrder = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.IsActive(); ok {
|
||||||
|
_spec.SetField(games.FieldIsActive, field.TypeBool, value)
|
||||||
|
_node.IsActive = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(games.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
_node.CreatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(games.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
_node.UpdatedAt = value
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// GamesCreateBulk is the builder for creating many Games entities in bulk.
|
||||||
|
type GamesCreateBulk struct {
|
||||||
|
config
|
||||||
|
err error
|
||||||
|
builders []*GamesCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Games entities in the database.
|
||||||
|
func (_c *GamesCreateBulk) Save(ctx context.Context) ([]*Games, error) {
|
||||||
|
if _c.err != nil {
|
||||||
|
return nil, _c.err
|
||||||
|
}
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||||
|
nodes := make([]*Games, len(_c.builders))
|
||||||
|
mutators := make([]Mutator, len(_c.builders))
|
||||||
|
for i := range _c.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := _c.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*GamesMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
var err error
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||||
|
} else {
|
||||||
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||||
|
// Invoke the actual operation on the latest mutation in the chain.
|
||||||
|
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
|
||||||
|
id := specs[i].ID.Value.(int64)
|
||||||
|
nodes[i].ID = int64(id)
|
||||||
|
}
|
||||||
|
mutation.done = true
|
||||||
|
return nodes[i], nil
|
||||||
|
})
|
||||||
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||||
|
mut = builder.hooks[i](mut)
|
||||||
|
}
|
||||||
|
mutators[i] = mut
|
||||||
|
}(i, ctx)
|
||||||
|
}
|
||||||
|
if len(mutators) > 0 {
|
||||||
|
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_c *GamesCreateBulk) SaveX(ctx context.Context) []*Games {
|
||||||
|
v, err := _c.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_c *GamesCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := _c.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_c *GamesCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := _c.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/games"
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/predicate"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GamesDelete is the builder for deleting a Games entity.
|
||||||
|
type GamesDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *GamesMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the GamesDelete builder.
|
||||||
|
func (_d *GamesDelete) Where(ps ...predicate.Games) *GamesDelete {
|
||||||
|
_d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (_d *GamesDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_d *GamesDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := _d.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_d *GamesDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(games.Table, sqlgraph.NewFieldSpec(games.FieldID, field.TypeInt64))
|
||||||
|
if ps := _d.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||||
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
_d.mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GamesDeleteOne is the builder for deleting a single Games entity.
|
||||||
|
type GamesDeleteOne struct {
|
||||||
|
_d *GamesDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the GamesDelete builder.
|
||||||
|
func (_d *GamesDeleteOne) Where(ps ...predicate.Games) *GamesDeleteOne {
|
||||||
|
_d._d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (_d *GamesDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := _d._d.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{games.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_d *GamesDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := _d.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,527 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/games"
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/predicate"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GamesQuery is the builder for querying Games entities.
|
||||||
|
type GamesQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []games.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.Games
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the GamesQuery builder.
|
||||||
|
func (_q *GamesQuery) Where(ps ...predicate.Games) *GamesQuery {
|
||||||
|
_q.predicates = append(_q.predicates, ps...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (_q *GamesQuery) Limit(limit int) *GamesQuery {
|
||||||
|
_q.ctx.Limit = &limit
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (_q *GamesQuery) Offset(offset int) *GamesQuery {
|
||||||
|
_q.ctx.Offset = &offset
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unique configures the query builder to filter duplicate records on query.
|
||||||
|
// By default, unique is set to true, and can be disabled using this method.
|
||||||
|
func (_q *GamesQuery) Unique(unique bool) *GamesQuery {
|
||||||
|
_q.ctx.Unique = &unique
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (_q *GamesQuery) Order(o ...games.OrderOption) *GamesQuery {
|
||||||
|
_q.order = append(_q.order, o...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first Games entity from the query.
|
||||||
|
// Returns a *NotFoundError when no Games was found.
|
||||||
|
func (_q *GamesQuery) First(ctx context.Context) (*Games, error) {
|
||||||
|
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{games.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (_q *GamesQuery) FirstX(ctx context.Context) *Games {
|
||||||
|
node, err := _q.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first Games ID from the query.
|
||||||
|
// Returns a *NotFoundError when no Games ID was found.
|
||||||
|
func (_q *GamesQuery) FirstID(ctx context.Context) (id int64, err error) {
|
||||||
|
var ids []int64
|
||||||
|
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{games.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (_q *GamesQuery) FirstIDX(ctx context.Context) int64 {
|
||||||
|
id, err := _q.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single Games entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one Games entity is found.
|
||||||
|
// Returns a *NotFoundError when no Games entities are found.
|
||||||
|
func (_q *GamesQuery) Only(ctx context.Context) (*Games, error) {
|
||||||
|
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{games.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{games.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (_q *GamesQuery) OnlyX(ctx context.Context) *Games {
|
||||||
|
node, err := _q.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only Games ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one Games ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (_q *GamesQuery) OnlyID(ctx context.Context) (id int64, err error) {
|
||||||
|
var ids []int64
|
||||||
|
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{games.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{games.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (_q *GamesQuery) OnlyIDX(ctx context.Context) int64 {
|
||||||
|
id, err := _q.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of GamesSlice.
|
||||||
|
func (_q *GamesQuery) All(ctx context.Context) ([]*Games, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||||
|
if err := _q.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*Games, *GamesQuery]()
|
||||||
|
return withInterceptors[[]*Games](ctx, _q, qr, _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (_q *GamesQuery) AllX(ctx context.Context) []*Games {
|
||||||
|
nodes, err := _q.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of Games IDs.
|
||||||
|
func (_q *GamesQuery) IDs(ctx context.Context) (ids []int64, err error) {
|
||||||
|
if _q.ctx.Unique == nil && _q.path != nil {
|
||||||
|
_q.Unique(true)
|
||||||
|
}
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||||
|
if err = _q.Select(games.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (_q *GamesQuery) IDsX(ctx context.Context) []int64 {
|
||||||
|
ids, err := _q.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (_q *GamesQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||||
|
if err := _q.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return withInterceptors[int](ctx, _q, querierCount[*GamesQuery](), _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (_q *GamesQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := _q.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (_q *GamesQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||||
|
switch _, err := _q.FirstID(ctx); {
|
||||||
|
case IsNotFound(err):
|
||||||
|
return false, nil
|
||||||
|
case err != nil:
|
||||||
|
return false, fmt.Errorf("models: check existence: %w", err)
|
||||||
|
default:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (_q *GamesQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := _q.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the GamesQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (_q *GamesQuery) Clone() *GamesQuery {
|
||||||
|
if _q == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &GamesQuery{
|
||||||
|
config: _q.config,
|
||||||
|
ctx: _q.ctx.Clone(),
|
||||||
|
order: append([]games.OrderOption{}, _q.order...),
|
||||||
|
inters: append([]Interceptor{}, _q.inters...),
|
||||||
|
predicates: append([]predicate.Games{}, _q.predicates...),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: _q.sql.Clone(),
|
||||||
|
path: _q.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupBy is used to group vertices by one or more fields/columns.
|
||||||
|
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// Name string `json:"name,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Games.Query().
|
||||||
|
// GroupBy(games.FieldName).
|
||||||
|
// Aggregate(models.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *GamesQuery) GroupBy(field string, fields ...string) *GamesGroupBy {
|
||||||
|
_q.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &GamesGroupBy{build: _q}
|
||||||
|
grbuild.flds = &_q.ctx.Fields
|
||||||
|
grbuild.label = games.Label
|
||||||
|
grbuild.scan = grbuild.Scan
|
||||||
|
return grbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows the selection one or more fields/columns for the given query,
|
||||||
|
// instead of selecting all fields in the entity.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// Name string `json:"name,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Games.Query().
|
||||||
|
// Select(games.FieldName).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *GamesQuery) Select(fields ...string) *GamesSelect {
|
||||||
|
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||||
|
sbuild := &GamesSelect{GamesQuery: _q}
|
||||||
|
sbuild.label = games.Label
|
||||||
|
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a GamesSelect configured with the given aggregations.
|
||||||
|
func (_q *GamesQuery) Aggregate(fns ...AggregateFunc) *GamesSelect {
|
||||||
|
return _q.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *GamesQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, inter := range _q.inters {
|
||||||
|
if inter == nil {
|
||||||
|
return fmt.Errorf("models: uninitialized interceptor (forgotten import models/runtime?)")
|
||||||
|
}
|
||||||
|
if trv, ok := inter.(Traverser); ok {
|
||||||
|
if err := trv.Traverse(ctx, _q); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range _q.ctx.Fields {
|
||||||
|
if !games.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _q.path != nil {
|
||||||
|
prev, err := _q.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_q.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *GamesQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Games, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*Games{}
|
||||||
|
_spec = _q.querySpec()
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*Games).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &Games{config: _q.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
for i := range hooks {
|
||||||
|
hooks[i](ctx, _spec)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *GamesQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := _q.querySpec()
|
||||||
|
_spec.Node.Columns = _q.ctx.Fields
|
||||||
|
if len(_q.ctx.Fields) > 0 {
|
||||||
|
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *GamesQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(games.Table, games.Columns, sqlgraph.NewFieldSpec(games.FieldID, field.TypeInt64))
|
||||||
|
_spec.From = _q.sql
|
||||||
|
if unique := _q.ctx.Unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
} else if _q.path != nil {
|
||||||
|
_spec.Unique = true
|
||||||
|
}
|
||||||
|
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, games.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != games.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := _q.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := _q.ctx.Limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := _q.ctx.Offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := _q.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *GamesQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(_q.driver.Dialect())
|
||||||
|
t1 := builder.Table(games.Table)
|
||||||
|
columns := _q.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = games.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if _q.sql != nil {
|
||||||
|
selector = _q.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, p := range _q.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range _q.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := _q.ctx.Offset; offset != nil {
|
||||||
|
// limit is mandatory for offset clause. We start
|
||||||
|
// with default value, and override it below if needed.
|
||||||
|
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||||
|
}
|
||||||
|
if limit := _q.ctx.Limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// GamesGroupBy is the group-by builder for Games entities.
|
||||||
|
type GamesGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *GamesQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (_g *GamesGroupBy) Aggregate(fns ...AggregateFunc) *GamesGroupBy {
|
||||||
|
_g.fns = append(_g.fns, fns...)
|
||||||
|
return _g
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_g *GamesGroupBy) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||||
|
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*GamesQuery, *GamesGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_g *GamesGroupBy) sqlScan(ctx context.Context, root *GamesQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx).Select()
|
||||||
|
aggregation := make([]string, 0, len(_g.fns))
|
||||||
|
for _, fn := range _g.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||||
|
for _, f := range *_g.flds {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GamesSelect is the builder for selecting fields of Games entities.
|
||||||
|
type GamesSelect struct {
|
||||||
|
*GamesQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (_s *GamesSelect) Aggregate(fns ...AggregateFunc) *GamesSelect {
|
||||||
|
_s.fns = append(_s.fns, fns...)
|
||||||
|
return _s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_s *GamesSelect) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||||
|
if err := _s.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*GamesQuery, *GamesSelect](ctx, _s.GamesQuery, _s, _s.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_s *GamesSelect) sqlScan(ctx context.Context, root *GamesQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx)
|
||||||
|
aggregation := make([]string, 0, len(_s.fns))
|
||||||
|
for _, fn := range _s.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
switch n := len(*_s.selector.flds); {
|
||||||
|
case n == 0 && len(aggregation) > 0:
|
||||||
|
selector.Select(aggregation...)
|
||||||
|
case n != 0 && len(aggregation) > 0:
|
||||||
|
selector.AppendSelect(aggregation...)
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
@@ -0,0 +1,456 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/games"
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/predicate"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GamesUpdate is the builder for updating Games entities.
|
||||||
|
type GamesUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *GamesMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the GamesUpdate builder.
|
||||||
|
func (_u *GamesUpdate) Where(ps ...predicate.Games) *GamesUpdate {
|
||||||
|
_u.mutation.Where(ps...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (_u *GamesUpdate) SetName(v string) *GamesUpdate {
|
||||||
|
_u.mutation.SetName(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (_u *GamesUpdate) SetNillableName(v *string) *GamesUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetName(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIcon sets the "icon" field.
|
||||||
|
func (_u *GamesUpdate) SetIcon(v string) *GamesUpdate {
|
||||||
|
_u.mutation.SetIcon(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableIcon sets the "icon" field if the given value is not nil.
|
||||||
|
func (_u *GamesUpdate) SetNillableIcon(v *string) *GamesUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetIcon(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCategory sets the "category" field.
|
||||||
|
func (_u *GamesUpdate) SetCategory(v string) *GamesUpdate {
|
||||||
|
_u.mutation.SetCategory(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCategory sets the "category" field if the given value is not nil.
|
||||||
|
func (_u *GamesUpdate) SetNillableCategory(v *string) *GamesUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetCategory(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSortOrder sets the "sort_order" field.
|
||||||
|
func (_u *GamesUpdate) SetSortOrder(v int) *GamesUpdate {
|
||||||
|
_u.mutation.ResetSortOrder()
|
||||||
|
_u.mutation.SetSortOrder(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
|
||||||
|
func (_u *GamesUpdate) SetNillableSortOrder(v *int) *GamesUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetSortOrder(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddSortOrder adds value to the "sort_order" field.
|
||||||
|
func (_u *GamesUpdate) AddSortOrder(v int) *GamesUpdate {
|
||||||
|
_u.mutation.AddSortOrder(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIsActive sets the "is_active" field.
|
||||||
|
func (_u *GamesUpdate) SetIsActive(v bool) *GamesUpdate {
|
||||||
|
_u.mutation.SetIsActive(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableIsActive sets the "is_active" field if the given value is not nil.
|
||||||
|
func (_u *GamesUpdate) SetNillableIsActive(v *bool) *GamesUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetIsActive(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearIsActive clears the value of the "is_active" field.
|
||||||
|
func (_u *GamesUpdate) ClearIsActive() *GamesUpdate {
|
||||||
|
_u.mutation.ClearIsActive()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_u *GamesUpdate) SetUpdatedAt(v time.Time) *GamesUpdate {
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the GamesMutation object of the builder.
|
||||||
|
func (_u *GamesUpdate) Mutation() *GamesMutation {
|
||||||
|
return _u.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (_u *GamesUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
_u.defaults()
|
||||||
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_u *GamesUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := _u.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_u *GamesUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := _u.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *GamesUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := _u.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (_u *GamesUpdate) defaults() {
|
||||||
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||||
|
v := games.UpdateDefaultUpdatedAt()
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_u *GamesUpdate) check() error {
|
||||||
|
if v, ok := _u.mutation.Name(); ok {
|
||||||
|
if err := games.NameValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "name", err: fmt.Errorf(`models: validator failed for field "Games.name": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.Category(); ok {
|
||||||
|
if err := games.CategoryValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "category", err: fmt.Errorf(`models: validator failed for field "Games.category": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_u *GamesUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||||
|
if err := _u.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(games.Table, games.Columns, sqlgraph.NewFieldSpec(games.FieldID, field.TypeInt64))
|
||||||
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Name(); ok {
|
||||||
|
_spec.SetField(games.FieldName, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Icon(); ok {
|
||||||
|
_spec.SetField(games.FieldIcon, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Category(); ok {
|
||||||
|
_spec.SetField(games.FieldCategory, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.SortOrder(); ok {
|
||||||
|
_spec.SetField(games.FieldSortOrder, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedSortOrder(); ok {
|
||||||
|
_spec.AddField(games.FieldSortOrder, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.IsActive(); ok {
|
||||||
|
_spec.SetField(games.FieldIsActive, field.TypeBool, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.IsActiveCleared() {
|
||||||
|
_spec.ClearField(games.FieldIsActive, field.TypeBool)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(games.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{games.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
_u.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GamesUpdateOne is the builder for updating a single Games entity.
|
||||||
|
type GamesUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *GamesMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (_u *GamesUpdateOne) SetName(v string) *GamesUpdateOne {
|
||||||
|
_u.mutation.SetName(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (_u *GamesUpdateOne) SetNillableName(v *string) *GamesUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetName(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIcon sets the "icon" field.
|
||||||
|
func (_u *GamesUpdateOne) SetIcon(v string) *GamesUpdateOne {
|
||||||
|
_u.mutation.SetIcon(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableIcon sets the "icon" field if the given value is not nil.
|
||||||
|
func (_u *GamesUpdateOne) SetNillableIcon(v *string) *GamesUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetIcon(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCategory sets the "category" field.
|
||||||
|
func (_u *GamesUpdateOne) SetCategory(v string) *GamesUpdateOne {
|
||||||
|
_u.mutation.SetCategory(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCategory sets the "category" field if the given value is not nil.
|
||||||
|
func (_u *GamesUpdateOne) SetNillableCategory(v *string) *GamesUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetCategory(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSortOrder sets the "sort_order" field.
|
||||||
|
func (_u *GamesUpdateOne) SetSortOrder(v int) *GamesUpdateOne {
|
||||||
|
_u.mutation.ResetSortOrder()
|
||||||
|
_u.mutation.SetSortOrder(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
|
||||||
|
func (_u *GamesUpdateOne) SetNillableSortOrder(v *int) *GamesUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetSortOrder(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddSortOrder adds value to the "sort_order" field.
|
||||||
|
func (_u *GamesUpdateOne) AddSortOrder(v int) *GamesUpdateOne {
|
||||||
|
_u.mutation.AddSortOrder(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIsActive sets the "is_active" field.
|
||||||
|
func (_u *GamesUpdateOne) SetIsActive(v bool) *GamesUpdateOne {
|
||||||
|
_u.mutation.SetIsActive(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableIsActive sets the "is_active" field if the given value is not nil.
|
||||||
|
func (_u *GamesUpdateOne) SetNillableIsActive(v *bool) *GamesUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetIsActive(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearIsActive clears the value of the "is_active" field.
|
||||||
|
func (_u *GamesUpdateOne) ClearIsActive() *GamesUpdateOne {
|
||||||
|
_u.mutation.ClearIsActive()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_u *GamesUpdateOne) SetUpdatedAt(v time.Time) *GamesUpdateOne {
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the GamesMutation object of the builder.
|
||||||
|
func (_u *GamesUpdateOne) Mutation() *GamesMutation {
|
||||||
|
return _u.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the GamesUpdate builder.
|
||||||
|
func (_u *GamesUpdateOne) Where(ps ...predicate.Games) *GamesUpdateOne {
|
||||||
|
_u.mutation.Where(ps...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (_u *GamesUpdateOne) Select(field string, fields ...string) *GamesUpdateOne {
|
||||||
|
_u.fields = append([]string{field}, fields...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated Games entity.
|
||||||
|
func (_u *GamesUpdateOne) Save(ctx context.Context) (*Games, error) {
|
||||||
|
_u.defaults()
|
||||||
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_u *GamesUpdateOne) SaveX(ctx context.Context) *Games {
|
||||||
|
node, err := _u.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (_u *GamesUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := _u.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *GamesUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := _u.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (_u *GamesUpdateOne) defaults() {
|
||||||
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||||
|
v := games.UpdateDefaultUpdatedAt()
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_u *GamesUpdateOne) check() error {
|
||||||
|
if v, ok := _u.mutation.Name(); ok {
|
||||||
|
if err := games.NameValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "name", err: fmt.Errorf(`models: validator failed for field "Games.name": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.Category(); ok {
|
||||||
|
if err := games.CategoryValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "category", err: fmt.Errorf(`models: validator failed for field "Games.category": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_u *GamesUpdateOne) sqlSave(ctx context.Context) (_node *Games, err error) {
|
||||||
|
if err := _u.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(games.Table, games.Columns, sqlgraph.NewFieldSpec(games.FieldID, field.TypeInt64))
|
||||||
|
id, ok := _u.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "Games.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := _u.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, games.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !games.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != games.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Name(); ok {
|
||||||
|
_spec.SetField(games.FieldName, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Icon(); ok {
|
||||||
|
_spec.SetField(games.FieldIcon, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Category(); ok {
|
||||||
|
_spec.SetField(games.FieldCategory, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.SortOrder(); ok {
|
||||||
|
_spec.SetField(games.FieldSortOrder, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedSortOrder(); ok {
|
||||||
|
_spec.AddField(games.FieldSortOrder, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.IsActive(); ok {
|
||||||
|
_spec.SetField(games.FieldIsActive, field.TypeBool, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.IsActiveCleared() {
|
||||||
|
_spec.ClearField(games.FieldIsActive, field.TypeBool)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(games.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
_node = &Games{config: _u.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{games.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_u.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,198 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package hook
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/game/rpc/internal/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The GamesFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as Games mutator.
|
||||||
|
type GamesFunc func(context.Context, *models.GamesMutation) (models.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f GamesFunc) Mutate(ctx context.Context, m models.Mutation) (models.Value, error) {
|
||||||
|
if mv, ok := m.(*models.GamesMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *models.GamesMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Condition is a hook condition function.
|
||||||
|
type Condition func(context.Context, models.Mutation) bool
|
||||||
|
|
||||||
|
// And groups conditions with the AND operator.
|
||||||
|
func And(first, second Condition, rest ...Condition) Condition {
|
||||||
|
return func(ctx context.Context, m models.Mutation) bool {
|
||||||
|
if !first(ctx, m) || !second(ctx, m) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, cond := range rest {
|
||||||
|
if !cond(ctx, m) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups conditions with the OR operator.
|
||||||
|
func Or(first, second Condition, rest ...Condition) Condition {
|
||||||
|
return func(ctx context.Context, m models.Mutation) bool {
|
||||||
|
if first(ctx, m) || second(ctx, m) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
for _, cond := range rest {
|
||||||
|
if cond(ctx, m) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not negates a given condition.
|
||||||
|
func Not(cond Condition) Condition {
|
||||||
|
return func(ctx context.Context, m models.Mutation) bool {
|
||||||
|
return !cond(ctx, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasOp is a condition testing mutation operation.
|
||||||
|
func HasOp(op models.Op) Condition {
|
||||||
|
return func(_ context.Context, m models.Mutation) bool {
|
||||||
|
return m.Op().Is(op)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasAddedFields is a condition validating `.AddedField` on fields.
|
||||||
|
func HasAddedFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m models.Mutation) bool {
|
||||||
|
if _, exists := m.AddedField(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if _, exists := m.AddedField(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasClearedFields is a condition validating `.FieldCleared` on fields.
|
||||||
|
func HasClearedFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m models.Mutation) bool {
|
||||||
|
if exists := m.FieldCleared(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if exists := m.FieldCleared(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasFields is a condition validating `.Field` on fields.
|
||||||
|
func HasFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m models.Mutation) bool {
|
||||||
|
if _, exists := m.Field(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if _, exists := m.Field(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If executes the given hook under condition.
|
||||||
|
//
|
||||||
|
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
|
||||||
|
func If(hk models.Hook, cond Condition) models.Hook {
|
||||||
|
return func(next models.Mutator) models.Mutator {
|
||||||
|
return models.MutateFunc(func(ctx context.Context, m models.Mutation) (models.Value, error) {
|
||||||
|
if cond(ctx, m) {
|
||||||
|
return hk(next).Mutate(ctx, m)
|
||||||
|
}
|
||||||
|
return next.Mutate(ctx, m)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// On executes the given hook only for the given operation.
|
||||||
|
//
|
||||||
|
// hook.On(Log, models.Delete|models.Create)
|
||||||
|
func On(hk models.Hook, op models.Op) models.Hook {
|
||||||
|
return If(hk, HasOp(op))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unless skips the given hook only for the given operation.
|
||||||
|
//
|
||||||
|
// hook.Unless(Log, models.Update|models.UpdateOne)
|
||||||
|
func Unless(hk models.Hook, op models.Op) models.Hook {
|
||||||
|
return If(hk, Not(HasOp(op)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FixedError is a hook returning a fixed error.
|
||||||
|
func FixedError(err error) models.Hook {
|
||||||
|
return func(models.Mutator) models.Mutator {
|
||||||
|
return models.MutateFunc(func(context.Context, models.Mutation) (models.Value, error) {
|
||||||
|
return nil, err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reject returns a hook that rejects all operations that match op.
|
||||||
|
//
|
||||||
|
// func (T) Hooks() []models.Hook {
|
||||||
|
// return []models.Hook{
|
||||||
|
// Reject(models.Delete|models.Update),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
func Reject(op models.Op) models.Hook {
|
||||||
|
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||||
|
return On(hk, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chain acts as a list of hooks and is effectively immutable.
|
||||||
|
// Once created, it will always hold the same set of hooks in the same order.
|
||||||
|
type Chain struct {
|
||||||
|
hooks []models.Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewChain creates a new chain of hooks.
|
||||||
|
func NewChain(hooks ...models.Hook) Chain {
|
||||||
|
return Chain{append([]models.Hook(nil), hooks...)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hook chains the list of hooks and returns the final hook.
|
||||||
|
func (c Chain) Hook() models.Hook {
|
||||||
|
return func(mutator models.Mutator) models.Mutator {
|
||||||
|
for i := len(c.hooks) - 1; i >= 0; i-- {
|
||||||
|
mutator = c.hooks[i](mutator)
|
||||||
|
}
|
||||||
|
return mutator
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append extends a chain, adding the specified hook
|
||||||
|
// as the last ones in the mutation flow.
|
||||||
|
func (c Chain) Append(hooks ...models.Hook) Chain {
|
||||||
|
newHooks := make([]models.Hook, 0, len(c.hooks)+len(hooks))
|
||||||
|
newHooks = append(newHooks, c.hooks...)
|
||||||
|
newHooks = append(newHooks, hooks...)
|
||||||
|
return Chain{newHooks}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extend extends a chain, adding the specified chain
|
||||||
|
// as the last ones in the mutation flow.
|
||||||
|
func (c Chain) Extend(chain Chain) Chain {
|
||||||
|
return c.Append(chain.hooks...)
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package migrate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// WithGlobalUniqueID sets the universal ids options to the migration.
|
||||||
|
// If this option is enabled, ent migration will allocate a 1<<32 range
|
||||||
|
// for the ids of each entity (table).
|
||||||
|
// Note that this option cannot be applied on tables that already exist.
|
||||||
|
WithGlobalUniqueID = schema.WithGlobalUniqueID
|
||||||
|
// WithDropColumn sets the drop column option to the migration.
|
||||||
|
// If this option is enabled, ent migration will drop old columns
|
||||||
|
// that were used for both fields and edges. This defaults to false.
|
||||||
|
WithDropColumn = schema.WithDropColumn
|
||||||
|
// WithDropIndex sets the drop index option to the migration.
|
||||||
|
// If this option is enabled, ent migration will drop old indexes
|
||||||
|
// that were defined in the schema. This defaults to false.
|
||||||
|
// Note that unique constraints are defined using `UNIQUE INDEX`,
|
||||||
|
// and therefore, it's recommended to enable this option to get more
|
||||||
|
// flexibility in the schema changes.
|
||||||
|
WithDropIndex = schema.WithDropIndex
|
||||||
|
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
|
||||||
|
WithForeignKeys = schema.WithForeignKeys
|
||||||
|
)
|
||||||
|
|
||||||
|
// Schema is the API for creating, migrating and dropping a schema.
|
||||||
|
type Schema struct {
|
||||||
|
drv dialect.Driver
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSchema creates a new schema client.
|
||||||
|
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
|
||||||
|
|
||||||
|
// Create creates all schema resources.
|
||||||
|
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
|
||||||
|
return Create(ctx, s, Tables, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create creates all table resources using the given schema driver.
|
||||||
|
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error {
|
||||||
|
migrate, err := schema.NewMigrate(s.drv, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("ent/migrate: %w", err)
|
||||||
|
}
|
||||||
|
return migrate.Create(ctx, tables...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteTo writes the schema changes to w instead of running them against the database.
|
||||||
|
//
|
||||||
|
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
|
||||||
|
// log.Fatal(err)
|
||||||
|
// }
|
||||||
|
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
|
||||||
|
return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...)
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package migrate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// GamesColumns holds the columns for the "games" table.
|
||||||
|
GamesColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
|
{Name: "name", Type: field.TypeString, Unique: true, Size: 100},
|
||||||
|
{Name: "icon", Type: field.TypeString},
|
||||||
|
{Name: "category", Type: field.TypeString, Size: 50},
|
||||||
|
{Name: "sort_order", Type: field.TypeInt, Default: 0},
|
||||||
|
{Name: "is_active", Type: field.TypeBool, Nullable: true, Default: true},
|
||||||
|
{Name: "created_at", Type: field.TypeTime},
|
||||||
|
{Name: "updated_at", Type: field.TypeTime},
|
||||||
|
}
|
||||||
|
// GamesTable holds the schema information for the "games" table.
|
||||||
|
GamesTable = &schema.Table{
|
||||||
|
Name: "games",
|
||||||
|
Columns: GamesColumns,
|
||||||
|
PrimaryKey: []*schema.Column{GamesColumns[0]},
|
||||||
|
}
|
||||||
|
// Tables holds all the tables in the schema.
|
||||||
|
Tables = []*schema.Table{
|
||||||
|
GamesTable,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
}
|
||||||
@@ -0,0 +1,742 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/games"
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/predicate"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Operation types.
|
||||||
|
OpCreate = ent.OpCreate
|
||||||
|
OpDelete = ent.OpDelete
|
||||||
|
OpDeleteOne = ent.OpDeleteOne
|
||||||
|
OpUpdate = ent.OpUpdate
|
||||||
|
OpUpdateOne = ent.OpUpdateOne
|
||||||
|
|
||||||
|
// Node types.
|
||||||
|
TypeGames = "Games"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GamesMutation represents an operation that mutates the Games nodes in the graph.
|
||||||
|
type GamesMutation struct {
|
||||||
|
config
|
||||||
|
op Op
|
||||||
|
typ string
|
||||||
|
id *int64
|
||||||
|
name *string
|
||||||
|
icon *string
|
||||||
|
category *string
|
||||||
|
sort_order *int
|
||||||
|
addsort_order *int
|
||||||
|
is_active *bool
|
||||||
|
created_at *time.Time
|
||||||
|
updated_at *time.Time
|
||||||
|
clearedFields map[string]struct{}
|
||||||
|
done bool
|
||||||
|
oldValue func(context.Context) (*Games, error)
|
||||||
|
predicates []predicate.Games
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ ent.Mutation = (*GamesMutation)(nil)
|
||||||
|
|
||||||
|
// gamesOption allows management of the mutation configuration using functional options.
|
||||||
|
type gamesOption func(*GamesMutation)
|
||||||
|
|
||||||
|
// newGamesMutation creates new mutation for the Games entity.
|
||||||
|
func newGamesMutation(c config, op Op, opts ...gamesOption) *GamesMutation {
|
||||||
|
m := &GamesMutation{
|
||||||
|
config: c,
|
||||||
|
op: op,
|
||||||
|
typ: TypeGames,
|
||||||
|
clearedFields: make(map[string]struct{}),
|
||||||
|
}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(m)
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
// withGamesID sets the ID field of the mutation.
|
||||||
|
func withGamesID(id int64) gamesOption {
|
||||||
|
return func(m *GamesMutation) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
once sync.Once
|
||||||
|
value *Games
|
||||||
|
)
|
||||||
|
m.oldValue = func(ctx context.Context) (*Games, error) {
|
||||||
|
once.Do(func() {
|
||||||
|
if m.done {
|
||||||
|
err = errors.New("querying old values post mutation is not allowed")
|
||||||
|
} else {
|
||||||
|
value, err = m.Client().Games.Get(ctx, id)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return value, err
|
||||||
|
}
|
||||||
|
m.id = &id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// withGames sets the old Games of the mutation.
|
||||||
|
func withGames(node *Games) gamesOption {
|
||||||
|
return func(m *GamesMutation) {
|
||||||
|
m.oldValue = func(context.Context) (*Games, error) {
|
||||||
|
return node, nil
|
||||||
|
}
|
||||||
|
m.id = &node.ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
||||||
|
// executed in a transaction (ent.Tx), a transactional client is returned.
|
||||||
|
func (m GamesMutation) Client() *Client {
|
||||||
|
client := &Client{config: m.config}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
||||||
|
// it returns an error otherwise.
|
||||||
|
func (m GamesMutation) Tx() (*Tx, error) {
|
||||||
|
if _, ok := m.driver.(*txDriver); !ok {
|
||||||
|
return nil, errors.New("models: mutation is not running in a transaction")
|
||||||
|
}
|
||||||
|
tx := &Tx{config: m.config}
|
||||||
|
tx.init()
|
||||||
|
return tx, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the value of the id field. Note that this
|
||||||
|
// operation is only accepted on creation of Games entities.
|
||||||
|
func (m *GamesMutation) SetID(id int64) {
|
||||||
|
m.id = &id
|
||||||
|
}
|
||||||
|
|
||||||
|
// ID returns the ID value in the mutation. Note that the ID is only available
|
||||||
|
// if it was provided to the builder or after it was returned from the database.
|
||||||
|
func (m *GamesMutation) ID() (id int64, exists bool) {
|
||||||
|
if m.id == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *m.id, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
||||||
|
// That means, if the mutation is applied within a transaction with an isolation level such
|
||||||
|
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
||||||
|
// or updated by the mutation.
|
||||||
|
func (m *GamesMutation) IDs(ctx context.Context) ([]int64, error) {
|
||||||
|
switch {
|
||||||
|
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
||||||
|
id, exists := m.ID()
|
||||||
|
if exists {
|
||||||
|
return []int64{id}, nil
|
||||||
|
}
|
||||||
|
fallthrough
|
||||||
|
case m.op.Is(OpUpdate | OpDelete):
|
||||||
|
return m.Client().Games.Query().Where(m.predicates...).IDs(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (m *GamesMutation) SetName(s string) {
|
||||||
|
m.name = &s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name returns the value of the "name" field in the mutation.
|
||||||
|
func (m *GamesMutation) Name() (r string, exists bool) {
|
||||||
|
v := m.name
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldName returns the old "name" field's value of the Games entity.
|
||||||
|
// If the Games object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *GamesMutation) OldName(ctx context.Context) (v string, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldName is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldName requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldName: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.Name, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetName resets all changes to the "name" field.
|
||||||
|
func (m *GamesMutation) ResetName() {
|
||||||
|
m.name = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIcon sets the "icon" field.
|
||||||
|
func (m *GamesMutation) SetIcon(s string) {
|
||||||
|
m.icon = &s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Icon returns the value of the "icon" field in the mutation.
|
||||||
|
func (m *GamesMutation) Icon() (r string, exists bool) {
|
||||||
|
v := m.icon
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldIcon returns the old "icon" field's value of the Games entity.
|
||||||
|
// If the Games object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *GamesMutation) OldIcon(ctx context.Context) (v string, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldIcon is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldIcon requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldIcon: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.Icon, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetIcon resets all changes to the "icon" field.
|
||||||
|
func (m *GamesMutation) ResetIcon() {
|
||||||
|
m.icon = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCategory sets the "category" field.
|
||||||
|
func (m *GamesMutation) SetCategory(s string) {
|
||||||
|
m.category = &s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Category returns the value of the "category" field in the mutation.
|
||||||
|
func (m *GamesMutation) Category() (r string, exists bool) {
|
||||||
|
v := m.category
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldCategory returns the old "category" field's value of the Games entity.
|
||||||
|
// If the Games object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *GamesMutation) OldCategory(ctx context.Context) (v string, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldCategory is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldCategory requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldCategory: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.Category, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetCategory resets all changes to the "category" field.
|
||||||
|
func (m *GamesMutation) ResetCategory() {
|
||||||
|
m.category = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSortOrder sets the "sort_order" field.
|
||||||
|
func (m *GamesMutation) SetSortOrder(i int) {
|
||||||
|
m.sort_order = &i
|
||||||
|
m.addsort_order = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SortOrder returns the value of the "sort_order" field in the mutation.
|
||||||
|
func (m *GamesMutation) SortOrder() (r int, exists bool) {
|
||||||
|
v := m.sort_order
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldSortOrder returns the old "sort_order" field's value of the Games entity.
|
||||||
|
// If the Games object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *GamesMutation) OldSortOrder(ctx context.Context) (v int, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldSortOrder is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldSortOrder requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldSortOrder: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.SortOrder, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddSortOrder adds i to the "sort_order" field.
|
||||||
|
func (m *GamesMutation) AddSortOrder(i int) {
|
||||||
|
if m.addsort_order != nil {
|
||||||
|
*m.addsort_order += i
|
||||||
|
} else {
|
||||||
|
m.addsort_order = &i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedSortOrder returns the value that was added to the "sort_order" field in this mutation.
|
||||||
|
func (m *GamesMutation) AddedSortOrder() (r int, exists bool) {
|
||||||
|
v := m.addsort_order
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetSortOrder resets all changes to the "sort_order" field.
|
||||||
|
func (m *GamesMutation) ResetSortOrder() {
|
||||||
|
m.sort_order = nil
|
||||||
|
m.addsort_order = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIsActive sets the "is_active" field.
|
||||||
|
func (m *GamesMutation) SetIsActive(b bool) {
|
||||||
|
m.is_active = &b
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsActive returns the value of the "is_active" field in the mutation.
|
||||||
|
func (m *GamesMutation) IsActive() (r bool, exists bool) {
|
||||||
|
v := m.is_active
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldIsActive returns the old "is_active" field's value of the Games entity.
|
||||||
|
// If the Games object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *GamesMutation) OldIsActive(ctx context.Context) (v bool, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldIsActive is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldIsActive requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldIsActive: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.IsActive, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearIsActive clears the value of the "is_active" field.
|
||||||
|
func (m *GamesMutation) ClearIsActive() {
|
||||||
|
m.is_active = nil
|
||||||
|
m.clearedFields[games.FieldIsActive] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsActiveCleared returns if the "is_active" field was cleared in this mutation.
|
||||||
|
func (m *GamesMutation) IsActiveCleared() bool {
|
||||||
|
_, ok := m.clearedFields[games.FieldIsActive]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetIsActive resets all changes to the "is_active" field.
|
||||||
|
func (m *GamesMutation) ResetIsActive() {
|
||||||
|
m.is_active = nil
|
||||||
|
delete(m.clearedFields, games.FieldIsActive)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (m *GamesMutation) SetCreatedAt(t time.Time) {
|
||||||
|
m.created_at = &t
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt returns the value of the "created_at" field in the mutation.
|
||||||
|
func (m *GamesMutation) CreatedAt() (r time.Time, exists bool) {
|
||||||
|
v := m.created_at
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldCreatedAt returns the old "created_at" field's value of the Games entity.
|
||||||
|
// If the Games object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *GamesMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.CreatedAt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetCreatedAt resets all changes to the "created_at" field.
|
||||||
|
func (m *GamesMutation) ResetCreatedAt() {
|
||||||
|
m.created_at = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (m *GamesMutation) SetUpdatedAt(t time.Time) {
|
||||||
|
m.updated_at = &t
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAt returns the value of the "updated_at" field in the mutation.
|
||||||
|
func (m *GamesMutation) UpdatedAt() (r time.Time, exists bool) {
|
||||||
|
v := m.updated_at
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldUpdatedAt returns the old "updated_at" field's value of the Games entity.
|
||||||
|
// If the Games object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *GamesMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.UpdatedAt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetUpdatedAt resets all changes to the "updated_at" field.
|
||||||
|
func (m *GamesMutation) ResetUpdatedAt() {
|
||||||
|
m.updated_at = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the GamesMutation builder.
|
||||||
|
func (m *GamesMutation) Where(ps ...predicate.Games) {
|
||||||
|
m.predicates = append(m.predicates, ps...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereP appends storage-level predicates to the GamesMutation builder. Using this method,
|
||||||
|
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||||
|
func (m *GamesMutation) WhereP(ps ...func(*sql.Selector)) {
|
||||||
|
p := make([]predicate.Games, len(ps))
|
||||||
|
for i := range ps {
|
||||||
|
p[i] = ps[i]
|
||||||
|
}
|
||||||
|
m.Where(p...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Op returns the operation name.
|
||||||
|
func (m *GamesMutation) Op() Op {
|
||||||
|
return m.op
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOp allows setting the mutation operation.
|
||||||
|
func (m *GamesMutation) SetOp(op Op) {
|
||||||
|
m.op = op
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type returns the node type of this mutation (Games).
|
||||||
|
func (m *GamesMutation) Type() string {
|
||||||
|
return m.typ
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fields returns all fields that were changed during this mutation. Note that in
|
||||||
|
// order to get all numeric fields that were incremented/decremented, call
|
||||||
|
// AddedFields().
|
||||||
|
func (m *GamesMutation) Fields() []string {
|
||||||
|
fields := make([]string, 0, 7)
|
||||||
|
if m.name != nil {
|
||||||
|
fields = append(fields, games.FieldName)
|
||||||
|
}
|
||||||
|
if m.icon != nil {
|
||||||
|
fields = append(fields, games.FieldIcon)
|
||||||
|
}
|
||||||
|
if m.category != nil {
|
||||||
|
fields = append(fields, games.FieldCategory)
|
||||||
|
}
|
||||||
|
if m.sort_order != nil {
|
||||||
|
fields = append(fields, games.FieldSortOrder)
|
||||||
|
}
|
||||||
|
if m.is_active != nil {
|
||||||
|
fields = append(fields, games.FieldIsActive)
|
||||||
|
}
|
||||||
|
if m.created_at != nil {
|
||||||
|
fields = append(fields, games.FieldCreatedAt)
|
||||||
|
}
|
||||||
|
if m.updated_at != nil {
|
||||||
|
fields = append(fields, games.FieldUpdatedAt)
|
||||||
|
}
|
||||||
|
return fields
|
||||||
|
}
|
||||||
|
|
||||||
|
// Field returns the value of a field with the given name. The second boolean
|
||||||
|
// return value indicates that this field was not set, or was not defined in the
|
||||||
|
// schema.
|
||||||
|
func (m *GamesMutation) Field(name string) (ent.Value, bool) {
|
||||||
|
switch name {
|
||||||
|
case games.FieldName:
|
||||||
|
return m.Name()
|
||||||
|
case games.FieldIcon:
|
||||||
|
return m.Icon()
|
||||||
|
case games.FieldCategory:
|
||||||
|
return m.Category()
|
||||||
|
case games.FieldSortOrder:
|
||||||
|
return m.SortOrder()
|
||||||
|
case games.FieldIsActive:
|
||||||
|
return m.IsActive()
|
||||||
|
case games.FieldCreatedAt:
|
||||||
|
return m.CreatedAt()
|
||||||
|
case games.FieldUpdatedAt:
|
||||||
|
return m.UpdatedAt()
|
||||||
|
}
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldField returns the old value of the field from the database. An error is
|
||||||
|
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||||
|
// database failed.
|
||||||
|
func (m *GamesMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||||
|
switch name {
|
||||||
|
case games.FieldName:
|
||||||
|
return m.OldName(ctx)
|
||||||
|
case games.FieldIcon:
|
||||||
|
return m.OldIcon(ctx)
|
||||||
|
case games.FieldCategory:
|
||||||
|
return m.OldCategory(ctx)
|
||||||
|
case games.FieldSortOrder:
|
||||||
|
return m.OldSortOrder(ctx)
|
||||||
|
case games.FieldIsActive:
|
||||||
|
return m.OldIsActive(ctx)
|
||||||
|
case games.FieldCreatedAt:
|
||||||
|
return m.OldCreatedAt(ctx)
|
||||||
|
case games.FieldUpdatedAt:
|
||||||
|
return m.OldUpdatedAt(ctx)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unknown Games field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetField sets the value of a field with the given name. It returns an error if
|
||||||
|
// the field is not defined in the schema, or if the type mismatched the field
|
||||||
|
// type.
|
||||||
|
func (m *GamesMutation) SetField(name string, value ent.Value) error {
|
||||||
|
switch name {
|
||||||
|
case games.FieldName:
|
||||||
|
v, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetName(v)
|
||||||
|
return nil
|
||||||
|
case games.FieldIcon:
|
||||||
|
v, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetIcon(v)
|
||||||
|
return nil
|
||||||
|
case games.FieldCategory:
|
||||||
|
v, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetCategory(v)
|
||||||
|
return nil
|
||||||
|
case games.FieldSortOrder:
|
||||||
|
v, ok := value.(int)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetSortOrder(v)
|
||||||
|
return nil
|
||||||
|
case games.FieldIsActive:
|
||||||
|
v, ok := value.(bool)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetIsActive(v)
|
||||||
|
return nil
|
||||||
|
case games.FieldCreatedAt:
|
||||||
|
v, ok := value.(time.Time)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetCreatedAt(v)
|
||||||
|
return nil
|
||||||
|
case games.FieldUpdatedAt:
|
||||||
|
v, ok := value.(time.Time)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetUpdatedAt(v)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unknown Games field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||||
|
// this mutation.
|
||||||
|
func (m *GamesMutation) AddedFields() []string {
|
||||||
|
var fields []string
|
||||||
|
if m.addsort_order != nil {
|
||||||
|
fields = append(fields, games.FieldSortOrder)
|
||||||
|
}
|
||||||
|
return fields
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||||
|
// with the given name. The second boolean return value indicates that this field
|
||||||
|
// was not set, or was not defined in the schema.
|
||||||
|
func (m *GamesMutation) AddedField(name string) (ent.Value, bool) {
|
||||||
|
switch name {
|
||||||
|
case games.FieldSortOrder:
|
||||||
|
return m.AddedSortOrder()
|
||||||
|
}
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddField adds the value to the field with the given name. It returns an error if
|
||||||
|
// the field is not defined in the schema, or if the type mismatched the field
|
||||||
|
// type.
|
||||||
|
func (m *GamesMutation) AddField(name string, value ent.Value) error {
|
||||||
|
switch name {
|
||||||
|
case games.FieldSortOrder:
|
||||||
|
v, ok := value.(int)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.AddSortOrder(v)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unknown Games numeric field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearedFields returns all nullable fields that were cleared during this
|
||||||
|
// mutation.
|
||||||
|
func (m *GamesMutation) ClearedFields() []string {
|
||||||
|
var fields []string
|
||||||
|
if m.FieldCleared(games.FieldIsActive) {
|
||||||
|
fields = append(fields, games.FieldIsActive)
|
||||||
|
}
|
||||||
|
return fields
|
||||||
|
}
|
||||||
|
|
||||||
|
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||||
|
// cleared in this mutation.
|
||||||
|
func (m *GamesMutation) FieldCleared(name string) bool {
|
||||||
|
_, ok := m.clearedFields[name]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearField clears the value of the field with the given name. It returns an
|
||||||
|
// error if the field is not defined in the schema.
|
||||||
|
func (m *GamesMutation) ClearField(name string) error {
|
||||||
|
switch name {
|
||||||
|
case games.FieldIsActive:
|
||||||
|
m.ClearIsActive()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unknown Games nullable field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetField resets all changes in the mutation for the field with the given name.
|
||||||
|
// It returns an error if the field is not defined in the schema.
|
||||||
|
func (m *GamesMutation) ResetField(name string) error {
|
||||||
|
switch name {
|
||||||
|
case games.FieldName:
|
||||||
|
m.ResetName()
|
||||||
|
return nil
|
||||||
|
case games.FieldIcon:
|
||||||
|
m.ResetIcon()
|
||||||
|
return nil
|
||||||
|
case games.FieldCategory:
|
||||||
|
m.ResetCategory()
|
||||||
|
return nil
|
||||||
|
case games.FieldSortOrder:
|
||||||
|
m.ResetSortOrder()
|
||||||
|
return nil
|
||||||
|
case games.FieldIsActive:
|
||||||
|
m.ResetIsActive()
|
||||||
|
return nil
|
||||||
|
case games.FieldCreatedAt:
|
||||||
|
m.ResetCreatedAt()
|
||||||
|
return nil
|
||||||
|
case games.FieldUpdatedAt:
|
||||||
|
m.ResetUpdatedAt()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unknown Games field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||||
|
func (m *GamesMutation) AddedEdges() []string {
|
||||||
|
edges := make([]string, 0, 0)
|
||||||
|
return edges
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||||
|
// name in this mutation.
|
||||||
|
func (m *GamesMutation) AddedIDs(name string) []ent.Value {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||||
|
func (m *GamesMutation) RemovedEdges() []string {
|
||||||
|
edges := make([]string, 0, 0)
|
||||||
|
return edges
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||||
|
// the given name in this mutation.
|
||||||
|
func (m *GamesMutation) RemovedIDs(name string) []ent.Value {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||||
|
func (m *GamesMutation) ClearedEdges() []string {
|
||||||
|
edges := make([]string, 0, 0)
|
||||||
|
return edges
|
||||||
|
}
|
||||||
|
|
||||||
|
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||||
|
// was cleared in this mutation.
|
||||||
|
func (m *GamesMutation) EdgeCleared(name string) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||||
|
// if that edge is not defined in the schema.
|
||||||
|
func (m *GamesMutation) ClearEdge(name string) error {
|
||||||
|
return fmt.Errorf("unknown Games unique edge %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||||
|
// It returns an error if the edge is not defined in the schema.
|
||||||
|
func (m *GamesMutation) ResetEdge(name string) error {
|
||||||
|
return fmt.Errorf("unknown Games edge %s", name)
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package predicate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Games is the predicate function for games builders.
|
||||||
|
type Games func(*sql.Selector)
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/games"
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/schema"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The init function reads all schema descriptors with runtime code
|
||||||
|
// (default values, validators, hooks and policies) and stitches it
|
||||||
|
// to their package variables.
|
||||||
|
func init() {
|
||||||
|
gamesFields := schema.Games{}.Fields()
|
||||||
|
_ = gamesFields
|
||||||
|
// gamesDescName is the schema descriptor for name field.
|
||||||
|
gamesDescName := gamesFields[1].Descriptor()
|
||||||
|
// games.NameValidator is a validator for the "name" field. It is called by the builders before save.
|
||||||
|
games.NameValidator = gamesDescName.Validators[0].(func(string) error)
|
||||||
|
// gamesDescCategory is the schema descriptor for category field.
|
||||||
|
gamesDescCategory := gamesFields[3].Descriptor()
|
||||||
|
// games.CategoryValidator is a validator for the "category" field. It is called by the builders before save.
|
||||||
|
games.CategoryValidator = gamesDescCategory.Validators[0].(func(string) error)
|
||||||
|
// gamesDescSortOrder is the schema descriptor for sort_order field.
|
||||||
|
gamesDescSortOrder := gamesFields[4].Descriptor()
|
||||||
|
// games.DefaultSortOrder holds the default value on creation for the sort_order field.
|
||||||
|
games.DefaultSortOrder = gamesDescSortOrder.Default.(int)
|
||||||
|
// gamesDescIsActive is the schema descriptor for is_active field.
|
||||||
|
gamesDescIsActive := gamesFields[5].Descriptor()
|
||||||
|
// games.DefaultIsActive holds the default value on creation for the is_active field.
|
||||||
|
games.DefaultIsActive = gamesDescIsActive.Default.(bool)
|
||||||
|
// gamesDescCreatedAt is the schema descriptor for created_at field.
|
||||||
|
gamesDescCreatedAt := gamesFields[6].Descriptor()
|
||||||
|
// games.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
|
games.DefaultCreatedAt = gamesDescCreatedAt.Default.(func() time.Time)
|
||||||
|
// gamesDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
|
gamesDescUpdatedAt := gamesFields[7].Descriptor()
|
||||||
|
// games.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
|
games.DefaultUpdatedAt = gamesDescUpdatedAt.Default.(func() time.Time)
|
||||||
|
// games.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||||
|
games.UpdateDefaultUpdatedAt = gamesDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package runtime
|
||||||
|
|
||||||
|
// The schema-stitching logic is generated in juwan-backend/app/game/rpc/internal/models/runtime.go
|
||||||
|
|
||||||
|
const (
|
||||||
|
Version = "v0.14.5" // Version of ent codegen.
|
||||||
|
Sum = "h1:Rj2WOYJtCkWyFo6a+5wB3EfBRP0rnx1fMk6gGA0UUe4=" // Sum of ent codegen.
|
||||||
|
)
|
||||||
@@ -0,0 +1,210 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Tx is a transactional client that is created by calling Client.Tx().
|
||||||
|
type Tx struct {
|
||||||
|
config
|
||||||
|
// Games is the client for interacting with the Games builders.
|
||||||
|
Games *GamesClient
|
||||||
|
|
||||||
|
// lazily loaded.
|
||||||
|
client *Client
|
||||||
|
clientOnce sync.Once
|
||||||
|
// ctx lives for the life of the transaction. It is
|
||||||
|
// the same context used by the underlying connection.
|
||||||
|
ctx context.Context
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Committer is the interface that wraps the Commit method.
|
||||||
|
Committer interface {
|
||||||
|
Commit(context.Context, *Tx) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// The CommitFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as a Committer. If f is a function with the appropriate
|
||||||
|
// signature, CommitFunc(f) is a Committer that calls f.
|
||||||
|
CommitFunc func(context.Context, *Tx) error
|
||||||
|
|
||||||
|
// CommitHook defines the "commit middleware". A function that gets a Committer
|
||||||
|
// and returns a Committer. For example:
|
||||||
|
//
|
||||||
|
// hook := func(next ent.Committer) ent.Committer {
|
||||||
|
// return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error {
|
||||||
|
// // Do some stuff before.
|
||||||
|
// if err := next.Commit(ctx, tx); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// // Do some stuff after.
|
||||||
|
// return nil
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
CommitHook func(Committer) Committer
|
||||||
|
)
|
||||||
|
|
||||||
|
// Commit calls f(ctx, m).
|
||||||
|
func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error {
|
||||||
|
return f(ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit commits the transaction.
|
||||||
|
func (tx *Tx) Commit() error {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
var fn Committer = CommitFunc(func(context.Context, *Tx) error {
|
||||||
|
return txDriver.tx.Commit()
|
||||||
|
})
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
hooks := append([]CommitHook(nil), txDriver.onCommit...)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
fn = hooks[i](fn)
|
||||||
|
}
|
||||||
|
return fn.Commit(tx.ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnCommit adds a hook to call on commit.
|
||||||
|
func (tx *Tx) OnCommit(f CommitHook) {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
txDriver.onCommit = append(txDriver.onCommit, f)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Rollbacker is the interface that wraps the Rollback method.
|
||||||
|
Rollbacker interface {
|
||||||
|
Rollback(context.Context, *Tx) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// The RollbackFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as a Rollbacker. If f is a function with the appropriate
|
||||||
|
// signature, RollbackFunc(f) is a Rollbacker that calls f.
|
||||||
|
RollbackFunc func(context.Context, *Tx) error
|
||||||
|
|
||||||
|
// RollbackHook defines the "rollback middleware". A function that gets a Rollbacker
|
||||||
|
// and returns a Rollbacker. For example:
|
||||||
|
//
|
||||||
|
// hook := func(next ent.Rollbacker) ent.Rollbacker {
|
||||||
|
// return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error {
|
||||||
|
// // Do some stuff before.
|
||||||
|
// if err := next.Rollback(ctx, tx); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// // Do some stuff after.
|
||||||
|
// return nil
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
RollbackHook func(Rollbacker) Rollbacker
|
||||||
|
)
|
||||||
|
|
||||||
|
// Rollback calls f(ctx, m).
|
||||||
|
func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error {
|
||||||
|
return f(ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rollback rollbacks the transaction.
|
||||||
|
func (tx *Tx) Rollback() error {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error {
|
||||||
|
return txDriver.tx.Rollback()
|
||||||
|
})
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
hooks := append([]RollbackHook(nil), txDriver.onRollback...)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
fn = hooks[i](fn)
|
||||||
|
}
|
||||||
|
return fn.Rollback(tx.ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnRollback adds a hook to call on rollback.
|
||||||
|
func (tx *Tx) OnRollback(f RollbackHook) {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
txDriver.onRollback = append(txDriver.onRollback, f)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client returns a Client that binds to current transaction.
|
||||||
|
func (tx *Tx) Client() *Client {
|
||||||
|
tx.clientOnce.Do(func() {
|
||||||
|
tx.client = &Client{config: tx.config}
|
||||||
|
tx.client.init()
|
||||||
|
})
|
||||||
|
return tx.client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tx *Tx) init() {
|
||||||
|
tx.Games = NewGamesClient(tx.config)
|
||||||
|
}
|
||||||
|
|
||||||
|
// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation.
|
||||||
|
// The idea is to support transactions without adding any extra code to the builders.
|
||||||
|
// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance.
|
||||||
|
// Commit and Rollback are nop for the internal builders and the user must call one
|
||||||
|
// of them in order to commit or rollback the transaction.
|
||||||
|
//
|
||||||
|
// If a closed transaction is embedded in one of the generated entities, and the entity
|
||||||
|
// applies a query, for example: Games.QueryXXX(), the query will be executed
|
||||||
|
// through the driver which created this transaction.
|
||||||
|
//
|
||||||
|
// Note that txDriver is not goroutine safe.
|
||||||
|
type txDriver struct {
|
||||||
|
// the driver we started the transaction from.
|
||||||
|
drv dialect.Driver
|
||||||
|
// tx is the underlying transaction.
|
||||||
|
tx dialect.Tx
|
||||||
|
// completion hooks.
|
||||||
|
mu sync.Mutex
|
||||||
|
onCommit []CommitHook
|
||||||
|
onRollback []RollbackHook
|
||||||
|
}
|
||||||
|
|
||||||
|
// newTx creates a new transactional driver.
|
||||||
|
func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) {
|
||||||
|
tx, err := drv.Tx(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &txDriver{tx: tx, drv: drv}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls
|
||||||
|
// from the internal builders. Should be called only by the internal builders.
|
||||||
|
func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil }
|
||||||
|
|
||||||
|
// Dialect returns the dialect of the driver we started the transaction from.
|
||||||
|
func (tx *txDriver) Dialect() string { return tx.drv.Dialect() }
|
||||||
|
|
||||||
|
// Close is a nop close.
|
||||||
|
func (*txDriver) Close() error { return nil }
|
||||||
|
|
||||||
|
// Commit is a nop commit for the internal builders.
|
||||||
|
// User must call `Tx.Commit` in order to commit the transaction.
|
||||||
|
func (*txDriver) Commit() error { return nil }
|
||||||
|
|
||||||
|
// Rollback is a nop rollback for the internal builders.
|
||||||
|
// User must call `Tx.Rollback` in order to rollback the transaction.
|
||||||
|
func (*txDriver) Rollback() error { return nil }
|
||||||
|
|
||||||
|
// Exec calls tx.Exec.
|
||||||
|
func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error {
|
||||||
|
return tx.tx.Exec(ctx, query, args, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query calls tx.Query.
|
||||||
|
func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error {
|
||||||
|
return tx.tx.Query(ctx, query, args, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ dialect.Driver = (*txDriver)(nil)
|
||||||
@@ -1,180 +0,0 @@
|
|||||||
// Code generated by goctl. DO NOT EDIT.
|
|
||||||
// goctl 1.9.2
|
|
||||||
// Source: game.proto
|
|
||||||
|
|
||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"juwan-backend/app/game/rpc/internal/logic"
|
|
||||||
"juwan-backend/app/game/rpc/internal/svc"
|
|
||||||
"juwan-backend/app/game/rpc/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
type GamePublicServer struct {
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
pb.UnimplementedGamePublicServer
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewGamePublicServer(svcCtx *svc.ServiceContext) *GamePublicServer {
|
|
||||||
return &GamePublicServer{
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------games-----------------------
|
|
||||||
func (s *GamePublicServer) AddGames(ctx context.Context, in *pb.AddGamesReq) (*pb.AddGamesResp, error) {
|
|
||||||
l := logic.NewAddGamesLogic(ctx, s.svcCtx)
|
|
||||||
return l.AddGames(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) UpdateGames(ctx context.Context, in *pb.UpdateGamesReq) (*pb.UpdateGamesResp, error) {
|
|
||||||
l := logic.NewUpdateGamesLogic(ctx, s.svcCtx)
|
|
||||||
return l.UpdateGames(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) DelGames(ctx context.Context, in *pb.DelGamesReq) (*pb.DelGamesResp, error) {
|
|
||||||
l := logic.NewDelGamesLogic(ctx, s.svcCtx)
|
|
||||||
return l.DelGames(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) GetGamesById(ctx context.Context, in *pb.GetGamesByIdReq) (*pb.GetGamesByIdResp, error) {
|
|
||||||
l := logic.NewGetGamesByIdLogic(ctx, s.svcCtx)
|
|
||||||
return l.GetGamesById(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) SearchGames(ctx context.Context, in *pb.SearchGamesReq) (*pb.SearchGamesResp, error) {
|
|
||||||
l := logic.NewSearchGamesLogic(ctx, s.svcCtx)
|
|
||||||
return l.SearchGames(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------playerServices-----------------------
|
|
||||||
func (s *GamePublicServer) AddPlayerServices(ctx context.Context, in *pb.AddPlayerServicesReq) (*pb.AddPlayerServicesResp, error) {
|
|
||||||
l := logic.NewAddPlayerServicesLogic(ctx, s.svcCtx)
|
|
||||||
return l.AddPlayerServices(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) UpdatePlayerServices(ctx context.Context, in *pb.UpdatePlayerServicesReq) (*pb.UpdatePlayerServicesResp, error) {
|
|
||||||
l := logic.NewUpdatePlayerServicesLogic(ctx, s.svcCtx)
|
|
||||||
return l.UpdatePlayerServices(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) DelPlayerServices(ctx context.Context, in *pb.DelPlayerServicesReq) (*pb.DelPlayerServicesResp, error) {
|
|
||||||
l := logic.NewDelPlayerServicesLogic(ctx, s.svcCtx)
|
|
||||||
return l.DelPlayerServices(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) GetPlayerServicesById(ctx context.Context, in *pb.GetPlayerServicesByIdReq) (*pb.GetPlayerServicesByIdResp, error) {
|
|
||||||
l := logic.NewGetPlayerServicesByIdLogic(ctx, s.svcCtx)
|
|
||||||
return l.GetPlayerServicesById(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) SearchPlayerServices(ctx context.Context, in *pb.SearchPlayerServicesReq) (*pb.SearchPlayerServicesResp, error) {
|
|
||||||
l := logic.NewSearchPlayerServicesLogic(ctx, s.svcCtx)
|
|
||||||
return l.SearchPlayerServices(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------players-----------------------
|
|
||||||
func (s *GamePublicServer) AddPlayers(ctx context.Context, in *pb.AddPlayersReq) (*pb.AddPlayersResp, error) {
|
|
||||||
l := logic.NewAddPlayersLogic(ctx, s.svcCtx)
|
|
||||||
return l.AddPlayers(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) UpdatePlayers(ctx context.Context, in *pb.UpdatePlayersReq) (*pb.UpdatePlayersResp, error) {
|
|
||||||
l := logic.NewUpdatePlayersLogic(ctx, s.svcCtx)
|
|
||||||
return l.UpdatePlayers(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) DelPlayers(ctx context.Context, in *pb.DelPlayersReq) (*pb.DelPlayersResp, error) {
|
|
||||||
l := logic.NewDelPlayersLogic(ctx, s.svcCtx)
|
|
||||||
return l.DelPlayers(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) GetPlayersById(ctx context.Context, in *pb.GetPlayersByIdReq) (*pb.GetPlayersByIdResp, error) {
|
|
||||||
l := logic.NewGetPlayersByIdLogic(ctx, s.svcCtx)
|
|
||||||
return l.GetPlayersById(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) SearchPlayers(ctx context.Context, in *pb.SearchPlayersReq) (*pb.SearchPlayersResp, error) {
|
|
||||||
l := logic.NewSearchPlayersLogic(ctx, s.svcCtx)
|
|
||||||
return l.SearchPlayers(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------shopInvitations-----------------------
|
|
||||||
func (s *GamePublicServer) AddShopInvitations(ctx context.Context, in *pb.AddShopInvitationsReq) (*pb.AddShopInvitationsResp, error) {
|
|
||||||
l := logic.NewAddShopInvitationsLogic(ctx, s.svcCtx)
|
|
||||||
return l.AddShopInvitations(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) UpdateShopInvitations(ctx context.Context, in *pb.UpdateShopInvitationsReq) (*pb.UpdateShopInvitationsResp, error) {
|
|
||||||
l := logic.NewUpdateShopInvitationsLogic(ctx, s.svcCtx)
|
|
||||||
return l.UpdateShopInvitations(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) DelShopInvitations(ctx context.Context, in *pb.DelShopInvitationsReq) (*pb.DelShopInvitationsResp, error) {
|
|
||||||
l := logic.NewDelShopInvitationsLogic(ctx, s.svcCtx)
|
|
||||||
return l.DelShopInvitations(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) GetShopInvitationsById(ctx context.Context, in *pb.GetShopInvitationsByIdReq) (*pb.GetShopInvitationsByIdResp, error) {
|
|
||||||
l := logic.NewGetShopInvitationsByIdLogic(ctx, s.svcCtx)
|
|
||||||
return l.GetShopInvitationsById(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) SearchShopInvitations(ctx context.Context, in *pb.SearchShopInvitationsReq) (*pb.SearchShopInvitationsResp, error) {
|
|
||||||
l := logic.NewSearchShopInvitationsLogic(ctx, s.svcCtx)
|
|
||||||
return l.SearchShopInvitations(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------shopPlayers-----------------------
|
|
||||||
func (s *GamePublicServer) AddShopPlayers(ctx context.Context, in *pb.AddShopPlayersReq) (*pb.AddShopPlayersResp, error) {
|
|
||||||
l := logic.NewAddShopPlayersLogic(ctx, s.svcCtx)
|
|
||||||
return l.AddShopPlayers(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) UpdateShopPlayers(ctx context.Context, in *pb.UpdateShopPlayersReq) (*pb.UpdateShopPlayersResp, error) {
|
|
||||||
l := logic.NewUpdateShopPlayersLogic(ctx, s.svcCtx)
|
|
||||||
return l.UpdateShopPlayers(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) DelShopPlayers(ctx context.Context, in *pb.DelShopPlayersReq) (*pb.DelShopPlayersResp, error) {
|
|
||||||
l := logic.NewDelShopPlayersLogic(ctx, s.svcCtx)
|
|
||||||
return l.DelShopPlayers(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) GetShopPlayersById(ctx context.Context, in *pb.GetShopPlayersByIdReq) (*pb.GetShopPlayersByIdResp, error) {
|
|
||||||
l := logic.NewGetShopPlayersByIdLogic(ctx, s.svcCtx)
|
|
||||||
return l.GetShopPlayersById(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) SearchShopPlayers(ctx context.Context, in *pb.SearchShopPlayersReq) (*pb.SearchShopPlayersResp, error) {
|
|
||||||
l := logic.NewSearchShopPlayersLogic(ctx, s.svcCtx)
|
|
||||||
return l.SearchShopPlayers(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------shops-----------------------
|
|
||||||
func (s *GamePublicServer) AddShops(ctx context.Context, in *pb.AddShopsReq) (*pb.AddShopsResp, error) {
|
|
||||||
l := logic.NewAddShopsLogic(ctx, s.svcCtx)
|
|
||||||
return l.AddShops(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) UpdateShops(ctx context.Context, in *pb.UpdateShopsReq) (*pb.UpdateShopsResp, error) {
|
|
||||||
l := logic.NewUpdateShopsLogic(ctx, s.svcCtx)
|
|
||||||
return l.UpdateShops(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) DelShops(ctx context.Context, in *pb.DelShopsReq) (*pb.DelShopsResp, error) {
|
|
||||||
l := logic.NewDelShopsLogic(ctx, s.svcCtx)
|
|
||||||
return l.DelShops(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) GetShopsById(ctx context.Context, in *pb.GetShopsByIdReq) (*pb.GetShopsByIdResp, error) {
|
|
||||||
l := logic.NewGetShopsByIdLogic(ctx, s.svcCtx)
|
|
||||||
return l.GetShopsById(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GamePublicServer) SearchShops(ctx context.Context, in *pb.SearchShopsReq) (*pb.SearchShopsResp, error) {
|
|
||||||
l := logic.NewSearchShopsLogic(ctx, s.svcCtx)
|
|
||||||
return l.SearchShops(in)
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
// goctl 1.9.2
|
||||||
|
// Source: game.proto
|
||||||
|
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/game/rpc/internal/logic"
|
||||||
|
"juwan-backend/app/game/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/game/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GameServiceServer struct {
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
pb.UnimplementedGameServiceServer
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGameServiceServer(svcCtx *svc.ServiceContext) *GameServiceServer {
|
||||||
|
return &GameServiceServer{
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------games-----------------------
|
||||||
|
func (s *GameServiceServer) AddGames(ctx context.Context, in *pb.AddGamesReq) (*pb.AddGamesResp, error) {
|
||||||
|
l := logic.NewAddGamesLogic(ctx, s.svcCtx)
|
||||||
|
return l.AddGames(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GameServiceServer) UpdateGames(ctx context.Context, in *pb.UpdateGamesReq) (*pb.UpdateGamesResp, error) {
|
||||||
|
l := logic.NewUpdateGamesLogic(ctx, s.svcCtx)
|
||||||
|
return l.UpdateGames(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GameServiceServer) DelGames(ctx context.Context, in *pb.DelGamesReq) (*pb.DelGamesResp, error) {
|
||||||
|
l := logic.NewDelGamesLogic(ctx, s.svcCtx)
|
||||||
|
return l.DelGames(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GameServiceServer) GetGamesById(ctx context.Context, in *pb.GetGamesByIdReq) (*pb.GetGamesByIdResp, error) {
|
||||||
|
l := logic.NewGetGamesByIdLogic(ctx, s.svcCtx)
|
||||||
|
return l.GetGamesById(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GameServiceServer) SearchGames(ctx context.Context, in *pb.SearchGamesReq) (*pb.SearchGamesResp, error) {
|
||||||
|
l := logic.NewSearchGamesLogic(ctx, s.svcCtx)
|
||||||
|
return l.SearchGames(in)
|
||||||
|
}
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
// Code generated by goctl. DO NOT EDIT.
|
|
||||||
// goctl 1.9.2
|
|
||||||
// Source: game.proto
|
|
||||||
|
|
||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"juwan-backend/app/game/rpc/internal/logic"
|
|
||||||
"juwan-backend/app/game/rpc/internal/svc"
|
|
||||||
"juwan-backend/app/game/rpc/pb"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PublicServer struct {
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
pb.UnimplementedPublicServer
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewPublicServer(svcCtx *svc.ServiceContext) *PublicServer {
|
|
||||||
return &PublicServer{
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------games-----------------------
|
|
||||||
func (s *PublicServer) AddGames(ctx context.Context, in *pb.AddGamesReq) (*pb.AddGamesResp, error) {
|
|
||||||
l := logic.NewAddGamesLogic(ctx, s.svcCtx)
|
|
||||||
return l.AddGames(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *PublicServer) UpdateGames(ctx context.Context, in *pb.UpdateGamesReq) (*pb.UpdateGamesResp, error) {
|
|
||||||
l := logic.NewUpdateGamesLogic(ctx, s.svcCtx)
|
|
||||||
return l.UpdateGames(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *PublicServer) DelGames(ctx context.Context, in *pb.DelGamesReq) (*pb.DelGamesResp, error) {
|
|
||||||
l := logic.NewDelGamesLogic(ctx, s.svcCtx)
|
|
||||||
return l.DelGames(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *PublicServer) GetGamesById(ctx context.Context, in *pb.GetGamesByIdReq) (*pb.GetGamesByIdResp, error) {
|
|
||||||
l := logic.NewGetGamesByIdLogic(ctx, s.svcCtx)
|
|
||||||
return l.GetGamesById(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *PublicServer) SearchGames(ctx context.Context, in *pb.SearchGamesReq) (*pb.SearchGamesResp, error) {
|
|
||||||
l := logic.NewSearchGamesLogic(ctx, s.svcCtx)
|
|
||||||
return l.SearchGames(in)
|
|
||||||
}
|
|
||||||
@@ -12,6 +12,8 @@ import (
|
|||||||
"ariga.io/entcache"
|
"ariga.io/entcache"
|
||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
|
||||||
|
_ "github.com/jackc/pgx/v5/stdlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
|
|||||||
+2
-2
@@ -22,11 +22,11 @@ func main() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.MustLoad(*configFile, &c)
|
conf.MustLoad(*configFile, &c, conf.UseEnv())
|
||||||
ctx := svc.NewServiceContext(c)
|
ctx := svc.NewServiceContext(c)
|
||||||
|
|
||||||
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
||||||
pb.RegisterGamePublicServer(grpcServer, server.NewGamePublicServer(ctx))
|
pb.RegisterGameServiceServer(grpcServer, server.NewGameServiceServer(ctx))
|
||||||
|
|
||||||
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
||||||
reflection.Register(grpcServer)
|
reflection.Register(grpcServer)
|
||||||
|
|||||||
+53
-42
@@ -559,13 +559,13 @@ type SearchGamesReq struct {
|
|||||||
Page int64 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"` //page
|
Page int64 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"` //page
|
||||||
Limit int64 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"` //limit
|
Limit int64 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"` //limit
|
||||||
Id int64 `protobuf:"varint,3,opt,name=id,proto3" json:"id,omitempty"` //id
|
Id int64 `protobuf:"varint,3,opt,name=id,proto3" json:"id,omitempty"` //id
|
||||||
Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"` //name
|
Name *string `protobuf:"bytes,4,opt,name=name,proto3,oneof" json:"name,omitempty"` //name
|
||||||
Icon string `protobuf:"bytes,5,opt,name=icon,proto3" json:"icon,omitempty"` //icon
|
Icon *string `protobuf:"bytes,5,opt,name=icon,proto3,oneof" json:"icon,omitempty"` //icon
|
||||||
Category string `protobuf:"bytes,6,opt,name=category,proto3" json:"category,omitempty"` //category
|
Category *string `protobuf:"bytes,6,opt,name=category,proto3,oneof" json:"category,omitempty"` //category
|
||||||
SortOrder int64 `protobuf:"varint,7,opt,name=sortOrder,proto3" json:"sortOrder,omitempty"` //sortOrder
|
SortOrder *int64 `protobuf:"varint,7,opt,name=sortOrder,proto3,oneof" json:"sortOrder,omitempty"` //sortOrder
|
||||||
IsActive bool `protobuf:"varint,8,opt,name=isActive,proto3" json:"isActive,omitempty"` //isActive
|
IsActive *bool `protobuf:"varint,8,opt,name=isActive,proto3,oneof" json:"isActive,omitempty"` //isActive
|
||||||
CreatedAt int64 `protobuf:"varint,9,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt
|
CreatedAt *int64 `protobuf:"varint,9,opt,name=createdAt,proto3,oneof" json:"createdAt,omitempty"` //createdAt
|
||||||
UpdatedAt int64 `protobuf:"varint,10,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt
|
UpdatedAt *int64 `protobuf:"varint,10,opt,name=updatedAt,proto3,oneof" json:"updatedAt,omitempty"` //updatedAt
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
@@ -622,50 +622,50 @@ func (x *SearchGamesReq) GetId() int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchGamesReq) GetName() string {
|
func (x *SearchGamesReq) GetName() string {
|
||||||
if x != nil {
|
if x != nil && x.Name != nil {
|
||||||
return x.Name
|
return *x.Name
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchGamesReq) GetIcon() string {
|
func (x *SearchGamesReq) GetIcon() string {
|
||||||
if x != nil {
|
if x != nil && x.Icon != nil {
|
||||||
return x.Icon
|
return *x.Icon
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchGamesReq) GetCategory() string {
|
func (x *SearchGamesReq) GetCategory() string {
|
||||||
if x != nil {
|
if x != nil && x.Category != nil {
|
||||||
return x.Category
|
return *x.Category
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchGamesReq) GetSortOrder() int64 {
|
func (x *SearchGamesReq) GetSortOrder() int64 {
|
||||||
if x != nil {
|
if x != nil && x.SortOrder != nil {
|
||||||
return x.SortOrder
|
return *x.SortOrder
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchGamesReq) GetIsActive() bool {
|
func (x *SearchGamesReq) GetIsActive() bool {
|
||||||
if x != nil {
|
if x != nil && x.IsActive != nil {
|
||||||
return x.IsActive
|
return *x.IsActive
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchGamesReq) GetCreatedAt() int64 {
|
func (x *SearchGamesReq) GetCreatedAt() int64 {
|
||||||
if x != nil {
|
if x != nil && x.CreatedAt != nil {
|
||||||
return x.CreatedAt
|
return *x.CreatedAt
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchGamesReq) GetUpdatedAt() int64 {
|
func (x *SearchGamesReq) GetUpdatedAt() int64 {
|
||||||
if x != nil {
|
if x != nil && x.UpdatedAt != nil {
|
||||||
return x.UpdatedAt
|
return *x.UpdatedAt
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -754,22 +754,32 @@ const file_game_proto_rawDesc = "" +
|
|||||||
"\x0fGetGamesByIdReq\x12\x0e\n" +
|
"\x0fGetGamesByIdReq\x12\x0e\n" +
|
||||||
"\x02id\x18\x01 \x01(\x03R\x02id\"3\n" +
|
"\x02id\x18\x01 \x01(\x03R\x02id\"3\n" +
|
||||||
"\x10GetGamesByIdResp\x12\x1f\n" +
|
"\x10GetGamesByIdResp\x12\x1f\n" +
|
||||||
"\x05games\x18\x01 \x01(\v2\t.pb.GamesR\x05games\"\x84\x02\n" +
|
"\x05games\x18\x01 \x01(\v2\t.pb.GamesR\x05games\"\xfd\x02\n" +
|
||||||
"\x0eSearchGamesReq\x12\x12\n" +
|
"\x0eSearchGamesReq\x12\x12\n" +
|
||||||
"\x04page\x18\x01 \x01(\x03R\x04page\x12\x14\n" +
|
"\x04page\x18\x01 \x01(\x03R\x04page\x12\x14\n" +
|
||||||
"\x05limit\x18\x02 \x01(\x03R\x05limit\x12\x0e\n" +
|
"\x05limit\x18\x02 \x01(\x03R\x05limit\x12\x0e\n" +
|
||||||
"\x02id\x18\x03 \x01(\x03R\x02id\x12\x12\n" +
|
"\x02id\x18\x03 \x01(\x03R\x02id\x12\x17\n" +
|
||||||
"\x04name\x18\x04 \x01(\tR\x04name\x12\x12\n" +
|
"\x04name\x18\x04 \x01(\tH\x00R\x04name\x88\x01\x01\x12\x17\n" +
|
||||||
"\x04icon\x18\x05 \x01(\tR\x04icon\x12\x1a\n" +
|
"\x04icon\x18\x05 \x01(\tH\x01R\x04icon\x88\x01\x01\x12\x1f\n" +
|
||||||
"\bcategory\x18\x06 \x01(\tR\bcategory\x12\x1c\n" +
|
"\bcategory\x18\x06 \x01(\tH\x02R\bcategory\x88\x01\x01\x12!\n" +
|
||||||
"\tsortOrder\x18\a \x01(\x03R\tsortOrder\x12\x1a\n" +
|
"\tsortOrder\x18\a \x01(\x03H\x03R\tsortOrder\x88\x01\x01\x12\x1f\n" +
|
||||||
"\bisActive\x18\b \x01(\bR\bisActive\x12\x1c\n" +
|
"\bisActive\x18\b \x01(\bH\x04R\bisActive\x88\x01\x01\x12!\n" +
|
||||||
"\tcreatedAt\x18\t \x01(\x03R\tcreatedAt\x12\x1c\n" +
|
"\tcreatedAt\x18\t \x01(\x03H\x05R\tcreatedAt\x88\x01\x01\x12!\n" +
|
||||||
"\tupdatedAt\x18\n" +
|
"\tupdatedAt\x18\n" +
|
||||||
" \x01(\x03R\tupdatedAt\"2\n" +
|
" \x01(\x03H\x06R\tupdatedAt\x88\x01\x01B\a\n" +
|
||||||
|
"\x05_nameB\a\n" +
|
||||||
|
"\x05_iconB\v\n" +
|
||||||
|
"\t_categoryB\f\n" +
|
||||||
|
"\n" +
|
||||||
|
"_sortOrderB\v\n" +
|
||||||
|
"\t_isActiveB\f\n" +
|
||||||
|
"\n" +
|
||||||
|
"_createdAtB\f\n" +
|
||||||
|
"\n" +
|
||||||
|
"_updatedAt\"2\n" +
|
||||||
"\x0fSearchGamesResp\x12\x1f\n" +
|
"\x0fSearchGamesResp\x12\x1f\n" +
|
||||||
"\x05games\x18\x01 \x03(\v2\t.pb.GamesR\x05games2\x91\x02\n" +
|
"\x05games\x18\x01 \x03(\v2\t.pb.GamesR\x05games2\x96\x02\n" +
|
||||||
"\x06public\x12-\n" +
|
"\vGameService\x12-\n" +
|
||||||
"\bAddGames\x12\x0f.pb.AddGamesReq\x1a\x10.pb.AddGamesResp\x126\n" +
|
"\bAddGames\x12\x0f.pb.AddGamesReq\x1a\x10.pb.AddGamesResp\x126\n" +
|
||||||
"\vUpdateGames\x12\x12.pb.UpdateGamesReq\x1a\x13.pb.UpdateGamesResp\x12-\n" +
|
"\vUpdateGames\x12\x12.pb.UpdateGamesReq\x1a\x13.pb.UpdateGamesResp\x12-\n" +
|
||||||
"\bDelGames\x12\x0f.pb.DelGamesReq\x1a\x10.pb.DelGamesResp\x129\n" +
|
"\bDelGames\x12\x0f.pb.DelGamesReq\x1a\x10.pb.DelGamesResp\x129\n" +
|
||||||
@@ -805,16 +815,16 @@ var file_game_proto_goTypes = []any{
|
|||||||
var file_game_proto_depIdxs = []int32{
|
var file_game_proto_depIdxs = []int32{
|
||||||
0, // 0: pb.GetGamesByIdResp.games:type_name -> pb.Games
|
0, // 0: pb.GetGamesByIdResp.games:type_name -> pb.Games
|
||||||
0, // 1: pb.SearchGamesResp.games:type_name -> pb.Games
|
0, // 1: pb.SearchGamesResp.games:type_name -> pb.Games
|
||||||
1, // 2: pb.public.AddGames:input_type -> pb.AddGamesReq
|
1, // 2: pb.GameService.AddGames:input_type -> pb.AddGamesReq
|
||||||
3, // 3: pb.public.UpdateGames:input_type -> pb.UpdateGamesReq
|
3, // 3: pb.GameService.UpdateGames:input_type -> pb.UpdateGamesReq
|
||||||
5, // 4: pb.public.DelGames:input_type -> pb.DelGamesReq
|
5, // 4: pb.GameService.DelGames:input_type -> pb.DelGamesReq
|
||||||
7, // 5: pb.public.GetGamesById:input_type -> pb.GetGamesByIdReq
|
7, // 5: pb.GameService.GetGamesById:input_type -> pb.GetGamesByIdReq
|
||||||
9, // 6: pb.public.SearchGames:input_type -> pb.SearchGamesReq
|
9, // 6: pb.GameService.SearchGames:input_type -> pb.SearchGamesReq
|
||||||
2, // 7: pb.public.AddGames:output_type -> pb.AddGamesResp
|
2, // 7: pb.GameService.AddGames:output_type -> pb.AddGamesResp
|
||||||
4, // 8: pb.public.UpdateGames:output_type -> pb.UpdateGamesResp
|
4, // 8: pb.GameService.UpdateGames:output_type -> pb.UpdateGamesResp
|
||||||
6, // 9: pb.public.DelGames:output_type -> pb.DelGamesResp
|
6, // 9: pb.GameService.DelGames:output_type -> pb.DelGamesResp
|
||||||
8, // 10: pb.public.GetGamesById:output_type -> pb.GetGamesByIdResp
|
8, // 10: pb.GameService.GetGamesById:output_type -> pb.GetGamesByIdResp
|
||||||
10, // 11: pb.public.SearchGames:output_type -> pb.SearchGamesResp
|
10, // 11: pb.GameService.SearchGames:output_type -> pb.SearchGamesResp
|
||||||
7, // [7:12] is the sub-list for method output_type
|
7, // [7:12] is the sub-list for method output_type
|
||||||
2, // [2:7] is the sub-list for method input_type
|
2, // [2:7] is the sub-list for method input_type
|
||||||
2, // [2:2] is the sub-list for extension type_name
|
2, // [2:2] is the sub-list for extension type_name
|
||||||
@@ -827,6 +837,7 @@ func file_game_proto_init() {
|
|||||||
if File_game_proto != nil {
|
if File_game_proto != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
file_game_proto_msgTypes[9].OneofWrappers = []any{}
|
||||||
type x struct{}
|
type x struct{}
|
||||||
out := protoimpl.TypeBuilder{
|
out := protoimpl.TypeBuilder{
|
||||||
File: protoimpl.DescBuilder{
|
File: protoimpl.DescBuilder{
|
||||||
|
|||||||
@@ -19,17 +19,17 @@ import (
|
|||||||
const _ = grpc.SupportPackageIsVersion9
|
const _ = grpc.SupportPackageIsVersion9
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Public_AddGames_FullMethodName = "/pb.public/AddGames"
|
GameService_AddGames_FullMethodName = "/pb.GameService/AddGames"
|
||||||
Public_UpdateGames_FullMethodName = "/pb.public/UpdateGames"
|
GameService_UpdateGames_FullMethodName = "/pb.GameService/UpdateGames"
|
||||||
Public_DelGames_FullMethodName = "/pb.public/DelGames"
|
GameService_DelGames_FullMethodName = "/pb.GameService/DelGames"
|
||||||
Public_GetGamesById_FullMethodName = "/pb.public/GetGamesById"
|
GameService_GetGamesById_FullMethodName = "/pb.GameService/GetGamesById"
|
||||||
Public_SearchGames_FullMethodName = "/pb.public/SearchGames"
|
GameService_SearchGames_FullMethodName = "/pb.GameService/SearchGames"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PublicClient is the client API for Public service.
|
// GameServiceClient is the client API for GameService 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.
|
// 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 PublicClient interface {
|
type GameServiceClient interface {
|
||||||
// -----------------------games-----------------------
|
// -----------------------games-----------------------
|
||||||
AddGames(ctx context.Context, in *AddGamesReq, opts ...grpc.CallOption) (*AddGamesResp, error)
|
AddGames(ctx context.Context, in *AddGamesReq, opts ...grpc.CallOption) (*AddGamesResp, error)
|
||||||
UpdateGames(ctx context.Context, in *UpdateGamesReq, opts ...grpc.CallOption) (*UpdateGamesResp, error)
|
UpdateGames(ctx context.Context, in *UpdateGamesReq, opts ...grpc.CallOption) (*UpdateGamesResp, error)
|
||||||
@@ -38,236 +38,236 @@ type PublicClient interface {
|
|||||||
SearchGames(ctx context.Context, in *SearchGamesReq, opts ...grpc.CallOption) (*SearchGamesResp, error)
|
SearchGames(ctx context.Context, in *SearchGamesReq, opts ...grpc.CallOption) (*SearchGamesResp, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type publicClient struct {
|
type gameServiceClient struct {
|
||||||
cc grpc.ClientConnInterface
|
cc grpc.ClientConnInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPublicClient(cc grpc.ClientConnInterface) PublicClient {
|
func NewGameServiceClient(cc grpc.ClientConnInterface) GameServiceClient {
|
||||||
return &publicClient{cc}
|
return &gameServiceClient{cc}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *publicClient) AddGames(ctx context.Context, in *AddGamesReq, opts ...grpc.CallOption) (*AddGamesResp, error) {
|
func (c *gameServiceClient) AddGames(ctx context.Context, in *AddGamesReq, opts ...grpc.CallOption) (*AddGamesResp, error) {
|
||||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
out := new(AddGamesResp)
|
out := new(AddGamesResp)
|
||||||
err := c.cc.Invoke(ctx, Public_AddGames_FullMethodName, in, out, cOpts...)
|
err := c.cc.Invoke(ctx, GameService_AddGames_FullMethodName, in, out, cOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *publicClient) UpdateGames(ctx context.Context, in *UpdateGamesReq, opts ...grpc.CallOption) (*UpdateGamesResp, error) {
|
func (c *gameServiceClient) UpdateGames(ctx context.Context, in *UpdateGamesReq, opts ...grpc.CallOption) (*UpdateGamesResp, error) {
|
||||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
out := new(UpdateGamesResp)
|
out := new(UpdateGamesResp)
|
||||||
err := c.cc.Invoke(ctx, Public_UpdateGames_FullMethodName, in, out, cOpts...)
|
err := c.cc.Invoke(ctx, GameService_UpdateGames_FullMethodName, in, out, cOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *publicClient) DelGames(ctx context.Context, in *DelGamesReq, opts ...grpc.CallOption) (*DelGamesResp, error) {
|
func (c *gameServiceClient) DelGames(ctx context.Context, in *DelGamesReq, opts ...grpc.CallOption) (*DelGamesResp, error) {
|
||||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
out := new(DelGamesResp)
|
out := new(DelGamesResp)
|
||||||
err := c.cc.Invoke(ctx, Public_DelGames_FullMethodName, in, out, cOpts...)
|
err := c.cc.Invoke(ctx, GameService_DelGames_FullMethodName, in, out, cOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *publicClient) GetGamesById(ctx context.Context, in *GetGamesByIdReq, opts ...grpc.CallOption) (*GetGamesByIdResp, error) {
|
func (c *gameServiceClient) GetGamesById(ctx context.Context, in *GetGamesByIdReq, opts ...grpc.CallOption) (*GetGamesByIdResp, error) {
|
||||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
out := new(GetGamesByIdResp)
|
out := new(GetGamesByIdResp)
|
||||||
err := c.cc.Invoke(ctx, Public_GetGamesById_FullMethodName, in, out, cOpts...)
|
err := c.cc.Invoke(ctx, GameService_GetGamesById_FullMethodName, in, out, cOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *publicClient) SearchGames(ctx context.Context, in *SearchGamesReq, opts ...grpc.CallOption) (*SearchGamesResp, error) {
|
func (c *gameServiceClient) SearchGames(ctx context.Context, in *SearchGamesReq, opts ...grpc.CallOption) (*SearchGamesResp, error) {
|
||||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
out := new(SearchGamesResp)
|
out := new(SearchGamesResp)
|
||||||
err := c.cc.Invoke(ctx, Public_SearchGames_FullMethodName, in, out, cOpts...)
|
err := c.cc.Invoke(ctx, GameService_SearchGames_FullMethodName, in, out, cOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PublicServer is the server API for Public service.
|
// GameServiceServer is the server API for GameService service.
|
||||||
// All implementations must embed UnimplementedPublicServer
|
// All implementations must embed UnimplementedGameServiceServer
|
||||||
// for forward compatibility.
|
// for forward compatibility.
|
||||||
type PublicServer interface {
|
type GameServiceServer interface {
|
||||||
// -----------------------games-----------------------
|
// -----------------------games-----------------------
|
||||||
AddGames(context.Context, *AddGamesReq) (*AddGamesResp, error)
|
AddGames(context.Context, *AddGamesReq) (*AddGamesResp, error)
|
||||||
UpdateGames(context.Context, *UpdateGamesReq) (*UpdateGamesResp, error)
|
UpdateGames(context.Context, *UpdateGamesReq) (*UpdateGamesResp, error)
|
||||||
DelGames(context.Context, *DelGamesReq) (*DelGamesResp, error)
|
DelGames(context.Context, *DelGamesReq) (*DelGamesResp, error)
|
||||||
GetGamesById(context.Context, *GetGamesByIdReq) (*GetGamesByIdResp, error)
|
GetGamesById(context.Context, *GetGamesByIdReq) (*GetGamesByIdResp, error)
|
||||||
SearchGames(context.Context, *SearchGamesReq) (*SearchGamesResp, error)
|
SearchGames(context.Context, *SearchGamesReq) (*SearchGamesResp, error)
|
||||||
mustEmbedUnimplementedPublicServer()
|
mustEmbedUnimplementedGameServiceServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnimplementedPublicServer must be embedded to have
|
// UnimplementedGameServiceServer must be embedded to have
|
||||||
// forward compatible implementations.
|
// forward compatible implementations.
|
||||||
//
|
//
|
||||||
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
||||||
// pointer dereference when methods are called.
|
// pointer dereference when methods are called.
|
||||||
type UnimplementedPublicServer struct{}
|
type UnimplementedGameServiceServer struct{}
|
||||||
|
|
||||||
func (UnimplementedPublicServer) AddGames(context.Context, *AddGamesReq) (*AddGamesResp, error) {
|
func (UnimplementedGameServiceServer) AddGames(context.Context, *AddGamesReq) (*AddGamesResp, error) {
|
||||||
return nil, status.Error(codes.Unimplemented, "method AddGames not implemented")
|
return nil, status.Error(codes.Unimplemented, "method AddGames not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedPublicServer) UpdateGames(context.Context, *UpdateGamesReq) (*UpdateGamesResp, error) {
|
func (UnimplementedGameServiceServer) UpdateGames(context.Context, *UpdateGamesReq) (*UpdateGamesResp, error) {
|
||||||
return nil, status.Error(codes.Unimplemented, "method UpdateGames not implemented")
|
return nil, status.Error(codes.Unimplemented, "method UpdateGames not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedPublicServer) DelGames(context.Context, *DelGamesReq) (*DelGamesResp, error) {
|
func (UnimplementedGameServiceServer) DelGames(context.Context, *DelGamesReq) (*DelGamesResp, error) {
|
||||||
return nil, status.Error(codes.Unimplemented, "method DelGames not implemented")
|
return nil, status.Error(codes.Unimplemented, "method DelGames not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedPublicServer) GetGamesById(context.Context, *GetGamesByIdReq) (*GetGamesByIdResp, error) {
|
func (UnimplementedGameServiceServer) GetGamesById(context.Context, *GetGamesByIdReq) (*GetGamesByIdResp, error) {
|
||||||
return nil, status.Error(codes.Unimplemented, "method GetGamesById not implemented")
|
return nil, status.Error(codes.Unimplemented, "method GetGamesById not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedPublicServer) SearchGames(context.Context, *SearchGamesReq) (*SearchGamesResp, error) {
|
func (UnimplementedGameServiceServer) SearchGames(context.Context, *SearchGamesReq) (*SearchGamesResp, error) {
|
||||||
return nil, status.Error(codes.Unimplemented, "method SearchGames not implemented")
|
return nil, status.Error(codes.Unimplemented, "method SearchGames not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedPublicServer) mustEmbedUnimplementedPublicServer() {}
|
func (UnimplementedGameServiceServer) mustEmbedUnimplementedGameServiceServer() {}
|
||||||
func (UnimplementedPublicServer) testEmbeddedByValue() {}
|
func (UnimplementedGameServiceServer) testEmbeddedByValue() {}
|
||||||
|
|
||||||
// UnsafePublicServer may be embedded to opt out of forward compatibility for this service.
|
// UnsafeGameServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||||
// Use of this interface is not recommended, as added methods to PublicServer will
|
// Use of this interface is not recommended, as added methods to GameServiceServer will
|
||||||
// result in compilation errors.
|
// result in compilation errors.
|
||||||
type UnsafePublicServer interface {
|
type UnsafeGameServiceServer interface {
|
||||||
mustEmbedUnimplementedPublicServer()
|
mustEmbedUnimplementedGameServiceServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterPublicServer(s grpc.ServiceRegistrar, srv PublicServer) {
|
func RegisterGameServiceServer(s grpc.ServiceRegistrar, srv GameServiceServer) {
|
||||||
// If the following call panics, it indicates UnimplementedPublicServer was
|
// If the following call panics, it indicates UnimplementedGameServiceServer was
|
||||||
// embedded by pointer and is nil. This will cause panics if an
|
// embedded by pointer and is nil. This will cause panics if an
|
||||||
// unimplemented method is ever invoked, so we test this at initialization
|
// unimplemented method is ever invoked, so we test this at initialization
|
||||||
// time to prevent it from happening at runtime later due to I/O.
|
// time to prevent it from happening at runtime later due to I/O.
|
||||||
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
||||||
t.testEmbeddedByValue()
|
t.testEmbeddedByValue()
|
||||||
}
|
}
|
||||||
s.RegisterService(&Public_ServiceDesc, srv)
|
s.RegisterService(&GameService_ServiceDesc, srv)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _Public_AddGames_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
func _GameService_AddGames_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
in := new(AddGamesReq)
|
in := new(AddGamesReq)
|
||||||
if err := dec(in); err != nil {
|
if err := dec(in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if interceptor == nil {
|
if interceptor == nil {
|
||||||
return srv.(PublicServer).AddGames(ctx, in)
|
return srv.(GameServiceServer).AddGames(ctx, in)
|
||||||
}
|
}
|
||||||
info := &grpc.UnaryServerInfo{
|
info := &grpc.UnaryServerInfo{
|
||||||
Server: srv,
|
Server: srv,
|
||||||
FullMethod: Public_AddGames_FullMethodName,
|
FullMethod: GameService_AddGames_FullMethodName,
|
||||||
}
|
}
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
return srv.(PublicServer).AddGames(ctx, req.(*AddGamesReq))
|
return srv.(GameServiceServer).AddGames(ctx, req.(*AddGamesReq))
|
||||||
}
|
}
|
||||||
return interceptor(ctx, in, info, handler)
|
return interceptor(ctx, in, info, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _Public_UpdateGames_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
func _GameService_UpdateGames_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
in := new(UpdateGamesReq)
|
in := new(UpdateGamesReq)
|
||||||
if err := dec(in); err != nil {
|
if err := dec(in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if interceptor == nil {
|
if interceptor == nil {
|
||||||
return srv.(PublicServer).UpdateGames(ctx, in)
|
return srv.(GameServiceServer).UpdateGames(ctx, in)
|
||||||
}
|
}
|
||||||
info := &grpc.UnaryServerInfo{
|
info := &grpc.UnaryServerInfo{
|
||||||
Server: srv,
|
Server: srv,
|
||||||
FullMethod: Public_UpdateGames_FullMethodName,
|
FullMethod: GameService_UpdateGames_FullMethodName,
|
||||||
}
|
}
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
return srv.(PublicServer).UpdateGames(ctx, req.(*UpdateGamesReq))
|
return srv.(GameServiceServer).UpdateGames(ctx, req.(*UpdateGamesReq))
|
||||||
}
|
}
|
||||||
return interceptor(ctx, in, info, handler)
|
return interceptor(ctx, in, info, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _Public_DelGames_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
func _GameService_DelGames_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
in := new(DelGamesReq)
|
in := new(DelGamesReq)
|
||||||
if err := dec(in); err != nil {
|
if err := dec(in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if interceptor == nil {
|
if interceptor == nil {
|
||||||
return srv.(PublicServer).DelGames(ctx, in)
|
return srv.(GameServiceServer).DelGames(ctx, in)
|
||||||
}
|
}
|
||||||
info := &grpc.UnaryServerInfo{
|
info := &grpc.UnaryServerInfo{
|
||||||
Server: srv,
|
Server: srv,
|
||||||
FullMethod: Public_DelGames_FullMethodName,
|
FullMethod: GameService_DelGames_FullMethodName,
|
||||||
}
|
}
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
return srv.(PublicServer).DelGames(ctx, req.(*DelGamesReq))
|
return srv.(GameServiceServer).DelGames(ctx, req.(*DelGamesReq))
|
||||||
}
|
}
|
||||||
return interceptor(ctx, in, info, handler)
|
return interceptor(ctx, in, info, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _Public_GetGamesById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
func _GameService_GetGamesById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
in := new(GetGamesByIdReq)
|
in := new(GetGamesByIdReq)
|
||||||
if err := dec(in); err != nil {
|
if err := dec(in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if interceptor == nil {
|
if interceptor == nil {
|
||||||
return srv.(PublicServer).GetGamesById(ctx, in)
|
return srv.(GameServiceServer).GetGamesById(ctx, in)
|
||||||
}
|
}
|
||||||
info := &grpc.UnaryServerInfo{
|
info := &grpc.UnaryServerInfo{
|
||||||
Server: srv,
|
Server: srv,
|
||||||
FullMethod: Public_GetGamesById_FullMethodName,
|
FullMethod: GameService_GetGamesById_FullMethodName,
|
||||||
}
|
}
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
return srv.(PublicServer).GetGamesById(ctx, req.(*GetGamesByIdReq))
|
return srv.(GameServiceServer).GetGamesById(ctx, req.(*GetGamesByIdReq))
|
||||||
}
|
}
|
||||||
return interceptor(ctx, in, info, handler)
|
return interceptor(ctx, in, info, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _Public_SearchGames_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
func _GameService_SearchGames_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
in := new(SearchGamesReq)
|
in := new(SearchGamesReq)
|
||||||
if err := dec(in); err != nil {
|
if err := dec(in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if interceptor == nil {
|
if interceptor == nil {
|
||||||
return srv.(PublicServer).SearchGames(ctx, in)
|
return srv.(GameServiceServer).SearchGames(ctx, in)
|
||||||
}
|
}
|
||||||
info := &grpc.UnaryServerInfo{
|
info := &grpc.UnaryServerInfo{
|
||||||
Server: srv,
|
Server: srv,
|
||||||
FullMethod: Public_SearchGames_FullMethodName,
|
FullMethod: GameService_SearchGames_FullMethodName,
|
||||||
}
|
}
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
return srv.(PublicServer).SearchGames(ctx, req.(*SearchGamesReq))
|
return srv.(GameServiceServer).SearchGames(ctx, req.(*SearchGamesReq))
|
||||||
}
|
}
|
||||||
return interceptor(ctx, in, info, handler)
|
return interceptor(ctx, in, info, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public_ServiceDesc is the grpc.ServiceDesc for Public service.
|
// GameService_ServiceDesc is the grpc.ServiceDesc for GameService service.
|
||||||
// It's only intended for direct use with grpc.RegisterService,
|
// It's only intended for direct use with grpc.RegisterService,
|
||||||
// and not to be introspected or modified (even as a copy)
|
// and not to be introspected or modified (even as a copy)
|
||||||
var Public_ServiceDesc = grpc.ServiceDesc{
|
var GameService_ServiceDesc = grpc.ServiceDesc{
|
||||||
ServiceName: "pb.public",
|
ServiceName: "pb.GameService",
|
||||||
HandlerType: (*PublicServer)(nil),
|
HandlerType: (*GameServiceServer)(nil),
|
||||||
Methods: []grpc.MethodDesc{
|
Methods: []grpc.MethodDesc{
|
||||||
{
|
{
|
||||||
MethodName: "AddGames",
|
MethodName: "AddGames",
|
||||||
Handler: _Public_AddGames_Handler,
|
Handler: _GameService_AddGames_Handler,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
MethodName: "UpdateGames",
|
MethodName: "UpdateGames",
|
||||||
Handler: _Public_UpdateGames_Handler,
|
Handler: _GameService_UpdateGames_Handler,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
MethodName: "DelGames",
|
MethodName: "DelGames",
|
||||||
Handler: _Public_DelGames_Handler,
|
Handler: _GameService_DelGames_Handler,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
MethodName: "GetGamesById",
|
MethodName: "GetGamesById",
|
||||||
Handler: _Public_GetGamesById_Handler,
|
Handler: _GameService_GetGamesById_Handler,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
MethodName: "SearchGames",
|
MethodName: "SearchGames",
|
||||||
Handler: _Public_SearchGames_Handler,
|
Handler: _GameService_SearchGames_Handler,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Streams: []grpc.StreamDesc{},
|
Streams: []grpc.StreamDesc{},
|
||||||
|
|||||||
@@ -2,5 +2,16 @@ Name: file-api
|
|||||||
Host: 0.0.0.0
|
Host: 0.0.0.0
|
||||||
Port: 8888
|
Port: 8888
|
||||||
|
|
||||||
|
Prometheus:
|
||||||
|
Host: 0.0.0.0
|
||||||
|
Port: 4001
|
||||||
|
Path: /metrics
|
||||||
|
|
||||||
|
|
||||||
FileRpcConf:
|
FileRpcConf:
|
||||||
Target: k8s://juwan/objectstory-rpc-svc:8080
|
Target: k8s://juwan/objectstory-rpc-svc:8080
|
||||||
|
#
|
||||||
|
#Log:
|
||||||
|
# Level: info
|
||||||
|
# k8s://juwan/<service name>:8080
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
FileRpcConf zrpc.RpcClientConf
|
FileRpcConf zrpc.RpcClientConf
|
||||||
Logger struct {
|
//Logger struct {
|
||||||
AccessSecret string
|
// AccessSecret string
|
||||||
AccessExpire int64
|
// AccessExpire int64
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
},
|
},
|
||||||
}...,
|
}...,
|
||||||
),
|
),
|
||||||
rest.WithJwt(serverCtx.Config.Logger.AccessSecret),
|
|
||||||
rest.WithPrefix("/api/v1"),
|
rest.WithPrefix("/api/v1"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user