fix: api descript
This commit is contained in:
+1
-1
@@ -91,7 +91,7 @@ const Generators = {
|
|||||||
await run('goctl', [
|
await run('goctl', [
|
||||||
"docker", "--go", path.relative(__dirname, servicePath)
|
"docker", "--go", path.relative(__dirname, servicePath)
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,3 +16,29 @@ Kmq:
|
|||||||
Offset: last
|
Offset: last
|
||||||
Consumers: 8
|
Consumers: 8
|
||||||
Processors: 8
|
Processors: 8
|
||||||
|
|
||||||
|
Mail:
|
||||||
|
Enabled: true
|
||||||
|
Host: "${EMAIL_SMTP_HOST}"
|
||||||
|
Port: ${EMAIL_SMTP_PORT}
|
||||||
|
Username: "${EMAIL_SMTP_USERNAME}"
|
||||||
|
Password: "${EMAIL_SMTP_PASSWORD}"
|
||||||
|
FromAddress: "${EMAIL_FROM_ADDRESS}"
|
||||||
|
FromName: "${EMAIL_FROM_NAME}"
|
||||||
|
UseSSL: true
|
||||||
|
UseStartTLS: false
|
||||||
|
InsecureSkipVerify: false
|
||||||
|
ReplyTo: "${EMAIL_REPLY_TO}"
|
||||||
|
|
||||||
|
# Mail:
|
||||||
|
# Enabled: true
|
||||||
|
# Host: "smtp.163.com"
|
||||||
|
# Port: 465
|
||||||
|
# Username: "churong2646@163.com"
|
||||||
|
# Password: "GTv6C6qNbv5urAiD"
|
||||||
|
# FromAddress: "churong2646@163.com"
|
||||||
|
# FromName: "聚玩"
|
||||||
|
# UseSSL: true
|
||||||
|
# UseStartTLS: false
|
||||||
|
# InsecureSkipVerify: false
|
||||||
|
# ReplyTo: ""
|
||||||
|
|||||||
@@ -7,5 +7,20 @@ import (
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
service.ServiceConf
|
service.ServiceConf
|
||||||
Kmq kq.KqConf
|
Kmq kq.KqConf
|
||||||
|
Mail MailConf
|
||||||
|
}
|
||||||
|
|
||||||
|
type MailConf struct {
|
||||||
|
Enabled bool `json:",optional"`
|
||||||
|
Host string `json:",optional"`
|
||||||
|
Port int `json:",optional"`
|
||||||
|
Username string `json:",optional"`
|
||||||
|
Password string `json:",optional"`
|
||||||
|
FromAddress string `json:",optional"`
|
||||||
|
FromName string `json:",optional"`
|
||||||
|
UseSSL bool `json:",optional"`
|
||||||
|
UseStartTLS bool `json:",optional"`
|
||||||
|
InsecureSkipVerify bool `json:",optional"`
|
||||||
|
ReplyTo string `json:",optional"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,12 @@ package logic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"juwan-backend/app/email/mq/internal/config"
|
"juwan-backend/app/email/mq/internal/config"
|
||||||
|
"juwan-backend/app/email/mq/internal/mailer"
|
||||||
"juwan-backend/app/email/mq/internal/svc"
|
"juwan-backend/app/email/mq/internal/svc"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
@@ -23,10 +27,59 @@ func NewSendVerificationCodeMq(ctx context.Context, c config.Config, svcCtx *svc
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *SendVerificationCodeMq) Consume(ctx context.Context, key, value string) error {
|
func (l *SendVerificationCodeMq) Consume(ctx context.Context, key, value string) error {
|
||||||
_ = ctx
|
|
||||||
_ = key
|
|
||||||
_ = value
|
|
||||||
logx.Infof("Consume get message key: %s, value: %s", key, value)
|
logx.Infof("Consume get message key: %s, value: %s", key, value)
|
||||||
|
if l.svcCxt.MailSender == nil {
|
||||||
|
return fmt.Errorf("mail sender not initialized")
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload verificationCodePayload
|
||||||
|
if err := json.Unmarshal([]byte(value), &payload); err != nil {
|
||||||
|
logx.Errorf("failed to unmarshal verification code payload: %v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if payload.Type != "verification_code" {
|
||||||
|
logx.Infof("skip unsupported email task type: %s", payload.Type)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
emailAddr := strings.TrimSpace(payload.Email)
|
||||||
|
code := strings.TrimSpace(payload.Code)
|
||||||
|
scene := strings.TrimSpace(payload.Scene)
|
||||||
|
if emailAddr == "" || code == "" {
|
||||||
|
logx.Errorf("invalid verification payload: email=%s, code=%s", emailAddr, code)
|
||||||
|
return fmt.Errorf("invalid verification payload: email/code is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
expireIn := payload.ExpireIn
|
||||||
|
if expireIn <= 0 {
|
||||||
|
expireIn = 60
|
||||||
|
}
|
||||||
|
|
||||||
|
subject := "Your verification code"
|
||||||
|
body := fmt.Sprintf("Your verification code is %s. It is valid for %d seconds. Scene: %s. RequestId: %s", code, expireIn, scene, payload.RequestID)
|
||||||
|
// logx.Info("Send email to address: %s, subject: %s", emailAddr, subject)
|
||||||
|
|
||||||
|
err := l.svcCxt.MailSender.Send(ctx, mailer.Message{
|
||||||
|
To: []string{emailAddr},
|
||||||
|
Subject: subject,
|
||||||
|
Body: body,
|
||||||
|
IsHTML: false,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("failed to send verification email to %s: %v", emailAddr, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logx.Infof("verification email sent to %s successfully", emailAddr)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type verificationCodePayload struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
RequestID string `json:"requestId"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
Scene string `json:"scene"`
|
||||||
|
Code string `json:"code"`
|
||||||
|
ExpireIn int64 `json:"expireIn"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,169 @@
|
|||||||
|
package mailer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"net/smtp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"juwan-backend/app/email/mq/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Sender struct {
|
||||||
|
conf config.MailConf
|
||||||
|
}
|
||||||
|
|
||||||
|
type Message struct {
|
||||||
|
To []string
|
||||||
|
Cc []string
|
||||||
|
Bcc []string
|
||||||
|
Subject string
|
||||||
|
Body string
|
||||||
|
IsHTML bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSender(conf config.MailConf) (*Sender, error) {
|
||||||
|
if strings.TrimSpace(conf.Host) == "" {
|
||||||
|
return nil, fmt.Errorf("mail host is required")
|
||||||
|
}
|
||||||
|
if conf.Port <= 0 {
|
||||||
|
return nil, fmt.Errorf("mail port is required")
|
||||||
|
}
|
||||||
|
if strings.TrimSpace(conf.FromAddress) == "" {
|
||||||
|
return nil, fmt.Errorf("mail from address is required")
|
||||||
|
}
|
||||||
|
if conf.UseSSL && conf.UseStartTLS {
|
||||||
|
return nil, fmt.Errorf("mail config invalid: UseSSL and UseStartTLS cannot both be true")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Sender{conf: conf}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Sender) Send(ctx context.Context, msg Message) error {
|
||||||
|
toList := compactAddresses(msg.To)
|
||||||
|
if len(toList) == 0 {
|
||||||
|
return fmt.Errorf("mail recipients are empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
ccList := compactAddresses(msg.Cc)
|
||||||
|
bccList := compactAddresses(msg.Bcc)
|
||||||
|
allRecipients := append(append([]string{}, toList...), ccList...)
|
||||||
|
allRecipients = append(allRecipients, bccList...)
|
||||||
|
|
||||||
|
addr := fmt.Sprintf("%s:%d", s.conf.Host, s.conf.Port)
|
||||||
|
|
||||||
|
var (
|
||||||
|
client *smtp.Client
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
tlsConfig := &tls.Config{
|
||||||
|
ServerName: s.conf.Host,
|
||||||
|
InsecureSkipVerify: s.conf.InsecureSkipVerify,
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.conf.UseSSL {
|
||||||
|
conn, dialErr := tls.DialWithDialer((&net.Dialer{}), "tcp", addr, tlsConfig)
|
||||||
|
if dialErr != nil {
|
||||||
|
return fmt.Errorf("smtp ssl dial failed(%s): %w", addr, dialErr)
|
||||||
|
}
|
||||||
|
client, err = smtp.NewClient(conn, s.conf.Host)
|
||||||
|
} else {
|
||||||
|
dialer := &net.Dialer{}
|
||||||
|
conn, dialErr := dialer.DialContext(ctx, "tcp", addr)
|
||||||
|
if dialErr != nil {
|
||||||
|
return fmt.Errorf("smtp dial failed(%s): %w", addr, dialErr)
|
||||||
|
}
|
||||||
|
client, err = smtp.NewClient(conn, s.conf.Host)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("smtp create client failed: %w", err)
|
||||||
|
}
|
||||||
|
defer client.Close()
|
||||||
|
|
||||||
|
if s.conf.UseStartTLS {
|
||||||
|
if err = client.StartTLS(tlsConfig); err != nil {
|
||||||
|
return fmt.Errorf("smtp starttls failed: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(s.conf.Username) != "" {
|
||||||
|
auth := smtp.PlainAuth("", s.conf.Username, s.conf.Password, s.conf.Host)
|
||||||
|
if err = client.Auth(auth); err != nil {
|
||||||
|
return fmt.Errorf("smtp auth failed: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = client.Mail(s.conf.FromAddress); err != nil {
|
||||||
|
return fmt.Errorf("smtp mail from failed: %w", err)
|
||||||
|
}
|
||||||
|
for _, rcpt := range allRecipients {
|
||||||
|
if err = client.Rcpt(rcpt); err != nil {
|
||||||
|
return fmt.Errorf("smtp rcpt to(%s) failed: %w", rcpt, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
w, err := client.Data()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("smtp data start failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
bodyType := "text/plain; charset=UTF-8"
|
||||||
|
if msg.IsHTML {
|
||||||
|
bodyType = "text/html; charset=UTF-8"
|
||||||
|
}
|
||||||
|
|
||||||
|
headers := []string{
|
||||||
|
fmt.Sprintf("From: %s", formatFrom(s.conf.FromName, s.conf.FromAddress)),
|
||||||
|
fmt.Sprintf("To: %s", strings.Join(toList, ",")),
|
||||||
|
fmt.Sprintf("Subject: %s", msg.Subject),
|
||||||
|
"MIME-Version: 1.0",
|
||||||
|
fmt.Sprintf("Content-Type: %s", bodyType),
|
||||||
|
}
|
||||||
|
if len(ccList) > 0 {
|
||||||
|
headers = append(headers, fmt.Sprintf("Cc: %s", strings.Join(ccList, ",")))
|
||||||
|
}
|
||||||
|
if strings.TrimSpace(s.conf.ReplyTo) != "" {
|
||||||
|
headers = append(headers, fmt.Sprintf("Reply-To: %s", strings.TrimSpace(s.conf.ReplyTo)))
|
||||||
|
}
|
||||||
|
|
||||||
|
raw := strings.Join(headers, "\r\n") + "\r\n\r\n" + msg.Body
|
||||||
|
if _, err = w.Write([]byte(raw)); err != nil {
|
||||||
|
_ = w.Close()
|
||||||
|
return fmt.Errorf("smtp write body failed: %w", err)
|
||||||
|
}
|
||||||
|
if err = w.Close(); err != nil {
|
||||||
|
return fmt.Errorf("smtp data close failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = client.Quit(); err != nil {
|
||||||
|
return fmt.Errorf("smtp quit failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatFrom(name, address string) string {
|
||||||
|
trimmedName := strings.TrimSpace(name)
|
||||||
|
trimmedAddress := strings.TrimSpace(address)
|
||||||
|
if trimmedName == "" {
|
||||||
|
return trimmedAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s <%s>", trimmedName, trimmedAddress)
|
||||||
|
}
|
||||||
|
|
||||||
|
func compactAddresses(input []string) []string {
|
||||||
|
result := make([]string, 0, len(input))
|
||||||
|
for _, item := range input {
|
||||||
|
trimmed := strings.TrimSpace(item)
|
||||||
|
if trimmed == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
result = append(result, trimmed)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
@@ -1,13 +1,30 @@
|
|||||||
package svc
|
package svc
|
||||||
|
|
||||||
import "juwan-backend/app/email/mq/internal/config"
|
import (
|
||||||
|
"juwan-backend/app/email/mq/internal/config"
|
||||||
|
"juwan-backend/app/email/mq/internal/mailer"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
c config.Config
|
c config.Config
|
||||||
|
MailSender *mailer.Sender
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
var sender *mailer.Sender
|
||||||
|
if c.Mail.Enabled {
|
||||||
|
mailSender, err := mailer.NewSender(c.Mail)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("failed to init mail sender: %v", err)
|
||||||
|
} else {
|
||||||
|
sender = mailSender
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
c: c,
|
c: c,
|
||||||
|
MailSender: sender,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
Name: game-api
|
||||||
|
Host: 0.0.0.0
|
||||||
|
Port: 8888
|
||||||
|
|
||||||
|
Prometheus:
|
||||||
|
Host: 0.0.0.0
|
||||||
|
Port: 4001
|
||||||
|
Path: /metrics
|
||||||
|
|
||||||
|
GameRpcConf:
|
||||||
|
Target: k8s://juwan/game-rpc-svc:8080
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"juwan-backend/app/game/api/internal/config"
|
||||||
|
"juwan-backend/app/game/api/internal/handler"
|
||||||
|
"juwan-backend/app/game/api/internal/svc"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/conf"
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
|
var configFile = flag.String("f", "etc/game-api.yaml", "the config file")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
var c config.Config
|
||||||
|
conf.MustLoad(*configFile, &c)
|
||||||
|
|
||||||
|
server := rest.MustNewServer(c.RestConf)
|
||||||
|
defer server.Stop()
|
||||||
|
|
||||||
|
ctx := svc.NewServiceContext(c)
|
||||||
|
handler.RegisterHandlers(server, ctx)
|
||||||
|
|
||||||
|
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||||
|
server.Start()
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
rest.RestConf
|
||||||
|
GameRpcConf zrpc.RpcClientConf
|
||||||
|
}
|
||||||
@@ -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 GetGameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.EmptyResp
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := game.NewGetGameLogic(r.Context(), svcCtx)
|
||||||
|
resp := l.GetGame(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package 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 ListGamesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.PageReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := game.NewListGamesLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.ListGames(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
game "juwan-backend/app/game/api/internal/handler/game"
|
||||||
|
"juwan-backend/app/game/api/internal/svc"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
|
server.AddRoutes(
|
||||||
|
[]rest.Route{
|
||||||
|
{
|
||||||
|
// 获取游戏列表
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/",
|
||||||
|
Handler: game.ListGamesHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 获取游戏详情
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/:id",
|
||||||
|
Handler: game.GetGameHandler(serverCtx),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rest.WithPrefix("/api/v1/games"),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package game
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/game/api/internal/svc"
|
||||||
|
"juwan-backend/app/game/api/internal/types"
|
||||||
|
"juwan-backend/app/game/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetGameLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取游戏详情
|
||||||
|
func NewGetGameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGameLogic {
|
||||||
|
return &GetGameLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetGameLogic) GetGame(req *types.GetGameReq) (resp *types.Game) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
game, err := l.svcCtx.GameRpc.GetGamesById(l.ctx, &pb.GetGamesByIdReq{Id: req.Id})
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &types.Game{
|
||||||
|
Id: game.Games.Id,
|
||||||
|
Name: game.Games.Name,
|
||||||
|
Icon: game.Games.Icon,
|
||||||
|
Category: game.Games.Category,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package game
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/game/api/internal/svc"
|
||||||
|
"juwan-backend/app/game/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ListGamesLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取游戏列表
|
||||||
|
func NewListGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListGamesLogic {
|
||||||
|
return &ListGamesLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListGamesLogic) ListGames(req *types.PageReq) (resp *types.GameListResp, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package svc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"juwan-backend/app/game/api/internal/config"
|
||||||
|
"juwan-backend/app/game/rpc/gamepublic"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ServiceContext struct {
|
||||||
|
Config config.Config
|
||||||
|
GameRpc gamepublic.GamePublic
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
return &ServiceContext{
|
||||||
|
Config: c,
|
||||||
|
GameRpc: gamepublic.NewGamePublic(zrpc.MustNewClient(c.GameRpcConf)),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
type EmptyResp struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type Game struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
Category string `json:"category"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GameListResp struct {
|
||||||
|
Items []Game `json:"items"`
|
||||||
|
Meta PageMeta `json:"meta"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetGameReq struct {
|
||||||
|
Id int64 `path:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PageMeta struct {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
Offset int64 `json:"offset"`
|
||||||
|
Limit int64 `json:"limit"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PageReq struct {
|
||||||
|
Offset int64 `form:"offset,default=0"`
|
||||||
|
Limit int64 `form:"limit,default=20"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SimpleUser struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Nickname string `json:"nickname"`
|
||||||
|
Avatar string `json:"avatar"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserProfile struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
Nickname string `json:"nickname"`
|
||||||
|
Avatar string `json:"avatar"`
|
||||||
|
Role string `json:"role"` // consumer, player, owner, admin
|
||||||
|
VerifiedRoles []string `json:"verifiedRoles"`
|
||||||
|
VerificationStatus map[string]string `json:"verificationStatus"`
|
||||||
|
Phone string `json:"phone,optional"`
|
||||||
|
Bio string `json:"bio,optional"`
|
||||||
|
CreatedAt string `json:"createdAt"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
Name: pb.rpc
|
||||||
|
ListenOn: 0.0.0.0:8080
|
||||||
|
|
||||||
|
|
||||||
|
Prometheus:
|
||||||
|
Host: 0.0.0.0
|
||||||
|
Port: 4001
|
||||||
|
Path: /metrics
|
||||||
|
|
||||||
|
# tcd:
|
||||||
|
# Hosts:
|
||||||
|
# - 127.0.0.1:2379
|
||||||
|
# Key: pb.rpc
|
||||||
|
|
||||||
|
# Target: k8s://juwan/<service name>.<namespace>:8080
|
||||||
|
|
||||||
|
|
||||||
|
#DB:
|
||||||
|
# Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@game-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
# Slave: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@game-db-ro.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
|
||||||
|
DB:
|
||||||
|
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
Slave: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-ro.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
|
||||||
|
|
||||||
|
CacheConf:
|
||||||
|
- Host: "${REDIS_M_HOST}"
|
||||||
|
Type: node
|
||||||
|
Pass: "${REDIS_PASSWORD}"
|
||||||
|
User: "default"
|
||||||
|
- Host: "${REDIS_S_HOST}"
|
||||||
|
Type: node
|
||||||
|
Pass: "${REDIS_PASSWORD}"
|
||||||
|
User: "default"
|
||||||
|
|
||||||
|
Log:
|
||||||
|
Level: info
|
||||||
@@ -0,0 +1,288 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
// goctl 1.9.2
|
||||||
|
// Source: game.proto
|
||||||
|
|
||||||
|
package gamepublic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/game/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
AddGamesReq = pb.AddGamesReq
|
||||||
|
AddGamesResp = pb.AddGamesResp
|
||||||
|
AddPlayerServicesReq = pb.AddPlayerServicesReq
|
||||||
|
AddPlayerServicesResp = pb.AddPlayerServicesResp
|
||||||
|
AddPlayersReq = pb.AddPlayersReq
|
||||||
|
AddPlayersResp = pb.AddPlayersResp
|
||||||
|
AddShopInvitationsReq = pb.AddShopInvitationsReq
|
||||||
|
AddShopInvitationsResp = pb.AddShopInvitationsResp
|
||||||
|
AddShopPlayersReq = pb.AddShopPlayersReq
|
||||||
|
AddShopPlayersResp = pb.AddShopPlayersResp
|
||||||
|
AddShopsReq = pb.AddShopsReq
|
||||||
|
AddShopsResp = pb.AddShopsResp
|
||||||
|
DelGamesReq = pb.DelGamesReq
|
||||||
|
DelGamesResp = pb.DelGamesResp
|
||||||
|
DelPlayerServicesReq = pb.DelPlayerServicesReq
|
||||||
|
DelPlayerServicesResp = pb.DelPlayerServicesResp
|
||||||
|
DelPlayersReq = pb.DelPlayersReq
|
||||||
|
DelPlayersResp = pb.DelPlayersResp
|
||||||
|
DelShopInvitationsReq = pb.DelShopInvitationsReq
|
||||||
|
DelShopInvitationsResp = pb.DelShopInvitationsResp
|
||||||
|
DelShopPlayersReq = pb.DelShopPlayersReq
|
||||||
|
DelShopPlayersResp = pb.DelShopPlayersResp
|
||||||
|
DelShopsReq = pb.DelShopsReq
|
||||||
|
DelShopsResp = pb.DelShopsResp
|
||||||
|
Games = pb.Games
|
||||||
|
GetGamesByIdReq = pb.GetGamesByIdReq
|
||||||
|
GetGamesByIdResp = pb.GetGamesByIdResp
|
||||||
|
GetPlayerServicesByIdReq = pb.GetPlayerServicesByIdReq
|
||||||
|
GetPlayerServicesByIdResp = pb.GetPlayerServicesByIdResp
|
||||||
|
GetPlayersByIdReq = pb.GetPlayersByIdReq
|
||||||
|
GetPlayersByIdResp = pb.GetPlayersByIdResp
|
||||||
|
GetShopInvitationsByIdReq = pb.GetShopInvitationsByIdReq
|
||||||
|
GetShopInvitationsByIdResp = pb.GetShopInvitationsByIdResp
|
||||||
|
GetShopPlayersByIdReq = pb.GetShopPlayersByIdReq
|
||||||
|
GetShopPlayersByIdResp = pb.GetShopPlayersByIdResp
|
||||||
|
GetShopsByIdReq = pb.GetShopsByIdReq
|
||||||
|
GetShopsByIdResp = pb.GetShopsByIdResp
|
||||||
|
PlayerServices = pb.PlayerServices
|
||||||
|
Players = pb.Players
|
||||||
|
SearchGamesReq = pb.SearchGamesReq
|
||||||
|
SearchGamesResp = pb.SearchGamesResp
|
||||||
|
SearchPlayerServicesReq = pb.SearchPlayerServicesReq
|
||||||
|
SearchPlayerServicesResp = pb.SearchPlayerServicesResp
|
||||||
|
SearchPlayersReq = pb.SearchPlayersReq
|
||||||
|
SearchPlayersResp = pb.SearchPlayersResp
|
||||||
|
SearchShopInvitationsReq = pb.SearchShopInvitationsReq
|
||||||
|
SearchShopInvitationsResp = pb.SearchShopInvitationsResp
|
||||||
|
SearchShopPlayersReq = pb.SearchShopPlayersReq
|
||||||
|
SearchShopPlayersResp = pb.SearchShopPlayersResp
|
||||||
|
SearchShopsReq = pb.SearchShopsReq
|
||||||
|
SearchShopsResp = pb.SearchShopsResp
|
||||||
|
ShopInvitations = pb.ShopInvitations
|
||||||
|
ShopPlayers = pb.ShopPlayers
|
||||||
|
Shops = pb.Shops
|
||||||
|
UpdateGamesReq = pb.UpdateGamesReq
|
||||||
|
UpdateGamesResp = pb.UpdateGamesResp
|
||||||
|
UpdatePlayerServicesReq = pb.UpdatePlayerServicesReq
|
||||||
|
UpdatePlayerServicesResp = pb.UpdatePlayerServicesResp
|
||||||
|
UpdatePlayersReq = pb.UpdatePlayersReq
|
||||||
|
UpdatePlayersResp = pb.UpdatePlayersResp
|
||||||
|
UpdateShopInvitationsReq = pb.UpdateShopInvitationsReq
|
||||||
|
UpdateShopInvitationsResp = pb.UpdateShopInvitationsResp
|
||||||
|
UpdateShopPlayersReq = pb.UpdateShopPlayersReq
|
||||||
|
UpdateShopPlayersResp = pb.UpdateShopPlayersResp
|
||||||
|
UpdateShopsReq = pb.UpdateShopsReq
|
||||||
|
UpdateShopsResp = pb.UpdateShopsResp
|
||||||
|
|
||||||
|
GamePublic interface {
|
||||||
|
// -----------------------games-----------------------
|
||||||
|
AddGames(ctx context.Context, in *AddGamesReq, opts ...grpc.CallOption) (*AddGamesResp, error)
|
||||||
|
UpdateGames(ctx context.Context, in *UpdateGamesReq, opts ...grpc.CallOption) (*UpdateGamesResp, error)
|
||||||
|
DelGames(ctx context.Context, in *DelGamesReq, opts ...grpc.CallOption) (*DelGamesResp, error)
|
||||||
|
GetGamesById(ctx context.Context, in *GetGamesByIdReq, opts ...grpc.CallOption) (*GetGamesByIdResp, error)
|
||||||
|
SearchGames(ctx context.Context, in *SearchGamesReq, opts ...grpc.CallOption) (*SearchGamesResp, error)
|
||||||
|
// -----------------------playerServices-----------------------
|
||||||
|
AddPlayerServices(ctx context.Context, in *AddPlayerServicesReq, opts ...grpc.CallOption) (*AddPlayerServicesResp, error)
|
||||||
|
UpdatePlayerServices(ctx context.Context, in *UpdatePlayerServicesReq, opts ...grpc.CallOption) (*UpdatePlayerServicesResp, error)
|
||||||
|
DelPlayerServices(ctx context.Context, in *DelPlayerServicesReq, opts ...grpc.CallOption) (*DelPlayerServicesResp, error)
|
||||||
|
GetPlayerServicesById(ctx context.Context, in *GetPlayerServicesByIdReq, opts ...grpc.CallOption) (*GetPlayerServicesByIdResp, error)
|
||||||
|
SearchPlayerServices(ctx context.Context, in *SearchPlayerServicesReq, opts ...grpc.CallOption) (*SearchPlayerServicesResp, error)
|
||||||
|
// -----------------------players-----------------------
|
||||||
|
AddPlayers(ctx context.Context, in *AddPlayersReq, opts ...grpc.CallOption) (*AddPlayersResp, error)
|
||||||
|
UpdatePlayers(ctx context.Context, in *UpdatePlayersReq, opts ...grpc.CallOption) (*UpdatePlayersResp, error)
|
||||||
|
DelPlayers(ctx context.Context, in *DelPlayersReq, opts ...grpc.CallOption) (*DelPlayersResp, error)
|
||||||
|
GetPlayersById(ctx context.Context, in *GetPlayersByIdReq, opts ...grpc.CallOption) (*GetPlayersByIdResp, error)
|
||||||
|
SearchPlayers(ctx context.Context, in *SearchPlayersReq, opts ...grpc.CallOption) (*SearchPlayersResp, error)
|
||||||
|
// -----------------------shopInvitations-----------------------
|
||||||
|
AddShopInvitations(ctx context.Context, in *AddShopInvitationsReq, opts ...grpc.CallOption) (*AddShopInvitationsResp, error)
|
||||||
|
UpdateShopInvitations(ctx context.Context, in *UpdateShopInvitationsReq, opts ...grpc.CallOption) (*UpdateShopInvitationsResp, error)
|
||||||
|
DelShopInvitations(ctx context.Context, in *DelShopInvitationsReq, opts ...grpc.CallOption) (*DelShopInvitationsResp, error)
|
||||||
|
GetShopInvitationsById(ctx context.Context, in *GetShopInvitationsByIdReq, opts ...grpc.CallOption) (*GetShopInvitationsByIdResp, error)
|
||||||
|
SearchShopInvitations(ctx context.Context, in *SearchShopInvitationsReq, opts ...grpc.CallOption) (*SearchShopInvitationsResp, error)
|
||||||
|
// -----------------------shopPlayers-----------------------
|
||||||
|
AddShopPlayers(ctx context.Context, in *AddShopPlayersReq, opts ...grpc.CallOption) (*AddShopPlayersResp, error)
|
||||||
|
UpdateShopPlayers(ctx context.Context, in *UpdateShopPlayersReq, opts ...grpc.CallOption) (*UpdateShopPlayersResp, error)
|
||||||
|
DelShopPlayers(ctx context.Context, in *DelShopPlayersReq, opts ...grpc.CallOption) (*DelShopPlayersResp, error)
|
||||||
|
GetShopPlayersById(ctx context.Context, in *GetShopPlayersByIdReq, opts ...grpc.CallOption) (*GetShopPlayersByIdResp, error)
|
||||||
|
SearchShopPlayers(ctx context.Context, in *SearchShopPlayersReq, opts ...grpc.CallOption) (*SearchShopPlayersResp, error)
|
||||||
|
// -----------------------shops-----------------------
|
||||||
|
AddShops(ctx context.Context, in *AddShopsReq, opts ...grpc.CallOption) (*AddShopsResp, error)
|
||||||
|
UpdateShops(ctx context.Context, in *UpdateShopsReq, opts ...grpc.CallOption) (*UpdateShopsResp, error)
|
||||||
|
DelShops(ctx context.Context, in *DelShopsReq, opts ...grpc.CallOption) (*DelShopsResp, error)
|
||||||
|
GetShopsById(ctx context.Context, in *GetShopsByIdReq, opts ...grpc.CallOption) (*GetShopsByIdResp, error)
|
||||||
|
SearchShops(ctx context.Context, in *SearchShopsReq, opts ...grpc.CallOption) (*SearchShopsResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultGamePublic struct {
|
||||||
|
cli zrpc.Client
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewGamePublic(cli zrpc.Client) GamePublic {
|
||||||
|
return &defaultGamePublic{
|
||||||
|
cli: cli,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------games-----------------------
|
||||||
|
func (m *defaultGamePublic) AddGames(ctx context.Context, in *AddGamesReq, opts ...grpc.CallOption) (*AddGamesResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.AddGames(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) UpdateGames(ctx context.Context, in *UpdateGamesReq, opts ...grpc.CallOption) (*UpdateGamesResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.UpdateGames(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) DelGames(ctx context.Context, in *DelGamesReq, opts ...grpc.CallOption) (*DelGamesResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.DelGames(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) GetGamesById(ctx context.Context, in *GetGamesByIdReq, opts ...grpc.CallOption) (*GetGamesByIdResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.GetGamesById(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) SearchGames(ctx context.Context, in *SearchGamesReq, opts ...grpc.CallOption) (*SearchGamesResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.SearchGames(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------playerServices-----------------------
|
||||||
|
func (m *defaultGamePublic) AddPlayerServices(ctx context.Context, in *AddPlayerServicesReq, opts ...grpc.CallOption) (*AddPlayerServicesResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.AddPlayerServices(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) UpdatePlayerServices(ctx context.Context, in *UpdatePlayerServicesReq, opts ...grpc.CallOption) (*UpdatePlayerServicesResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.UpdatePlayerServices(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) DelPlayerServices(ctx context.Context, in *DelPlayerServicesReq, opts ...grpc.CallOption) (*DelPlayerServicesResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.DelPlayerServices(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) GetPlayerServicesById(ctx context.Context, in *GetPlayerServicesByIdReq, opts ...grpc.CallOption) (*GetPlayerServicesByIdResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.GetPlayerServicesById(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) SearchPlayerServices(ctx context.Context, in *SearchPlayerServicesReq, opts ...grpc.CallOption) (*SearchPlayerServicesResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.SearchPlayerServices(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------players-----------------------
|
||||||
|
func (m *defaultGamePublic) AddPlayers(ctx context.Context, in *AddPlayersReq, opts ...grpc.CallOption) (*AddPlayersResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.AddPlayers(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) UpdatePlayers(ctx context.Context, in *UpdatePlayersReq, opts ...grpc.CallOption) (*UpdatePlayersResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.UpdatePlayers(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) DelPlayers(ctx context.Context, in *DelPlayersReq, opts ...grpc.CallOption) (*DelPlayersResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.DelPlayers(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) GetPlayersById(ctx context.Context, in *GetPlayersByIdReq, opts ...grpc.CallOption) (*GetPlayersByIdResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.GetPlayersById(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) SearchPlayers(ctx context.Context, in *SearchPlayersReq, opts ...grpc.CallOption) (*SearchPlayersResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.SearchPlayers(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------shopInvitations-----------------------
|
||||||
|
func (m *defaultGamePublic) AddShopInvitations(ctx context.Context, in *AddShopInvitationsReq, opts ...grpc.CallOption) (*AddShopInvitationsResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.AddShopInvitations(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) UpdateShopInvitations(ctx context.Context, in *UpdateShopInvitationsReq, opts ...grpc.CallOption) (*UpdateShopInvitationsResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.UpdateShopInvitations(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) DelShopInvitations(ctx context.Context, in *DelShopInvitationsReq, opts ...grpc.CallOption) (*DelShopInvitationsResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.DelShopInvitations(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) GetShopInvitationsById(ctx context.Context, in *GetShopInvitationsByIdReq, opts ...grpc.CallOption) (*GetShopInvitationsByIdResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.GetShopInvitationsById(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) SearchShopInvitations(ctx context.Context, in *SearchShopInvitationsReq, opts ...grpc.CallOption) (*SearchShopInvitationsResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.SearchShopInvitations(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------shopPlayers-----------------------
|
||||||
|
func (m *defaultGamePublic) AddShopPlayers(ctx context.Context, in *AddShopPlayersReq, opts ...grpc.CallOption) (*AddShopPlayersResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.AddShopPlayers(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) UpdateShopPlayers(ctx context.Context, in *UpdateShopPlayersReq, opts ...grpc.CallOption) (*UpdateShopPlayersResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.UpdateShopPlayers(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) DelShopPlayers(ctx context.Context, in *DelShopPlayersReq, opts ...grpc.CallOption) (*DelShopPlayersResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.DelShopPlayers(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) GetShopPlayersById(ctx context.Context, in *GetShopPlayersByIdReq, opts ...grpc.CallOption) (*GetShopPlayersByIdResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.GetShopPlayersById(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) SearchShopPlayers(ctx context.Context, in *SearchShopPlayersReq, opts ...grpc.CallOption) (*SearchShopPlayersResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.SearchShopPlayers(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------shops-----------------------
|
||||||
|
func (m *defaultGamePublic) AddShops(ctx context.Context, in *AddShopsReq, opts ...grpc.CallOption) (*AddShopsResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.AddShops(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) UpdateShops(ctx context.Context, in *UpdateShopsReq, opts ...grpc.CallOption) (*UpdateShopsResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.UpdateShops(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) DelShops(ctx context.Context, in *DelShopsReq, opts ...grpc.CallOption) (*DelShopsResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.DelShops(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) GetShopsById(ctx context.Context, in *GetShopsByIdReq, opts ...grpc.CallOption) (*GetShopsByIdResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.GetShopsById(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultGamePublic) SearchShops(ctx context.Context, in *SearchShopsReq, opts ...grpc.CallOption) (*SearchShopsResp, error) {
|
||||||
|
client := pb.NewGamePublicClient(m.cli.Conn())
|
||||||
|
return client.SearchShops(ctx, in, opts...)
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
zrpc.RpcServerConf
|
||||||
|
SnowflakeRpcConf zrpc.RpcClientConf
|
||||||
|
DB struct {
|
||||||
|
Master string
|
||||||
|
Slaves string
|
||||||
|
}
|
||||||
|
CacheConf cache.CacheConf
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||||
|
|
||||||
|
"juwan-backend/app/game/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/game/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AddGamesLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAddGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddGamesLogic {
|
||||||
|
return &AddGamesLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------games-----------------------
|
||||||
|
func (l *AddGamesLogic) AddGames(in *pb.AddGamesReq) (*pb.AddGamesResp, error) {
|
||||||
|
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("AddGamesLogic.addGames err:%v", err)
|
||||||
|
return nil, errors.New("create game id failed")
|
||||||
|
}
|
||||||
|
_, err = l.svcCtx.GameModelRW.Games.Create().
|
||||||
|
SetID(idResp.Id).
|
||||||
|
SetName(in.Name).
|
||||||
|
SetIcon(in.Icon).
|
||||||
|
SetCategory(in.Category).
|
||||||
|
SetSortOrder(int(in.SortOrder)).
|
||||||
|
Save(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("AddGamesLogic.addGames err:%v", err)
|
||||||
|
return nil, errors.New("add game failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.AddGamesResp{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
type AddGamesReq struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` //name
|
||||||
|
Icon string `protobuf:"bytes,2,opt,name=icon,proto3" json:"icon,omitempty"` //icon
|
||||||
|
Category string `protobuf:"bytes,3,opt,name=category,proto3" json:"category,omitempty"` //category
|
||||||
|
SortOrder int64 `protobuf:"varint,4,opt,name=sortOrder,proto3" json:"sortOrder,omitempty"` //sortOrder
|
||||||
|
IsActive bool `protobuf:"varint,5,opt,name=isActive,proto3" json:"isActive,omitempty"` //isActive
|
||||||
|
CreatedAt int64 `protobuf:"varint,6,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt
|
||||||
|
UpdatedAt int64 `protobuf:"varint,7,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
*/
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/game/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/game/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DelGamesLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDelGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelGamesLogic {
|
||||||
|
return &DelGamesLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *DelGamesLogic) DelGames(in *pb.DelGamesReq) (*pb.DelGamesResp, error) {
|
||||||
|
err := l.svcCtx.GameModelRW.Games.DeleteOneID(in.Id).Exec(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("delete games failed, %s", err.Error())
|
||||||
|
return nil, errors.New("delete games failed")
|
||||||
|
}
|
||||||
|
return &pb.DelGamesResp{}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/games"
|
||||||
|
|
||||||
|
"juwan-backend/app/game/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/game/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetGamesByIdLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetGamesByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGamesByIdLogic {
|
||||||
|
return &GetGamesByIdLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetGamesByIdLogic) GetGamesById(in *pb.GetGamesByIdReq) (*pb.GetGamesByIdResp, error) {
|
||||||
|
game, err := l.svcCtx.GameModelRO.Games.Query().Where(games.IDEQ(in.Id)).First(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.WithContext(l.ctx).Errorf("GetGamesByIdLogic err: %v", err)
|
||||||
|
return nil, errors.New("get games by id failed")
|
||||||
|
}
|
||||||
|
pbGame := pb.Games{}
|
||||||
|
err = copier.Copy(&pbGame, &game)
|
||||||
|
if err != nil {
|
||||||
|
logx.WithContext(l.ctx).Errorf("GetGamesByIdLogic copier err: %v", err)
|
||||||
|
return nil, errors.New("get games by id failed")
|
||||||
|
}
|
||||||
|
pbGame.CreatedAt = game.CreatedAt.Unix()
|
||||||
|
pbGame.UpdatedAt = game.UpdatedAt.Unix()
|
||||||
|
return &pb.GetGamesByIdResp{
|
||||||
|
Games: &pbGame,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/games"
|
||||||
|
"juwan-backend/app/game/rpc/internal/models/predicate"
|
||||||
|
|
||||||
|
"juwan-backend/app/game/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/game/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SearchGamesLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSearchGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchGamesLogic {
|
||||||
|
return &SearchGamesLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *SearchGamesLogic) SearchGames(in *pb.SearchGamesReq) (*pb.SearchGamesResp, error) {
|
||||||
|
if in.Limit > 1000 {
|
||||||
|
return nil, errors.New("limit too large")
|
||||||
|
}
|
||||||
|
|
||||||
|
preds := make([]predicate.Games, 0, 8)
|
||||||
|
if in.IdOpt != nil {
|
||||||
|
preds = append(preds, games.IDEQ(*in.IdOpt))
|
||||||
|
} else if in.Id != 0 {
|
||||||
|
preds = append(preds, games.IDEQ(in.Id))
|
||||||
|
}
|
||||||
|
if in.NameOpt != nil {
|
||||||
|
if *in.NameOpt != "" {
|
||||||
|
preds = append(preds, games.NameContainsFold(*in.NameOpt))
|
||||||
|
}
|
||||||
|
} else if in.Name != "" {
|
||||||
|
preds = append(preds, games.NameContainsFold(in.Name))
|
||||||
|
}
|
||||||
|
if in.IconOpt != nil {
|
||||||
|
if *in.IconOpt != "" {
|
||||||
|
preds = append(preds, games.IconContainsFold(*in.IconOpt))
|
||||||
|
}
|
||||||
|
} else if in.Icon != "" {
|
||||||
|
preds = append(preds, games.IconContainsFold(in.Icon))
|
||||||
|
}
|
||||||
|
if in.CategoryOpt != nil {
|
||||||
|
if *in.CategoryOpt != "" {
|
||||||
|
preds = append(preds, games.CategoryContainsFold(*in.CategoryOpt))
|
||||||
|
}
|
||||||
|
} else if in.Category != "" {
|
||||||
|
preds = append(preds, games.CategoryContainsFold(in.Category))
|
||||||
|
}
|
||||||
|
if in.SortOrderOpt != nil {
|
||||||
|
preds = append(preds, games.SortOrderEQ(int(*in.SortOrderOpt)))
|
||||||
|
} else if in.SortOrder != 0 {
|
||||||
|
preds = append(preds, games.SortOrderEQ(int(in.SortOrder)))
|
||||||
|
}
|
||||||
|
if in.IsActiveOpt != nil {
|
||||||
|
preds = append(preds, games.IsActiveEQ(*in.IsActiveOpt))
|
||||||
|
} else if in.IsActive {
|
||||||
|
preds = append(preds, games.IsActiveEQ(true))
|
||||||
|
}
|
||||||
|
|
||||||
|
query := l.svcCtx.GameModelRO.Games.Query()
|
||||||
|
if len(preds) > 0 {
|
||||||
|
if in.MatchMode == pb.MatchMode_MATCH_MODE_AND {
|
||||||
|
query = query.Where(games.And(preds...))
|
||||||
|
} else {
|
||||||
|
query = query.Where(games.Or(preds...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
all, err := query.
|
||||||
|
Offset(int(in.Page * in.Limit)).
|
||||||
|
Limit(int(in.Limit)).
|
||||||
|
All(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("search games failed, %s", err.Error())
|
||||||
|
return nil, errors.New("search games failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
list := make([]*pb.Games, 0, len(all))
|
||||||
|
for _, v := range all {
|
||||||
|
temp := &pb.Games{}
|
||||||
|
err = copier.Copy(temp, &v)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("search games failed, %s", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
temp.CreatedAt = v.CreatedAt.Unix()
|
||||||
|
temp.UpdatedAt = v.UpdatedAt.Unix()
|
||||||
|
list = append(list, temp)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.SearchGamesResp{
|
||||||
|
Games: list,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"juwan-backend/app/game/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/game/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdateGamesLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUpdateGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateGamesLogic {
|
||||||
|
return &UpdateGamesLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *UpdateGamesLogic) UpdateGames(in *pb.UpdateGamesReq) (*pb.UpdateGamesResp, error) {
|
||||||
|
update := l.svcCtx.GameModelRW.Games.UpdateOneID(in.Id)
|
||||||
|
updated := false
|
||||||
|
|
||||||
|
if in.NameOpt != nil {
|
||||||
|
update.SetNillableName(in.NameOpt)
|
||||||
|
updated = true
|
||||||
|
} else if in.Name != "" {
|
||||||
|
update.SetName(in.Name)
|
||||||
|
updated = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if in.IconOpt != nil {
|
||||||
|
update.SetNillableIcon(in.IconOpt)
|
||||||
|
updated = true
|
||||||
|
} else if in.Icon != "" {
|
||||||
|
update.SetIcon(in.Icon)
|
||||||
|
updated = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if in.CategoryOpt != nil {
|
||||||
|
update.SetNillableCategory(in.CategoryOpt)
|
||||||
|
updated = true
|
||||||
|
} else if in.Category != "" {
|
||||||
|
update.SetCategory(in.Category)
|
||||||
|
updated = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if in.SortOrderOpt != nil {
|
||||||
|
sortOrder := int(*in.SortOrderOpt)
|
||||||
|
update.SetNillableSortOrder(&sortOrder)
|
||||||
|
updated = true
|
||||||
|
} else if in.SortOrder != 0 {
|
||||||
|
sortOrder := int(in.SortOrder)
|
||||||
|
update.SetSortOrder(sortOrder)
|
||||||
|
updated = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if in.IsActiveOpt != nil {
|
||||||
|
update.SetNillableIsActive(in.IsActiveOpt)
|
||||||
|
updated = true
|
||||||
|
} else if in.IsActive {
|
||||||
|
update.SetIsActive(true)
|
||||||
|
updated = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if !updated {
|
||||||
|
return nil, errors.New("no fields to update")
|
||||||
|
}
|
||||||
|
|
||||||
|
update.SetUpdatedAt(time.Now())
|
||||||
|
if err := update.Exec(l.ctx); err != nil {
|
||||||
|
logx.WithContext(l.ctx).Errorf("UpdateGamesLogic err: %v", err)
|
||||||
|
return nil, errors.New("update games failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.UpdateGamesResp{}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Games holds the schema definition for the Games entity.
|
||||||
|
type Games struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fields of the Games.
|
||||||
|
func (Games) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
field.Int64("id").Immutable().Unique(),
|
||||||
|
field.String("name").MaxLen(100).Unique(),
|
||||||
|
field.String("icon"),
|
||||||
|
field.String("category").MaxLen(50),
|
||||||
|
field.Int("sort_order").Default(0),
|
||||||
|
field.Bool("is_active").Optional().Default(true),
|
||||||
|
field.Time("created_at").Default(time.Now).Immutable(),
|
||||||
|
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edges of the Games.
|
||||||
|
func (Games) Edges() []ent.Edge {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
// goctl 1.9.2
|
||||||
|
// Source: game.proto
|
||||||
|
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/game/rpc/internal/logic"
|
||||||
|
"juwan-backend/app/game/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/game/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GamePublicServer struct {
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
pb.UnimplementedGamePublicServer
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGamePublicServer(svcCtx *svc.ServiceContext) *GamePublicServer {
|
||||||
|
return &GamePublicServer{
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------games-----------------------
|
||||||
|
func (s *GamePublicServer) AddGames(ctx context.Context, in *pb.AddGamesReq) (*pb.AddGamesResp, error) {
|
||||||
|
l := logic.NewAddGamesLogic(ctx, s.svcCtx)
|
||||||
|
return l.AddGames(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) UpdateGames(ctx context.Context, in *pb.UpdateGamesReq) (*pb.UpdateGamesResp, error) {
|
||||||
|
l := logic.NewUpdateGamesLogic(ctx, s.svcCtx)
|
||||||
|
return l.UpdateGames(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) DelGames(ctx context.Context, in *pb.DelGamesReq) (*pb.DelGamesResp, error) {
|
||||||
|
l := logic.NewDelGamesLogic(ctx, s.svcCtx)
|
||||||
|
return l.DelGames(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) GetGamesById(ctx context.Context, in *pb.GetGamesByIdReq) (*pb.GetGamesByIdResp, error) {
|
||||||
|
l := logic.NewGetGamesByIdLogic(ctx, s.svcCtx)
|
||||||
|
return l.GetGamesById(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) SearchGames(ctx context.Context, in *pb.SearchGamesReq) (*pb.SearchGamesResp, error) {
|
||||||
|
l := logic.NewSearchGamesLogic(ctx, s.svcCtx)
|
||||||
|
return l.SearchGames(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------playerServices-----------------------
|
||||||
|
func (s *GamePublicServer) AddPlayerServices(ctx context.Context, in *pb.AddPlayerServicesReq) (*pb.AddPlayerServicesResp, error) {
|
||||||
|
l := logic.NewAddPlayerServicesLogic(ctx, s.svcCtx)
|
||||||
|
return l.AddPlayerServices(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) UpdatePlayerServices(ctx context.Context, in *pb.UpdatePlayerServicesReq) (*pb.UpdatePlayerServicesResp, error) {
|
||||||
|
l := logic.NewUpdatePlayerServicesLogic(ctx, s.svcCtx)
|
||||||
|
return l.UpdatePlayerServices(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) DelPlayerServices(ctx context.Context, in *pb.DelPlayerServicesReq) (*pb.DelPlayerServicesResp, error) {
|
||||||
|
l := logic.NewDelPlayerServicesLogic(ctx, s.svcCtx)
|
||||||
|
return l.DelPlayerServices(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) GetPlayerServicesById(ctx context.Context, in *pb.GetPlayerServicesByIdReq) (*pb.GetPlayerServicesByIdResp, error) {
|
||||||
|
l := logic.NewGetPlayerServicesByIdLogic(ctx, s.svcCtx)
|
||||||
|
return l.GetPlayerServicesById(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) SearchPlayerServices(ctx context.Context, in *pb.SearchPlayerServicesReq) (*pb.SearchPlayerServicesResp, error) {
|
||||||
|
l := logic.NewSearchPlayerServicesLogic(ctx, s.svcCtx)
|
||||||
|
return l.SearchPlayerServices(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------players-----------------------
|
||||||
|
func (s *GamePublicServer) AddPlayers(ctx context.Context, in *pb.AddPlayersReq) (*pb.AddPlayersResp, error) {
|
||||||
|
l := logic.NewAddPlayersLogic(ctx, s.svcCtx)
|
||||||
|
return l.AddPlayers(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) UpdatePlayers(ctx context.Context, in *pb.UpdatePlayersReq) (*pb.UpdatePlayersResp, error) {
|
||||||
|
l := logic.NewUpdatePlayersLogic(ctx, s.svcCtx)
|
||||||
|
return l.UpdatePlayers(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) DelPlayers(ctx context.Context, in *pb.DelPlayersReq) (*pb.DelPlayersResp, error) {
|
||||||
|
l := logic.NewDelPlayersLogic(ctx, s.svcCtx)
|
||||||
|
return l.DelPlayers(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) GetPlayersById(ctx context.Context, in *pb.GetPlayersByIdReq) (*pb.GetPlayersByIdResp, error) {
|
||||||
|
l := logic.NewGetPlayersByIdLogic(ctx, s.svcCtx)
|
||||||
|
return l.GetPlayersById(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) SearchPlayers(ctx context.Context, in *pb.SearchPlayersReq) (*pb.SearchPlayersResp, error) {
|
||||||
|
l := logic.NewSearchPlayersLogic(ctx, s.svcCtx)
|
||||||
|
return l.SearchPlayers(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------shopInvitations-----------------------
|
||||||
|
func (s *GamePublicServer) AddShopInvitations(ctx context.Context, in *pb.AddShopInvitationsReq) (*pb.AddShopInvitationsResp, error) {
|
||||||
|
l := logic.NewAddShopInvitationsLogic(ctx, s.svcCtx)
|
||||||
|
return l.AddShopInvitations(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) UpdateShopInvitations(ctx context.Context, in *pb.UpdateShopInvitationsReq) (*pb.UpdateShopInvitationsResp, error) {
|
||||||
|
l := logic.NewUpdateShopInvitationsLogic(ctx, s.svcCtx)
|
||||||
|
return l.UpdateShopInvitations(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) DelShopInvitations(ctx context.Context, in *pb.DelShopInvitationsReq) (*pb.DelShopInvitationsResp, error) {
|
||||||
|
l := logic.NewDelShopInvitationsLogic(ctx, s.svcCtx)
|
||||||
|
return l.DelShopInvitations(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) GetShopInvitationsById(ctx context.Context, in *pb.GetShopInvitationsByIdReq) (*pb.GetShopInvitationsByIdResp, error) {
|
||||||
|
l := logic.NewGetShopInvitationsByIdLogic(ctx, s.svcCtx)
|
||||||
|
return l.GetShopInvitationsById(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) SearchShopInvitations(ctx context.Context, in *pb.SearchShopInvitationsReq) (*pb.SearchShopInvitationsResp, error) {
|
||||||
|
l := logic.NewSearchShopInvitationsLogic(ctx, s.svcCtx)
|
||||||
|
return l.SearchShopInvitations(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------shopPlayers-----------------------
|
||||||
|
func (s *GamePublicServer) AddShopPlayers(ctx context.Context, in *pb.AddShopPlayersReq) (*pb.AddShopPlayersResp, error) {
|
||||||
|
l := logic.NewAddShopPlayersLogic(ctx, s.svcCtx)
|
||||||
|
return l.AddShopPlayers(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) UpdateShopPlayers(ctx context.Context, in *pb.UpdateShopPlayersReq) (*pb.UpdateShopPlayersResp, error) {
|
||||||
|
l := logic.NewUpdateShopPlayersLogic(ctx, s.svcCtx)
|
||||||
|
return l.UpdateShopPlayers(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) DelShopPlayers(ctx context.Context, in *pb.DelShopPlayersReq) (*pb.DelShopPlayersResp, error) {
|
||||||
|
l := logic.NewDelShopPlayersLogic(ctx, s.svcCtx)
|
||||||
|
return l.DelShopPlayers(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) GetShopPlayersById(ctx context.Context, in *pb.GetShopPlayersByIdReq) (*pb.GetShopPlayersByIdResp, error) {
|
||||||
|
l := logic.NewGetShopPlayersByIdLogic(ctx, s.svcCtx)
|
||||||
|
return l.GetShopPlayersById(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) SearchShopPlayers(ctx context.Context, in *pb.SearchShopPlayersReq) (*pb.SearchShopPlayersResp, error) {
|
||||||
|
l := logic.NewSearchShopPlayersLogic(ctx, s.svcCtx)
|
||||||
|
return l.SearchShopPlayers(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------shops-----------------------
|
||||||
|
func (s *GamePublicServer) AddShops(ctx context.Context, in *pb.AddShopsReq) (*pb.AddShopsResp, error) {
|
||||||
|
l := logic.NewAddShopsLogic(ctx, s.svcCtx)
|
||||||
|
return l.AddShops(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) UpdateShops(ctx context.Context, in *pb.UpdateShopsReq) (*pb.UpdateShopsResp, error) {
|
||||||
|
l := logic.NewUpdateShopsLogic(ctx, s.svcCtx)
|
||||||
|
return l.UpdateShops(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) DelShops(ctx context.Context, in *pb.DelShopsReq) (*pb.DelShopsResp, error) {
|
||||||
|
l := logic.NewDelShopsLogic(ctx, s.svcCtx)
|
||||||
|
return l.DelShops(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) GetShopsById(ctx context.Context, in *pb.GetShopsByIdReq) (*pb.GetShopsByIdResp, error) {
|
||||||
|
l := logic.NewGetShopsByIdLogic(ctx, s.svcCtx)
|
||||||
|
return l.GetShopsById(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GamePublicServer) SearchShops(ctx context.Context, in *pb.SearchShopsReq) (*pb.SearchShopsResp, error) {
|
||||||
|
l := logic.NewSearchShopsLogic(ctx, s.svcCtx)
|
||||||
|
return l.SearchShops(in)
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
// goctl 1.9.2
|
||||||
|
// Source: game.proto
|
||||||
|
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/game/rpc/internal/logic"
|
||||||
|
"juwan-backend/app/game/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/game/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PublicServer struct {
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
pb.UnimplementedPublicServer
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPublicServer(svcCtx *svc.ServiceContext) *PublicServer {
|
||||||
|
return &PublicServer{
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------games-----------------------
|
||||||
|
func (s *PublicServer) AddGames(ctx context.Context, in *pb.AddGamesReq) (*pb.AddGamesResp, error) {
|
||||||
|
l := logic.NewAddGamesLogic(ctx, s.svcCtx)
|
||||||
|
return l.AddGames(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublicServer) UpdateGames(ctx context.Context, in *pb.UpdateGamesReq) (*pb.UpdateGamesResp, error) {
|
||||||
|
l := logic.NewUpdateGamesLogic(ctx, s.svcCtx)
|
||||||
|
return l.UpdateGames(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublicServer) DelGames(ctx context.Context, in *pb.DelGamesReq) (*pb.DelGamesResp, error) {
|
||||||
|
l := logic.NewDelGamesLogic(ctx, s.svcCtx)
|
||||||
|
return l.DelGames(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublicServer) GetGamesById(ctx context.Context, in *pb.GetGamesByIdReq) (*pb.GetGamesByIdResp, error) {
|
||||||
|
l := logic.NewGetGamesByIdLogic(ctx, s.svcCtx)
|
||||||
|
return l.GetGamesById(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublicServer) SearchGames(ctx context.Context, in *pb.SearchGamesReq) (*pb.SearchGamesResp, error) {
|
||||||
|
l := logic.NewSearchGamesLogic(ctx, s.svcCtx)
|
||||||
|
return l.SearchGames(in)
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package svc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"juwan-backend/app/game/rpc/internal/config"
|
||||||
|
"juwan-backend/app/game/rpc/internal/models"
|
||||||
|
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||||
|
"juwan-backend/common/redisx"
|
||||||
|
"juwan-backend/common/snowflakex"
|
||||||
|
"juwan-backend/pkg/adapter"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"ariga.io/entcache"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ServiceContext struct {
|
||||||
|
Config config.Config
|
||||||
|
Snowflake snowflake.SnowflakeServiceClient
|
||||||
|
GameModelRW *models.Client
|
||||||
|
GameModelRO *models.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
RWConn, err := sql.Open("pgx", c.DB.Master)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
ROConn, err := sql.Open("pgx", c.DB.Slaves)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
redisCluster, err := redisx.ConnectMasterSlaveCluster(c.CacheConf, 5*time.Second)
|
||||||
|
if redisCluster == nil || err != nil {
|
||||||
|
logx.Errorf("failed to connect to Redis cluster: %v", err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
RWDrv := entcache.NewDriver(RWConn, entcache.TTL(30*time.Second), entcache.Levels(adapter.NewRedisCache(redisCluster.Client)))
|
||||||
|
RODrv := entcache.NewDriver(ROConn, entcache.TTL(30*time.Second), entcache.Levels(adapter.NewRedisCache(redisCluster.Client)))
|
||||||
|
return &ServiceContext{
|
||||||
|
Config: c,
|
||||||
|
GameModelRW: models.NewClient(models.Driver(RWDrv)),
|
||||||
|
GameModelRO: models.NewClient(models.Driver(RODrv)),
|
||||||
|
Snowflake: snowflakex.NewClient(c.SnowflakeRpcConf),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"juwan-backend/app/game/rpc/internal/config"
|
||||||
|
"juwan-backend/app/game/rpc/internal/server"
|
||||||
|
"juwan-backend/app/game/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/game/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/conf"
|
||||||
|
"github.com/zeromicro/go-zero/core/service"
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/reflection"
|
||||||
|
)
|
||||||
|
|
||||||
|
var configFile = flag.String("f", "etc/pb.yaml", "the config file")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
var c config.Config
|
||||||
|
conf.MustLoad(*configFile, &c)
|
||||||
|
ctx := svc.NewServiceContext(c)
|
||||||
|
|
||||||
|
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
||||||
|
pb.RegisterGamePublicServer(grpcServer, server.NewGamePublicServer(ctx))
|
||||||
|
|
||||||
|
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
||||||
|
reflection.Register(grpcServer)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
defer s.Stop()
|
||||||
|
|
||||||
|
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
|
||||||
|
s.Start()
|
||||||
|
}
|
||||||
@@ -0,0 +1,847 @@
|
|||||||
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// protoc-gen-go v1.36.11
|
||||||
|
// protoc v5.29.6
|
||||||
|
// source: game.proto
|
||||||
|
|
||||||
|
package pb
|
||||||
|
|
||||||
|
import (
|
||||||
|
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||||
|
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||||
|
reflect "reflect"
|
||||||
|
sync "sync"
|
||||||
|
unsafe "unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Verify that this generated code is sufficiently up-to-date.
|
||||||
|
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||||
|
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||||
|
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||||
|
)
|
||||||
|
|
||||||
|
// --------------------------------games--------------------------------
|
||||||
|
type Games struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id
|
||||||
|
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` //name
|
||||||
|
Icon string `protobuf:"bytes,3,opt,name=icon,proto3" json:"icon,omitempty"` //icon
|
||||||
|
Category string `protobuf:"bytes,4,opt,name=category,proto3" json:"category,omitempty"` //category
|
||||||
|
SortOrder int64 `protobuf:"varint,5,opt,name=sortOrder,proto3" json:"sortOrder,omitempty"` //sortOrder
|
||||||
|
IsActive bool `protobuf:"varint,6,opt,name=isActive,proto3" json:"isActive,omitempty"` //isActive
|
||||||
|
CreatedAt int64 `protobuf:"varint,7,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt
|
||||||
|
UpdatedAt int64 `protobuf:"varint,8,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Games) Reset() {
|
||||||
|
*x = Games{}
|
||||||
|
mi := &file_game_proto_msgTypes[0]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Games) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Games) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *Games) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_game_proto_msgTypes[0]
|
||||||
|
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 Games.ProtoReflect.Descriptor instead.
|
||||||
|
func (*Games) Descriptor() ([]byte, []int) {
|
||||||
|
return file_game_proto_rawDescGZIP(), []int{0}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Games) GetId() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Games) GetName() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Name
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Games) GetIcon() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Icon
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Games) GetCategory() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Category
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Games) GetSortOrder() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.SortOrder
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Games) GetIsActive() bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.IsActive
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Games) GetCreatedAt() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.CreatedAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Games) GetUpdatedAt() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.UpdatedAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type AddGamesReq struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` //name
|
||||||
|
Icon string `protobuf:"bytes,2,opt,name=icon,proto3" json:"icon,omitempty"` //icon
|
||||||
|
Category string `protobuf:"bytes,3,opt,name=category,proto3" json:"category,omitempty"` //category
|
||||||
|
SortOrder int64 `protobuf:"varint,4,opt,name=sortOrder,proto3" json:"sortOrder,omitempty"` //sortOrder
|
||||||
|
IsActive bool `protobuf:"varint,5,opt,name=isActive,proto3" json:"isActive,omitempty"` //isActive
|
||||||
|
CreatedAt int64 `protobuf:"varint,6,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt
|
||||||
|
UpdatedAt int64 `protobuf:"varint,7,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddGamesReq) Reset() {
|
||||||
|
*x = AddGamesReq{}
|
||||||
|
mi := &file_game_proto_msgTypes[1]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddGamesReq) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*AddGamesReq) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *AddGamesReq) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_game_proto_msgTypes[1]
|
||||||
|
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 AddGamesReq.ProtoReflect.Descriptor instead.
|
||||||
|
func (*AddGamesReq) Descriptor() ([]byte, []int) {
|
||||||
|
return file_game_proto_rawDescGZIP(), []int{1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddGamesReq) GetName() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Name
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddGamesReq) GetIcon() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Icon
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddGamesReq) GetCategory() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Category
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddGamesReq) GetSortOrder() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.SortOrder
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddGamesReq) GetIsActive() bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.IsActive
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddGamesReq) GetCreatedAt() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.CreatedAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddGamesReq) GetUpdatedAt() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.UpdatedAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type AddGamesResp struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddGamesResp) Reset() {
|
||||||
|
*x = AddGamesResp{}
|
||||||
|
mi := &file_game_proto_msgTypes[2]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddGamesResp) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*AddGamesResp) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *AddGamesResp) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_game_proto_msgTypes[2]
|
||||||
|
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 AddGamesResp.ProtoReflect.Descriptor instead.
|
||||||
|
func (*AddGamesResp) Descriptor() ([]byte, []int) {
|
||||||
|
return file_game_proto_rawDescGZIP(), []int{2}
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateGamesReq struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id
|
||||||
|
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` //name
|
||||||
|
Icon string `protobuf:"bytes,3,opt,name=icon,proto3" json:"icon,omitempty"` //icon
|
||||||
|
Category string `protobuf:"bytes,4,opt,name=category,proto3" json:"category,omitempty"` //category
|
||||||
|
SortOrder int64 `protobuf:"varint,5,opt,name=sortOrder,proto3" json:"sortOrder,omitempty"` //sortOrder
|
||||||
|
IsActive bool `protobuf:"varint,6,opt,name=isActive,proto3" json:"isActive,omitempty"` //isActive
|
||||||
|
CreatedAt int64 `protobuf:"varint,7,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt
|
||||||
|
UpdatedAt int64 `protobuf:"varint,8,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateGamesReq) Reset() {
|
||||||
|
*x = UpdateGamesReq{}
|
||||||
|
mi := &file_game_proto_msgTypes[3]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateGamesReq) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*UpdateGamesReq) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *UpdateGamesReq) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_game_proto_msgTypes[3]
|
||||||
|
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 UpdateGamesReq.ProtoReflect.Descriptor instead.
|
||||||
|
func (*UpdateGamesReq) Descriptor() ([]byte, []int) {
|
||||||
|
return file_game_proto_rawDescGZIP(), []int{3}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateGamesReq) GetId() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateGamesReq) GetName() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Name
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateGamesReq) GetIcon() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Icon
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateGamesReq) GetCategory() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Category
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateGamesReq) GetSortOrder() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.SortOrder
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateGamesReq) GetIsActive() bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.IsActive
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateGamesReq) GetCreatedAt() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.CreatedAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateGamesReq) GetUpdatedAt() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.UpdatedAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateGamesResp struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateGamesResp) Reset() {
|
||||||
|
*x = UpdateGamesResp{}
|
||||||
|
mi := &file_game_proto_msgTypes[4]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateGamesResp) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*UpdateGamesResp) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *UpdateGamesResp) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_game_proto_msgTypes[4]
|
||||||
|
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 UpdateGamesResp.ProtoReflect.Descriptor instead.
|
||||||
|
func (*UpdateGamesResp) Descriptor() ([]byte, []int) {
|
||||||
|
return file_game_proto_rawDescGZIP(), []int{4}
|
||||||
|
}
|
||||||
|
|
||||||
|
type DelGamesReq struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DelGamesReq) Reset() {
|
||||||
|
*x = DelGamesReq{}
|
||||||
|
mi := &file_game_proto_msgTypes[5]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DelGamesReq) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*DelGamesReq) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *DelGamesReq) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_game_proto_msgTypes[5]
|
||||||
|
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 DelGamesReq.ProtoReflect.Descriptor instead.
|
||||||
|
func (*DelGamesReq) Descriptor() ([]byte, []int) {
|
||||||
|
return file_game_proto_rawDescGZIP(), []int{5}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DelGamesReq) GetId() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type DelGamesResp struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DelGamesResp) Reset() {
|
||||||
|
*x = DelGamesResp{}
|
||||||
|
mi := &file_game_proto_msgTypes[6]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DelGamesResp) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*DelGamesResp) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *DelGamesResp) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_game_proto_msgTypes[6]
|
||||||
|
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 DelGamesResp.ProtoReflect.Descriptor instead.
|
||||||
|
func (*DelGamesResp) Descriptor() ([]byte, []int) {
|
||||||
|
return file_game_proto_rawDescGZIP(), []int{6}
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetGamesByIdReq struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetGamesByIdReq) Reset() {
|
||||||
|
*x = GetGamesByIdReq{}
|
||||||
|
mi := &file_game_proto_msgTypes[7]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetGamesByIdReq) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*GetGamesByIdReq) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *GetGamesByIdReq) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_game_proto_msgTypes[7]
|
||||||
|
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 GetGamesByIdReq.ProtoReflect.Descriptor instead.
|
||||||
|
func (*GetGamesByIdReq) Descriptor() ([]byte, []int) {
|
||||||
|
return file_game_proto_rawDescGZIP(), []int{7}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetGamesByIdReq) GetId() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetGamesByIdResp struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Games *Games `protobuf:"bytes,1,opt,name=games,proto3" json:"games,omitempty"` //games
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetGamesByIdResp) Reset() {
|
||||||
|
*x = GetGamesByIdResp{}
|
||||||
|
mi := &file_game_proto_msgTypes[8]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetGamesByIdResp) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*GetGamesByIdResp) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *GetGamesByIdResp) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_game_proto_msgTypes[8]
|
||||||
|
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 GetGamesByIdResp.ProtoReflect.Descriptor instead.
|
||||||
|
func (*GetGamesByIdResp) Descriptor() ([]byte, []int) {
|
||||||
|
return file_game_proto_rawDescGZIP(), []int{8}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetGamesByIdResp) GetGames() *Games {
|
||||||
|
if x != nil {
|
||||||
|
return x.Games
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type SearchGamesReq struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Page int64 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"` //page
|
||||||
|
Limit int64 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"` //limit
|
||||||
|
Id int64 `protobuf:"varint,3,opt,name=id,proto3" json:"id,omitempty"` //id
|
||||||
|
Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"` //name
|
||||||
|
Icon string `protobuf:"bytes,5,opt,name=icon,proto3" json:"icon,omitempty"` //icon
|
||||||
|
Category string `protobuf:"bytes,6,opt,name=category,proto3" json:"category,omitempty"` //category
|
||||||
|
SortOrder int64 `protobuf:"varint,7,opt,name=sortOrder,proto3" json:"sortOrder,omitempty"` //sortOrder
|
||||||
|
IsActive bool `protobuf:"varint,8,opt,name=isActive,proto3" json:"isActive,omitempty"` //isActive
|
||||||
|
CreatedAt int64 `protobuf:"varint,9,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt
|
||||||
|
UpdatedAt int64 `protobuf:"varint,10,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchGamesReq) Reset() {
|
||||||
|
*x = SearchGamesReq{}
|
||||||
|
mi := &file_game_proto_msgTypes[9]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchGamesReq) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*SearchGamesReq) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *SearchGamesReq) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_game_proto_msgTypes[9]
|
||||||
|
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 SearchGamesReq.ProtoReflect.Descriptor instead.
|
||||||
|
func (*SearchGamesReq) Descriptor() ([]byte, []int) {
|
||||||
|
return file_game_proto_rawDescGZIP(), []int{9}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchGamesReq) GetPage() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Page
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchGamesReq) GetLimit() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Limit
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchGamesReq) GetId() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchGamesReq) GetName() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Name
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchGamesReq) GetIcon() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Icon
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchGamesReq) GetCategory() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Category
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchGamesReq) GetSortOrder() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.SortOrder
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchGamesReq) GetIsActive() bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.IsActive
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchGamesReq) GetCreatedAt() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.CreatedAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchGamesReq) GetUpdatedAt() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.UpdatedAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type SearchGamesResp struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Games []*Games `protobuf:"bytes,1,rep,name=games,proto3" json:"games,omitempty"` //games
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchGamesResp) Reset() {
|
||||||
|
*x = SearchGamesResp{}
|
||||||
|
mi := &file_game_proto_msgTypes[10]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchGamesResp) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*SearchGamesResp) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *SearchGamesResp) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_game_proto_msgTypes[10]
|
||||||
|
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 SearchGamesResp.ProtoReflect.Descriptor instead.
|
||||||
|
func (*SearchGamesResp) Descriptor() ([]byte, []int) {
|
||||||
|
return file_game_proto_rawDescGZIP(), []int{10}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchGamesResp) GetGames() []*Games {
|
||||||
|
if x != nil {
|
||||||
|
return x.Games
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var File_game_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
|
const file_game_proto_rawDesc = "" +
|
||||||
|
"\n" +
|
||||||
|
"\n" +
|
||||||
|
"game.proto\x12\x02pb\"\xd1\x01\n" +
|
||||||
|
"\x05Games\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x12\n" +
|
||||||
|
"\x04name\x18\x02 \x01(\tR\x04name\x12\x12\n" +
|
||||||
|
"\x04icon\x18\x03 \x01(\tR\x04icon\x12\x1a\n" +
|
||||||
|
"\bcategory\x18\x04 \x01(\tR\bcategory\x12\x1c\n" +
|
||||||
|
"\tsortOrder\x18\x05 \x01(\x03R\tsortOrder\x12\x1a\n" +
|
||||||
|
"\bisActive\x18\x06 \x01(\bR\bisActive\x12\x1c\n" +
|
||||||
|
"\tcreatedAt\x18\a \x01(\x03R\tcreatedAt\x12\x1c\n" +
|
||||||
|
"\tupdatedAt\x18\b \x01(\x03R\tupdatedAt\"\xc7\x01\n" +
|
||||||
|
"\vAddGamesReq\x12\x12\n" +
|
||||||
|
"\x04name\x18\x01 \x01(\tR\x04name\x12\x12\n" +
|
||||||
|
"\x04icon\x18\x02 \x01(\tR\x04icon\x12\x1a\n" +
|
||||||
|
"\bcategory\x18\x03 \x01(\tR\bcategory\x12\x1c\n" +
|
||||||
|
"\tsortOrder\x18\x04 \x01(\x03R\tsortOrder\x12\x1a\n" +
|
||||||
|
"\bisActive\x18\x05 \x01(\bR\bisActive\x12\x1c\n" +
|
||||||
|
"\tcreatedAt\x18\x06 \x01(\x03R\tcreatedAt\x12\x1c\n" +
|
||||||
|
"\tupdatedAt\x18\a \x01(\x03R\tupdatedAt\"\x0e\n" +
|
||||||
|
"\fAddGamesResp\"\xda\x01\n" +
|
||||||
|
"\x0eUpdateGamesReq\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x12\n" +
|
||||||
|
"\x04name\x18\x02 \x01(\tR\x04name\x12\x12\n" +
|
||||||
|
"\x04icon\x18\x03 \x01(\tR\x04icon\x12\x1a\n" +
|
||||||
|
"\bcategory\x18\x04 \x01(\tR\bcategory\x12\x1c\n" +
|
||||||
|
"\tsortOrder\x18\x05 \x01(\x03R\tsortOrder\x12\x1a\n" +
|
||||||
|
"\bisActive\x18\x06 \x01(\bR\bisActive\x12\x1c\n" +
|
||||||
|
"\tcreatedAt\x18\a \x01(\x03R\tcreatedAt\x12\x1c\n" +
|
||||||
|
"\tupdatedAt\x18\b \x01(\x03R\tupdatedAt\"\x11\n" +
|
||||||
|
"\x0fUpdateGamesResp\"\x1d\n" +
|
||||||
|
"\vDelGamesReq\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\x03R\x02id\"\x0e\n" +
|
||||||
|
"\fDelGamesResp\"!\n" +
|
||||||
|
"\x0fGetGamesByIdReq\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\x03R\x02id\"3\n" +
|
||||||
|
"\x10GetGamesByIdResp\x12\x1f\n" +
|
||||||
|
"\x05games\x18\x01 \x01(\v2\t.pb.GamesR\x05games\"\x84\x02\n" +
|
||||||
|
"\x0eSearchGamesReq\x12\x12\n" +
|
||||||
|
"\x04page\x18\x01 \x01(\x03R\x04page\x12\x14\n" +
|
||||||
|
"\x05limit\x18\x02 \x01(\x03R\x05limit\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x03 \x01(\x03R\x02id\x12\x12\n" +
|
||||||
|
"\x04name\x18\x04 \x01(\tR\x04name\x12\x12\n" +
|
||||||
|
"\x04icon\x18\x05 \x01(\tR\x04icon\x12\x1a\n" +
|
||||||
|
"\bcategory\x18\x06 \x01(\tR\bcategory\x12\x1c\n" +
|
||||||
|
"\tsortOrder\x18\a \x01(\x03R\tsortOrder\x12\x1a\n" +
|
||||||
|
"\bisActive\x18\b \x01(\bR\bisActive\x12\x1c\n" +
|
||||||
|
"\tcreatedAt\x18\t \x01(\x03R\tcreatedAt\x12\x1c\n" +
|
||||||
|
"\tupdatedAt\x18\n" +
|
||||||
|
" \x01(\x03R\tupdatedAt\"2\n" +
|
||||||
|
"\x0fSearchGamesResp\x12\x1f\n" +
|
||||||
|
"\x05games\x18\x01 \x03(\v2\t.pb.GamesR\x05games2\x91\x02\n" +
|
||||||
|
"\x06public\x12-\n" +
|
||||||
|
"\bAddGames\x12\x0f.pb.AddGamesReq\x1a\x10.pb.AddGamesResp\x126\n" +
|
||||||
|
"\vUpdateGames\x12\x12.pb.UpdateGamesReq\x1a\x13.pb.UpdateGamesResp\x12-\n" +
|
||||||
|
"\bDelGames\x12\x0f.pb.DelGamesReq\x1a\x10.pb.DelGamesResp\x129\n" +
|
||||||
|
"\fGetGamesById\x12\x13.pb.GetGamesByIdReq\x1a\x14.pb.GetGamesByIdResp\x126\n" +
|
||||||
|
"\vSearchGames\x12\x12.pb.SearchGamesReq\x1a\x13.pb.SearchGamesRespB\x06Z\x04./pbb\x06proto3"
|
||||||
|
|
||||||
|
var (
|
||||||
|
file_game_proto_rawDescOnce sync.Once
|
||||||
|
file_game_proto_rawDescData []byte
|
||||||
|
)
|
||||||
|
|
||||||
|
func file_game_proto_rawDescGZIP() []byte {
|
||||||
|
file_game_proto_rawDescOnce.Do(func() {
|
||||||
|
file_game_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_game_proto_rawDesc), len(file_game_proto_rawDesc)))
|
||||||
|
})
|
||||||
|
return file_game_proto_rawDescData
|
||||||
|
}
|
||||||
|
|
||||||
|
var file_game_proto_msgTypes = make([]protoimpl.MessageInfo, 11)
|
||||||
|
var file_game_proto_goTypes = []any{
|
||||||
|
(*Games)(nil), // 0: pb.Games
|
||||||
|
(*AddGamesReq)(nil), // 1: pb.AddGamesReq
|
||||||
|
(*AddGamesResp)(nil), // 2: pb.AddGamesResp
|
||||||
|
(*UpdateGamesReq)(nil), // 3: pb.UpdateGamesReq
|
||||||
|
(*UpdateGamesResp)(nil), // 4: pb.UpdateGamesResp
|
||||||
|
(*DelGamesReq)(nil), // 5: pb.DelGamesReq
|
||||||
|
(*DelGamesResp)(nil), // 6: pb.DelGamesResp
|
||||||
|
(*GetGamesByIdReq)(nil), // 7: pb.GetGamesByIdReq
|
||||||
|
(*GetGamesByIdResp)(nil), // 8: pb.GetGamesByIdResp
|
||||||
|
(*SearchGamesReq)(nil), // 9: pb.SearchGamesReq
|
||||||
|
(*SearchGamesResp)(nil), // 10: pb.SearchGamesResp
|
||||||
|
}
|
||||||
|
var file_game_proto_depIdxs = []int32{
|
||||||
|
0, // 0: pb.GetGamesByIdResp.games:type_name -> pb.Games
|
||||||
|
0, // 1: pb.SearchGamesResp.games:type_name -> pb.Games
|
||||||
|
1, // 2: pb.public.AddGames:input_type -> pb.AddGamesReq
|
||||||
|
3, // 3: pb.public.UpdateGames:input_type -> pb.UpdateGamesReq
|
||||||
|
5, // 4: pb.public.DelGames:input_type -> pb.DelGamesReq
|
||||||
|
7, // 5: pb.public.GetGamesById:input_type -> pb.GetGamesByIdReq
|
||||||
|
9, // 6: pb.public.SearchGames:input_type -> pb.SearchGamesReq
|
||||||
|
2, // 7: pb.public.AddGames:output_type -> pb.AddGamesResp
|
||||||
|
4, // 8: pb.public.UpdateGames:output_type -> pb.UpdateGamesResp
|
||||||
|
6, // 9: pb.public.DelGames:output_type -> pb.DelGamesResp
|
||||||
|
8, // 10: pb.public.GetGamesById:output_type -> pb.GetGamesByIdResp
|
||||||
|
10, // 11: pb.public.SearchGames:output_type -> pb.SearchGamesResp
|
||||||
|
7, // [7:12] is the sub-list for method output_type
|
||||||
|
2, // [2:7] is the sub-list for method input_type
|
||||||
|
2, // [2:2] is the sub-list for extension type_name
|
||||||
|
2, // [2:2] is the sub-list for extension extendee
|
||||||
|
0, // [0:2] is the sub-list for field type_name
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { file_game_proto_init() }
|
||||||
|
func file_game_proto_init() {
|
||||||
|
if File_game_proto != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
type x struct{}
|
||||||
|
out := protoimpl.TypeBuilder{
|
||||||
|
File: protoimpl.DescBuilder{
|
||||||
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
|
RawDescriptor: unsafe.Slice(unsafe.StringData(file_game_proto_rawDesc), len(file_game_proto_rawDesc)),
|
||||||
|
NumEnums: 0,
|
||||||
|
NumMessages: 11,
|
||||||
|
NumExtensions: 0,
|
||||||
|
NumServices: 1,
|
||||||
|
},
|
||||||
|
GoTypes: file_game_proto_goTypes,
|
||||||
|
DependencyIndexes: file_game_proto_depIdxs,
|
||||||
|
MessageInfos: file_game_proto_msgTypes,
|
||||||
|
}.Build()
|
||||||
|
File_game_proto = out.File
|
||||||
|
file_game_proto_goTypes = nil
|
||||||
|
file_game_proto_depIdxs = nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,275 @@
|
|||||||
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// - protoc-gen-go-grpc v1.6.1
|
||||||
|
// - protoc v5.29.6
|
||||||
|
// source: game.proto
|
||||||
|
|
||||||
|
package pb
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
codes "google.golang.org/grpc/codes"
|
||||||
|
status "google.golang.org/grpc/status"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
// Requires gRPC-Go v1.64.0 or later.
|
||||||
|
const _ = grpc.SupportPackageIsVersion9
|
||||||
|
|
||||||
|
const (
|
||||||
|
Public_AddGames_FullMethodName = "/pb.public/AddGames"
|
||||||
|
Public_UpdateGames_FullMethodName = "/pb.public/UpdateGames"
|
||||||
|
Public_DelGames_FullMethodName = "/pb.public/DelGames"
|
||||||
|
Public_GetGamesById_FullMethodName = "/pb.public/GetGamesById"
|
||||||
|
Public_SearchGames_FullMethodName = "/pb.public/SearchGames"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PublicClient is the client API for Public service.
|
||||||
|
//
|
||||||
|
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||||
|
type PublicClient interface {
|
||||||
|
// -----------------------games-----------------------
|
||||||
|
AddGames(ctx context.Context, in *AddGamesReq, opts ...grpc.CallOption) (*AddGamesResp, error)
|
||||||
|
UpdateGames(ctx context.Context, in *UpdateGamesReq, opts ...grpc.CallOption) (*UpdateGamesResp, error)
|
||||||
|
DelGames(ctx context.Context, in *DelGamesReq, opts ...grpc.CallOption) (*DelGamesResp, error)
|
||||||
|
GetGamesById(ctx context.Context, in *GetGamesByIdReq, opts ...grpc.CallOption) (*GetGamesByIdResp, error)
|
||||||
|
SearchGames(ctx context.Context, in *SearchGamesReq, opts ...grpc.CallOption) (*SearchGamesResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type publicClient struct {
|
||||||
|
cc grpc.ClientConnInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPublicClient(cc grpc.ClientConnInterface) PublicClient {
|
||||||
|
return &publicClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *publicClient) AddGames(ctx context.Context, in *AddGamesReq, opts ...grpc.CallOption) (*AddGamesResp, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(AddGamesResp)
|
||||||
|
err := c.cc.Invoke(ctx, Public_AddGames_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *publicClient) UpdateGames(ctx context.Context, in *UpdateGamesReq, opts ...grpc.CallOption) (*UpdateGamesResp, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(UpdateGamesResp)
|
||||||
|
err := c.cc.Invoke(ctx, Public_UpdateGames_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *publicClient) DelGames(ctx context.Context, in *DelGamesReq, opts ...grpc.CallOption) (*DelGamesResp, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(DelGamesResp)
|
||||||
|
err := c.cc.Invoke(ctx, Public_DelGames_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *publicClient) GetGamesById(ctx context.Context, in *GetGamesByIdReq, opts ...grpc.CallOption) (*GetGamesByIdResp, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(GetGamesByIdResp)
|
||||||
|
err := c.cc.Invoke(ctx, Public_GetGamesById_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *publicClient) SearchGames(ctx context.Context, in *SearchGamesReq, opts ...grpc.CallOption) (*SearchGamesResp, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(SearchGamesResp)
|
||||||
|
err := c.cc.Invoke(ctx, Public_SearchGames_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// PublicServer is the server API for Public service.
|
||||||
|
// All implementations must embed UnimplementedPublicServer
|
||||||
|
// for forward compatibility.
|
||||||
|
type PublicServer interface {
|
||||||
|
// -----------------------games-----------------------
|
||||||
|
AddGames(context.Context, *AddGamesReq) (*AddGamesResp, error)
|
||||||
|
UpdateGames(context.Context, *UpdateGamesReq) (*UpdateGamesResp, error)
|
||||||
|
DelGames(context.Context, *DelGamesReq) (*DelGamesResp, error)
|
||||||
|
GetGamesById(context.Context, *GetGamesByIdReq) (*GetGamesByIdResp, error)
|
||||||
|
SearchGames(context.Context, *SearchGamesReq) (*SearchGamesResp, error)
|
||||||
|
mustEmbedUnimplementedPublicServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnimplementedPublicServer must be embedded to have
|
||||||
|
// forward compatible implementations.
|
||||||
|
//
|
||||||
|
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
||||||
|
// pointer dereference when methods are called.
|
||||||
|
type UnimplementedPublicServer struct{}
|
||||||
|
|
||||||
|
func (UnimplementedPublicServer) AddGames(context.Context, *AddGamesReq) (*AddGamesResp, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method AddGames not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedPublicServer) UpdateGames(context.Context, *UpdateGamesReq) (*UpdateGamesResp, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method UpdateGames not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedPublicServer) DelGames(context.Context, *DelGamesReq) (*DelGamesResp, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method DelGames not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedPublicServer) GetGamesById(context.Context, *GetGamesByIdReq) (*GetGamesByIdResp, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method GetGamesById not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedPublicServer) SearchGames(context.Context, *SearchGamesReq) (*SearchGamesResp, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method SearchGames not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedPublicServer) mustEmbedUnimplementedPublicServer() {}
|
||||||
|
func (UnimplementedPublicServer) testEmbeddedByValue() {}
|
||||||
|
|
||||||
|
// UnsafePublicServer may be embedded to opt out of forward compatibility for this service.
|
||||||
|
// Use of this interface is not recommended, as added methods to PublicServer will
|
||||||
|
// result in compilation errors.
|
||||||
|
type UnsafePublicServer interface {
|
||||||
|
mustEmbedUnimplementedPublicServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterPublicServer(s grpc.ServiceRegistrar, srv PublicServer) {
|
||||||
|
// If the following call panics, it indicates UnimplementedPublicServer was
|
||||||
|
// embedded by pointer and is nil. This will cause panics if an
|
||||||
|
// unimplemented method is ever invoked, so we test this at initialization
|
||||||
|
// time to prevent it from happening at runtime later due to I/O.
|
||||||
|
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
||||||
|
t.testEmbeddedByValue()
|
||||||
|
}
|
||||||
|
s.RegisterService(&Public_ServiceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Public_AddGames_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(AddGamesReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(PublicServer).AddGames(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: Public_AddGames_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(PublicServer).AddGames(ctx, req.(*AddGamesReq))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Public_UpdateGames_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(UpdateGamesReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(PublicServer).UpdateGames(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: Public_UpdateGames_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(PublicServer).UpdateGames(ctx, req.(*UpdateGamesReq))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Public_DelGames_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(DelGamesReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(PublicServer).DelGames(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: Public_DelGames_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(PublicServer).DelGames(ctx, req.(*DelGamesReq))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Public_GetGamesById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(GetGamesByIdReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(PublicServer).GetGamesById(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: Public_GetGamesById_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(PublicServer).GetGamesById(ctx, req.(*GetGamesByIdReq))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Public_SearchGames_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(SearchGamesReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(PublicServer).SearchGames(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: Public_SearchGames_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(PublicServer).SearchGames(ctx, req.(*SearchGamesReq))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Public_ServiceDesc is the grpc.ServiceDesc for Public service.
|
||||||
|
// It's only intended for direct use with grpc.RegisterService,
|
||||||
|
// and not to be introspected or modified (even as a copy)
|
||||||
|
var Public_ServiceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "pb.public",
|
||||||
|
HandlerType: (*PublicServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "AddGames",
|
||||||
|
Handler: _Public_AddGames_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "UpdateGames",
|
||||||
|
Handler: _Public_UpdateGames_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "DelGames",
|
||||||
|
Handler: _Public_DelGames_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "GetGamesById",
|
||||||
|
Handler: _Public_GetGamesById_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "SearchGames",
|
||||||
|
Handler: _Public_SearchGames_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc.StreamDesc{},
|
||||||
|
Metadata: "game.proto",
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
// goctl 1.9.2
|
||||||
|
// Source: game.proto
|
||||||
|
|
||||||
|
package public
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/game/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
AddGamesReq = pb.AddGamesReq
|
||||||
|
AddGamesResp = pb.AddGamesResp
|
||||||
|
DelGamesReq = pb.DelGamesReq
|
||||||
|
DelGamesResp = pb.DelGamesResp
|
||||||
|
Games = pb.Games
|
||||||
|
GetGamesByIdReq = pb.GetGamesByIdReq
|
||||||
|
GetGamesByIdResp = pb.GetGamesByIdResp
|
||||||
|
SearchGamesReq = pb.SearchGamesReq
|
||||||
|
SearchGamesResp = pb.SearchGamesResp
|
||||||
|
UpdateGamesReq = pb.UpdateGamesReq
|
||||||
|
UpdateGamesResp = pb.UpdateGamesResp
|
||||||
|
|
||||||
|
Public interface {
|
||||||
|
// -----------------------games-----------------------
|
||||||
|
AddGames(ctx context.Context, in *AddGamesReq, opts ...grpc.CallOption) (*AddGamesResp, error)
|
||||||
|
UpdateGames(ctx context.Context, in *UpdateGamesReq, opts ...grpc.CallOption) (*UpdateGamesResp, error)
|
||||||
|
DelGames(ctx context.Context, in *DelGamesReq, opts ...grpc.CallOption) (*DelGamesResp, error)
|
||||||
|
GetGamesById(ctx context.Context, in *GetGamesByIdReq, opts ...grpc.CallOption) (*GetGamesByIdResp, error)
|
||||||
|
SearchGames(ctx context.Context, in *SearchGamesReq, opts ...grpc.CallOption) (*SearchGamesResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultPublic struct {
|
||||||
|
cli zrpc.Client
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewPublic(cli zrpc.Client) Public {
|
||||||
|
return &defaultPublic{
|
||||||
|
cli: cli,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------games-----------------------
|
||||||
|
func (m *defaultPublic) AddGames(ctx context.Context, in *AddGamesReq, opts ...grpc.CallOption) (*AddGamesResp, error) {
|
||||||
|
client := pb.NewPublicClient(m.cli.Conn())
|
||||||
|
return client.AddGames(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultPublic) UpdateGames(ctx context.Context, in *UpdateGamesReq, opts ...grpc.CallOption) (*UpdateGamesResp, error) {
|
||||||
|
client := pb.NewPublicClient(m.cli.Conn())
|
||||||
|
return client.UpdateGames(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultPublic) DelGames(ctx context.Context, in *DelGamesReq, opts ...grpc.CallOption) (*DelGamesResp, error) {
|
||||||
|
client := pb.NewPublicClient(m.cli.Conn())
|
||||||
|
return client.DelGames(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultPublic) GetGamesById(ctx context.Context, in *GetGamesByIdReq, opts ...grpc.CallOption) (*GetGamesByIdResp, error) {
|
||||||
|
client := pb.NewPublicClient(m.cli.Conn())
|
||||||
|
return client.GetGamesById(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultPublic) SearchGames(ctx context.Context, in *SearchGamesReq, opts ...grpc.CallOption) (*SearchGamesResp, error) {
|
||||||
|
client := pb.NewPublicClient(m.cli.Conn())
|
||||||
|
return client.SearchGames(ctx, in, opts...)
|
||||||
|
}
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
Name: file-api
|
Name: file-api
|
||||||
Host: 0.0.0.0
|
Host: 0.0.0.0
|
||||||
Port: 8888
|
Port: 8888
|
||||||
|
|
||||||
|
FileRpcConf:
|
||||||
|
Target: k8s://juwan/objectstory-rpc-svc:8080
|
||||||
|
|||||||
@@ -3,11 +3,15 @@
|
|||||||
|
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import "github.com/zeromicro/go-zero/rest"
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
Logger struct {
|
FileRpcConf zrpc.RpcClientConf
|
||||||
|
Logger struct {
|
||||||
AccessSecret string
|
AccessSecret string
|
||||||
AccessExpire int64
|
AccessExpire int64
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ package file
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
"juwan-backend/app/objectstory/api/internal/logic/file"
|
"juwan-backend/app/objectstory/api/internal/logic/file"
|
||||||
"juwan-backend/app/objectstory/api/internal/svc"
|
"juwan-backend/app/objectstory/api/internal/svc"
|
||||||
"juwan-backend/app/objectstory/api/internal/types"
|
"juwan-backend/app/objectstory/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 文件获取接口 (如果是私有文件,通过此接口获取或重定向)
|
// 文件获取接口 (如果是私有文件,通过此接口获取或重定向)
|
||||||
@@ -22,11 +23,11 @@ func GetFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
l := file.NewGetFileLogic(r.Context(), svcCtx)
|
l := file.NewGetFileLogic(r.Context(), svcCtx)
|
||||||
err := l.GetFile(&req)
|
url, err := l.GetFile(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
} else {
|
} else {
|
||||||
httpx.Ok(w)
|
http.Redirect(w, r, url, http.StatusTemporaryRedirect)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ package file
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
"juwan-backend/app/objectstory/api/internal/logic/file"
|
"juwan-backend/app/objectstory/api/internal/logic/file"
|
||||||
"juwan-backend/app/objectstory/api/internal/svc"
|
"juwan-backend/app/objectstory/api/internal/svc"
|
||||||
"juwan-backend/app/objectstory/api/internal/types"
|
"juwan-backend/app/objectstory/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 文件上传接口
|
// 文件上传接口
|
||||||
@@ -22,7 +23,7 @@ func UploadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
l := file.NewUploadLogic(r.Context(), svcCtx)
|
l := file.NewUploadLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.Upload(&req)
|
resp, err := l.Upload(&req, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -5,9 +5,13 @@ package file
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"juwan-backend/app/objectstory/api/internal/svc"
|
"juwan-backend/app/objectstory/api/internal/svc"
|
||||||
"juwan-backend/app/objectstory/api/internal/types"
|
"juwan-backend/app/objectstory/api/internal/types"
|
||||||
|
"juwan-backend/app/objectstory/rpc/fileservice"
|
||||||
|
"juwan-backend/common/utils/contextx"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
@@ -27,8 +31,26 @@ func NewGetFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFileLo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *GetFileLogic) GetFile(req *types.GetFileReq) error {
|
func (l *GetFileLogic) GetFile(req *types.GetFileReq) (string, error) {
|
||||||
// todo: add your logic here and delete this line
|
if req == nil || req.FileId == "" {
|
||||||
|
return "", errors.New("file id is required")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
userID, err := contextx.UserIDFrom(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return "", contextx.ERRILLEGALUSER
|
||||||
|
}
|
||||||
|
|
||||||
|
rpcResp, err := l.svcCtx.FileRpc.GetFileUrl(l.ctx, &fileservice.GetFileUrlReq{
|
||||||
|
FileId: req.FileId,
|
||||||
|
UserId: strconv.FormatInt(userID, 10),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if rpcResp.GetUrl() == "" {
|
||||||
|
return "", errors.New("file url is empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
return rpcResp.GetUrl(), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,15 @@ package file
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"juwan-backend/app/objectstory/api/internal/svc"
|
"juwan-backend/app/objectstory/api/internal/svc"
|
||||||
"juwan-backend/app/objectstory/api/internal/types"
|
"juwan-backend/app/objectstory/api/internal/types"
|
||||||
|
"juwan-backend/app/objectstory/rpc/fileservice"
|
||||||
|
"juwan-backend/common/utils/contextx"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
@@ -27,8 +33,43 @@ func NewUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *UploadLogic) Upload(req *types.UploadReq) (resp *types.UploadResp, err error) {
|
func (l *UploadLogic) Upload(req *types.UploadReq, r *http.Request) (resp *types.UploadResp, err error) {
|
||||||
// todo: add your logic here and delete this line
|
if req == nil {
|
||||||
|
return nil, errors.New("invalid request")
|
||||||
|
}
|
||||||
|
|
||||||
return
|
file, fileHeader, err := r.FormFile("file")
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("file is required")
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
fileData, err := io.ReadAll(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("read file failed")
|
||||||
|
}
|
||||||
|
if len(fileData) == 0 {
|
||||||
|
return nil, errors.New("empty file is not allowed")
|
||||||
|
}
|
||||||
|
|
||||||
|
userID, err := contextx.UserIDFrom(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, contextx.ERRILLEGALUSER
|
||||||
|
}
|
||||||
|
|
||||||
|
rpcResp, err := l.svcCtx.FileRpc.Upload(l.ctx, &fileservice.UploadFileMetadataReq{
|
||||||
|
FileName: fileHeader.Filename,
|
||||||
|
FileSize: fileHeader.Size,
|
||||||
|
FileType: req.Type,
|
||||||
|
UserId: strconv.FormatInt(userID, 10),
|
||||||
|
FileData: fileData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if rpcResp.GetUrl() == "" {
|
||||||
|
return nil, errors.New("upload failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.UploadResp{Url: rpcResp.GetUrl()}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ package middleware
|
|||||||
|
|
||||||
import "net/http"
|
import "net/http"
|
||||||
|
|
||||||
|
const maxUploadSizeBytes int64 = 20 << 20
|
||||||
|
|
||||||
type FileSizeLimitMiddleware struct {
|
type FileSizeLimitMiddleware struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -14,9 +16,10 @@ func NewFileSizeLimitMiddleware() *FileSizeLimitMiddleware {
|
|||||||
|
|
||||||
func (m *FileSizeLimitMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
func (m *FileSizeLimitMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// TODO generate middleware implement function, delete after code implementation
|
if r.Method == http.MethodPost && r.URL != nil && r.URL.Path == "/api/v1/upload" {
|
||||||
|
r.Body = http.MaxBytesReader(w, r.Body, maxUploadSizeBytes)
|
||||||
|
}
|
||||||
|
|
||||||
// Passthrough to next handler if need
|
|
||||||
next(w, r)
|
next(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,19 +4,24 @@
|
|||||||
package svc
|
package svc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/zeromicro/go-zero/rest"
|
|
||||||
"juwan-backend/app/objectstory/api/internal/config"
|
"juwan-backend/app/objectstory/api/internal/config"
|
||||||
"juwan-backend/app/objectstory/api/internal/middleware"
|
"juwan-backend/app/objectstory/api/internal/middleware"
|
||||||
|
"juwan-backend/app/objectstory/rpc/fileservice"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
FileSizeLimit rest.Middleware
|
FileSizeLimit rest.Middleware
|
||||||
|
FileRpc fileservice.FileService
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
FileSizeLimit: middleware.NewFileSizeLimitMiddleware().Handle,
|
FileSizeLimit: middleware.NewFileSizeLimitMiddleware().Handle,
|
||||||
|
FileRpc: fileservice.NewFileService(zrpc.MustNewClient(c.FileRpcConf)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,40 @@
|
|||||||
Name: file.rpc
|
Name: file.rpc
|
||||||
ListenOn: 0.0.0.0:8080
|
ListenOn: 0.0.0.0:8080
|
||||||
Etcd:
|
|
||||||
Hosts:
|
Prometheus:
|
||||||
- 127.0.0.1:2379
|
Host: 0.0.0.0
|
||||||
Key: file.rpc
|
Port: 4001
|
||||||
|
Path: /metrics
|
||||||
|
|
||||||
|
# Target: k8s://juwan/<service name>.<namespace>:8080
|
||||||
|
#S3Conf:
|
||||||
|
# Endpoint: "${S3_ENDPOINT}"
|
||||||
|
# AccessKey: "${S3_ACCESS_KEY}"
|
||||||
|
# SecretKey: "${S3_SECRET_KEY}"
|
||||||
|
# Bucket: "${S3_BUCKET_NAME}"
|
||||||
|
# Region: "${S3_REGION}"
|
||||||
|
|
||||||
|
S3Conf:
|
||||||
|
Endpoint: "https://cn-nb1.rains3.com"
|
||||||
|
AccessKey: "mfgGnaAcUDP2zYAi"
|
||||||
|
SecretKey: "ZfKkbhUvsAchiKlxzIXrDHrSyskyRj"
|
||||||
|
Bucket: "juwan-dev-image-zj"
|
||||||
|
Region: auto
|
||||||
|
UsePathStyle: true
|
||||||
|
|
||||||
|
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
|
||||||
|
|||||||
@@ -1,7 +1,19 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import "github.com/zeromicro/go-zero/zrpc"
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
zrpc.RpcServerConf
|
zrpc.RpcServerConf
|
||||||
|
S3Conf S3ObjectConf
|
||||||
|
}
|
||||||
|
|
||||||
|
type S3ObjectConf struct {
|
||||||
|
AccessKey string
|
||||||
|
SecretKey string
|
||||||
|
Bucket string
|
||||||
|
Endpoint string
|
||||||
|
Region string
|
||||||
|
UsePathStyle bool
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,13 @@ package logic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
"juwan-backend/app/objectstory/rpc/internal/svc"
|
"juwan-backend/app/objectstory/rpc/internal/svc"
|
||||||
"juwan-backend/app/objectstory/rpc/pb"
|
"juwan-backend/app/objectstory/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,7 +28,26 @@ func NewGetFileUrlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFil
|
|||||||
|
|
||||||
// 获取文件访问链接(处理私有文件的鉴权)
|
// 获取文件访问链接(处理私有文件的鉴权)
|
||||||
func (l *GetFileUrlLogic) GetFileUrl(in *pb.GetFileUrlReq) (*pb.GetFileUrlResp, error) {
|
func (l *GetFileUrlLogic) GetFileUrl(in *pb.GetFileUrlReq) (*pb.GetFileUrlResp, error) {
|
||||||
// todo: add your logic here and delete this line
|
if in == nil || in.GetFileId() == "" {
|
||||||
|
return nil, errors.New("file id is required")
|
||||||
|
}
|
||||||
|
|
||||||
return &pb.GetFileUrlResp{}, nil
|
_, err := l.svcCtx.S3.HeadObject(l.ctx, &s3.HeadObjectInput{
|
||||||
|
Bucket: &l.svcCtx.Config.S3Conf.Bucket,
|
||||||
|
Key: &in.FileId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
presignClient := s3.NewPresignClient(l.svcCtx.S3)
|
||||||
|
presigned, err := presignClient.PresignGetObject(l.ctx, &s3.GetObjectInput{
|
||||||
|
Bucket: &l.svcCtx.Config.S3Conf.Bucket,
|
||||||
|
Key: &in.FileId,
|
||||||
|
}, s3.WithPresignExpires(15*time.Minute))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.GetFileUrlResp{Url: presigned.URL}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,19 @@
|
|||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"juwan-backend/app/objectstory/rpc/internal/svc"
|
"juwan-backend/app/objectstory/rpc/internal/svc"
|
||||||
"juwan-backend/app/objectstory/rpc/pb"
|
"juwan-backend/app/objectstory/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,7 +33,40 @@ func NewUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogi
|
|||||||
|
|
||||||
// 简单上传(适合小文件,或保存元数据)
|
// 简单上传(适合小文件,或保存元数据)
|
||||||
func (l *UploadLogic) Upload(in *pb.UploadFileMetadataReq) (*pb.UploadFileResp, error) {
|
func (l *UploadLogic) Upload(in *pb.UploadFileMetadataReq) (*pb.UploadFileResp, error) {
|
||||||
// todo: add your logic here and delete this line
|
if in == nil {
|
||||||
|
return nil, errors.New("invalid request")
|
||||||
|
}
|
||||||
|
if len(in.GetFileData()) == 0 {
|
||||||
|
return nil, errors.New("file data is required")
|
||||||
|
}
|
||||||
|
if in.GetFileName() == "" {
|
||||||
|
return nil, errors.New("file name is required")
|
||||||
|
}
|
||||||
|
if in.GetFileType() == "" {
|
||||||
|
return nil, errors.New("file type is required")
|
||||||
|
}
|
||||||
|
|
||||||
return &pb.UploadFileResp{}, nil
|
fileID := uuid.NewString()
|
||||||
|
ext := strings.ToLower(filepath.Ext(in.GetFileName()))
|
||||||
|
if len(ext) > 10 {
|
||||||
|
ext = ""
|
||||||
|
}
|
||||||
|
objectKey := fmt.Sprintf("%s/%s/%s%s", in.GetFileType(), in.GetUserId(), fileID, ext)
|
||||||
|
|
||||||
|
_, err := l.svcCtx.S3.PutObject(l.ctx, &s3.PutObjectInput{
|
||||||
|
Bucket: &l.svcCtx.Config.S3Conf.Bucket,
|
||||||
|
Key: &objectKey,
|
||||||
|
Body: bytes.NewReader(in.GetFileData()),
|
||||||
|
ContentLength: aws.Int64(int64(len(in.GetFileData()))),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
url := strings.TrimRight(l.svcCtx.Config.S3Conf.Endpoint, "/") + "/" + l.svcCtx.Config.S3Conf.Bucket + "/" + objectKey
|
||||||
|
|
||||||
|
return &pb.UploadFileResp{
|
||||||
|
Url: url,
|
||||||
|
FileId: objectKey,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package svc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/objectstory/rpc/internal/config"
|
||||||
|
|
||||||
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
|
awsConfig "github.com/aws/aws-sdk-go-v2/config"
|
||||||
|
"github.com/aws/aws-sdk-go-v2/credentials"
|
||||||
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ObjectStorageSvc struct {
|
||||||
|
c config.S3ObjectConf
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewObjectStorage(c config.S3ObjectConf) *ObjectStorageSvc {
|
||||||
|
return &ObjectStorageSvc{
|
||||||
|
c: c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ObjectStorageSvc) MustNews3Client(ctx context.Context) *s3.Client {
|
||||||
|
awsCfg, err := awsConfig.LoadDefaultConfig(ctx,
|
||||||
|
awsConfig.WithRegion(s.c.Region),
|
||||||
|
awsConfig.WithCredentialsProvider(
|
||||||
|
credentials.NewStaticCredentialsProvider(
|
||||||
|
s.c.AccessKey,
|
||||||
|
s.c.SecretKey,
|
||||||
|
"",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return s3.NewFromConfig(awsCfg, func(o *s3.Options) {
|
||||||
|
o.BaseEndpoint = aws.String(s.c.Endpoint)
|
||||||
|
o.UsePathStyle = s.c.UsePathStyle
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -1,13 +1,22 @@
|
|||||||
package svc
|
package svc
|
||||||
|
|
||||||
import "juwan-backend/app/objectstory/rpc/internal/config"
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/objectstory/rpc/internal/config"
|
||||||
|
|
||||||
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
|
S3 *s3.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
s3obj := NewObjectStorage(c.S3Conf)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
S3: s3obj.MustNews3Client(context.Background()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 v5.29.6
|
// protoc v3.19.4
|
||||||
// source: objectstory.proto
|
// source: objectstory.proto
|
||||||
|
|
||||||
package pb
|
package pb
|
||||||
|
|||||||
@@ -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 v5.29.6
|
// - protoc v3.19.4
|
||||||
// source: objectstory.proto
|
// source: objectstory.proto
|
||||||
|
|
||||||
package pb
|
package pb
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
Name: juwan-api
|
||||||
|
Host: 0.0.0.0
|
||||||
|
Port: 8888
|
||||||
|
|
||||||
|
Prometheus:
|
||||||
|
Host: 0.0.0.0
|
||||||
|
Port: 4001
|
||||||
|
Path: /metrics
|
||||||
|
|
||||||
|
# k8s://juwan/<service name>:8080
|
||||||
|
PlayerRpcConf:
|
||||||
|
Target: k8s://juwan/player-rpc-svc:8080
|
||||||
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
rest.RestConf
|
||||||
|
PlayerRpcConf zrpc.RpcClientConf
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/player/api/internal/logic/player"
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 创建服务
|
||||||
|
func CreateServiceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.CreateServiceReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := player.NewCreateServiceLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.CreateService(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/player/api/internal/logic/player"
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 删除服务
|
||||||
|
func DeleteServiceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.EmptyResp
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := player.NewDeleteServiceLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.DeleteService(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/player/api/internal/logic/player"
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 获取打手详情
|
||||||
|
func GetPlayerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.EmptyResp
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := player.NewGetPlayerLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.GetPlayer(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/player/api/internal/logic/player"
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 获取服务详情
|
||||||
|
func GetServiceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.EmptyResp
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := player.NewGetServiceLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.GetService(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/player/api/internal/logic/player"
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 获取指定打手的服务列表
|
||||||
|
func ListPlayerServicesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.PageReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := player.NewListPlayerServicesLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.ListPlayerServices(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/player/api/internal/logic/player"
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 获取打手列表
|
||||||
|
func ListPlayersHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.PlayerListReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := player.NewListPlayersLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.ListPlayers(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/player/api/internal/logic/player"
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 获取所有服务列表
|
||||||
|
func ListServicesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.PageReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := player.NewListServicesLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.ListServices(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/player/api/internal/logic/player"
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 更新接单状态
|
||||||
|
func UpdatePlayerStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.UpdatePlayerStatusReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := player.NewUpdatePlayerStatusLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.UpdatePlayerStatus(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/player/api/internal/logic/player"
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 更新服务
|
||||||
|
func UpdateServiceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.CreateServiceReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := player.NewUpdateServiceLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.UpdateService(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
player "juwan-backend/app/player/api/internal/handler/player"
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
|
server.AddRoutes(
|
||||||
|
[]rest.Route{
|
||||||
|
{
|
||||||
|
// 获取打手列表
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/players",
|
||||||
|
Handler: player.ListPlayersHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 获取打手详情
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/players/:id",
|
||||||
|
Handler: player.GetPlayerHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 获取指定打手的服务列表
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/players/:id/services",
|
||||||
|
Handler: player.ListPlayerServicesHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 获取所有服务列表
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/services",
|
||||||
|
Handler: player.ListServicesHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 获取服务详情
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/services/:id",
|
||||||
|
Handler: player.GetServiceHandler(serverCtx),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rest.WithPrefix("/api/v1"),
|
||||||
|
)
|
||||||
|
|
||||||
|
server.AddRoutes(
|
||||||
|
[]rest.Route{
|
||||||
|
{
|
||||||
|
// 更新接单状态
|
||||||
|
Method: http.MethodPut,
|
||||||
|
Path: "/players/me/status",
|
||||||
|
Handler: player.UpdatePlayerStatusHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 创建服务
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/services",
|
||||||
|
Handler: player.CreateServiceHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 更新服务
|
||||||
|
Method: http.MethodPut,
|
||||||
|
Path: "/services/:id",
|
||||||
|
Handler: player.UpdateServiceHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 删除服务
|
||||||
|
Method: http.MethodDelete,
|
||||||
|
Path: "/services/:id",
|
||||||
|
Handler: player.DeleteServiceHandler(serverCtx),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rest.WithPrefix("/api/v1"),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/player/rpc/playerservice"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CreateServiceLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建服务
|
||||||
|
func NewCreateServiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateServiceLogic {
|
||||||
|
return &CreateServiceLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *CreateServiceLogic) CreateService(req *types.CreateServiceReq) (resp *types.PlayerService, err error) {
|
||||||
|
_, err = l.svcCtx.PlayerRpc.AddPlayerServices(l.ctx, &playerservice.AddPlayerServicesReq{
|
||||||
|
|
||||||
|
GameId: req.GameId,
|
||||||
|
Title: req.Title,
|
||||||
|
Description: req.Description,
|
||||||
|
Price: req.Price,
|
||||||
|
Unit: req.Unit,
|
||||||
|
RankRange: req.RankRange,
|
||||||
|
Availability: req.Availability,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("failed to create player service: " + err.Error())
|
||||||
|
return nil, errors.New("failed to create player service")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/player/rpc/playerservice"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DeleteServiceLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除服务
|
||||||
|
func NewDeleteServiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteServiceLogic {
|
||||||
|
return &DeleteServiceLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *DeleteServiceLogic) DeleteService(req *types.DeleteServiceReq) (resp *types.EmptyResp, err error) {
|
||||||
|
_, err = l.svcCtx.PlayerRpc.DelPlayerServices(l.ctx, &playerservice.DelPlayerServicesReq{
|
||||||
|
Id: req.Id,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("DeleteServiceLogic.DeleteService err:%v", err)
|
||||||
|
return nil, errors.New("failed to delete player service")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/player/rpc/playerservice"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetPlayerLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取打手详情
|
||||||
|
func NewGetPlayerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPlayerLogic {
|
||||||
|
return &GetPlayerLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetPlayerLogic) GetPlayer(req *types.GetPlayerReq) (resp *types.PlayerProfile, err error) {
|
||||||
|
player, err := l.svcCtx.PlayerRpc.GetPlayersById(l.ctx, &playerservice.GetPlayersByIdReq{
|
||||||
|
Id: req.Id,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("GetPlayerLogic.GetPlayers err: %v", err)
|
||||||
|
return nil, errors.New("failed to get player details")
|
||||||
|
}
|
||||||
|
err = copier.Copy(resp, &player)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("copier.Copy err: %v", err)
|
||||||
|
return nil, errors.New("copier.Copy err")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/player/rpc/playerservice"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetServiceLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取服务详情
|
||||||
|
func NewGetServiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetServiceLogic {
|
||||||
|
return &GetServiceLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetServiceLogic) GetService(req *types.GetServiceReq) (resp *types.PlayerService, err error) {
|
||||||
|
s, err := l.svcCtx.PlayerRpc.GetPlayerServicesById(l.ctx, &playerservice.GetPlayerServicesByIdReq{
|
||||||
|
Id: req.Id,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("GetServiceLogic.GetService err: %v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = copier.Copy(resp, &s)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("GetServiceLogic.GetService err: %v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/player/rpc/playerservice"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ListPlayerServicesLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取指定打手的服务列表
|
||||||
|
func NewListPlayerServicesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListPlayerServicesLogic {
|
||||||
|
return &ListPlayerServicesLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListPlayerServicesLogic) ListPlayerServices(req *types.ListPlayerServicesReq) (resp *types.PlayerServiceListResp, err error) {
|
||||||
|
resp = &types.PlayerServiceListResp{}
|
||||||
|
s, err := l.svcCtx.PlayerRpc.SearchPlayerServices(l.ctx, &playerservice.SearchPlayerServicesReq{
|
||||||
|
Page: req.Offset,
|
||||||
|
Limit: req.Limit,
|
||||||
|
PlayerId: req.Id,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, v := range s.PlayerServices {
|
||||||
|
temp := types.PlayerService{}
|
||||||
|
err = copier.Copy(&temp, &v)
|
||||||
|
if err == nil {
|
||||||
|
logx.Errorf("ListPlayerServicesLogic.ListPlayerServices copier.Copy err: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
resp.Items = append(resp.Items, temp)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/player/rpc/pb"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ListPlayersLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取打手列表
|
||||||
|
func NewListPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListPlayersLogic {
|
||||||
|
return &ListPlayersLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListPlayersLogic) ListPlayers(req *types.PlayerListReq) (resp *types.PlayerListResp, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
p, err := l.svcCtx.PlayerRpc.SearchPlayers(l.ctx, &pb.SearchPlayersReq{
|
||||||
|
Page: req.Offset,
|
||||||
|
Limit: req.Limit,
|
||||||
|
Gender: int64(req.Gender),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
list := make([]types.PlayerProfile, 0, len(p.Players))
|
||||||
|
for _, v := range p.Players {
|
||||||
|
temp := types.PlayerProfile{}
|
||||||
|
err = copier.Copy(&temp, &v)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("ListPlayersLogic.ListPlayers copier.Copy err: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
list = append(list, temp)
|
||||||
|
}
|
||||||
|
resp = &types.PlayerListResp{}
|
||||||
|
resp.Items = list
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/player/rpc/playerservice"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ListServicesLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取所有服务列表
|
||||||
|
func NewListServicesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListServicesLogic {
|
||||||
|
return &ListServicesLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListServicesLogic) ListServices(req *types.PageReq) (resp *types.PlayerServiceListResp, err error) {
|
||||||
|
resp = &types.PlayerServiceListResp{}
|
||||||
|
s, err := l.svcCtx.PlayerRpc.SearchPlayerServices(l.ctx, &playerservice.SearchPlayerServicesReq{
|
||||||
|
Page: req.Offset,
|
||||||
|
Limit: req.Limit,
|
||||||
|
PlayerId: 0,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, v := range s.PlayerServices {
|
||||||
|
temp := types.PlayerService{}
|
||||||
|
err = copier.Copy(&temp, &v)
|
||||||
|
if err == nil {
|
||||||
|
logx.Errorf("ListPlayerServicesLogic.ListPlayerServices copier.Copy err: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
resp.Items = append(resp.Items, temp)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/player/rpc/pb"
|
||||||
|
"juwan-backend/common/utils/contextx"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdatePlayerStatusLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新接单状态
|
||||||
|
func NewUpdatePlayerStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePlayerStatusLogic {
|
||||||
|
return &UpdatePlayerStatusLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *UpdatePlayerStatusLogic) UpdatePlayerStatus(req *types.UpdatePlayerStatusReq) (resp *types.EmptyResp, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
userId, err := contextx.UserIDFrom(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, err = l.svcCtx.PlayerRpc.UpdatePlayers(l.ctx, &pb.UpdatePlayersReq{
|
||||||
|
Id: userId,
|
||||||
|
Status: &req.Status,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/player/rpc/pb"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
"juwan-backend/app/player/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdateServiceLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新服务
|
||||||
|
func NewUpdateServiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateServiceLogic {
|
||||||
|
return &UpdateServiceLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *UpdateServiceLogic) UpdateService(req *types.UpdateServiceReq) (resp *types.PlayerService, err error) {
|
||||||
|
_, err = l.svcCtx.PlayerRpc.UpdatePlayerServices(l.ctx, &pb.UpdatePlayerServicesReq{
|
||||||
|
Id: req.Id,
|
||||||
|
GameId: req.GameId,
|
||||||
|
Title: req.Title,
|
||||||
|
Description: req.Description,
|
||||||
|
Price: req.Price,
|
||||||
|
Unit: req.Unit,
|
||||||
|
RankRange: req.RankRange,
|
||||||
|
Availability: req.Availability,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package svc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"juwan-backend/app/player/api/internal/config"
|
||||||
|
"juwan-backend/app/player/rpc/playerservice"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ServiceContext struct {
|
||||||
|
Config config.Config
|
||||||
|
PlayerRpc playerservice.PlayerService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
return &ServiceContext{
|
||||||
|
Config: c,
|
||||||
|
PlayerRpc: playerservice.NewPlayerService(zrpc.MustNewClient(c.PlayerRpcConf)),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
type CreateServiceReq struct {
|
||||||
|
Id int64 `path:"id"`
|
||||||
|
GameId int64 `json:"gameId, optional"`
|
||||||
|
Title string `json:"title,optional"`
|
||||||
|
Description string `json:"description,optional"`
|
||||||
|
Price float64 `json:"price"`
|
||||||
|
Unit string `json:"unit"`
|
||||||
|
RankRange string `json:"rankRange,optional"`
|
||||||
|
Availability []string `json:"availability,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteServiceReq struct {
|
||||||
|
Id int64 `path:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type EmptyResp struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetPlayerReq struct {
|
||||||
|
Id int64 `path:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetServiceReq struct {
|
||||||
|
Id int64 `path:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListPlayerServicesReq struct {
|
||||||
|
PageReq
|
||||||
|
Id int64 `path:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PageMeta struct {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
Offset int64 `json:"offset"`
|
||||||
|
Limit int64 `json:"limit"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PageReq struct {
|
||||||
|
Offset int64 `form:"offset,default=0"`
|
||||||
|
Limit int64 `form:"limit,default=20"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PlayerListReq struct {
|
||||||
|
PageReq
|
||||||
|
GameId int64 `form:"gameId,optional"`
|
||||||
|
Gender int `form:"gender,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PlayerListResp struct {
|
||||||
|
Items []PlayerProfile `json:"items"`
|
||||||
|
Meta PageMeta `json:"meta"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PlayerProfile struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
User UserProfile `json:"user"`
|
||||||
|
Rating float64 `json:"rating"`
|
||||||
|
TotalOrders int64 `json:"totalOrders"`
|
||||||
|
CompletionRate float64 `json:"completionRate"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Games []string `json:"games"`
|
||||||
|
Services []PlayerService `json:"services"`
|
||||||
|
ShopId string `json:"shopId,optional"`
|
||||||
|
ShopName string `json:"shopName,optional"`
|
||||||
|
Tags []string `json:"tags"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PlayerService struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
PlayerId int64 `json:"playerId"`
|
||||||
|
GameId int64 `json:"gameId"`
|
||||||
|
GameName string `json:"gameName"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Price float64 `json:"price"`
|
||||||
|
Unit string `json:"unit"`
|
||||||
|
RankRange string `json:"rankRange,optional"`
|
||||||
|
Availability []string `json:"availability"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PlayerServiceListResp struct {
|
||||||
|
Items []PlayerService `json:"items"`
|
||||||
|
Meta PageMeta `json:"meta"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SimpleUser struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Nickname string `json:"nickname"`
|
||||||
|
Avatar string `json:"avatar"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdatePlayerStatusReq struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateServiceReq struct {
|
||||||
|
Id int64 `path:"id"`
|
||||||
|
GameId *int64 `json:"gameId, optional"`
|
||||||
|
Title *string `json:"title,optional"`
|
||||||
|
Description *string `json:"description,optional"`
|
||||||
|
Price *float64 `json:"price,optional"`
|
||||||
|
Unit *string `json:"unit,optional"`
|
||||||
|
RankRange *string `json:"rankRange,optional"`
|
||||||
|
Availability []string `json:"availability"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserProfile struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
Nickname string `json:"nickname"`
|
||||||
|
Avatar string `json:"avatar"`
|
||||||
|
Role string `json:"role"` // consumer, player, owner, admin
|
||||||
|
VerifiedRoles []string `json:"verifiedRoles"`
|
||||||
|
VerificationStatus map[string]string `json:"verificationStatus"`
|
||||||
|
Phone string `json:"phone,optional"`
|
||||||
|
Bio string `json:"bio,optional"`
|
||||||
|
CreatedAt string `json:"createdAt"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/api/internal/config"
|
||||||
|
"juwan-backend/app/player/api/internal/handler"
|
||||||
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/conf"
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
|
var configFile = flag.String("f", "etc/juwan-api.yaml", "the config file")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
var c config.Config
|
||||||
|
conf.MustLoad(*configFile, &c)
|
||||||
|
|
||||||
|
server := rest.MustNewServer(c.RestConf)
|
||||||
|
defer server.Stop()
|
||||||
|
|
||||||
|
ctx := svc.NewServiceContext(c)
|
||||||
|
handler.RegisterHandlers(server, ctx)
|
||||||
|
|
||||||
|
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||||
|
server.Start()
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
Name: pb.rpc
|
||||||
|
ListenOn: 0.0.0.0:8080
|
||||||
|
|
||||||
|
|
||||||
|
Prometheus:
|
||||||
|
Host: 0.0.0.0
|
||||||
|
Port: 4001
|
||||||
|
Path: /metrics
|
||||||
|
|
||||||
|
# tcd:
|
||||||
|
# Hosts:
|
||||||
|
# - 127.0.0.1:2379
|
||||||
|
# Key: pb.rpc
|
||||||
|
|
||||||
|
# Target: k8s://juwan/<service name>.<namespace>:8080
|
||||||
|
|
||||||
|
|
||||||
|
SnowflakeRpcConf:
|
||||||
|
Target: k8s://juwan/snowflake-svc:8080
|
||||||
|
|
||||||
|
|
||||||
|
DB:
|
||||||
|
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
Slave: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-ro.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
|
||||||
|
|
||||||
|
CacheConf:
|
||||||
|
- Host: "${REDIS_M_HOST}"
|
||||||
|
Type: node
|
||||||
|
Pass: "${REDIS_PASSWORD}"
|
||||||
|
User: "default"
|
||||||
|
- Host: "${REDIS_S_HOST}"
|
||||||
|
Type: node
|
||||||
|
Pass: "${REDIS_PASSWORD}"
|
||||||
|
User: "default"
|
||||||
|
|
||||||
|
Log:
|
||||||
|
Level: info
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
zrpc.RpcServerConf
|
||||||
|
|
||||||
|
SnowflakeRpcConf zrpc.RpcClientConf
|
||||||
|
DB struct {
|
||||||
|
Master string
|
||||||
|
Slaves string
|
||||||
|
}
|
||||||
|
CacheConf cache.CacheConf
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/player/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/player/rpc/pb"
|
||||||
|
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||||
|
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AddPlayerServicesLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAddPlayerServicesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddPlayerServicesLogic {
|
||||||
|
return &AddPlayerServicesLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------playerServices-----------------------
|
||||||
|
func (l *AddPlayerServicesLogic) AddPlayerServices(in *pb.AddPlayerServicesReq) (*pb.AddPlayerServicesResp, error) {
|
||||||
|
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("addPlayerServices err:%v", err)
|
||||||
|
return nil, errors.New("create player service id failed")
|
||||||
|
}
|
||||||
|
_, err = l.svcCtx.PlayerModelRW.PlayerServices.Create().
|
||||||
|
SetID(idResp.Id).
|
||||||
|
SetPlayerID(in.PlayerId).
|
||||||
|
SetGameID(in.GameId).
|
||||||
|
SetTitle(in.Title).
|
||||||
|
SetDescription(in.Description).
|
||||||
|
SetPrice(decimal.NewFromFloat(in.Price)).
|
||||||
|
SetUnit(in.Unit).
|
||||||
|
SetRankRange(in.RankRange).
|
||||||
|
SetAvailability(in.Availability).
|
||||||
|
SetRating(decimal.NewFromFloat(in.Rating)).
|
||||||
|
SetIsActive(in.IsActive).
|
||||||
|
Save(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("addPlayerServices err:%v", err)
|
||||||
|
return nil, errors.New("add player service failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.AddPlayerServicesResp{}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/player/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AddPlayersLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAddPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddPlayersLogic {
|
||||||
|
return &AddPlayersLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------players-----------------------
|
||||||
|
func (l *AddPlayersLogic) AddPlayers(in *pb.AddPlayersReq) (*pb.AddPlayersResp, error) {
|
||||||
|
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("addPlayerServices err:%v", err)
|
||||||
|
return nil, errors.New("create player service id failed")
|
||||||
|
}
|
||||||
|
gender := 0
|
||||||
|
if in.Gender != 0 {
|
||||||
|
gender = 1
|
||||||
|
}
|
||||||
|
_, err = l.svcCtx.PlayerModelRW.Players.Create().
|
||||||
|
SetID(idResp.Id).
|
||||||
|
SetUserID(in.UserId).
|
||||||
|
SetStatus(in.Status).
|
||||||
|
SetRating(decimal.NewFromFloat(in.Rating)).
|
||||||
|
SetTotalOrders(int(in.TotalOrders)).
|
||||||
|
SetCompletedOrders(int(in.CompletedOrders)).
|
||||||
|
SetShopID(in.ShopId).
|
||||||
|
SetTags(in.Tags).
|
||||||
|
SetGender(gender).
|
||||||
|
SetGames(in.Games).
|
||||||
|
Save(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("addPlayerServices err:%v", err)
|
||||||
|
return nil, errors.New("add player service failed")
|
||||||
|
}
|
||||||
|
return &pb.AddPlayersResp{}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/player/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DelPlayerServicesLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDelPlayerServicesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelPlayerServicesLogic {
|
||||||
|
return &DelPlayerServicesLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *DelPlayerServicesLogic) DelPlayerServices(in *pb.DelPlayerServicesReq) (*pb.DelPlayerServicesResp, error) {
|
||||||
|
err := l.svcCtx.PlayerModelRW.PlayerServices.DeleteOneID(in.Id).Exec(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("delete player services failed, %s", err.Error())
|
||||||
|
return nil, errors.New("delete failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.DelPlayerServicesResp{}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/player/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DelPlayersLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDelPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelPlayersLogic {
|
||||||
|
return &DelPlayersLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *DelPlayersLogic) DelPlayers(in *pb.DelPlayersReq) (*pb.DelPlayersResp, error) {
|
||||||
|
err := l.svcCtx.PlayerModelRW.Players.DeleteOneID(in.Id).Exec(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("delete player services failed, %s", err.Error())
|
||||||
|
return nil, errors.New("delete failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.DelPlayersResp{}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/playerservices"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/player/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetPlayerServicesByIdLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetPlayerServicesByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPlayerServicesByIdLogic {
|
||||||
|
return &GetPlayerServicesByIdLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetPlayerServicesByIdLogic) GetPlayerServicesById(in *pb.GetPlayerServicesByIdReq) (*pb.GetPlayerServicesByIdResp, error) {
|
||||||
|
playerService, err := l.svcCtx.PlayerModelRO.PlayerServices.Query().Where(playerservices.IDEQ(in.Id)).First(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.WithContext(l.ctx).Errorf("GetPlayerServicesByIdLogic err: %v", err)
|
||||||
|
return nil, errors.New("get player services by id failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
pbPlayerService := pb.PlayerServices{
|
||||||
|
Id: playerService.ID,
|
||||||
|
PlayerId: playerService.PlayerID,
|
||||||
|
GameId: playerService.GameID,
|
||||||
|
Title: playerService.Title,
|
||||||
|
Price: playerService.Price.InexactFloat64(),
|
||||||
|
Unit: playerService.Unit,
|
||||||
|
Availability: playerService.Availability,
|
||||||
|
Rating: playerService.Rating.InexactFloat64(),
|
||||||
|
IsActive: playerService.IsActive,
|
||||||
|
CreatedAt: playerService.CreatedAt.Unix(),
|
||||||
|
UpdatedAt: playerService.UpdatedAt.Unix(),
|
||||||
|
}
|
||||||
|
if playerService.Description != nil {
|
||||||
|
pbPlayerService.Description = *playerService.Description
|
||||||
|
}
|
||||||
|
if playerService.RankRange != nil {
|
||||||
|
pbPlayerService.RankRange = *playerService.RankRange
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.GetPlayerServicesByIdResp{PlayerServices: &pbPlayerService}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/players"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/player/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetPlayersByIdLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetPlayersByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPlayersByIdLogic {
|
||||||
|
return &GetPlayersByIdLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetPlayersByIdLogic) GetPlayersById(in *pb.GetPlayersByIdReq) (*pb.GetPlayersByIdResp, error) {
|
||||||
|
player, err := l.svcCtx.PlayerModelRO.Players.Query().Where(players.IDEQ(in.Id)).First(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.WithContext(l.ctx).Errorf("GetPlayersByIdLogic err: %v", err)
|
||||||
|
return nil, errors.New("get players by id failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
pbPlayer := pb.Players{
|
||||||
|
Id: player.ID,
|
||||||
|
UserId: player.UserID,
|
||||||
|
Status: player.Status,
|
||||||
|
Rating: player.Rating.InexactFloat64(),
|
||||||
|
TotalOrders: int64(player.TotalOrders),
|
||||||
|
CompletedOrders: int64(player.CompletedOrders),
|
||||||
|
Tags: player.Tags,
|
||||||
|
Games: []int64(player.Games),
|
||||||
|
CreatedAt: player.CreatedAt.Unix(),
|
||||||
|
UpdatedAt: player.UpdatedAt.Unix(),
|
||||||
|
}
|
||||||
|
if player.ShopID != nil {
|
||||||
|
pbPlayer.ShopId = *player.ShopID
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.GetPlayersByIdResp{Players: &pbPlayer}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/playerservices"
|
||||||
|
"juwan-backend/app/player/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/player/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SearchPlayerServicesLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSearchPlayerServicesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchPlayerServicesLogic {
|
||||||
|
return &SearchPlayerServicesLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *SearchPlayerServicesLogic) SearchPlayerServices(in *pb.SearchPlayerServicesReq) (*pb.SearchPlayerServicesResp, error) {
|
||||||
|
if in.Limit > 1000 {
|
||||||
|
return nil, errors.New("limit too large")
|
||||||
|
}
|
||||||
|
|
||||||
|
update := l.svcCtx.PlayerModelRO.PlayerServices.Query()
|
||||||
|
if in.PlayerId != 0 {
|
||||||
|
update.Where(playerservices.PlayerIDEQ(in.PlayerId))
|
||||||
|
}
|
||||||
|
|
||||||
|
all, err := update.
|
||||||
|
Limit(int(in.Limit)).
|
||||||
|
Offset(int(in.Limit * in.Page)).
|
||||||
|
All(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("query all player services err")
|
||||||
|
}
|
||||||
|
|
||||||
|
list := make([]*pb.PlayerServices, 0, len(all))
|
||||||
|
for _, v := range all {
|
||||||
|
temp := &pb.PlayerServices{
|
||||||
|
Id: v.ID,
|
||||||
|
PlayerId: v.PlayerID,
|
||||||
|
GameId: v.GameID,
|
||||||
|
Title: v.Title,
|
||||||
|
Price: v.Price.InexactFloat64(),
|
||||||
|
Unit: v.Unit,
|
||||||
|
Availability: v.Availability,
|
||||||
|
Rating: v.Rating.InexactFloat64(),
|
||||||
|
IsActive: v.IsActive,
|
||||||
|
CreatedAt: v.CreatedAt.Unix(),
|
||||||
|
UpdatedAt: v.UpdatedAt.Unix(),
|
||||||
|
}
|
||||||
|
if v.Description != nil {
|
||||||
|
temp.Description = *v.Description
|
||||||
|
}
|
||||||
|
if v.RankRange != nil {
|
||||||
|
temp.RankRange = *v.RankRange
|
||||||
|
}
|
||||||
|
list = append(list, temp)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.SearchPlayerServicesResp{PlayerServices: list}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/players"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/player/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SearchPlayersLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSearchPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchPlayersLogic {
|
||||||
|
return &SearchPlayersLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *SearchPlayersLogic) SearchPlayers(in *pb.SearchPlayersReq) (*pb.SearchPlayersResp, error) {
|
||||||
|
gender := 0
|
||||||
|
if in.Gender > 0 {
|
||||||
|
gender = 1
|
||||||
|
}
|
||||||
|
searcher := l.svcCtx.PlayerModelRO.Players.Query()
|
||||||
|
if in.Gender >= 0 {
|
||||||
|
searcher.Where(players.GenderEQ(gender))
|
||||||
|
}
|
||||||
|
|
||||||
|
all, err := searcher.Limit(int(in.Limit)).Offset(int(in.Page * in.Limit)).All(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("SearchPlayers err: %v", err)
|
||||||
|
return nil, errors.New("search players")
|
||||||
|
}
|
||||||
|
list := make([]*pb.Players, 0, len(all))
|
||||||
|
for _, v := range all {
|
||||||
|
temp := &pb.Players{}
|
||||||
|
err := copier.Copy(temp, v)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("SearchPlayers copier.Copy err: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
list = append(list, temp)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.SearchPlayersResp{Players: list}, nil
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/player/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/player/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdatePlayerServicesLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUpdatePlayerServicesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePlayerServicesLogic {
|
||||||
|
return &UpdatePlayerServicesLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *UpdatePlayerServicesLogic) UpdatePlayerServices(in *pb.UpdatePlayerServicesReq) (*pb.UpdatePlayerServicesResp, error) {
|
||||||
|
update := l.svcCtx.PlayerModelRW.PlayerServices.UpdateOneID(in.Id).
|
||||||
|
SetNillablePlayerID(in.PlayerId).
|
||||||
|
SetNillableDescription(in.Description).
|
||||||
|
SetNillableGameID(in.GameId).
|
||||||
|
SetNillableIsActive(in.IsActive).
|
||||||
|
SetNillableRankRange(in.RankRange).
|
||||||
|
SetNillableTitle(in.Title).
|
||||||
|
SetNillableUnit(in.Unit).
|
||||||
|
SetAvailability(in.Availability)
|
||||||
|
if in.Price != nil {
|
||||||
|
price := decimal.NewFromFloat(*in.Price)
|
||||||
|
update.SetNillablePrice(&price)
|
||||||
|
}
|
||||||
|
if in.Rating != nil {
|
||||||
|
rating := decimal.NewFromFloat(*in.Rating)
|
||||||
|
update.SetNillableRating(&rating)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := update.Save(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("failed to update player services: " + err.Error())
|
||||||
|
return nil, errors.New("failed to update player services")
|
||||||
|
}
|
||||||
|
return &pb.UpdatePlayerServicesResp{}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/player/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/player/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdatePlayersLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUpdatePlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePlayersLogic {
|
||||||
|
return &UpdatePlayersLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *UpdatePlayersLogic) UpdatePlayers(in *pb.UpdatePlayersReq) (*pb.UpdatePlayersResp, error) {
|
||||||
|
update := l.svcCtx.PlayerModelRW.Players.UpdateOneID(in.Id).
|
||||||
|
SetNillableStatus(in.Status).
|
||||||
|
SetNillableUserID(in.UserId).
|
||||||
|
SetNillableShopID(in.ShopId)
|
||||||
|
if in.Rating != nil {
|
||||||
|
rating := decimal.NewFromFloat(*in.Rating)
|
||||||
|
update.SetRating(rating)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.UpdatePlayersResp{}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,484 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/migrate"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/players"
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/playerservices"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Client is the client that holds all ent builders.
|
||||||
|
type Client struct {
|
||||||
|
config
|
||||||
|
// Schema is the client for creating, migrating and dropping schema.
|
||||||
|
Schema *migrate.Schema
|
||||||
|
// PlayerServices is the client for interacting with the PlayerServices builders.
|
||||||
|
PlayerServices *PlayerServicesClient
|
||||||
|
// Players is the client for interacting with the Players builders.
|
||||||
|
Players *PlayersClient
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient creates a new client configured with the given options.
|
||||||
|
func NewClient(opts ...Option) *Client {
|
||||||
|
client := &Client{config: newConfig(opts...)}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) init() {
|
||||||
|
c.Schema = migrate.NewSchema(c.driver)
|
||||||
|
c.PlayerServices = NewPlayerServicesClient(c.config)
|
||||||
|
c.Players = NewPlayersClient(c.config)
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// config is the configuration for the client and its builder.
|
||||||
|
config struct {
|
||||||
|
// driver used for executing database requests.
|
||||||
|
driver dialect.Driver
|
||||||
|
// debug enable a debug logging.
|
||||||
|
debug bool
|
||||||
|
// log used for logging on debug mode.
|
||||||
|
log func(...any)
|
||||||
|
// hooks to execute on mutations.
|
||||||
|
hooks *hooks
|
||||||
|
// interceptors to execute on queries.
|
||||||
|
inters *inters
|
||||||
|
}
|
||||||
|
// Option function to configure the client.
|
||||||
|
Option func(*config)
|
||||||
|
)
|
||||||
|
|
||||||
|
// newConfig creates a new config for the client.
|
||||||
|
func newConfig(opts ...Option) config {
|
||||||
|
cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
|
||||||
|
cfg.options(opts...)
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
|
|
||||||
|
// options applies the options on the config object.
|
||||||
|
func (c *config) options(opts ...Option) {
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(c)
|
||||||
|
}
|
||||||
|
if c.debug {
|
||||||
|
c.driver = dialect.Debug(c.driver, c.log)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug enables debug logging on the ent.Driver.
|
||||||
|
func Debug() Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.debug = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log sets the logging function for debug mode.
|
||||||
|
func Log(fn func(...any)) Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.log = fn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Driver configures the client driver.
|
||||||
|
func Driver(driver dialect.Driver) Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.driver = driver
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open opens a database/sql.DB specified by the driver name and
|
||||||
|
// the data source name, and returns a new client attached to it.
|
||||||
|
// Optional parameters can be added for configuring the client.
|
||||||
|
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
|
||||||
|
switch driverName {
|
||||||
|
case dialect.MySQL, dialect.Postgres, dialect.SQLite:
|
||||||
|
drv, err := sql.Open(driverName, dataSourceName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return NewClient(append(options, Driver(drv))...), nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unsupported driver: %q", driverName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrTxStarted is returned when trying to start a new transaction from a transactional client.
|
||||||
|
var ErrTxStarted = errors.New("models: cannot start a transaction within a transaction")
|
||||||
|
|
||||||
|
// Tx returns a new transactional client. The provided context
|
||||||
|
// is used until the transaction is committed or rolled back.
|
||||||
|
func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||||
|
if _, ok := c.driver.(*txDriver); ok {
|
||||||
|
return nil, ErrTxStarted
|
||||||
|
}
|
||||||
|
tx, err := newTx(ctx, c.driver)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("models: starting a transaction: %w", err)
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = tx
|
||||||
|
return &Tx{
|
||||||
|
ctx: ctx,
|
||||||
|
config: cfg,
|
||||||
|
PlayerServices: NewPlayerServicesClient(cfg),
|
||||||
|
Players: NewPlayersClient(cfg),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeginTx returns a transactional client with specified options.
|
||||||
|
func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
|
||||||
|
if _, ok := c.driver.(*txDriver); ok {
|
||||||
|
return nil, errors.New("ent: cannot start a transaction within a transaction")
|
||||||
|
}
|
||||||
|
tx, err := c.driver.(interface {
|
||||||
|
BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
|
||||||
|
}).BeginTx(ctx, opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = &txDriver{tx: tx, drv: c.driver}
|
||||||
|
return &Tx{
|
||||||
|
ctx: ctx,
|
||||||
|
config: cfg,
|
||||||
|
PlayerServices: NewPlayerServicesClient(cfg),
|
||||||
|
Players: NewPlayersClient(cfg),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||||
|
//
|
||||||
|
// client.Debug().
|
||||||
|
// PlayerServices.
|
||||||
|
// Query().
|
||||||
|
// Count(ctx)
|
||||||
|
func (c *Client) Debug() *Client {
|
||||||
|
if c.debug {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = dialect.Debug(c.driver, c.log)
|
||||||
|
client := &Client{config: cfg}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close closes the database connection and prevents new queries from starting.
|
||||||
|
func (c *Client) Close() error {
|
||||||
|
return c.driver.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds the mutation hooks to all the entity clients.
|
||||||
|
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||||
|
func (c *Client) Use(hooks ...Hook) {
|
||||||
|
c.PlayerServices.Use(hooks...)
|
||||||
|
c.Players.Use(hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds the query interceptors to all the entity clients.
|
||||||
|
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||||
|
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.PlayerServices.Intercept(interceptors...)
|
||||||
|
c.Players.Intercept(interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutate implements the ent.Mutator interface.
|
||||||
|
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
switch m := m.(type) {
|
||||||
|
case *PlayerServicesMutation:
|
||||||
|
return c.PlayerServices.mutate(ctx, m)
|
||||||
|
case *PlayersMutation:
|
||||||
|
return c.Players.mutate(ctx, m)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("models: unknown mutation type %T", m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PlayerServicesClient is a client for the PlayerServices schema.
|
||||||
|
type PlayerServicesClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPlayerServicesClient returns a client for the PlayerServices from the given config.
|
||||||
|
func NewPlayerServicesClient(c config) *PlayerServicesClient {
|
||||||
|
return &PlayerServicesClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `playerservices.Hooks(f(g(h())))`.
|
||||||
|
func (c *PlayerServicesClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.PlayerServices = append(c.hooks.PlayerServices, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `playerservices.Intercept(f(g(h())))`.
|
||||||
|
func (c *PlayerServicesClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.PlayerServices = append(c.inters.PlayerServices, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a PlayerServices entity.
|
||||||
|
func (c *PlayerServicesClient) Create() *PlayerServicesCreate {
|
||||||
|
mutation := newPlayerServicesMutation(c.config, OpCreate)
|
||||||
|
return &PlayerServicesCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of PlayerServices entities.
|
||||||
|
func (c *PlayerServicesClient) CreateBulk(builders ...*PlayerServicesCreate) *PlayerServicesCreateBulk {
|
||||||
|
return &PlayerServicesCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *PlayerServicesClient) MapCreateBulk(slice any, setFunc func(*PlayerServicesCreate, int)) *PlayerServicesCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &PlayerServicesCreateBulk{err: fmt.Errorf("calling to PlayerServicesClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*PlayerServicesCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &PlayerServicesCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for PlayerServices.
|
||||||
|
func (c *PlayerServicesClient) Update() *PlayerServicesUpdate {
|
||||||
|
mutation := newPlayerServicesMutation(c.config, OpUpdate)
|
||||||
|
return &PlayerServicesUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *PlayerServicesClient) UpdateOne(_m *PlayerServices) *PlayerServicesUpdateOne {
|
||||||
|
mutation := newPlayerServicesMutation(c.config, OpUpdateOne, withPlayerServices(_m))
|
||||||
|
return &PlayerServicesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *PlayerServicesClient) UpdateOneID(id int64) *PlayerServicesUpdateOne {
|
||||||
|
mutation := newPlayerServicesMutation(c.config, OpUpdateOne, withPlayerServicesID(id))
|
||||||
|
return &PlayerServicesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for PlayerServices.
|
||||||
|
func (c *PlayerServicesClient) Delete() *PlayerServicesDelete {
|
||||||
|
mutation := newPlayerServicesMutation(c.config, OpDelete)
|
||||||
|
return &PlayerServicesDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *PlayerServicesClient) DeleteOne(_m *PlayerServices) *PlayerServicesDeleteOne {
|
||||||
|
return c.DeleteOneID(_m.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *PlayerServicesClient) DeleteOneID(id int64) *PlayerServicesDeleteOne {
|
||||||
|
builder := c.Delete().Where(playerservices.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &PlayerServicesDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for PlayerServices.
|
||||||
|
func (c *PlayerServicesClient) Query() *PlayerServicesQuery {
|
||||||
|
return &PlayerServicesQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypePlayerServices},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a PlayerServices entity by its id.
|
||||||
|
func (c *PlayerServicesClient) Get(ctx context.Context, id int64) (*PlayerServices, error) {
|
||||||
|
return c.Query().Where(playerservices.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *PlayerServicesClient) GetX(ctx context.Context, id int64) *PlayerServices {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *PlayerServicesClient) Hooks() []Hook {
|
||||||
|
return c.hooks.PlayerServices
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *PlayerServicesClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.PlayerServices
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *PlayerServicesClient) mutate(ctx context.Context, m *PlayerServicesMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&PlayerServicesCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&PlayerServicesUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&PlayerServicesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&PlayerServicesDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("models: unknown PlayerServices mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PlayersClient is a client for the Players schema.
|
||||||
|
type PlayersClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPlayersClient returns a client for the Players from the given config.
|
||||||
|
func NewPlayersClient(c config) *PlayersClient {
|
||||||
|
return &PlayersClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `players.Hooks(f(g(h())))`.
|
||||||
|
func (c *PlayersClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.Players = append(c.hooks.Players, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `players.Intercept(f(g(h())))`.
|
||||||
|
func (c *PlayersClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.Players = append(c.inters.Players, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a Players entity.
|
||||||
|
func (c *PlayersClient) Create() *PlayersCreate {
|
||||||
|
mutation := newPlayersMutation(c.config, OpCreate)
|
||||||
|
return &PlayersCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of Players entities.
|
||||||
|
func (c *PlayersClient) CreateBulk(builders ...*PlayersCreate) *PlayersCreateBulk {
|
||||||
|
return &PlayersCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *PlayersClient) MapCreateBulk(slice any, setFunc func(*PlayersCreate, int)) *PlayersCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &PlayersCreateBulk{err: fmt.Errorf("calling to PlayersClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*PlayersCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &PlayersCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for Players.
|
||||||
|
func (c *PlayersClient) Update() *PlayersUpdate {
|
||||||
|
mutation := newPlayersMutation(c.config, OpUpdate)
|
||||||
|
return &PlayersUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *PlayersClient) UpdateOne(_m *Players) *PlayersUpdateOne {
|
||||||
|
mutation := newPlayersMutation(c.config, OpUpdateOne, withPlayers(_m))
|
||||||
|
return &PlayersUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *PlayersClient) UpdateOneID(id int64) *PlayersUpdateOne {
|
||||||
|
mutation := newPlayersMutation(c.config, OpUpdateOne, withPlayersID(id))
|
||||||
|
return &PlayersUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for Players.
|
||||||
|
func (c *PlayersClient) Delete() *PlayersDelete {
|
||||||
|
mutation := newPlayersMutation(c.config, OpDelete)
|
||||||
|
return &PlayersDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *PlayersClient) DeleteOne(_m *Players) *PlayersDeleteOne {
|
||||||
|
return c.DeleteOneID(_m.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *PlayersClient) DeleteOneID(id int64) *PlayersDeleteOne {
|
||||||
|
builder := c.Delete().Where(players.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &PlayersDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for Players.
|
||||||
|
func (c *PlayersClient) Query() *PlayersQuery {
|
||||||
|
return &PlayersQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypePlayers},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a Players entity by its id.
|
||||||
|
func (c *PlayersClient) Get(ctx context.Context, id int64) (*Players, error) {
|
||||||
|
return c.Query().Where(players.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *PlayersClient) GetX(ctx context.Context, id int64) *Players {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *PlayersClient) Hooks() []Hook {
|
||||||
|
return c.hooks.Players
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *PlayersClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.Players
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *PlayersClient) mutate(ctx context.Context, m *PlayersMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&PlayersCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&PlayersUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&PlayersUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&PlayersDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("models: unknown Players mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// hooks and interceptors per client, for fast access.
|
||||||
|
type (
|
||||||
|
hooks struct {
|
||||||
|
PlayerServices, Players []ent.Hook
|
||||||
|
}
|
||||||
|
inters struct {
|
||||||
|
PlayerServices, Players []ent.Interceptor
|
||||||
|
}
|
||||||
|
)
|
||||||
@@ -0,0 +1,610 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/players"
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/playerservices"
|
||||||
|
"reflect"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ent aliases to avoid import conflicts in user's code.
|
||||||
|
type (
|
||||||
|
Op = ent.Op
|
||||||
|
Hook = ent.Hook
|
||||||
|
Value = ent.Value
|
||||||
|
Query = ent.Query
|
||||||
|
QueryContext = ent.QueryContext
|
||||||
|
Querier = ent.Querier
|
||||||
|
QuerierFunc = ent.QuerierFunc
|
||||||
|
Interceptor = ent.Interceptor
|
||||||
|
InterceptFunc = ent.InterceptFunc
|
||||||
|
Traverser = ent.Traverser
|
||||||
|
TraverseFunc = ent.TraverseFunc
|
||||||
|
Policy = ent.Policy
|
||||||
|
Mutator = ent.Mutator
|
||||||
|
Mutation = ent.Mutation
|
||||||
|
MutateFunc = ent.MutateFunc
|
||||||
|
)
|
||||||
|
|
||||||
|
type clientCtxKey struct{}
|
||||||
|
|
||||||
|
// FromContext returns a Client stored inside a context, or nil if there isn't one.
|
||||||
|
func FromContext(ctx context.Context) *Client {
|
||||||
|
c, _ := ctx.Value(clientCtxKey{}).(*Client)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewContext returns a new context with the given Client attached.
|
||||||
|
func NewContext(parent context.Context, c *Client) context.Context {
|
||||||
|
return context.WithValue(parent, clientCtxKey{}, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
type txCtxKey struct{}
|
||||||
|
|
||||||
|
// TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
|
||||||
|
func TxFromContext(ctx context.Context) *Tx {
|
||||||
|
tx, _ := ctx.Value(txCtxKey{}).(*Tx)
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTxContext returns a new context with the given Tx attached.
|
||||||
|
func NewTxContext(parent context.Context, tx *Tx) context.Context {
|
||||||
|
return context.WithValue(parent, txCtxKey{}, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OrderFunc applies an ordering on the sql selector.
|
||||||
|
// Deprecated: Use Asc/Desc functions or the package builders instead.
|
||||||
|
type OrderFunc func(*sql.Selector)
|
||||||
|
|
||||||
|
var (
|
||||||
|
initCheck sync.Once
|
||||||
|
columnCheck sql.ColumnCheck
|
||||||
|
)
|
||||||
|
|
||||||
|
// checkColumn checks if the column exists in the given table.
|
||||||
|
func checkColumn(t, c string) error {
|
||||||
|
initCheck.Do(func() {
|
||||||
|
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||||
|
playerservices.Table: playerservices.ValidColumn,
|
||||||
|
players.Table: players.ValidColumn,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return columnCheck(t, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asc applies the given fields in ASC order.
|
||||||
|
func Asc(fields ...string) func(*sql.Selector) {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
for _, f := range fields {
|
||||||
|
if err := checkColumn(s.TableName(), f); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("models: %w", err)})
|
||||||
|
}
|
||||||
|
s.OrderBy(sql.Asc(s.C(f)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Desc applies the given fields in DESC order.
|
||||||
|
func Desc(fields ...string) func(*sql.Selector) {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
for _, f := range fields {
|
||||||
|
if err := checkColumn(s.TableName(), f); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("models: %w", err)})
|
||||||
|
}
|
||||||
|
s.OrderBy(sql.Desc(s.C(f)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
|
||||||
|
type AggregateFunc func(*sql.Selector) string
|
||||||
|
|
||||||
|
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
|
||||||
|
//
|
||||||
|
// GroupBy(field1, field2).
|
||||||
|
// Aggregate(models.As(models.Sum(field1), "sum_field1"), (models.As(models.Sum(field2), "sum_field2")).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func As(fn AggregateFunc, end string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
return sql.As(fn(s), end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count applies the "count" aggregation function on each group.
|
||||||
|
func Count() AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
return sql.Count("*")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Max applies the "max" aggregation function on the given field of each group.
|
||||||
|
func Max(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Max(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mean applies the "mean" aggregation function on the given field of each group.
|
||||||
|
func Mean(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Avg(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Min applies the "min" aggregation function on the given field of each group.
|
||||||
|
func Min(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Min(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sum applies the "sum" aggregation function on the given field of each group.
|
||||||
|
func Sum(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Sum(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidationError returns when validating a field or edge fails.
|
||||||
|
type ValidationError struct {
|
||||||
|
Name string // Field or edge name.
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *ValidationError) Error() string {
|
||||||
|
return e.err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap implements the errors.Wrapper interface.
|
||||||
|
func (e *ValidationError) Unwrap() error {
|
||||||
|
return e.err
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValidationError returns a boolean indicating whether the error is a validation error.
|
||||||
|
func IsValidationError(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *ValidationError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
|
||||||
|
type NotFoundError struct {
|
||||||
|
label string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotFoundError) Error() string {
|
||||||
|
return "models: " + e.label + " not found"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||||
|
func IsNotFound(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotFoundError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaskNotFound masks not found error.
|
||||||
|
func MaskNotFound(err error) error {
|
||||||
|
if IsNotFound(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
|
||||||
|
type NotSingularError struct {
|
||||||
|
label string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotSingularError) Error() string {
|
||||||
|
return "models: " + e.label + " not singular"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||||
|
func IsNotSingular(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotSingularError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotLoadedError returns when trying to get a node that was not loaded by the query.
|
||||||
|
type NotLoadedError struct {
|
||||||
|
edge string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotLoadedError) Error() string {
|
||||||
|
return "models: " + e.edge + " edge was not loaded"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||||
|
func IsNotLoaded(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotLoadedError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConstraintError returns when trying to create/update one or more entities and
|
||||||
|
// one or more of their constraints failed. For example, violation of edge or
|
||||||
|
// field uniqueness.
|
||||||
|
type ConstraintError struct {
|
||||||
|
msg string
|
||||||
|
wrap error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e ConstraintError) Error() string {
|
||||||
|
return "models: constraint failed: " + e.msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap implements the errors.Wrapper interface.
|
||||||
|
func (e *ConstraintError) Unwrap() error {
|
||||||
|
return e.wrap
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||||
|
func IsConstraintError(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *ConstraintError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// selector embedded by the different Select/GroupBy builders.
|
||||||
|
type selector struct {
|
||||||
|
label string
|
||||||
|
flds *[]string
|
||||||
|
fns []AggregateFunc
|
||||||
|
scan func(context.Context, any) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScanX is like Scan, but panics if an error occurs.
|
||||||
|
func (s *selector) ScanX(ctx context.Context, v any) {
|
||||||
|
if err := s.scan(ctx, v); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Strings(ctx context.Context) ([]string, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("models: Strings is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []string
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringsX is like Strings, but panics if an error occurs.
|
||||||
|
func (s *selector) StringsX(ctx context.Context) []string {
|
||||||
|
v, err := s.Strings(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a single string from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) String(ctx context.Context) (_ string, err error) {
|
||||||
|
var v []string
|
||||||
|
if v, err = s.Strings(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("models: Strings returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringX is like String, but panics if an error occurs.
|
||||||
|
func (s *selector) StringX(ctx context.Context) string {
|
||||||
|
v, err := s.String(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Ints(ctx context.Context) ([]int, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("models: Ints is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []int
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntsX is like Ints, but panics if an error occurs.
|
||||||
|
func (s *selector) IntsX(ctx context.Context) []int {
|
||||||
|
v, err := s.Ints(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int returns a single int from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Int(ctx context.Context) (_ int, err error) {
|
||||||
|
var v []int
|
||||||
|
if v, err = s.Ints(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("models: Ints returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntX is like Int, but panics if an error occurs.
|
||||||
|
func (s *selector) IntX(ctx context.Context) int {
|
||||||
|
v, err := s.Int(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Float64s(ctx context.Context) ([]float64, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("models: Float64s is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []float64
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64sX is like Float64s, but panics if an error occurs.
|
||||||
|
func (s *selector) Float64sX(ctx context.Context) []float64 {
|
||||||
|
v, err := s.Float64s(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Float64(ctx context.Context) (_ float64, err error) {
|
||||||
|
var v []float64
|
||||||
|
if v, err = s.Float64s(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("models: Float64s returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64X is like Float64, but panics if an error occurs.
|
||||||
|
func (s *selector) Float64X(ctx context.Context) float64 {
|
||||||
|
v, err := s.Float64(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Bools(ctx context.Context) ([]bool, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("models: Bools is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []bool
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolsX is like Bools, but panics if an error occurs.
|
||||||
|
func (s *selector) BoolsX(ctx context.Context) []bool {
|
||||||
|
v, err := s.Bools(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Bool(ctx context.Context) (_ bool, err error) {
|
||||||
|
var v []bool
|
||||||
|
if v, err = s.Bools(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("models: Bools returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolX is like Bool, but panics if an error occurs.
|
||||||
|
func (s *selector) BoolX(ctx context.Context) bool {
|
||||||
|
v, err := s.Bool(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// withHooks invokes the builder operation with the given hooks, if any.
|
||||||
|
func withHooks[V Value, M any, PM interface {
|
||||||
|
*M
|
||||||
|
Mutation
|
||||||
|
}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) {
|
||||||
|
if len(hooks) == 0 {
|
||||||
|
return exec(ctx)
|
||||||
|
}
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutationT, ok := any(m).(PM)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
// Set the mutation to the builder.
|
||||||
|
*mutation = *mutationT
|
||||||
|
return exec(ctx)
|
||||||
|
})
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
if hooks[i] == nil {
|
||||||
|
return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = hooks[i](mut)
|
||||||
|
}
|
||||||
|
v, err := mut.Mutate(ctx, mutation)
|
||||||
|
if err != nil {
|
||||||
|
return value, err
|
||||||
|
}
|
||||||
|
nv, ok := v.(V)
|
||||||
|
if !ok {
|
||||||
|
return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation)
|
||||||
|
}
|
||||||
|
return nv, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist.
|
||||||
|
func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context {
|
||||||
|
if ent.QueryFromContext(ctx) == nil {
|
||||||
|
qc.Op = op
|
||||||
|
ctx = ent.NewQueryContext(ctx, qc)
|
||||||
|
}
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
func querierAll[V Value, Q interface {
|
||||||
|
sqlAll(context.Context, ...queryHook) (V, error)
|
||||||
|
}]() Querier {
|
||||||
|
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
return query.sqlAll(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func querierCount[Q interface {
|
||||||
|
sqlCount(context.Context) (int, error)
|
||||||
|
}]() Querier {
|
||||||
|
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
return query.sqlCount(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) {
|
||||||
|
for i := len(inters) - 1; i >= 0; i-- {
|
||||||
|
qr = inters[i].Intercept(qr)
|
||||||
|
}
|
||||||
|
rv, err := qr.Query(ctx, q)
|
||||||
|
if err != nil {
|
||||||
|
return v, err
|
||||||
|
}
|
||||||
|
vt, ok := rv.(V)
|
||||||
|
if !ok {
|
||||||
|
return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v)
|
||||||
|
}
|
||||||
|
return vt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func scanWithInterceptors[Q1 ent.Query, Q2 interface {
|
||||||
|
sqlScan(context.Context, Q1, any) error
|
||||||
|
}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error {
|
||||||
|
rv := reflect.ValueOf(v)
|
||||||
|
var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q1)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
if err := selectOrGroup.sqlScan(ctx, query, v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() {
|
||||||
|
return rv.Elem().Interface(), nil
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
})
|
||||||
|
for i := len(inters) - 1; i >= 0; i-- {
|
||||||
|
qr = inters[i].Intercept(qr)
|
||||||
|
}
|
||||||
|
vv, err := qr.Query(ctx, rootQuery)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
switch rv2 := reflect.ValueOf(vv); {
|
||||||
|
case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer:
|
||||||
|
case rv.Type() == rv2.Type():
|
||||||
|
rv.Elem().Set(rv2.Elem())
|
||||||
|
case rv.Elem().Type() == rv2.Type():
|
||||||
|
rv.Elem().Set(rv2)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// queryHook describes an internal hook for the different sqlAll methods.
|
||||||
|
type queryHook func(context.Context, *sqlgraph.QuerySpec)
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package enttest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/rpc/internal/models"
|
||||||
|
// required by schema hooks.
|
||||||
|
_ "juwan-backend/app/player/rpc/internal/models/runtime"
|
||||||
|
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/migrate"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// TestingT is the interface that is shared between
|
||||||
|
// testing.T and testing.B and used by enttest.
|
||||||
|
TestingT interface {
|
||||||
|
FailNow()
|
||||||
|
Error(...any)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Option configures client creation.
|
||||||
|
Option func(*options)
|
||||||
|
|
||||||
|
options struct {
|
||||||
|
opts []models.Option
|
||||||
|
migrateOpts []schema.MigrateOption
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// WithOptions forwards options to client creation.
|
||||||
|
func WithOptions(opts ...models.Option) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.opts = append(o.opts, opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithMigrateOptions forwards options to auto migration.
|
||||||
|
func WithMigrateOptions(opts ...schema.MigrateOption) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.migrateOpts = append(o.migrateOpts, opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newOptions(opts []Option) *options {
|
||||||
|
o := &options{}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(o)
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open calls models.Open and auto-run migration.
|
||||||
|
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *models.Client {
|
||||||
|
o := newOptions(opts)
|
||||||
|
c, err := models.Open(driverName, dataSourceName, o.opts...)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
migrateSchema(t, c, o)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient calls models.NewClient and auto-run migration.
|
||||||
|
func NewClient(t TestingT, opts ...Option) *models.Client {
|
||||||
|
o := newOptions(opts)
|
||||||
|
c := models.NewClient(o.opts...)
|
||||||
|
migrateSchema(t, c, o)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
func migrateSchema(t TestingT, c *models.Client, o *options) {
|
||||||
|
tables, err := schema.CopyTables(migrate.Tables)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,210 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package hook
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/player/rpc/internal/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The PlayerServicesFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as PlayerServices mutator.
|
||||||
|
type PlayerServicesFunc func(context.Context, *models.PlayerServicesMutation) (models.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f PlayerServicesFunc) Mutate(ctx context.Context, m models.Mutation) (models.Value, error) {
|
||||||
|
if mv, ok := m.(*models.PlayerServicesMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *models.PlayerServicesMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The PlayersFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as Players mutator.
|
||||||
|
type PlayersFunc func(context.Context, *models.PlayersMutation) (models.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f PlayersFunc) Mutate(ctx context.Context, m models.Mutation) (models.Value, error) {
|
||||||
|
if mv, ok := m.(*models.PlayersMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *models.PlayersMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Condition is a hook condition function.
|
||||||
|
type Condition func(context.Context, models.Mutation) bool
|
||||||
|
|
||||||
|
// And groups conditions with the AND operator.
|
||||||
|
func And(first, second Condition, rest ...Condition) Condition {
|
||||||
|
return func(ctx context.Context, m models.Mutation) bool {
|
||||||
|
if !first(ctx, m) || !second(ctx, m) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, cond := range rest {
|
||||||
|
if !cond(ctx, m) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups conditions with the OR operator.
|
||||||
|
func Or(first, second Condition, rest ...Condition) Condition {
|
||||||
|
return func(ctx context.Context, m models.Mutation) bool {
|
||||||
|
if first(ctx, m) || second(ctx, m) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
for _, cond := range rest {
|
||||||
|
if cond(ctx, m) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not negates a given condition.
|
||||||
|
func Not(cond Condition) Condition {
|
||||||
|
return func(ctx context.Context, m models.Mutation) bool {
|
||||||
|
return !cond(ctx, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasOp is a condition testing mutation operation.
|
||||||
|
func HasOp(op models.Op) Condition {
|
||||||
|
return func(_ context.Context, m models.Mutation) bool {
|
||||||
|
return m.Op().Is(op)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasAddedFields is a condition validating `.AddedField` on fields.
|
||||||
|
func HasAddedFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m models.Mutation) bool {
|
||||||
|
if _, exists := m.AddedField(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if _, exists := m.AddedField(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasClearedFields is a condition validating `.FieldCleared` on fields.
|
||||||
|
func HasClearedFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m models.Mutation) bool {
|
||||||
|
if exists := m.FieldCleared(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if exists := m.FieldCleared(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasFields is a condition validating `.Field` on fields.
|
||||||
|
func HasFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m models.Mutation) bool {
|
||||||
|
if _, exists := m.Field(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if _, exists := m.Field(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If executes the given hook under condition.
|
||||||
|
//
|
||||||
|
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
|
||||||
|
func If(hk models.Hook, cond Condition) models.Hook {
|
||||||
|
return func(next models.Mutator) models.Mutator {
|
||||||
|
return models.MutateFunc(func(ctx context.Context, m models.Mutation) (models.Value, error) {
|
||||||
|
if cond(ctx, m) {
|
||||||
|
return hk(next).Mutate(ctx, m)
|
||||||
|
}
|
||||||
|
return next.Mutate(ctx, m)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// On executes the given hook only for the given operation.
|
||||||
|
//
|
||||||
|
// hook.On(Log, models.Delete|models.Create)
|
||||||
|
func On(hk models.Hook, op models.Op) models.Hook {
|
||||||
|
return If(hk, HasOp(op))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unless skips the given hook only for the given operation.
|
||||||
|
//
|
||||||
|
// hook.Unless(Log, models.Update|models.UpdateOne)
|
||||||
|
func Unless(hk models.Hook, op models.Op) models.Hook {
|
||||||
|
return If(hk, Not(HasOp(op)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FixedError is a hook returning a fixed error.
|
||||||
|
func FixedError(err error) models.Hook {
|
||||||
|
return func(models.Mutator) models.Mutator {
|
||||||
|
return models.MutateFunc(func(context.Context, models.Mutation) (models.Value, error) {
|
||||||
|
return nil, err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reject returns a hook that rejects all operations that match op.
|
||||||
|
//
|
||||||
|
// func (T) Hooks() []models.Hook {
|
||||||
|
// return []models.Hook{
|
||||||
|
// Reject(models.Delete|models.Update),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
func Reject(op models.Op) models.Hook {
|
||||||
|
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||||
|
return On(hk, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chain acts as a list of hooks and is effectively immutable.
|
||||||
|
// Once created, it will always hold the same set of hooks in the same order.
|
||||||
|
type Chain struct {
|
||||||
|
hooks []models.Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewChain creates a new chain of hooks.
|
||||||
|
func NewChain(hooks ...models.Hook) Chain {
|
||||||
|
return Chain{append([]models.Hook(nil), hooks...)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hook chains the list of hooks and returns the final hook.
|
||||||
|
func (c Chain) Hook() models.Hook {
|
||||||
|
return func(mutator models.Mutator) models.Mutator {
|
||||||
|
for i := len(c.hooks) - 1; i >= 0; i-- {
|
||||||
|
mutator = c.hooks[i](mutator)
|
||||||
|
}
|
||||||
|
return mutator
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append extends a chain, adding the specified hook
|
||||||
|
// as the last ones in the mutation flow.
|
||||||
|
func (c Chain) Append(hooks ...models.Hook) Chain {
|
||||||
|
newHooks := make([]models.Hook, 0, len(c.hooks)+len(hooks))
|
||||||
|
newHooks = append(newHooks, c.hooks...)
|
||||||
|
newHooks = append(newHooks, hooks...)
|
||||||
|
return Chain{newHooks}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extend extends a chain, adding the specified chain
|
||||||
|
// as the last ones in the mutation flow.
|
||||||
|
func (c Chain) Extend(chain Chain) Chain {
|
||||||
|
return c.Append(chain.hooks...)
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package migrate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// WithGlobalUniqueID sets the universal ids options to the migration.
|
||||||
|
// If this option is enabled, ent migration will allocate a 1<<32 range
|
||||||
|
// for the ids of each entity (table).
|
||||||
|
// Note that this option cannot be applied on tables that already exist.
|
||||||
|
WithGlobalUniqueID = schema.WithGlobalUniqueID
|
||||||
|
// WithDropColumn sets the drop column option to the migration.
|
||||||
|
// If this option is enabled, ent migration will drop old columns
|
||||||
|
// that were used for both fields and edges. This defaults to false.
|
||||||
|
WithDropColumn = schema.WithDropColumn
|
||||||
|
// WithDropIndex sets the drop index option to the migration.
|
||||||
|
// If this option is enabled, ent migration will drop old indexes
|
||||||
|
// that were defined in the schema. This defaults to false.
|
||||||
|
// Note that unique constraints are defined using `UNIQUE INDEX`,
|
||||||
|
// and therefore, it's recommended to enable this option to get more
|
||||||
|
// flexibility in the schema changes.
|
||||||
|
WithDropIndex = schema.WithDropIndex
|
||||||
|
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
|
||||||
|
WithForeignKeys = schema.WithForeignKeys
|
||||||
|
)
|
||||||
|
|
||||||
|
// Schema is the API for creating, migrating and dropping a schema.
|
||||||
|
type Schema struct {
|
||||||
|
drv dialect.Driver
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSchema creates a new schema client.
|
||||||
|
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
|
||||||
|
|
||||||
|
// Create creates all schema resources.
|
||||||
|
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
|
||||||
|
return Create(ctx, s, Tables, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create creates all table resources using the given schema driver.
|
||||||
|
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error {
|
||||||
|
migrate, err := schema.NewMigrate(s.drv, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("ent/migrate: %w", err)
|
||||||
|
}
|
||||||
|
return migrate.Create(ctx, tables...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteTo writes the schema changes to w instead of running them against the database.
|
||||||
|
//
|
||||||
|
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
|
||||||
|
// log.Fatal(err)
|
||||||
|
// }
|
||||||
|
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
|
||||||
|
return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...)
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package migrate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent/dialect/entsql"
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// PlayerServicesColumns holds the columns for the "player_services" table.
|
||||||
|
PlayerServicesColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
|
{Name: "player_id", Type: field.TypeInt64},
|
||||||
|
{Name: "game_id", Type: field.TypeInt64},
|
||||||
|
{Name: "title", Type: field.TypeString, Size: 200},
|
||||||
|
{Name: "description", Type: field.TypeString, Nullable: true},
|
||||||
|
{Name: "price", Type: field.TypeOther, SchemaType: map[string]string{"postgres": "decimal(10,2)"}},
|
||||||
|
{Name: "unit", Type: field.TypeString, Size: 20},
|
||||||
|
{Name: "rank_range", Type: field.TypeString, Nullable: true, Size: 100},
|
||||||
|
{Name: "availability", Type: field.TypeJSON, Nullable: true},
|
||||||
|
{Name: "rating", Type: field.TypeOther, SchemaType: map[string]string{"postgres": "decimal(3,2)"}},
|
||||||
|
{Name: "is_active", Type: field.TypeBool, Nullable: true, Default: true},
|
||||||
|
{Name: "created_at", Type: field.TypeTime},
|
||||||
|
{Name: "updated_at", Type: field.TypeTime},
|
||||||
|
}
|
||||||
|
// PlayerServicesTable holds the schema information for the "player_services" table.
|
||||||
|
PlayerServicesTable = &schema.Table{
|
||||||
|
Name: "player_services",
|
||||||
|
Columns: PlayerServicesColumns,
|
||||||
|
PrimaryKey: []*schema.Column{PlayerServicesColumns[0]},
|
||||||
|
}
|
||||||
|
// PlayersColumns holds the columns for the "players" table.
|
||||||
|
PlayersColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
|
{Name: "user_id", Type: field.TypeInt64, Unique: true},
|
||||||
|
{Name: "status", Type: field.TypeString, Size: 20, Default: "offline"},
|
||||||
|
{Name: "gender", Type: field.TypeInt, Unique: true},
|
||||||
|
{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: "completed_orders", Type: field.TypeInt, Nullable: true, Default: 0},
|
||||||
|
{Name: "shop_id", Type: field.TypeInt64, Nullable: true},
|
||||||
|
{Name: "tags", Type: field.TypeJSON, Nullable: true},
|
||||||
|
{Name: "games", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "bigint[]"}},
|
||||||
|
{Name: "created_at", Type: field.TypeTime},
|
||||||
|
{Name: "updated_at", Type: field.TypeTime},
|
||||||
|
}
|
||||||
|
// PlayersTable holds the schema information for the "players" table.
|
||||||
|
PlayersTable = &schema.Table{
|
||||||
|
Name: "players",
|
||||||
|
Columns: PlayersColumns,
|
||||||
|
PrimaryKey: []*schema.Column{PlayersColumns[0]},
|
||||||
|
}
|
||||||
|
// Tables holds all the tables in the schema.
|
||||||
|
Tables = []*schema.Table{
|
||||||
|
PlayerServicesTable,
|
||||||
|
PlayersTable,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
PlayerServicesTable.Annotation = &entsql.Annotation{
|
||||||
|
Table: "player_services",
|
||||||
|
}
|
||||||
|
PlayerServicesTable.Annotation.Checks = map[string]string{
|
||||||
|
"chk_price_positive": "price > 0",
|
||||||
|
"chk_service_rating": "rating >= 0 AND rating <= 5",
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,230 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/players"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/lib/pq"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Players is the model entity for the Players schema.
|
||||||
|
type Players struct {
|
||||||
|
config `json:"-"`
|
||||||
|
// ID of the ent.
|
||||||
|
ID int64 `json:"id,omitempty"`
|
||||||
|
// UserID holds the value of the "user_id" field.
|
||||||
|
UserID int64 `json:"user_id,omitempty"`
|
||||||
|
// Status holds the value of the "status" field.
|
||||||
|
Status string `json:"status,omitempty"`
|
||||||
|
// Gender holds the value of the "gender" field.
|
||||||
|
Gender int `json:"gender,omitempty"`
|
||||||
|
// Rating holds the value of the "rating" field.
|
||||||
|
Rating decimal.Decimal `json:"rating,omitempty"`
|
||||||
|
// TotalOrders holds the value of the "total_orders" field.
|
||||||
|
TotalOrders int `json:"total_orders,omitempty"`
|
||||||
|
// CompletedOrders holds the value of the "completed_orders" field.
|
||||||
|
CompletedOrders int `json:"completed_orders,omitempty"`
|
||||||
|
// ShopID holds the value of the "shop_id" field.
|
||||||
|
ShopID *int64 `json:"shop_id,omitempty"`
|
||||||
|
// Tags holds the value of the "tags" field.
|
||||||
|
Tags []string `json:"tags,omitempty"`
|
||||||
|
// Games holds the value of the "games" field.
|
||||||
|
Games pq.Int64Array `json:"games,omitempty"`
|
||||||
|
// CreatedAt holds the value of the "created_at" field.
|
||||||
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||||
|
selectValues sql.SelectValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*Players) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case players.FieldTags:
|
||||||
|
values[i] = new([]byte)
|
||||||
|
case players.FieldRating:
|
||||||
|
values[i] = new(decimal.Decimal)
|
||||||
|
case players.FieldGames:
|
||||||
|
values[i] = new(pq.Int64Array)
|
||||||
|
case players.FieldID, players.FieldUserID, players.FieldGender, players.FieldTotalOrders, players.FieldCompletedOrders, players.FieldShopID:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case players.FieldStatus:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case players.FieldCreatedAt, players.FieldUpdatedAt:
|
||||||
|
values[i] = new(sql.NullTime)
|
||||||
|
default:
|
||||||
|
values[i] = new(sql.UnknownType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the Players fields.
|
||||||
|
func (_m *Players) assignValues(columns []string, values []any) error {
|
||||||
|
if m, n := len(values), len(columns); m < n {
|
||||||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||||
|
}
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case players.FieldID:
|
||||||
|
value, ok := values[i].(*sql.NullInt64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||||||
|
}
|
||||||
|
_m.ID = int64(value.Int64)
|
||||||
|
case players.FieldUserID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.UserID = value.Int64
|
||||||
|
}
|
||||||
|
case players.FieldStatus:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field status", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Status = value.String
|
||||||
|
}
|
||||||
|
case players.FieldGender:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field gender", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Gender = int(value.Int64)
|
||||||
|
}
|
||||||
|
case players.FieldRating:
|
||||||
|
if value, ok := values[i].(*decimal.Decimal); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field rating", values[i])
|
||||||
|
} else if value != nil {
|
||||||
|
_m.Rating = *value
|
||||||
|
}
|
||||||
|
case players.FieldTotalOrders:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field total_orders", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.TotalOrders = int(value.Int64)
|
||||||
|
}
|
||||||
|
case players.FieldCompletedOrders:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field completed_orders", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.CompletedOrders = int(value.Int64)
|
||||||
|
}
|
||||||
|
case players.FieldShopID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field shop_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ShopID = new(int64)
|
||||||
|
*_m.ShopID = value.Int64
|
||||||
|
}
|
||||||
|
case players.FieldTags:
|
||||||
|
if value, ok := values[i].(*[]byte); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field tags", values[i])
|
||||||
|
} else if value != nil && len(*value) > 0 {
|
||||||
|
if err := json.Unmarshal(*value, &_m.Tags); err != nil {
|
||||||
|
return fmt.Errorf("unmarshal field tags: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case players.FieldGames:
|
||||||
|
if value, ok := values[i].(*pq.Int64Array); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field games", values[i])
|
||||||
|
} else if value != nil {
|
||||||
|
_m.Games = *value
|
||||||
|
}
|
||||||
|
case players.FieldCreatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.CreatedAt = value.Time
|
||||||
|
}
|
||||||
|
case players.FieldUpdatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.UpdatedAt = value.Time
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
_m.selectValues.Set(columns[i], values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the Players.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (_m *Players) Value(name string) (ent.Value, error) {
|
||||||
|
return _m.selectValues.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this Players.
|
||||||
|
// Note that you need to call Players.Unwrap() before calling this method if this Players
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (_m *Players) Update() *PlayersUpdateOne {
|
||||||
|
return NewPlayersClient(_m.config).UpdateOne(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the Players entity that was returned from a transaction after it was closed,
|
||||||
|
// so that all future queries will be executed through the driver which created the transaction.
|
||||||
|
func (_m *Players) Unwrap() *Players {
|
||||||
|
_tx, ok := _m.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("models: Players is not a transactional entity")
|
||||||
|
}
|
||||||
|
_m.config.driver = _tx.drv
|
||||||
|
return _m
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (_m *Players) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("Players(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||||
|
builder.WriteString("user_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.UserID))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("status=")
|
||||||
|
builder.WriteString(_m.Status)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("gender=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.Gender))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("rating=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.Rating))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("total_orders=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.TotalOrders))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("completed_orders=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.CompletedOrders))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.ShopID; v != nil {
|
||||||
|
builder.WriteString("shop_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", *v))
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("tags=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.Tags))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("games=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.Games))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("created_at=")
|
||||||
|
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("updated_at=")
|
||||||
|
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// PlayersSlice is a parsable slice of Players.
|
||||||
|
type PlayersSlice []*Players
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package players
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/lib/pq"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the players type in the database.
|
||||||
|
Label = "players"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldUserID holds the string denoting the user_id field in the database.
|
||||||
|
FieldUserID = "user_id"
|
||||||
|
// FieldStatus holds the string denoting the status field in the database.
|
||||||
|
FieldStatus = "status"
|
||||||
|
// FieldGender holds the string denoting the gender field in the database.
|
||||||
|
FieldGender = "gender"
|
||||||
|
// FieldRating holds the string denoting the rating field in the database.
|
||||||
|
FieldRating = "rating"
|
||||||
|
// FieldTotalOrders holds the string denoting the total_orders field in the database.
|
||||||
|
FieldTotalOrders = "total_orders"
|
||||||
|
// FieldCompletedOrders holds the string denoting the completed_orders field in the database.
|
||||||
|
FieldCompletedOrders = "completed_orders"
|
||||||
|
// FieldShopID holds the string denoting the shop_id field in the database.
|
||||||
|
FieldShopID = "shop_id"
|
||||||
|
// FieldTags holds the string denoting the tags field in the database.
|
||||||
|
FieldTags = "tags"
|
||||||
|
// FieldGames holds the string denoting the games field in the database.
|
||||||
|
FieldGames = "games"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// Table holds the table name of the players in the database.
|
||||||
|
Table = "players"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for players fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldUserID,
|
||||||
|
FieldStatus,
|
||||||
|
FieldGender,
|
||||||
|
FieldRating,
|
||||||
|
FieldTotalOrders,
|
||||||
|
FieldCompletedOrders,
|
||||||
|
FieldShopID,
|
||||||
|
FieldTags,
|
||||||
|
FieldGames,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultStatus holds the default value on creation for the "status" field.
|
||||||
|
DefaultStatus string
|
||||||
|
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
||||||
|
StatusValidator func(string) error
|
||||||
|
// DefaultRating holds the default value on creation for the "rating" field.
|
||||||
|
DefaultRating decimal.Decimal
|
||||||
|
// DefaultTotalOrders holds the default value on creation for the "total_orders" field.
|
||||||
|
DefaultTotalOrders int
|
||||||
|
// DefaultCompletedOrders holds the default value on creation for the "completed_orders" field.
|
||||||
|
DefaultCompletedOrders int
|
||||||
|
// DefaultTags holds the default value on creation for the "tags" field.
|
||||||
|
DefaultTags []string
|
||||||
|
// DefaultGames holds the default value on creation for the "games" field.
|
||||||
|
DefaultGames pq.Int64Array
|
||||||
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
|
DefaultCreatedAt func() time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt func() time.Time
|
||||||
|
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||||
|
UpdateDefaultUpdatedAt func() time.Time
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the Players queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUserID orders the results by the user_id field.
|
||||||
|
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUserID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByStatus orders the results by the status field.
|
||||||
|
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByGender orders the results by the gender field.
|
||||||
|
func ByGender(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldGender, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByRating orders the results by the rating field.
|
||||||
|
func ByRating(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldRating, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByTotalOrders orders the results by the total_orders field.
|
||||||
|
func ByTotalOrders(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldTotalOrders, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCompletedOrders orders the results by the completed_orders field.
|
||||||
|
func ByCompletedOrders(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCompletedOrders, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByShopID orders the results by the shop_id field.
|
||||||
|
func ByShopID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldShopID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByGames orders the results by the games field.
|
||||||
|
func ByGames(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldGames, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdatedAt orders the results by the updated_at field.
|
||||||
|
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
@@ -0,0 +1,607 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package players
|
||||||
|
|
||||||
|
import (
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/predicate"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/lib/pq"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||||
|
func UserID(v int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
|
||||||
|
func Status(v string) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gender applies equality check predicate on the "gender" field. It's identical to GenderEQ.
|
||||||
|
func Gender(v int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldGender, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rating applies equality check predicate on the "rating" field. It's identical to RatingEQ.
|
||||||
|
func Rating(v decimal.Decimal) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldRating, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TotalOrders applies equality check predicate on the "total_orders" field. It's identical to TotalOrdersEQ.
|
||||||
|
func TotalOrders(v int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldTotalOrders, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompletedOrders applies equality check predicate on the "completed_orders" field. It's identical to CompletedOrdersEQ.
|
||||||
|
func CompletedOrders(v int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldCompletedOrders, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShopID applies equality check predicate on the "shop_id" field. It's identical to ShopIDEQ.
|
||||||
|
func ShopID(v int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldShopID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Games applies equality check predicate on the "games" field. It's identical to GamesEQ.
|
||||||
|
func Games(v pq.Int64Array) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldGames, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
|
func CreatedAt(v time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||||
|
func UpdatedAt(v time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||||
|
func UserIDEQ(v int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
|
||||||
|
func UserIDNEQ(v int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDIn applies the In predicate on the "user_id" field.
|
||||||
|
func UserIDIn(vs ...int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldIn(FieldUserID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
|
||||||
|
func UserIDNotIn(vs ...int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNotIn(FieldUserID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDGT applies the GT predicate on the "user_id" field.
|
||||||
|
func UserIDGT(v int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGT(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDGTE applies the GTE predicate on the "user_id" field.
|
||||||
|
func UserIDGTE(v int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGTE(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDLT applies the LT predicate on the "user_id" field.
|
||||||
|
func UserIDLT(v int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLT(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDLTE applies the LTE predicate on the "user_id" field.
|
||||||
|
func UserIDLTE(v int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLTE(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusEQ applies the EQ predicate on the "status" field.
|
||||||
|
func StatusEQ(v string) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusNEQ applies the NEQ predicate on the "status" field.
|
||||||
|
func StatusNEQ(v string) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNEQ(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusIn applies the In predicate on the "status" field.
|
||||||
|
func StatusIn(vs ...string) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldIn(FieldStatus, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusNotIn applies the NotIn predicate on the "status" field.
|
||||||
|
func StatusNotIn(vs ...string) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNotIn(FieldStatus, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusGT applies the GT predicate on the "status" field.
|
||||||
|
func StatusGT(v string) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGT(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusGTE applies the GTE predicate on the "status" field.
|
||||||
|
func StatusGTE(v string) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGTE(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusLT applies the LT predicate on the "status" field.
|
||||||
|
func StatusLT(v string) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLT(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusLTE applies the LTE predicate on the "status" field.
|
||||||
|
func StatusLTE(v string) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLTE(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusContains applies the Contains predicate on the "status" field.
|
||||||
|
func StatusContains(v string) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldContains(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
|
||||||
|
func StatusHasPrefix(v string) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldHasPrefix(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
|
||||||
|
func StatusHasSuffix(v string) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldHasSuffix(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusEqualFold applies the EqualFold predicate on the "status" field.
|
||||||
|
func StatusEqualFold(v string) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEqualFold(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
|
||||||
|
func StatusContainsFold(v string) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldContainsFold(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenderEQ applies the EQ predicate on the "gender" field.
|
||||||
|
func GenderEQ(v int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldGender, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenderNEQ applies the NEQ predicate on the "gender" field.
|
||||||
|
func GenderNEQ(v int) predicate.Players {
|
||||||
|
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.
|
||||||
|
func RatingEQ(v decimal.Decimal) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldRating, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RatingNEQ applies the NEQ predicate on the "rating" field.
|
||||||
|
func RatingNEQ(v decimal.Decimal) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNEQ(FieldRating, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RatingIn applies the In predicate on the "rating" field.
|
||||||
|
func RatingIn(vs ...decimal.Decimal) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldIn(FieldRating, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RatingNotIn applies the NotIn predicate on the "rating" field.
|
||||||
|
func RatingNotIn(vs ...decimal.Decimal) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNotIn(FieldRating, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RatingGT applies the GT predicate on the "rating" field.
|
||||||
|
func RatingGT(v decimal.Decimal) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGT(FieldRating, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RatingGTE applies the GTE predicate on the "rating" field.
|
||||||
|
func RatingGTE(v decimal.Decimal) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGTE(FieldRating, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RatingLT applies the LT predicate on the "rating" field.
|
||||||
|
func RatingLT(v decimal.Decimal) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLT(FieldRating, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RatingLTE applies the LTE predicate on the "rating" field.
|
||||||
|
func RatingLTE(v decimal.Decimal) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLTE(FieldRating, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RatingIsNil applies the IsNil predicate on the "rating" field.
|
||||||
|
func RatingIsNil() predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldIsNull(FieldRating))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RatingNotNil applies the NotNil predicate on the "rating" field.
|
||||||
|
func RatingNotNil() predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNotNull(FieldRating))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TotalOrdersEQ applies the EQ predicate on the "total_orders" field.
|
||||||
|
func TotalOrdersEQ(v int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldTotalOrders, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TotalOrdersNEQ applies the NEQ predicate on the "total_orders" field.
|
||||||
|
func TotalOrdersNEQ(v int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNEQ(FieldTotalOrders, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TotalOrdersIn applies the In predicate on the "total_orders" field.
|
||||||
|
func TotalOrdersIn(vs ...int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldIn(FieldTotalOrders, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TotalOrdersNotIn applies the NotIn predicate on the "total_orders" field.
|
||||||
|
func TotalOrdersNotIn(vs ...int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNotIn(FieldTotalOrders, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TotalOrdersGT applies the GT predicate on the "total_orders" field.
|
||||||
|
func TotalOrdersGT(v int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGT(FieldTotalOrders, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TotalOrdersGTE applies the GTE predicate on the "total_orders" field.
|
||||||
|
func TotalOrdersGTE(v int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGTE(FieldTotalOrders, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TotalOrdersLT applies the LT predicate on the "total_orders" field.
|
||||||
|
func TotalOrdersLT(v int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLT(FieldTotalOrders, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TotalOrdersLTE applies the LTE predicate on the "total_orders" field.
|
||||||
|
func TotalOrdersLTE(v int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLTE(FieldTotalOrders, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TotalOrdersIsNil applies the IsNil predicate on the "total_orders" field.
|
||||||
|
func TotalOrdersIsNil() predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldIsNull(FieldTotalOrders))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TotalOrdersNotNil applies the NotNil predicate on the "total_orders" field.
|
||||||
|
func TotalOrdersNotNil() predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNotNull(FieldTotalOrders))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompletedOrdersEQ applies the EQ predicate on the "completed_orders" field.
|
||||||
|
func CompletedOrdersEQ(v int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldCompletedOrders, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompletedOrdersNEQ applies the NEQ predicate on the "completed_orders" field.
|
||||||
|
func CompletedOrdersNEQ(v int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNEQ(FieldCompletedOrders, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompletedOrdersIn applies the In predicate on the "completed_orders" field.
|
||||||
|
func CompletedOrdersIn(vs ...int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldIn(FieldCompletedOrders, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompletedOrdersNotIn applies the NotIn predicate on the "completed_orders" field.
|
||||||
|
func CompletedOrdersNotIn(vs ...int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNotIn(FieldCompletedOrders, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompletedOrdersGT applies the GT predicate on the "completed_orders" field.
|
||||||
|
func CompletedOrdersGT(v int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGT(FieldCompletedOrders, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompletedOrdersGTE applies the GTE predicate on the "completed_orders" field.
|
||||||
|
func CompletedOrdersGTE(v int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGTE(FieldCompletedOrders, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompletedOrdersLT applies the LT predicate on the "completed_orders" field.
|
||||||
|
func CompletedOrdersLT(v int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLT(FieldCompletedOrders, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompletedOrdersLTE applies the LTE predicate on the "completed_orders" field.
|
||||||
|
func CompletedOrdersLTE(v int) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLTE(FieldCompletedOrders, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompletedOrdersIsNil applies the IsNil predicate on the "completed_orders" field.
|
||||||
|
func CompletedOrdersIsNil() predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldIsNull(FieldCompletedOrders))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CompletedOrdersNotNil applies the NotNil predicate on the "completed_orders" field.
|
||||||
|
func CompletedOrdersNotNil() predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNotNull(FieldCompletedOrders))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShopIDEQ applies the EQ predicate on the "shop_id" field.
|
||||||
|
func ShopIDEQ(v int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldShopID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShopIDNEQ applies the NEQ predicate on the "shop_id" field.
|
||||||
|
func ShopIDNEQ(v int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNEQ(FieldShopID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShopIDIn applies the In predicate on the "shop_id" field.
|
||||||
|
func ShopIDIn(vs ...int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldIn(FieldShopID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShopIDNotIn applies the NotIn predicate on the "shop_id" field.
|
||||||
|
func ShopIDNotIn(vs ...int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNotIn(FieldShopID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShopIDGT applies the GT predicate on the "shop_id" field.
|
||||||
|
func ShopIDGT(v int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGT(FieldShopID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShopIDGTE applies the GTE predicate on the "shop_id" field.
|
||||||
|
func ShopIDGTE(v int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGTE(FieldShopID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShopIDLT applies the LT predicate on the "shop_id" field.
|
||||||
|
func ShopIDLT(v int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLT(FieldShopID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShopIDLTE applies the LTE predicate on the "shop_id" field.
|
||||||
|
func ShopIDLTE(v int64) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLTE(FieldShopID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShopIDIsNil applies the IsNil predicate on the "shop_id" field.
|
||||||
|
func ShopIDIsNil() predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldIsNull(FieldShopID))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShopIDNotNil applies the NotNil predicate on the "shop_id" field.
|
||||||
|
func ShopIDNotNil() predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNotNull(FieldShopID))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TagsIsNil applies the IsNil predicate on the "tags" field.
|
||||||
|
func TagsIsNil() predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldIsNull(FieldTags))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TagsNotNil applies the NotNil predicate on the "tags" field.
|
||||||
|
func TagsNotNil() predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNotNull(FieldTags))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GamesEQ applies the EQ predicate on the "games" field.
|
||||||
|
func GamesEQ(v pq.Int64Array) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldGames, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GamesNEQ applies the NEQ predicate on the "games" field.
|
||||||
|
func GamesNEQ(v pq.Int64Array) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNEQ(FieldGames, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GamesIn applies the In predicate on the "games" field.
|
||||||
|
func GamesIn(vs ...pq.Int64Array) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldIn(FieldGames, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GamesNotIn applies the NotIn predicate on the "games" field.
|
||||||
|
func GamesNotIn(vs ...pq.Int64Array) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNotIn(FieldGames, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GamesGT applies the GT predicate on the "games" field.
|
||||||
|
func GamesGT(v pq.Int64Array) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGT(FieldGames, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GamesGTE applies the GTE predicate on the "games" field.
|
||||||
|
func GamesGTE(v pq.Int64Array) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGTE(FieldGames, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GamesLT applies the LT predicate on the "games" field.
|
||||||
|
func GamesLT(v pq.Int64Array) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLT(FieldGames, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GamesLTE applies the LTE predicate on the "games" field.
|
||||||
|
func GamesLTE(v pq.Int64Array) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLTE(FieldGames, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GamesIsNil applies the IsNil predicate on the "games" field.
|
||||||
|
func GamesIsNil() predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldIsNull(FieldGames))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GamesNotNil applies the NotNil predicate on the "games" field.
|
||||||
|
func GamesNotNil() predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNotNull(FieldGames))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtEQ(v time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtNEQ(v time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||||
|
func CreatedAtIn(vs ...time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotIn(vs ...time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||||
|
func CreatedAtGT(v time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtGTE(v time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||||
|
func CreatedAtLT(v time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtLTE(v time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtEQ(v time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNEQ(v time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIn(vs ...time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotIn(vs ...time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGT(v time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGTE(v time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldGTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLT(v time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLTE(v time.Time) predicate.Players {
|
||||||
|
return predicate.Players(sql.FieldLTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.Players) predicate.Players {
|
||||||
|
return predicate.Players(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.Players) predicate.Players {
|
||||||
|
return predicate.Players(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.Players) predicate.Players {
|
||||||
|
return predicate.Players(sql.NotPredicates(p))
|
||||||
|
}
|
||||||
@@ -0,0 +1,409 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/players"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/lib/pq"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PlayersCreate is the builder for creating a Players entity.
|
||||||
|
type PlayersCreate struct {
|
||||||
|
config
|
||||||
|
mutation *PlayersMutation
|
||||||
|
hooks []Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (_c *PlayersCreate) SetUserID(v int64) *PlayersCreate {
|
||||||
|
_c.mutation.SetUserID(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets the "status" field.
|
||||||
|
func (_c *PlayersCreate) SetStatus(v string) *PlayersCreate {
|
||||||
|
_c.mutation.SetStatus(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||||
|
func (_c *PlayersCreate) SetNillableStatus(v *string) *PlayersCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetStatus(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGender sets the "gender" field.
|
||||||
|
func (_c *PlayersCreate) SetGender(v int) *PlayersCreate {
|
||||||
|
_c.mutation.SetGender(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRating sets the "rating" field.
|
||||||
|
func (_c *PlayersCreate) SetRating(v decimal.Decimal) *PlayersCreate {
|
||||||
|
_c.mutation.SetRating(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableRating sets the "rating" field if the given value is not nil.
|
||||||
|
func (_c *PlayersCreate) SetNillableRating(v *decimal.Decimal) *PlayersCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetRating(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTotalOrders sets the "total_orders" field.
|
||||||
|
func (_c *PlayersCreate) SetTotalOrders(v int) *PlayersCreate {
|
||||||
|
_c.mutation.SetTotalOrders(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableTotalOrders sets the "total_orders" field if the given value is not nil.
|
||||||
|
func (_c *PlayersCreate) SetNillableTotalOrders(v *int) *PlayersCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetTotalOrders(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCompletedOrders sets the "completed_orders" field.
|
||||||
|
func (_c *PlayersCreate) SetCompletedOrders(v int) *PlayersCreate {
|
||||||
|
_c.mutation.SetCompletedOrders(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCompletedOrders sets the "completed_orders" field if the given value is not nil.
|
||||||
|
func (_c *PlayersCreate) SetNillableCompletedOrders(v *int) *PlayersCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetCompletedOrders(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetShopID sets the "shop_id" field.
|
||||||
|
func (_c *PlayersCreate) SetShopID(v int64) *PlayersCreate {
|
||||||
|
_c.mutation.SetShopID(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableShopID sets the "shop_id" field if the given value is not nil.
|
||||||
|
func (_c *PlayersCreate) SetNillableShopID(v *int64) *PlayersCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetShopID(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTags sets the "tags" field.
|
||||||
|
func (_c *PlayersCreate) SetTags(v []string) *PlayersCreate {
|
||||||
|
_c.mutation.SetTags(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGames sets the "games" field.
|
||||||
|
func (_c *PlayersCreate) SetGames(v pq.Int64Array) *PlayersCreate {
|
||||||
|
_c.mutation.SetGames(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (_c *PlayersCreate) SetCreatedAt(v time.Time) *PlayersCreate {
|
||||||
|
_c.mutation.SetCreatedAt(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (_c *PlayersCreate) SetNillableCreatedAt(v *time.Time) *PlayersCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetCreatedAt(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_c *PlayersCreate) SetUpdatedAt(v time.Time) *PlayersCreate {
|
||||||
|
_c.mutation.SetUpdatedAt(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||||
|
func (_c *PlayersCreate) SetNillableUpdatedAt(v *time.Time) *PlayersCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetUpdatedAt(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the "id" field.
|
||||||
|
func (_c *PlayersCreate) SetID(v int64) *PlayersCreate {
|
||||||
|
_c.mutation.SetID(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the PlayersMutation object of the builder.
|
||||||
|
func (_c *PlayersCreate) Mutation() *PlayersMutation {
|
||||||
|
return _c.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Players in the database.
|
||||||
|
func (_c *PlayersCreate) Save(ctx context.Context) (*Players, error) {
|
||||||
|
_c.defaults()
|
||||||
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (_c *PlayersCreate) SaveX(ctx context.Context) *Players {
|
||||||
|
v, err := _c.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_c *PlayersCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := _c.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_c *PlayersCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := _c.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (_c *PlayersCreate) defaults() {
|
||||||
|
if _, ok := _c.mutation.Status(); !ok {
|
||||||
|
v := players.DefaultStatus
|
||||||
|
_c.mutation.SetStatus(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.Rating(); !ok {
|
||||||
|
v := players.DefaultRating
|
||||||
|
_c.mutation.SetRating(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.TotalOrders(); !ok {
|
||||||
|
v := players.DefaultTotalOrders
|
||||||
|
_c.mutation.SetTotalOrders(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.CompletedOrders(); !ok {
|
||||||
|
v := players.DefaultCompletedOrders
|
||||||
|
_c.mutation.SetCompletedOrders(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.Tags(); !ok {
|
||||||
|
v := players.DefaultTags
|
||||||
|
_c.mutation.SetTags(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.Games(); !ok {
|
||||||
|
v := players.DefaultGames
|
||||||
|
_c.mutation.SetGames(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||||
|
v := players.DefaultCreatedAt()
|
||||||
|
_c.mutation.SetCreatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||||
|
v := players.DefaultUpdatedAt()
|
||||||
|
_c.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_c *PlayersCreate) check() error {
|
||||||
|
if _, ok := _c.mutation.UserID(); !ok {
|
||||||
|
return &ValidationError{Name: "user_id", err: errors.New(`models: missing required field "Players.user_id"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.Status(); !ok {
|
||||||
|
return &ValidationError{Name: "status", err: errors.New(`models: missing required field "Players.status"`)}
|
||||||
|
}
|
||||||
|
if v, ok := _c.mutation.Status(); ok {
|
||||||
|
if err := players.StatusValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "status", err: fmt.Errorf(`models: validator failed for field "Players.status": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.Gender(); !ok {
|
||||||
|
return &ValidationError{Name: "gender", err: errors.New(`models: missing required field "Players.gender"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "created_at", err: errors.New(`models: missing required field "Players.created_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "updated_at", err: errors.New(`models: missing required field "Players.updated_at"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_c *PlayersCreate) sqlSave(ctx context.Context) (*Players, error) {
|
||||||
|
if err := _c.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_node, _spec := _c.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if _spec.ID.Value != _node.ID {
|
||||||
|
id := _spec.ID.Value.(int64)
|
||||||
|
_node.ID = int64(id)
|
||||||
|
}
|
||||||
|
_c.mutation.id = &_node.ID
|
||||||
|
_c.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_c *PlayersCreate) createSpec() (*Players, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &Players{config: _c.config}
|
||||||
|
_spec = sqlgraph.NewCreateSpec(players.Table, sqlgraph.NewFieldSpec(players.FieldID, field.TypeInt64))
|
||||||
|
)
|
||||||
|
if id, ok := _c.mutation.ID(); ok {
|
||||||
|
_node.ID = id
|
||||||
|
_spec.ID.Value = id
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.UserID(); ok {
|
||||||
|
_spec.SetField(players.FieldUserID, field.TypeInt64, value)
|
||||||
|
_node.UserID = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.Status(); ok {
|
||||||
|
_spec.SetField(players.FieldStatus, field.TypeString, value)
|
||||||
|
_node.Status = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.Gender(); ok {
|
||||||
|
_spec.SetField(players.FieldGender, field.TypeInt, value)
|
||||||
|
_node.Gender = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.Rating(); ok {
|
||||||
|
_spec.SetField(players.FieldRating, field.TypeOther, value)
|
||||||
|
_node.Rating = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.TotalOrders(); ok {
|
||||||
|
_spec.SetField(players.FieldTotalOrders, field.TypeInt, value)
|
||||||
|
_node.TotalOrders = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.CompletedOrders(); ok {
|
||||||
|
_spec.SetField(players.FieldCompletedOrders, field.TypeInt, value)
|
||||||
|
_node.CompletedOrders = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.ShopID(); ok {
|
||||||
|
_spec.SetField(players.FieldShopID, field.TypeInt64, value)
|
||||||
|
_node.ShopID = &value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.Tags(); ok {
|
||||||
|
_spec.SetField(players.FieldTags, field.TypeJSON, value)
|
||||||
|
_node.Tags = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.Games(); ok {
|
||||||
|
_spec.SetField(players.FieldGames, field.TypeOther, value)
|
||||||
|
_node.Games = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(players.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
_node.CreatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(players.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
_node.UpdatedAt = value
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// PlayersCreateBulk is the builder for creating many Players entities in bulk.
|
||||||
|
type PlayersCreateBulk struct {
|
||||||
|
config
|
||||||
|
err error
|
||||||
|
builders []*PlayersCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Players entities in the database.
|
||||||
|
func (_c *PlayersCreateBulk) Save(ctx context.Context) ([]*Players, error) {
|
||||||
|
if _c.err != nil {
|
||||||
|
return nil, _c.err
|
||||||
|
}
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||||
|
nodes := make([]*Players, len(_c.builders))
|
||||||
|
mutators := make([]Mutator, len(_c.builders))
|
||||||
|
for i := range _c.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := _c.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*PlayersMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
var err error
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||||
|
} else {
|
||||||
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||||
|
// Invoke the actual operation on the latest mutation in the chain.
|
||||||
|
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
|
||||||
|
id := specs[i].ID.Value.(int64)
|
||||||
|
nodes[i].ID = int64(id)
|
||||||
|
}
|
||||||
|
mutation.done = true
|
||||||
|
return nodes[i], nil
|
||||||
|
})
|
||||||
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||||
|
mut = builder.hooks[i](mut)
|
||||||
|
}
|
||||||
|
mutators[i] = mut
|
||||||
|
}(i, ctx)
|
||||||
|
}
|
||||||
|
if len(mutators) > 0 {
|
||||||
|
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_c *PlayersCreateBulk) SaveX(ctx context.Context) []*Players {
|
||||||
|
v, err := _c.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_c *PlayersCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := _c.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_c *PlayersCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := _c.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/players"
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/predicate"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PlayersDelete is the builder for deleting a Players entity.
|
||||||
|
type PlayersDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *PlayersMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the PlayersDelete builder.
|
||||||
|
func (_d *PlayersDelete) Where(ps ...predicate.Players) *PlayersDelete {
|
||||||
|
_d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (_d *PlayersDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_d *PlayersDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := _d.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_d *PlayersDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(players.Table, sqlgraph.NewFieldSpec(players.FieldID, field.TypeInt64))
|
||||||
|
if ps := _d.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||||
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
_d.mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// PlayersDeleteOne is the builder for deleting a single Players entity.
|
||||||
|
type PlayersDeleteOne struct {
|
||||||
|
_d *PlayersDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the PlayersDelete builder.
|
||||||
|
func (_d *PlayersDeleteOne) Where(ps ...predicate.Players) *PlayersDeleteOne {
|
||||||
|
_d._d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (_d *PlayersDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := _d._d.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{players.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_d *PlayersDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := _d.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,527 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/players"
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/predicate"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PlayersQuery is the builder for querying Players entities.
|
||||||
|
type PlayersQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []players.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.Players
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the PlayersQuery builder.
|
||||||
|
func (_q *PlayersQuery) Where(ps ...predicate.Players) *PlayersQuery {
|
||||||
|
_q.predicates = append(_q.predicates, ps...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (_q *PlayersQuery) Limit(limit int) *PlayersQuery {
|
||||||
|
_q.ctx.Limit = &limit
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (_q *PlayersQuery) Offset(offset int) *PlayersQuery {
|
||||||
|
_q.ctx.Offset = &offset
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unique configures the query builder to filter duplicate records on query.
|
||||||
|
// By default, unique is set to true, and can be disabled using this method.
|
||||||
|
func (_q *PlayersQuery) Unique(unique bool) *PlayersQuery {
|
||||||
|
_q.ctx.Unique = &unique
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (_q *PlayersQuery) Order(o ...players.OrderOption) *PlayersQuery {
|
||||||
|
_q.order = append(_q.order, o...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first Players entity from the query.
|
||||||
|
// Returns a *NotFoundError when no Players was found.
|
||||||
|
func (_q *PlayersQuery) First(ctx context.Context) (*Players, error) {
|
||||||
|
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{players.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (_q *PlayersQuery) FirstX(ctx context.Context) *Players {
|
||||||
|
node, err := _q.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first Players ID from the query.
|
||||||
|
// Returns a *NotFoundError when no Players ID was found.
|
||||||
|
func (_q *PlayersQuery) FirstID(ctx context.Context) (id int64, err error) {
|
||||||
|
var ids []int64
|
||||||
|
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{players.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (_q *PlayersQuery) FirstIDX(ctx context.Context) int64 {
|
||||||
|
id, err := _q.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single Players entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one Players entity is found.
|
||||||
|
// Returns a *NotFoundError when no Players entities are found.
|
||||||
|
func (_q *PlayersQuery) Only(ctx context.Context) (*Players, error) {
|
||||||
|
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{players.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{players.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (_q *PlayersQuery) OnlyX(ctx context.Context) *Players {
|
||||||
|
node, err := _q.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only Players ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one Players ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (_q *PlayersQuery) OnlyID(ctx context.Context) (id int64, err error) {
|
||||||
|
var ids []int64
|
||||||
|
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{players.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{players.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (_q *PlayersQuery) OnlyIDX(ctx context.Context) int64 {
|
||||||
|
id, err := _q.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of PlayersSlice.
|
||||||
|
func (_q *PlayersQuery) All(ctx context.Context) ([]*Players, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||||
|
if err := _q.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*Players, *PlayersQuery]()
|
||||||
|
return withInterceptors[[]*Players](ctx, _q, qr, _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (_q *PlayersQuery) AllX(ctx context.Context) []*Players {
|
||||||
|
nodes, err := _q.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of Players IDs.
|
||||||
|
func (_q *PlayersQuery) IDs(ctx context.Context) (ids []int64, err error) {
|
||||||
|
if _q.ctx.Unique == nil && _q.path != nil {
|
||||||
|
_q.Unique(true)
|
||||||
|
}
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||||
|
if err = _q.Select(players.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (_q *PlayersQuery) IDsX(ctx context.Context) []int64 {
|
||||||
|
ids, err := _q.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (_q *PlayersQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||||
|
if err := _q.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return withInterceptors[int](ctx, _q, querierCount[*PlayersQuery](), _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (_q *PlayersQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := _q.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (_q *PlayersQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||||
|
switch _, err := _q.FirstID(ctx); {
|
||||||
|
case IsNotFound(err):
|
||||||
|
return false, nil
|
||||||
|
case err != nil:
|
||||||
|
return false, fmt.Errorf("models: check existence: %w", err)
|
||||||
|
default:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (_q *PlayersQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := _q.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the PlayersQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (_q *PlayersQuery) Clone() *PlayersQuery {
|
||||||
|
if _q == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &PlayersQuery{
|
||||||
|
config: _q.config,
|
||||||
|
ctx: _q.ctx.Clone(),
|
||||||
|
order: append([]players.OrderOption{}, _q.order...),
|
||||||
|
inters: append([]Interceptor{}, _q.inters...),
|
||||||
|
predicates: append([]predicate.Players{}, _q.predicates...),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: _q.sql.Clone(),
|
||||||
|
path: _q.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupBy is used to group vertices by one or more fields/columns.
|
||||||
|
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// UserID int64 `json:"user_id,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Players.Query().
|
||||||
|
// GroupBy(players.FieldUserID).
|
||||||
|
// Aggregate(models.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *PlayersQuery) GroupBy(field string, fields ...string) *PlayersGroupBy {
|
||||||
|
_q.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &PlayersGroupBy{build: _q}
|
||||||
|
grbuild.flds = &_q.ctx.Fields
|
||||||
|
grbuild.label = players.Label
|
||||||
|
grbuild.scan = grbuild.Scan
|
||||||
|
return grbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows the selection one or more fields/columns for the given query,
|
||||||
|
// instead of selecting all fields in the entity.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// UserID int64 `json:"user_id,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Players.Query().
|
||||||
|
// Select(players.FieldUserID).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *PlayersQuery) Select(fields ...string) *PlayersSelect {
|
||||||
|
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||||
|
sbuild := &PlayersSelect{PlayersQuery: _q}
|
||||||
|
sbuild.label = players.Label
|
||||||
|
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a PlayersSelect configured with the given aggregations.
|
||||||
|
func (_q *PlayersQuery) Aggregate(fns ...AggregateFunc) *PlayersSelect {
|
||||||
|
return _q.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *PlayersQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, inter := range _q.inters {
|
||||||
|
if inter == nil {
|
||||||
|
return fmt.Errorf("models: uninitialized interceptor (forgotten import models/runtime?)")
|
||||||
|
}
|
||||||
|
if trv, ok := inter.(Traverser); ok {
|
||||||
|
if err := trv.Traverse(ctx, _q); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range _q.ctx.Fields {
|
||||||
|
if !players.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _q.path != nil {
|
||||||
|
prev, err := _q.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_q.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *PlayersQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Players, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*Players{}
|
||||||
|
_spec = _q.querySpec()
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*Players).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &Players{config: _q.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
for i := range hooks {
|
||||||
|
hooks[i](ctx, _spec)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *PlayersQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := _q.querySpec()
|
||||||
|
_spec.Node.Columns = _q.ctx.Fields
|
||||||
|
if len(_q.ctx.Fields) > 0 {
|
||||||
|
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *PlayersQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(players.Table, players.Columns, sqlgraph.NewFieldSpec(players.FieldID, field.TypeInt64))
|
||||||
|
_spec.From = _q.sql
|
||||||
|
if unique := _q.ctx.Unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
} else if _q.path != nil {
|
||||||
|
_spec.Unique = true
|
||||||
|
}
|
||||||
|
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, players.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != players.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := _q.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := _q.ctx.Limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := _q.ctx.Offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := _q.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *PlayersQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(_q.driver.Dialect())
|
||||||
|
t1 := builder.Table(players.Table)
|
||||||
|
columns := _q.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = players.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if _q.sql != nil {
|
||||||
|
selector = _q.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, p := range _q.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range _q.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := _q.ctx.Offset; offset != nil {
|
||||||
|
// limit is mandatory for offset clause. We start
|
||||||
|
// with default value, and override it below if needed.
|
||||||
|
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||||
|
}
|
||||||
|
if limit := _q.ctx.Limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// PlayersGroupBy is the group-by builder for Players entities.
|
||||||
|
type PlayersGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *PlayersQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (_g *PlayersGroupBy) Aggregate(fns ...AggregateFunc) *PlayersGroupBy {
|
||||||
|
_g.fns = append(_g.fns, fns...)
|
||||||
|
return _g
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_g *PlayersGroupBy) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||||
|
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*PlayersQuery, *PlayersGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_g *PlayersGroupBy) sqlScan(ctx context.Context, root *PlayersQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx).Select()
|
||||||
|
aggregation := make([]string, 0, len(_g.fns))
|
||||||
|
for _, fn := range _g.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||||
|
for _, f := range *_g.flds {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PlayersSelect is the builder for selecting fields of Players entities.
|
||||||
|
type PlayersSelect struct {
|
||||||
|
*PlayersQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (_s *PlayersSelect) Aggregate(fns ...AggregateFunc) *PlayersSelect {
|
||||||
|
_s.fns = append(_s.fns, fns...)
|
||||||
|
return _s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_s *PlayersSelect) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||||
|
if err := _s.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*PlayersQuery, *PlayersSelect](ctx, _s.PlayersQuery, _s, _s.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_s *PlayersSelect) sqlScan(ctx context.Context, root *PlayersQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx)
|
||||||
|
aggregation := make([]string, 0, len(_s.fns))
|
||||||
|
for _, fn := range _s.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
switch n := len(*_s.selector.flds); {
|
||||||
|
case n == 0 && len(aggregation) > 0:
|
||||||
|
selector.Select(aggregation...)
|
||||||
|
case n != 0 && len(aggregation) > 0:
|
||||||
|
selector.AppendSelect(aggregation...)
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
@@ -0,0 +1,745 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/players"
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/predicate"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/dialect/sql/sqljson"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/lib/pq"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PlayersUpdate is the builder for updating Players entities.
|
||||||
|
type PlayersUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *PlayersMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the PlayersUpdate builder.
|
||||||
|
func (_u *PlayersUpdate) Where(ps ...predicate.Players) *PlayersUpdate {
|
||||||
|
_u.mutation.Where(ps...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (_u *PlayersUpdate) SetUserID(v int64) *PlayersUpdate {
|
||||||
|
_u.mutation.ResetUserID()
|
||||||
|
_u.mutation.SetUserID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||||
|
func (_u *PlayersUpdate) SetNillableUserID(v *int64) *PlayersUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetUserID(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddUserID adds value to the "user_id" field.
|
||||||
|
func (_u *PlayersUpdate) AddUserID(v int64) *PlayersUpdate {
|
||||||
|
_u.mutation.AddUserID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets the "status" field.
|
||||||
|
func (_u *PlayersUpdate) SetStatus(v string) *PlayersUpdate {
|
||||||
|
_u.mutation.SetStatus(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||||
|
func (_u *PlayersUpdate) SetNillableStatus(v *string) *PlayersUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetStatus(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGender sets the "gender" field.
|
||||||
|
func (_u *PlayersUpdate) SetGender(v int) *PlayersUpdate {
|
||||||
|
_u.mutation.ResetGender()
|
||||||
|
_u.mutation.SetGender(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableGender sets the "gender" field if the given value is not nil.
|
||||||
|
func (_u *PlayersUpdate) SetNillableGender(v *int) *PlayersUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetGender(*v)
|
||||||
|
}
|
||||||
|
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.
|
||||||
|
func (_u *PlayersUpdate) SetRating(v decimal.Decimal) *PlayersUpdate {
|
||||||
|
_u.mutation.SetRating(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableRating sets the "rating" field if the given value is not nil.
|
||||||
|
func (_u *PlayersUpdate) SetNillableRating(v *decimal.Decimal) *PlayersUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetRating(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearRating clears the value of the "rating" field.
|
||||||
|
func (_u *PlayersUpdate) ClearRating() *PlayersUpdate {
|
||||||
|
_u.mutation.ClearRating()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTotalOrders sets the "total_orders" field.
|
||||||
|
func (_u *PlayersUpdate) SetTotalOrders(v int) *PlayersUpdate {
|
||||||
|
_u.mutation.ResetTotalOrders()
|
||||||
|
_u.mutation.SetTotalOrders(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableTotalOrders sets the "total_orders" field if the given value is not nil.
|
||||||
|
func (_u *PlayersUpdate) SetNillableTotalOrders(v *int) *PlayersUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetTotalOrders(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddTotalOrders adds value to the "total_orders" field.
|
||||||
|
func (_u *PlayersUpdate) AddTotalOrders(v int) *PlayersUpdate {
|
||||||
|
_u.mutation.AddTotalOrders(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearTotalOrders clears the value of the "total_orders" field.
|
||||||
|
func (_u *PlayersUpdate) ClearTotalOrders() *PlayersUpdate {
|
||||||
|
_u.mutation.ClearTotalOrders()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCompletedOrders sets the "completed_orders" field.
|
||||||
|
func (_u *PlayersUpdate) SetCompletedOrders(v int) *PlayersUpdate {
|
||||||
|
_u.mutation.ResetCompletedOrders()
|
||||||
|
_u.mutation.SetCompletedOrders(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCompletedOrders sets the "completed_orders" field if the given value is not nil.
|
||||||
|
func (_u *PlayersUpdate) SetNillableCompletedOrders(v *int) *PlayersUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetCompletedOrders(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddCompletedOrders adds value to the "completed_orders" field.
|
||||||
|
func (_u *PlayersUpdate) AddCompletedOrders(v int) *PlayersUpdate {
|
||||||
|
_u.mutation.AddCompletedOrders(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearCompletedOrders clears the value of the "completed_orders" field.
|
||||||
|
func (_u *PlayersUpdate) ClearCompletedOrders() *PlayersUpdate {
|
||||||
|
_u.mutation.ClearCompletedOrders()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetShopID sets the "shop_id" field.
|
||||||
|
func (_u *PlayersUpdate) SetShopID(v int64) *PlayersUpdate {
|
||||||
|
_u.mutation.ResetShopID()
|
||||||
|
_u.mutation.SetShopID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableShopID sets the "shop_id" field if the given value is not nil.
|
||||||
|
func (_u *PlayersUpdate) SetNillableShopID(v *int64) *PlayersUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetShopID(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddShopID adds value to the "shop_id" field.
|
||||||
|
func (_u *PlayersUpdate) AddShopID(v int64) *PlayersUpdate {
|
||||||
|
_u.mutation.AddShopID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearShopID clears the value of the "shop_id" field.
|
||||||
|
func (_u *PlayersUpdate) ClearShopID() *PlayersUpdate {
|
||||||
|
_u.mutation.ClearShopID()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTags sets the "tags" field.
|
||||||
|
func (_u *PlayersUpdate) SetTags(v []string) *PlayersUpdate {
|
||||||
|
_u.mutation.SetTags(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AppendTags appends value to the "tags" field.
|
||||||
|
func (_u *PlayersUpdate) AppendTags(v []string) *PlayersUpdate {
|
||||||
|
_u.mutation.AppendTags(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearTags clears the value of the "tags" field.
|
||||||
|
func (_u *PlayersUpdate) ClearTags() *PlayersUpdate {
|
||||||
|
_u.mutation.ClearTags()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGames sets the "games" field.
|
||||||
|
func (_u *PlayersUpdate) SetGames(v pq.Int64Array) *PlayersUpdate {
|
||||||
|
_u.mutation.SetGames(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearGames clears the value of the "games" field.
|
||||||
|
func (_u *PlayersUpdate) ClearGames() *PlayersUpdate {
|
||||||
|
_u.mutation.ClearGames()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_u *PlayersUpdate) SetUpdatedAt(v time.Time) *PlayersUpdate {
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the PlayersMutation object of the builder.
|
||||||
|
func (_u *PlayersUpdate) Mutation() *PlayersMutation {
|
||||||
|
return _u.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (_u *PlayersUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
_u.defaults()
|
||||||
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_u *PlayersUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := _u.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_u *PlayersUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := _u.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *PlayersUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := _u.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (_u *PlayersUpdate) defaults() {
|
||||||
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||||
|
v := players.UpdateDefaultUpdatedAt()
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_u *PlayersUpdate) check() error {
|
||||||
|
if v, ok := _u.mutation.Status(); ok {
|
||||||
|
if err := players.StatusValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "status", err: fmt.Errorf(`models: validator failed for field "Players.status": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_u *PlayersUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||||
|
if err := _u.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(players.Table, players.Columns, sqlgraph.NewFieldSpec(players.FieldID, field.TypeInt64))
|
||||||
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.UserID(); ok {
|
||||||
|
_spec.SetField(players.FieldUserID, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedUserID(); ok {
|
||||||
|
_spec.AddField(players.FieldUserID, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Status(); ok {
|
||||||
|
_spec.SetField(players.FieldStatus, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Gender(); ok {
|
||||||
|
_spec.SetField(players.FieldGender, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedGender(); ok {
|
||||||
|
_spec.AddField(players.FieldGender, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Rating(); ok {
|
||||||
|
_spec.SetField(players.FieldRating, field.TypeOther, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.RatingCleared() {
|
||||||
|
_spec.ClearField(players.FieldRating, field.TypeOther)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.TotalOrders(); ok {
|
||||||
|
_spec.SetField(players.FieldTotalOrders, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedTotalOrders(); ok {
|
||||||
|
_spec.AddField(players.FieldTotalOrders, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.TotalOrdersCleared() {
|
||||||
|
_spec.ClearField(players.FieldTotalOrders, field.TypeInt)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.CompletedOrders(); ok {
|
||||||
|
_spec.SetField(players.FieldCompletedOrders, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedCompletedOrders(); ok {
|
||||||
|
_spec.AddField(players.FieldCompletedOrders, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.CompletedOrdersCleared() {
|
||||||
|
_spec.ClearField(players.FieldCompletedOrders, field.TypeInt)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ShopID(); ok {
|
||||||
|
_spec.SetField(players.FieldShopID, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedShopID(); ok {
|
||||||
|
_spec.AddField(players.FieldShopID, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.ShopIDCleared() {
|
||||||
|
_spec.ClearField(players.FieldShopID, field.TypeInt64)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Tags(); ok {
|
||||||
|
_spec.SetField(players.FieldTags, field.TypeJSON, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AppendedTags(); ok {
|
||||||
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
||||||
|
sqljson.Append(u, players.FieldTags, value)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if _u.mutation.TagsCleared() {
|
||||||
|
_spec.ClearField(players.FieldTags, field.TypeJSON)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Games(); ok {
|
||||||
|
_spec.SetField(players.FieldGames, field.TypeOther, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.GamesCleared() {
|
||||||
|
_spec.ClearField(players.FieldGames, field.TypeOther)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(players.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{players.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
_u.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// PlayersUpdateOne is the builder for updating a single Players entity.
|
||||||
|
type PlayersUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *PlayersMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (_u *PlayersUpdateOne) SetUserID(v int64) *PlayersUpdateOne {
|
||||||
|
_u.mutation.ResetUserID()
|
||||||
|
_u.mutation.SetUserID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||||
|
func (_u *PlayersUpdateOne) SetNillableUserID(v *int64) *PlayersUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetUserID(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddUserID adds value to the "user_id" field.
|
||||||
|
func (_u *PlayersUpdateOne) AddUserID(v int64) *PlayersUpdateOne {
|
||||||
|
_u.mutation.AddUserID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets the "status" field.
|
||||||
|
func (_u *PlayersUpdateOne) SetStatus(v string) *PlayersUpdateOne {
|
||||||
|
_u.mutation.SetStatus(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||||
|
func (_u *PlayersUpdateOne) SetNillableStatus(v *string) *PlayersUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetStatus(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGender sets the "gender" field.
|
||||||
|
func (_u *PlayersUpdateOne) SetGender(v int) *PlayersUpdateOne {
|
||||||
|
_u.mutation.ResetGender()
|
||||||
|
_u.mutation.SetGender(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableGender sets the "gender" field if the given value is not nil.
|
||||||
|
func (_u *PlayersUpdateOne) SetNillableGender(v *int) *PlayersUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetGender(*v)
|
||||||
|
}
|
||||||
|
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.
|
||||||
|
func (_u *PlayersUpdateOne) SetRating(v decimal.Decimal) *PlayersUpdateOne {
|
||||||
|
_u.mutation.SetRating(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableRating sets the "rating" field if the given value is not nil.
|
||||||
|
func (_u *PlayersUpdateOne) SetNillableRating(v *decimal.Decimal) *PlayersUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetRating(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearRating clears the value of the "rating" field.
|
||||||
|
func (_u *PlayersUpdateOne) ClearRating() *PlayersUpdateOne {
|
||||||
|
_u.mutation.ClearRating()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTotalOrders sets the "total_orders" field.
|
||||||
|
func (_u *PlayersUpdateOne) SetTotalOrders(v int) *PlayersUpdateOne {
|
||||||
|
_u.mutation.ResetTotalOrders()
|
||||||
|
_u.mutation.SetTotalOrders(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableTotalOrders sets the "total_orders" field if the given value is not nil.
|
||||||
|
func (_u *PlayersUpdateOne) SetNillableTotalOrders(v *int) *PlayersUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetTotalOrders(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddTotalOrders adds value to the "total_orders" field.
|
||||||
|
func (_u *PlayersUpdateOne) AddTotalOrders(v int) *PlayersUpdateOne {
|
||||||
|
_u.mutation.AddTotalOrders(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearTotalOrders clears the value of the "total_orders" field.
|
||||||
|
func (_u *PlayersUpdateOne) ClearTotalOrders() *PlayersUpdateOne {
|
||||||
|
_u.mutation.ClearTotalOrders()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCompletedOrders sets the "completed_orders" field.
|
||||||
|
func (_u *PlayersUpdateOne) SetCompletedOrders(v int) *PlayersUpdateOne {
|
||||||
|
_u.mutation.ResetCompletedOrders()
|
||||||
|
_u.mutation.SetCompletedOrders(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCompletedOrders sets the "completed_orders" field if the given value is not nil.
|
||||||
|
func (_u *PlayersUpdateOne) SetNillableCompletedOrders(v *int) *PlayersUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetCompletedOrders(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddCompletedOrders adds value to the "completed_orders" field.
|
||||||
|
func (_u *PlayersUpdateOne) AddCompletedOrders(v int) *PlayersUpdateOne {
|
||||||
|
_u.mutation.AddCompletedOrders(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearCompletedOrders clears the value of the "completed_orders" field.
|
||||||
|
func (_u *PlayersUpdateOne) ClearCompletedOrders() *PlayersUpdateOne {
|
||||||
|
_u.mutation.ClearCompletedOrders()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetShopID sets the "shop_id" field.
|
||||||
|
func (_u *PlayersUpdateOne) SetShopID(v int64) *PlayersUpdateOne {
|
||||||
|
_u.mutation.ResetShopID()
|
||||||
|
_u.mutation.SetShopID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableShopID sets the "shop_id" field if the given value is not nil.
|
||||||
|
func (_u *PlayersUpdateOne) SetNillableShopID(v *int64) *PlayersUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetShopID(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddShopID adds value to the "shop_id" field.
|
||||||
|
func (_u *PlayersUpdateOne) AddShopID(v int64) *PlayersUpdateOne {
|
||||||
|
_u.mutation.AddShopID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearShopID clears the value of the "shop_id" field.
|
||||||
|
func (_u *PlayersUpdateOne) ClearShopID() *PlayersUpdateOne {
|
||||||
|
_u.mutation.ClearShopID()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTags sets the "tags" field.
|
||||||
|
func (_u *PlayersUpdateOne) SetTags(v []string) *PlayersUpdateOne {
|
||||||
|
_u.mutation.SetTags(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AppendTags appends value to the "tags" field.
|
||||||
|
func (_u *PlayersUpdateOne) AppendTags(v []string) *PlayersUpdateOne {
|
||||||
|
_u.mutation.AppendTags(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearTags clears the value of the "tags" field.
|
||||||
|
func (_u *PlayersUpdateOne) ClearTags() *PlayersUpdateOne {
|
||||||
|
_u.mutation.ClearTags()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGames sets the "games" field.
|
||||||
|
func (_u *PlayersUpdateOne) SetGames(v pq.Int64Array) *PlayersUpdateOne {
|
||||||
|
_u.mutation.SetGames(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearGames clears the value of the "games" field.
|
||||||
|
func (_u *PlayersUpdateOne) ClearGames() *PlayersUpdateOne {
|
||||||
|
_u.mutation.ClearGames()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_u *PlayersUpdateOne) SetUpdatedAt(v time.Time) *PlayersUpdateOne {
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the PlayersMutation object of the builder.
|
||||||
|
func (_u *PlayersUpdateOne) Mutation() *PlayersMutation {
|
||||||
|
return _u.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the PlayersUpdate builder.
|
||||||
|
func (_u *PlayersUpdateOne) Where(ps ...predicate.Players) *PlayersUpdateOne {
|
||||||
|
_u.mutation.Where(ps...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (_u *PlayersUpdateOne) Select(field string, fields ...string) *PlayersUpdateOne {
|
||||||
|
_u.fields = append([]string{field}, fields...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated Players entity.
|
||||||
|
func (_u *PlayersUpdateOne) Save(ctx context.Context) (*Players, error) {
|
||||||
|
_u.defaults()
|
||||||
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_u *PlayersUpdateOne) SaveX(ctx context.Context) *Players {
|
||||||
|
node, err := _u.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (_u *PlayersUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := _u.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *PlayersUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := _u.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (_u *PlayersUpdateOne) defaults() {
|
||||||
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||||
|
v := players.UpdateDefaultUpdatedAt()
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_u *PlayersUpdateOne) check() error {
|
||||||
|
if v, ok := _u.mutation.Status(); ok {
|
||||||
|
if err := players.StatusValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "status", err: fmt.Errorf(`models: validator failed for field "Players.status": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_u *PlayersUpdateOne) sqlSave(ctx context.Context) (_node *Players, err error) {
|
||||||
|
if err := _u.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(players.Table, players.Columns, sqlgraph.NewFieldSpec(players.FieldID, field.TypeInt64))
|
||||||
|
id, ok := _u.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "Players.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := _u.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, players.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !players.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != players.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.UserID(); ok {
|
||||||
|
_spec.SetField(players.FieldUserID, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedUserID(); ok {
|
||||||
|
_spec.AddField(players.FieldUserID, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Status(); ok {
|
||||||
|
_spec.SetField(players.FieldStatus, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Gender(); ok {
|
||||||
|
_spec.SetField(players.FieldGender, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedGender(); ok {
|
||||||
|
_spec.AddField(players.FieldGender, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Rating(); ok {
|
||||||
|
_spec.SetField(players.FieldRating, field.TypeOther, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.RatingCleared() {
|
||||||
|
_spec.ClearField(players.FieldRating, field.TypeOther)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.TotalOrders(); ok {
|
||||||
|
_spec.SetField(players.FieldTotalOrders, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedTotalOrders(); ok {
|
||||||
|
_spec.AddField(players.FieldTotalOrders, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.TotalOrdersCleared() {
|
||||||
|
_spec.ClearField(players.FieldTotalOrders, field.TypeInt)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.CompletedOrders(); ok {
|
||||||
|
_spec.SetField(players.FieldCompletedOrders, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedCompletedOrders(); ok {
|
||||||
|
_spec.AddField(players.FieldCompletedOrders, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.CompletedOrdersCleared() {
|
||||||
|
_spec.ClearField(players.FieldCompletedOrders, field.TypeInt)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ShopID(); ok {
|
||||||
|
_spec.SetField(players.FieldShopID, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedShopID(); ok {
|
||||||
|
_spec.AddField(players.FieldShopID, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.ShopIDCleared() {
|
||||||
|
_spec.ClearField(players.FieldShopID, field.TypeInt64)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Tags(); ok {
|
||||||
|
_spec.SetField(players.FieldTags, field.TypeJSON, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AppendedTags(); ok {
|
||||||
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
||||||
|
sqljson.Append(u, players.FieldTags, value)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if _u.mutation.TagsCleared() {
|
||||||
|
_spec.ClearField(players.FieldTags, field.TypeJSON)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Games(); ok {
|
||||||
|
_spec.SetField(players.FieldGames, field.TypeOther, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.GamesCleared() {
|
||||||
|
_spec.ClearField(players.FieldGames, field.TypeOther)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(players.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
_node = &Players{config: _u.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{players.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_u.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,243 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/player/rpc/internal/models/playerservices"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PlayerServices is the model entity for the PlayerServices schema.
|
||||||
|
type PlayerServices struct {
|
||||||
|
config `json:"-"`
|
||||||
|
// ID of the ent.
|
||||||
|
ID int64 `json:"id,omitempty"`
|
||||||
|
// PlayerID holds the value of the "player_id" field.
|
||||||
|
PlayerID int64 `json:"player_id,omitempty"`
|
||||||
|
// GameID holds the value of the "game_id" field.
|
||||||
|
GameID int64 `json:"game_id,omitempty"`
|
||||||
|
// Title holds the value of the "title" field.
|
||||||
|
Title string `json:"title,omitempty"`
|
||||||
|
// Description holds the value of the "description" field.
|
||||||
|
Description *string `json:"description,omitempty"`
|
||||||
|
// Price holds the value of the "price" field.
|
||||||
|
Price decimal.Decimal `json:"price,omitempty"`
|
||||||
|
// Unit holds the value of the "unit" field.
|
||||||
|
Unit string `json:"unit,omitempty"`
|
||||||
|
// RankRange holds the value of the "rank_range" field.
|
||||||
|
RankRange *string `json:"rank_range,omitempty"`
|
||||||
|
// Availability holds the value of the "availability" field.
|
||||||
|
Availability []string `json:"availability,omitempty"`
|
||||||
|
// Rating holds the value of the "rating" field.
|
||||||
|
Rating decimal.Decimal `json:"rating,omitempty"`
|
||||||
|
// IsActive holds the value of the "is_active" field.
|
||||||
|
IsActive bool `json:"is_active,omitempty"`
|
||||||
|
// CreatedAt holds the value of the "created_at" field.
|
||||||
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||||
|
selectValues sql.SelectValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*PlayerServices) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case playerservices.FieldAvailability:
|
||||||
|
values[i] = new([]byte)
|
||||||
|
case playerservices.FieldPrice, playerservices.FieldRating:
|
||||||
|
values[i] = new(decimal.Decimal)
|
||||||
|
case playerservices.FieldIsActive:
|
||||||
|
values[i] = new(sql.NullBool)
|
||||||
|
case playerservices.FieldID, playerservices.FieldPlayerID, playerservices.FieldGameID:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case playerservices.FieldTitle, playerservices.FieldDescription, playerservices.FieldUnit, playerservices.FieldRankRange:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case playerservices.FieldCreatedAt, playerservices.FieldUpdatedAt:
|
||||||
|
values[i] = new(sql.NullTime)
|
||||||
|
default:
|
||||||
|
values[i] = new(sql.UnknownType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the PlayerServices fields.
|
||||||
|
func (_m *PlayerServices) assignValues(columns []string, values []any) error {
|
||||||
|
if m, n := len(values), len(columns); m < n {
|
||||||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||||
|
}
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case playerservices.FieldID:
|
||||||
|
value, ok := values[i].(*sql.NullInt64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||||||
|
}
|
||||||
|
_m.ID = int64(value.Int64)
|
||||||
|
case playerservices.FieldPlayerID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field player_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.PlayerID = value.Int64
|
||||||
|
}
|
||||||
|
case playerservices.FieldGameID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field game_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.GameID = value.Int64
|
||||||
|
}
|
||||||
|
case playerservices.FieldTitle:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field title", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Title = value.String
|
||||||
|
}
|
||||||
|
case playerservices.FieldDescription:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field description", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Description = new(string)
|
||||||
|
*_m.Description = value.String
|
||||||
|
}
|
||||||
|
case playerservices.FieldPrice:
|
||||||
|
if value, ok := values[i].(*decimal.Decimal); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field price", values[i])
|
||||||
|
} else if value != nil {
|
||||||
|
_m.Price = *value
|
||||||
|
}
|
||||||
|
case playerservices.FieldUnit:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field unit", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Unit = value.String
|
||||||
|
}
|
||||||
|
case playerservices.FieldRankRange:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field rank_range", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.RankRange = new(string)
|
||||||
|
*_m.RankRange = value.String
|
||||||
|
}
|
||||||
|
case playerservices.FieldAvailability:
|
||||||
|
if value, ok := values[i].(*[]byte); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field availability", values[i])
|
||||||
|
} else if value != nil && len(*value) > 0 {
|
||||||
|
if err := json.Unmarshal(*value, &_m.Availability); err != nil {
|
||||||
|
return fmt.Errorf("unmarshal field availability: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case playerservices.FieldRating:
|
||||||
|
if value, ok := values[i].(*decimal.Decimal); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field rating", values[i])
|
||||||
|
} else if value != nil {
|
||||||
|
_m.Rating = *value
|
||||||
|
}
|
||||||
|
case playerservices.FieldIsActive:
|
||||||
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field is_active", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.IsActive = value.Bool
|
||||||
|
}
|
||||||
|
case playerservices.FieldCreatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.CreatedAt = value.Time
|
||||||
|
}
|
||||||
|
case playerservices.FieldUpdatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.UpdatedAt = value.Time
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
_m.selectValues.Set(columns[i], values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the PlayerServices.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (_m *PlayerServices) Value(name string) (ent.Value, error) {
|
||||||
|
return _m.selectValues.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this PlayerServices.
|
||||||
|
// Note that you need to call PlayerServices.Unwrap() before calling this method if this PlayerServices
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (_m *PlayerServices) Update() *PlayerServicesUpdateOne {
|
||||||
|
return NewPlayerServicesClient(_m.config).UpdateOne(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the PlayerServices entity that was returned from a transaction after it was closed,
|
||||||
|
// so that all future queries will be executed through the driver which created the transaction.
|
||||||
|
func (_m *PlayerServices) Unwrap() *PlayerServices {
|
||||||
|
_tx, ok := _m.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("models: PlayerServices is not a transactional entity")
|
||||||
|
}
|
||||||
|
_m.config.driver = _tx.drv
|
||||||
|
return _m
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (_m *PlayerServices) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("PlayerServices(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||||
|
builder.WriteString("player_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.PlayerID))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("game_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.GameID))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("title=")
|
||||||
|
builder.WriteString(_m.Title)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.Description; v != nil {
|
||||||
|
builder.WriteString("description=")
|
||||||
|
builder.WriteString(*v)
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("price=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.Price))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("unit=")
|
||||||
|
builder.WriteString(_m.Unit)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.RankRange; v != nil {
|
||||||
|
builder.WriteString("rank_range=")
|
||||||
|
builder.WriteString(*v)
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("availability=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.Availability))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("rating=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.Rating))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("is_active=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.IsActive))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("created_at=")
|
||||||
|
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("updated_at=")
|
||||||
|
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// PlayerServicesSlice is a parsable slice of PlayerServices.
|
||||||
|
type PlayerServicesSlice []*PlayerServices
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package playerservices
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the playerservices type in the database.
|
||||||
|
Label = "player_services"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldPlayerID holds the string denoting the player_id field in the database.
|
||||||
|
FieldPlayerID = "player_id"
|
||||||
|
// FieldGameID holds the string denoting the game_id field in the database.
|
||||||
|
FieldGameID = "game_id"
|
||||||
|
// FieldTitle holds the string denoting the title field in the database.
|
||||||
|
FieldTitle = "title"
|
||||||
|
// FieldDescription holds the string denoting the description field in the database.
|
||||||
|
FieldDescription = "description"
|
||||||
|
// FieldPrice holds the string denoting the price field in the database.
|
||||||
|
FieldPrice = "price"
|
||||||
|
// FieldUnit holds the string denoting the unit field in the database.
|
||||||
|
FieldUnit = "unit"
|
||||||
|
// FieldRankRange holds the string denoting the rank_range field in the database.
|
||||||
|
FieldRankRange = "rank_range"
|
||||||
|
// FieldAvailability holds the string denoting the availability field in the database.
|
||||||
|
FieldAvailability = "availability"
|
||||||
|
// FieldRating holds the string denoting the rating field in the database.
|
||||||
|
FieldRating = "rating"
|
||||||
|
// FieldIsActive holds the string denoting the is_active field in the database.
|
||||||
|
FieldIsActive = "is_active"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// Table holds the table name of the playerservices in the database.
|
||||||
|
Table = "player_services"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for playerservices fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldPlayerID,
|
||||||
|
FieldGameID,
|
||||||
|
FieldTitle,
|
||||||
|
FieldDescription,
|
||||||
|
FieldPrice,
|
||||||
|
FieldUnit,
|
||||||
|
FieldRankRange,
|
||||||
|
FieldAvailability,
|
||||||
|
FieldRating,
|
||||||
|
FieldIsActive,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// TitleValidator is a validator for the "title" field. It is called by the builders before save.
|
||||||
|
TitleValidator func(string) error
|
||||||
|
// UnitValidator is a validator for the "unit" field. It is called by the builders before save.
|
||||||
|
UnitValidator func(string) error
|
||||||
|
// RankRangeValidator is a validator for the "rank_range" field. It is called by the builders before save.
|
||||||
|
RankRangeValidator func(string) error
|
||||||
|
// DefaultAvailability holds the default value on creation for the "availability" field.
|
||||||
|
DefaultAvailability []string
|
||||||
|
// DefaultRating holds the default value on creation for the "rating" field.
|
||||||
|
DefaultRating decimal.Decimal
|
||||||
|
// DefaultIsActive holds the default value on creation for the "is_active" field.
|
||||||
|
DefaultIsActive bool
|
||||||
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
|
DefaultCreatedAt func() time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt func() time.Time
|
||||||
|
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||||
|
UpdateDefaultUpdatedAt func() time.Time
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the PlayerServices queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByPlayerID orders the results by the player_id field.
|
||||||
|
func ByPlayerID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldPlayerID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByGameID orders the results by the game_id field.
|
||||||
|
func ByGameID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldGameID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByTitle orders the results by the title field.
|
||||||
|
func ByTitle(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldTitle, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByDescription orders the results by the description field.
|
||||||
|
func ByDescription(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldDescription, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByPrice orders the results by the price field.
|
||||||
|
func ByPrice(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldPrice, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUnit orders the results by the unit field.
|
||||||
|
func ByUnit(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUnit, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByRankRange orders the results by the rank_range field.
|
||||||
|
func ByRankRange(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldRankRange, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByRating orders the results by the rating field.
|
||||||
|
func ByRating(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldRating, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByIsActive orders the results by the is_active field.
|
||||||
|
func ByIsActive(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldIsActive, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdatedAt orders the results by the updated_at field.
|
||||||
|
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user