fix: some api bug
This commit is contained in:
@@ -9,10 +9,6 @@ on:
|
|||||||
- "feature/**"
|
- "feature/**"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
env:
|
|
||||||
GO_VERSION: "1.24"
|
|
||||||
NODE_VERSION: "22"
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
docker-build-push:
|
docker-build-push:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -20,70 +16,32 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: http://103.236.53.208:3000/actions/checkout@v4
|
uses: http://103.236.53.208:3000/actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup Node.js
|
|
||||||
uses: http://103.236.53.208:3000/actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: ${{ env.NODE_VERSION }}
|
|
||||||
|
|
||||||
- name: Setup Go
|
|
||||||
uses: http://103.236.53.208:3000/actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: ${{ env.GO_VERSION }}
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: npm ci
|
|
||||||
|
|
||||||
- name: Install goctl
|
|
||||||
run: |
|
|
||||||
go install github.com/zeromicro/go-zero/tools/goctl@latest
|
|
||||||
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
|
|
||||||
|
|
||||||
- name: Set image tags
|
- name: Set image tags
|
||||||
id: vars
|
id: vars
|
||||||
run: |
|
run: |
|
||||||
echo "short_sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
|
echo "short_sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
|
||||||
echo "date_tag=$(date +%Y%m%d%H%M%S)" >> "$GITHUB_OUTPUT"
|
echo "date_tag=$(date +%Y%m%d%H%M%S)" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
# 调试步骤:检查 Secret 是否正确读取 (只会输出字符长度,不会泄露密码)
|
||||||
|
- name: Debug Secrets
|
||||||
|
run: |
|
||||||
|
echo "Registry: ${{ secrets.HARBOR_REGISTRY }}"
|
||||||
|
echo "User length: ${#HARBOR_USERNAME}"
|
||||||
|
echo "Pass length: ${#HARBOR_PASSWORD}"
|
||||||
|
env:
|
||||||
|
HARBOR_USERNAME: ${{ secrets.HARBOR_USERNAME }}
|
||||||
|
HARBOR_PASSWORD: ${{ secrets.HARBOR_PASSWORD }}
|
||||||
|
|
||||||
- name: Login Harbor
|
- name: Login Harbor
|
||||||
env:
|
env:
|
||||||
HARBOR_REGISTRY: ${{ secrets.HARBOR_REGISTRY }}
|
HARBOR_REGISTRY: ${{ secrets.HARBOR_REGISTRY }}
|
||||||
HARBOR_USERNAME: ${{ secrets.HARBOR_USERNAME }}
|
HARBOR_USERNAME: ${{ secrets.HARBOR_USERNAME }}
|
||||||
HARBOR_PASSWORD: ${{ secrets.HARBOR_PASSWORD }}
|
HARBOR_PASSWORD: ${{ secrets.HARBOR_PASSWORD }}
|
||||||
run: |
|
run: |
|
||||||
|
# 尝试登录,如果失败会打印详细信息
|
||||||
echo "$HARBOR_PASSWORD" | docker login "$HARBOR_REGISTRY" -u "$HARBOR_USERNAME" --password-stdin
|
echo "$HARBOR_PASSWORD" | docker login "$HARBOR_REGISTRY" -u "$HARBOR_USERNAME" --password-stdin
|
||||||
|
|
||||||
- name: Discover docker targets
|
- name: Build and Push Monorepo Services
|
||||||
id: targets
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
: > docker-targets.txt
|
|
||||||
|
|
||||||
while IFS= read -r service_dir; do
|
|
||||||
service_name="$(basename "$service_dir")"
|
|
||||||
|
|
||||||
while IFS= read -r svc_dir; do
|
|
||||||
svc_type="$(basename "$svc_dir")"
|
|
||||||
if [[ "$svc_type" == "rpc" ]]; then
|
|
||||||
go_entry="$svc_dir/pb.go"
|
|
||||||
else
|
|
||||||
go_entry="$svc_dir/$service_name.go"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -f "$go_entry" ]]; then
|
|
||||||
echo "$go_entry" >> docker-targets.txt
|
|
||||||
fi
|
|
||||||
done < <(find "$service_dir" -mindepth 1 -maxdepth 1 -type d | sort)
|
|
||||||
|
|
||||||
done < <(find app -mindepth 1 -maxdepth 1 -type d | sort)
|
|
||||||
|
|
||||||
target_count="$(wc -l < docker-targets.txt | tr -d ' ')"
|
|
||||||
echo "count=$target_count" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "Found $target_count docker targets"
|
|
||||||
cat docker-targets.txt
|
|
||||||
|
|
||||||
- name: Generate Dockerfile, build and push images
|
|
||||||
if: steps.targets.outputs.count != '0'
|
|
||||||
env:
|
env:
|
||||||
HARBOR_REGISTRY: ${{ secrets.HARBOR_REGISTRY }}
|
HARBOR_REGISTRY: ${{ secrets.HARBOR_REGISTRY }}
|
||||||
HARBOR_PROJECT: ${{ secrets.HARBOR_PROJECT }}
|
HARBOR_PROJECT: ${{ secrets.HARBOR_PROJECT }}
|
||||||
@@ -93,27 +51,100 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
while IFS= read -r target; do
|
# 1. 定义要遍历的微服务根目录 (根据你的项目结构)
|
||||||
[[ -z "$target" ]] && continue
|
# 你的结构是 app/<service>/<type>
|
||||||
|
# 我们只关心 api, rpc, mq 这三种类型
|
||||||
|
|
||||||
service_name="$(echo "$target" | cut -d'/' -f2)"
|
echo "🔍 开始扫描 Go-Zero 微服务..."
|
||||||
svc_type="$(echo "$target" | cut -d'/' -f3)"
|
|
||||||
image_name="${service_name}-${svc_type}"
|
# 找到 app 下所有的 api/rpc/mq 目录
|
||||||
|
find app -mindepth 2 -maxdepth 2 -type d \( -name "api" -o -name "rpc" -o -name "mq" \) | sort | while read -r service_dir; do
|
||||||
|
|
||||||
|
# service_dir 举例: app/community/api
|
||||||
|
service_type=$(basename "$service_dir") # api
|
||||||
|
parent_dir=$(dirname "$service_dir") # app/community
|
||||||
|
service_name=$(basename "$parent_dir") # community
|
||||||
|
|
||||||
|
# 2. 智能查找入口文件 (main.go 或 service_name.go)
|
||||||
|
# 在当前目录下查找含有 "package main" 的 .go 文件
|
||||||
|
entry_file=$(grep -l "package main" "$service_dir"/*.go | head -n 1 || true)
|
||||||
|
|
||||||
|
if [[ -z "$entry_file" ]]; then
|
||||||
|
echo "⚠️ 跳过 $service_dir: 未找到 package main 入口文件"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 3. 智能查找配置文件 (etc/*.yaml)
|
||||||
|
config_file=$(ls "$service_dir/etc/"*.yaml 2>/dev/null | head -n 1 || true)
|
||||||
|
if [[ -z "$config_file" ]]; then
|
||||||
|
echo "⚠️ 警告 $service_name-$service_type: 未找到 etc/*.yaml 配置文件,容器启动可能失败"
|
||||||
|
config_name="config.yaml" # fallback
|
||||||
|
else
|
||||||
|
config_name=$(basename "$config_file")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 镜像名称: community-api, user-rpc 等
|
||||||
|
image_name="${service_name}-${service_type}"
|
||||||
image_ref="$HARBOR_REGISTRY/$HARBOR_PROJECT/$image_name"
|
image_ref="$HARBOR_REGISTRY/$HARBOR_PROJECT/$image_name"
|
||||||
|
|
||||||
echo "==== Building $image_name from $target ===="
|
echo "----------------------------------------------------"
|
||||||
npx hereby -t docker -s "$target"
|
echo "🚀 构建目标: $image_name"
|
||||||
|
echo "📂 入口文件: $entry_file"
|
||||||
|
echo "📄 配置文件: $config_name"
|
||||||
|
echo "----------------------------------------------------"
|
||||||
|
|
||||||
docker build \
|
# 4. 动态生成 Dockerfile (针对 Monorepo 优化)
|
||||||
-f Dockerfile \
|
# 关键点:COPY . . 把整个根目录拷进去,因为 Go-Zero 项目通常依赖 ../../common
|
||||||
-t "$image_ref:$SHORT_SHA" \
|
cat <<EOF > Dockerfile.tmp
|
||||||
-t "$image_ref:$DATE_TAG" \
|
FROM golang:alpine AS builder
|
||||||
-t "$image_ref:latest" \
|
|
||||||
.
|
|
||||||
|
|
||||||
|
# 优化:使用阿里云 Alpine 源
|
||||||
|
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
|
||||||
|
apk update --no-cache && apk add --no-cache tzdata
|
||||||
|
|
||||||
|
WORKDIR /build
|
||||||
|
|
||||||
|
# 优化:利用层缓存,先下载依赖
|
||||||
|
ENV GOPROXY=https://goproxy.cn,direct
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# 拷贝所有源码 (解决 common 依赖问题)
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# 编译
|
||||||
|
RUN go build -ldflags="-s -w" -o /app/main $entry_file
|
||||||
|
|
||||||
|
# 运行时镜像
|
||||||
|
FROM scratch
|
||||||
|
|
||||||
|
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||||
|
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai
|
||||||
|
ENV TZ=Asia/Shanghai
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=builder /app/main /app/main
|
||||||
|
|
||||||
|
# 拷贝 etc 配置
|
||||||
|
COPY $service_dir/etc /app/etc
|
||||||
|
|
||||||
|
# 启动命令
|
||||||
|
CMD ["./main", "-f", "etc/$config_name"]
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# 5. 执行 Docker Build
|
||||||
|
docker build -f Dockerfile.tmp -t "$image_ref:$SHORT_SHA" .
|
||||||
|
|
||||||
|
# 打其他 Tag
|
||||||
|
docker tag "$image_ref:$SHORT_SHA" "$image_ref:$DATE_TAG"
|
||||||
|
docker tag "$image_ref:$SHORT_SHA" "$image_ref:latest"
|
||||||
|
|
||||||
|
# 6. 推送
|
||||||
|
echo "📤 推送镜像..."
|
||||||
docker push "$image_ref:$SHORT_SHA"
|
docker push "$image_ref:$SHORT_SHA"
|
||||||
docker push "$image_ref:$DATE_TAG"
|
docker push "$image_ref:$DATE_TAG"
|
||||||
docker push "$image_ref:latest"
|
docker push "$image_ref:latest"
|
||||||
|
|
||||||
rm -f Dockerfile
|
echo "✅ $image_name 完成"
|
||||||
done < docker-targets.txt
|
rm -f Dockerfile.tmp
|
||||||
|
done
|
||||||
|
|||||||
+1
-1
@@ -70,7 +70,7 @@ web_modules/
|
|||||||
.yarn-integrity
|
.yarn-integrity
|
||||||
|
|
||||||
# dotenv environment variables file
|
# dotenv environment variables file
|
||||||
.env
|
dev test
|
||||||
.env.test
|
.env.test
|
||||||
.env.production
|
.env.production
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
# authz-adapter
|
|
||||||
|
|
||||||
Envoy `ext_authz` 适配服务,实现 `envoy.service.auth.v3.Authorization`,并调用 `user-rpc.ValidateToken`。
|
|
||||||
|
|
||||||
## 环境变量
|
|
||||||
|
|
||||||
- `LISTEN_ON`:监听地址,默认 `0.0.0.0:9002`
|
|
||||||
- `USER_RPC_TARGET`:user-rpc 地址,默认 `user-rpc-svc.juwan.svc.cluster.local:9001`
|
|
||||||
|
|
||||||
## 本地运行
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
go run ./app/authz/adapter
|
|
||||||
```
|
|
||||||
|
|
||||||
## Docker 构建
|
|
||||||
|
|
||||||
在仓库根目录执行:
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
docker build -f app/authz/adapter/Dockerfile -t authz-adapter:local .
|
|
||||||
docker run --rm -p 9002:9002 authz-adapter:local
|
|
||||||
```
|
|
||||||
|
|
||||||
## 说明
|
|
||||||
|
|
||||||
- 放行路径:`/healthz`、`/api/users/login`、`/api/users/register`
|
|
||||||
- 受保护路径:其余请求要求
|
|
||||||
- Cookie 中有 `JToken`
|
|
||||||
- Header 中有 `x-auth-user-id`(由 Envoy `jwt_authn` 注入)
|
|
||||||
- 鉴权通过后回传:`x-auth-user-id`、`x-auth-role-type`
|
|
||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
corev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
|
corev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
|
||||||
authv3 "github.com/envoyproxy/go-control-plane/envoy/service/auth/v3"
|
authv3 "github.com/envoyproxy/go-control-plane/envoy/service/auth/v3"
|
||||||
typev3 "github.com/envoyproxy/go-control-plane/envoy/type/v3"
|
typev3 "github.com/envoyproxy/go-control-plane/envoy/type/v3"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
codepb "google.golang.org/genproto/googleapis/rpc/code"
|
codepb "google.golang.org/genproto/googleapis/rpc/code"
|
||||||
statuspb "google.golang.org/genproto/googleapis/rpc/status"
|
statuspb "google.golang.org/genproto/googleapis/rpc/status"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
@@ -68,15 +69,17 @@ func (s *authzServer) Check(ctx context.Context, req *authv3.CheckRequest) (*aut
|
|||||||
UserId: userID,
|
UserId: userID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logx.Infof("validate token rpc failed, err: %v", err)
|
||||||
return deny(codepb.Code_UNAUTHENTICATED, typev3.StatusCode_Unauthorized, "validate token failed"), nil
|
return deny(codepb.Code_UNAUTHENTICATED, typev3.StatusCode_Unauthorized, "validate token failed"), nil
|
||||||
}
|
}
|
||||||
if !resp.GetValid() {
|
if !resp.GetValid() {
|
||||||
|
logx.Infof("validate token rpc failed, err: %v", err)
|
||||||
return deny(codepb.Code_PERMISSION_DENIED, typev3.StatusCode_Forbidden, "token invalid"), nil
|
return deny(codepb.Code_PERMISSION_DENIED, typev3.StatusCode_Forbidden, "token invalid"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
outHeaders := []*corev3.HeaderValueOption{
|
outHeaders := []*corev3.HeaderValueOption{
|
||||||
{Header: &corev3.HeaderValue{Key: headerAuthUserID, Value: strconv.FormatInt(resp.GetUserId(), 10)}},
|
{Header: &corev3.HeaderValue{Key: headerAuthUserID, Value: strconv.FormatInt(resp.GetUserId(), 10)}},
|
||||||
{Header: &corev3.HeaderValue{Key: headerAuthRoleType, Value: strconv.FormatInt(resp.GetRoleType(), 10)}},
|
{Header: &corev3.HeaderValue{Key: headerAuthRoleType, Value: resp.GetRoleType()}},
|
||||||
}
|
}
|
||||||
|
|
||||||
if getHeader(httpReq.GetHeaders(), headerAuthIsAdmin) != "" {
|
if getHeader(httpReq.GetHeaders(), headerAuthIsAdmin) != "" {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ Prometheus:
|
|||||||
Kmq:
|
Kmq:
|
||||||
Name: email-mq
|
Name: email-mq
|
||||||
Brokers:
|
Brokers:
|
||||||
- my-cluster-kafka-bootstrap.kafka.svc.cluster.local:9092
|
- "${KAFKA_BROKER}"
|
||||||
Topic: email-task
|
Topic: email-task
|
||||||
Group: email-consumer-group
|
Group: email-consumer-group
|
||||||
ForceCommit: true
|
ForceCommit: true
|
||||||
|
|||||||
@@ -7,5 +7,14 @@ Prometheus:
|
|||||||
Port: 4001
|
Port: 4001
|
||||||
Path: /metrics
|
Path: /metrics
|
||||||
|
|
||||||
|
# ===== PROC CONF =====
|
||||||
|
#GameRpcConf:
|
||||||
|
# Target: k8s://juwan/game-rpc-svc:8080
|
||||||
|
|
||||||
|
# ===== DEV CONF =====
|
||||||
GameRpcConf:
|
GameRpcConf:
|
||||||
Target: k8s://juwan/game-rpc-svc:8080
|
Endpoints:
|
||||||
|
- game-rpc:8080
|
||||||
|
|
||||||
|
Log:
|
||||||
|
Level: debug
|
||||||
@@ -6,6 +6,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"juwan-backend/common/middlewares"
|
||||||
|
|
||||||
"juwan-backend/app/game/api/internal/config"
|
"juwan-backend/app/game/api/internal/config"
|
||||||
"juwan-backend/app/game/api/internal/handler"
|
"juwan-backend/app/game/api/internal/handler"
|
||||||
@@ -24,6 +25,8 @@ func main() {
|
|||||||
conf.MustLoad(*configFile, &c)
|
conf.MustLoad(*configFile, &c)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf)
|
server := rest.MustNewServer(c.RestConf)
|
||||||
|
server.Use(middlewares.NewRequestMiddleware().Handle)
|
||||||
|
server.Use(middlewares.NewHeaderExtractorMiddleware().Handle)
|
||||||
defer server.Stop()
|
defer server.Stop()
|
||||||
|
|
||||||
ctx := svc.NewServiceContext(c)
|
ctx := svc.NewServiceContext(c)
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package game
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/game/api/internal/logic/game"
|
||||||
|
"juwan-backend/app/game/api/internal/svc"
|
||||||
|
"juwan-backend/app/game/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 创建游戏
|
||||||
|
func CreateGameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.Game
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := game.NewCreateGameLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.CreateGame(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Path: "/",
|
Path: "/",
|
||||||
Handler: game.ListGamesHandler(serverCtx),
|
Handler: game.ListGamesHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// 创建游戏
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/",
|
||||||
|
Handler: game.CreateGameHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
// 获取游戏详情
|
// 获取游戏详情
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package game
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/game/rpc/pb"
|
||||||
|
|
||||||
|
"juwan-backend/app/game/api/internal/svc"
|
||||||
|
"juwan-backend/app/game/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CreateGameLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建游戏
|
||||||
|
func NewCreateGameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateGameLogic {
|
||||||
|
return &CreateGameLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *CreateGameLogic) CreateGame(req *types.Game) (resp *types.Game, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
_, err = l.svcCtx.GameRpc.AddGames(l.ctx, &pb.AddGamesReq{
|
||||||
|
Name: req.Name,
|
||||||
|
Icon: req.Icon,
|
||||||
|
Category: req.Category,
|
||||||
|
IsActive: false,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("add game err: %v", err)
|
||||||
|
return nil, errors.New("add game err")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.Game{}, nil
|
||||||
|
}
|
||||||
@@ -35,6 +35,7 @@ func (l *ListGamesLogic) ListGames(req *types.PageReq) (resp *types.GameListResp
|
|||||||
Limit: req.Limit,
|
Limit: req.Limit,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logx.Errorf("ListGames err:%v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+30
-13
@@ -6,23 +6,40 @@ Prometheus:
|
|||||||
Port: 4001
|
Port: 4001
|
||||||
Path: /metrics
|
Path: /metrics
|
||||||
|
|
||||||
DB:
|
# ===== PROC CONF =====
|
||||||
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
#DB:
|
||||||
Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-ro.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
# Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.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:
|
||||||
|
# - 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
|
||||||
|
|
||||||
|
# ===== DEV CONF =====
|
||||||
SnowflakeRpcConf:
|
SnowflakeRpcConf:
|
||||||
Target: k8s://juwan/snowflake-svc:8080
|
Endpoints:
|
||||||
|
- snowflake:8080
|
||||||
|
|
||||||
|
DB:
|
||||||
|
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
|
||||||
CacheConf:
|
CacheConf:
|
||||||
- Host: "${REDIS_M_HOST}"
|
- Host: "${REDIS_HOST}:${REDIS_PORT}"
|
||||||
Type: node
|
Type: node
|
||||||
Pass: "${REDIS_PASSWORD}"
|
|
||||||
User: "default"
|
|
||||||
- Host: "${REDIS_S_HOST}"
|
|
||||||
Type: node
|
|
||||||
Pass: "${REDIS_PASSWORD}"
|
|
||||||
User: "default"
|
|
||||||
|
|
||||||
Log:
|
Log:
|
||||||
Level: info
|
Level: debug
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func (l *AddGamesLogic) AddGames(in *pb.AddGamesReq) (*pb.AddGamesResp, error) {
|
|||||||
SetName(in.Name).
|
SetName(in.Name).
|
||||||
SetIcon(in.Icon).
|
SetIcon(in.Icon).
|
||||||
SetCategory(in.Category).
|
SetCategory(in.Category).
|
||||||
SetSortOrder(int(in.SortOrder)).
|
SetSortOrder(0).
|
||||||
Save(l.ctx)
|
Save(l.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Errorf("AddGamesLogic.addGames err:%v", err)
|
logx.Errorf("AddGamesLogic.addGames err:%v", err)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"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"
|
||||||
|
|
||||||
|
"ariga.io/entcache"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
@@ -25,14 +26,19 @@ 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) {
|
||||||
|
notFoundErr := entcache.ErrNotFound
|
||||||
if in.Page <= 0 || in.Limit <= 0 || in.Page > 1000 || in.Limit > 100 {
|
if in.Page <= 0 || in.Limit <= 0 || in.Page > 1000 || in.Limit > 100 {
|
||||||
return nil, errors.New("invalid pagination parameters")
|
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)
|
all, err := l.svcCtx.GameModelRO.Games.Query().Limit(int(in.Limit)).Offset(int(in.Limit * (in.Page - 1))).All(l.ctx)
|
||||||
if err != nil {
|
if err != nil && !errors.As(err, ¬FoundErr) {
|
||||||
logx.Errorf("failed to query games: %v", err)
|
logx.Errorf("failed to query games: %v", err)
|
||||||
return nil, errors.New("failed to query games")
|
return nil, errors.New("failed to query games")
|
||||||
}
|
}
|
||||||
|
logx.Debugf("games: %v", all)
|
||||||
|
if err != nil {
|
||||||
|
return &pb.SearchGamesResp{}, nil
|
||||||
|
}
|
||||||
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{}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package svc
|
package svc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
stdsql "database/sql"
|
||||||
"juwan-backend/app/game/rpc/internal/config"
|
"juwan-backend/app/game/rpc/internal/config"
|
||||||
"juwan-backend/app/game/rpc/internal/models"
|
"juwan-backend/app/game/rpc/internal/models"
|
||||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||||
@@ -10,6 +11,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"ariga.io/entcache"
|
"ariga.io/entcache"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
|
||||||
@@ -24,14 +26,16 @@ type ServiceContext struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
RWConn, err := sql.Open("pgx", c.DB.Master)
|
rawRW, err := stdsql.Open("pgx", c.DB.Master)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
ROConn, err := sql.Open("pgx", c.DB.Slaves)
|
rawRO, err := stdsql.Open("pgx", c.DB.Slaves)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
RWConn := sql.OpenDB(dialect.Postgres, rawRW)
|
||||||
|
ROConn := sql.OpenDB(dialect.Postgres, rawRO)
|
||||||
|
|
||||||
redisCluster, err := redisx.ConnectMasterSlaveCluster(c.CacheConf, 5*time.Second)
|
redisCluster, err := redisx.ConnectMasterSlaveCluster(c.CacheConf, 5*time.Second)
|
||||||
if redisCluster == nil || err != nil {
|
if redisCluster == nil || err != nil {
|
||||||
|
|||||||
@@ -8,10 +8,20 @@ Prometheus:
|
|||||||
Path: /metrics
|
Path: /metrics
|
||||||
|
|
||||||
|
|
||||||
FileRpcConf:
|
# ===== PROC CONF =====
|
||||||
Target: k8s://juwan/objectstory-rpc-svc:8080
|
#FileRpcConf:
|
||||||
|
# Target: k8s://juwan/objectstory-rpc-svc:8080
|
||||||
#
|
#
|
||||||
#Log:
|
#Log:
|
||||||
# Level: info
|
# Level: info
|
||||||
|
|
||||||
|
# ===== DEV CONF =====
|
||||||
|
FileRpcConf:
|
||||||
|
Endpoints:
|
||||||
|
- objectstory-rpc:8080
|
||||||
|
|
||||||
|
Log:
|
||||||
|
Level: debug
|
||||||
|
|
||||||
# k8s://juwan/<service name>:8080
|
# k8s://juwan/<service name>:8080
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
{
|
{
|
||||||
// 文件获取接口 (如果是私有文件,通过此接口获取或重定向)
|
// 文件获取接口 (如果是私有文件,通过此接口获取或重定向)
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/files/:fileId",
|
Path: "/files",
|
||||||
Handler: file.GetFileHandler(serverCtx),
|
Handler: file.GetFileHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
type GetFileReq struct {
|
type GetFileReq struct {
|
||||||
FileId string `path:"fileId"`
|
FileId string `form:"key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UploadReq struct {
|
type UploadReq struct {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"juwan-backend/common/middlewares"
|
||||||
|
|
||||||
"juwan-backend/app/objectstory/api/internal/config"
|
"juwan-backend/app/objectstory/api/internal/config"
|
||||||
"juwan-backend/app/objectstory/api/internal/handler"
|
"juwan-backend/app/objectstory/api/internal/handler"
|
||||||
@@ -24,6 +25,8 @@ func main() {
|
|||||||
conf.MustLoad(*configFile, &c)
|
conf.MustLoad(*configFile, &c)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf)
|
server := rest.MustNewServer(c.RestConf)
|
||||||
|
server.Use(middlewares.NewRequestMiddleware().Handle)
|
||||||
|
server.Use(middlewares.NewHeaderExtractorMiddleware().Handle)
|
||||||
defer server.Stop()
|
defer server.Stop()
|
||||||
|
|
||||||
ctx := svc.NewServiceContext(c)
|
ctx := svc.NewServiceContext(c)
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ S3Conf:
|
|||||||
Region: auto
|
Region: auto
|
||||||
UsePathStyle: true
|
UsePathStyle: true
|
||||||
|
|
||||||
|
Log:
|
||||||
|
Level: debug
|
||||||
|
|
||||||
#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"
|
||||||
# Slaves: "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"
|
||||||
@@ -36,5 +39,3 @@ S3Conf:
|
|||||||
# Pass: "${REDIS_PASSWORD}"
|
# Pass: "${REDIS_PASSWORD}"
|
||||||
# User: "default"
|
# User: "default"
|
||||||
#
|
#
|
||||||
Log:
|
|
||||||
Level: info
|
|
||||||
|
|||||||
@@ -8,11 +8,25 @@ Prometheus:
|
|||||||
Path: /metrics
|
Path: /metrics
|
||||||
|
|
||||||
# k8s://juwan/<service name>:8080
|
# k8s://juwan/<service name>:8080
|
||||||
|
# ===== PROC CONF =====
|
||||||
|
#OrderRpcConf:
|
||||||
|
# Target: k8s://juwan/order-rpc-svc:8080
|
||||||
|
#
|
||||||
|
#PlayerRpcConf:
|
||||||
|
# Target: k8s://juwan/player-rpc-svc:8080
|
||||||
|
#
|
||||||
|
#ShopRpcConf:
|
||||||
|
# Target: k8s://juwan/shop-rpc-svc:8080
|
||||||
|
|
||||||
|
# ===== DEV CONF ====
|
||||||
OrderRpcConf:
|
OrderRpcConf:
|
||||||
Target: k8s://juwan/order-rpc-svc:8080
|
Endpoints:
|
||||||
|
- order-rpc:8080
|
||||||
|
|
||||||
PlayerRpcConf:
|
PlayerRpcConf:
|
||||||
Target: k8s://juwan/player-rpc-svc:8080
|
Endpoints:
|
||||||
|
- player-rpc:8080
|
||||||
|
|
||||||
ShopRpcConf:
|
ShopRpcConf:
|
||||||
Target: k8s://juwan/shop-rpc-svc:8080
|
Endpoints:
|
||||||
|
- shop-rpc:8080
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"juwan-backend/common/middlewares"
|
||||||
|
|
||||||
"juwan-backend/app/order/api/internal/config"
|
"juwan-backend/app/order/api/internal/config"
|
||||||
"juwan-backend/app/order/api/internal/handler"
|
"juwan-backend/app/order/api/internal/handler"
|
||||||
@@ -24,6 +25,8 @@ func main() {
|
|||||||
conf.MustLoad(*configFile, &c)
|
conf.MustLoad(*configFile, &c)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf)
|
server := rest.MustNewServer(c.RestConf)
|
||||||
|
server.Use(middlewares.NewRequestMiddleware().Handle)
|
||||||
|
server.Use(middlewares.NewHeaderExtractorMiddleware().Handle)
|
||||||
defer server.Stop()
|
defer server.Stop()
|
||||||
|
|
||||||
ctx := svc.NewServiceContext(c)
|
ctx := svc.NewServiceContext(c)
|
||||||
|
|||||||
+29
-13
@@ -14,25 +14,41 @@ Prometheus:
|
|||||||
|
|
||||||
# Target: k8s://juwan/<service name>.<namespace>:8080
|
# Target: k8s://juwan/<service name>.<namespace>:8080
|
||||||
|
|
||||||
|
# ==== PROC CONF ====
|
||||||
|
#SnowflakeRpcConf:
|
||||||
|
# Target: k8s://juwan/snowflake-svc:8080
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#DB:
|
||||||
|
# Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
# Slaves: "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
|
||||||
|
|
||||||
|
# ==== DEV CONF ====
|
||||||
SnowflakeRpcConf:
|
SnowflakeRpcConf:
|
||||||
Target: k8s://juwan/snowflake-svc:8080
|
Endpoints:
|
||||||
|
- snowflake:8080
|
||||||
|
|
||||||
DB:
|
DB:
|
||||||
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-ro.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
|
||||||
|
|
||||||
CacheConf:
|
CacheConf:
|
||||||
- Host: "${REDIS_M_HOST}"
|
- Host: "${REDIS_HOST}:${REDIS_PORT}"
|
||||||
Type: node
|
Type: node
|
||||||
Pass: "${REDIS_PASSWORD}"
|
|
||||||
User: "default"
|
|
||||||
- Host: "${REDIS_S_HOST}"
|
|
||||||
Type: node
|
|
||||||
Pass: "${REDIS_PASSWORD}"
|
|
||||||
User: "default"
|
|
||||||
|
|
||||||
Log:
|
Log:
|
||||||
Level: info
|
Level: debug
|
||||||
@@ -1,20 +1,22 @@
|
|||||||
package svc
|
package svc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
stdsql "database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"ariga.io/entcache"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
_ "github.com/jackc/pgx/v5/stdlib"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"juwan-backend/app/order/rpc/internal/config"
|
"juwan-backend/app/order/rpc/internal/config"
|
||||||
"juwan-backend/app/order/rpc/internal/models"
|
"juwan-backend/app/order/rpc/internal/models"
|
||||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||||
"juwan-backend/common/redisx"
|
"juwan-backend/common/redisx"
|
||||||
"juwan-backend/common/snowflakex"
|
"juwan-backend/common/snowflakex"
|
||||||
"juwan-backend/pkg/adapter"
|
"juwan-backend/pkg/adapter"
|
||||||
|
|
||||||
"ariga.io/entcache"
|
|
||||||
"entgo.io/ent/dialect/sql"
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
@@ -25,14 +27,16 @@ type ServiceContext struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
RWConn, err := sql.Open("pgx", c.DB.Master)
|
rawRW, err := stdsql.Open("pgx", c.DB.Master)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
ROConn, err := sql.Open("pgx", c.DB.Slaves)
|
rawRO, err := stdsql.Open("pgx", c.DB.Slaves)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
RWConn := sql.OpenDB(dialect.Postgres, rawRW)
|
||||||
|
ROConn := sql.OpenDB(dialect.Postgres, rawRO)
|
||||||
|
|
||||||
redisCluster, err := redisx.ConnectMasterSlaveCluster(c.CacheConf, 5*time.Second)
|
redisCluster, err := redisx.ConnectMasterSlaveCluster(c.CacheConf, 5*time.Second)
|
||||||
if redisCluster == nil || err != nil {
|
if redisCluster == nil || err != nil {
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ 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) {
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ Prometheus:
|
|||||||
Path: /metrics
|
Path: /metrics
|
||||||
|
|
||||||
# k8s://juwan/<service name>:8080
|
# k8s://juwan/<service name>:8080
|
||||||
PlayerRpcConf:
|
# ===== PROC CONF =====
|
||||||
Target: k8s://juwan/player-rpc-svc:8080
|
#PlayerRpcConf:
|
||||||
|
# Target: k8s://juwan/player-rpc-svc:8080
|
||||||
|
|
||||||
|
# ===== DEV CONF ====
|
||||||
|
PlayerRpcConf:
|
||||||
|
Endpoints:
|
||||||
|
- player-rpc:8080
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ func NewListPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListP
|
|||||||
func (l *ListPlayersLogic) ListPlayers(req *types.PlayerListReq) (resp *types.PlayerListResp, err error) {
|
func (l *ListPlayersLogic) ListPlayers(req *types.PlayerListReq) (resp *types.PlayerListResp, err error) {
|
||||||
// todo: add your logic here and delete this line
|
// todo: add your logic here and delete this line
|
||||||
p, err := l.svcCtx.PlayerRpc.SearchPlayers(l.ctx, &pb.SearchPlayersReq{
|
p, err := l.svcCtx.PlayerRpc.SearchPlayers(l.ctx, &pb.SearchPlayersReq{
|
||||||
Page: req.Offset,
|
Page: &req.Offset,
|
||||||
Limit: req.Limit,
|
Limit: &req.Limit,
|
||||||
Gender: int64(req.Gender),
|
Gender: &req.Gender,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ type PageReq struct {
|
|||||||
type PlayerListReq struct {
|
type PlayerListReq struct {
|
||||||
PageReq
|
PageReq
|
||||||
GameId int64 `form:"gameId,optional"`
|
GameId int64 `form:"gameId,optional"`
|
||||||
Gender int `form:"gender,optional"`
|
Gender int64 `form:"gender,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PlayerListResp struct {
|
type PlayerListResp struct {
|
||||||
@@ -67,6 +67,7 @@ type PlayerProfile struct {
|
|||||||
Services []PlayerService `json:"services"`
|
Services []PlayerService `json:"services"`
|
||||||
ShopId string `json:"shopId,optional"`
|
ShopId string `json:"shopId,optional"`
|
||||||
ShopName string `json:"shopName,optional"`
|
ShopName string `json:"shopName,optional"`
|
||||||
|
Gender bool `json:"gender"`
|
||||||
Tags []string `json:"tags"`
|
Tags []string `json:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+25
-12
@@ -8,28 +8,41 @@ Prometheus:
|
|||||||
Path: /metrics
|
Path: /metrics
|
||||||
|
|
||||||
|
|
||||||
SnowflakeRpcConf:
|
|
||||||
Target: k8s://juwan/snowflake-svc:8080
|
|
||||||
|
|
||||||
|
|
||||||
|
# ===== PROC CONF =====
|
||||||
|
#SnowflakeRpcConf:
|
||||||
|
# Target: k8s://juwan/snowflake-svc:8080
|
||||||
|
|
||||||
#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"
|
||||||
# Slaves: "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"
|
||||||
|
#
|
||||||
|
#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
|
||||||
|
|
||||||
|
# ===== DEV CONF =====
|
||||||
|
SnowflakeRpcConf:
|
||||||
|
Endpoints:
|
||||||
|
- snowflake:8080
|
||||||
|
|
||||||
DB:
|
DB:
|
||||||
Master: "postgresql://app:7BGs8CdEE8sLPshMjyXkYmxNMTV88EBrd2GN6tdIX1VhIgBzIcgKXbJjVdYiX4a9@user-db-rw:5432/app"
|
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
Slaves: "postgresql://app:7BGs8CdEE8sLPshMjyXkYmxNMTV88EBrd2GN6tdIX1VhIgBzIcgKXbJjVdYiX4a9@user-db-ro:5432/app"
|
Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
|
||||||
CacheConf:
|
CacheConf:
|
||||||
- Host: "${REDIS_M_HOST}"
|
- Host: "${REDIS_HOST}:${REDIS_PORT}"
|
||||||
Type: node
|
Type: node
|
||||||
Pass: "${REDIS_PASSWORD}"
|
|
||||||
User: "default"
|
|
||||||
- Host: "${REDIS_S_HOST}"
|
|
||||||
Type: node
|
|
||||||
Pass: "${REDIS_PASSWORD}"
|
|
||||||
User: "default"
|
|
||||||
|
|
||||||
Log:
|
Log:
|
||||||
Level: info
|
Level: debug
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"juwan-backend/app/player/rpc/internal/models/players"
|
"juwan-backend/app/player/rpc/internal/models/players"
|
||||||
|
|
||||||
"juwan-backend/app/player/rpc/internal/svc"
|
"juwan-backend/app/player/rpc/internal/svc"
|
||||||
"juwan-backend/app/player/rpc/pb"
|
"juwan-backend/app/player/rpc/pb"
|
||||||
|
|
||||||
@@ -27,16 +26,17 @@ func NewSearchPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sea
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *SearchPlayersLogic) SearchPlayers(in *pb.SearchPlayersReq) (*pb.SearchPlayersResp, error) {
|
func (l *SearchPlayersLogic) SearchPlayers(in *pb.SearchPlayersReq) (*pb.SearchPlayersResp, error) {
|
||||||
gender := 0
|
|
||||||
if in.Gender > 0 {
|
|
||||||
gender = 1
|
|
||||||
}
|
|
||||||
searcher := l.svcCtx.PlayerModelRO.Players.Query()
|
searcher := l.svcCtx.PlayerModelRO.Players.Query()
|
||||||
if in.Gender >= 0 {
|
|
||||||
|
if in.Gender != nil && *in.Gender != 0 {
|
||||||
|
// 1 man 2 woman
|
||||||
|
gender := true
|
||||||
|
if *in.Gender == 2 {
|
||||||
|
gender = false
|
||||||
|
}
|
||||||
searcher.Where(players.GenderEQ(gender))
|
searcher.Where(players.GenderEQ(gender))
|
||||||
}
|
}
|
||||||
|
all, err := searcher.Limit(int(*in.Limit)).Offset(int(*in.Page * *in.Limit)).All(l.ctx)
|
||||||
all, err := searcher.Limit(int(in.Limit)).Offset(int(in.Page * in.Limit)).All(l.ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Errorf("SearchPlayers err: %v", err)
|
logx.Errorf("SearchPlayers err: %v", err)
|
||||||
return nil, errors.New("search players")
|
return nil, errors.New("search players")
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ var (
|
|||||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
{Name: "user_id", Type: field.TypeInt64, Unique: true},
|
{Name: "user_id", Type: field.TypeInt64, Unique: true},
|
||||||
{Name: "status", Type: field.TypeString, Size: 20, Default: "offline"},
|
{Name: "status", Type: field.TypeString, Size: 20, Default: "offline"},
|
||||||
{Name: "gender", Type: field.TypeInt, Unique: true},
|
{Name: "gender", Type: field.TypeBool, Default: true},
|
||||||
{Name: "rating", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "decimal(3,2)"}},
|
{Name: "rating", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "decimal(3,2)"}},
|
||||||
{Name: "total_orders", Type: field.TypeInt, Nullable: true, Default: 0},
|
{Name: "total_orders", Type: field.TypeInt, Nullable: true, Default: 0},
|
||||||
{Name: "completed_orders", Type: field.TypeInt, Nullable: true, Default: 0},
|
{Name: "completed_orders", Type: field.TypeInt, Nullable: true, Default: 0},
|
||||||
|
|||||||
@@ -1131,8 +1131,7 @@ type PlayersMutation struct {
|
|||||||
user_id *int64
|
user_id *int64
|
||||||
adduser_id *int64
|
adduser_id *int64
|
||||||
status *string
|
status *string
|
||||||
gender *int
|
gender *bool
|
||||||
addgender *int
|
|
||||||
rating *decimal.Decimal
|
rating *decimal.Decimal
|
||||||
total_orders *int
|
total_orders *int
|
||||||
addtotal_orders *int
|
addtotal_orders *int
|
||||||
@@ -1348,13 +1347,12 @@ func (m *PlayersMutation) ResetStatus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetGender sets the "gender" field.
|
// SetGender sets the "gender" field.
|
||||||
func (m *PlayersMutation) SetGender(i int) {
|
func (m *PlayersMutation) SetGender(b bool) {
|
||||||
m.gender = &i
|
m.gender = &b
|
||||||
m.addgender = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gender returns the value of the "gender" field in the mutation.
|
// Gender returns the value of the "gender" field in the mutation.
|
||||||
func (m *PlayersMutation) Gender() (r int, exists bool) {
|
func (m *PlayersMutation) Gender() (r bool, exists bool) {
|
||||||
v := m.gender
|
v := m.gender
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return
|
return
|
||||||
@@ -1365,7 +1363,7 @@ func (m *PlayersMutation) Gender() (r int, exists bool) {
|
|||||||
// OldGender returns the old "gender" field's value of the Players entity.
|
// OldGender returns the old "gender" field's value of the Players entity.
|
||||||
// If the Players object wasn't provided to the builder, the object is fetched from the database.
|
// If the Players 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.
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
func (m *PlayersMutation) OldGender(ctx context.Context) (v int, err error) {
|
func (m *PlayersMutation) OldGender(ctx context.Context) (v bool, err error) {
|
||||||
if !m.op.Is(OpUpdateOne) {
|
if !m.op.Is(OpUpdateOne) {
|
||||||
return v, errors.New("OldGender is only allowed on UpdateOne operations")
|
return v, errors.New("OldGender is only allowed on UpdateOne operations")
|
||||||
}
|
}
|
||||||
@@ -1379,28 +1377,9 @@ func (m *PlayersMutation) OldGender(ctx context.Context) (v int, err error) {
|
|||||||
return oldValue.Gender, nil
|
return oldValue.Gender, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddGender adds i to the "gender" field.
|
|
||||||
func (m *PlayersMutation) AddGender(i int) {
|
|
||||||
if m.addgender != nil {
|
|
||||||
*m.addgender += i
|
|
||||||
} else {
|
|
||||||
m.addgender = &i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddedGender returns the value that was added to the "gender" field in this mutation.
|
|
||||||
func (m *PlayersMutation) AddedGender() (r int, exists bool) {
|
|
||||||
v := m.addgender
|
|
||||||
if v == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return *v, true
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResetGender resets all changes to the "gender" field.
|
// ResetGender resets all changes to the "gender" field.
|
||||||
func (m *PlayersMutation) ResetGender() {
|
func (m *PlayersMutation) ResetGender() {
|
||||||
m.gender = nil
|
m.gender = nil
|
||||||
m.addgender = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetRating sets the "rating" field.
|
// SetRating sets the "rating" field.
|
||||||
@@ -2001,7 +1980,7 @@ func (m *PlayersMutation) SetField(name string, value ent.Value) error {
|
|||||||
m.SetStatus(v)
|
m.SetStatus(v)
|
||||||
return nil
|
return nil
|
||||||
case players.FieldGender:
|
case players.FieldGender:
|
||||||
v, ok := value.(int)
|
v, ok := value.(bool)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
}
|
}
|
||||||
@@ -2074,9 +2053,6 @@ func (m *PlayersMutation) AddedFields() []string {
|
|||||||
if m.adduser_id != nil {
|
if m.adduser_id != nil {
|
||||||
fields = append(fields, players.FieldUserID)
|
fields = append(fields, players.FieldUserID)
|
||||||
}
|
}
|
||||||
if m.addgender != nil {
|
|
||||||
fields = append(fields, players.FieldGender)
|
|
||||||
}
|
|
||||||
if m.addtotal_orders != nil {
|
if m.addtotal_orders != nil {
|
||||||
fields = append(fields, players.FieldTotalOrders)
|
fields = append(fields, players.FieldTotalOrders)
|
||||||
}
|
}
|
||||||
@@ -2096,8 +2072,6 @@ func (m *PlayersMutation) AddedField(name string) (ent.Value, bool) {
|
|||||||
switch name {
|
switch name {
|
||||||
case players.FieldUserID:
|
case players.FieldUserID:
|
||||||
return m.AddedUserID()
|
return m.AddedUserID()
|
||||||
case players.FieldGender:
|
|
||||||
return m.AddedGender()
|
|
||||||
case players.FieldTotalOrders:
|
case players.FieldTotalOrders:
|
||||||
return m.AddedTotalOrders()
|
return m.AddedTotalOrders()
|
||||||
case players.FieldCompletedOrders:
|
case players.FieldCompletedOrders:
|
||||||
@@ -2120,13 +2094,6 @@ func (m *PlayersMutation) AddField(name string, value ent.Value) error {
|
|||||||
}
|
}
|
||||||
m.AddUserID(v)
|
m.AddUserID(v)
|
||||||
return nil
|
return nil
|
||||||
case players.FieldGender:
|
|
||||||
v, ok := value.(int)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
||||||
}
|
|
||||||
m.AddGender(v)
|
|
||||||
return nil
|
|
||||||
case players.FieldTotalOrders:
|
case players.FieldTotalOrders:
|
||||||
v, ok := value.(int)
|
v, ok := value.(int)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ type Players struct {
|
|||||||
// Status holds the value of the "status" field.
|
// Status holds the value of the "status" field.
|
||||||
Status string `json:"status,omitempty"`
|
Status string `json:"status,omitempty"`
|
||||||
// Gender holds the value of the "gender" field.
|
// Gender holds the value of the "gender" field.
|
||||||
Gender int `json:"gender,omitempty"`
|
Gender bool `json:"gender,omitempty"`
|
||||||
// Rating holds the value of the "rating" field.
|
// Rating holds the value of the "rating" field.
|
||||||
Rating decimal.Decimal `json:"rating,omitempty"`
|
Rating decimal.Decimal `json:"rating,omitempty"`
|
||||||
// TotalOrders holds the value of the "total_orders" field.
|
// TotalOrders holds the value of the "total_orders" field.
|
||||||
@@ -56,7 +56,9 @@ func (*Players) scanValues(columns []string) ([]any, error) {
|
|||||||
values[i] = new(decimal.Decimal)
|
values[i] = new(decimal.Decimal)
|
||||||
case players.FieldGames:
|
case players.FieldGames:
|
||||||
values[i] = new(pq.Int64Array)
|
values[i] = new(pq.Int64Array)
|
||||||
case players.FieldID, players.FieldUserID, players.FieldGender, players.FieldTotalOrders, players.FieldCompletedOrders, players.FieldShopID:
|
case players.FieldGender:
|
||||||
|
values[i] = new(sql.NullBool)
|
||||||
|
case players.FieldID, players.FieldUserID, players.FieldTotalOrders, players.FieldCompletedOrders, players.FieldShopID:
|
||||||
values[i] = new(sql.NullInt64)
|
values[i] = new(sql.NullInt64)
|
||||||
case players.FieldStatus:
|
case players.FieldStatus:
|
||||||
values[i] = new(sql.NullString)
|
values[i] = new(sql.NullString)
|
||||||
@@ -96,10 +98,10 @@ func (_m *Players) assignValues(columns []string, values []any) error {
|
|||||||
_m.Status = value.String
|
_m.Status = value.String
|
||||||
}
|
}
|
||||||
case players.FieldGender:
|
case players.FieldGender:
|
||||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field gender", values[i])
|
return fmt.Errorf("unexpected type %T for field gender", values[i])
|
||||||
} else if value.Valid {
|
} else if value.Valid {
|
||||||
_m.Gender = int(value.Int64)
|
_m.Gender = value.Bool
|
||||||
}
|
}
|
||||||
case players.FieldRating:
|
case players.FieldRating:
|
||||||
if value, ok := values[i].(*decimal.Decimal); !ok {
|
if value, ok := values[i].(*decimal.Decimal); !ok {
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ var (
|
|||||||
DefaultStatus string
|
DefaultStatus string
|
||||||
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
||||||
StatusValidator func(string) error
|
StatusValidator func(string) error
|
||||||
|
// DefaultGender holds the default value on creation for the "gender" field.
|
||||||
|
DefaultGender bool
|
||||||
// DefaultRating holds the default value on creation for the "rating" field.
|
// DefaultRating holds the default value on creation for the "rating" field.
|
||||||
DefaultRating decimal.Decimal
|
DefaultRating decimal.Decimal
|
||||||
// DefaultTotalOrders holds the default value on creation for the "total_orders" field.
|
// DefaultTotalOrders holds the default value on creation for the "total_orders" field.
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func Status(v string) predicate.Players {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Gender applies equality check predicate on the "gender" field. It's identical to GenderEQ.
|
// Gender applies equality check predicate on the "gender" field. It's identical to GenderEQ.
|
||||||
func Gender(v int) predicate.Players {
|
func Gender(v bool) predicate.Players {
|
||||||
return predicate.Players(sql.FieldEQ(FieldGender, v))
|
return predicate.Players(sql.FieldEQ(FieldGender, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,45 +212,15 @@ func StatusContainsFold(v string) predicate.Players {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GenderEQ applies the EQ predicate on the "gender" field.
|
// GenderEQ applies the EQ predicate on the "gender" field.
|
||||||
func GenderEQ(v int) predicate.Players {
|
func GenderEQ(v bool) predicate.Players {
|
||||||
return predicate.Players(sql.FieldEQ(FieldGender, v))
|
return predicate.Players(sql.FieldEQ(FieldGender, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenderNEQ applies the NEQ predicate on the "gender" field.
|
// GenderNEQ applies the NEQ predicate on the "gender" field.
|
||||||
func GenderNEQ(v int) predicate.Players {
|
func GenderNEQ(v bool) predicate.Players {
|
||||||
return predicate.Players(sql.FieldNEQ(FieldGender, v))
|
return predicate.Players(sql.FieldNEQ(FieldGender, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenderIn applies the In predicate on the "gender" field.
|
|
||||||
func GenderIn(vs ...int) predicate.Players {
|
|
||||||
return predicate.Players(sql.FieldIn(FieldGender, vs...))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenderNotIn applies the NotIn predicate on the "gender" field.
|
|
||||||
func GenderNotIn(vs ...int) predicate.Players {
|
|
||||||
return predicate.Players(sql.FieldNotIn(FieldGender, vs...))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenderGT applies the GT predicate on the "gender" field.
|
|
||||||
func GenderGT(v int) predicate.Players {
|
|
||||||
return predicate.Players(sql.FieldGT(FieldGender, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenderGTE applies the GTE predicate on the "gender" field.
|
|
||||||
func GenderGTE(v int) predicate.Players {
|
|
||||||
return predicate.Players(sql.FieldGTE(FieldGender, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenderLT applies the LT predicate on the "gender" field.
|
|
||||||
func GenderLT(v int) predicate.Players {
|
|
||||||
return predicate.Players(sql.FieldLT(FieldGender, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenderLTE applies the LTE predicate on the "gender" field.
|
|
||||||
func GenderLTE(v int) predicate.Players {
|
|
||||||
return predicate.Players(sql.FieldLTE(FieldGender, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
// RatingEQ applies the EQ predicate on the "rating" field.
|
// RatingEQ applies the EQ predicate on the "rating" field.
|
||||||
func RatingEQ(v decimal.Decimal) predicate.Players {
|
func RatingEQ(v decimal.Decimal) predicate.Players {
|
||||||
return predicate.Players(sql.FieldEQ(FieldRating, v))
|
return predicate.Players(sql.FieldEQ(FieldRating, v))
|
||||||
|
|||||||
@@ -43,11 +43,19 @@ func (_c *PlayersCreate) SetNillableStatus(v *string) *PlayersCreate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetGender sets the "gender" field.
|
// SetGender sets the "gender" field.
|
||||||
func (_c *PlayersCreate) SetGender(v int) *PlayersCreate {
|
func (_c *PlayersCreate) SetGender(v bool) *PlayersCreate {
|
||||||
_c.mutation.SetGender(v)
|
_c.mutation.SetGender(v)
|
||||||
return _c
|
return _c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetNillableGender sets the "gender" field if the given value is not nil.
|
||||||
|
func (_c *PlayersCreate) SetNillableGender(v *bool) *PlayersCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetGender(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
// SetRating sets the "rating" field.
|
// SetRating sets the "rating" field.
|
||||||
func (_c *PlayersCreate) SetRating(v decimal.Decimal) *PlayersCreate {
|
func (_c *PlayersCreate) SetRating(v decimal.Decimal) *PlayersCreate {
|
||||||
_c.mutation.SetRating(v)
|
_c.mutation.SetRating(v)
|
||||||
@@ -189,6 +197,10 @@ func (_c *PlayersCreate) defaults() {
|
|||||||
v := players.DefaultStatus
|
v := players.DefaultStatus
|
||||||
_c.mutation.SetStatus(v)
|
_c.mutation.SetStatus(v)
|
||||||
}
|
}
|
||||||
|
if _, ok := _c.mutation.Gender(); !ok {
|
||||||
|
v := players.DefaultGender
|
||||||
|
_c.mutation.SetGender(v)
|
||||||
|
}
|
||||||
if _, ok := _c.mutation.Rating(); !ok {
|
if _, ok := _c.mutation.Rating(); !ok {
|
||||||
v := players.DefaultRating
|
v := players.DefaultRating
|
||||||
_c.mutation.SetRating(v)
|
_c.mutation.SetRating(v)
|
||||||
@@ -282,7 +294,7 @@ func (_c *PlayersCreate) createSpec() (*Players, *sqlgraph.CreateSpec) {
|
|||||||
_node.Status = value
|
_node.Status = value
|
||||||
}
|
}
|
||||||
if value, ok := _c.mutation.Gender(); ok {
|
if value, ok := _c.mutation.Gender(); ok {
|
||||||
_spec.SetField(players.FieldGender, field.TypeInt, value)
|
_spec.SetField(players.FieldGender, field.TypeBool, value)
|
||||||
_node.Gender = value
|
_node.Gender = value
|
||||||
}
|
}
|
||||||
if value, ok := _c.mutation.Rating(); ok {
|
if value, ok := _c.mutation.Rating(); ok {
|
||||||
|
|||||||
@@ -67,26 +67,19 @@ func (_u *PlayersUpdate) SetNillableStatus(v *string) *PlayersUpdate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetGender sets the "gender" field.
|
// SetGender sets the "gender" field.
|
||||||
func (_u *PlayersUpdate) SetGender(v int) *PlayersUpdate {
|
func (_u *PlayersUpdate) SetGender(v bool) *PlayersUpdate {
|
||||||
_u.mutation.ResetGender()
|
|
||||||
_u.mutation.SetGender(v)
|
_u.mutation.SetGender(v)
|
||||||
return _u
|
return _u
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetNillableGender sets the "gender" field if the given value is not nil.
|
// SetNillableGender sets the "gender" field if the given value is not nil.
|
||||||
func (_u *PlayersUpdate) SetNillableGender(v *int) *PlayersUpdate {
|
func (_u *PlayersUpdate) SetNillableGender(v *bool) *PlayersUpdate {
|
||||||
if v != nil {
|
if v != nil {
|
||||||
_u.SetGender(*v)
|
_u.SetGender(*v)
|
||||||
}
|
}
|
||||||
return _u
|
return _u
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddGender adds value to the "gender" field.
|
|
||||||
func (_u *PlayersUpdate) AddGender(v int) *PlayersUpdate {
|
|
||||||
_u.mutation.AddGender(v)
|
|
||||||
return _u
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetRating sets the "rating" field.
|
// SetRating sets the "rating" field.
|
||||||
func (_u *PlayersUpdate) SetRating(v decimal.Decimal) *PlayersUpdate {
|
func (_u *PlayersUpdate) SetRating(v decimal.Decimal) *PlayersUpdate {
|
||||||
_u.mutation.SetRating(v)
|
_u.mutation.SetRating(v)
|
||||||
@@ -297,10 +290,7 @@ func (_u *PlayersUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|||||||
_spec.SetField(players.FieldStatus, field.TypeString, value)
|
_spec.SetField(players.FieldStatus, field.TypeString, value)
|
||||||
}
|
}
|
||||||
if value, ok := _u.mutation.Gender(); ok {
|
if value, ok := _u.mutation.Gender(); ok {
|
||||||
_spec.SetField(players.FieldGender, field.TypeInt, value)
|
_spec.SetField(players.FieldGender, field.TypeBool, value)
|
||||||
}
|
|
||||||
if value, ok := _u.mutation.AddedGender(); ok {
|
|
||||||
_spec.AddField(players.FieldGender, field.TypeInt, value)
|
|
||||||
}
|
}
|
||||||
if value, ok := _u.mutation.Rating(); ok {
|
if value, ok := _u.mutation.Rating(); ok {
|
||||||
_spec.SetField(players.FieldRating, field.TypeOther, value)
|
_spec.SetField(players.FieldRating, field.TypeOther, value)
|
||||||
@@ -411,26 +401,19 @@ func (_u *PlayersUpdateOne) SetNillableStatus(v *string) *PlayersUpdateOne {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetGender sets the "gender" field.
|
// SetGender sets the "gender" field.
|
||||||
func (_u *PlayersUpdateOne) SetGender(v int) *PlayersUpdateOne {
|
func (_u *PlayersUpdateOne) SetGender(v bool) *PlayersUpdateOne {
|
||||||
_u.mutation.ResetGender()
|
|
||||||
_u.mutation.SetGender(v)
|
_u.mutation.SetGender(v)
|
||||||
return _u
|
return _u
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetNillableGender sets the "gender" field if the given value is not nil.
|
// SetNillableGender sets the "gender" field if the given value is not nil.
|
||||||
func (_u *PlayersUpdateOne) SetNillableGender(v *int) *PlayersUpdateOne {
|
func (_u *PlayersUpdateOne) SetNillableGender(v *bool) *PlayersUpdateOne {
|
||||||
if v != nil {
|
if v != nil {
|
||||||
_u.SetGender(*v)
|
_u.SetGender(*v)
|
||||||
}
|
}
|
||||||
return _u
|
return _u
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddGender adds value to the "gender" field.
|
|
||||||
func (_u *PlayersUpdateOne) AddGender(v int) *PlayersUpdateOne {
|
|
||||||
_u.mutation.AddGender(v)
|
|
||||||
return _u
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetRating sets the "rating" field.
|
// SetRating sets the "rating" field.
|
||||||
func (_u *PlayersUpdateOne) SetRating(v decimal.Decimal) *PlayersUpdateOne {
|
func (_u *PlayersUpdateOne) SetRating(v decimal.Decimal) *PlayersUpdateOne {
|
||||||
_u.mutation.SetRating(v)
|
_u.mutation.SetRating(v)
|
||||||
@@ -671,10 +654,7 @@ func (_u *PlayersUpdateOne) sqlSave(ctx context.Context) (_node *Players, err er
|
|||||||
_spec.SetField(players.FieldStatus, field.TypeString, value)
|
_spec.SetField(players.FieldStatus, field.TypeString, value)
|
||||||
}
|
}
|
||||||
if value, ok := _u.mutation.Gender(); ok {
|
if value, ok := _u.mutation.Gender(); ok {
|
||||||
_spec.SetField(players.FieldGender, field.TypeInt, value)
|
_spec.SetField(players.FieldGender, field.TypeBool, value)
|
||||||
}
|
|
||||||
if value, ok := _u.mutation.AddedGender(); ok {
|
|
||||||
_spec.AddField(players.FieldGender, field.TypeInt, value)
|
|
||||||
}
|
}
|
||||||
if value, ok := _u.mutation.Rating(); ok {
|
if value, ok := _u.mutation.Rating(); ok {
|
||||||
_spec.SetField(players.FieldRating, field.TypeOther, value)
|
_spec.SetField(players.FieldRating, field.TypeOther, value)
|
||||||
|
|||||||
@@ -60,6 +60,10 @@ func init() {
|
|||||||
players.DefaultStatus = playersDescStatus.Default.(string)
|
players.DefaultStatus = playersDescStatus.Default.(string)
|
||||||
// players.StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
// players.StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
||||||
players.StatusValidator = playersDescStatus.Validators[0].(func(string) error)
|
players.StatusValidator = playersDescStatus.Validators[0].(func(string) error)
|
||||||
|
// playersDescGender is the schema descriptor for gender field.
|
||||||
|
playersDescGender := playersFields[3].Descriptor()
|
||||||
|
// players.DefaultGender holds the default value on creation for the gender field.
|
||||||
|
players.DefaultGender = playersDescGender.Default.(bool)
|
||||||
// playersDescRating is the schema descriptor for rating field.
|
// playersDescRating is the schema descriptor for rating field.
|
||||||
playersDescRating := playersFields[4].Descriptor()
|
playersDescRating := playersFields[4].Descriptor()
|
||||||
// players.DefaultRating holds the default value on creation for the rating field.
|
// players.DefaultRating holds the default value on creation for the rating field.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package schema
|
package schema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"juwan-backend/pkg/types"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"entgo.io/ent"
|
"entgo.io/ent"
|
||||||
@@ -23,7 +24,7 @@ func (Players) Fields() []ent.Field {
|
|||||||
field.Int64("id").Immutable().Unique(),
|
field.Int64("id").Immutable().Unique(),
|
||||||
field.Int64("user_id").Unique(),
|
field.Int64("user_id").Unique(),
|
||||||
field.String("status").MaxLen(20).Default("offline"),
|
field.String("status").MaxLen(20).Default("offline"),
|
||||||
field.Int("gender").Unique(),
|
field.Bool("gender").Default(true),
|
||||||
field.Other("rating", decimal.Decimal{}).
|
field.Other("rating", decimal.Decimal{}).
|
||||||
Optional().
|
Optional().
|
||||||
Default(playerDefaultRating).
|
Default(playerDefaultRating).
|
||||||
@@ -33,7 +34,9 @@ func (Players) Fields() []ent.Field {
|
|||||||
field.Int("total_orders").Optional().Default(0),
|
field.Int("total_orders").Optional().Default(0),
|
||||||
field.Int("completed_orders").Optional().Default(0),
|
field.Int("completed_orders").Optional().Default(0),
|
||||||
field.Int64("shop_id").Optional().Nillable(),
|
field.Int64("shop_id").Optional().Nillable(),
|
||||||
field.Strings("tags").Optional().Default([]string{}),
|
field.Other("tags", types.TextArray{}).SchemaType(map[string]string{
|
||||||
|
dialect.Postgres: "text[]",
|
||||||
|
}).Optional(),
|
||||||
field.Other("games", pq.Int64Array{}).
|
field.Other("games", pq.Int64Array{}).
|
||||||
Optional().
|
Optional().
|
||||||
Default(pq.Int64Array{}).
|
Default(pq.Int64Array{}).
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package schema
|
package schema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"juwan-backend/pkg/types"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"entgo.io/ent"
|
"entgo.io/ent"
|
||||||
@@ -47,7 +48,9 @@ func (PlayerServices) Fields() []ent.Field {
|
|||||||
}),
|
}),
|
||||||
field.String("unit").MaxLen(20),
|
field.String("unit").MaxLen(20),
|
||||||
field.String("rank_range").MaxLen(100).Optional().Nillable(),
|
field.String("rank_range").MaxLen(100).Optional().Nillable(),
|
||||||
field.Strings("availability").Optional().Default([]string{}),
|
field.Other("availability", types.TextArray{}).SchemaType(map[string]string{
|
||||||
|
dialect.Postgres: "text[]",
|
||||||
|
}).Optional().Nillable(),
|
||||||
field.Other("rating", decimal.Decimal{}).
|
field.Other("rating", decimal.Decimal{}).
|
||||||
Default(decFive).
|
Default(decFive).
|
||||||
SchemaType(map[string]string{
|
SchemaType(map[string]string{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package svc
|
package svc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
stdsql "database/sql"
|
||||||
"juwan-backend/app/player/rpc/internal/config"
|
"juwan-backend/app/player/rpc/internal/config"
|
||||||
"juwan-backend/app/player/rpc/internal/models"
|
"juwan-backend/app/player/rpc/internal/models"
|
||||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||||
@@ -10,6 +11,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"ariga.io/entcache"
|
"ariga.io/entcache"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
|
||||||
@@ -24,14 +26,16 @@ type ServiceContext struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
RWConn, err := sql.Open("pgx", c.DB.Master)
|
rawRW, err := stdsql.Open("pgx", c.DB.Master)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
ROConn, err := sql.Open("pgx", c.DB.Slaves)
|
rawRO, err := stdsql.Open("pgx", c.DB.Slaves)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
RWConn := sql.OpenDB(dialect.Postgres, rawRW)
|
||||||
|
ROConn := sql.OpenDB(dialect.Postgres, rawRO)
|
||||||
|
|
||||||
redisCluster, err := redisx.ConnectMasterSlaveCluster(c.CacheConf, 5*time.Second)
|
redisCluster, err := redisx.ConnectMasterSlaveCluster(c.CacheConf, 5*time.Second)
|
||||||
if redisCluster == nil || err != nil {
|
if redisCluster == nil || err != nil {
|
||||||
|
|||||||
@@ -888,7 +888,7 @@ type Players struct {
|
|||||||
Games []int64 `protobuf:"varint,9,rep,packed,name=games,proto3" json:"games,omitempty"` //games
|
Games []int64 `protobuf:"varint,9,rep,packed,name=games,proto3" json:"games,omitempty"` //games
|
||||||
CreatedAt int64 `protobuf:"varint,10,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt
|
CreatedAt int64 `protobuf:"varint,10,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt
|
||||||
UpdatedAt int64 `protobuf:"varint,11,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt
|
UpdatedAt int64 `protobuf:"varint,11,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt
|
||||||
Gender int64 `protobuf:"varint,12,opt,name=gender,proto3" json:"gender,omitempty"` //gender
|
Gender bool `protobuf:"varint,12,opt,name=gender,proto3" json:"gender,omitempty"` //gender
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
@@ -1000,11 +1000,11 @@ func (x *Players) GetUpdatedAt() int64 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Players) GetGender() int64 {
|
func (x *Players) GetGender() bool {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Gender
|
return x.Gender
|
||||||
}
|
}
|
||||||
return 0
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddPlayersReq struct {
|
type AddPlayersReq struct {
|
||||||
@@ -1505,20 +1505,20 @@ func (x *GetPlayersByIdResp) GetPlayers() *Players {
|
|||||||
|
|
||||||
type SearchPlayersReq struct {
|
type SearchPlayersReq struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
Page int64 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"` //page
|
Page *int64 `protobuf:"varint,1,opt,name=page,proto3,oneof" 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,oneof" 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,oneof" json:"id,omitempty"` //id
|
||||||
UserId int64 `protobuf:"varint,4,opt,name=userId,proto3" json:"userId,omitempty"` //userId
|
UserId *int64 `protobuf:"varint,4,opt,name=userId,proto3,oneof" json:"userId,omitempty"` //userId
|
||||||
Status string `protobuf:"bytes,5,opt,name=status,proto3" json:"status,omitempty"` //status
|
Status *string `protobuf:"bytes,5,opt,name=status,proto3,oneof" json:"status,omitempty"` //status
|
||||||
Rating float64 `protobuf:"fixed64,6,opt,name=rating,proto3" json:"rating,omitempty"` //rating
|
Rating *float64 `protobuf:"fixed64,6,opt,name=rating,proto3,oneof" json:"rating,omitempty"` //rating
|
||||||
TotalOrders int64 `protobuf:"varint,7,opt,name=totalOrders,proto3" json:"totalOrders,omitempty"` //totalOrders
|
TotalOrders *int64 `protobuf:"varint,7,opt,name=totalOrders,proto3,oneof" json:"totalOrders,omitempty"` //totalOrders
|
||||||
CompletedOrders int64 `protobuf:"varint,8,opt,name=completedOrders,proto3" json:"completedOrders,omitempty"` //completedOrders
|
CompletedOrders *int64 `protobuf:"varint,8,opt,name=completedOrders,proto3,oneof" json:"completedOrders,omitempty"` //completedOrders
|
||||||
ShopId int64 `protobuf:"varint,9,opt,name=shopId,proto3" json:"shopId,omitempty"` //shopId
|
ShopId *int64 `protobuf:"varint,9,opt,name=shopId,proto3,oneof" json:"shopId,omitempty"` //shopId
|
||||||
Tags []string `protobuf:"bytes,10,rep,name=tags,proto3" json:"tags,omitempty"` //tags
|
Tags []string `protobuf:"bytes,10,rep,name=tags,proto3" json:"tags,omitempty"` //tags
|
||||||
Games []int64 `protobuf:"varint,11,rep,packed,name=games,proto3" json:"games,omitempty"` //games
|
Games []int64 `protobuf:"varint,11,rep,packed,name=games,proto3" json:"games,omitempty"` //games
|
||||||
CreatedAt int64 `protobuf:"varint,12,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt
|
CreatedAt *int64 `protobuf:"varint,12,opt,name=createdAt,proto3,oneof" json:"createdAt,omitempty"` //createdAt
|
||||||
UpdatedAt int64 `protobuf:"varint,13,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt
|
UpdatedAt *int64 `protobuf:"varint,13,opt,name=updatedAt,proto3,oneof" json:"updatedAt,omitempty"` //updatedAt
|
||||||
Gender int64 `protobuf:"varint,14,opt,name=gender,proto3" json:"gender,omitempty"` //gender
|
Gender *int64 `protobuf:"varint,14,opt,name=gender,proto3,oneof" json:"gender,omitempty"` //gender
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
@@ -1554,64 +1554,64 @@ func (*SearchPlayersReq) Descriptor() ([]byte, []int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchPlayersReq) GetPage() int64 {
|
func (x *SearchPlayersReq) GetPage() int64 {
|
||||||
if x != nil {
|
if x != nil && x.Page != nil {
|
||||||
return x.Page
|
return *x.Page
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchPlayersReq) GetLimit() int64 {
|
func (x *SearchPlayersReq) GetLimit() int64 {
|
||||||
if x != nil {
|
if x != nil && x.Limit != nil {
|
||||||
return x.Limit
|
return *x.Limit
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchPlayersReq) GetId() int64 {
|
func (x *SearchPlayersReq) GetId() int64 {
|
||||||
if x != nil {
|
if x != nil && x.Id != nil {
|
||||||
return x.Id
|
return *x.Id
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchPlayersReq) GetUserId() int64 {
|
func (x *SearchPlayersReq) GetUserId() int64 {
|
||||||
if x != nil {
|
if x != nil && x.UserId != nil {
|
||||||
return x.UserId
|
return *x.UserId
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchPlayersReq) GetStatus() string {
|
func (x *SearchPlayersReq) GetStatus() string {
|
||||||
if x != nil {
|
if x != nil && x.Status != nil {
|
||||||
return x.Status
|
return *x.Status
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchPlayersReq) GetRating() float64 {
|
func (x *SearchPlayersReq) GetRating() float64 {
|
||||||
if x != nil {
|
if x != nil && x.Rating != nil {
|
||||||
return x.Rating
|
return *x.Rating
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchPlayersReq) GetTotalOrders() int64 {
|
func (x *SearchPlayersReq) GetTotalOrders() int64 {
|
||||||
if x != nil {
|
if x != nil && x.TotalOrders != nil {
|
||||||
return x.TotalOrders
|
return *x.TotalOrders
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchPlayersReq) GetCompletedOrders() int64 {
|
func (x *SearchPlayersReq) GetCompletedOrders() int64 {
|
||||||
if x != nil {
|
if x != nil && x.CompletedOrders != nil {
|
||||||
return x.CompletedOrders
|
return *x.CompletedOrders
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchPlayersReq) GetShopId() int64 {
|
func (x *SearchPlayersReq) GetShopId() int64 {
|
||||||
if x != nil {
|
if x != nil && x.ShopId != nil {
|
||||||
return x.ShopId
|
return *x.ShopId
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -1631,22 +1631,22 @@ func (x *SearchPlayersReq) GetGames() []int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchPlayersReq) GetCreatedAt() int64 {
|
func (x *SearchPlayersReq) GetCreatedAt() int64 {
|
||||||
if x != nil {
|
if x != nil && x.CreatedAt != nil {
|
||||||
return x.CreatedAt
|
return *x.CreatedAt
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchPlayersReq) GetUpdatedAt() int64 {
|
func (x *SearchPlayersReq) GetUpdatedAt() int64 {
|
||||||
if x != nil {
|
if x != nil && x.UpdatedAt != nil {
|
||||||
return x.UpdatedAt
|
return *x.UpdatedAt
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SearchPlayersReq) GetGender() int64 {
|
func (x *SearchPlayersReq) GetGender() int64 {
|
||||||
if x != nil {
|
if x != nil && x.Gender != nil {
|
||||||
return x.Gender
|
return *x.Gender
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -1800,7 +1800,7 @@ const file_player_proto_rawDesc = "" +
|
|||||||
"\tcreatedAt\x18\n" +
|
"\tcreatedAt\x18\n" +
|
||||||
" \x01(\x03R\tcreatedAt\x12\x1c\n" +
|
" \x01(\x03R\tcreatedAt\x12\x1c\n" +
|
||||||
"\tupdatedAt\x18\v \x01(\x03R\tupdatedAt\x12\x16\n" +
|
"\tupdatedAt\x18\v \x01(\x03R\tupdatedAt\x12\x16\n" +
|
||||||
"\x06gender\x18\f \x01(\x03R\x06gender\"\xb9\x02\n" +
|
"\x06gender\x18\f \x01(\bR\x06gender\"\xb9\x02\n" +
|
||||||
"\rAddPlayersReq\x12\x16\n" +
|
"\rAddPlayersReq\x12\x16\n" +
|
||||||
"\x06userId\x18\x01 \x01(\x03R\x06userId\x12\x16\n" +
|
"\x06userId\x18\x01 \x01(\x03R\x06userId\x12\x16\n" +
|
||||||
"\x06status\x18\x02 \x01(\tR\x06status\x12\x16\n" +
|
"\x06status\x18\x02 \x01(\tR\x06status\x12\x16\n" +
|
||||||
@@ -1847,23 +1847,38 @@ const file_player_proto_rawDesc = "" +
|
|||||||
"\x11GetPlayersByIdReq\x12\x0e\n" +
|
"\x11GetPlayersByIdReq\x12\x0e\n" +
|
||||||
"\x02id\x18\x01 \x01(\x03R\x02id\";\n" +
|
"\x02id\x18\x01 \x01(\x03R\x02id\";\n" +
|
||||||
"\x12GetPlayersByIdResp\x12%\n" +
|
"\x12GetPlayersByIdResp\x12%\n" +
|
||||||
"\aplayers\x18\x01 \x01(\v2\v.pb.PlayersR\aplayers\"\xf6\x02\n" +
|
"\aplayers\x18\x01 \x01(\v2\v.pb.PlayersR\aplayers\"\xc3\x04\n" +
|
||||||
"\x10SearchPlayersReq\x12\x12\n" +
|
"\x10SearchPlayersReq\x12\x17\n" +
|
||||||
"\x04page\x18\x01 \x01(\x03R\x04page\x12\x14\n" +
|
"\x04page\x18\x01 \x01(\x03H\x00R\x04page\x88\x01\x01\x12\x19\n" +
|
||||||
"\x05limit\x18\x02 \x01(\x03R\x05limit\x12\x0e\n" +
|
"\x05limit\x18\x02 \x01(\x03H\x01R\x05limit\x88\x01\x01\x12\x13\n" +
|
||||||
"\x02id\x18\x03 \x01(\x03R\x02id\x12\x16\n" +
|
"\x02id\x18\x03 \x01(\x03H\x02R\x02id\x88\x01\x01\x12\x1b\n" +
|
||||||
"\x06userId\x18\x04 \x01(\x03R\x06userId\x12\x16\n" +
|
"\x06userId\x18\x04 \x01(\x03H\x03R\x06userId\x88\x01\x01\x12\x1b\n" +
|
||||||
"\x06status\x18\x05 \x01(\tR\x06status\x12\x16\n" +
|
"\x06status\x18\x05 \x01(\tH\x04R\x06status\x88\x01\x01\x12\x1b\n" +
|
||||||
"\x06rating\x18\x06 \x01(\x01R\x06rating\x12 \n" +
|
"\x06rating\x18\x06 \x01(\x01H\x05R\x06rating\x88\x01\x01\x12%\n" +
|
||||||
"\vtotalOrders\x18\a \x01(\x03R\vtotalOrders\x12(\n" +
|
"\vtotalOrders\x18\a \x01(\x03H\x06R\vtotalOrders\x88\x01\x01\x12-\n" +
|
||||||
"\x0fcompletedOrders\x18\b \x01(\x03R\x0fcompletedOrders\x12\x16\n" +
|
"\x0fcompletedOrders\x18\b \x01(\x03H\aR\x0fcompletedOrders\x88\x01\x01\x12\x1b\n" +
|
||||||
"\x06shopId\x18\t \x01(\x03R\x06shopId\x12\x12\n" +
|
"\x06shopId\x18\t \x01(\x03H\bR\x06shopId\x88\x01\x01\x12\x12\n" +
|
||||||
"\x04tags\x18\n" +
|
"\x04tags\x18\n" +
|
||||||
" \x03(\tR\x04tags\x12\x14\n" +
|
" \x03(\tR\x04tags\x12\x14\n" +
|
||||||
"\x05games\x18\v \x03(\x03R\x05games\x12\x1c\n" +
|
"\x05games\x18\v \x03(\x03R\x05games\x12!\n" +
|
||||||
"\tcreatedAt\x18\f \x01(\x03R\tcreatedAt\x12\x1c\n" +
|
"\tcreatedAt\x18\f \x01(\x03H\tR\tcreatedAt\x88\x01\x01\x12!\n" +
|
||||||
"\tupdatedAt\x18\r \x01(\x03R\tupdatedAt\x12\x16\n" +
|
"\tupdatedAt\x18\r \x01(\x03H\n" +
|
||||||
"\x06gender\x18\x0e \x01(\x03R\x06gender\":\n" +
|
"R\tupdatedAt\x88\x01\x01\x12\x1b\n" +
|
||||||
|
"\x06gender\x18\x0e \x01(\x03H\vR\x06gender\x88\x01\x01B\a\n" +
|
||||||
|
"\x05_pageB\b\n" +
|
||||||
|
"\x06_limitB\x05\n" +
|
||||||
|
"\x03_idB\t\n" +
|
||||||
|
"\a_userIdB\t\n" +
|
||||||
|
"\a_statusB\t\n" +
|
||||||
|
"\a_ratingB\x0e\n" +
|
||||||
|
"\f_totalOrdersB\x12\n" +
|
||||||
|
"\x10_completedOrdersB\t\n" +
|
||||||
|
"\a_shopIdB\f\n" +
|
||||||
|
"\n" +
|
||||||
|
"_createdAtB\f\n" +
|
||||||
|
"\n" +
|
||||||
|
"_updatedAtB\t\n" +
|
||||||
|
"\a_gender\":\n" +
|
||||||
"\x11SearchPlayersResp\x12%\n" +
|
"\x11SearchPlayersResp\x12%\n" +
|
||||||
"\aplayers\x18\x01 \x03(\v2\v.pb.PlayersR\aplayers2\xc6\x05\n" +
|
"\aplayers\x18\x01 \x03(\v2\v.pb.PlayersR\aplayers2\xc6\x05\n" +
|
||||||
"\rplayerService\x12H\n" +
|
"\rplayerService\x12H\n" +
|
||||||
@@ -1956,6 +1971,7 @@ func file_player_proto_init() {
|
|||||||
}
|
}
|
||||||
file_player_proto_msgTypes[3].OneofWrappers = []any{}
|
file_player_proto_msgTypes[3].OneofWrappers = []any{}
|
||||||
file_player_proto_msgTypes[14].OneofWrappers = []any{}
|
file_player_proto_msgTypes[14].OneofWrappers = []any{}
|
||||||
|
file_player_proto_msgTypes[20].OneofWrappers = []any{}
|
||||||
type x struct{}
|
type x struct{}
|
||||||
out := protoimpl.TypeBuilder{
|
out := protoimpl.TypeBuilder{
|
||||||
File: protoimpl.DescBuilder{
|
File: protoimpl.DescBuilder{
|
||||||
|
|||||||
@@ -9,6 +9,12 @@ Prometheus:
|
|||||||
|
|
||||||
# k8s://juwan/<service name>:8080
|
# k8s://juwan/<service name>:8080
|
||||||
|
|
||||||
ShopRpcConf:
|
# ===== PROC CONFIG =====
|
||||||
Target: k8s://juwan/shop-rpc-svc.juwan:8080
|
#ShopRpcConf:
|
||||||
|
# Target: k8s://juwan/shop-rpc-svc.juwan:8080
|
||||||
|
|
||||||
|
|
||||||
|
# ===== DEV CONFIG ====
|
||||||
|
ShopRpcConf:
|
||||||
|
Endpoints:
|
||||||
|
- shop-rpc:8080
|
||||||
@@ -4,17 +4,12 @@
|
|||||||
package shop
|
package shop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"juwan-backend/common/utils/contextj"
|
|
||||||
"juwan-backend/common/utils/httpj"
|
|
||||||
"juwan-backend/common/utils/responses"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||||
"juwan-backend/app/shop/api/internal/svc"
|
"juwan-backend/app/shop/api/internal/svc"
|
||||||
"juwan-backend/app/shop/api/internal/types"
|
"juwan-backend/app/shop/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 接受邀请
|
// 接受邀请
|
||||||
@@ -26,12 +21,7 @@ func AcceptInvitationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
l := shop.NewAcceptInvitationLogic(r.Context(), svcCtx)
|
||||||
if err != nil {
|
|
||||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
|
||||||
}
|
|
||||||
ctx := contextj.WithUserID(r.Context(), userId)
|
|
||||||
l := shop.NewAcceptInvitationLogic(ctx, svcCtx)
|
|
||||||
resp, err := l.AcceptInvitation(&req)
|
resp, err := l.AcceptInvitation(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@@ -4,17 +4,12 @@
|
|||||||
package shop
|
package shop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"juwan-backend/common/utils/contextj"
|
|
||||||
"juwan-backend/common/utils/httpj"
|
|
||||||
"juwan-backend/common/utils/responses"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||||
"juwan-backend/app/shop/api/internal/svc"
|
"juwan-backend/app/shop/api/internal/svc"
|
||||||
"juwan-backend/app/shop/api/internal/types"
|
"juwan-backend/app/shop/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 新增店铺公告
|
// 新增店铺公告
|
||||||
@@ -26,12 +21,7 @@ func AddAnnouncementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
l := shop.NewAddAnnouncementLogic(r.Context(), svcCtx)
|
||||||
if err != nil {
|
|
||||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
|
||||||
}
|
|
||||||
ctx := contextj.WithUserID(r.Context(), userId)
|
|
||||||
l := shop.NewAddAnnouncementLogic(ctx, svcCtx)
|
|
||||||
resp, err := l.AddAnnouncement(&req)
|
resp, err := l.AddAnnouncement(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@@ -4,17 +4,12 @@
|
|||||||
package shop
|
package shop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"juwan-backend/common/utils/contextj"
|
|
||||||
"juwan-backend/common/utils/httpj"
|
|
||||||
"juwan-backend/common/utils/responses"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||||
"juwan-backend/app/shop/api/internal/svc"
|
"juwan-backend/app/shop/api/internal/svc"
|
||||||
"juwan-backend/app/shop/api/internal/types"
|
"juwan-backend/app/shop/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 创建店铺
|
// 创建店铺
|
||||||
@@ -26,12 +21,7 @@ func CreateShopHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
l := shop.NewCreateShopLogic(r.Context(), svcCtx)
|
||||||
if err != nil {
|
|
||||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
|
||||||
}
|
|
||||||
ctx := contextj.WithUserID(r.Context(), userId)
|
|
||||||
l := shop.NewCreateShopLogic(ctx, svcCtx)
|
|
||||||
resp, err := l.CreateShop(&req)
|
resp, err := l.CreateShop(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@@ -4,17 +4,12 @@
|
|||||||
package shop
|
package shop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"juwan-backend/common/utils/contextj"
|
|
||||||
"juwan-backend/common/utils/httpj"
|
|
||||||
"juwan-backend/common/utils/responses"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||||
"juwan-backend/app/shop/api/internal/svc"
|
"juwan-backend/app/shop/api/internal/svc"
|
||||||
"juwan-backend/app/shop/api/internal/types"
|
"juwan-backend/app/shop/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 删除店铺公告
|
// 删除店铺公告
|
||||||
@@ -26,12 +21,7 @@ func DeleteAnnouncementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
l := shop.NewDeleteAnnouncementLogic(r.Context(), svcCtx)
|
||||||
if err != nil {
|
|
||||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
|
||||||
}
|
|
||||||
ctx := contextj.WithUserID(r.Context(), userId)
|
|
||||||
l := shop.NewDeleteAnnouncementLogic(ctx, svcCtx)
|
|
||||||
resp, err := l.DeleteAnnouncement(&req)
|
resp, err := l.DeleteAnnouncement(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@@ -4,17 +4,12 @@
|
|||||||
package shop
|
package shop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"juwan-backend/common/utils/contextj"
|
|
||||||
"juwan-backend/common/utils/httpj"
|
|
||||||
"juwan-backend/common/utils/responses"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||||
"juwan-backend/app/shop/api/internal/svc"
|
"juwan-backend/app/shop/api/internal/svc"
|
||||||
"juwan-backend/app/shop/api/internal/types"
|
"juwan-backend/app/shop/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 获取当前用户的店铺
|
// 获取当前用户的店铺
|
||||||
@@ -26,12 +21,7 @@ func GetMyShopHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
l := shop.NewGetMyShopLogic(r.Context(), svcCtx)
|
||||||
if err != nil {
|
|
||||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
|
||||||
}
|
|
||||||
ctx := contextj.WithUserID(r.Context(), userId)
|
|
||||||
l := shop.NewGetMyShopLogic(ctx, svcCtx)
|
|
||||||
resp, err := l.GetMyShop(&req)
|
resp, err := l.GetMyShop(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ package shop
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||||
"juwan-backend/app/shop/api/internal/svc"
|
"juwan-backend/app/shop/api/internal/svc"
|
||||||
"juwan-backend/app/shop/api/internal/types"
|
"juwan-backend/app/shop/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 获取店铺详情
|
// 获取店铺详情
|
||||||
|
|||||||
@@ -4,17 +4,12 @@
|
|||||||
package shop
|
package shop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"juwan-backend/common/utils/contextj"
|
|
||||||
"juwan-backend/common/utils/httpj"
|
|
||||||
"juwan-backend/common/utils/responses"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||||
"juwan-backend/app/shop/api/internal/svc"
|
"juwan-backend/app/shop/api/internal/svc"
|
||||||
"juwan-backend/app/shop/api/internal/types"
|
"juwan-backend/app/shop/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 获取收入统计
|
// 获取收入统计
|
||||||
@@ -26,12 +21,7 @@ func GetShopIncomeStatsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
l := shop.NewGetShopIncomeStatsLogic(r.Context(), svcCtx)
|
||||||
if err != nil {
|
|
||||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
|
||||||
}
|
|
||||||
ctx := contextj.WithUserID(r.Context(), userId)
|
|
||||||
l := shop.NewGetShopIncomeStatsLogic(ctx, svcCtx)
|
|
||||||
resp, err := l.GetShopIncomeStats(&req)
|
resp, err := l.GetShopIncomeStats(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ package shop
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||||
"juwan-backend/app/shop/api/internal/svc"
|
"juwan-backend/app/shop/api/internal/svc"
|
||||||
"juwan-backend/app/shop/api/internal/types"
|
"juwan-backend/app/shop/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 获取店长的店铺
|
// 获取店长的店铺
|
||||||
|
|||||||
@@ -4,17 +4,12 @@
|
|||||||
package shop
|
package shop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"juwan-backend/common/utils/contextj"
|
|
||||||
"juwan-backend/common/utils/httpj"
|
|
||||||
"juwan-backend/common/utils/responses"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||||
"juwan-backend/app/shop/api/internal/svc"
|
"juwan-backend/app/shop/api/internal/svc"
|
||||||
"juwan-backend/app/shop/api/internal/types"
|
"juwan-backend/app/shop/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 邀请打手
|
// 邀请打手
|
||||||
@@ -26,12 +21,7 @@ func InvitePlayerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
l := shop.NewInvitePlayerLogic(r.Context(), svcCtx)
|
||||||
if err != nil {
|
|
||||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
|
||||||
}
|
|
||||||
ctx := contextj.WithUserID(r.Context(), userId)
|
|
||||||
l := shop.NewInvitePlayerLogic(ctx, svcCtx)
|
|
||||||
resp, err := l.InvitePlayer(&req)
|
resp, err := l.InvitePlayer(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@@ -4,17 +4,12 @@
|
|||||||
package shop
|
package shop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"juwan-backend/common/utils/contextj"
|
|
||||||
"juwan-backend/common/utils/httpj"
|
|
||||||
"juwan-backend/common/utils/responses"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||||
"juwan-backend/app/shop/api/internal/svc"
|
"juwan-backend/app/shop/api/internal/svc"
|
||||||
"juwan-backend/app/shop/api/internal/types"
|
"juwan-backend/app/shop/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 拒绝邀请
|
// 拒绝邀请
|
||||||
@@ -26,12 +21,7 @@ func RejectInvitationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
l := shop.NewRejectInvitationLogic(r.Context(), svcCtx)
|
||||||
if err != nil {
|
|
||||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
|
||||||
}
|
|
||||||
ctx := contextj.WithUserID(r.Context(), userId)
|
|
||||||
l := shop.NewRejectInvitationLogic(ctx, svcCtx)
|
|
||||||
resp, err := l.RejectInvitation(&req)
|
resp, err := l.RejectInvitation(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@@ -4,17 +4,12 @@
|
|||||||
package shop
|
package shop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"juwan-backend/common/utils/contextj"
|
|
||||||
"juwan-backend/common/utils/httpj"
|
|
||||||
"juwan-backend/common/utils/responses"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||||
"juwan-backend/app/shop/api/internal/svc"
|
"juwan-backend/app/shop/api/internal/svc"
|
||||||
"juwan-backend/app/shop/api/internal/types"
|
"juwan-backend/app/shop/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 移除打手
|
// 移除打手
|
||||||
@@ -26,12 +21,7 @@ func RemovePlayerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
l := shop.NewRemovePlayerLogic(r.Context(), svcCtx)
|
||||||
if err != nil {
|
|
||||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
|
||||||
}
|
|
||||||
ctx := contextj.WithUserID(r.Context(), userId)
|
|
||||||
l := shop.NewRemovePlayerLogic(ctx, svcCtx)
|
|
||||||
resp, err := l.RemovePlayer(&req)
|
resp, err := l.RemovePlayer(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@@ -4,10 +4,6 @@
|
|||||||
package shop
|
package shop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"juwan-backend/common/utils/contextj"
|
|
||||||
"juwan-backend/common/utils/httpj"
|
|
||||||
"juwan-backend/common/utils/responses"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||||
@@ -26,12 +22,7 @@ func UpdateShopHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
l := shop.NewUpdateShopLogic(r.Context(), svcCtx)
|
||||||
if err != nil {
|
|
||||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
|
||||||
}
|
|
||||||
ctx := contextj.WithUserID(r.Context(), userId)
|
|
||||||
l := shop.NewUpdateShopLogic(ctx, svcCtx)
|
|
||||||
resp, err := l.UpdateShop(&req)
|
resp, err := l.UpdateShop(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@@ -4,17 +4,12 @@
|
|||||||
package shop
|
package shop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"juwan-backend/common/utils/contextj"
|
|
||||||
"juwan-backend/common/utils/httpj"
|
|
||||||
"juwan-backend/common/utils/responses"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||||
"juwan-backend/app/shop/api/internal/svc"
|
"juwan-backend/app/shop/api/internal/svc"
|
||||||
"juwan-backend/app/shop/api/internal/types"
|
"juwan-backend/app/shop/api/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 更新店铺模板
|
// 更新店铺模板
|
||||||
@@ -26,12 +21,7 @@ func UpdateShopTemplateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
l := shop.NewUpdateShopTemplateLogic(r.Context(), svcCtx)
|
||||||
if err != nil {
|
|
||||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
|
||||||
}
|
|
||||||
ctx := contextj.WithUserID(r.Context(), userId)
|
|
||||||
l := shop.NewUpdateShopTemplateLogic(ctx, svcCtx)
|
|
||||||
resp, err := l.UpdateShopTemplate(&req)
|
resp, err := l.UpdateShopTemplate(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ func (l *CreateShopLogic) CreateShop(req *types.CreateShopReq) (resp *types.Shop
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if ownerID == 0 {
|
||||||
|
return nil, errors.New("user not authenticated")
|
||||||
|
}
|
||||||
|
|
||||||
if req.Name == "" {
|
if req.Name == "" {
|
||||||
return nil, errors.New("name is required")
|
return nil, errors.New("name is required")
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ func (l *UpdateShopLogic) UpdateShop(req *types.UpdateShopReq) (resp *types.Shop
|
|||||||
if current.Shops.OwnerId != userID {
|
if current.Shops.OwnerId != userID {
|
||||||
return nil, contextj.ERRILLEGALUSER
|
return nil, contextj.ERRILLEGALUSER
|
||||||
}
|
}
|
||||||
|
logx.Debugf("update shop %+v", req)
|
||||||
|
|
||||||
name := current.Shops.Name
|
name := current.Shops.Name
|
||||||
if req.Name != "" {
|
if req.Name != "" {
|
||||||
|
|||||||
@@ -6,18 +6,22 @@ package svc
|
|||||||
import (
|
import (
|
||||||
"juwan-backend/app/shop/api/internal/config"
|
"juwan-backend/app/shop/api/internal/config"
|
||||||
"juwan-backend/app/shop/rpc/shopservice"
|
"juwan-backend/app/shop/rpc/shopservice"
|
||||||
|
"juwan-backend/common/middlewares"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
"github.com/zeromicro/go-zero/zrpc"
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
ShopRpc shopservice.ShopService
|
ShopRpc shopservice.ShopService
|
||||||
|
HeaderExtractorMiddleware rest.Middleware
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
ShopRpc: shopservice.NewShopService(zrpc.MustNewClient(c.ShopRpcConf)),
|
ShopRpc: shopservice.NewShopService(zrpc.MustNewClient(c.ShopRpcConf)),
|
||||||
|
HeaderExtractorMiddleware: middlewares.NewHeaderExtractorMiddleware().Handle,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"juwan-backend/common/middlewares"
|
||||||
|
|
||||||
"juwan-backend/app/shop/api/internal/config"
|
"juwan-backend/app/shop/api/internal/config"
|
||||||
"juwan-backend/app/shop/api/internal/handler"
|
"juwan-backend/app/shop/api/internal/handler"
|
||||||
@@ -24,6 +25,8 @@ func main() {
|
|||||||
conf.MustLoad(*configFile, &c)
|
conf.MustLoad(*configFile, &c)
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf)
|
server := rest.MustNewServer(c.RestConf)
|
||||||
|
server.Use(middlewares.NewHeaderExtractorMiddleware().Handle)
|
||||||
|
server.Use(middlewares.NewRequestMiddleware().Handle)
|
||||||
defer server.Stop()
|
defer server.Stop()
|
||||||
|
|
||||||
ctx := svc.NewServiceContext(c)
|
ctx := svc.NewServiceContext(c)
|
||||||
|
|||||||
+36
-14
@@ -1,7 +1,6 @@
|
|||||||
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
|
||||||
@@ -12,26 +11,49 @@ Prometheus:
|
|||||||
# - 127.0.0.1:2379
|
# - 127.0.0.1:2379
|
||||||
# Key: pb.rpc
|
# Key: pb.rpc
|
||||||
|
|
||||||
# Target: k8s://juwan/<service name>.<namespace>:8080
|
# ===== PROC Config =====
|
||||||
|
#SnowflakeRpcConf:
|
||||||
|
# Target: k8s://juwan/snowflake-svc:8080
|
||||||
|
#UsersRpcConf:
|
||||||
|
# Target: k8s://juwan/user-rpc-svc:8080
|
||||||
|
|
||||||
|
#DB:
|
||||||
|
# Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@{DB_HOST_RW}.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
# Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@{BD_HOST_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"
|
||||||
|
|
||||||
|
# ===== DEV Config =====
|
||||||
SnowflakeRpcConf:
|
SnowflakeRpcConf:
|
||||||
Target: k8s://juwan/snowflake-svc:8080
|
Endpoints:
|
||||||
|
- snowflake:8080
|
||||||
|
-
|
||||||
|
UsersRpcConf:
|
||||||
|
Endpoints:
|
||||||
|
- user-rpc:8080
|
||||||
|
|
||||||
DB:
|
DB:
|
||||||
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-ro.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
|
||||||
|
|
||||||
CacheConf:
|
CacheConf:
|
||||||
- Host: "${REDIS_M_HOST}"
|
- Host: "${REDIS_HOST}:${REDIS_PORT}"
|
||||||
Type: node
|
Type: node
|
||||||
Pass: "${REDIS_PASSWORD}"
|
|
||||||
User: "default"
|
|
||||||
- Host: "${REDIS_S_HOST}"
|
|
||||||
Type: node
|
|
||||||
Pass: "${REDIS_PASSWORD}"
|
|
||||||
User: "default"
|
|
||||||
|
|
||||||
Log:
|
Log:
|
||||||
Level: info
|
Level: info
|
||||||
|
|
||||||
|
|
||||||
|
# Target: k8s://juwan/<service name>.<namespace>:8080
|
||||||
|
#DB:
|
||||||
|
# Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
# Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-ro.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
zrpc.RpcServerConf
|
zrpc.RpcServerConf
|
||||||
SnowflakeRpcConf zrpc.RpcClientConf
|
SnowflakeRpcConf zrpc.RpcClientConf
|
||||||
|
UsersRpcConf zrpc.RpcClientConf
|
||||||
DB struct {
|
DB struct {
|
||||||
Master string
|
Master string
|
||||||
Slaves string
|
Slaves string
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"juwan-backend/app/shop/rpc/internal/models/schema"
|
||||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||||
|
pb2 "juwan-backend/app/users/rpc/pb"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"juwan-backend/app/shop/rpc/internal/svc"
|
"juwan-backend/app/shop/rpc/internal/svc"
|
||||||
"juwan-backend/app/shop/rpc/pb"
|
"juwan-backend/app/shop/rpc/pb"
|
||||||
@@ -27,8 +31,25 @@ func NewAddShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddShops
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var allowedRoles = []string{"owner", "admin"}
|
||||||
|
var allowedCommissionTypes = []string{"fixed", "percentage"}
|
||||||
|
var allowedDispatchModes = []string{"manual", "auto"}
|
||||||
|
|
||||||
// -----------------------shops-----------------------
|
// -----------------------shops-----------------------
|
||||||
func (l *AddShopsLogic) AddShops(in *pb.AddShopsReq) (*pb.AddShopsResp, error) {
|
func (l *AddShopsLogic) AddShops(in *pb.AddShopsReq) (*pb.AddShopsResp, error) {
|
||||||
|
user, err := l.svcCtx.UsersRpc.GetUsersById(l.ctx, &pb2.GetUsersByIdReq{
|
||||||
|
Id: in.OwnerId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("add shops err: %v", err)
|
||||||
|
return nil, errors.New("user not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !slices.Contains(allowedRoles, user.Users.CurrentRole) {
|
||||||
|
logx.Errorf("add shops err: user %v has no permission to add shop", in.OwnerId)
|
||||||
|
return nil, errors.New("no permission to add shop")
|
||||||
|
}
|
||||||
|
|
||||||
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Errorf("addPlayerServices err:%v", err)
|
logx.Errorf("addPlayerServices err:%v", err)
|
||||||
@@ -44,28 +65,53 @@ func (l *AddShopsLogic) AddShops(in *pb.AddShopsReq) (*pb.AddShopsResp, error) {
|
|||||||
|
|
||||||
rating, err := decimal.NewFromString(in.Rating)
|
rating, err := decimal.NewFromString(in.Rating)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logx.Errorf("addPlayerServices new from string err:%v", err)
|
||||||
return nil, errors.New("invalid rating")
|
return nil, errors.New("invalid rating")
|
||||||
}
|
}
|
||||||
commissionValue, err := decimal.NewFromString(in.CommissionValue)
|
commissionValue, err := decimal.NewFromString(in.CommissionValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logx.Errorf("addPlayerServices new from string err:%v", err)
|
||||||
return nil, errors.New("invalid commissionValue")
|
return nil, errors.New("invalid commissionValue")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = l.svcCtx.ShopModelRO.Shops.Create().
|
commissionType := strings.ToLower(strings.TrimSpace(in.CommissionType))
|
||||||
|
if commissionType == "" {
|
||||||
|
commissionType = "percentage"
|
||||||
|
}
|
||||||
|
if !slices.Contains(allowedCommissionTypes, commissionType) {
|
||||||
|
logx.Errorf("addPlayerServices contains err: invalid commissionType %v", in.CommissionType)
|
||||||
|
return nil, errors.New("invalid commissionType")
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatchMode := strings.ToLower(strings.TrimSpace(in.DispatchMode))
|
||||||
|
if dispatchMode == "" {
|
||||||
|
dispatchMode = "manual"
|
||||||
|
}
|
||||||
|
if !slices.Contains(allowedDispatchModes, dispatchMode) {
|
||||||
|
logx.Errorf("addPlayerServices contains err: invalid dispatchMode %v", in.DispatchMode)
|
||||||
|
return nil, errors.New("invalid dispatchMode")
|
||||||
|
}
|
||||||
|
|
||||||
|
announcements := schema.TextArray{Elements: in.Announcements, Valid: true}
|
||||||
|
if announcements.Elements == nil {
|
||||||
|
announcements.Elements = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = l.svcCtx.ShopModelRW.Shops.Create().
|
||||||
SetID(idResp.Id).
|
SetID(idResp.Id).
|
||||||
SetOwnerID(in.OwnerId).
|
SetOwnerID(idResp.Id).
|
||||||
SetName(in.Name).
|
SetName(in.Name).
|
||||||
SetBanner(in.Banner).
|
SetBanner(in.Banner).
|
||||||
SetDescription(in.Description).
|
SetDescription(in.Description).
|
||||||
SetRating(rating).
|
SetRating(rating).
|
||||||
SetTotalOrders(int(in.TotalOrders)).
|
SetTotalOrders(int(in.TotalOrders)).
|
||||||
SetPlayerCount(int(in.PlayerCount)).
|
SetPlayerCount(int(in.PlayerCount)).
|
||||||
SetNillableCommissionType(&in.CommissionType).
|
SetCommissionType(commissionType).
|
||||||
SetCommissionValue(commissionValue).
|
SetCommissionValue(commissionValue).
|
||||||
SetAllowMultiShop(in.AllowMultiShop).
|
SetAllowMultiShop(in.AllowMultiShop).
|
||||||
SetAllowIndependentOrders(in.AllowIndependentOrders).
|
SetAllowIndependentOrders(in.AllowIndependentOrders).
|
||||||
SetDispatchMode(in.DispatchMode).
|
SetDispatchMode(dispatchMode).
|
||||||
SetAnnouncements(in.Announcements).
|
SetAnnouncements(announcements).
|
||||||
SetTemplateConfig(templateConfig).
|
SetTemplateConfig(templateConfig).
|
||||||
Save(l.ctx)
|
Save(l.ctx)
|
||||||
|
|
||||||
@@ -73,5 +119,6 @@ func (l *AddShopsLogic) AddShops(in *pb.AddShopsReq) (*pb.AddShopsResp, error) {
|
|||||||
logx.Errorf("addPlayerServices err:%v", err)
|
logx.Errorf("addPlayerServices err:%v", err)
|
||||||
return nil, errors.New("add player service failed")
|
return nil, errors.New("add player service failed")
|
||||||
}
|
}
|
||||||
|
logx.Debugf("shop created with id: %v", idResp.Id)
|
||||||
return &pb.AddShopsResp{}, nil
|
return &pb.AddShopsResp{}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func (l *GetShopsByIdLogic) GetShopsById(in *pb.GetShopsByIdReq) (*pb.GetShopsBy
|
|||||||
AllowMultiShop: shop.AllowMultiShop,
|
AllowMultiShop: shop.AllowMultiShop,
|
||||||
AllowIndependentOrders: shop.AllowIndependentOrders,
|
AllowIndependentOrders: shop.AllowIndependentOrders,
|
||||||
DispatchMode: shop.DispatchMode,
|
DispatchMode: shop.DispatchMode,
|
||||||
Announcements: shop.Announcements,
|
Announcements: shop.Announcements.Elements,
|
||||||
TemplateConfig: string(templateConfigBytes),
|
TemplateConfig: string(templateConfigBytes),
|
||||||
CreatedAt: shop.CreatedAt.Unix(),
|
CreatedAt: shop.CreatedAt.Unix(),
|
||||||
UpdatedAt: shop.UpdatedAt.Unix(),
|
UpdatedAt: shop.UpdatedAt.Unix(),
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ func (l *SearchShopsLogic) SearchShops(in *pb.SearchShopsReq) (*pb.SearchShopsRe
|
|||||||
AllowMultiShop: item.AllowMultiShop,
|
AllowMultiShop: item.AllowMultiShop,
|
||||||
AllowIndependentOrders: item.AllowIndependentOrders,
|
AllowIndependentOrders: item.AllowIndependentOrders,
|
||||||
DispatchMode: item.DispatchMode,
|
DispatchMode: item.DispatchMode,
|
||||||
Announcements: item.Announcements,
|
Announcements: item.Announcements.Elements,
|
||||||
TemplateConfig: string(templateConfigBytes),
|
TemplateConfig: string(templateConfigBytes),
|
||||||
CreatedAt: item.CreatedAt.Unix(),
|
CreatedAt: item.CreatedAt.Unix(),
|
||||||
UpdatedAt: item.UpdatedAt.Unix(),
|
UpdatedAt: item.UpdatedAt.Unix(),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"juwan-backend/app/shop/rpc/internal/models/schema"
|
||||||
"juwan-backend/app/shop/rpc/internal/models/shops"
|
"juwan-backend/app/shop/rpc/internal/models/shops"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -75,7 +76,7 @@ func (l *UpdateShopsLogic) UpdateShops(in *pb.UpdateShopsReq) (*pb.UpdateShopsRe
|
|||||||
SetAllowIndependentOrders(in.AllowIndependentOrders)
|
SetAllowIndependentOrders(in.AllowIndependentOrders)
|
||||||
|
|
||||||
if len(in.Announcements) > 0 {
|
if len(in.Announcements) > 0 {
|
||||||
updater = updater.SetAnnouncements(in.Announcements)
|
updater = updater.SetAnnouncements(schema.TextArray{Elements: in.Announcements, Valid: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
if in.TemplateConfig != "" {
|
if in.TemplateConfig != "" {
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ var (
|
|||||||
{Name: "allow_multi_shop", Type: field.TypeBool, Nullable: true, Default: false},
|
{Name: "allow_multi_shop", Type: field.TypeBool, Nullable: true, Default: false},
|
||||||
{Name: "allow_independent_orders", Type: field.TypeBool, Nullable: true, Default: true},
|
{Name: "allow_independent_orders", Type: field.TypeBool, Nullable: true, Default: true},
|
||||||
{Name: "dispatch_mode", Type: field.TypeString, Size: 20, Default: "manual"},
|
{Name: "dispatch_mode", Type: field.TypeString, Size: 20, Default: "manual"},
|
||||||
{Name: "announcements", Type: field.TypeJSON, Nullable: true},
|
{Name: "announcements", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "text[]"}},
|
||||||
{Name: "template_config", Type: field.TypeJSON, Nullable: true},
|
{Name: "template_config", Type: field.TypeJSON, Nullable: true},
|
||||||
{Name: "created_at", Type: field.TypeTime},
|
{Name: "created_at", Type: field.TypeTime},
|
||||||
{Name: "updated_at", Type: field.TypeTime},
|
{Name: "updated_at", Type: field.TypeTime},
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"juwan-backend/app/shop/rpc/internal/models/predicate"
|
"juwan-backend/app/shop/rpc/internal/models/predicate"
|
||||||
|
"juwan-backend/app/shop/rpc/internal/models/schema"
|
||||||
"juwan-backend/app/shop/rpc/internal/models/shopinvitations"
|
"juwan-backend/app/shop/rpc/internal/models/shopinvitations"
|
||||||
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
|
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
|
||||||
"juwan-backend/app/shop/rpc/internal/models/shops"
|
"juwan-backend/app/shop/rpc/internal/models/shops"
|
||||||
@@ -1437,8 +1438,7 @@ type ShopsMutation struct {
|
|||||||
allow_multi_shop *bool
|
allow_multi_shop *bool
|
||||||
allow_independent_orders *bool
|
allow_independent_orders *bool
|
||||||
dispatch_mode *string
|
dispatch_mode *string
|
||||||
announcements *[]string
|
announcements *schema.TextArray
|
||||||
appendannouncements []string
|
|
||||||
template_config *map[string]interface{}
|
template_config *map[string]interface{}
|
||||||
created_at *time.Time
|
created_at *time.Time
|
||||||
updated_at *time.Time
|
updated_at *time.Time
|
||||||
@@ -2138,13 +2138,12 @@ func (m *ShopsMutation) ResetDispatchMode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetAnnouncements sets the "announcements" field.
|
// SetAnnouncements sets the "announcements" field.
|
||||||
func (m *ShopsMutation) SetAnnouncements(s []string) {
|
func (m *ShopsMutation) SetAnnouncements(sa schema.TextArray) {
|
||||||
m.announcements = &s
|
m.announcements = &sa
|
||||||
m.appendannouncements = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Announcements returns the value of the "announcements" field in the mutation.
|
// Announcements returns the value of the "announcements" field in the mutation.
|
||||||
func (m *ShopsMutation) Announcements() (r []string, exists bool) {
|
func (m *ShopsMutation) Announcements() (r schema.TextArray, exists bool) {
|
||||||
v := m.announcements
|
v := m.announcements
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return
|
return
|
||||||
@@ -2155,7 +2154,7 @@ func (m *ShopsMutation) Announcements() (r []string, exists bool) {
|
|||||||
// OldAnnouncements returns the old "announcements" field's value of the Shops entity.
|
// OldAnnouncements returns the old "announcements" field's value of the Shops entity.
|
||||||
// If the Shops object wasn't provided to the builder, the object is fetched from the database.
|
// If the Shops 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.
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
func (m *ShopsMutation) OldAnnouncements(ctx context.Context) (v []string, err error) {
|
func (m *ShopsMutation) OldAnnouncements(ctx context.Context) (v schema.TextArray, err error) {
|
||||||
if !m.op.Is(OpUpdateOne) {
|
if !m.op.Is(OpUpdateOne) {
|
||||||
return v, errors.New("OldAnnouncements is only allowed on UpdateOne operations")
|
return v, errors.New("OldAnnouncements is only allowed on UpdateOne operations")
|
||||||
}
|
}
|
||||||
@@ -2169,23 +2168,9 @@ func (m *ShopsMutation) OldAnnouncements(ctx context.Context) (v []string, err e
|
|||||||
return oldValue.Announcements, nil
|
return oldValue.Announcements, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendAnnouncements adds s to the "announcements" field.
|
|
||||||
func (m *ShopsMutation) AppendAnnouncements(s []string) {
|
|
||||||
m.appendannouncements = append(m.appendannouncements, s...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AppendedAnnouncements returns the list of values that were appended to the "announcements" field in this mutation.
|
|
||||||
func (m *ShopsMutation) AppendedAnnouncements() ([]string, bool) {
|
|
||||||
if len(m.appendannouncements) == 0 {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
return m.appendannouncements, true
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearAnnouncements clears the value of the "announcements" field.
|
// ClearAnnouncements clears the value of the "announcements" field.
|
||||||
func (m *ShopsMutation) ClearAnnouncements() {
|
func (m *ShopsMutation) ClearAnnouncements() {
|
||||||
m.announcements = nil
|
m.announcements = nil
|
||||||
m.appendannouncements = nil
|
|
||||||
m.clearedFields[shops.FieldAnnouncements] = struct{}{}
|
m.clearedFields[shops.FieldAnnouncements] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2198,7 +2183,6 @@ func (m *ShopsMutation) AnnouncementsCleared() bool {
|
|||||||
// ResetAnnouncements resets all changes to the "announcements" field.
|
// ResetAnnouncements resets all changes to the "announcements" field.
|
||||||
func (m *ShopsMutation) ResetAnnouncements() {
|
func (m *ShopsMutation) ResetAnnouncements() {
|
||||||
m.announcements = nil
|
m.announcements = nil
|
||||||
m.appendannouncements = nil
|
|
||||||
delete(m.clearedFields, shops.FieldAnnouncements)
|
delete(m.clearedFields, shops.FieldAnnouncements)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2581,7 +2565,7 @@ func (m *ShopsMutation) SetField(name string, value ent.Value) error {
|
|||||||
m.SetDispatchMode(v)
|
m.SetDispatchMode(v)
|
||||||
return nil
|
return nil
|
||||||
case shops.FieldAnnouncements:
|
case shops.FieldAnnouncements:
|
||||||
v, ok := value.([]string)
|
v, ok := value.(schema.TextArray)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,10 +76,6 @@ func init() {
|
|||||||
shops.DefaultDispatchMode = shopsDescDispatchMode.Default.(string)
|
shops.DefaultDispatchMode = shopsDescDispatchMode.Default.(string)
|
||||||
// shops.DispatchModeValidator is a validator for the "dispatch_mode" field. It is called by the builders before save.
|
// shops.DispatchModeValidator is a validator for the "dispatch_mode" field. It is called by the builders before save.
|
||||||
shops.DispatchModeValidator = shopsDescDispatchMode.Validators[0].(func(string) error)
|
shops.DispatchModeValidator = shopsDescDispatchMode.Validators[0].(func(string) error)
|
||||||
// shopsDescAnnouncements is the schema descriptor for announcements field.
|
|
||||||
shopsDescAnnouncements := shopsFields[13].Descriptor()
|
|
||||||
// shops.DefaultAnnouncements holds the default value on creation for the announcements field.
|
|
||||||
shops.DefaultAnnouncements = shopsDescAnnouncements.Default.([]string)
|
|
||||||
// shopsDescCreatedAt is the schema descriptor for created_at field.
|
// shopsDescCreatedAt is the schema descriptor for created_at field.
|
||||||
shopsDescCreatedAt := shopsFields[15].Descriptor()
|
shopsDescCreatedAt := shopsFields[15].Descriptor()
|
||||||
// shops.DefaultCreatedAt holds the default value on creation for the created_at field.
|
// shops.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package schema
|
package schema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql/driver"
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"entgo.io/ent"
|
"entgo.io/ent"
|
||||||
@@ -8,11 +11,53 @@ import (
|
|||||||
"entgo.io/ent/dialect/entsql"
|
"entgo.io/ent/dialect/entsql"
|
||||||
"entgo.io/ent/schema"
|
"entgo.io/ent/schema"
|
||||||
"entgo.io/ent/schema/field"
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
"github.com/shopspring/decimal"
|
"github.com/shopspring/decimal"
|
||||||
)
|
)
|
||||||
|
|
||||||
var shopDefaultRating = decimal.RequireFromString("5.00")
|
var shopDefaultRating = decimal.RequireFromString("5.00")
|
||||||
|
|
||||||
|
type TextArray pgtype.Array[string]
|
||||||
|
|
||||||
|
func (s *TextArray) Scan(src any) error {
|
||||||
|
if src == nil {
|
||||||
|
s.Elements = []string{}
|
||||||
|
s.Dims = nil
|
||||||
|
s.Valid = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var strSrc string
|
||||||
|
switch v := src.(type) {
|
||||||
|
case string:
|
||||||
|
strSrc = v
|
||||||
|
case []byte:
|
||||||
|
strSrc = string(v)
|
||||||
|
default:
|
||||||
|
return errors.New("failed to scan text array")
|
||||||
|
}
|
||||||
|
|
||||||
|
trimmed := strings.Trim(strSrc, "{}")
|
||||||
|
if len(trimmed) == 0 {
|
||||||
|
s.Elements = []string{}
|
||||||
|
s.Dims = nil
|
||||||
|
s.Valid = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
s.Elements = strings.Split(trimmed, ",")
|
||||||
|
s.Dims = nil
|
||||||
|
s.Valid = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s TextArray) Value() (driver.Value, error) {
|
||||||
|
if s.Elements == nil {
|
||||||
|
return []string{}, nil
|
||||||
|
}
|
||||||
|
return s.Elements, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Shops holds the schema definition for the Shops entity.
|
// Shops holds the schema definition for the Shops entity.
|
||||||
type Shops struct {
|
type Shops struct {
|
||||||
ent.Schema
|
ent.Schema
|
||||||
@@ -56,7 +101,9 @@ func (Shops) Fields() []ent.Field {
|
|||||||
field.Bool("allow_multi_shop").Optional().Default(false),
|
field.Bool("allow_multi_shop").Optional().Default(false),
|
||||||
field.Bool("allow_independent_orders").Optional().Default(true),
|
field.Bool("allow_independent_orders").Optional().Default(true),
|
||||||
field.String("dispatch_mode").MaxLen(20).Default("manual"),
|
field.String("dispatch_mode").MaxLen(20).Default("manual"),
|
||||||
field.Strings("announcements").Optional().Default([]string{}),
|
field.Other("announcements", TextArray{}).
|
||||||
|
SchemaType(map[string]string{dialect.Postgres: "text[]"}).
|
||||||
|
Optional(),
|
||||||
field.JSON("template_config", map[string]any{}).Optional(),
|
field.JSON("template_config", map[string]any{}).Optional(),
|
||||||
field.Time("created_at").Default(time.Now).Immutable(),
|
field.Time("created_at").Default(time.Now).Immutable(),
|
||||||
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
|
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package models
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"juwan-backend/app/shop/rpc/internal/models/schema"
|
||||||
"juwan-backend/app/shop/rpc/internal/models/shops"
|
"juwan-backend/app/shop/rpc/internal/models/shops"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -44,7 +45,7 @@ type Shops struct {
|
|||||||
// DispatchMode holds the value of the "dispatch_mode" field.
|
// DispatchMode holds the value of the "dispatch_mode" field.
|
||||||
DispatchMode string `json:"dispatch_mode,omitempty"`
|
DispatchMode string `json:"dispatch_mode,omitempty"`
|
||||||
// Announcements holds the value of the "announcements" field.
|
// Announcements holds the value of the "announcements" field.
|
||||||
Announcements []string `json:"announcements,omitempty"`
|
Announcements schema.TextArray `json:"announcements,omitempty"`
|
||||||
// TemplateConfig holds the value of the "template_config" field.
|
// TemplateConfig holds the value of the "template_config" field.
|
||||||
TemplateConfig map[string]interface{} `json:"template_config,omitempty"`
|
TemplateConfig map[string]interface{} `json:"template_config,omitempty"`
|
||||||
// CreatedAt holds the value of the "created_at" field.
|
// CreatedAt holds the value of the "created_at" field.
|
||||||
@@ -59,10 +60,12 @@ func (*Shops) scanValues(columns []string) ([]any, error) {
|
|||||||
values := make([]any, len(columns))
|
values := make([]any, len(columns))
|
||||||
for i := range columns {
|
for i := range columns {
|
||||||
switch columns[i] {
|
switch columns[i] {
|
||||||
case shops.FieldAnnouncements, shops.FieldTemplateConfig:
|
case shops.FieldTemplateConfig:
|
||||||
values[i] = new([]byte)
|
values[i] = new([]byte)
|
||||||
case shops.FieldRating, shops.FieldCommissionValue:
|
case shops.FieldRating, shops.FieldCommissionValue:
|
||||||
values[i] = new(decimal.Decimal)
|
values[i] = new(decimal.Decimal)
|
||||||
|
case shops.FieldAnnouncements:
|
||||||
|
values[i] = new(schema.TextArray)
|
||||||
case shops.FieldAllowMultiShop, shops.FieldAllowIndependentOrders:
|
case shops.FieldAllowMultiShop, shops.FieldAllowIndependentOrders:
|
||||||
values[i] = new(sql.NullBool)
|
values[i] = new(sql.NullBool)
|
||||||
case shops.FieldID, shops.FieldOwnerID, shops.FieldTotalOrders, shops.FieldPlayerCount:
|
case shops.FieldID, shops.FieldOwnerID, shops.FieldTotalOrders, shops.FieldPlayerCount:
|
||||||
@@ -167,12 +170,10 @@ func (_m *Shops) assignValues(columns []string, values []any) error {
|
|||||||
_m.DispatchMode = value.String
|
_m.DispatchMode = value.String
|
||||||
}
|
}
|
||||||
case shops.FieldAnnouncements:
|
case shops.FieldAnnouncements:
|
||||||
if value, ok := values[i].(*[]byte); !ok {
|
if value, ok := values[i].(*schema.TextArray); !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field announcements", values[i])
|
return fmt.Errorf("unexpected type %T for field announcements", values[i])
|
||||||
} else if value != nil && len(*value) > 0 {
|
} else if value != nil {
|
||||||
if err := json.Unmarshal(*value, &_m.Announcements); err != nil {
|
_m.Announcements = *value
|
||||||
return fmt.Errorf("unmarshal field announcements: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case shops.FieldTemplateConfig:
|
case shops.FieldTemplateConfig:
|
||||||
if value, ok := values[i].(*[]byte); !ok {
|
if value, ok := values[i].(*[]byte); !ok {
|
||||||
|
|||||||
@@ -102,8 +102,6 @@ var (
|
|||||||
DefaultDispatchMode string
|
DefaultDispatchMode string
|
||||||
// DispatchModeValidator is a validator for the "dispatch_mode" field. It is called by the builders before save.
|
// DispatchModeValidator is a validator for the "dispatch_mode" field. It is called by the builders before save.
|
||||||
DispatchModeValidator func(string) error
|
DispatchModeValidator func(string) error
|
||||||
// DefaultAnnouncements holds the default value on creation for the "announcements" field.
|
|
||||||
DefaultAnnouncements []string
|
|
||||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
DefaultCreatedAt func() time.Time
|
DefaultCreatedAt func() time.Time
|
||||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
@@ -180,6 +178,11 @@ func ByDispatchMode(opts ...sql.OrderTermOption) OrderOption {
|
|||||||
return sql.OrderByField(FieldDispatchMode, opts...).ToFunc()
|
return sql.OrderByField(FieldDispatchMode, opts...).ToFunc()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ByAnnouncements orders the results by the announcements field.
|
||||||
|
func ByAnnouncements(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldAnnouncements, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
// ByCreatedAt orders the results by the created_at field.
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package shops
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"juwan-backend/app/shop/rpc/internal/models/predicate"
|
"juwan-backend/app/shop/rpc/internal/models/predicate"
|
||||||
|
"juwan-backend/app/shop/rpc/internal/models/schema"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
@@ -115,6 +116,11 @@ func DispatchMode(v string) predicate.Shops {
|
|||||||
return predicate.Shops(sql.FieldEQ(FieldDispatchMode, v))
|
return predicate.Shops(sql.FieldEQ(FieldDispatchMode, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Announcements applies equality check predicate on the "announcements" field. It's identical to AnnouncementsEQ.
|
||||||
|
func Announcements(v schema.TextArray) predicate.Shops {
|
||||||
|
return predicate.Shops(sql.FieldEQ(FieldAnnouncements, v))
|
||||||
|
}
|
||||||
|
|
||||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
func CreatedAt(v time.Time) predicate.Shops {
|
func CreatedAt(v time.Time) predicate.Shops {
|
||||||
return predicate.Shops(sql.FieldEQ(FieldCreatedAt, v))
|
return predicate.Shops(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
@@ -740,6 +746,46 @@ func DispatchModeContainsFold(v string) predicate.Shops {
|
|||||||
return predicate.Shops(sql.FieldContainsFold(FieldDispatchMode, v))
|
return predicate.Shops(sql.FieldContainsFold(FieldDispatchMode, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AnnouncementsEQ applies the EQ predicate on the "announcements" field.
|
||||||
|
func AnnouncementsEQ(v schema.TextArray) predicate.Shops {
|
||||||
|
return predicate.Shops(sql.FieldEQ(FieldAnnouncements, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AnnouncementsNEQ applies the NEQ predicate on the "announcements" field.
|
||||||
|
func AnnouncementsNEQ(v schema.TextArray) predicate.Shops {
|
||||||
|
return predicate.Shops(sql.FieldNEQ(FieldAnnouncements, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AnnouncementsIn applies the In predicate on the "announcements" field.
|
||||||
|
func AnnouncementsIn(vs ...schema.TextArray) predicate.Shops {
|
||||||
|
return predicate.Shops(sql.FieldIn(FieldAnnouncements, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AnnouncementsNotIn applies the NotIn predicate on the "announcements" field.
|
||||||
|
func AnnouncementsNotIn(vs ...schema.TextArray) predicate.Shops {
|
||||||
|
return predicate.Shops(sql.FieldNotIn(FieldAnnouncements, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AnnouncementsGT applies the GT predicate on the "announcements" field.
|
||||||
|
func AnnouncementsGT(v schema.TextArray) predicate.Shops {
|
||||||
|
return predicate.Shops(sql.FieldGT(FieldAnnouncements, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AnnouncementsGTE applies the GTE predicate on the "announcements" field.
|
||||||
|
func AnnouncementsGTE(v schema.TextArray) predicate.Shops {
|
||||||
|
return predicate.Shops(sql.FieldGTE(FieldAnnouncements, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AnnouncementsLT applies the LT predicate on the "announcements" field.
|
||||||
|
func AnnouncementsLT(v schema.TextArray) predicate.Shops {
|
||||||
|
return predicate.Shops(sql.FieldLT(FieldAnnouncements, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AnnouncementsLTE applies the LTE predicate on the "announcements" field.
|
||||||
|
func AnnouncementsLTE(v schema.TextArray) predicate.Shops {
|
||||||
|
return predicate.Shops(sql.FieldLTE(FieldAnnouncements, v))
|
||||||
|
}
|
||||||
|
|
||||||
// AnnouncementsIsNil applies the IsNil predicate on the "announcements" field.
|
// AnnouncementsIsNil applies the IsNil predicate on the "announcements" field.
|
||||||
func AnnouncementsIsNil() predicate.Shops {
|
func AnnouncementsIsNil() predicate.Shops {
|
||||||
return predicate.Shops(sql.FieldIsNull(FieldAnnouncements))
|
return predicate.Shops(sql.FieldIsNull(FieldAnnouncements))
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"juwan-backend/app/shop/rpc/internal/models/schema"
|
||||||
"juwan-backend/app/shop/rpc/internal/models/shops"
|
"juwan-backend/app/shop/rpc/internal/models/shops"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -166,11 +167,19 @@ func (_c *ShopsCreate) SetNillableDispatchMode(v *string) *ShopsCreate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetAnnouncements sets the "announcements" field.
|
// SetAnnouncements sets the "announcements" field.
|
||||||
func (_c *ShopsCreate) SetAnnouncements(v []string) *ShopsCreate {
|
func (_c *ShopsCreate) SetAnnouncements(v schema.TextArray) *ShopsCreate {
|
||||||
_c.mutation.SetAnnouncements(v)
|
_c.mutation.SetAnnouncements(v)
|
||||||
return _c
|
return _c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetNillableAnnouncements sets the "announcements" field if the given value is not nil.
|
||||||
|
func (_c *ShopsCreate) SetNillableAnnouncements(v *schema.TextArray) *ShopsCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetAnnouncements(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
// SetTemplateConfig sets the "template_config" field.
|
// SetTemplateConfig sets the "template_config" field.
|
||||||
func (_c *ShopsCreate) SetTemplateConfig(v map[string]interface{}) *ShopsCreate {
|
func (_c *ShopsCreate) SetTemplateConfig(v map[string]interface{}) *ShopsCreate {
|
||||||
_c.mutation.SetTemplateConfig(v)
|
_c.mutation.SetTemplateConfig(v)
|
||||||
@@ -274,10 +283,6 @@ func (_c *ShopsCreate) defaults() {
|
|||||||
v := shops.DefaultDispatchMode
|
v := shops.DefaultDispatchMode
|
||||||
_c.mutation.SetDispatchMode(v)
|
_c.mutation.SetDispatchMode(v)
|
||||||
}
|
}
|
||||||
if _, ok := _c.mutation.Announcements(); !ok {
|
|
||||||
v := shops.DefaultAnnouncements
|
|
||||||
_c.mutation.SetAnnouncements(v)
|
|
||||||
}
|
|
||||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||||
v := shops.DefaultCreatedAt()
|
v := shops.DefaultCreatedAt()
|
||||||
_c.mutation.SetCreatedAt(v)
|
_c.mutation.SetCreatedAt(v)
|
||||||
@@ -407,7 +412,7 @@ func (_c *ShopsCreate) createSpec() (*Shops, *sqlgraph.CreateSpec) {
|
|||||||
_node.DispatchMode = value
|
_node.DispatchMode = value
|
||||||
}
|
}
|
||||||
if value, ok := _c.mutation.Announcements(); ok {
|
if value, ok := _c.mutation.Announcements(); ok {
|
||||||
_spec.SetField(shops.FieldAnnouncements, field.TypeJSON, value)
|
_spec.SetField(shops.FieldAnnouncements, field.TypeOther, value)
|
||||||
_node.Announcements = value
|
_node.Announcements = value
|
||||||
}
|
}
|
||||||
if value, ok := _c.mutation.TemplateConfig(); ok {
|
if value, ok := _c.mutation.TemplateConfig(); ok {
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"juwan-backend/app/shop/rpc/internal/models/predicate"
|
"juwan-backend/app/shop/rpc/internal/models/predicate"
|
||||||
|
"juwan-backend/app/shop/rpc/internal/models/schema"
|
||||||
"juwan-backend/app/shop/rpc/internal/models/shops"
|
"juwan-backend/app/shop/rpc/internal/models/shops"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
"entgo.io/ent/dialect/sql/sqljson"
|
|
||||||
"entgo.io/ent/schema/field"
|
"entgo.io/ent/schema/field"
|
||||||
"github.com/shopspring/decimal"
|
"github.com/shopspring/decimal"
|
||||||
)
|
)
|
||||||
@@ -262,14 +262,16 @@ func (_u *ShopsUpdate) SetNillableDispatchMode(v *string) *ShopsUpdate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetAnnouncements sets the "announcements" field.
|
// SetAnnouncements sets the "announcements" field.
|
||||||
func (_u *ShopsUpdate) SetAnnouncements(v []string) *ShopsUpdate {
|
func (_u *ShopsUpdate) SetAnnouncements(v schema.TextArray) *ShopsUpdate {
|
||||||
_u.mutation.SetAnnouncements(v)
|
_u.mutation.SetAnnouncements(v)
|
||||||
return _u
|
return _u
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendAnnouncements appends value to the "announcements" field.
|
// SetNillableAnnouncements sets the "announcements" field if the given value is not nil.
|
||||||
func (_u *ShopsUpdate) AppendAnnouncements(v []string) *ShopsUpdate {
|
func (_u *ShopsUpdate) SetNillableAnnouncements(v *schema.TextArray) *ShopsUpdate {
|
||||||
_u.mutation.AppendAnnouncements(v)
|
if v != nil {
|
||||||
|
_u.SetAnnouncements(*v)
|
||||||
|
}
|
||||||
return _u
|
return _u
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -437,15 +439,10 @@ func (_u *ShopsUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|||||||
_spec.SetField(shops.FieldDispatchMode, field.TypeString, value)
|
_spec.SetField(shops.FieldDispatchMode, field.TypeString, value)
|
||||||
}
|
}
|
||||||
if value, ok := _u.mutation.Announcements(); ok {
|
if value, ok := _u.mutation.Announcements(); ok {
|
||||||
_spec.SetField(shops.FieldAnnouncements, field.TypeJSON, value)
|
_spec.SetField(shops.FieldAnnouncements, field.TypeOther, value)
|
||||||
}
|
|
||||||
if value, ok := _u.mutation.AppendedAnnouncements(); ok {
|
|
||||||
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
||||||
sqljson.Append(u, shops.FieldAnnouncements, value)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if _u.mutation.AnnouncementsCleared() {
|
if _u.mutation.AnnouncementsCleared() {
|
||||||
_spec.ClearField(shops.FieldAnnouncements, field.TypeJSON)
|
_spec.ClearField(shops.FieldAnnouncements, field.TypeOther)
|
||||||
}
|
}
|
||||||
if value, ok := _u.mutation.TemplateConfig(); ok {
|
if value, ok := _u.mutation.TemplateConfig(); ok {
|
||||||
_spec.SetField(shops.FieldTemplateConfig, field.TypeJSON, value)
|
_spec.SetField(shops.FieldTemplateConfig, field.TypeJSON, value)
|
||||||
@@ -708,14 +705,16 @@ func (_u *ShopsUpdateOne) SetNillableDispatchMode(v *string) *ShopsUpdateOne {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetAnnouncements sets the "announcements" field.
|
// SetAnnouncements sets the "announcements" field.
|
||||||
func (_u *ShopsUpdateOne) SetAnnouncements(v []string) *ShopsUpdateOne {
|
func (_u *ShopsUpdateOne) SetAnnouncements(v schema.TextArray) *ShopsUpdateOne {
|
||||||
_u.mutation.SetAnnouncements(v)
|
_u.mutation.SetAnnouncements(v)
|
||||||
return _u
|
return _u
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendAnnouncements appends value to the "announcements" field.
|
// SetNillableAnnouncements sets the "announcements" field if the given value is not nil.
|
||||||
func (_u *ShopsUpdateOne) AppendAnnouncements(v []string) *ShopsUpdateOne {
|
func (_u *ShopsUpdateOne) SetNillableAnnouncements(v *schema.TextArray) *ShopsUpdateOne {
|
||||||
_u.mutation.AppendAnnouncements(v)
|
if v != nil {
|
||||||
|
_u.SetAnnouncements(*v)
|
||||||
|
}
|
||||||
return _u
|
return _u
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -913,15 +912,10 @@ func (_u *ShopsUpdateOne) sqlSave(ctx context.Context) (_node *Shops, err error)
|
|||||||
_spec.SetField(shops.FieldDispatchMode, field.TypeString, value)
|
_spec.SetField(shops.FieldDispatchMode, field.TypeString, value)
|
||||||
}
|
}
|
||||||
if value, ok := _u.mutation.Announcements(); ok {
|
if value, ok := _u.mutation.Announcements(); ok {
|
||||||
_spec.SetField(shops.FieldAnnouncements, field.TypeJSON, value)
|
_spec.SetField(shops.FieldAnnouncements, field.TypeOther, value)
|
||||||
}
|
|
||||||
if value, ok := _u.mutation.AppendedAnnouncements(); ok {
|
|
||||||
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
||||||
sqljson.Append(u, shops.FieldAnnouncements, value)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if _u.mutation.AnnouncementsCleared() {
|
if _u.mutation.AnnouncementsCleared() {
|
||||||
_spec.ClearField(shops.FieldAnnouncements, field.TypeJSON)
|
_spec.ClearField(shops.FieldAnnouncements, field.TypeOther)
|
||||||
}
|
}
|
||||||
if value, ok := _u.mutation.TemplateConfig(); ok {
|
if value, ok := _u.mutation.TemplateConfig(); ok {
|
||||||
_spec.SetField(shops.FieldTemplateConfig, field.TypeJSON, value)
|
_spec.SetField(shops.FieldTemplateConfig, field.TypeJSON, value)
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package svc
|
package svc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
stdsql "database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"juwan-backend/app/shop/rpc/internal/config"
|
"juwan-backend/app/shop/rpc/internal/config"
|
||||||
"juwan-backend/app/shop/rpc/internal/models"
|
"juwan-backend/app/shop/rpc/internal/models"
|
||||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||||
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
"juwan-backend/common/redisx"
|
"juwan-backend/common/redisx"
|
||||||
"juwan-backend/common/snowflakex"
|
"juwan-backend/common/snowflakex"
|
||||||
"juwan-backend/pkg/adapter"
|
"juwan-backend/pkg/adapter"
|
||||||
@@ -12,27 +14,32 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"ariga.io/entcache"
|
"ariga.io/entcache"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
_ "github.com/jackc/pgx/v5/stdlib"
|
_ "github.com/jackc/pgx/v5/stdlib"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
Snowflake snowflake.SnowflakeServiceClient
|
Snowflake snowflake.SnowflakeServiceClient
|
||||||
|
UsersRpc usercenter.Usercenter
|
||||||
ShopModelRW *models.Client
|
ShopModelRW *models.Client
|
||||||
ShopModelRO *models.Client
|
ShopModelRO *models.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
RWConn, err := sql.Open("pgx", c.DB.Master)
|
rawRW, err := stdsql.Open("pgx", c.DB.Master)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
ROConn, err := sql.Open("pgx", c.DB.Slaves)
|
rawRO, err := stdsql.Open("pgx", c.DB.Slaves)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
RWConn := sql.OpenDB(dialect.Postgres, rawRW)
|
||||||
|
ROConn := sql.OpenDB(dialect.Postgres, rawRO)
|
||||||
|
|
||||||
redisCluster, err := redisx.ConnectMasterSlaveCluster(c.CacheConf, 5*time.Second)
|
redisCluster, err := redisx.ConnectMasterSlaveCluster(c.CacheConf, 5*time.Second)
|
||||||
if redisCluster == nil || err != nil {
|
if redisCluster == nil || err != nil {
|
||||||
@@ -58,6 +65,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
Snowflake: snowflakex.NewClient(c.SnowflakeRpcConf),
|
Snowflake: snowflakex.NewClient(c.SnowflakeRpcConf),
|
||||||
|
UsersRpc: usercenter.NewUsercenter(zrpc.MustNewClient(c.UsersRpcConf)),
|
||||||
ShopModelRO: models.NewClient(roModelOpts...),
|
ShopModelRO: models.NewClient(roModelOpts...),
|
||||||
ShopModelRW: models.NewClient(rwModelOpts...),
|
ShopModelRW: models.NewClient(rwModelOpts...),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,45 @@
|
|||||||
Name: pb.rpc
|
Name: pb.rpc
|
||||||
ListenOn: 0.0.0.0:8080
|
ListenOn: 0.0.0.0:8080
|
||||||
|
|
||||||
DataSource: "${DB_URI}?sslmode=disable"
|
|
||||||
|
|
||||||
UserVeriRpcConf :
|
# ===== PROC Config =====
|
||||||
Target: k8s://juwan/user_verifications-rpc-svc.juwan:8080
|
#SnowflakeRpcConf:
|
||||||
|
# Target: k8s://juwan/snowflake-svc.juwan:8080
|
||||||
|
#UserRpcConf:
|
||||||
|
# Target: k8s://juwan/user-rpc-svc.juwan: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
|
||||||
|
|
||||||
|
# ===== DEV Config =====
|
||||||
SnowflakeRpcConf:
|
SnowflakeRpcConf:
|
||||||
Target: k8s://juwan/snowflake-svc.juwan:8080
|
Endpoints:
|
||||||
|
- snowflake:8080
|
||||||
|
UserRpcConf:
|
||||||
|
Endpoints:
|
||||||
|
- user-rpc:8080
|
||||||
|
|
||||||
DB:
|
DB:
|
||||||
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
Slave: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-ro.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
Slave: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
|
||||||
CacheConf:
|
CacheConf:
|
||||||
- Host: "${REDIS_M_HOST}"
|
- Host: "${REDIS_HOST}:${REDIS_PORT}"
|
||||||
Type: node
|
Type: node
|
||||||
Pass: "${REDIS_PASSWORD}"
|
|
||||||
User: "default"
|
|
||||||
- Host: "${REDIS_S_HOST}"
|
|
||||||
Type: node
|
|
||||||
Pass: "${REDIS_PASSWORD}"
|
|
||||||
User: "default"
|
|
||||||
|
|
||||||
Log:
|
Log:
|
||||||
Level: info
|
Level: debug
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ type Config struct {
|
|||||||
Slave string
|
Slave string
|
||||||
}
|
}
|
||||||
CacheConf cache.CacheConf
|
CacheConf cache.CacheConf
|
||||||
UserVeriRpcConf zrpc.RpcClientConf
|
|
||||||
SnowflakeRpcConf zrpc.RpcClientConf
|
SnowflakeRpcConf zrpc.RpcClientConf
|
||||||
|
UserRpcConf zrpc.RpcClientConf
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/schema"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/pb"
|
||||||
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
|
"slices"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AddOrUpdateUserVerificationsLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAddOrUpdateUserVerificationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddOrUpdateUserVerificationsLogic {
|
||||||
|
return &AddOrUpdateUserVerificationsLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *AddOrUpdateUserVerificationsLogic) AddOrUpdateUserVerifications(in *pb.AddOrUpdateUserVerificationsReq) (*pb.AddOrUpdateUserVerificationsResp, error) {
|
||||||
|
NotFoundError := &models.NotFoundError{}
|
||||||
|
var materials schema.MaterialStruct
|
||||||
|
|
||||||
|
uv, vErr := l.svcCtx.UserVeriModelRO.Query().
|
||||||
|
Where(
|
||||||
|
userverifications.UserIDEQ(in.UserId),
|
||||||
|
userverifications.RoleEQ(in.Role),
|
||||||
|
userverifications.StatusNEQ("rejected"),
|
||||||
|
).
|
||||||
|
First(l.ctx)
|
||||||
|
if vErr != nil && !errors.As(vErr, &NotFoundError) {
|
||||||
|
logx.Errorf("add or update user verifications: get user err:%v", vErr)
|
||||||
|
return nil, errors.New("")
|
||||||
|
}
|
||||||
|
|
||||||
|
isRole, err := l.checkIsRole(in.UserId, in.Role)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("add or update user verifications: check user err:%v", err)
|
||||||
|
return nil, errors.New("check user role failed")
|
||||||
|
}
|
||||||
|
if isRole {
|
||||||
|
return nil, errors.New("user already has the role")
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonErr := json.Unmarshal([]byte(in.Material), &materials)
|
||||||
|
if jsonErr != nil {
|
||||||
|
logx.Errorf("add or update user verifications: marshal materials err:%v", jsonErr)
|
||||||
|
return nil, errors.New("invalid materials")
|
||||||
|
}
|
||||||
|
|
||||||
|
idResp, rpcErr := l.svcCtx.SnowflakeRpc.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||||
|
if errors.As(vErr, &NotFoundError) {
|
||||||
|
if rpcErr != nil {
|
||||||
|
logx.Errorf("add or update user verifications: get next id err:%v", rpcErr)
|
||||||
|
return nil, errors.New("generate id failed: ")
|
||||||
|
}
|
||||||
|
|
||||||
|
uv, err = l.svcCtx.UserVeriModelRW.Create().
|
||||||
|
SetID(idResp.Id).
|
||||||
|
SetUserID(in.UserId).
|
||||||
|
SetRole(in.Role).
|
||||||
|
SetMaterials(materials).
|
||||||
|
SetRejectReason("").
|
||||||
|
SetReviewedBy(0).
|
||||||
|
Save(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("add or update user verifications: create user verifications err:%v", err)
|
||||||
|
return nil, errors.New("create user verifications failed")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
uv, err = uv.Update().
|
||||||
|
SetRole(in.Role).
|
||||||
|
SetMaterials(materials).
|
||||||
|
Save(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("add or update user verifications: update user verifications err:%v", err)
|
||||||
|
return nil, errors.New("update user verifications failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.AddOrUpdateUserVerificationsResp{
|
||||||
|
Success: true,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *AddOrUpdateUserVerificationsLogic) checkIsRole(userid int64, role string) (bool, error) {
|
||||||
|
user, err := l.svcCtx.UserRpc.GetUsersById(l.ctx, &usercenter.GetUsersByIdReq{
|
||||||
|
Id: userid,
|
||||||
|
})
|
||||||
|
logx.Debug("checkIsRole user:", user)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
logx.Debug("checkIsRole user verified roles:", user.Users.VerifiedRoles)
|
||||||
|
if slices.Contains(user.Users.VerifiedRoles, role) {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
|
||||||
|
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ListUserVerificationsByUserIdLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewListUserVerificationsByUserIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListUserVerificationsByUserIdLogic {
|
||||||
|
return &ListUserVerificationsByUserIdLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListUserVerificationsByUserIdLogic) ListUserVerificationsByUserId(in *pb.ListUserVerificationsByUserIdReq) (*pb.ListUserVerificationsByUserIdResp, error) {
|
||||||
|
all, err := l.svcCtx.UserVeriModelRO.Query().
|
||||||
|
Where(userverifications.UserIDEQ(in.UserId)).
|
||||||
|
All(l.ctx)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("ListUserVerificationsByUserId err: %v", err)
|
||||||
|
return nil, errors.New("list user verifications by user id err")
|
||||||
|
}
|
||||||
|
|
||||||
|
list := make([]*pb.UserVerifications, 0, len(all))
|
||||||
|
for _, v := range all {
|
||||||
|
var temp pb.UserVerifications
|
||||||
|
err = copier.Copy(&temp, v)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("copy user verifications err: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
temp.CreatedAt = v.CreatedAt.Unix()
|
||||||
|
temp.UpdatedAt = v.UpdatedAt.Unix()
|
||||||
|
if v.ReviewedAt != nil {
|
||||||
|
temp.ReviewedAt = v.ReviewedAt.Unix()
|
||||||
|
}
|
||||||
|
list = append(list, &temp)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.ListUserVerificationsByUserIdResp{
|
||||||
|
UserVerifications: list,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -31,11 +31,7 @@ func (l *SearchUserVerificationsLogic) SearchUserVerifications(in *pb.SearchUser
|
|||||||
logx.Errorf("Limit exceeds max limit: %d", in.Limit)
|
logx.Errorf("Limit exceeds max limit: %d", in.Limit)
|
||||||
return nil, errors.New("limit exceeds max limit")
|
return nil, errors.New("limit exceeds max limit")
|
||||||
}
|
}
|
||||||
verifications, err := l.svcCtx.UserVeriModelRO.Query().Where(userverifications.Or(
|
verifications, err := l.svcCtx.UserVeriModelRO.Query().Where(userverifications.UserIDEQ(in.UserId)).
|
||||||
userverifications.UserIDEQ(in.UserId),
|
|
||||||
userverifications.StatusEQ(in.Status),
|
|
||||||
userverifications.Role(in.Role),
|
|
||||||
)).
|
|
||||||
Offset(int(in.Page * in.Limit)).
|
Offset(int(in.Page * in.Limit)).
|
||||||
Limit(int(in.Limit)).
|
Limit(int(in.Limit)).
|
||||||
All(l.ctx)
|
All(l.ctx)
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ var (
|
|||||||
UserVerificationsColumns = []*schema.Column{
|
UserVerificationsColumns = []*schema.Column{
|
||||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
{Name: "user_id", Type: field.TypeInt64, Unique: true},
|
{Name: "user_id", Type: field.TypeInt64, Unique: true},
|
||||||
{Name: "role", Type: field.TypeString, Unique: true},
|
{Name: "role", Type: field.TypeString},
|
||||||
{Name: "status", Type: field.TypeString, Default: "pending"},
|
{Name: "status", Type: field.TypeString, Default: "pending"},
|
||||||
{Name: "materials", Type: field.TypeJSON},
|
{Name: "materials", Type: field.TypeJSON},
|
||||||
{Name: "reject_reason", Type: field.TypeString, Default: ""},
|
{Name: "reject_reason", Type: field.TypeString, Nullable: true},
|
||||||
{Name: "reviewed_by", Type: field.TypeInt64},
|
{Name: "reviewed_by", Type: field.TypeInt64, Nullable: true},
|
||||||
{Name: "reviewed_at", Type: field.TypeTime},
|
{Name: "reviewed_at", Type: field.TypeTime, Nullable: true},
|
||||||
{Name: "created_at", Type: field.TypeTime},
|
{Name: "created_at", Type: field.TypeTime, Nullable: true},
|
||||||
{Name: "updated_at", Type: field.TypeTime},
|
{Name: "updated_at", Type: field.TypeTime, Nullable: true},
|
||||||
}
|
}
|
||||||
// UserVerificationsTable holds the schema information for the "user_verifications" table.
|
// UserVerificationsTable holds the schema information for the "user_verifications" table.
|
||||||
UserVerificationsTable = &schema.Table{
|
UserVerificationsTable = &schema.Table{
|
||||||
|
|||||||
@@ -336,7 +336,7 @@ func (m *UserVerificationsMutation) RejectReason() (r string, exists bool) {
|
|||||||
// OldRejectReason returns the old "reject_reason" field's value of the UserVerifications entity.
|
// OldRejectReason returns the old "reject_reason" field's value of the UserVerifications entity.
|
||||||
// If the UserVerifications object wasn't provided to the builder, the object is fetched from the database.
|
// If the UserVerifications 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.
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
func (m *UserVerificationsMutation) OldRejectReason(ctx context.Context) (v string, err error) {
|
func (m *UserVerificationsMutation) OldRejectReason(ctx context.Context) (v *string, err error) {
|
||||||
if !m.op.Is(OpUpdateOne) {
|
if !m.op.Is(OpUpdateOne) {
|
||||||
return v, errors.New("OldRejectReason is only allowed on UpdateOne operations")
|
return v, errors.New("OldRejectReason is only allowed on UpdateOne operations")
|
||||||
}
|
}
|
||||||
@@ -350,9 +350,22 @@ func (m *UserVerificationsMutation) OldRejectReason(ctx context.Context) (v stri
|
|||||||
return oldValue.RejectReason, nil
|
return oldValue.RejectReason, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearRejectReason clears the value of the "reject_reason" field.
|
||||||
|
func (m *UserVerificationsMutation) ClearRejectReason() {
|
||||||
|
m.reject_reason = nil
|
||||||
|
m.clearedFields[userverifications.FieldRejectReason] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RejectReasonCleared returns if the "reject_reason" field was cleared in this mutation.
|
||||||
|
func (m *UserVerificationsMutation) RejectReasonCleared() bool {
|
||||||
|
_, ok := m.clearedFields[userverifications.FieldRejectReason]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
// ResetRejectReason resets all changes to the "reject_reason" field.
|
// ResetRejectReason resets all changes to the "reject_reason" field.
|
||||||
func (m *UserVerificationsMutation) ResetRejectReason() {
|
func (m *UserVerificationsMutation) ResetRejectReason() {
|
||||||
m.reject_reason = nil
|
m.reject_reason = nil
|
||||||
|
delete(m.clearedFields, userverifications.FieldRejectReason)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetReviewedBy sets the "reviewed_by" field.
|
// SetReviewedBy sets the "reviewed_by" field.
|
||||||
@@ -373,7 +386,7 @@ func (m *UserVerificationsMutation) ReviewedBy() (r int64, exists bool) {
|
|||||||
// OldReviewedBy returns the old "reviewed_by" field's value of the UserVerifications entity.
|
// OldReviewedBy returns the old "reviewed_by" field's value of the UserVerifications entity.
|
||||||
// If the UserVerifications object wasn't provided to the builder, the object is fetched from the database.
|
// If the UserVerifications 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.
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
func (m *UserVerificationsMutation) OldReviewedBy(ctx context.Context) (v int64, err error) {
|
func (m *UserVerificationsMutation) OldReviewedBy(ctx context.Context) (v *int64, err error) {
|
||||||
if !m.op.Is(OpUpdateOne) {
|
if !m.op.Is(OpUpdateOne) {
|
||||||
return v, errors.New("OldReviewedBy is only allowed on UpdateOne operations")
|
return v, errors.New("OldReviewedBy is only allowed on UpdateOne operations")
|
||||||
}
|
}
|
||||||
@@ -405,10 +418,24 @@ func (m *UserVerificationsMutation) AddedReviewedBy() (r int64, exists bool) {
|
|||||||
return *v, true
|
return *v, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearReviewedBy clears the value of the "reviewed_by" field.
|
||||||
|
func (m *UserVerificationsMutation) ClearReviewedBy() {
|
||||||
|
m.reviewed_by = nil
|
||||||
|
m.addreviewed_by = nil
|
||||||
|
m.clearedFields[userverifications.FieldReviewedBy] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedByCleared returns if the "reviewed_by" field was cleared in this mutation.
|
||||||
|
func (m *UserVerificationsMutation) ReviewedByCleared() bool {
|
||||||
|
_, ok := m.clearedFields[userverifications.FieldReviewedBy]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
// ResetReviewedBy resets all changes to the "reviewed_by" field.
|
// ResetReviewedBy resets all changes to the "reviewed_by" field.
|
||||||
func (m *UserVerificationsMutation) ResetReviewedBy() {
|
func (m *UserVerificationsMutation) ResetReviewedBy() {
|
||||||
m.reviewed_by = nil
|
m.reviewed_by = nil
|
||||||
m.addreviewed_by = nil
|
m.addreviewed_by = nil
|
||||||
|
delete(m.clearedFields, userverifications.FieldReviewedBy)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetReviewedAt sets the "reviewed_at" field.
|
// SetReviewedAt sets the "reviewed_at" field.
|
||||||
@@ -428,7 +455,7 @@ func (m *UserVerificationsMutation) ReviewedAt() (r time.Time, exists bool) {
|
|||||||
// OldReviewedAt returns the old "reviewed_at" field's value of the UserVerifications entity.
|
// OldReviewedAt returns the old "reviewed_at" field's value of the UserVerifications entity.
|
||||||
// If the UserVerifications object wasn't provided to the builder, the object is fetched from the database.
|
// If the UserVerifications 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.
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
func (m *UserVerificationsMutation) OldReviewedAt(ctx context.Context) (v time.Time, err error) {
|
func (m *UserVerificationsMutation) OldReviewedAt(ctx context.Context) (v *time.Time, err error) {
|
||||||
if !m.op.Is(OpUpdateOne) {
|
if !m.op.Is(OpUpdateOne) {
|
||||||
return v, errors.New("OldReviewedAt is only allowed on UpdateOne operations")
|
return v, errors.New("OldReviewedAt is only allowed on UpdateOne operations")
|
||||||
}
|
}
|
||||||
@@ -442,9 +469,22 @@ func (m *UserVerificationsMutation) OldReviewedAt(ctx context.Context) (v time.T
|
|||||||
return oldValue.ReviewedAt, nil
|
return oldValue.ReviewedAt, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearReviewedAt clears the value of the "reviewed_at" field.
|
||||||
|
func (m *UserVerificationsMutation) ClearReviewedAt() {
|
||||||
|
m.reviewed_at = nil
|
||||||
|
m.clearedFields[userverifications.FieldReviewedAt] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedAtCleared returns if the "reviewed_at" field was cleared in this mutation.
|
||||||
|
func (m *UserVerificationsMutation) ReviewedAtCleared() bool {
|
||||||
|
_, ok := m.clearedFields[userverifications.FieldReviewedAt]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
// ResetReviewedAt resets all changes to the "reviewed_at" field.
|
// ResetReviewedAt resets all changes to the "reviewed_at" field.
|
||||||
func (m *UserVerificationsMutation) ResetReviewedAt() {
|
func (m *UserVerificationsMutation) ResetReviewedAt() {
|
||||||
m.reviewed_at = nil
|
m.reviewed_at = nil
|
||||||
|
delete(m.clearedFields, userverifications.FieldReviewedAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCreatedAt sets the "created_at" field.
|
// SetCreatedAt sets the "created_at" field.
|
||||||
@@ -478,9 +518,22 @@ func (m *UserVerificationsMutation) OldCreatedAt(ctx context.Context) (v time.Ti
|
|||||||
return oldValue.CreatedAt, nil
|
return oldValue.CreatedAt, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearCreatedAt clears the value of the "created_at" field.
|
||||||
|
func (m *UserVerificationsMutation) ClearCreatedAt() {
|
||||||
|
m.created_at = nil
|
||||||
|
m.clearedFields[userverifications.FieldCreatedAt] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtCleared returns if the "created_at" field was cleared in this mutation.
|
||||||
|
func (m *UserVerificationsMutation) CreatedAtCleared() bool {
|
||||||
|
_, ok := m.clearedFields[userverifications.FieldCreatedAt]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
// ResetCreatedAt resets all changes to the "created_at" field.
|
// ResetCreatedAt resets all changes to the "created_at" field.
|
||||||
func (m *UserVerificationsMutation) ResetCreatedAt() {
|
func (m *UserVerificationsMutation) ResetCreatedAt() {
|
||||||
m.created_at = nil
|
m.created_at = nil
|
||||||
|
delete(m.clearedFields, userverifications.FieldCreatedAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUpdatedAt sets the "updated_at" field.
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
@@ -514,9 +567,22 @@ func (m *UserVerificationsMutation) OldUpdatedAt(ctx context.Context) (v time.Ti
|
|||||||
return oldValue.UpdatedAt, nil
|
return oldValue.UpdatedAt, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearUpdatedAt clears the value of the "updated_at" field.
|
||||||
|
func (m *UserVerificationsMutation) ClearUpdatedAt() {
|
||||||
|
m.updated_at = nil
|
||||||
|
m.clearedFields[userverifications.FieldUpdatedAt] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtCleared returns if the "updated_at" field was cleared in this mutation.
|
||||||
|
func (m *UserVerificationsMutation) UpdatedAtCleared() bool {
|
||||||
|
_, ok := m.clearedFields[userverifications.FieldUpdatedAt]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
// ResetUpdatedAt resets all changes to the "updated_at" field.
|
// ResetUpdatedAt resets all changes to the "updated_at" field.
|
||||||
func (m *UserVerificationsMutation) ResetUpdatedAt() {
|
func (m *UserVerificationsMutation) ResetUpdatedAt() {
|
||||||
m.updated_at = nil
|
m.updated_at = nil
|
||||||
|
delete(m.clearedFields, userverifications.FieldUpdatedAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Where appends a list predicates to the UserVerificationsMutation builder.
|
// Where appends a list predicates to the UserVerificationsMutation builder.
|
||||||
@@ -762,7 +828,23 @@ func (m *UserVerificationsMutation) AddField(name string, value ent.Value) error
|
|||||||
// ClearedFields returns all nullable fields that were cleared during this
|
// ClearedFields returns all nullable fields that were cleared during this
|
||||||
// mutation.
|
// mutation.
|
||||||
func (m *UserVerificationsMutation) ClearedFields() []string {
|
func (m *UserVerificationsMutation) ClearedFields() []string {
|
||||||
return nil
|
var fields []string
|
||||||
|
if m.FieldCleared(userverifications.FieldRejectReason) {
|
||||||
|
fields = append(fields, userverifications.FieldRejectReason)
|
||||||
|
}
|
||||||
|
if m.FieldCleared(userverifications.FieldReviewedBy) {
|
||||||
|
fields = append(fields, userverifications.FieldReviewedBy)
|
||||||
|
}
|
||||||
|
if m.FieldCleared(userverifications.FieldReviewedAt) {
|
||||||
|
fields = append(fields, userverifications.FieldReviewedAt)
|
||||||
|
}
|
||||||
|
if m.FieldCleared(userverifications.FieldCreatedAt) {
|
||||||
|
fields = append(fields, userverifications.FieldCreatedAt)
|
||||||
|
}
|
||||||
|
if m.FieldCleared(userverifications.FieldUpdatedAt) {
|
||||||
|
fields = append(fields, userverifications.FieldUpdatedAt)
|
||||||
|
}
|
||||||
|
return fields
|
||||||
}
|
}
|
||||||
|
|
||||||
// FieldCleared returns a boolean indicating if a field with the given name was
|
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||||
@@ -775,6 +857,23 @@ func (m *UserVerificationsMutation) FieldCleared(name string) bool {
|
|||||||
// ClearField clears the value of the field with the given name. It returns an
|
// ClearField clears the value of the field with the given name. It returns an
|
||||||
// error if the field is not defined in the schema.
|
// error if the field is not defined in the schema.
|
||||||
func (m *UserVerificationsMutation) ClearField(name string) error {
|
func (m *UserVerificationsMutation) ClearField(name string) error {
|
||||||
|
switch name {
|
||||||
|
case userverifications.FieldRejectReason:
|
||||||
|
m.ClearRejectReason()
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldReviewedBy:
|
||||||
|
m.ClearReviewedBy()
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldReviewedAt:
|
||||||
|
m.ClearReviewedAt()
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldCreatedAt:
|
||||||
|
m.ClearCreatedAt()
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldUpdatedAt:
|
||||||
|
m.ClearUpdatedAt()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("unknown UserVerifications nullable field %s", name)
|
return fmt.Errorf("unknown UserVerifications nullable field %s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package models
|
|||||||
import (
|
import (
|
||||||
"juwan-backend/app/user_verifications/rpc/internal/models/schema"
|
"juwan-backend/app/user_verifications/rpc/internal/models/schema"
|
||||||
"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
|
"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The init function reads all schema descriptors with runtime code
|
// The init function reads all schema descriptors with runtime code
|
||||||
@@ -17,8 +18,12 @@ func init() {
|
|||||||
userverificationsDescStatus := userverificationsFields[3].Descriptor()
|
userverificationsDescStatus := userverificationsFields[3].Descriptor()
|
||||||
// userverifications.DefaultStatus holds the default value on creation for the status field.
|
// userverifications.DefaultStatus holds the default value on creation for the status field.
|
||||||
userverifications.DefaultStatus = userverificationsDescStatus.Default.(string)
|
userverifications.DefaultStatus = userverificationsDescStatus.Default.(string)
|
||||||
// userverificationsDescRejectReason is the schema descriptor for reject_reason field.
|
// userverificationsDescCreatedAt is the schema descriptor for created_at field.
|
||||||
userverificationsDescRejectReason := userverificationsFields[5].Descriptor()
|
userverificationsDescCreatedAt := userverificationsFields[8].Descriptor()
|
||||||
// userverifications.DefaultRejectReason holds the default value on creation for the reject_reason field.
|
// userverifications.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
userverifications.DefaultRejectReason = userverificationsDescRejectReason.Default.(string)
|
userverifications.DefaultCreatedAt = userverificationsDescCreatedAt.Default.(func() time.Time)
|
||||||
|
// userverificationsDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
|
userverificationsDescUpdatedAt := userverificationsFields[9].Descriptor()
|
||||||
|
// userverifications.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
|
userverifications.DefaultUpdatedAt = userverificationsDescUpdatedAt.Default.(func() time.Time)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package schema
|
package schema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"entgo.io/ent"
|
"entgo.io/ent"
|
||||||
"entgo.io/ent/schema/field"
|
"entgo.io/ent/schema/field"
|
||||||
)
|
)
|
||||||
@@ -13,8 +15,8 @@ type UserVerifications struct {
|
|||||||
type MaterialStruct struct {
|
type MaterialStruct struct {
|
||||||
IdCardFront string `json:"idCardFront"`
|
IdCardFront string `json:"idCardFront"`
|
||||||
IdCardBack string `json:"idCardBack"`
|
IdCardBack string `json:"idCardBack"`
|
||||||
GameScreenshots []string `json:"gameScreenshots"`
|
GameScreenshots []string `json:"gameScreenshots,omitempty"`
|
||||||
VoiceDemo string `json:"voiceDemo"`
|
VoiceDemo string `json:"voiceDemo,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fields of the UserVerifications.
|
// Fields of the UserVerifications.
|
||||||
@@ -22,14 +24,14 @@ func (UserVerifications) Fields() []ent.Field {
|
|||||||
return []ent.Field{
|
return []ent.Field{
|
||||||
field.Int64("id").Immutable().Unique(),
|
field.Int64("id").Immutable().Unique(),
|
||||||
field.Int64("user_id").Immutable().Unique(),
|
field.Int64("user_id").Immutable().Unique(),
|
||||||
field.String("role").Unique(),
|
field.String("role"),
|
||||||
field.String("status").Default("pending"),
|
field.String("status").Default("pending"),
|
||||||
field.JSON("materials", MaterialStruct{}),
|
field.JSON("materials", MaterialStruct{}),
|
||||||
field.String("reject_reason").Default(""),
|
field.String("reject_reason").Nillable().Optional(),
|
||||||
field.Int64("reviewed_by"),
|
field.Int64("reviewed_by").Nillable().Optional(),
|
||||||
field.Time("reviewed_at").Immutable(),
|
field.Time("reviewed_at").Nillable().Optional(),
|
||||||
field.Time("created_at").Immutable(),
|
field.Time("created_at").Immutable().Optional().Default(time.Now),
|
||||||
field.Time("updated_at").Immutable(),
|
field.Time("updated_at").Immutable().Optional().Default(time.Now),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UserVerifications is the models entity for the UserVerifications schema.
|
// UserVerifications is the model entity for the UserVerifications schema.
|
||||||
type UserVerifications struct {
|
type UserVerifications struct {
|
||||||
config `json:"-"`
|
config `json:"-"`
|
||||||
// ID of the ent.
|
// ID of the ent.
|
||||||
@@ -28,11 +28,11 @@ type UserVerifications struct {
|
|||||||
// Materials holds the value of the "materials" field.
|
// Materials holds the value of the "materials" field.
|
||||||
Materials schema.MaterialStruct `json:"materials,omitempty"`
|
Materials schema.MaterialStruct `json:"materials,omitempty"`
|
||||||
// RejectReason holds the value of the "reject_reason" field.
|
// RejectReason holds the value of the "reject_reason" field.
|
||||||
RejectReason string `json:"reject_reason,omitempty"`
|
RejectReason *string `json:"reject_reason,omitempty"`
|
||||||
// ReviewedBy holds the value of the "reviewed_by" field.
|
// ReviewedBy holds the value of the "reviewed_by" field.
|
||||||
ReviewedBy int64 `json:"reviewed_by,omitempty"`
|
ReviewedBy *int64 `json:"reviewed_by,omitempty"`
|
||||||
// ReviewedAt holds the value of the "reviewed_at" field.
|
// ReviewedAt holds the value of the "reviewed_at" field.
|
||||||
ReviewedAt time.Time `json:"reviewed_at,omitempty"`
|
ReviewedAt *time.Time `json:"reviewed_at,omitempty"`
|
||||||
// CreatedAt holds the value of the "created_at" field.
|
// CreatedAt holds the value of the "created_at" field.
|
||||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
// UpdatedAt holds the value of the "updated_at" field.
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
@@ -104,19 +104,22 @@ func (_m *UserVerifications) assignValues(columns []string, values []any) error
|
|||||||
if value, ok := values[i].(*sql.NullString); !ok {
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field reject_reason", values[i])
|
return fmt.Errorf("unexpected type %T for field reject_reason", values[i])
|
||||||
} else if value.Valid {
|
} else if value.Valid {
|
||||||
_m.RejectReason = value.String
|
_m.RejectReason = new(string)
|
||||||
|
*_m.RejectReason = value.String
|
||||||
}
|
}
|
||||||
case userverifications.FieldReviewedBy:
|
case userverifications.FieldReviewedBy:
|
||||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field reviewed_by", values[i])
|
return fmt.Errorf("unexpected type %T for field reviewed_by", values[i])
|
||||||
} else if value.Valid {
|
} else if value.Valid {
|
||||||
_m.ReviewedBy = value.Int64
|
_m.ReviewedBy = new(int64)
|
||||||
|
*_m.ReviewedBy = value.Int64
|
||||||
}
|
}
|
||||||
case userverifications.FieldReviewedAt:
|
case userverifications.FieldReviewedAt:
|
||||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field reviewed_at", values[i])
|
return fmt.Errorf("unexpected type %T for field reviewed_at", values[i])
|
||||||
} else if value.Valid {
|
} else if value.Valid {
|
||||||
_m.ReviewedAt = value.Time
|
_m.ReviewedAt = new(time.Time)
|
||||||
|
*_m.ReviewedAt = value.Time
|
||||||
}
|
}
|
||||||
case userverifications.FieldCreatedAt:
|
case userverifications.FieldCreatedAt:
|
||||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
@@ -178,14 +181,20 @@ func (_m *UserVerifications) String() string {
|
|||||||
builder.WriteString("materials=")
|
builder.WriteString("materials=")
|
||||||
builder.WriteString(fmt.Sprintf("%v", _m.Materials))
|
builder.WriteString(fmt.Sprintf("%v", _m.Materials))
|
||||||
builder.WriteString(", ")
|
builder.WriteString(", ")
|
||||||
builder.WriteString("reject_reason=")
|
if v := _m.RejectReason; v != nil {
|
||||||
builder.WriteString(_m.RejectReason)
|
builder.WriteString("reject_reason=")
|
||||||
|
builder.WriteString(*v)
|
||||||
|
}
|
||||||
builder.WriteString(", ")
|
builder.WriteString(", ")
|
||||||
builder.WriteString("reviewed_by=")
|
if v := _m.ReviewedBy; v != nil {
|
||||||
builder.WriteString(fmt.Sprintf("%v", _m.ReviewedBy))
|
builder.WriteString("reviewed_by=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", *v))
|
||||||
|
}
|
||||||
builder.WriteString(", ")
|
builder.WriteString(", ")
|
||||||
builder.WriteString("reviewed_at=")
|
if v := _m.ReviewedAt; v != nil {
|
||||||
builder.WriteString(_m.ReviewedAt.Format(time.ANSIC))
|
builder.WriteString("reviewed_at=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
builder.WriteString(", ")
|
builder.WriteString(", ")
|
||||||
builder.WriteString("created_at=")
|
builder.WriteString("created_at=")
|
||||||
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
package userverifications
|
package userverifications
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -60,8 +62,10 @@ func ValidColumn(column string) bool {
|
|||||||
var (
|
var (
|
||||||
// DefaultStatus holds the default value on creation for the "status" field.
|
// DefaultStatus holds the default value on creation for the "status" field.
|
||||||
DefaultStatus string
|
DefaultStatus string
|
||||||
// DefaultRejectReason holds the default value on creation for the "reject_reason" field.
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
DefaultRejectReason string
|
DefaultCreatedAt func() time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt func() time.Time
|
||||||
)
|
)
|
||||||
|
|
||||||
// OrderOption defines the ordering options for the UserVerifications queries.
|
// OrderOption defines the ordering options for the UserVerifications queries.
|
||||||
|
|||||||
@@ -319,6 +319,16 @@ func RejectReasonHasSuffix(v string) predicate.UserVerifications {
|
|||||||
return predicate.UserVerifications(sql.FieldHasSuffix(FieldRejectReason, v))
|
return predicate.UserVerifications(sql.FieldHasSuffix(FieldRejectReason, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RejectReasonIsNil applies the IsNil predicate on the "reject_reason" field.
|
||||||
|
func RejectReasonIsNil() predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldIsNull(FieldRejectReason))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RejectReasonNotNil applies the NotNil predicate on the "reject_reason" field.
|
||||||
|
func RejectReasonNotNil() predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNotNull(FieldRejectReason))
|
||||||
|
}
|
||||||
|
|
||||||
// RejectReasonEqualFold applies the EqualFold predicate on the "reject_reason" field.
|
// RejectReasonEqualFold applies the EqualFold predicate on the "reject_reason" field.
|
||||||
func RejectReasonEqualFold(v string) predicate.UserVerifications {
|
func RejectReasonEqualFold(v string) predicate.UserVerifications {
|
||||||
return predicate.UserVerifications(sql.FieldEqualFold(FieldRejectReason, v))
|
return predicate.UserVerifications(sql.FieldEqualFold(FieldRejectReason, v))
|
||||||
@@ -369,6 +379,16 @@ func ReviewedByLTE(v int64) predicate.UserVerifications {
|
|||||||
return predicate.UserVerifications(sql.FieldLTE(FieldReviewedBy, v))
|
return predicate.UserVerifications(sql.FieldLTE(FieldReviewedBy, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReviewedByIsNil applies the IsNil predicate on the "reviewed_by" field.
|
||||||
|
func ReviewedByIsNil() predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldIsNull(FieldReviewedBy))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedByNotNil applies the NotNil predicate on the "reviewed_by" field.
|
||||||
|
func ReviewedByNotNil() predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNotNull(FieldReviewedBy))
|
||||||
|
}
|
||||||
|
|
||||||
// ReviewedAtEQ applies the EQ predicate on the "reviewed_at" field.
|
// ReviewedAtEQ applies the EQ predicate on the "reviewed_at" field.
|
||||||
func ReviewedAtEQ(v time.Time) predicate.UserVerifications {
|
func ReviewedAtEQ(v time.Time) predicate.UserVerifications {
|
||||||
return predicate.UserVerifications(sql.FieldEQ(FieldReviewedAt, v))
|
return predicate.UserVerifications(sql.FieldEQ(FieldReviewedAt, v))
|
||||||
@@ -409,6 +429,16 @@ func ReviewedAtLTE(v time.Time) predicate.UserVerifications {
|
|||||||
return predicate.UserVerifications(sql.FieldLTE(FieldReviewedAt, v))
|
return predicate.UserVerifications(sql.FieldLTE(FieldReviewedAt, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReviewedAtIsNil applies the IsNil predicate on the "reviewed_at" field.
|
||||||
|
func ReviewedAtIsNil() predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldIsNull(FieldReviewedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedAtNotNil applies the NotNil predicate on the "reviewed_at" field.
|
||||||
|
func ReviewedAtNotNil() predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNotNull(FieldReviewedAt))
|
||||||
|
}
|
||||||
|
|
||||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
func CreatedAtEQ(v time.Time) predicate.UserVerifications {
|
func CreatedAtEQ(v time.Time) predicate.UserVerifications {
|
||||||
return predicate.UserVerifications(sql.FieldEQ(FieldCreatedAt, v))
|
return predicate.UserVerifications(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
@@ -449,6 +479,16 @@ func CreatedAtLTE(v time.Time) predicate.UserVerifications {
|
|||||||
return predicate.UserVerifications(sql.FieldLTE(FieldCreatedAt, v))
|
return predicate.UserVerifications(sql.FieldLTE(FieldCreatedAt, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreatedAtIsNil applies the IsNil predicate on the "created_at" field.
|
||||||
|
func CreatedAtIsNil() predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldIsNull(FieldCreatedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNotNil applies the NotNil predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotNil() predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNotNull(FieldCreatedAt))
|
||||||
|
}
|
||||||
|
|
||||||
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||||
func UpdatedAtEQ(v time.Time) predicate.UserVerifications {
|
func UpdatedAtEQ(v time.Time) predicate.UserVerifications {
|
||||||
return predicate.UserVerifications(sql.FieldEQ(FieldUpdatedAt, v))
|
return predicate.UserVerifications(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
@@ -489,6 +529,16 @@ func UpdatedAtLTE(v time.Time) predicate.UserVerifications {
|
|||||||
return predicate.UserVerifications(sql.FieldLTE(FieldUpdatedAt, v))
|
return predicate.UserVerifications(sql.FieldLTE(FieldUpdatedAt, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIsNil applies the IsNil predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIsNil() predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldIsNull(FieldUpdatedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotNil applies the NotNil predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotNil() predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNotNull(FieldUpdatedAt))
|
||||||
|
}
|
||||||
|
|
||||||
// And groups predicates with the AND operator between them.
|
// And groups predicates with the AND operator between them.
|
||||||
func And(predicates ...predicate.UserVerifications) predicate.UserVerifications {
|
func And(predicates ...predicate.UserVerifications) predicate.UserVerifications {
|
||||||
return predicate.UserVerifications(sql.AndPredicates(predicates...))
|
return predicate.UserVerifications(sql.AndPredicates(predicates...))
|
||||||
|
|||||||
@@ -73,24 +73,56 @@ func (_c *UserVerificationsCreate) SetReviewedBy(v int64) *UserVerificationsCrea
|
|||||||
return _c
|
return _c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetNillableReviewedBy sets the "reviewed_by" field if the given value is not nil.
|
||||||
|
func (_c *UserVerificationsCreate) SetNillableReviewedBy(v *int64) *UserVerificationsCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetReviewedBy(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
// SetReviewedAt sets the "reviewed_at" field.
|
// SetReviewedAt sets the "reviewed_at" field.
|
||||||
func (_c *UserVerificationsCreate) SetReviewedAt(v time.Time) *UserVerificationsCreate {
|
func (_c *UserVerificationsCreate) SetReviewedAt(v time.Time) *UserVerificationsCreate {
|
||||||
_c.mutation.SetReviewedAt(v)
|
_c.mutation.SetReviewedAt(v)
|
||||||
return _c
|
return _c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetNillableReviewedAt sets the "reviewed_at" field if the given value is not nil.
|
||||||
|
func (_c *UserVerificationsCreate) SetNillableReviewedAt(v *time.Time) *UserVerificationsCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetReviewedAt(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
// SetCreatedAt sets the "created_at" field.
|
// SetCreatedAt sets the "created_at" field.
|
||||||
func (_c *UserVerificationsCreate) SetCreatedAt(v time.Time) *UserVerificationsCreate {
|
func (_c *UserVerificationsCreate) SetCreatedAt(v time.Time) *UserVerificationsCreate {
|
||||||
_c.mutation.SetCreatedAt(v)
|
_c.mutation.SetCreatedAt(v)
|
||||||
return _c
|
return _c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (_c *UserVerificationsCreate) SetNillableCreatedAt(v *time.Time) *UserVerificationsCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetCreatedAt(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
// SetUpdatedAt sets the "updated_at" field.
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
func (_c *UserVerificationsCreate) SetUpdatedAt(v time.Time) *UserVerificationsCreate {
|
func (_c *UserVerificationsCreate) SetUpdatedAt(v time.Time) *UserVerificationsCreate {
|
||||||
_c.mutation.SetUpdatedAt(v)
|
_c.mutation.SetUpdatedAt(v)
|
||||||
return _c
|
return _c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||||
|
func (_c *UserVerificationsCreate) SetNillableUpdatedAt(v *time.Time) *UserVerificationsCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetUpdatedAt(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
// SetID sets the "id" field.
|
// SetID sets the "id" field.
|
||||||
func (_c *UserVerificationsCreate) SetID(v int64) *UserVerificationsCreate {
|
func (_c *UserVerificationsCreate) SetID(v int64) *UserVerificationsCreate {
|
||||||
_c.mutation.SetID(v)
|
_c.mutation.SetID(v)
|
||||||
@@ -136,9 +168,13 @@ func (_c *UserVerificationsCreate) defaults() {
|
|||||||
v := userverifications.DefaultStatus
|
v := userverifications.DefaultStatus
|
||||||
_c.mutation.SetStatus(v)
|
_c.mutation.SetStatus(v)
|
||||||
}
|
}
|
||||||
if _, ok := _c.mutation.RejectReason(); !ok {
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||||
v := userverifications.DefaultRejectReason
|
v := userverifications.DefaultCreatedAt()
|
||||||
_c.mutation.SetRejectReason(v)
|
_c.mutation.SetCreatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||||
|
v := userverifications.DefaultUpdatedAt()
|
||||||
|
_c.mutation.SetUpdatedAt(v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,21 +192,6 @@ func (_c *UserVerificationsCreate) check() error {
|
|||||||
if _, ok := _c.mutation.Materials(); !ok {
|
if _, ok := _c.mutation.Materials(); !ok {
|
||||||
return &ValidationError{Name: "materials", err: errors.New(`models: missing required field "UserVerifications.materials"`)}
|
return &ValidationError{Name: "materials", err: errors.New(`models: missing required field "UserVerifications.materials"`)}
|
||||||
}
|
}
|
||||||
if _, ok := _c.mutation.RejectReason(); !ok {
|
|
||||||
return &ValidationError{Name: "reject_reason", err: errors.New(`models: missing required field "UserVerifications.reject_reason"`)}
|
|
||||||
}
|
|
||||||
if _, ok := _c.mutation.ReviewedBy(); !ok {
|
|
||||||
return &ValidationError{Name: "reviewed_by", err: errors.New(`models: missing required field "UserVerifications.reviewed_by"`)}
|
|
||||||
}
|
|
||||||
if _, ok := _c.mutation.ReviewedAt(); !ok {
|
|
||||||
return &ValidationError{Name: "reviewed_at", err: errors.New(`models: missing required field "UserVerifications.reviewed_at"`)}
|
|
||||||
}
|
|
||||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
||||||
return &ValidationError{Name: "created_at", err: errors.New(`models: missing required field "UserVerifications.created_at"`)}
|
|
||||||
}
|
|
||||||
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
||||||
return &ValidationError{Name: "updated_at", err: errors.New(`models: missing required field "UserVerifications.updated_at"`)}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,15 +242,15 @@ func (_c *UserVerificationsCreate) createSpec() (*UserVerifications, *sqlgraph.C
|
|||||||
}
|
}
|
||||||
if value, ok := _c.mutation.RejectReason(); ok {
|
if value, ok := _c.mutation.RejectReason(); ok {
|
||||||
_spec.SetField(userverifications.FieldRejectReason, field.TypeString, value)
|
_spec.SetField(userverifications.FieldRejectReason, field.TypeString, value)
|
||||||
_node.RejectReason = value
|
_node.RejectReason = &value
|
||||||
}
|
}
|
||||||
if value, ok := _c.mutation.ReviewedBy(); ok {
|
if value, ok := _c.mutation.ReviewedBy(); ok {
|
||||||
_spec.SetField(userverifications.FieldReviewedBy, field.TypeInt64, value)
|
_spec.SetField(userverifications.FieldReviewedBy, field.TypeInt64, value)
|
||||||
_node.ReviewedBy = value
|
_node.ReviewedBy = &value
|
||||||
}
|
}
|
||||||
if value, ok := _c.mutation.ReviewedAt(); ok {
|
if value, ok := _c.mutation.ReviewedAt(); ok {
|
||||||
_spec.SetField(userverifications.FieldReviewedAt, field.TypeTime, value)
|
_spec.SetField(userverifications.FieldReviewedAt, field.TypeTime, value)
|
||||||
_node.ReviewedAt = value
|
_node.ReviewedAt = &value
|
||||||
}
|
}
|
||||||
if value, ok := _c.mutation.CreatedAt(); ok {
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||||
_spec.SetField(userverifications.FieldCreatedAt, field.TypeTime, value)
|
_spec.SetField(userverifications.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"juwan-backend/app/user_verifications/rpc/internal/models/predicate"
|
"juwan-backend/app/user_verifications/rpc/internal/models/predicate"
|
||||||
"juwan-backend/app/user_verifications/rpc/internal/models/schema"
|
"juwan-backend/app/user_verifications/rpc/internal/models/schema"
|
||||||
"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
|
"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
|
||||||
|
"time"
|
||||||
|
|
||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
@@ -84,6 +85,12 @@ func (_u *UserVerificationsUpdate) SetNillableRejectReason(v *string) *UserVerif
|
|||||||
return _u
|
return _u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearRejectReason clears the value of the "reject_reason" field.
|
||||||
|
func (_u *UserVerificationsUpdate) ClearRejectReason() *UserVerificationsUpdate {
|
||||||
|
_u.mutation.ClearRejectReason()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
// SetReviewedBy sets the "reviewed_by" field.
|
// SetReviewedBy sets the "reviewed_by" field.
|
||||||
func (_u *UserVerificationsUpdate) SetReviewedBy(v int64) *UserVerificationsUpdate {
|
func (_u *UserVerificationsUpdate) SetReviewedBy(v int64) *UserVerificationsUpdate {
|
||||||
_u.mutation.ResetReviewedBy()
|
_u.mutation.ResetReviewedBy()
|
||||||
@@ -105,6 +112,32 @@ func (_u *UserVerificationsUpdate) AddReviewedBy(v int64) *UserVerificationsUpda
|
|||||||
return _u
|
return _u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearReviewedBy clears the value of the "reviewed_by" field.
|
||||||
|
func (_u *UserVerificationsUpdate) ClearReviewedBy() *UserVerificationsUpdate {
|
||||||
|
_u.mutation.ClearReviewedBy()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetReviewedAt sets the "reviewed_at" field.
|
||||||
|
func (_u *UserVerificationsUpdate) SetReviewedAt(v time.Time) *UserVerificationsUpdate {
|
||||||
|
_u.mutation.SetReviewedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableReviewedAt sets the "reviewed_at" field if the given value is not nil.
|
||||||
|
func (_u *UserVerificationsUpdate) SetNillableReviewedAt(v *time.Time) *UserVerificationsUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetReviewedAt(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearReviewedAt clears the value of the "reviewed_at" field.
|
||||||
|
func (_u *UserVerificationsUpdate) ClearReviewedAt() *UserVerificationsUpdate {
|
||||||
|
_u.mutation.ClearReviewedAt()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
// Mutation returns the UserVerificationsMutation object of the builder.
|
// Mutation returns the UserVerificationsMutation object of the builder.
|
||||||
func (_u *UserVerificationsUpdate) Mutation() *UserVerificationsMutation {
|
func (_u *UserVerificationsUpdate) Mutation() *UserVerificationsMutation {
|
||||||
return _u.mutation
|
return _u.mutation
|
||||||
@@ -158,12 +191,30 @@ func (_u *UserVerificationsUpdate) sqlSave(ctx context.Context) (_node int, err
|
|||||||
if value, ok := _u.mutation.RejectReason(); ok {
|
if value, ok := _u.mutation.RejectReason(); ok {
|
||||||
_spec.SetField(userverifications.FieldRejectReason, field.TypeString, value)
|
_spec.SetField(userverifications.FieldRejectReason, field.TypeString, value)
|
||||||
}
|
}
|
||||||
|
if _u.mutation.RejectReasonCleared() {
|
||||||
|
_spec.ClearField(userverifications.FieldRejectReason, field.TypeString)
|
||||||
|
}
|
||||||
if value, ok := _u.mutation.ReviewedBy(); ok {
|
if value, ok := _u.mutation.ReviewedBy(); ok {
|
||||||
_spec.SetField(userverifications.FieldReviewedBy, field.TypeInt64, value)
|
_spec.SetField(userverifications.FieldReviewedBy, field.TypeInt64, value)
|
||||||
}
|
}
|
||||||
if value, ok := _u.mutation.AddedReviewedBy(); ok {
|
if value, ok := _u.mutation.AddedReviewedBy(); ok {
|
||||||
_spec.AddField(userverifications.FieldReviewedBy, field.TypeInt64, value)
|
_spec.AddField(userverifications.FieldReviewedBy, field.TypeInt64, value)
|
||||||
}
|
}
|
||||||
|
if _u.mutation.ReviewedByCleared() {
|
||||||
|
_spec.ClearField(userverifications.FieldReviewedBy, field.TypeInt64)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ReviewedAt(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldReviewedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.ReviewedAtCleared() {
|
||||||
|
_spec.ClearField(userverifications.FieldReviewedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if _u.mutation.CreatedAtCleared() {
|
||||||
|
_spec.ClearField(userverifications.FieldCreatedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if _u.mutation.UpdatedAtCleared() {
|
||||||
|
_spec.ClearField(userverifications.FieldUpdatedAt, field.TypeTime)
|
||||||
|
}
|
||||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
err = &NotFoundError{userverifications.Label}
|
err = &NotFoundError{userverifications.Label}
|
||||||
@@ -240,6 +291,12 @@ func (_u *UserVerificationsUpdateOne) SetNillableRejectReason(v *string) *UserVe
|
|||||||
return _u
|
return _u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearRejectReason clears the value of the "reject_reason" field.
|
||||||
|
func (_u *UserVerificationsUpdateOne) ClearRejectReason() *UserVerificationsUpdateOne {
|
||||||
|
_u.mutation.ClearRejectReason()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
// SetReviewedBy sets the "reviewed_by" field.
|
// SetReviewedBy sets the "reviewed_by" field.
|
||||||
func (_u *UserVerificationsUpdateOne) SetReviewedBy(v int64) *UserVerificationsUpdateOne {
|
func (_u *UserVerificationsUpdateOne) SetReviewedBy(v int64) *UserVerificationsUpdateOne {
|
||||||
_u.mutation.ResetReviewedBy()
|
_u.mutation.ResetReviewedBy()
|
||||||
@@ -261,6 +318,32 @@ func (_u *UserVerificationsUpdateOne) AddReviewedBy(v int64) *UserVerificationsU
|
|||||||
return _u
|
return _u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearReviewedBy clears the value of the "reviewed_by" field.
|
||||||
|
func (_u *UserVerificationsUpdateOne) ClearReviewedBy() *UserVerificationsUpdateOne {
|
||||||
|
_u.mutation.ClearReviewedBy()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetReviewedAt sets the "reviewed_at" field.
|
||||||
|
func (_u *UserVerificationsUpdateOne) SetReviewedAt(v time.Time) *UserVerificationsUpdateOne {
|
||||||
|
_u.mutation.SetReviewedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableReviewedAt sets the "reviewed_at" field if the given value is not nil.
|
||||||
|
func (_u *UserVerificationsUpdateOne) SetNillableReviewedAt(v *time.Time) *UserVerificationsUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetReviewedAt(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearReviewedAt clears the value of the "reviewed_at" field.
|
||||||
|
func (_u *UserVerificationsUpdateOne) ClearReviewedAt() *UserVerificationsUpdateOne {
|
||||||
|
_u.mutation.ClearReviewedAt()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
// Mutation returns the UserVerificationsMutation object of the builder.
|
// Mutation returns the UserVerificationsMutation object of the builder.
|
||||||
func (_u *UserVerificationsUpdateOne) Mutation() *UserVerificationsMutation {
|
func (_u *UserVerificationsUpdateOne) Mutation() *UserVerificationsMutation {
|
||||||
return _u.mutation
|
return _u.mutation
|
||||||
@@ -344,12 +427,30 @@ func (_u *UserVerificationsUpdateOne) sqlSave(ctx context.Context) (_node *UserV
|
|||||||
if value, ok := _u.mutation.RejectReason(); ok {
|
if value, ok := _u.mutation.RejectReason(); ok {
|
||||||
_spec.SetField(userverifications.FieldRejectReason, field.TypeString, value)
|
_spec.SetField(userverifications.FieldRejectReason, field.TypeString, value)
|
||||||
}
|
}
|
||||||
|
if _u.mutation.RejectReasonCleared() {
|
||||||
|
_spec.ClearField(userverifications.FieldRejectReason, field.TypeString)
|
||||||
|
}
|
||||||
if value, ok := _u.mutation.ReviewedBy(); ok {
|
if value, ok := _u.mutation.ReviewedBy(); ok {
|
||||||
_spec.SetField(userverifications.FieldReviewedBy, field.TypeInt64, value)
|
_spec.SetField(userverifications.FieldReviewedBy, field.TypeInt64, value)
|
||||||
}
|
}
|
||||||
if value, ok := _u.mutation.AddedReviewedBy(); ok {
|
if value, ok := _u.mutation.AddedReviewedBy(); ok {
|
||||||
_spec.AddField(userverifications.FieldReviewedBy, field.TypeInt64, value)
|
_spec.AddField(userverifications.FieldReviewedBy, field.TypeInt64, value)
|
||||||
}
|
}
|
||||||
|
if _u.mutation.ReviewedByCleared() {
|
||||||
|
_spec.ClearField(userverifications.FieldReviewedBy, field.TypeInt64)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ReviewedAt(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldReviewedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.ReviewedAtCleared() {
|
||||||
|
_spec.ClearField(userverifications.FieldReviewedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if _u.mutation.CreatedAtCleared() {
|
||||||
|
_spec.ClearField(userverifications.FieldCreatedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if _u.mutation.UpdatedAtCleared() {
|
||||||
|
_spec.ClearField(userverifications.FieldUpdatedAt, field.TypeTime)
|
||||||
|
}
|
||||||
_node = &UserVerifications{config: _u.config}
|
_node = &UserVerifications{config: _u.config}
|
||||||
_spec.Assign = _node.assignValues
|
_spec.Assign = _node.assignValues
|
||||||
_spec.ScanValues = _node.scanValues
|
_spec.ScanValues = _node.scanValues
|
||||||
|
|||||||
@@ -48,3 +48,13 @@ func (s *UserVerificationsServer) SearchUserVerifications(ctx context.Context, i
|
|||||||
l := logic.NewSearchUserVerificationsLogic(ctx, s.svcCtx)
|
l := logic.NewSearchUserVerificationsLogic(ctx, s.svcCtx)
|
||||||
return l.SearchUserVerifications(in)
|
return l.SearchUserVerifications(in)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *UserVerificationsServer) AddOrUpdateUserVerifications(ctx context.Context, in *pb.AddOrUpdateUserVerificationsReq) (*pb.AddOrUpdateUserVerificationsResp, error) {
|
||||||
|
l := logic.NewAddOrUpdateUserVerificationsLogic(ctx, s.svcCtx)
|
||||||
|
return l.AddOrUpdateUserVerifications(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *UserVerificationsServer) ListUserVerificationsByUserId(ctx context.Context, in *pb.ListUserVerificationsByUserIdReq) (*pb.ListUserVerificationsByUserIdResp, error) {
|
||||||
|
l := logic.NewListUserVerificationsByUserIdLogic(ctx, s.svcCtx)
|
||||||
|
return l.ListUserVerificationsByUserId(in)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,20 +1,24 @@
|
|||||||
package svc
|
package svc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
stdsql "database/sql"
|
||||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||||
"juwan-backend/app/user_verifications/rpc/internal/config"
|
"juwan-backend/app/user_verifications/rpc/internal/config"
|
||||||
"juwan-backend/app/user_verifications/rpc/internal/models"
|
"juwan-backend/app/user_verifications/rpc/internal/models"
|
||||||
"juwan-backend/app/user_verifications/rpc/userverifications"
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
"juwan-backend/common/redisx"
|
"juwan-backend/common/redisx"
|
||||||
"juwan-backend/common/snowflakex"
|
"juwan-backend/common/snowflakex"
|
||||||
"juwan-backend/pkg/adapter"
|
"juwan-backend/pkg/adapter"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
_ "github.com/jackc/pgx/v5/stdlib"
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
|
||||||
"ariga.io/entcache"
|
"ariga.io/entcache"
|
||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/zrpc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
@@ -22,19 +26,23 @@ type ServiceContext struct {
|
|||||||
UserVeriModelRW *models.UserVerificationsClient
|
UserVeriModelRW *models.UserVerificationsClient
|
||||||
UserVeriModelRO *models.UserVerificationsClient
|
UserVeriModelRO *models.UserVerificationsClient
|
||||||
RedisClient *redis.ClusterClient
|
RedisClient *redis.ClusterClient
|
||||||
UserVeriRpc userverifications.UserVerificationsZrpcClient
|
|
||||||
SnowflakeRpc snowflake.SnowflakeServiceClient
|
SnowflakeRpc snowflake.SnowflakeServiceClient
|
||||||
|
UserRpc usercenter.Usercenter
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
RWConn, err := sql.Open("pgx", c.DB.Master)
|
rawRW, err := stdsql.Open("pgx", c.DB.Master)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
ROConn, err := sql.Open("pgx", c.DB.Slave)
|
rawRO, err := stdsql.Open("pgx", c.DB.Slave)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
RWConn := sql.OpenDB(dialect.Postgres, rawRW)
|
||||||
|
ROConn := sql.OpenDB(dialect.Postgres, rawRO)
|
||||||
|
|
||||||
|
logx.Infof("success to connect to postgres~")
|
||||||
|
|
||||||
redisConn, err := redisx.ConnectMasterSlaveCluster(c.CacheConf, 5*time.Second)
|
redisConn, err := redisx.ConnectMasterSlaveCluster(c.CacheConf, 5*time.Second)
|
||||||
if err != nil || redisConn == nil {
|
if err != nil || redisConn == nil {
|
||||||
@@ -49,7 +57,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
UserVeriModelRW: models.NewClient(models.Driver(RWDrv)).UserVerifications,
|
UserVeriModelRW: models.NewClient(models.Driver(RWDrv)).UserVerifications,
|
||||||
UserVeriModelRO: models.NewClient(models.Driver(RODrv)).UserVerifications,
|
UserVeriModelRO: models.NewClient(models.Driver(RODrv)).UserVerifications,
|
||||||
RedisClient: redisConn.Client,
|
RedisClient: redisConn.Client,
|
||||||
UserVeriRpc: userverifications.NewUserVerificationsZrpcClient(zrpc.MustNewClient(c.UserVeriRpcConf)),
|
|
||||||
SnowflakeRpc: snowflakex.NewClient(c.SnowflakeRpcConf),
|
SnowflakeRpc: snowflakex.NewClient(c.SnowflakeRpcConf),
|
||||||
|
UserRpc: usercenter.NewUsercenter(zrpc.MustNewClient(c.UserRpcConf)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.11
|
// protoc-gen-go v1.36.11
|
||||||
// protoc v3.19.4
|
// protoc v5.29.6
|
||||||
// source: user_verifications.proto
|
// source: user_verifications.proto
|
||||||
|
|
||||||
package pb
|
package pb
|
||||||
@@ -778,6 +778,198 @@ func (x *SearchUserVerificationsResp) GetUserVerifications() []*UserVerification
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AddOrUpdateUserVerificationsReq struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
UserId int64 `protobuf:"varint,1,opt,name=userId,proto3" json:"userId,omitempty"` // userId
|
||||||
|
Role string `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"`
|
||||||
|
Material string `protobuf:"bytes,3,opt,name=material,proto3" json:"material,omitempty"` // material
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddOrUpdateUserVerificationsReq) Reset() {
|
||||||
|
*x = AddOrUpdateUserVerificationsReq{}
|
||||||
|
mi := &file_user_verifications_proto_msgTypes[11]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddOrUpdateUserVerificationsReq) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*AddOrUpdateUserVerificationsReq) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *AddOrUpdateUserVerificationsReq) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_user_verifications_proto_msgTypes[11]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use AddOrUpdateUserVerificationsReq.ProtoReflect.Descriptor instead.
|
||||||
|
func (*AddOrUpdateUserVerificationsReq) Descriptor() ([]byte, []int) {
|
||||||
|
return file_user_verifications_proto_rawDescGZIP(), []int{11}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddOrUpdateUserVerificationsReq) GetUserId() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.UserId
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddOrUpdateUserVerificationsReq) GetRole() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Role
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddOrUpdateUserVerificationsReq) GetMaterial() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Material
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type AddOrUpdateUserVerificationsResp struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"` // success
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddOrUpdateUserVerificationsResp) Reset() {
|
||||||
|
*x = AddOrUpdateUserVerificationsResp{}
|
||||||
|
mi := &file_user_verifications_proto_msgTypes[12]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddOrUpdateUserVerificationsResp) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*AddOrUpdateUserVerificationsResp) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *AddOrUpdateUserVerificationsResp) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_user_verifications_proto_msgTypes[12]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use AddOrUpdateUserVerificationsResp.ProtoReflect.Descriptor instead.
|
||||||
|
func (*AddOrUpdateUserVerificationsResp) Descriptor() ([]byte, []int) {
|
||||||
|
return file_user_verifications_proto_rawDescGZIP(), []int{12}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddOrUpdateUserVerificationsResp) GetSuccess() bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.Success
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListUserVerificationsByUserIdReq struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
UserId int64 `protobuf:"varint,1,opt,name=userId,proto3" json:"userId,omitempty"` // userId
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListUserVerificationsByUserIdReq) Reset() {
|
||||||
|
*x = ListUserVerificationsByUserIdReq{}
|
||||||
|
mi := &file_user_verifications_proto_msgTypes[13]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListUserVerificationsByUserIdReq) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ListUserVerificationsByUserIdReq) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *ListUserVerificationsByUserIdReq) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_user_verifications_proto_msgTypes[13]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use ListUserVerificationsByUserIdReq.ProtoReflect.Descriptor instead.
|
||||||
|
func (*ListUserVerificationsByUserIdReq) Descriptor() ([]byte, []int) {
|
||||||
|
return file_user_verifications_proto_rawDescGZIP(), []int{13}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListUserVerificationsByUserIdReq) GetUserId() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.UserId
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListUserVerificationsByUserIdResp struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
UserVerifications []*UserVerifications `protobuf:"bytes,1,rep,name=userVerifications,proto3" json:"userVerifications,omitempty"` // userVerifications
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListUserVerificationsByUserIdResp) Reset() {
|
||||||
|
*x = ListUserVerificationsByUserIdResp{}
|
||||||
|
mi := &file_user_verifications_proto_msgTypes[14]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListUserVerificationsByUserIdResp) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ListUserVerificationsByUserIdResp) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *ListUserVerificationsByUserIdResp) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_user_verifications_proto_msgTypes[14]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use ListUserVerificationsByUserIdResp.ProtoReflect.Descriptor instead.
|
||||||
|
func (*ListUserVerificationsByUserIdResp) Descriptor() ([]byte, []int) {
|
||||||
|
return file_user_verifications_proto_rawDescGZIP(), []int{14}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListUserVerificationsByUserIdResp) GetUserVerifications() []*UserVerifications {
|
||||||
|
if x != nil {
|
||||||
|
return x.UserVerifications
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var File_user_verifications_proto protoreflect.FileDescriptor
|
var File_user_verifications_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
const file_user_verifications_proto_rawDesc = "" +
|
const file_user_verifications_proto_rawDesc = "" +
|
||||||
@@ -863,13 +1055,25 @@ const file_user_verifications_proto_rawDesc = "" +
|
|||||||
"\tcreatedAt\x18\v \x01(\x03R\tcreatedAt\x12\x1c\n" +
|
"\tcreatedAt\x18\v \x01(\x03R\tcreatedAt\x12\x1c\n" +
|
||||||
"\tupdatedAt\x18\f \x01(\x03R\tupdatedAt\"b\n" +
|
"\tupdatedAt\x18\f \x01(\x03R\tupdatedAt\"b\n" +
|
||||||
"\x1bSearchUserVerificationsResp\x12C\n" +
|
"\x1bSearchUserVerificationsResp\x12C\n" +
|
||||||
"\x11userVerifications\x18\x01 \x03(\v2\x15.pb.UserVerificationsR\x11userVerifications2\xd1\x03\n" +
|
"\x11userVerifications\x18\x01 \x03(\v2\x15.pb.UserVerificationsR\x11userVerifications\"i\n" +
|
||||||
|
"\x1fAddOrUpdateUserVerificationsReq\x12\x16\n" +
|
||||||
|
"\x06userId\x18\x01 \x01(\x03R\x06userId\x12\x12\n" +
|
||||||
|
"\x04role\x18\x02 \x01(\tR\x04role\x12\x1a\n" +
|
||||||
|
"\bmaterial\x18\x03 \x01(\tR\bmaterial\"<\n" +
|
||||||
|
" AddOrUpdateUserVerificationsResp\x12\x18\n" +
|
||||||
|
"\asuccess\x18\x01 \x01(\bR\asuccess\":\n" +
|
||||||
|
" ListUserVerificationsByUserIdReq\x12\x16\n" +
|
||||||
|
"\x06userId\x18\x01 \x01(\x03R\x06userId\"h\n" +
|
||||||
|
"!ListUserVerificationsByUserIdResp\x12C\n" +
|
||||||
|
"\x11userVerifications\x18\x01 \x03(\v2\x15.pb.UserVerificationsR\x11userVerifications2\xaa\x05\n" +
|
||||||
"\x12user_verifications\x12Q\n" +
|
"\x12user_verifications\x12Q\n" +
|
||||||
"\x14AddUserVerifications\x12\x1b.pb.AddUserVerificationsReq\x1a\x1c.pb.AddUserVerificationsResp\x12Z\n" +
|
"\x14AddUserVerifications\x12\x1b.pb.AddUserVerificationsReq\x1a\x1c.pb.AddUserVerificationsResp\x12Z\n" +
|
||||||
"\x17UpdateUserVerifications\x12\x1e.pb.UpdateUserVerificationsReq\x1a\x1f.pb.UpdateUserVerificationsResp\x12Q\n" +
|
"\x17UpdateUserVerifications\x12\x1e.pb.UpdateUserVerificationsReq\x1a\x1f.pb.UpdateUserVerificationsResp\x12Q\n" +
|
||||||
"\x14DelUserVerifications\x12\x1b.pb.DelUserVerificationsReq\x1a\x1c.pb.DelUserVerificationsResp\x12]\n" +
|
"\x14DelUserVerifications\x12\x1b.pb.DelUserVerificationsReq\x1a\x1c.pb.DelUserVerificationsResp\x12]\n" +
|
||||||
"\x18GetUserVerificationsById\x12\x1f.pb.GetUserVerificationsByIdReq\x1a .pb.GetUserVerificationsByIdResp\x12Z\n" +
|
"\x18GetUserVerificationsById\x12\x1f.pb.GetUserVerificationsByIdReq\x1a .pb.GetUserVerificationsByIdResp\x12Z\n" +
|
||||||
"\x17SearchUserVerifications\x12\x1e.pb.SearchUserVerificationsReq\x1a\x1f.pb.SearchUserVerificationsRespB\x06Z\x04./pbb\x06proto3"
|
"\x17SearchUserVerifications\x12\x1e.pb.SearchUserVerificationsReq\x1a\x1f.pb.SearchUserVerificationsResp\x12i\n" +
|
||||||
|
"\x1cAddOrUpdateUserVerifications\x12#.pb.AddOrUpdateUserVerificationsReq\x1a$.pb.AddOrUpdateUserVerificationsResp\x12l\n" +
|
||||||
|
"\x1dListUserVerificationsByUserId\x12$.pb.ListUserVerificationsByUserIdReq\x1a%.pb.ListUserVerificationsByUserIdRespB\x06Z\x04./pbb\x06proto3"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
file_user_verifications_proto_rawDescOnce sync.Once
|
file_user_verifications_proto_rawDescOnce sync.Once
|
||||||
@@ -883,38 +1087,47 @@ func file_user_verifications_proto_rawDescGZIP() []byte {
|
|||||||
return file_user_verifications_proto_rawDescData
|
return file_user_verifications_proto_rawDescData
|
||||||
}
|
}
|
||||||
|
|
||||||
var file_user_verifications_proto_msgTypes = make([]protoimpl.MessageInfo, 11)
|
var file_user_verifications_proto_msgTypes = make([]protoimpl.MessageInfo, 15)
|
||||||
var file_user_verifications_proto_goTypes = []any{
|
var file_user_verifications_proto_goTypes = []any{
|
||||||
(*UserVerifications)(nil), // 0: pb.UserVerifications
|
(*UserVerifications)(nil), // 0: pb.UserVerifications
|
||||||
(*AddUserVerificationsReq)(nil), // 1: pb.AddUserVerificationsReq
|
(*AddUserVerificationsReq)(nil), // 1: pb.AddUserVerificationsReq
|
||||||
(*AddUserVerificationsResp)(nil), // 2: pb.AddUserVerificationsResp
|
(*AddUserVerificationsResp)(nil), // 2: pb.AddUserVerificationsResp
|
||||||
(*UpdateUserVerificationsReq)(nil), // 3: pb.UpdateUserVerificationsReq
|
(*UpdateUserVerificationsReq)(nil), // 3: pb.UpdateUserVerificationsReq
|
||||||
(*UpdateUserVerificationsResp)(nil), // 4: pb.UpdateUserVerificationsResp
|
(*UpdateUserVerificationsResp)(nil), // 4: pb.UpdateUserVerificationsResp
|
||||||
(*DelUserVerificationsReq)(nil), // 5: pb.DelUserVerificationsReq
|
(*DelUserVerificationsReq)(nil), // 5: pb.DelUserVerificationsReq
|
||||||
(*DelUserVerificationsResp)(nil), // 6: pb.DelUserVerificationsResp
|
(*DelUserVerificationsResp)(nil), // 6: pb.DelUserVerificationsResp
|
||||||
(*GetUserVerificationsByIdReq)(nil), // 7: pb.GetUserVerificationsByIdReq
|
(*GetUserVerificationsByIdReq)(nil), // 7: pb.GetUserVerificationsByIdReq
|
||||||
(*GetUserVerificationsByIdResp)(nil), // 8: pb.GetUserVerificationsByIdResp
|
(*GetUserVerificationsByIdResp)(nil), // 8: pb.GetUserVerificationsByIdResp
|
||||||
(*SearchUserVerificationsReq)(nil), // 9: pb.SearchUserVerificationsReq
|
(*SearchUserVerificationsReq)(nil), // 9: pb.SearchUserVerificationsReq
|
||||||
(*SearchUserVerificationsResp)(nil), // 10: pb.SearchUserVerificationsResp
|
(*SearchUserVerificationsResp)(nil), // 10: pb.SearchUserVerificationsResp
|
||||||
|
(*AddOrUpdateUserVerificationsReq)(nil), // 11: pb.AddOrUpdateUserVerificationsReq
|
||||||
|
(*AddOrUpdateUserVerificationsResp)(nil), // 12: pb.AddOrUpdateUserVerificationsResp
|
||||||
|
(*ListUserVerificationsByUserIdReq)(nil), // 13: pb.ListUserVerificationsByUserIdReq
|
||||||
|
(*ListUserVerificationsByUserIdResp)(nil), // 14: pb.ListUserVerificationsByUserIdResp
|
||||||
}
|
}
|
||||||
var file_user_verifications_proto_depIdxs = []int32{
|
var file_user_verifications_proto_depIdxs = []int32{
|
||||||
0, // 0: pb.GetUserVerificationsByIdResp.userVerifications:type_name -> pb.UserVerifications
|
0, // 0: pb.GetUserVerificationsByIdResp.userVerifications:type_name -> pb.UserVerifications
|
||||||
0, // 1: pb.SearchUserVerificationsResp.userVerifications:type_name -> pb.UserVerifications
|
0, // 1: pb.SearchUserVerificationsResp.userVerifications:type_name -> pb.UserVerifications
|
||||||
1, // 2: pb.user_verifications.AddUserVerifications:input_type -> pb.AddUserVerificationsReq
|
0, // 2: pb.ListUserVerificationsByUserIdResp.userVerifications:type_name -> pb.UserVerifications
|
||||||
3, // 3: pb.user_verifications.UpdateUserVerifications:input_type -> pb.UpdateUserVerificationsReq
|
1, // 3: pb.user_verifications.AddUserVerifications:input_type -> pb.AddUserVerificationsReq
|
||||||
5, // 4: pb.user_verifications.DelUserVerifications:input_type -> pb.DelUserVerificationsReq
|
3, // 4: pb.user_verifications.UpdateUserVerifications:input_type -> pb.UpdateUserVerificationsReq
|
||||||
7, // 5: pb.user_verifications.GetUserVerificationsById:input_type -> pb.GetUserVerificationsByIdReq
|
5, // 5: pb.user_verifications.DelUserVerifications:input_type -> pb.DelUserVerificationsReq
|
||||||
9, // 6: pb.user_verifications.SearchUserVerifications:input_type -> pb.SearchUserVerificationsReq
|
7, // 6: pb.user_verifications.GetUserVerificationsById:input_type -> pb.GetUserVerificationsByIdReq
|
||||||
2, // 7: pb.user_verifications.AddUserVerifications:output_type -> pb.AddUserVerificationsResp
|
9, // 7: pb.user_verifications.SearchUserVerifications:input_type -> pb.SearchUserVerificationsReq
|
||||||
4, // 8: pb.user_verifications.UpdateUserVerifications:output_type -> pb.UpdateUserVerificationsResp
|
11, // 8: pb.user_verifications.AddOrUpdateUserVerifications:input_type -> pb.AddOrUpdateUserVerificationsReq
|
||||||
6, // 9: pb.user_verifications.DelUserVerifications:output_type -> pb.DelUserVerificationsResp
|
13, // 9: pb.user_verifications.ListUserVerificationsByUserId:input_type -> pb.ListUserVerificationsByUserIdReq
|
||||||
8, // 10: pb.user_verifications.GetUserVerificationsById:output_type -> pb.GetUserVerificationsByIdResp
|
2, // 10: pb.user_verifications.AddUserVerifications:output_type -> pb.AddUserVerificationsResp
|
||||||
10, // 11: pb.user_verifications.SearchUserVerifications:output_type -> pb.SearchUserVerificationsResp
|
4, // 11: pb.user_verifications.UpdateUserVerifications:output_type -> pb.UpdateUserVerificationsResp
|
||||||
7, // [7:12] is the sub-list for method output_type
|
6, // 12: pb.user_verifications.DelUserVerifications:output_type -> pb.DelUserVerificationsResp
|
||||||
2, // [2:7] is the sub-list for method input_type
|
8, // 13: pb.user_verifications.GetUserVerificationsById:output_type -> pb.GetUserVerificationsByIdResp
|
||||||
2, // [2:2] is the sub-list for extension type_name
|
10, // 14: pb.user_verifications.SearchUserVerifications:output_type -> pb.SearchUserVerificationsResp
|
||||||
2, // [2:2] is the sub-list for extension extendee
|
12, // 15: pb.user_verifications.AddOrUpdateUserVerifications:output_type -> pb.AddOrUpdateUserVerificationsResp
|
||||||
0, // [0:2] is the sub-list for field type_name
|
14, // 16: pb.user_verifications.ListUserVerificationsByUserId:output_type -> pb.ListUserVerificationsByUserIdResp
|
||||||
|
10, // [10:17] is the sub-list for method output_type
|
||||||
|
3, // [3:10] is the sub-list for method input_type
|
||||||
|
3, // [3:3] is the sub-list for extension type_name
|
||||||
|
3, // [3:3] is the sub-list for extension extendee
|
||||||
|
0, // [0:3] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_user_verifications_proto_init() }
|
func init() { file_user_verifications_proto_init() }
|
||||||
@@ -929,7 +1142,7 @@ func file_user_verifications_proto_init() {
|
|||||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_user_verifications_proto_rawDesc), len(file_user_verifications_proto_rawDesc)),
|
RawDescriptor: unsafe.Slice(unsafe.StringData(file_user_verifications_proto_rawDesc), len(file_user_verifications_proto_rawDesc)),
|
||||||
NumEnums: 0,
|
NumEnums: 0,
|
||||||
NumMessages: 11,
|
NumMessages: 15,
|
||||||
NumExtensions: 0,
|
NumExtensions: 0,
|
||||||
NumServices: 1,
|
NumServices: 1,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// - protoc-gen-go-grpc v1.6.1
|
// - protoc-gen-go-grpc v1.6.1
|
||||||
// - protoc v3.19.4
|
// - protoc v5.29.6
|
||||||
// source: user_verifications.proto
|
// source: user_verifications.proto
|
||||||
|
|
||||||
package pb
|
package pb
|
||||||
@@ -19,11 +19,13 @@ import (
|
|||||||
const _ = grpc.SupportPackageIsVersion9
|
const _ = grpc.SupportPackageIsVersion9
|
||||||
|
|
||||||
const (
|
const (
|
||||||
UserVerifications_AddUserVerifications_FullMethodName = "/pb.user_verifications/AddUserVerifications"
|
UserVerifications_AddUserVerifications_FullMethodName = "/pb.user_verifications/AddUserVerifications"
|
||||||
UserVerifications_UpdateUserVerifications_FullMethodName = "/pb.user_verifications/UpdateUserVerifications"
|
UserVerifications_UpdateUserVerifications_FullMethodName = "/pb.user_verifications/UpdateUserVerifications"
|
||||||
UserVerifications_DelUserVerifications_FullMethodName = "/pb.user_verifications/DelUserVerifications"
|
UserVerifications_DelUserVerifications_FullMethodName = "/pb.user_verifications/DelUserVerifications"
|
||||||
UserVerifications_GetUserVerificationsById_FullMethodName = "/pb.user_verifications/GetUserVerificationsById"
|
UserVerifications_GetUserVerificationsById_FullMethodName = "/pb.user_verifications/GetUserVerificationsById"
|
||||||
UserVerifications_SearchUserVerifications_FullMethodName = "/pb.user_verifications/SearchUserVerifications"
|
UserVerifications_SearchUserVerifications_FullMethodName = "/pb.user_verifications/SearchUserVerifications"
|
||||||
|
UserVerifications_AddOrUpdateUserVerifications_FullMethodName = "/pb.user_verifications/AddOrUpdateUserVerifications"
|
||||||
|
UserVerifications_ListUserVerificationsByUserId_FullMethodName = "/pb.user_verifications/ListUserVerificationsByUserId"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UserVerificationsClient is the client API for UserVerifications service.
|
// UserVerificationsClient is the client API for UserVerifications service.
|
||||||
@@ -36,6 +38,8 @@ type UserVerificationsClient interface {
|
|||||||
DelUserVerifications(ctx context.Context, in *DelUserVerificationsReq, opts ...grpc.CallOption) (*DelUserVerificationsResp, error)
|
DelUserVerifications(ctx context.Context, in *DelUserVerificationsReq, opts ...grpc.CallOption) (*DelUserVerificationsResp, error)
|
||||||
GetUserVerificationsById(ctx context.Context, in *GetUserVerificationsByIdReq, opts ...grpc.CallOption) (*GetUserVerificationsByIdResp, error)
|
GetUserVerificationsById(ctx context.Context, in *GetUserVerificationsByIdReq, opts ...grpc.CallOption) (*GetUserVerificationsByIdResp, error)
|
||||||
SearchUserVerifications(ctx context.Context, in *SearchUserVerificationsReq, opts ...grpc.CallOption) (*SearchUserVerificationsResp, error)
|
SearchUserVerifications(ctx context.Context, in *SearchUserVerificationsReq, opts ...grpc.CallOption) (*SearchUserVerificationsResp, error)
|
||||||
|
AddOrUpdateUserVerifications(ctx context.Context, in *AddOrUpdateUserVerificationsReq, opts ...grpc.CallOption) (*AddOrUpdateUserVerificationsResp, error)
|
||||||
|
ListUserVerificationsByUserId(ctx context.Context, in *ListUserVerificationsByUserIdReq, opts ...grpc.CallOption) (*ListUserVerificationsByUserIdResp, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type userVerificationsClient struct {
|
type userVerificationsClient struct {
|
||||||
@@ -96,6 +100,26 @@ func (c *userVerificationsClient) SearchUserVerifications(ctx context.Context, i
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *userVerificationsClient) AddOrUpdateUserVerifications(ctx context.Context, in *AddOrUpdateUserVerificationsReq, opts ...grpc.CallOption) (*AddOrUpdateUserVerificationsResp, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(AddOrUpdateUserVerificationsResp)
|
||||||
|
err := c.cc.Invoke(ctx, UserVerifications_AddOrUpdateUserVerifications_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *userVerificationsClient) ListUserVerificationsByUserId(ctx context.Context, in *ListUserVerificationsByUserIdReq, opts ...grpc.CallOption) (*ListUserVerificationsByUserIdResp, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(ListUserVerificationsByUserIdResp)
|
||||||
|
err := c.cc.Invoke(ctx, UserVerifications_ListUserVerificationsByUserId_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
// UserVerificationsServer is the server API for UserVerifications service.
|
// UserVerificationsServer is the server API for UserVerifications service.
|
||||||
// All implementations must embed UnimplementedUserVerificationsServer
|
// All implementations must embed UnimplementedUserVerificationsServer
|
||||||
// for forward compatibility.
|
// for forward compatibility.
|
||||||
@@ -106,6 +130,8 @@ type UserVerificationsServer interface {
|
|||||||
DelUserVerifications(context.Context, *DelUserVerificationsReq) (*DelUserVerificationsResp, error)
|
DelUserVerifications(context.Context, *DelUserVerificationsReq) (*DelUserVerificationsResp, error)
|
||||||
GetUserVerificationsById(context.Context, *GetUserVerificationsByIdReq) (*GetUserVerificationsByIdResp, error)
|
GetUserVerificationsById(context.Context, *GetUserVerificationsByIdReq) (*GetUserVerificationsByIdResp, error)
|
||||||
SearchUserVerifications(context.Context, *SearchUserVerificationsReq) (*SearchUserVerificationsResp, error)
|
SearchUserVerifications(context.Context, *SearchUserVerificationsReq) (*SearchUserVerificationsResp, error)
|
||||||
|
AddOrUpdateUserVerifications(context.Context, *AddOrUpdateUserVerificationsReq) (*AddOrUpdateUserVerificationsResp, error)
|
||||||
|
ListUserVerificationsByUserId(context.Context, *ListUserVerificationsByUserIdReq) (*ListUserVerificationsByUserIdResp, error)
|
||||||
mustEmbedUnimplementedUserVerificationsServer()
|
mustEmbedUnimplementedUserVerificationsServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,6 +157,12 @@ func (UnimplementedUserVerificationsServer) GetUserVerificationsById(context.Con
|
|||||||
func (UnimplementedUserVerificationsServer) SearchUserVerifications(context.Context, *SearchUserVerificationsReq) (*SearchUserVerificationsResp, error) {
|
func (UnimplementedUserVerificationsServer) SearchUserVerifications(context.Context, *SearchUserVerificationsReq) (*SearchUserVerificationsResp, error) {
|
||||||
return nil, status.Error(codes.Unimplemented, "method SearchUserVerifications not implemented")
|
return nil, status.Error(codes.Unimplemented, "method SearchUserVerifications not implemented")
|
||||||
}
|
}
|
||||||
|
func (UnimplementedUserVerificationsServer) AddOrUpdateUserVerifications(context.Context, *AddOrUpdateUserVerificationsReq) (*AddOrUpdateUserVerificationsResp, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method AddOrUpdateUserVerifications not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedUserVerificationsServer) ListUserVerificationsByUserId(context.Context, *ListUserVerificationsByUserIdReq) (*ListUserVerificationsByUserIdResp, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method ListUserVerificationsByUserId not implemented")
|
||||||
|
}
|
||||||
func (UnimplementedUserVerificationsServer) mustEmbedUnimplementedUserVerificationsServer() {}
|
func (UnimplementedUserVerificationsServer) mustEmbedUnimplementedUserVerificationsServer() {}
|
||||||
func (UnimplementedUserVerificationsServer) testEmbeddedByValue() {}
|
func (UnimplementedUserVerificationsServer) testEmbeddedByValue() {}
|
||||||
|
|
||||||
@@ -242,6 +274,42 @@ func _UserVerifications_SearchUserVerifications_Handler(srv interface{}, ctx con
|
|||||||
return interceptor(ctx, in, info, handler)
|
return interceptor(ctx, in, info, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _UserVerifications_AddOrUpdateUserVerifications_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(AddOrUpdateUserVerificationsReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(UserVerificationsServer).AddOrUpdateUserVerifications(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: UserVerifications_AddOrUpdateUserVerifications_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(UserVerificationsServer).AddOrUpdateUserVerifications(ctx, req.(*AddOrUpdateUserVerificationsReq))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _UserVerifications_ListUserVerificationsByUserId_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(ListUserVerificationsByUserIdReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(UserVerificationsServer).ListUserVerificationsByUserId(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: UserVerifications_ListUserVerificationsByUserId_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(UserVerificationsServer).ListUserVerificationsByUserId(ctx, req.(*ListUserVerificationsByUserIdReq))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
// UserVerifications_ServiceDesc is the grpc.ServiceDesc for UserVerifications service.
|
// UserVerifications_ServiceDesc is the grpc.ServiceDesc for UserVerifications 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)
|
||||||
@@ -269,6 +337,14 @@ var UserVerifications_ServiceDesc = grpc.ServiceDesc{
|
|||||||
MethodName: "SearchUserVerifications",
|
MethodName: "SearchUserVerifications",
|
||||||
Handler: _UserVerifications_SearchUserVerifications_Handler,
|
Handler: _UserVerifications_SearchUserVerifications_Handler,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
MethodName: "AddOrUpdateUserVerifications",
|
||||||
|
Handler: _UserVerifications_AddOrUpdateUserVerifications_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "ListUserVerificationsByUserId",
|
||||||
|
Handler: _UserVerifications_ListUserVerificationsByUserId_Handler,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Streams: []grpc.StreamDesc{},
|
Streams: []grpc.StreamDesc{},
|
||||||
Metadata: "user_verifications.proto",
|
Metadata: "user_verifications.proto",
|
||||||
|
|||||||
@@ -14,17 +14,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
AddUserVerificationsReq = pb.AddUserVerificationsReq
|
AddOrUpdateUserVerificationsReq = pb.AddOrUpdateUserVerificationsReq
|
||||||
AddUserVerificationsResp = pb.AddUserVerificationsResp
|
AddOrUpdateUserVerificationsResp = pb.AddOrUpdateUserVerificationsResp
|
||||||
DelUserVerificationsReq = pb.DelUserVerificationsReq
|
AddUserVerificationsReq = pb.AddUserVerificationsReq
|
||||||
DelUserVerificationsResp = pb.DelUserVerificationsResp
|
AddUserVerificationsResp = pb.AddUserVerificationsResp
|
||||||
GetUserVerificationsByIdReq = pb.GetUserVerificationsByIdReq
|
DelUserVerificationsReq = pb.DelUserVerificationsReq
|
||||||
GetUserVerificationsByIdResp = pb.GetUserVerificationsByIdResp
|
DelUserVerificationsResp = pb.DelUserVerificationsResp
|
||||||
SearchUserVerificationsReq = pb.SearchUserVerificationsReq
|
GetUserVerificationsByIdReq = pb.GetUserVerificationsByIdReq
|
||||||
SearchUserVerificationsResp = pb.SearchUserVerificationsResp
|
GetUserVerificationsByIdResp = pb.GetUserVerificationsByIdResp
|
||||||
UpdateUserVerificationsReq = pb.UpdateUserVerificationsReq
|
ListUserVerificationsByUserIdReq = pb.ListUserVerificationsByUserIdReq
|
||||||
UpdateUserVerificationsResp = pb.UpdateUserVerificationsResp
|
ListUserVerificationsByUserIdResp = pb.ListUserVerificationsByUserIdResp
|
||||||
UserVerifications = pb.UserVerifications
|
SearchUserVerificationsReq = pb.SearchUserVerificationsReq
|
||||||
|
SearchUserVerificationsResp = pb.SearchUserVerificationsResp
|
||||||
|
UpdateUserVerificationsReq = pb.UpdateUserVerificationsReq
|
||||||
|
UpdateUserVerificationsResp = pb.UpdateUserVerificationsResp
|
||||||
|
UserVerifications = pb.UserVerifications
|
||||||
|
|
||||||
UserVerificationsZrpcClient interface {
|
UserVerificationsZrpcClient interface {
|
||||||
// -----------------------userVerifications-----------------------
|
// -----------------------userVerifications-----------------------
|
||||||
@@ -33,6 +37,8 @@ type (
|
|||||||
DelUserVerifications(ctx context.Context, in *DelUserVerificationsReq, opts ...grpc.CallOption) (*DelUserVerificationsResp, error)
|
DelUserVerifications(ctx context.Context, in *DelUserVerificationsReq, opts ...grpc.CallOption) (*DelUserVerificationsResp, error)
|
||||||
GetUserVerificationsById(ctx context.Context, in *GetUserVerificationsByIdReq, opts ...grpc.CallOption) (*GetUserVerificationsByIdResp, error)
|
GetUserVerificationsById(ctx context.Context, in *GetUserVerificationsByIdReq, opts ...grpc.CallOption) (*GetUserVerificationsByIdResp, error)
|
||||||
SearchUserVerifications(ctx context.Context, in *SearchUserVerificationsReq, opts ...grpc.CallOption) (*SearchUserVerificationsResp, error)
|
SearchUserVerifications(ctx context.Context, in *SearchUserVerificationsReq, opts ...grpc.CallOption) (*SearchUserVerificationsResp, error)
|
||||||
|
AddOrUpdateUserVerifications(ctx context.Context, in *AddOrUpdateUserVerificationsReq, opts ...grpc.CallOption) (*AddOrUpdateUserVerificationsResp, error)
|
||||||
|
ListUserVerificationsByUserId(ctx context.Context, in *ListUserVerificationsByUserIdReq, opts ...grpc.CallOption) (*ListUserVerificationsByUserIdResp, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultUserVerificationsZrpcClient struct {
|
defaultUserVerificationsZrpcClient struct {
|
||||||
@@ -71,3 +77,13 @@ func (m *defaultUserVerificationsZrpcClient) SearchUserVerifications(ctx context
|
|||||||
client := pb.NewUserVerificationsClient(m.cli.Conn())
|
client := pb.NewUserVerificationsClient(m.cli.Conn())
|
||||||
return client.SearchUserVerifications(ctx, in, opts...)
|
return client.SearchUserVerifications(ctx, in, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *defaultUserVerificationsZrpcClient) AddOrUpdateUserVerifications(ctx context.Context, in *AddOrUpdateUserVerificationsReq, opts ...grpc.CallOption) (*AddOrUpdateUserVerificationsResp, error) {
|
||||||
|
client := pb.NewUserVerificationsClient(m.cli.Conn())
|
||||||
|
return client.AddOrUpdateUserVerifications(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultUserVerificationsZrpcClient) ListUserVerificationsByUserId(ctx context.Context, in *ListUserVerificationsByUserIdReq, opts ...grpc.CallOption) (*ListUserVerificationsByUserIdResp, error) {
|
||||||
|
client := pb.NewUserVerificationsClient(m.cli.Conn())
|
||||||
|
return client.ListUserVerificationsByUserId(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,9 +7,19 @@ Prometheus:
|
|||||||
Port: 4001
|
Port: 4001
|
||||||
Path: /metrics
|
Path: /metrics
|
||||||
|
|
||||||
|
# ===== PROC CONFIG =====
|
||||||
|
#UsercenterRpcConf:
|
||||||
|
# Target: k8s://juwan/user-rpc-svc:8080
|
||||||
|
#UserVerificationRpc:
|
||||||
|
# Target: k8s://juwan/user_verifications-svc:8080
|
||||||
|
|
||||||
SnowflakeRpcConf:
|
# ===== DEV CONFIG ====
|
||||||
Target: k8s://juwan/snowflake-svc:8080
|
|
||||||
|
|
||||||
UserVerificationRpc:
|
UserVerificationRpc:
|
||||||
Target: k8s://juwan/user_verifications-svc:8080
|
Endpoints:
|
||||||
|
- user-verifications-rpc:8080
|
||||||
|
UsercenterRpcConf:
|
||||||
|
Endpoints:
|
||||||
|
- user-rpc:8080
|
||||||
|
|
||||||
|
Log:
|
||||||
|
Level: debug
|
||||||
@@ -146,23 +146,20 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
server.AddRoutes(
|
server.AddRoutes(
|
||||||
rest.WithMiddlewares(
|
[]rest.Route{
|
||||||
[]rest.Middleware{serverCtx.Logger},
|
{
|
||||||
[]rest.Route{
|
// 提交或修改角色认证申请 (支持幂等更新)
|
||||||
{
|
Method: http.MethodPost,
|
||||||
// 提交或修改角色认证申请 (支持幂等更新)
|
Path: "/me/verification",
|
||||||
Method: http.MethodPost,
|
Handler: verification_user.ApplyVerificationHandler(serverCtx),
|
||||||
Path: "/me/verification",
|
},
|
||||||
Handler: verification_user.ApplyVerificationHandler(serverCtx),
|
{
|
||||||
},
|
// 获取我的所有认证状态
|
||||||
{
|
Method: http.MethodGet,
|
||||||
// 获取我的所有认证状态
|
Path: "/me/verification",
|
||||||
Method: http.MethodGet,
|
Handler: verification_user.GetMyVerificationsHandler(serverCtx),
|
||||||
Path: "/me/verification",
|
},
|
||||||
Handler: verification_user.GetMyVerificationsHandler(serverCtx),
|
},
|
||||||
},
|
|
||||||
}...,
|
|
||||||
),
|
|
||||||
rest.WithPrefix("/api/v1/users"),
|
rest.WithPrefix("/api/v1/users"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package auth
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"juwan-backend/app/users/rpc/pb"
|
"juwan-backend/app/users/rpc/pb"
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
"juwan-backend/common/utils/contextj"
|
"juwan-backend/common/utils/contextj"
|
||||||
@@ -57,7 +58,8 @@ func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.RegisterRe
|
|||||||
return nil, errors.New("hash password failed")
|
return nil, errors.New("hash password failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
requestId, err := contextj.RequestIdFrom(l.ctx)
|
requestId, err := contextj.RIdFrom(l.ctx)
|
||||||
|
logx.Infof("requestId: %s", requestId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Errorf("contextj.RequestIdFrom failed: %v", err)
|
logx.Errorf("contextj.RequestIdFrom failed: %v", err)
|
||||||
return nil, errors.New("contextj.RequestIdFrom failed")
|
return nil, errors.New("contextj.RequestIdFrom failed")
|
||||||
@@ -73,7 +75,7 @@ func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.RegisterRe
|
|||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error("failed to register user: ", err)
|
logx.Error("failed to register user: ", err)
|
||||||
return nil, errors.New("failed to register user")
|
return nil, errors.New(fmt.Sprintf("failed to register user: %v", err.Error()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 返回响应
|
// 返回响应
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ package user
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
|
"juwan-backend/common/utils/contextj"
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
"juwan-backend/app/users/api/internal/types"
|
"juwan-backend/app/users/api/internal/types"
|
||||||
@@ -29,6 +32,19 @@ func NewFollowUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Follow
|
|||||||
|
|
||||||
func (l *FollowUserLogic) FollowUser(req *types.FollowUserReq) (resp *types.EmptyResp, err error) {
|
func (l *FollowUserLogic) FollowUser(req *types.FollowUserReq) (resp *types.EmptyResp, err error) {
|
||||||
// todo: add your logic here and delete this line
|
// todo: add your logic here and delete this line
|
||||||
|
userId, err := contextj.UserIDFrom(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("unauthorized")
|
||||||
|
}
|
||||||
|
|
||||||
return
|
_, err = l.svcCtx.UserRpc.AddUserFollows(l.ctx, &usercenter.AddUserFollowsReq{
|
||||||
|
FollowerId: userId,
|
||||||
|
FolloweeId: req.Id,
|
||||||
|
CreatedAt: 0,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("add user follow err: %v", err)
|
||||||
|
return nil, errors.New("failed to follow user")
|
||||||
|
}
|
||||||
|
return &types.EmptyResp{}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ package user
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
"juwan-backend/common/converter"
|
|
||||||
"juwan-backend/common/utils/contextj"
|
"juwan-backend/common/utils/contextj"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"github.com/jinzhu/copier"
|
||||||
"juwan-backend/app/users/api/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"k8s.io/apimachinery/pkg/util/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetMeLogic struct {
|
type GetMeLogic struct {
|
||||||
@@ -35,19 +35,34 @@ func NewGetMeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMeLogic
|
|||||||
func (l *GetMeLogic) GetMe() (resp *types.User, err error) {
|
func (l *GetMeLogic) GetMe() (resp *types.User, err error) {
|
||||||
userId, err := contextj.UserIDFrom(l.ctx)
|
userId, err := contextj.UserIDFrom(l.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("illegal id")
|
logx.Errorf("get user id from context: %v", err)
|
||||||
|
return nil, errors.New("illegal user")
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err := l.svcCtx.UserRpc.GetUsersById(l.ctx, &usercenter.GetUsersByIdReq{
|
user, err := l.svcCtx.UserRpc.GetUsersById(l.ctx, &usercenter.GetUsersByIdReq{
|
||||||
Id: userId,
|
Id: userId,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("get user by id error")
|
logx.Errorf("GetMeLogic.GetUsersById err: %v", err)
|
||||||
|
return nil, errors.New("get user failed")
|
||||||
}
|
}
|
||||||
err = converter.StructToStruct(user, &resp)
|
logx.Debugf("get user resp: %+v", user)
|
||||||
createAt := time.Unix(user.Users.CreatedAt, 0)
|
|
||||||
resp.CreatedAt = createAt.Format(time.DateTime)
|
resp = &types.User{}
|
||||||
|
|
||||||
|
err = copier.Copy(&resp, user.Users)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("to struct error")
|
logx.Errorf("copier.Copy err: %v", err)
|
||||||
|
return nil, errors.New("copy user failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var verificationStatus map[string]string
|
||||||
|
err = json.Unmarshal([]byte(user.Users.VerificationStatus), &verificationStatus)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("json.Unmarshal err: %v", err)
|
||||||
|
}
|
||||||
|
resp.VerifiedRoles = user.Users.VerifiedRoles
|
||||||
|
resp.VerificationStatus = verificationStatus
|
||||||
|
resp.CreatedAt = time.Unix(user.Users.CreatedAt, 0).Format(time.DateTime)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user