diff --git a/Herebyfile.mjs b/Herebyfile.mjs index 4949c08..fa9c977 100644 --- a/Herebyfile.mjs +++ b/Herebyfile.mjs @@ -91,7 +91,7 @@ const Generators = { await run('goctl', [ "docker", "--go", path.relative(__dirname, servicePath) ]) - }, + } }; diff --git a/app/email/mq/etc/email.yaml b/app/email/mq/etc/email.yaml index 754d152..f9e9c60 100644 --- a/app/email/mq/etc/email.yaml +++ b/app/email/mq/etc/email.yaml @@ -16,3 +16,29 @@ Kmq: Offset: last Consumers: 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: "" diff --git a/app/email/mq/internal/config/config.go b/app/email/mq/internal/config/config.go index ea57f80..21484c0 100644 --- a/app/email/mq/internal/config/config.go +++ b/app/email/mq/internal/config/config.go @@ -7,5 +7,20 @@ import ( type Config struct { 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"` } diff --git a/app/email/mq/internal/logic/send_verification_code_logic.go b/app/email/mq/internal/logic/send_verification_code_logic.go index 93c1afa..1d8007f 100644 --- a/app/email/mq/internal/logic/send_verification_code_logic.go +++ b/app/email/mq/internal/logic/send_verification_code_logic.go @@ -2,8 +2,12 @@ package logic import ( "context" + "encoding/json" + "fmt" "juwan-backend/app/email/mq/internal/config" + "juwan-backend/app/email/mq/internal/mailer" "juwan-backend/app/email/mq/internal/svc" + "strings" "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 { - _ = ctx - _ = 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 } + +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"` +} diff --git a/app/email/mq/internal/mailer/sender.go b/app/email/mq/internal/mailer/sender.go new file mode 100644 index 0000000..931bc6e --- /dev/null +++ b/app/email/mq/internal/mailer/sender.go @@ -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 +} diff --git a/app/email/mq/internal/svc/serviceContext.go b/app/email/mq/internal/svc/serviceContext.go index e4e0b69..8f6c98b 100644 --- a/app/email/mq/internal/svc/serviceContext.go +++ b/app/email/mq/internal/svc/serviceContext.go @@ -1,13 +1,30 @@ 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 { - c config.Config + c config.Config + MailSender *mailer.Sender } 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{ - c: c, + c: c, + MailSender: sender, } } diff --git a/app/game/api/etc/game-api.yaml b/app/game/api/etc/game-api.yaml new file mode 100644 index 0000000..107cbf6 --- /dev/null +++ b/app/game/api/etc/game-api.yaml @@ -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 diff --git a/app/game/api/game.go b/app/game/api/game.go new file mode 100644 index 0000000..0ea70e5 --- /dev/null +++ b/app/game/api/game.go @@ -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() +} diff --git a/app/game/api/internal/config/config.go b/app/game/api/internal/config/config.go new file mode 100644 index 0000000..2f61c6b --- /dev/null +++ b/app/game/api/internal/config/config.go @@ -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 +} diff --git a/app/game/api/internal/handler/game/getGameHandler.go b/app/game/api/internal/handler/game/getGameHandler.go new file mode 100644 index 0000000..cdee532 --- /dev/null +++ b/app/game/api/internal/handler/game/getGameHandler.go @@ -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) + } + } +} diff --git a/app/game/api/internal/handler/game/listGamesHandler.go b/app/game/api/internal/handler/game/listGamesHandler.go new file mode 100644 index 0000000..77ff793 --- /dev/null +++ b/app/game/api/internal/handler/game/listGamesHandler.go @@ -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) + } + } +} diff --git a/app/game/api/internal/handler/routes.go b/app/game/api/internal/handler/routes.go new file mode 100644 index 0000000..912451f --- /dev/null +++ b/app/game/api/internal/handler/routes.go @@ -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"), + ) +} diff --git a/app/game/api/internal/logic/game/getGameLogic.go b/app/game/api/internal/logic/game/getGameLogic.go new file mode 100644 index 0000000..a87cacf --- /dev/null +++ b/app/game/api/internal/logic/game/getGameLogic.go @@ -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, + } +} diff --git a/app/game/api/internal/logic/game/listGamesLogic.go b/app/game/api/internal/logic/game/listGamesLogic.go new file mode 100644 index 0000000..1791d22 --- /dev/null +++ b/app/game/api/internal/logic/game/listGamesLogic.go @@ -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 +} diff --git a/app/game/api/internal/svc/serviceContext.go b/app/game/api/internal/svc/serviceContext.go new file mode 100644 index 0000000..33e5cbf --- /dev/null +++ b/app/game/api/internal/svc/serviceContext.go @@ -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)), + } +} diff --git a/app/game/api/internal/types/types.go b/app/game/api/internal/types/types.go new file mode 100644 index 0000000..9dc5602 --- /dev/null +++ b/app/game/api/internal/types/types.go @@ -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"` +} diff --git a/app/game/rpc/etc/pb.yaml b/app/game/rpc/etc/pb.yaml new file mode 100644 index 0000000..4e156f8 --- /dev/null +++ b/app/game/rpc/etc/pb.yaml @@ -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/.: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 diff --git a/app/game/rpc/gamepublic/gamePublic.go b/app/game/rpc/gamepublic/gamePublic.go new file mode 100644 index 0000000..7a07687 --- /dev/null +++ b/app/game/rpc/gamepublic/gamePublic.go @@ -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...) +} diff --git a/app/game/rpc/internal/config/config.go b/app/game/rpc/internal/config/config.go new file mode 100644 index 0000000..99ce632 --- /dev/null +++ b/app/game/rpc/internal/config/config.go @@ -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 +} diff --git a/app/game/rpc/internal/logic/addGamesLogic.go b/app/game/rpc/internal/logic/addGamesLogic.go new file mode 100644 index 0000000..f2bb784 --- /dev/null +++ b/app/game/rpc/internal/logic/addGamesLogic.go @@ -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 +} +*/ diff --git a/app/game/rpc/internal/logic/delGamesLogic.go b/app/game/rpc/internal/logic/delGamesLogic.go new file mode 100644 index 0000000..4c9d316 --- /dev/null +++ b/app/game/rpc/internal/logic/delGamesLogic.go @@ -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 +} diff --git a/app/game/rpc/internal/logic/getGamesByIdLogic.go b/app/game/rpc/internal/logic/getGamesByIdLogic.go new file mode 100644 index 0000000..56a62e2 --- /dev/null +++ b/app/game/rpc/internal/logic/getGamesByIdLogic.go @@ -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 +} diff --git a/app/game/rpc/internal/logic/searchGamesLogic.go b/app/game/rpc/internal/logic/searchGamesLogic.go new file mode 100644 index 0000000..36b5698 --- /dev/null +++ b/app/game/rpc/internal/logic/searchGamesLogic.go @@ -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 +} diff --git a/app/game/rpc/internal/logic/updateGamesLogic.go b/app/game/rpc/internal/logic/updateGamesLogic.go new file mode 100644 index 0000000..e7a5dd6 --- /dev/null +++ b/app/game/rpc/internal/logic/updateGamesLogic.go @@ -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 +} diff --git a/app/game/rpc/internal/models/schema/games.go b/app/game/rpc/internal/models/schema/games.go new file mode 100644 index 0000000..f61b92a --- /dev/null +++ b/app/game/rpc/internal/models/schema/games.go @@ -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 +} diff --git a/app/game/rpc/internal/server/gamePublicServer.go b/app/game/rpc/internal/server/gamePublicServer.go new file mode 100644 index 0000000..fdd3bff --- /dev/null +++ b/app/game/rpc/internal/server/gamePublicServer.go @@ -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) +} diff --git a/app/game/rpc/internal/server/publicServer.go b/app/game/rpc/internal/server/publicServer.go new file mode 100644 index 0000000..fe97327 --- /dev/null +++ b/app/game/rpc/internal/server/publicServer.go @@ -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) +} diff --git a/app/game/rpc/internal/svc/serviceContext.go b/app/game/rpc/internal/svc/serviceContext.go new file mode 100644 index 0000000..e732072 --- /dev/null +++ b/app/game/rpc/internal/svc/serviceContext.go @@ -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), + } +} diff --git a/app/game/rpc/pb.go b/app/game/rpc/pb.go new file mode 100644 index 0000000..ceb632d --- /dev/null +++ b/app/game/rpc/pb.go @@ -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() +} diff --git a/app/game/rpc/pb/game.pb.go b/app/game/rpc/pb/game.pb.go new file mode 100644 index 0000000..d979884 --- /dev/null +++ b/app/game/rpc/pb/game.pb.go @@ -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 +} diff --git a/app/game/rpc/pb/game_grpc.pb.go b/app/game/rpc/pb/game_grpc.pb.go new file mode 100644 index 0000000..f29e9b8 --- /dev/null +++ b/app/game/rpc/pb/game_grpc.pb.go @@ -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", +} diff --git a/app/game/rpc/public/public.go b/app/game/rpc/public/public.go new file mode 100644 index 0000000..56c730f --- /dev/null +++ b/app/game/rpc/public/public.go @@ -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...) +} diff --git a/app/objectstory/api/etc/file-api.yaml b/app/objectstory/api/etc/file-api.yaml index e65e032..3c8f6d1 100644 --- a/app/objectstory/api/etc/file-api.yaml +++ b/app/objectstory/api/etc/file-api.yaml @@ -1,3 +1,6 @@ Name: file-api Host: 0.0.0.0 Port: 8888 + +FileRpcConf: + Target: k8s://juwan/objectstory-rpc-svc:8080 diff --git a/app/objectstory/api/internal/config/config.go b/app/objectstory/api/internal/config/config.go index 33aaf22..243e22d 100644 --- a/app/objectstory/api/internal/config/config.go +++ b/app/objectstory/api/internal/config/config.go @@ -3,11 +3,15 @@ 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 { rest.RestConf - Logger struct { + FileRpcConf zrpc.RpcClientConf + Logger struct { AccessSecret string AccessExpire int64 } diff --git a/app/objectstory/api/internal/handler/file/getFileHandler.go b/app/objectstory/api/internal/handler/file/getFileHandler.go index 5182473..813d137 100644 --- a/app/objectstory/api/internal/handler/file/getFileHandler.go +++ b/app/objectstory/api/internal/handler/file/getFileHandler.go @@ -6,10 +6,11 @@ package file import ( "net/http" - "github.com/zeromicro/go-zero/rest/httpx" "juwan-backend/app/objectstory/api/internal/logic/file" "juwan-backend/app/objectstory/api/internal/svc" "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) - err := l.GetFile(&req) + url, err := l.GetFile(&req) if err != nil { httpx.ErrorCtx(r.Context(), w, err) } else { - httpx.Ok(w) + http.Redirect(w, r, url, http.StatusTemporaryRedirect) } } } diff --git a/app/objectstory/api/internal/handler/file/uploadHandler.go b/app/objectstory/api/internal/handler/file/uploadHandler.go index ebe0f0d..ff6afe8 100644 --- a/app/objectstory/api/internal/handler/file/uploadHandler.go +++ b/app/objectstory/api/internal/handler/file/uploadHandler.go @@ -6,10 +6,11 @@ package file import ( "net/http" - "github.com/zeromicro/go-zero/rest/httpx" "juwan-backend/app/objectstory/api/internal/logic/file" "juwan-backend/app/objectstory/api/internal/svc" "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) - resp, err := l.Upload(&req) + resp, err := l.Upload(&req, r) if err != nil { httpx.ErrorCtx(r.Context(), w, err) } else { diff --git a/app/objectstory/api/internal/logic/file/getFileLogic.go b/app/objectstory/api/internal/logic/file/getFileLogic.go index f482810..8204aba 100644 --- a/app/objectstory/api/internal/logic/file/getFileLogic.go +++ b/app/objectstory/api/internal/logic/file/getFileLogic.go @@ -5,9 +5,13 @@ package file import ( "context" + "errors" + "strconv" "juwan-backend/app/objectstory/api/internal/svc" "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" ) @@ -27,8 +31,26 @@ func NewGetFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFileLo } } -func (l *GetFileLogic) GetFile(req *types.GetFileReq) error { - // todo: add your logic here and delete this line +func (l *GetFileLogic) GetFile(req *types.GetFileReq) (string, error) { + 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 } diff --git a/app/objectstory/api/internal/logic/file/uploadLogic.go b/app/objectstory/api/internal/logic/file/uploadLogic.go index 8494b4b..af5808b 100644 --- a/app/objectstory/api/internal/logic/file/uploadLogic.go +++ b/app/objectstory/api/internal/logic/file/uploadLogic.go @@ -5,9 +5,15 @@ package file import ( "context" + "errors" + "io" + "net/http" + "strconv" "juwan-backend/app/objectstory/api/internal/svc" "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" ) @@ -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) { - // todo: add your logic here and delete this line +func (l *UploadLogic) Upload(req *types.UploadReq, r *http.Request) (resp *types.UploadResp, err error) { + 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 } diff --git a/app/objectstory/api/internal/middleware/filesizelimitMiddleware.go b/app/objectstory/api/internal/middleware/filesizelimitMiddleware.go index 8aecbc7..c071e28 100644 --- a/app/objectstory/api/internal/middleware/filesizelimitMiddleware.go +++ b/app/objectstory/api/internal/middleware/filesizelimitMiddleware.go @@ -5,6 +5,8 @@ package middleware import "net/http" +const maxUploadSizeBytes int64 = 20 << 20 + type FileSizeLimitMiddleware struct { } @@ -14,9 +16,10 @@ func NewFileSizeLimitMiddleware() *FileSizeLimitMiddleware { func (m *FileSizeLimitMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc { 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) } } diff --git a/app/objectstory/api/internal/svc/serviceContext.go b/app/objectstory/api/internal/svc/serviceContext.go index 2edfc00..cefa01d 100644 --- a/app/objectstory/api/internal/svc/serviceContext.go +++ b/app/objectstory/api/internal/svc/serviceContext.go @@ -4,19 +4,24 @@ package svc import ( - "github.com/zeromicro/go-zero/rest" "juwan-backend/app/objectstory/api/internal/config" "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 { Config config.Config FileSizeLimit rest.Middleware + FileRpc fileservice.FileService } func NewServiceContext(c config.Config) *ServiceContext { return &ServiceContext{ Config: c, FileSizeLimit: middleware.NewFileSizeLimitMiddleware().Handle, + FileRpc: fileservice.NewFileService(zrpc.MustNewClient(c.FileRpcConf)), } } diff --git a/app/objectstory/rpc/etc/file.yaml b/app/objectstory/rpc/etc/file.yaml index dd71650..cc87957 100644 --- a/app/objectstory/rpc/etc/file.yaml +++ b/app/objectstory/rpc/etc/file.yaml @@ -1,6 +1,40 @@ Name: file.rpc ListenOn: 0.0.0.0:8080 -Etcd: - Hosts: - - 127.0.0.1:2379 - Key: file.rpc + +Prometheus: + Host: 0.0.0.0 + Port: 4001 + Path: /metrics + +# Target: k8s://juwan/.: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 diff --git a/app/objectstory/rpc/internal/config/config.go b/app/objectstory/rpc/internal/config/config.go index c1f85b9..0178e49 100644 --- a/app/objectstory/rpc/internal/config/config.go +++ b/app/objectstory/rpc/internal/config/config.go @@ -1,7 +1,19 @@ package config -import "github.com/zeromicro/go-zero/zrpc" +import ( + "github.com/zeromicro/go-zero/zrpc" +) type Config struct { zrpc.RpcServerConf + S3Conf S3ObjectConf +} + +type S3ObjectConf struct { + AccessKey string + SecretKey string + Bucket string + Endpoint string + Region string + UsePathStyle bool } diff --git a/app/objectstory/rpc/internal/logic/getFileUrlLogic.go b/app/objectstory/rpc/internal/logic/getFileUrlLogic.go index 3509d4f..97c9ddd 100644 --- a/app/objectstory/rpc/internal/logic/getFileUrlLogic.go +++ b/app/objectstory/rpc/internal/logic/getFileUrlLogic.go @@ -2,10 +2,13 @@ package logic import ( "context" + "errors" + "time" "juwan-backend/app/objectstory/rpc/internal/svc" "juwan-backend/app/objectstory/rpc/pb" + "github.com/aws/aws-sdk-go-v2/service/s3" "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) { - // 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 } diff --git a/app/objectstory/rpc/internal/logic/uploadLogic.go b/app/objectstory/rpc/internal/logic/uploadLogic.go index 685075c..a3d3adb 100644 --- a/app/objectstory/rpc/internal/logic/uploadLogic.go +++ b/app/objectstory/rpc/internal/logic/uploadLogic.go @@ -1,11 +1,19 @@ package logic import ( + "bytes" "context" + "errors" + "fmt" + "path/filepath" + "strings" "juwan-backend/app/objectstory/rpc/internal/svc" "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" ) @@ -25,7 +33,40 @@ func NewUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogi // 简单上传(适合小文件,或保存元数据) 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 } diff --git a/app/objectstory/rpc/internal/svc/objectStorage.go b/app/objectstory/rpc/internal/svc/objectStorage.go new file mode 100644 index 0000000..906c5d0 --- /dev/null +++ b/app/objectstory/rpc/internal/svc/objectStorage.go @@ -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 + }) +} diff --git a/app/objectstory/rpc/internal/svc/serviceContext.go b/app/objectstory/rpc/internal/svc/serviceContext.go index 38212dd..350eef4 100644 --- a/app/objectstory/rpc/internal/svc/serviceContext.go +++ b/app/objectstory/rpc/internal/svc/serviceContext.go @@ -1,13 +1,22 @@ 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 { Config config.Config + S3 *s3.Client } func NewServiceContext(c config.Config) *ServiceContext { + s3obj := NewObjectStorage(c.S3Conf) + return &ServiceContext{ Config: c, + S3: s3obj.MustNews3Client(context.Background()), } } diff --git a/app/objectstory/rpc/pb/objectstory.pb.go b/app/objectstory/rpc/pb/objectstory.pb.go index 5e4fc52..c74bd33 100644 --- a/app/objectstory/rpc/pb/objectstory.pb.go +++ b/app/objectstory/rpc/pb/objectstory.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.36.11 -// protoc v5.29.6 +// protoc v3.19.4 // source: objectstory.proto package pb diff --git a/app/objectstory/rpc/pb/objectstory_grpc.pb.go b/app/objectstory/rpc/pb/objectstory_grpc.pb.go index c88400b..ed6b91c 100644 --- a/app/objectstory/rpc/pb/objectstory_grpc.pb.go +++ b/app/objectstory/rpc/pb/objectstory_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.6.1 -// - protoc v5.29.6 +// - protoc v3.19.4 // source: objectstory.proto package pb diff --git a/app/player/api/etc/juwan-api.yaml b/app/player/api/etc/juwan-api.yaml new file mode 100644 index 0000000..71d4954 --- /dev/null +++ b/app/player/api/etc/juwan-api.yaml @@ -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/:8080 +PlayerRpcConf: + Target: k8s://juwan/player-rpc-svc:8080 + diff --git a/app/player/api/internal/config/config.go b/app/player/api/internal/config/config.go new file mode 100644 index 0000000..57cf769 --- /dev/null +++ b/app/player/api/internal/config/config.go @@ -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 +} diff --git a/app/player/api/internal/handler/player/createServiceHandler.go b/app/player/api/internal/handler/player/createServiceHandler.go new file mode 100644 index 0000000..145e3a7 --- /dev/null +++ b/app/player/api/internal/handler/player/createServiceHandler.go @@ -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) + } + } +} diff --git a/app/player/api/internal/handler/player/deleteServiceHandler.go b/app/player/api/internal/handler/player/deleteServiceHandler.go new file mode 100644 index 0000000..6116bb7 --- /dev/null +++ b/app/player/api/internal/handler/player/deleteServiceHandler.go @@ -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) + } + } +} diff --git a/app/player/api/internal/handler/player/getPlayerHandler.go b/app/player/api/internal/handler/player/getPlayerHandler.go new file mode 100644 index 0000000..a60df99 --- /dev/null +++ b/app/player/api/internal/handler/player/getPlayerHandler.go @@ -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) + } + } +} diff --git a/app/player/api/internal/handler/player/getServiceHandler.go b/app/player/api/internal/handler/player/getServiceHandler.go new file mode 100644 index 0000000..24282f4 --- /dev/null +++ b/app/player/api/internal/handler/player/getServiceHandler.go @@ -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) + } + } +} diff --git a/app/player/api/internal/handler/player/listPlayerServicesHandler.go b/app/player/api/internal/handler/player/listPlayerServicesHandler.go new file mode 100644 index 0000000..62d151e --- /dev/null +++ b/app/player/api/internal/handler/player/listPlayerServicesHandler.go @@ -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) + } + } +} diff --git a/app/player/api/internal/handler/player/listPlayersHandler.go b/app/player/api/internal/handler/player/listPlayersHandler.go new file mode 100644 index 0000000..dd598ac --- /dev/null +++ b/app/player/api/internal/handler/player/listPlayersHandler.go @@ -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) + } + } +} diff --git a/app/player/api/internal/handler/player/listServicesHandler.go b/app/player/api/internal/handler/player/listServicesHandler.go new file mode 100644 index 0000000..cf7805d --- /dev/null +++ b/app/player/api/internal/handler/player/listServicesHandler.go @@ -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) + } + } +} diff --git a/app/player/api/internal/handler/player/updatePlayerStatusHandler.go b/app/player/api/internal/handler/player/updatePlayerStatusHandler.go new file mode 100644 index 0000000..0b01f66 --- /dev/null +++ b/app/player/api/internal/handler/player/updatePlayerStatusHandler.go @@ -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) + } + } +} diff --git a/app/player/api/internal/handler/player/updateServiceHandler.go b/app/player/api/internal/handler/player/updateServiceHandler.go new file mode 100644 index 0000000..497f6eb --- /dev/null +++ b/app/player/api/internal/handler/player/updateServiceHandler.go @@ -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) + } + } +} diff --git a/app/player/api/internal/handler/routes.go b/app/player/api/internal/handler/routes.go new file mode 100644 index 0000000..726c0d5 --- /dev/null +++ b/app/player/api/internal/handler/routes.go @@ -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"), + ) +} diff --git a/app/player/api/internal/logic/player/createServiceLogic.go b/app/player/api/internal/logic/player/createServiceLogic.go new file mode 100644 index 0000000..5202ed2 --- /dev/null +++ b/app/player/api/internal/logic/player/createServiceLogic.go @@ -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 +} diff --git a/app/player/api/internal/logic/player/deleteServiceLogic.go b/app/player/api/internal/logic/player/deleteServiceLogic.go new file mode 100644 index 0000000..0f57a34 --- /dev/null +++ b/app/player/api/internal/logic/player/deleteServiceLogic.go @@ -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 +} diff --git a/app/player/api/internal/logic/player/getPlayerLogic.go b/app/player/api/internal/logic/player/getPlayerLogic.go new file mode 100644 index 0000000..b41e167 --- /dev/null +++ b/app/player/api/internal/logic/player/getPlayerLogic.go @@ -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 +} diff --git a/app/player/api/internal/logic/player/getServiceLogic.go b/app/player/api/internal/logic/player/getServiceLogic.go new file mode 100644 index 0000000..504a353 --- /dev/null +++ b/app/player/api/internal/logic/player/getServiceLogic.go @@ -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 +} diff --git a/app/player/api/internal/logic/player/listPlayerServicesLogic.go b/app/player/api/internal/logic/player/listPlayerServicesLogic.go new file mode 100644 index 0000000..4ef46ee --- /dev/null +++ b/app/player/api/internal/logic/player/listPlayerServicesLogic.go @@ -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 +} diff --git a/app/player/api/internal/logic/player/listPlayersLogic.go b/app/player/api/internal/logic/player/listPlayersLogic.go new file mode 100644 index 0000000..eb68e3d --- /dev/null +++ b/app/player/api/internal/logic/player/listPlayersLogic.go @@ -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 +} diff --git a/app/player/api/internal/logic/player/listServicesLogic.go b/app/player/api/internal/logic/player/listServicesLogic.go new file mode 100644 index 0000000..22f5030 --- /dev/null +++ b/app/player/api/internal/logic/player/listServicesLogic.go @@ -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 +} diff --git a/app/player/api/internal/logic/player/updatePlayerStatusLogic.go b/app/player/api/internal/logic/player/updatePlayerStatusLogic.go new file mode 100644 index 0000000..9e81b92 --- /dev/null +++ b/app/player/api/internal/logic/player/updatePlayerStatusLogic.go @@ -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 +} diff --git a/app/player/api/internal/logic/player/updateServiceLogic.go b/app/player/api/internal/logic/player/updateServiceLogic.go new file mode 100644 index 0000000..58e2da7 --- /dev/null +++ b/app/player/api/internal/logic/player/updateServiceLogic.go @@ -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 +} diff --git a/app/player/api/internal/svc/serviceContext.go b/app/player/api/internal/svc/serviceContext.go new file mode 100644 index 0000000..1f1ce92 --- /dev/null +++ b/app/player/api/internal/svc/serviceContext.go @@ -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)), + } +} diff --git a/app/player/api/internal/types/types.go b/app/player/api/internal/types/types.go new file mode 100644 index 0000000..eff9148 --- /dev/null +++ b/app/player/api/internal/types/types.go @@ -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"` +} diff --git a/app/player/api/juwan.go b/app/player/api/juwan.go new file mode 100644 index 0000000..6dc04d5 --- /dev/null +++ b/app/player/api/juwan.go @@ -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() +} diff --git a/app/player/rpc/etc/pb.yaml b/app/player/rpc/etc/pb.yaml new file mode 100644 index 0000000..3763106 --- /dev/null +++ b/app/player/rpc/etc/pb.yaml @@ -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/.: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 diff --git a/app/player/rpc/internal/config/config.go b/app/player/rpc/internal/config/config.go new file mode 100644 index 0000000..faeb55a --- /dev/null +++ b/app/player/rpc/internal/config/config.go @@ -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 +} diff --git a/app/player/rpc/internal/logic/addPlayerServicesLogic.go b/app/player/rpc/internal/logic/addPlayerServicesLogic.go new file mode 100644 index 0000000..4334b05 --- /dev/null +++ b/app/player/rpc/internal/logic/addPlayerServicesLogic.go @@ -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 +} diff --git a/app/player/rpc/internal/logic/addPlayersLogic.go b/app/player/rpc/internal/logic/addPlayersLogic.go new file mode 100644 index 0000000..660b2ab --- /dev/null +++ b/app/player/rpc/internal/logic/addPlayersLogic.go @@ -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 +} diff --git a/app/player/rpc/internal/logic/delPlayerServicesLogic.go b/app/player/rpc/internal/logic/delPlayerServicesLogic.go new file mode 100644 index 0000000..5623880 --- /dev/null +++ b/app/player/rpc/internal/logic/delPlayerServicesLogic.go @@ -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 +} diff --git a/app/player/rpc/internal/logic/delPlayersLogic.go b/app/player/rpc/internal/logic/delPlayersLogic.go new file mode 100644 index 0000000..8429b1b --- /dev/null +++ b/app/player/rpc/internal/logic/delPlayersLogic.go @@ -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 +} diff --git a/app/player/rpc/internal/logic/getPlayerServicesByIdLogic.go b/app/player/rpc/internal/logic/getPlayerServicesByIdLogic.go new file mode 100644 index 0000000..1423ce5 --- /dev/null +++ b/app/player/rpc/internal/logic/getPlayerServicesByIdLogic.go @@ -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 +} diff --git a/app/player/rpc/internal/logic/getPlayersByIdLogic.go b/app/player/rpc/internal/logic/getPlayersByIdLogic.go new file mode 100644 index 0000000..959bd20 --- /dev/null +++ b/app/player/rpc/internal/logic/getPlayersByIdLogic.go @@ -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 +} diff --git a/app/player/rpc/internal/logic/searchPlayerServicesLogic.go b/app/player/rpc/internal/logic/searchPlayerServicesLogic.go new file mode 100644 index 0000000..4f93b06 --- /dev/null +++ b/app/player/rpc/internal/logic/searchPlayerServicesLogic.go @@ -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 +} diff --git a/app/player/rpc/internal/logic/searchPlayersLogic.go b/app/player/rpc/internal/logic/searchPlayersLogic.go new file mode 100644 index 0000000..25a1133 --- /dev/null +++ b/app/player/rpc/internal/logic/searchPlayersLogic.go @@ -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 + +} diff --git a/app/player/rpc/internal/logic/updatePlayerServicesLogic.go b/app/player/rpc/internal/logic/updatePlayerServicesLogic.go new file mode 100644 index 0000000..1231056 --- /dev/null +++ b/app/player/rpc/internal/logic/updatePlayerServicesLogic.go @@ -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 +} diff --git a/app/player/rpc/internal/logic/updatePlayersLogic.go b/app/player/rpc/internal/logic/updatePlayersLogic.go new file mode 100644 index 0000000..d6486da --- /dev/null +++ b/app/player/rpc/internal/logic/updatePlayersLogic.go @@ -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 +} diff --git a/app/player/rpc/internal/models/client.go b/app/player/rpc/internal/models/client.go new file mode 100644 index 0000000..5f0bbdb --- /dev/null +++ b/app/player/rpc/internal/models/client.go @@ -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 + } +) diff --git a/app/player/rpc/internal/models/ent.go b/app/player/rpc/internal/models/ent.go new file mode 100644 index 0000000..d15d4c1 --- /dev/null +++ b/app/player/rpc/internal/models/ent.go @@ -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) diff --git a/app/player/rpc/internal/models/enttest/enttest.go b/app/player/rpc/internal/models/enttest/enttest.go new file mode 100644 index 0000000..1c96082 --- /dev/null +++ b/app/player/rpc/internal/models/enttest/enttest.go @@ -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() + } +} diff --git a/app/player/rpc/internal/models/hook/hook.go b/app/player/rpc/internal/models/hook/hook.go new file mode 100644 index 0000000..6f3ef98 --- /dev/null +++ b/app/player/rpc/internal/models/hook/hook.go @@ -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...) +} diff --git a/app/player/rpc/internal/models/migrate/migrate.go b/app/player/rpc/internal/models/migrate/migrate.go new file mode 100644 index 0000000..1956a6b --- /dev/null +++ b/app/player/rpc/internal/models/migrate/migrate.go @@ -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...) +} diff --git a/app/player/rpc/internal/models/migrate/schema.go b/app/player/rpc/internal/models/migrate/schema.go new file mode 100644 index 0000000..b1a3ac5 --- /dev/null +++ b/app/player/rpc/internal/models/migrate/schema.go @@ -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", + } +} diff --git a/app/player/rpc/internal/models/mutation.go b/app/player/rpc/internal/models/mutation.go new file mode 100644 index 0000000..24ec5e2 --- /dev/null +++ b/app/player/rpc/internal/models/mutation.go @@ -0,0 +1,2300 @@ +// 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" + "juwan-backend/app/player/rpc/internal/models/predicate" + "sync" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/lib/pq" + "github.com/shopspring/decimal" +) + +const ( + // Operation types. + OpCreate = ent.OpCreate + OpDelete = ent.OpDelete + OpDeleteOne = ent.OpDeleteOne + OpUpdate = ent.OpUpdate + OpUpdateOne = ent.OpUpdateOne + + // Node types. + TypePlayerServices = "PlayerServices" + TypePlayers = "Players" +) + +// PlayerServicesMutation represents an operation that mutates the PlayerServices nodes in the graph. +type PlayerServicesMutation struct { + config + op Op + typ string + id *int64 + player_id *int64 + addplayer_id *int64 + game_id *int64 + addgame_id *int64 + title *string + description *string + price *decimal.Decimal + unit *string + rank_range *string + availability *[]string + appendavailability []string + rating *decimal.Decimal + is_active *bool + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*PlayerServices, error) + predicates []predicate.PlayerServices +} + +var _ ent.Mutation = (*PlayerServicesMutation)(nil) + +// playerservicesOption allows management of the mutation configuration using functional options. +type playerservicesOption func(*PlayerServicesMutation) + +// newPlayerServicesMutation creates new mutation for the PlayerServices entity. +func newPlayerServicesMutation(c config, op Op, opts ...playerservicesOption) *PlayerServicesMutation { + m := &PlayerServicesMutation{ + config: c, + op: op, + typ: TypePlayerServices, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withPlayerServicesID sets the ID field of the mutation. +func withPlayerServicesID(id int64) playerservicesOption { + return func(m *PlayerServicesMutation) { + var ( + err error + once sync.Once + value *PlayerServices + ) + m.oldValue = func(ctx context.Context) (*PlayerServices, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().PlayerServices.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withPlayerServices sets the old PlayerServices of the mutation. +func withPlayerServices(node *PlayerServices) playerservicesOption { + return func(m *PlayerServicesMutation) { + m.oldValue = func(context.Context) (*PlayerServices, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m PlayerServicesMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m PlayerServicesMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("models: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of PlayerServices entities. +func (m *PlayerServicesMutation) SetID(id int64) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *PlayerServicesMutation) ID() (id int64, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *PlayerServicesMutation) IDs(ctx context.Context) ([]int64, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int64{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().PlayerServices.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetPlayerID sets the "player_id" field. +func (m *PlayerServicesMutation) SetPlayerID(i int64) { + m.player_id = &i + m.addplayer_id = nil +} + +// PlayerID returns the value of the "player_id" field in the mutation. +func (m *PlayerServicesMutation) PlayerID() (r int64, exists bool) { + v := m.player_id + if v == nil { + return + } + return *v, true +} + +// OldPlayerID returns the old "player_id" field's value of the PlayerServices entity. +// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayerServicesMutation) OldPlayerID(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPlayerID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPlayerID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPlayerID: %w", err) + } + return oldValue.PlayerID, nil +} + +// AddPlayerID adds i to the "player_id" field. +func (m *PlayerServicesMutation) AddPlayerID(i int64) { + if m.addplayer_id != nil { + *m.addplayer_id += i + } else { + m.addplayer_id = &i + } +} + +// AddedPlayerID returns the value that was added to the "player_id" field in this mutation. +func (m *PlayerServicesMutation) AddedPlayerID() (r int64, exists bool) { + v := m.addplayer_id + if v == nil { + return + } + return *v, true +} + +// ResetPlayerID resets all changes to the "player_id" field. +func (m *PlayerServicesMutation) ResetPlayerID() { + m.player_id = nil + m.addplayer_id = nil +} + +// SetGameID sets the "game_id" field. +func (m *PlayerServicesMutation) SetGameID(i int64) { + m.game_id = &i + m.addgame_id = nil +} + +// GameID returns the value of the "game_id" field in the mutation. +func (m *PlayerServicesMutation) GameID() (r int64, exists bool) { + v := m.game_id + if v == nil { + return + } + return *v, true +} + +// OldGameID returns the old "game_id" field's value of the PlayerServices entity. +// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayerServicesMutation) OldGameID(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldGameID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldGameID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldGameID: %w", err) + } + return oldValue.GameID, nil +} + +// AddGameID adds i to the "game_id" field. +func (m *PlayerServicesMutation) AddGameID(i int64) { + if m.addgame_id != nil { + *m.addgame_id += i + } else { + m.addgame_id = &i + } +} + +// AddedGameID returns the value that was added to the "game_id" field in this mutation. +func (m *PlayerServicesMutation) AddedGameID() (r int64, exists bool) { + v := m.addgame_id + if v == nil { + return + } + return *v, true +} + +// ResetGameID resets all changes to the "game_id" field. +func (m *PlayerServicesMutation) ResetGameID() { + m.game_id = nil + m.addgame_id = nil +} + +// SetTitle sets the "title" field. +func (m *PlayerServicesMutation) SetTitle(s string) { + m.title = &s +} + +// Title returns the value of the "title" field in the mutation. +func (m *PlayerServicesMutation) Title() (r string, exists bool) { + v := m.title + if v == nil { + return + } + return *v, true +} + +// OldTitle returns the old "title" field's value of the PlayerServices entity. +// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayerServicesMutation) OldTitle(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTitle is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTitle requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTitle: %w", err) + } + return oldValue.Title, nil +} + +// ResetTitle resets all changes to the "title" field. +func (m *PlayerServicesMutation) ResetTitle() { + m.title = nil +} + +// SetDescription sets the "description" field. +func (m *PlayerServicesMutation) SetDescription(s string) { + m.description = &s +} + +// Description returns the value of the "description" field in the mutation. +func (m *PlayerServicesMutation) Description() (r string, exists bool) { + v := m.description + if v == nil { + return + } + return *v, true +} + +// OldDescription returns the old "description" field's value of the PlayerServices entity. +// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayerServicesMutation) OldDescription(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDescription is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDescription requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDescription: %w", err) + } + return oldValue.Description, nil +} + +// ClearDescription clears the value of the "description" field. +func (m *PlayerServicesMutation) ClearDescription() { + m.description = nil + m.clearedFields[playerservices.FieldDescription] = struct{}{} +} + +// DescriptionCleared returns if the "description" field was cleared in this mutation. +func (m *PlayerServicesMutation) DescriptionCleared() bool { + _, ok := m.clearedFields[playerservices.FieldDescription] + return ok +} + +// ResetDescription resets all changes to the "description" field. +func (m *PlayerServicesMutation) ResetDescription() { + m.description = nil + delete(m.clearedFields, playerservices.FieldDescription) +} + +// SetPrice sets the "price" field. +func (m *PlayerServicesMutation) SetPrice(d decimal.Decimal) { + m.price = &d +} + +// Price returns the value of the "price" field in the mutation. +func (m *PlayerServicesMutation) Price() (r decimal.Decimal, exists bool) { + v := m.price + if v == nil { + return + } + return *v, true +} + +// OldPrice returns the old "price" field's value of the PlayerServices entity. +// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayerServicesMutation) OldPrice(ctx context.Context) (v decimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPrice is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPrice requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPrice: %w", err) + } + return oldValue.Price, nil +} + +// ResetPrice resets all changes to the "price" field. +func (m *PlayerServicesMutation) ResetPrice() { + m.price = nil +} + +// SetUnit sets the "unit" field. +func (m *PlayerServicesMutation) SetUnit(s string) { + m.unit = &s +} + +// Unit returns the value of the "unit" field in the mutation. +func (m *PlayerServicesMutation) Unit() (r string, exists bool) { + v := m.unit + if v == nil { + return + } + return *v, true +} + +// OldUnit returns the old "unit" field's value of the PlayerServices entity. +// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayerServicesMutation) OldUnit(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUnit is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUnit requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUnit: %w", err) + } + return oldValue.Unit, nil +} + +// ResetUnit resets all changes to the "unit" field. +func (m *PlayerServicesMutation) ResetUnit() { + m.unit = nil +} + +// SetRankRange sets the "rank_range" field. +func (m *PlayerServicesMutation) SetRankRange(s string) { + m.rank_range = &s +} + +// RankRange returns the value of the "rank_range" field in the mutation. +func (m *PlayerServicesMutation) RankRange() (r string, exists bool) { + v := m.rank_range + if v == nil { + return + } + return *v, true +} + +// OldRankRange returns the old "rank_range" field's value of the PlayerServices entity. +// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayerServicesMutation) OldRankRange(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRankRange is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRankRange requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRankRange: %w", err) + } + return oldValue.RankRange, nil +} + +// ClearRankRange clears the value of the "rank_range" field. +func (m *PlayerServicesMutation) ClearRankRange() { + m.rank_range = nil + m.clearedFields[playerservices.FieldRankRange] = struct{}{} +} + +// RankRangeCleared returns if the "rank_range" field was cleared in this mutation. +func (m *PlayerServicesMutation) RankRangeCleared() bool { + _, ok := m.clearedFields[playerservices.FieldRankRange] + return ok +} + +// ResetRankRange resets all changes to the "rank_range" field. +func (m *PlayerServicesMutation) ResetRankRange() { + m.rank_range = nil + delete(m.clearedFields, playerservices.FieldRankRange) +} + +// SetAvailability sets the "availability" field. +func (m *PlayerServicesMutation) SetAvailability(s []string) { + m.availability = &s + m.appendavailability = nil +} + +// Availability returns the value of the "availability" field in the mutation. +func (m *PlayerServicesMutation) Availability() (r []string, exists bool) { + v := m.availability + if v == nil { + return + } + return *v, true +} + +// OldAvailability returns the old "availability" field's value of the PlayerServices entity. +// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayerServicesMutation) OldAvailability(ctx context.Context) (v []string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAvailability is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAvailability requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAvailability: %w", err) + } + return oldValue.Availability, nil +} + +// AppendAvailability adds s to the "availability" field. +func (m *PlayerServicesMutation) AppendAvailability(s []string) { + m.appendavailability = append(m.appendavailability, s...) +} + +// AppendedAvailability returns the list of values that were appended to the "availability" field in this mutation. +func (m *PlayerServicesMutation) AppendedAvailability() ([]string, bool) { + if len(m.appendavailability) == 0 { + return nil, false + } + return m.appendavailability, true +} + +// ClearAvailability clears the value of the "availability" field. +func (m *PlayerServicesMutation) ClearAvailability() { + m.availability = nil + m.appendavailability = nil + m.clearedFields[playerservices.FieldAvailability] = struct{}{} +} + +// AvailabilityCleared returns if the "availability" field was cleared in this mutation. +func (m *PlayerServicesMutation) AvailabilityCleared() bool { + _, ok := m.clearedFields[playerservices.FieldAvailability] + return ok +} + +// ResetAvailability resets all changes to the "availability" field. +func (m *PlayerServicesMutation) ResetAvailability() { + m.availability = nil + m.appendavailability = nil + delete(m.clearedFields, playerservices.FieldAvailability) +} + +// SetRating sets the "rating" field. +func (m *PlayerServicesMutation) SetRating(d decimal.Decimal) { + m.rating = &d +} + +// Rating returns the value of the "rating" field in the mutation. +func (m *PlayerServicesMutation) Rating() (r decimal.Decimal, exists bool) { + v := m.rating + if v == nil { + return + } + return *v, true +} + +// OldRating returns the old "rating" field's value of the PlayerServices entity. +// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayerServicesMutation) OldRating(ctx context.Context) (v decimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRating is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRating requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRating: %w", err) + } + return oldValue.Rating, nil +} + +// ResetRating resets all changes to the "rating" field. +func (m *PlayerServicesMutation) ResetRating() { + m.rating = nil +} + +// SetIsActive sets the "is_active" field. +func (m *PlayerServicesMutation) SetIsActive(b bool) { + m.is_active = &b +} + +// IsActive returns the value of the "is_active" field in the mutation. +func (m *PlayerServicesMutation) IsActive() (r bool, exists bool) { + v := m.is_active + if v == nil { + return + } + return *v, true +} + +// OldIsActive returns the old "is_active" field's value of the PlayerServices entity. +// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayerServicesMutation) OldIsActive(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldIsActive is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldIsActive requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIsActive: %w", err) + } + return oldValue.IsActive, nil +} + +// ClearIsActive clears the value of the "is_active" field. +func (m *PlayerServicesMutation) ClearIsActive() { + m.is_active = nil + m.clearedFields[playerservices.FieldIsActive] = struct{}{} +} + +// IsActiveCleared returns if the "is_active" field was cleared in this mutation. +func (m *PlayerServicesMutation) IsActiveCleared() bool { + _, ok := m.clearedFields[playerservices.FieldIsActive] + return ok +} + +// ResetIsActive resets all changes to the "is_active" field. +func (m *PlayerServicesMutation) ResetIsActive() { + m.is_active = nil + delete(m.clearedFields, playerservices.FieldIsActive) +} + +// SetCreatedAt sets the "created_at" field. +func (m *PlayerServicesMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *PlayerServicesMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the PlayerServices entity. +// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayerServicesMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *PlayerServicesMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *PlayerServicesMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *PlayerServicesMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the PlayerServices entity. +// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayerServicesMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *PlayerServicesMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// Where appends a list predicates to the PlayerServicesMutation builder. +func (m *PlayerServicesMutation) Where(ps ...predicate.PlayerServices) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the PlayerServicesMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *PlayerServicesMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.PlayerServices, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *PlayerServicesMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *PlayerServicesMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (PlayerServices). +func (m *PlayerServicesMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *PlayerServicesMutation) Fields() []string { + fields := make([]string, 0, 12) + if m.player_id != nil { + fields = append(fields, playerservices.FieldPlayerID) + } + if m.game_id != nil { + fields = append(fields, playerservices.FieldGameID) + } + if m.title != nil { + fields = append(fields, playerservices.FieldTitle) + } + if m.description != nil { + fields = append(fields, playerservices.FieldDescription) + } + if m.price != nil { + fields = append(fields, playerservices.FieldPrice) + } + if m.unit != nil { + fields = append(fields, playerservices.FieldUnit) + } + if m.rank_range != nil { + fields = append(fields, playerservices.FieldRankRange) + } + if m.availability != nil { + fields = append(fields, playerservices.FieldAvailability) + } + if m.rating != nil { + fields = append(fields, playerservices.FieldRating) + } + if m.is_active != nil { + fields = append(fields, playerservices.FieldIsActive) + } + if m.created_at != nil { + fields = append(fields, playerservices.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, playerservices.FieldUpdatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *PlayerServicesMutation) Field(name string) (ent.Value, bool) { + switch name { + case playerservices.FieldPlayerID: + return m.PlayerID() + case playerservices.FieldGameID: + return m.GameID() + case playerservices.FieldTitle: + return m.Title() + case playerservices.FieldDescription: + return m.Description() + case playerservices.FieldPrice: + return m.Price() + case playerservices.FieldUnit: + return m.Unit() + case playerservices.FieldRankRange: + return m.RankRange() + case playerservices.FieldAvailability: + return m.Availability() + case playerservices.FieldRating: + return m.Rating() + case playerservices.FieldIsActive: + return m.IsActive() + case playerservices.FieldCreatedAt: + return m.CreatedAt() + case playerservices.FieldUpdatedAt: + return m.UpdatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *PlayerServicesMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case playerservices.FieldPlayerID: + return m.OldPlayerID(ctx) + case playerservices.FieldGameID: + return m.OldGameID(ctx) + case playerservices.FieldTitle: + return m.OldTitle(ctx) + case playerservices.FieldDescription: + return m.OldDescription(ctx) + case playerservices.FieldPrice: + return m.OldPrice(ctx) + case playerservices.FieldUnit: + return m.OldUnit(ctx) + case playerservices.FieldRankRange: + return m.OldRankRange(ctx) + case playerservices.FieldAvailability: + return m.OldAvailability(ctx) + case playerservices.FieldRating: + return m.OldRating(ctx) + case playerservices.FieldIsActive: + return m.OldIsActive(ctx) + case playerservices.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case playerservices.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown PlayerServices field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *PlayerServicesMutation) SetField(name string, value ent.Value) error { + switch name { + case playerservices.FieldPlayerID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPlayerID(v) + return nil + case playerservices.FieldGameID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetGameID(v) + return nil + case playerservices.FieldTitle: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTitle(v) + return nil + case playerservices.FieldDescription: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDescription(v) + return nil + case playerservices.FieldPrice: + v, ok := value.(decimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPrice(v) + return nil + case playerservices.FieldUnit: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUnit(v) + return nil + case playerservices.FieldRankRange: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRankRange(v) + return nil + case playerservices.FieldAvailability: + v, ok := value.([]string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAvailability(v) + return nil + case playerservices.FieldRating: + v, ok := value.(decimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRating(v) + return nil + case playerservices.FieldIsActive: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetIsActive(v) + return nil + case playerservices.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case playerservices.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown PlayerServices field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *PlayerServicesMutation) AddedFields() []string { + var fields []string + if m.addplayer_id != nil { + fields = append(fields, playerservices.FieldPlayerID) + } + if m.addgame_id != nil { + fields = append(fields, playerservices.FieldGameID) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *PlayerServicesMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case playerservices.FieldPlayerID: + return m.AddedPlayerID() + case playerservices.FieldGameID: + return m.AddedGameID() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *PlayerServicesMutation) AddField(name string, value ent.Value) error { + switch name { + case playerservices.FieldPlayerID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddPlayerID(v) + return nil + case playerservices.FieldGameID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddGameID(v) + return nil + } + return fmt.Errorf("unknown PlayerServices numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *PlayerServicesMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(playerservices.FieldDescription) { + fields = append(fields, playerservices.FieldDescription) + } + if m.FieldCleared(playerservices.FieldRankRange) { + fields = append(fields, playerservices.FieldRankRange) + } + if m.FieldCleared(playerservices.FieldAvailability) { + fields = append(fields, playerservices.FieldAvailability) + } + if m.FieldCleared(playerservices.FieldIsActive) { + fields = append(fields, playerservices.FieldIsActive) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *PlayerServicesMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *PlayerServicesMutation) ClearField(name string) error { + switch name { + case playerservices.FieldDescription: + m.ClearDescription() + return nil + case playerservices.FieldRankRange: + m.ClearRankRange() + return nil + case playerservices.FieldAvailability: + m.ClearAvailability() + return nil + case playerservices.FieldIsActive: + m.ClearIsActive() + return nil + } + return fmt.Errorf("unknown PlayerServices nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *PlayerServicesMutation) ResetField(name string) error { + switch name { + case playerservices.FieldPlayerID: + m.ResetPlayerID() + return nil + case playerservices.FieldGameID: + m.ResetGameID() + return nil + case playerservices.FieldTitle: + m.ResetTitle() + return nil + case playerservices.FieldDescription: + m.ResetDescription() + return nil + case playerservices.FieldPrice: + m.ResetPrice() + return nil + case playerservices.FieldUnit: + m.ResetUnit() + return nil + case playerservices.FieldRankRange: + m.ResetRankRange() + return nil + case playerservices.FieldAvailability: + m.ResetAvailability() + return nil + case playerservices.FieldRating: + m.ResetRating() + return nil + case playerservices.FieldIsActive: + m.ResetIsActive() + return nil + case playerservices.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case playerservices.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown PlayerServices field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *PlayerServicesMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *PlayerServicesMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *PlayerServicesMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *PlayerServicesMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *PlayerServicesMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *PlayerServicesMutation) EdgeCleared(name string) bool { + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *PlayerServicesMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown PlayerServices unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *PlayerServicesMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown PlayerServices edge %s", name) +} + +// PlayersMutation represents an operation that mutates the Players nodes in the graph. +type PlayersMutation struct { + config + op Op + typ string + id *int64 + user_id *int64 + adduser_id *int64 + status *string + gender *int + addgender *int + rating *decimal.Decimal + total_orders *int + addtotal_orders *int + completed_orders *int + addcompleted_orders *int + shop_id *int64 + addshop_id *int64 + tags *[]string + appendtags []string + games *pq.Int64Array + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*Players, error) + predicates []predicate.Players +} + +var _ ent.Mutation = (*PlayersMutation)(nil) + +// playersOption allows management of the mutation configuration using functional options. +type playersOption func(*PlayersMutation) + +// newPlayersMutation creates new mutation for the Players entity. +func newPlayersMutation(c config, op Op, opts ...playersOption) *PlayersMutation { + m := &PlayersMutation{ + config: c, + op: op, + typ: TypePlayers, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withPlayersID sets the ID field of the mutation. +func withPlayersID(id int64) playersOption { + return func(m *PlayersMutation) { + var ( + err error + once sync.Once + value *Players + ) + m.oldValue = func(ctx context.Context) (*Players, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Players.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withPlayers sets the old Players of the mutation. +func withPlayers(node *Players) playersOption { + return func(m *PlayersMutation) { + m.oldValue = func(context.Context) (*Players, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m PlayersMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m PlayersMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("models: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of Players entities. +func (m *PlayersMutation) SetID(id int64) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *PlayersMutation) ID() (id int64, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *PlayersMutation) IDs(ctx context.Context) ([]int64, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int64{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Players.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetUserID sets the "user_id" field. +func (m *PlayersMutation) SetUserID(i int64) { + m.user_id = &i + m.adduser_id = nil +} + +// UserID returns the value of the "user_id" field in the mutation. +func (m *PlayersMutation) UserID() (r int64, exists bool) { + v := m.user_id + if v == nil { + return + } + return *v, true +} + +// OldUserID returns the old "user_id" field's value of the Players entity. +// If the Players object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayersMutation) OldUserID(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUserID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUserID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUserID: %w", err) + } + return oldValue.UserID, nil +} + +// AddUserID adds i to the "user_id" field. +func (m *PlayersMutation) AddUserID(i int64) { + if m.adduser_id != nil { + *m.adduser_id += i + } else { + m.adduser_id = &i + } +} + +// AddedUserID returns the value that was added to the "user_id" field in this mutation. +func (m *PlayersMutation) AddedUserID() (r int64, exists bool) { + v := m.adduser_id + if v == nil { + return + } + return *v, true +} + +// ResetUserID resets all changes to the "user_id" field. +func (m *PlayersMutation) ResetUserID() { + m.user_id = nil + m.adduser_id = nil +} + +// SetStatus sets the "status" field. +func (m *PlayersMutation) SetStatus(s string) { + m.status = &s +} + +// Status returns the value of the "status" field in the mutation. +func (m *PlayersMutation) Status() (r string, exists bool) { + v := m.status + if v == nil { + return + } + return *v, true +} + +// OldStatus returns the old "status" field's value of the Players entity. +// If the Players object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayersMutation) OldStatus(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStatus is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStatus requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStatus: %w", err) + } + return oldValue.Status, nil +} + +// ResetStatus resets all changes to the "status" field. +func (m *PlayersMutation) ResetStatus() { + m.status = nil +} + +// SetGender sets the "gender" field. +func (m *PlayersMutation) SetGender(i int) { + m.gender = &i + m.addgender = nil +} + +// Gender returns the value of the "gender" field in the mutation. +func (m *PlayersMutation) Gender() (r int, exists bool) { + v := m.gender + if v == nil { + return + } + return *v, true +} + +// OldGender returns the old "gender" field's value of the Players entity. +// If the Players object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayersMutation) OldGender(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldGender is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldGender requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldGender: %w", err) + } + return oldValue.Gender, nil +} + +// AddGender adds i to the "gender" field. +func (m *PlayersMutation) AddGender(i int) { + if m.addgender != nil { + *m.addgender += i + } else { + m.addgender = &i + } +} + +// AddedGender returns the value that was added to the "gender" field in this mutation. +func (m *PlayersMutation) AddedGender() (r int, exists bool) { + v := m.addgender + if v == nil { + return + } + return *v, true +} + +// ResetGender resets all changes to the "gender" field. +func (m *PlayersMutation) ResetGender() { + m.gender = nil + m.addgender = nil +} + +// SetRating sets the "rating" field. +func (m *PlayersMutation) SetRating(d decimal.Decimal) { + m.rating = &d +} + +// Rating returns the value of the "rating" field in the mutation. +func (m *PlayersMutation) Rating() (r decimal.Decimal, exists bool) { + v := m.rating + if v == nil { + return + } + return *v, true +} + +// OldRating returns the old "rating" field's value of the Players entity. +// If the Players object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayersMutation) OldRating(ctx context.Context) (v decimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRating is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRating requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRating: %w", err) + } + return oldValue.Rating, nil +} + +// ClearRating clears the value of the "rating" field. +func (m *PlayersMutation) ClearRating() { + m.rating = nil + m.clearedFields[players.FieldRating] = struct{}{} +} + +// RatingCleared returns if the "rating" field was cleared in this mutation. +func (m *PlayersMutation) RatingCleared() bool { + _, ok := m.clearedFields[players.FieldRating] + return ok +} + +// ResetRating resets all changes to the "rating" field. +func (m *PlayersMutation) ResetRating() { + m.rating = nil + delete(m.clearedFields, players.FieldRating) +} + +// SetTotalOrders sets the "total_orders" field. +func (m *PlayersMutation) SetTotalOrders(i int) { + m.total_orders = &i + m.addtotal_orders = nil +} + +// TotalOrders returns the value of the "total_orders" field in the mutation. +func (m *PlayersMutation) TotalOrders() (r int, exists bool) { + v := m.total_orders + if v == nil { + return + } + return *v, true +} + +// OldTotalOrders returns the old "total_orders" field's value of the Players entity. +// If the Players object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayersMutation) OldTotalOrders(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTotalOrders is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTotalOrders requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTotalOrders: %w", err) + } + return oldValue.TotalOrders, nil +} + +// AddTotalOrders adds i to the "total_orders" field. +func (m *PlayersMutation) AddTotalOrders(i int) { + if m.addtotal_orders != nil { + *m.addtotal_orders += i + } else { + m.addtotal_orders = &i + } +} + +// AddedTotalOrders returns the value that was added to the "total_orders" field in this mutation. +func (m *PlayersMutation) AddedTotalOrders() (r int, exists bool) { + v := m.addtotal_orders + if v == nil { + return + } + return *v, true +} + +// ClearTotalOrders clears the value of the "total_orders" field. +func (m *PlayersMutation) ClearTotalOrders() { + m.total_orders = nil + m.addtotal_orders = nil + m.clearedFields[players.FieldTotalOrders] = struct{}{} +} + +// TotalOrdersCleared returns if the "total_orders" field was cleared in this mutation. +func (m *PlayersMutation) TotalOrdersCleared() bool { + _, ok := m.clearedFields[players.FieldTotalOrders] + return ok +} + +// ResetTotalOrders resets all changes to the "total_orders" field. +func (m *PlayersMutation) ResetTotalOrders() { + m.total_orders = nil + m.addtotal_orders = nil + delete(m.clearedFields, players.FieldTotalOrders) +} + +// SetCompletedOrders sets the "completed_orders" field. +func (m *PlayersMutation) SetCompletedOrders(i int) { + m.completed_orders = &i + m.addcompleted_orders = nil +} + +// CompletedOrders returns the value of the "completed_orders" field in the mutation. +func (m *PlayersMutation) CompletedOrders() (r int, exists bool) { + v := m.completed_orders + if v == nil { + return + } + return *v, true +} + +// OldCompletedOrders returns the old "completed_orders" field's value of the Players entity. +// If the Players object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayersMutation) OldCompletedOrders(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCompletedOrders is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCompletedOrders requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCompletedOrders: %w", err) + } + return oldValue.CompletedOrders, nil +} + +// AddCompletedOrders adds i to the "completed_orders" field. +func (m *PlayersMutation) AddCompletedOrders(i int) { + if m.addcompleted_orders != nil { + *m.addcompleted_orders += i + } else { + m.addcompleted_orders = &i + } +} + +// AddedCompletedOrders returns the value that was added to the "completed_orders" field in this mutation. +func (m *PlayersMutation) AddedCompletedOrders() (r int, exists bool) { + v := m.addcompleted_orders + if v == nil { + return + } + return *v, true +} + +// ClearCompletedOrders clears the value of the "completed_orders" field. +func (m *PlayersMutation) ClearCompletedOrders() { + m.completed_orders = nil + m.addcompleted_orders = nil + m.clearedFields[players.FieldCompletedOrders] = struct{}{} +} + +// CompletedOrdersCleared returns if the "completed_orders" field was cleared in this mutation. +func (m *PlayersMutation) CompletedOrdersCleared() bool { + _, ok := m.clearedFields[players.FieldCompletedOrders] + return ok +} + +// ResetCompletedOrders resets all changes to the "completed_orders" field. +func (m *PlayersMutation) ResetCompletedOrders() { + m.completed_orders = nil + m.addcompleted_orders = nil + delete(m.clearedFields, players.FieldCompletedOrders) +} + +// SetShopID sets the "shop_id" field. +func (m *PlayersMutation) SetShopID(i int64) { + m.shop_id = &i + m.addshop_id = nil +} + +// ShopID returns the value of the "shop_id" field in the mutation. +func (m *PlayersMutation) ShopID() (r int64, exists bool) { + v := m.shop_id + if v == nil { + return + } + return *v, true +} + +// OldShopID returns the old "shop_id" field's value of the Players entity. +// If the Players object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayersMutation) OldShopID(ctx context.Context) (v *int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldShopID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldShopID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldShopID: %w", err) + } + return oldValue.ShopID, nil +} + +// AddShopID adds i to the "shop_id" field. +func (m *PlayersMutation) AddShopID(i int64) { + if m.addshop_id != nil { + *m.addshop_id += i + } else { + m.addshop_id = &i + } +} + +// AddedShopID returns the value that was added to the "shop_id" field in this mutation. +func (m *PlayersMutation) AddedShopID() (r int64, exists bool) { + v := m.addshop_id + if v == nil { + return + } + return *v, true +} + +// ClearShopID clears the value of the "shop_id" field. +func (m *PlayersMutation) ClearShopID() { + m.shop_id = nil + m.addshop_id = nil + m.clearedFields[players.FieldShopID] = struct{}{} +} + +// ShopIDCleared returns if the "shop_id" field was cleared in this mutation. +func (m *PlayersMutation) ShopIDCleared() bool { + _, ok := m.clearedFields[players.FieldShopID] + return ok +} + +// ResetShopID resets all changes to the "shop_id" field. +func (m *PlayersMutation) ResetShopID() { + m.shop_id = nil + m.addshop_id = nil + delete(m.clearedFields, players.FieldShopID) +} + +// SetTags sets the "tags" field. +func (m *PlayersMutation) SetTags(s []string) { + m.tags = &s + m.appendtags = nil +} + +// Tags returns the value of the "tags" field in the mutation. +func (m *PlayersMutation) Tags() (r []string, exists bool) { + v := m.tags + if v == nil { + return + } + return *v, true +} + +// OldTags returns the old "tags" field's value of the Players entity. +// If the Players object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayersMutation) OldTags(ctx context.Context) (v []string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTags is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTags requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTags: %w", err) + } + return oldValue.Tags, nil +} + +// AppendTags adds s to the "tags" field. +func (m *PlayersMutation) AppendTags(s []string) { + m.appendtags = append(m.appendtags, s...) +} + +// AppendedTags returns the list of values that were appended to the "tags" field in this mutation. +func (m *PlayersMutation) AppendedTags() ([]string, bool) { + if len(m.appendtags) == 0 { + return nil, false + } + return m.appendtags, true +} + +// ClearTags clears the value of the "tags" field. +func (m *PlayersMutation) ClearTags() { + m.tags = nil + m.appendtags = nil + m.clearedFields[players.FieldTags] = struct{}{} +} + +// TagsCleared returns if the "tags" field was cleared in this mutation. +func (m *PlayersMutation) TagsCleared() bool { + _, ok := m.clearedFields[players.FieldTags] + return ok +} + +// ResetTags resets all changes to the "tags" field. +func (m *PlayersMutation) ResetTags() { + m.tags = nil + m.appendtags = nil + delete(m.clearedFields, players.FieldTags) +} + +// SetGames sets the "games" field. +func (m *PlayersMutation) SetGames(pq pq.Int64Array) { + m.games = &pq +} + +// Games returns the value of the "games" field in the mutation. +func (m *PlayersMutation) Games() (r pq.Int64Array, exists bool) { + v := m.games + if v == nil { + return + } + return *v, true +} + +// OldGames returns the old "games" field's value of the Players entity. +// If the Players object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayersMutation) OldGames(ctx context.Context) (v pq.Int64Array, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldGames is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldGames requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldGames: %w", err) + } + return oldValue.Games, nil +} + +// ClearGames clears the value of the "games" field. +func (m *PlayersMutation) ClearGames() { + m.games = nil + m.clearedFields[players.FieldGames] = struct{}{} +} + +// GamesCleared returns if the "games" field was cleared in this mutation. +func (m *PlayersMutation) GamesCleared() bool { + _, ok := m.clearedFields[players.FieldGames] + return ok +} + +// ResetGames resets all changes to the "games" field. +func (m *PlayersMutation) ResetGames() { + m.games = nil + delete(m.clearedFields, players.FieldGames) +} + +// SetCreatedAt sets the "created_at" field. +func (m *PlayersMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *PlayersMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the Players entity. +// If the Players object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayersMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *PlayersMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *PlayersMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *PlayersMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the Players entity. +// If the Players object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *PlayersMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *PlayersMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// Where appends a list predicates to the PlayersMutation builder. +func (m *PlayersMutation) Where(ps ...predicate.Players) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the PlayersMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *PlayersMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Players, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *PlayersMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *PlayersMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (Players). +func (m *PlayersMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *PlayersMutation) Fields() []string { + fields := make([]string, 0, 11) + if m.user_id != nil { + fields = append(fields, players.FieldUserID) + } + if m.status != nil { + fields = append(fields, players.FieldStatus) + } + if m.gender != nil { + fields = append(fields, players.FieldGender) + } + if m.rating != nil { + fields = append(fields, players.FieldRating) + } + if m.total_orders != nil { + fields = append(fields, players.FieldTotalOrders) + } + if m.completed_orders != nil { + fields = append(fields, players.FieldCompletedOrders) + } + if m.shop_id != nil { + fields = append(fields, players.FieldShopID) + } + if m.tags != nil { + fields = append(fields, players.FieldTags) + } + if m.games != nil { + fields = append(fields, players.FieldGames) + } + if m.created_at != nil { + fields = append(fields, players.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, players.FieldUpdatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *PlayersMutation) Field(name string) (ent.Value, bool) { + switch name { + case players.FieldUserID: + return m.UserID() + case players.FieldStatus: + return m.Status() + case players.FieldGender: + return m.Gender() + case players.FieldRating: + return m.Rating() + case players.FieldTotalOrders: + return m.TotalOrders() + case players.FieldCompletedOrders: + return m.CompletedOrders() + case players.FieldShopID: + return m.ShopID() + case players.FieldTags: + return m.Tags() + case players.FieldGames: + return m.Games() + case players.FieldCreatedAt: + return m.CreatedAt() + case players.FieldUpdatedAt: + return m.UpdatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *PlayersMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case players.FieldUserID: + return m.OldUserID(ctx) + case players.FieldStatus: + return m.OldStatus(ctx) + case players.FieldGender: + return m.OldGender(ctx) + case players.FieldRating: + return m.OldRating(ctx) + case players.FieldTotalOrders: + return m.OldTotalOrders(ctx) + case players.FieldCompletedOrders: + return m.OldCompletedOrders(ctx) + case players.FieldShopID: + return m.OldShopID(ctx) + case players.FieldTags: + return m.OldTags(ctx) + case players.FieldGames: + return m.OldGames(ctx) + case players.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case players.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown Players field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *PlayersMutation) SetField(name string, value ent.Value) error { + switch name { + case players.FieldUserID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUserID(v) + return nil + case players.FieldStatus: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStatus(v) + return nil + case players.FieldGender: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetGender(v) + return nil + case players.FieldRating: + v, ok := value.(decimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRating(v) + return nil + case players.FieldTotalOrders: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTotalOrders(v) + return nil + case players.FieldCompletedOrders: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCompletedOrders(v) + return nil + case players.FieldShopID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetShopID(v) + return nil + case players.FieldTags: + v, ok := value.([]string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTags(v) + return nil + case players.FieldGames: + v, ok := value.(pq.Int64Array) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetGames(v) + return nil + case players.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case players.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown Players field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *PlayersMutation) AddedFields() []string { + var fields []string + if m.adduser_id != nil { + fields = append(fields, players.FieldUserID) + } + if m.addgender != nil { + fields = append(fields, players.FieldGender) + } + if m.addtotal_orders != nil { + fields = append(fields, players.FieldTotalOrders) + } + if m.addcompleted_orders != nil { + fields = append(fields, players.FieldCompletedOrders) + } + if m.addshop_id != nil { + fields = append(fields, players.FieldShopID) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *PlayersMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case players.FieldUserID: + return m.AddedUserID() + case players.FieldGender: + return m.AddedGender() + case players.FieldTotalOrders: + return m.AddedTotalOrders() + case players.FieldCompletedOrders: + return m.AddedCompletedOrders() + case players.FieldShopID: + return m.AddedShopID() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *PlayersMutation) AddField(name string, value ent.Value) error { + switch name { + case players.FieldUserID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddUserID(v) + return nil + case players.FieldGender: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddGender(v) + return nil + case players.FieldTotalOrders: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddTotalOrders(v) + return nil + case players.FieldCompletedOrders: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddCompletedOrders(v) + return nil + case players.FieldShopID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddShopID(v) + return nil + } + return fmt.Errorf("unknown Players numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *PlayersMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(players.FieldRating) { + fields = append(fields, players.FieldRating) + } + if m.FieldCleared(players.FieldTotalOrders) { + fields = append(fields, players.FieldTotalOrders) + } + if m.FieldCleared(players.FieldCompletedOrders) { + fields = append(fields, players.FieldCompletedOrders) + } + if m.FieldCleared(players.FieldShopID) { + fields = append(fields, players.FieldShopID) + } + if m.FieldCleared(players.FieldTags) { + fields = append(fields, players.FieldTags) + } + if m.FieldCleared(players.FieldGames) { + fields = append(fields, players.FieldGames) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *PlayersMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *PlayersMutation) ClearField(name string) error { + switch name { + case players.FieldRating: + m.ClearRating() + return nil + case players.FieldTotalOrders: + m.ClearTotalOrders() + return nil + case players.FieldCompletedOrders: + m.ClearCompletedOrders() + return nil + case players.FieldShopID: + m.ClearShopID() + return nil + case players.FieldTags: + m.ClearTags() + return nil + case players.FieldGames: + m.ClearGames() + return nil + } + return fmt.Errorf("unknown Players nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *PlayersMutation) ResetField(name string) error { + switch name { + case players.FieldUserID: + m.ResetUserID() + return nil + case players.FieldStatus: + m.ResetStatus() + return nil + case players.FieldGender: + m.ResetGender() + return nil + case players.FieldRating: + m.ResetRating() + return nil + case players.FieldTotalOrders: + m.ResetTotalOrders() + return nil + case players.FieldCompletedOrders: + m.ResetCompletedOrders() + return nil + case players.FieldShopID: + m.ResetShopID() + return nil + case players.FieldTags: + m.ResetTags() + return nil + case players.FieldGames: + m.ResetGames() + return nil + case players.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case players.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown Players field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *PlayersMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *PlayersMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *PlayersMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *PlayersMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *PlayersMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *PlayersMutation) EdgeCleared(name string) bool { + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *PlayersMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown Players unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *PlayersMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown Players edge %s", name) +} diff --git a/app/player/rpc/internal/models/players.go b/app/player/rpc/internal/models/players.go new file mode 100644 index 0000000..638193e --- /dev/null +++ b/app/player/rpc/internal/models/players.go @@ -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 diff --git a/app/player/rpc/internal/models/players/players.go b/app/player/rpc/internal/models/players/players.go new file mode 100644 index 0000000..1c3b814 --- /dev/null +++ b/app/player/rpc/internal/models/players/players.go @@ -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() +} diff --git a/app/player/rpc/internal/models/players/where.go b/app/player/rpc/internal/models/players/where.go new file mode 100644 index 0000000..20088be --- /dev/null +++ b/app/player/rpc/internal/models/players/where.go @@ -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)) +} diff --git a/app/player/rpc/internal/models/players_create.go b/app/player/rpc/internal/models/players_create.go new file mode 100644 index 0000000..ea5e179 --- /dev/null +++ b/app/player/rpc/internal/models/players_create.go @@ -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) + } +} diff --git a/app/player/rpc/internal/models/players_delete.go b/app/player/rpc/internal/models/players_delete.go new file mode 100644 index 0000000..8710b94 --- /dev/null +++ b/app/player/rpc/internal/models/players_delete.go @@ -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) + } +} diff --git a/app/player/rpc/internal/models/players_query.go b/app/player/rpc/internal/models/players_query.go new file mode 100644 index 0000000..faf73de --- /dev/null +++ b/app/player/rpc/internal/models/players_query.go @@ -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) +} diff --git a/app/player/rpc/internal/models/players_update.go b/app/player/rpc/internal/models/players_update.go new file mode 100644 index 0000000..3a771a0 --- /dev/null +++ b/app/player/rpc/internal/models/players_update.go @@ -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 +} diff --git a/app/player/rpc/internal/models/playerservices.go b/app/player/rpc/internal/models/playerservices.go new file mode 100644 index 0000000..8f21635 --- /dev/null +++ b/app/player/rpc/internal/models/playerservices.go @@ -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 diff --git a/app/player/rpc/internal/models/playerservices/playerservices.go b/app/player/rpc/internal/models/playerservices/playerservices.go new file mode 100644 index 0000000..68bd47e --- /dev/null +++ b/app/player/rpc/internal/models/playerservices/playerservices.go @@ -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() +} diff --git a/app/player/rpc/internal/models/playerservices/where.go b/app/player/rpc/internal/models/playerservices/where.go new file mode 100644 index 0000000..2c00bbf --- /dev/null +++ b/app/player/rpc/internal/models/playerservices/where.go @@ -0,0 +1,676 @@ +// Code generated by ent, DO NOT EDIT. + +package playerservices + +import ( + "juwan-backend/app/player/rpc/internal/models/predicate" + "time" + + "entgo.io/ent/dialect/sql" + "github.com/shopspring/decimal" +) + +// ID filters vertices based on their ID field. +func ID(id int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLTE(FieldID, id)) +} + +// PlayerID applies equality check predicate on the "player_id" field. It's identical to PlayerIDEQ. +func PlayerID(v int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldPlayerID, v)) +} + +// GameID applies equality check predicate on the "game_id" field. It's identical to GameIDEQ. +func GameID(v int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldGameID, v)) +} + +// Title applies equality check predicate on the "title" field. It's identical to TitleEQ. +func Title(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldTitle, v)) +} + +// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. +func Description(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldDescription, v)) +} + +// Price applies equality check predicate on the "price" field. It's identical to PriceEQ. +func Price(v decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldPrice, v)) +} + +// Unit applies equality check predicate on the "unit" field. It's identical to UnitEQ. +func Unit(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldUnit, v)) +} + +// RankRange applies equality check predicate on the "rank_range" field. It's identical to RankRangeEQ. +func RankRange(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldRankRange, v)) +} + +// Rating applies equality check predicate on the "rating" field. It's identical to RatingEQ. +func Rating(v decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldRating, v)) +} + +// IsActive applies equality check predicate on the "is_active" field. It's identical to IsActiveEQ. +func IsActive(v bool) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldIsActive, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.PlayerServices { + return predicate.PlayerServices(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.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// PlayerIDEQ applies the EQ predicate on the "player_id" field. +func PlayerIDEQ(v int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldPlayerID, v)) +} + +// PlayerIDNEQ applies the NEQ predicate on the "player_id" field. +func PlayerIDNEQ(v int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNEQ(FieldPlayerID, v)) +} + +// PlayerIDIn applies the In predicate on the "player_id" field. +func PlayerIDIn(vs ...int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldIn(FieldPlayerID, vs...)) +} + +// PlayerIDNotIn applies the NotIn predicate on the "player_id" field. +func PlayerIDNotIn(vs ...int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNotIn(FieldPlayerID, vs...)) +} + +// PlayerIDGT applies the GT predicate on the "player_id" field. +func PlayerIDGT(v int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGT(FieldPlayerID, v)) +} + +// PlayerIDGTE applies the GTE predicate on the "player_id" field. +func PlayerIDGTE(v int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGTE(FieldPlayerID, v)) +} + +// PlayerIDLT applies the LT predicate on the "player_id" field. +func PlayerIDLT(v int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLT(FieldPlayerID, v)) +} + +// PlayerIDLTE applies the LTE predicate on the "player_id" field. +func PlayerIDLTE(v int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLTE(FieldPlayerID, v)) +} + +// GameIDEQ applies the EQ predicate on the "game_id" field. +func GameIDEQ(v int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldGameID, v)) +} + +// GameIDNEQ applies the NEQ predicate on the "game_id" field. +func GameIDNEQ(v int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNEQ(FieldGameID, v)) +} + +// GameIDIn applies the In predicate on the "game_id" field. +func GameIDIn(vs ...int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldIn(FieldGameID, vs...)) +} + +// GameIDNotIn applies the NotIn predicate on the "game_id" field. +func GameIDNotIn(vs ...int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNotIn(FieldGameID, vs...)) +} + +// GameIDGT applies the GT predicate on the "game_id" field. +func GameIDGT(v int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGT(FieldGameID, v)) +} + +// GameIDGTE applies the GTE predicate on the "game_id" field. +func GameIDGTE(v int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGTE(FieldGameID, v)) +} + +// GameIDLT applies the LT predicate on the "game_id" field. +func GameIDLT(v int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLT(FieldGameID, v)) +} + +// GameIDLTE applies the LTE predicate on the "game_id" field. +func GameIDLTE(v int64) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLTE(FieldGameID, v)) +} + +// TitleEQ applies the EQ predicate on the "title" field. +func TitleEQ(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldTitle, v)) +} + +// TitleNEQ applies the NEQ predicate on the "title" field. +func TitleNEQ(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNEQ(FieldTitle, v)) +} + +// TitleIn applies the In predicate on the "title" field. +func TitleIn(vs ...string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldIn(FieldTitle, vs...)) +} + +// TitleNotIn applies the NotIn predicate on the "title" field. +func TitleNotIn(vs ...string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNotIn(FieldTitle, vs...)) +} + +// TitleGT applies the GT predicate on the "title" field. +func TitleGT(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGT(FieldTitle, v)) +} + +// TitleGTE applies the GTE predicate on the "title" field. +func TitleGTE(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGTE(FieldTitle, v)) +} + +// TitleLT applies the LT predicate on the "title" field. +func TitleLT(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLT(FieldTitle, v)) +} + +// TitleLTE applies the LTE predicate on the "title" field. +func TitleLTE(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLTE(FieldTitle, v)) +} + +// TitleContains applies the Contains predicate on the "title" field. +func TitleContains(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldContains(FieldTitle, v)) +} + +// TitleHasPrefix applies the HasPrefix predicate on the "title" field. +func TitleHasPrefix(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldHasPrefix(FieldTitle, v)) +} + +// TitleHasSuffix applies the HasSuffix predicate on the "title" field. +func TitleHasSuffix(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldHasSuffix(FieldTitle, v)) +} + +// TitleEqualFold applies the EqualFold predicate on the "title" field. +func TitleEqualFold(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEqualFold(FieldTitle, v)) +} + +// TitleContainsFold applies the ContainsFold predicate on the "title" field. +func TitleContainsFold(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldContainsFold(FieldTitle, v)) +} + +// DescriptionEQ applies the EQ predicate on the "description" field. +func DescriptionEQ(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldDescription, v)) +} + +// DescriptionNEQ applies the NEQ predicate on the "description" field. +func DescriptionNEQ(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNEQ(FieldDescription, v)) +} + +// DescriptionIn applies the In predicate on the "description" field. +func DescriptionIn(vs ...string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldIn(FieldDescription, vs...)) +} + +// DescriptionNotIn applies the NotIn predicate on the "description" field. +func DescriptionNotIn(vs ...string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNotIn(FieldDescription, vs...)) +} + +// DescriptionGT applies the GT predicate on the "description" field. +func DescriptionGT(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGT(FieldDescription, v)) +} + +// DescriptionGTE applies the GTE predicate on the "description" field. +func DescriptionGTE(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGTE(FieldDescription, v)) +} + +// DescriptionLT applies the LT predicate on the "description" field. +func DescriptionLT(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLT(FieldDescription, v)) +} + +// DescriptionLTE applies the LTE predicate on the "description" field. +func DescriptionLTE(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLTE(FieldDescription, v)) +} + +// DescriptionContains applies the Contains predicate on the "description" field. +func DescriptionContains(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldContains(FieldDescription, v)) +} + +// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. +func DescriptionHasPrefix(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldHasPrefix(FieldDescription, v)) +} + +// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. +func DescriptionHasSuffix(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldHasSuffix(FieldDescription, v)) +} + +// DescriptionIsNil applies the IsNil predicate on the "description" field. +func DescriptionIsNil() predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldIsNull(FieldDescription)) +} + +// DescriptionNotNil applies the NotNil predicate on the "description" field. +func DescriptionNotNil() predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNotNull(FieldDescription)) +} + +// DescriptionEqualFold applies the EqualFold predicate on the "description" field. +func DescriptionEqualFold(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEqualFold(FieldDescription, v)) +} + +// DescriptionContainsFold applies the ContainsFold predicate on the "description" field. +func DescriptionContainsFold(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldContainsFold(FieldDescription, v)) +} + +// PriceEQ applies the EQ predicate on the "price" field. +func PriceEQ(v decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldPrice, v)) +} + +// PriceNEQ applies the NEQ predicate on the "price" field. +func PriceNEQ(v decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNEQ(FieldPrice, v)) +} + +// PriceIn applies the In predicate on the "price" field. +func PriceIn(vs ...decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldIn(FieldPrice, vs...)) +} + +// PriceNotIn applies the NotIn predicate on the "price" field. +func PriceNotIn(vs ...decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNotIn(FieldPrice, vs...)) +} + +// PriceGT applies the GT predicate on the "price" field. +func PriceGT(v decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGT(FieldPrice, v)) +} + +// PriceGTE applies the GTE predicate on the "price" field. +func PriceGTE(v decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGTE(FieldPrice, v)) +} + +// PriceLT applies the LT predicate on the "price" field. +func PriceLT(v decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLT(FieldPrice, v)) +} + +// PriceLTE applies the LTE predicate on the "price" field. +func PriceLTE(v decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLTE(FieldPrice, v)) +} + +// UnitEQ applies the EQ predicate on the "unit" field. +func UnitEQ(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldUnit, v)) +} + +// UnitNEQ applies the NEQ predicate on the "unit" field. +func UnitNEQ(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNEQ(FieldUnit, v)) +} + +// UnitIn applies the In predicate on the "unit" field. +func UnitIn(vs ...string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldIn(FieldUnit, vs...)) +} + +// UnitNotIn applies the NotIn predicate on the "unit" field. +func UnitNotIn(vs ...string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNotIn(FieldUnit, vs...)) +} + +// UnitGT applies the GT predicate on the "unit" field. +func UnitGT(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGT(FieldUnit, v)) +} + +// UnitGTE applies the GTE predicate on the "unit" field. +func UnitGTE(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGTE(FieldUnit, v)) +} + +// UnitLT applies the LT predicate on the "unit" field. +func UnitLT(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLT(FieldUnit, v)) +} + +// UnitLTE applies the LTE predicate on the "unit" field. +func UnitLTE(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLTE(FieldUnit, v)) +} + +// UnitContains applies the Contains predicate on the "unit" field. +func UnitContains(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldContains(FieldUnit, v)) +} + +// UnitHasPrefix applies the HasPrefix predicate on the "unit" field. +func UnitHasPrefix(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldHasPrefix(FieldUnit, v)) +} + +// UnitHasSuffix applies the HasSuffix predicate on the "unit" field. +func UnitHasSuffix(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldHasSuffix(FieldUnit, v)) +} + +// UnitEqualFold applies the EqualFold predicate on the "unit" field. +func UnitEqualFold(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEqualFold(FieldUnit, v)) +} + +// UnitContainsFold applies the ContainsFold predicate on the "unit" field. +func UnitContainsFold(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldContainsFold(FieldUnit, v)) +} + +// RankRangeEQ applies the EQ predicate on the "rank_range" field. +func RankRangeEQ(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldRankRange, v)) +} + +// RankRangeNEQ applies the NEQ predicate on the "rank_range" field. +func RankRangeNEQ(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNEQ(FieldRankRange, v)) +} + +// RankRangeIn applies the In predicate on the "rank_range" field. +func RankRangeIn(vs ...string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldIn(FieldRankRange, vs...)) +} + +// RankRangeNotIn applies the NotIn predicate on the "rank_range" field. +func RankRangeNotIn(vs ...string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNotIn(FieldRankRange, vs...)) +} + +// RankRangeGT applies the GT predicate on the "rank_range" field. +func RankRangeGT(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGT(FieldRankRange, v)) +} + +// RankRangeGTE applies the GTE predicate on the "rank_range" field. +func RankRangeGTE(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGTE(FieldRankRange, v)) +} + +// RankRangeLT applies the LT predicate on the "rank_range" field. +func RankRangeLT(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLT(FieldRankRange, v)) +} + +// RankRangeLTE applies the LTE predicate on the "rank_range" field. +func RankRangeLTE(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLTE(FieldRankRange, v)) +} + +// RankRangeContains applies the Contains predicate on the "rank_range" field. +func RankRangeContains(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldContains(FieldRankRange, v)) +} + +// RankRangeHasPrefix applies the HasPrefix predicate on the "rank_range" field. +func RankRangeHasPrefix(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldHasPrefix(FieldRankRange, v)) +} + +// RankRangeHasSuffix applies the HasSuffix predicate on the "rank_range" field. +func RankRangeHasSuffix(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldHasSuffix(FieldRankRange, v)) +} + +// RankRangeIsNil applies the IsNil predicate on the "rank_range" field. +func RankRangeIsNil() predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldIsNull(FieldRankRange)) +} + +// RankRangeNotNil applies the NotNil predicate on the "rank_range" field. +func RankRangeNotNil() predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNotNull(FieldRankRange)) +} + +// RankRangeEqualFold applies the EqualFold predicate on the "rank_range" field. +func RankRangeEqualFold(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEqualFold(FieldRankRange, v)) +} + +// RankRangeContainsFold applies the ContainsFold predicate on the "rank_range" field. +func RankRangeContainsFold(v string) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldContainsFold(FieldRankRange, v)) +} + +// AvailabilityIsNil applies the IsNil predicate on the "availability" field. +func AvailabilityIsNil() predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldIsNull(FieldAvailability)) +} + +// AvailabilityNotNil applies the NotNil predicate on the "availability" field. +func AvailabilityNotNil() predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNotNull(FieldAvailability)) +} + +// RatingEQ applies the EQ predicate on the "rating" field. +func RatingEQ(v decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldRating, v)) +} + +// RatingNEQ applies the NEQ predicate on the "rating" field. +func RatingNEQ(v decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNEQ(FieldRating, v)) +} + +// RatingIn applies the In predicate on the "rating" field. +func RatingIn(vs ...decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldIn(FieldRating, vs...)) +} + +// RatingNotIn applies the NotIn predicate on the "rating" field. +func RatingNotIn(vs ...decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNotIn(FieldRating, vs...)) +} + +// RatingGT applies the GT predicate on the "rating" field. +func RatingGT(v decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGT(FieldRating, v)) +} + +// RatingGTE applies the GTE predicate on the "rating" field. +func RatingGTE(v decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGTE(FieldRating, v)) +} + +// RatingLT applies the LT predicate on the "rating" field. +func RatingLT(v decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLT(FieldRating, v)) +} + +// RatingLTE applies the LTE predicate on the "rating" field. +func RatingLTE(v decimal.Decimal) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLTE(FieldRating, v)) +} + +// IsActiveEQ applies the EQ predicate on the "is_active" field. +func IsActiveEQ(v bool) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldIsActive, v)) +} + +// IsActiveNEQ applies the NEQ predicate on the "is_active" field. +func IsActiveNEQ(v bool) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNEQ(FieldIsActive, v)) +} + +// IsActiveIsNil applies the IsNil predicate on the "is_active" field. +func IsActiveIsNil() predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldIsNull(FieldIsActive)) +} + +// IsActiveNotNil applies the NotNil predicate on the "is_active" field. +func IsActiveNotNil() predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNotNull(FieldIsActive)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.PlayerServices { + return predicate.PlayerServices(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.PlayerServices) predicate.PlayerServices { + return predicate.PlayerServices(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.PlayerServices) predicate.PlayerServices { + return predicate.PlayerServices(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.PlayerServices) predicate.PlayerServices { + return predicate.PlayerServices(sql.NotPredicates(p)) +} diff --git a/app/player/rpc/internal/models/playerservices_create.go b/app/player/rpc/internal/models/playerservices_create.go new file mode 100644 index 0000000..9f9eca5 --- /dev/null +++ b/app/player/rpc/internal/models/playerservices_create.go @@ -0,0 +1,417 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "errors" + "fmt" + "juwan-backend/app/player/rpc/internal/models/playerservices" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/shopspring/decimal" +) + +// PlayerServicesCreate is the builder for creating a PlayerServices entity. +type PlayerServicesCreate struct { + config + mutation *PlayerServicesMutation + hooks []Hook +} + +// SetPlayerID sets the "player_id" field. +func (_c *PlayerServicesCreate) SetPlayerID(v int64) *PlayerServicesCreate { + _c.mutation.SetPlayerID(v) + return _c +} + +// SetGameID sets the "game_id" field. +func (_c *PlayerServicesCreate) SetGameID(v int64) *PlayerServicesCreate { + _c.mutation.SetGameID(v) + return _c +} + +// SetTitle sets the "title" field. +func (_c *PlayerServicesCreate) SetTitle(v string) *PlayerServicesCreate { + _c.mutation.SetTitle(v) + return _c +} + +// SetDescription sets the "description" field. +func (_c *PlayerServicesCreate) SetDescription(v string) *PlayerServicesCreate { + _c.mutation.SetDescription(v) + return _c +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_c *PlayerServicesCreate) SetNillableDescription(v *string) *PlayerServicesCreate { + if v != nil { + _c.SetDescription(*v) + } + return _c +} + +// SetPrice sets the "price" field. +func (_c *PlayerServicesCreate) SetPrice(v decimal.Decimal) *PlayerServicesCreate { + _c.mutation.SetPrice(v) + return _c +} + +// SetUnit sets the "unit" field. +func (_c *PlayerServicesCreate) SetUnit(v string) *PlayerServicesCreate { + _c.mutation.SetUnit(v) + return _c +} + +// SetRankRange sets the "rank_range" field. +func (_c *PlayerServicesCreate) SetRankRange(v string) *PlayerServicesCreate { + _c.mutation.SetRankRange(v) + return _c +} + +// SetNillableRankRange sets the "rank_range" field if the given value is not nil. +func (_c *PlayerServicesCreate) SetNillableRankRange(v *string) *PlayerServicesCreate { + if v != nil { + _c.SetRankRange(*v) + } + return _c +} + +// SetAvailability sets the "availability" field. +func (_c *PlayerServicesCreate) SetAvailability(v []string) *PlayerServicesCreate { + _c.mutation.SetAvailability(v) + return _c +} + +// SetRating sets the "rating" field. +func (_c *PlayerServicesCreate) SetRating(v decimal.Decimal) *PlayerServicesCreate { + _c.mutation.SetRating(v) + return _c +} + +// SetNillableRating sets the "rating" field if the given value is not nil. +func (_c *PlayerServicesCreate) SetNillableRating(v *decimal.Decimal) *PlayerServicesCreate { + if v != nil { + _c.SetRating(*v) + } + return _c +} + +// SetIsActive sets the "is_active" field. +func (_c *PlayerServicesCreate) SetIsActive(v bool) *PlayerServicesCreate { + _c.mutation.SetIsActive(v) + return _c +} + +// SetNillableIsActive sets the "is_active" field if the given value is not nil. +func (_c *PlayerServicesCreate) SetNillableIsActive(v *bool) *PlayerServicesCreate { + if v != nil { + _c.SetIsActive(*v) + } + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *PlayerServicesCreate) SetCreatedAt(v time.Time) *PlayerServicesCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *PlayerServicesCreate) SetNillableCreatedAt(v *time.Time) *PlayerServicesCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *PlayerServicesCreate) SetUpdatedAt(v time.Time) *PlayerServicesCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *PlayerServicesCreate) SetNillableUpdatedAt(v *time.Time) *PlayerServicesCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *PlayerServicesCreate) SetID(v int64) *PlayerServicesCreate { + _c.mutation.SetID(v) + return _c +} + +// Mutation returns the PlayerServicesMutation object of the builder. +func (_c *PlayerServicesCreate) Mutation() *PlayerServicesMutation { + return _c.mutation +} + +// Save creates the PlayerServices in the database. +func (_c *PlayerServicesCreate) Save(ctx context.Context) (*PlayerServices, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *PlayerServicesCreate) SaveX(ctx context.Context) *PlayerServices { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *PlayerServicesCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *PlayerServicesCreate) 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 *PlayerServicesCreate) defaults() { + if _, ok := _c.mutation.Availability(); !ok { + v := playerservices.DefaultAvailability + _c.mutation.SetAvailability(v) + } + if _, ok := _c.mutation.Rating(); !ok { + v := playerservices.DefaultRating + _c.mutation.SetRating(v) + } + if _, ok := _c.mutation.IsActive(); !ok { + v := playerservices.DefaultIsActive + _c.mutation.SetIsActive(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := playerservices.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := playerservices.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *PlayerServicesCreate) check() error { + if _, ok := _c.mutation.PlayerID(); !ok { + return &ValidationError{Name: "player_id", err: errors.New(`models: missing required field "PlayerServices.player_id"`)} + } + if _, ok := _c.mutation.GameID(); !ok { + return &ValidationError{Name: "game_id", err: errors.New(`models: missing required field "PlayerServices.game_id"`)} + } + if _, ok := _c.mutation.Title(); !ok { + return &ValidationError{Name: "title", err: errors.New(`models: missing required field "PlayerServices.title"`)} + } + if v, ok := _c.mutation.Title(); ok { + if err := playerservices.TitleValidator(v); err != nil { + return &ValidationError{Name: "title", err: fmt.Errorf(`models: validator failed for field "PlayerServices.title": %w`, err)} + } + } + if _, ok := _c.mutation.Price(); !ok { + return &ValidationError{Name: "price", err: errors.New(`models: missing required field "PlayerServices.price"`)} + } + if _, ok := _c.mutation.Unit(); !ok { + return &ValidationError{Name: "unit", err: errors.New(`models: missing required field "PlayerServices.unit"`)} + } + if v, ok := _c.mutation.Unit(); ok { + if err := playerservices.UnitValidator(v); err != nil { + return &ValidationError{Name: "unit", err: fmt.Errorf(`models: validator failed for field "PlayerServices.unit": %w`, err)} + } + } + if v, ok := _c.mutation.RankRange(); ok { + if err := playerservices.RankRangeValidator(v); err != nil { + return &ValidationError{Name: "rank_range", err: fmt.Errorf(`models: validator failed for field "PlayerServices.rank_range": %w`, err)} + } + } + if _, ok := _c.mutation.Rating(); !ok { + return &ValidationError{Name: "rating", err: errors.New(`models: missing required field "PlayerServices.rating"`)} + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`models: missing required field "PlayerServices.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`models: missing required field "PlayerServices.updated_at"`)} + } + return nil +} + +func (_c *PlayerServicesCreate) sqlSave(ctx context.Context) (*PlayerServices, 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 *PlayerServicesCreate) createSpec() (*PlayerServices, *sqlgraph.CreateSpec) { + var ( + _node = &PlayerServices{config: _c.config} + _spec = sqlgraph.NewCreateSpec(playerservices.Table, sqlgraph.NewFieldSpec(playerservices.FieldID, field.TypeInt64)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := _c.mutation.PlayerID(); ok { + _spec.SetField(playerservices.FieldPlayerID, field.TypeInt64, value) + _node.PlayerID = value + } + if value, ok := _c.mutation.GameID(); ok { + _spec.SetField(playerservices.FieldGameID, field.TypeInt64, value) + _node.GameID = value + } + if value, ok := _c.mutation.Title(); ok { + _spec.SetField(playerservices.FieldTitle, field.TypeString, value) + _node.Title = value + } + if value, ok := _c.mutation.Description(); ok { + _spec.SetField(playerservices.FieldDescription, field.TypeString, value) + _node.Description = &value + } + if value, ok := _c.mutation.Price(); ok { + _spec.SetField(playerservices.FieldPrice, field.TypeOther, value) + _node.Price = value + } + if value, ok := _c.mutation.Unit(); ok { + _spec.SetField(playerservices.FieldUnit, field.TypeString, value) + _node.Unit = value + } + if value, ok := _c.mutation.RankRange(); ok { + _spec.SetField(playerservices.FieldRankRange, field.TypeString, value) + _node.RankRange = &value + } + if value, ok := _c.mutation.Availability(); ok { + _spec.SetField(playerservices.FieldAvailability, field.TypeJSON, value) + _node.Availability = value + } + if value, ok := _c.mutation.Rating(); ok { + _spec.SetField(playerservices.FieldRating, field.TypeOther, value) + _node.Rating = value + } + if value, ok := _c.mutation.IsActive(); ok { + _spec.SetField(playerservices.FieldIsActive, field.TypeBool, value) + _node.IsActive = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(playerservices.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(playerservices.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + return _node, _spec +} + +// PlayerServicesCreateBulk is the builder for creating many PlayerServices entities in bulk. +type PlayerServicesCreateBulk struct { + config + err error + builders []*PlayerServicesCreate +} + +// Save creates the PlayerServices entities in the database. +func (_c *PlayerServicesCreateBulk) Save(ctx context.Context) ([]*PlayerServices, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*PlayerServices, 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.(*PlayerServicesMutation) + 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 *PlayerServicesCreateBulk) SaveX(ctx context.Context) []*PlayerServices { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *PlayerServicesCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *PlayerServicesCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/app/player/rpc/internal/models/playerservices_delete.go b/app/player/rpc/internal/models/playerservices_delete.go new file mode 100644 index 0000000..f99ee34 --- /dev/null +++ b/app/player/rpc/internal/models/playerservices_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "juwan-backend/app/player/rpc/internal/models/playerservices" + "juwan-backend/app/player/rpc/internal/models/predicate" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// PlayerServicesDelete is the builder for deleting a PlayerServices entity. +type PlayerServicesDelete struct { + config + hooks []Hook + mutation *PlayerServicesMutation +} + +// Where appends a list predicates to the PlayerServicesDelete builder. +func (_d *PlayerServicesDelete) Where(ps ...predicate.PlayerServices) *PlayerServicesDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *PlayerServicesDelete) 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 *PlayerServicesDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *PlayerServicesDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(playerservices.Table, sqlgraph.NewFieldSpec(playerservices.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 +} + +// PlayerServicesDeleteOne is the builder for deleting a single PlayerServices entity. +type PlayerServicesDeleteOne struct { + _d *PlayerServicesDelete +} + +// Where appends a list predicates to the PlayerServicesDelete builder. +func (_d *PlayerServicesDeleteOne) Where(ps ...predicate.PlayerServices) *PlayerServicesDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *PlayerServicesDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{playerservices.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *PlayerServicesDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/app/player/rpc/internal/models/playerservices_query.go b/app/player/rpc/internal/models/playerservices_query.go new file mode 100644 index 0000000..aad0d91 --- /dev/null +++ b/app/player/rpc/internal/models/playerservices_query.go @@ -0,0 +1,527 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "fmt" + "juwan-backend/app/player/rpc/internal/models/playerservices" + "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" +) + +// PlayerServicesQuery is the builder for querying PlayerServices entities. +type PlayerServicesQuery struct { + config + ctx *QueryContext + order []playerservices.OrderOption + inters []Interceptor + predicates []predicate.PlayerServices + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the PlayerServicesQuery builder. +func (_q *PlayerServicesQuery) Where(ps ...predicate.PlayerServices) *PlayerServicesQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *PlayerServicesQuery) Limit(limit int) *PlayerServicesQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *PlayerServicesQuery) Offset(offset int) *PlayerServicesQuery { + _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 *PlayerServicesQuery) Unique(unique bool) *PlayerServicesQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *PlayerServicesQuery) Order(o ...playerservices.OrderOption) *PlayerServicesQuery { + _q.order = append(_q.order, o...) + return _q +} + +// First returns the first PlayerServices entity from the query. +// Returns a *NotFoundError when no PlayerServices was found. +func (_q *PlayerServicesQuery) First(ctx context.Context) (*PlayerServices, 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{playerservices.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *PlayerServicesQuery) FirstX(ctx context.Context) *PlayerServices { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first PlayerServices ID from the query. +// Returns a *NotFoundError when no PlayerServices ID was found. +func (_q *PlayerServicesQuery) 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{playerservices.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *PlayerServicesQuery) FirstIDX(ctx context.Context) int64 { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single PlayerServices entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one PlayerServices entity is found. +// Returns a *NotFoundError when no PlayerServices entities are found. +func (_q *PlayerServicesQuery) Only(ctx context.Context) (*PlayerServices, 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{playerservices.Label} + default: + return nil, &NotSingularError{playerservices.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *PlayerServicesQuery) OnlyX(ctx context.Context) *PlayerServices { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only PlayerServices ID in the query. +// Returns a *NotSingularError when more than one PlayerServices ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *PlayerServicesQuery) 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{playerservices.Label} + default: + err = &NotSingularError{playerservices.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *PlayerServicesQuery) 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 PlayerServicesSlice. +func (_q *PlayerServicesQuery) All(ctx context.Context) ([]*PlayerServices, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*PlayerServices, *PlayerServicesQuery]() + return withInterceptors[[]*PlayerServices](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *PlayerServicesQuery) AllX(ctx context.Context) []*PlayerServices { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of PlayerServices IDs. +func (_q *PlayerServicesQuery) 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(playerservices.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *PlayerServicesQuery) 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 *PlayerServicesQuery) 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[*PlayerServicesQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *PlayerServicesQuery) 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 *PlayerServicesQuery) 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 *PlayerServicesQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the PlayerServicesQuery 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 *PlayerServicesQuery) Clone() *PlayerServicesQuery { + if _q == nil { + return nil + } + return &PlayerServicesQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]playerservices.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.PlayerServices{}, _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 { +// PlayerID int64 `json:"player_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.PlayerServices.Query(). +// GroupBy(playerservices.FieldPlayerID). +// Aggregate(models.Count()). +// Scan(ctx, &v) +func (_q *PlayerServicesQuery) GroupBy(field string, fields ...string) *PlayerServicesGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &PlayerServicesGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = playerservices.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 { +// PlayerID int64 `json:"player_id,omitempty"` +// } +// +// client.PlayerServices.Query(). +// Select(playerservices.FieldPlayerID). +// Scan(ctx, &v) +func (_q *PlayerServicesQuery) Select(fields ...string) *PlayerServicesSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &PlayerServicesSelect{PlayerServicesQuery: _q} + sbuild.label = playerservices.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a PlayerServicesSelect configured with the given aggregations. +func (_q *PlayerServicesQuery) Aggregate(fns ...AggregateFunc) *PlayerServicesSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *PlayerServicesQuery) 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 !playerservices.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 *PlayerServicesQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*PlayerServices, error) { + var ( + nodes = []*PlayerServices{} + _spec = _q.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*PlayerServices).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &PlayerServices{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 *PlayerServicesQuery) 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 *PlayerServicesQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(playerservices.Table, playerservices.Columns, sqlgraph.NewFieldSpec(playerservices.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, playerservices.FieldID) + for i := range fields { + if fields[i] != playerservices.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 *PlayerServicesQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(playerservices.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = playerservices.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 +} + +// PlayerServicesGroupBy is the group-by builder for PlayerServices entities. +type PlayerServicesGroupBy struct { + selector + build *PlayerServicesQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *PlayerServicesGroupBy) Aggregate(fns ...AggregateFunc) *PlayerServicesGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *PlayerServicesGroupBy) 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[*PlayerServicesQuery, *PlayerServicesGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *PlayerServicesGroupBy) sqlScan(ctx context.Context, root *PlayerServicesQuery, 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) +} + +// PlayerServicesSelect is the builder for selecting fields of PlayerServices entities. +type PlayerServicesSelect struct { + *PlayerServicesQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *PlayerServicesSelect) Aggregate(fns ...AggregateFunc) *PlayerServicesSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *PlayerServicesSelect) 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[*PlayerServicesQuery, *PlayerServicesSelect](ctx, _s.PlayerServicesQuery, _s, _s.inters, v) +} + +func (_s *PlayerServicesSelect) sqlScan(ctx context.Context, root *PlayerServicesQuery, 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) +} diff --git a/app/player/rpc/internal/models/playerservices_update.go b/app/player/rpc/internal/models/playerservices_update.go new file mode 100644 index 0000000..9735200 --- /dev/null +++ b/app/player/rpc/internal/models/playerservices_update.go @@ -0,0 +1,718 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "errors" + "fmt" + "juwan-backend/app/player/rpc/internal/models/playerservices" + "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/shopspring/decimal" +) + +// PlayerServicesUpdate is the builder for updating PlayerServices entities. +type PlayerServicesUpdate struct { + config + hooks []Hook + mutation *PlayerServicesMutation +} + +// Where appends a list predicates to the PlayerServicesUpdate builder. +func (_u *PlayerServicesUpdate) Where(ps ...predicate.PlayerServices) *PlayerServicesUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetPlayerID sets the "player_id" field. +func (_u *PlayerServicesUpdate) SetPlayerID(v int64) *PlayerServicesUpdate { + _u.mutation.ResetPlayerID() + _u.mutation.SetPlayerID(v) + return _u +} + +// SetNillablePlayerID sets the "player_id" field if the given value is not nil. +func (_u *PlayerServicesUpdate) SetNillablePlayerID(v *int64) *PlayerServicesUpdate { + if v != nil { + _u.SetPlayerID(*v) + } + return _u +} + +// AddPlayerID adds value to the "player_id" field. +func (_u *PlayerServicesUpdate) AddPlayerID(v int64) *PlayerServicesUpdate { + _u.mutation.AddPlayerID(v) + return _u +} + +// SetGameID sets the "game_id" field. +func (_u *PlayerServicesUpdate) SetGameID(v int64) *PlayerServicesUpdate { + _u.mutation.ResetGameID() + _u.mutation.SetGameID(v) + return _u +} + +// SetNillableGameID sets the "game_id" field if the given value is not nil. +func (_u *PlayerServicesUpdate) SetNillableGameID(v *int64) *PlayerServicesUpdate { + if v != nil { + _u.SetGameID(*v) + } + return _u +} + +// AddGameID adds value to the "game_id" field. +func (_u *PlayerServicesUpdate) AddGameID(v int64) *PlayerServicesUpdate { + _u.mutation.AddGameID(v) + return _u +} + +// SetTitle sets the "title" field. +func (_u *PlayerServicesUpdate) SetTitle(v string) *PlayerServicesUpdate { + _u.mutation.SetTitle(v) + return _u +} + +// SetNillableTitle sets the "title" field if the given value is not nil. +func (_u *PlayerServicesUpdate) SetNillableTitle(v *string) *PlayerServicesUpdate { + if v != nil { + _u.SetTitle(*v) + } + return _u +} + +// SetDescription sets the "description" field. +func (_u *PlayerServicesUpdate) SetDescription(v string) *PlayerServicesUpdate { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *PlayerServicesUpdate) SetNillableDescription(v *string) *PlayerServicesUpdate { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// ClearDescription clears the value of the "description" field. +func (_u *PlayerServicesUpdate) ClearDescription() *PlayerServicesUpdate { + _u.mutation.ClearDescription() + return _u +} + +// SetPrice sets the "price" field. +func (_u *PlayerServicesUpdate) SetPrice(v decimal.Decimal) *PlayerServicesUpdate { + _u.mutation.SetPrice(v) + return _u +} + +// SetNillablePrice sets the "price" field if the given value is not nil. +func (_u *PlayerServicesUpdate) SetNillablePrice(v *decimal.Decimal) *PlayerServicesUpdate { + if v != nil { + _u.SetPrice(*v) + } + return _u +} + +// SetUnit sets the "unit" field. +func (_u *PlayerServicesUpdate) SetUnit(v string) *PlayerServicesUpdate { + _u.mutation.SetUnit(v) + return _u +} + +// SetNillableUnit sets the "unit" field if the given value is not nil. +func (_u *PlayerServicesUpdate) SetNillableUnit(v *string) *PlayerServicesUpdate { + if v != nil { + _u.SetUnit(*v) + } + return _u +} + +// SetRankRange sets the "rank_range" field. +func (_u *PlayerServicesUpdate) SetRankRange(v string) *PlayerServicesUpdate { + _u.mutation.SetRankRange(v) + return _u +} + +// SetNillableRankRange sets the "rank_range" field if the given value is not nil. +func (_u *PlayerServicesUpdate) SetNillableRankRange(v *string) *PlayerServicesUpdate { + if v != nil { + _u.SetRankRange(*v) + } + return _u +} + +// ClearRankRange clears the value of the "rank_range" field. +func (_u *PlayerServicesUpdate) ClearRankRange() *PlayerServicesUpdate { + _u.mutation.ClearRankRange() + return _u +} + +// SetAvailability sets the "availability" field. +func (_u *PlayerServicesUpdate) SetAvailability(v []string) *PlayerServicesUpdate { + _u.mutation.SetAvailability(v) + return _u +} + +// AppendAvailability appends value to the "availability" field. +func (_u *PlayerServicesUpdate) AppendAvailability(v []string) *PlayerServicesUpdate { + _u.mutation.AppendAvailability(v) + return _u +} + +// ClearAvailability clears the value of the "availability" field. +func (_u *PlayerServicesUpdate) ClearAvailability() *PlayerServicesUpdate { + _u.mutation.ClearAvailability() + return _u +} + +// SetRating sets the "rating" field. +func (_u *PlayerServicesUpdate) SetRating(v decimal.Decimal) *PlayerServicesUpdate { + _u.mutation.SetRating(v) + return _u +} + +// SetNillableRating sets the "rating" field if the given value is not nil. +func (_u *PlayerServicesUpdate) SetNillableRating(v *decimal.Decimal) *PlayerServicesUpdate { + if v != nil { + _u.SetRating(*v) + } + return _u +} + +// SetIsActive sets the "is_active" field. +func (_u *PlayerServicesUpdate) SetIsActive(v bool) *PlayerServicesUpdate { + _u.mutation.SetIsActive(v) + return _u +} + +// SetNillableIsActive sets the "is_active" field if the given value is not nil. +func (_u *PlayerServicesUpdate) SetNillableIsActive(v *bool) *PlayerServicesUpdate { + if v != nil { + _u.SetIsActive(*v) + } + return _u +} + +// ClearIsActive clears the value of the "is_active" field. +func (_u *PlayerServicesUpdate) ClearIsActive() *PlayerServicesUpdate { + _u.mutation.ClearIsActive() + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *PlayerServicesUpdate) SetUpdatedAt(v time.Time) *PlayerServicesUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// Mutation returns the PlayerServicesMutation object of the builder. +func (_u *PlayerServicesUpdate) Mutation() *PlayerServicesMutation { + return _u.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *PlayerServicesUpdate) 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 *PlayerServicesUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *PlayerServicesUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *PlayerServicesUpdate) 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 *PlayerServicesUpdate) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := playerservices.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *PlayerServicesUpdate) check() error { + if v, ok := _u.mutation.Title(); ok { + if err := playerservices.TitleValidator(v); err != nil { + return &ValidationError{Name: "title", err: fmt.Errorf(`models: validator failed for field "PlayerServices.title": %w`, err)} + } + } + if v, ok := _u.mutation.Unit(); ok { + if err := playerservices.UnitValidator(v); err != nil { + return &ValidationError{Name: "unit", err: fmt.Errorf(`models: validator failed for field "PlayerServices.unit": %w`, err)} + } + } + if v, ok := _u.mutation.RankRange(); ok { + if err := playerservices.RankRangeValidator(v); err != nil { + return &ValidationError{Name: "rank_range", err: fmt.Errorf(`models: validator failed for field "PlayerServices.rank_range": %w`, err)} + } + } + return nil +} + +func (_u *PlayerServicesUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(playerservices.Table, playerservices.Columns, sqlgraph.NewFieldSpec(playerservices.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.PlayerID(); ok { + _spec.SetField(playerservices.FieldPlayerID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedPlayerID(); ok { + _spec.AddField(playerservices.FieldPlayerID, field.TypeInt64, value) + } + if value, ok := _u.mutation.GameID(); ok { + _spec.SetField(playerservices.FieldGameID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedGameID(); ok { + _spec.AddField(playerservices.FieldGameID, field.TypeInt64, value) + } + if value, ok := _u.mutation.Title(); ok { + _spec.SetField(playerservices.FieldTitle, field.TypeString, value) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(playerservices.FieldDescription, field.TypeString, value) + } + if _u.mutation.DescriptionCleared() { + _spec.ClearField(playerservices.FieldDescription, field.TypeString) + } + if value, ok := _u.mutation.Price(); ok { + _spec.SetField(playerservices.FieldPrice, field.TypeOther, value) + } + if value, ok := _u.mutation.Unit(); ok { + _spec.SetField(playerservices.FieldUnit, field.TypeString, value) + } + if value, ok := _u.mutation.RankRange(); ok { + _spec.SetField(playerservices.FieldRankRange, field.TypeString, value) + } + if _u.mutation.RankRangeCleared() { + _spec.ClearField(playerservices.FieldRankRange, field.TypeString) + } + if value, ok := _u.mutation.Availability(); ok { + _spec.SetField(playerservices.FieldAvailability, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedAvailability(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, playerservices.FieldAvailability, value) + }) + } + if _u.mutation.AvailabilityCleared() { + _spec.ClearField(playerservices.FieldAvailability, field.TypeJSON) + } + if value, ok := _u.mutation.Rating(); ok { + _spec.SetField(playerservices.FieldRating, field.TypeOther, value) + } + if value, ok := _u.mutation.IsActive(); ok { + _spec.SetField(playerservices.FieldIsActive, field.TypeBool, value) + } + if _u.mutation.IsActiveCleared() { + _spec.ClearField(playerservices.FieldIsActive, field.TypeBool) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(playerservices.FieldUpdatedAt, field.TypeTime, value) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{playerservices.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// PlayerServicesUpdateOne is the builder for updating a single PlayerServices entity. +type PlayerServicesUpdateOne struct { + config + fields []string + hooks []Hook + mutation *PlayerServicesMutation +} + +// SetPlayerID sets the "player_id" field. +func (_u *PlayerServicesUpdateOne) SetPlayerID(v int64) *PlayerServicesUpdateOne { + _u.mutation.ResetPlayerID() + _u.mutation.SetPlayerID(v) + return _u +} + +// SetNillablePlayerID sets the "player_id" field if the given value is not nil. +func (_u *PlayerServicesUpdateOne) SetNillablePlayerID(v *int64) *PlayerServicesUpdateOne { + if v != nil { + _u.SetPlayerID(*v) + } + return _u +} + +// AddPlayerID adds value to the "player_id" field. +func (_u *PlayerServicesUpdateOne) AddPlayerID(v int64) *PlayerServicesUpdateOne { + _u.mutation.AddPlayerID(v) + return _u +} + +// SetGameID sets the "game_id" field. +func (_u *PlayerServicesUpdateOne) SetGameID(v int64) *PlayerServicesUpdateOne { + _u.mutation.ResetGameID() + _u.mutation.SetGameID(v) + return _u +} + +// SetNillableGameID sets the "game_id" field if the given value is not nil. +func (_u *PlayerServicesUpdateOne) SetNillableGameID(v *int64) *PlayerServicesUpdateOne { + if v != nil { + _u.SetGameID(*v) + } + return _u +} + +// AddGameID adds value to the "game_id" field. +func (_u *PlayerServicesUpdateOne) AddGameID(v int64) *PlayerServicesUpdateOne { + _u.mutation.AddGameID(v) + return _u +} + +// SetTitle sets the "title" field. +func (_u *PlayerServicesUpdateOne) SetTitle(v string) *PlayerServicesUpdateOne { + _u.mutation.SetTitle(v) + return _u +} + +// SetNillableTitle sets the "title" field if the given value is not nil. +func (_u *PlayerServicesUpdateOne) SetNillableTitle(v *string) *PlayerServicesUpdateOne { + if v != nil { + _u.SetTitle(*v) + } + return _u +} + +// SetDescription sets the "description" field. +func (_u *PlayerServicesUpdateOne) SetDescription(v string) *PlayerServicesUpdateOne { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *PlayerServicesUpdateOne) SetNillableDescription(v *string) *PlayerServicesUpdateOne { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// ClearDescription clears the value of the "description" field. +func (_u *PlayerServicesUpdateOne) ClearDescription() *PlayerServicesUpdateOne { + _u.mutation.ClearDescription() + return _u +} + +// SetPrice sets the "price" field. +func (_u *PlayerServicesUpdateOne) SetPrice(v decimal.Decimal) *PlayerServicesUpdateOne { + _u.mutation.SetPrice(v) + return _u +} + +// SetNillablePrice sets the "price" field if the given value is not nil. +func (_u *PlayerServicesUpdateOne) SetNillablePrice(v *decimal.Decimal) *PlayerServicesUpdateOne { + if v != nil { + _u.SetPrice(*v) + } + return _u +} + +// SetUnit sets the "unit" field. +func (_u *PlayerServicesUpdateOne) SetUnit(v string) *PlayerServicesUpdateOne { + _u.mutation.SetUnit(v) + return _u +} + +// SetNillableUnit sets the "unit" field if the given value is not nil. +func (_u *PlayerServicesUpdateOne) SetNillableUnit(v *string) *PlayerServicesUpdateOne { + if v != nil { + _u.SetUnit(*v) + } + return _u +} + +// SetRankRange sets the "rank_range" field. +func (_u *PlayerServicesUpdateOne) SetRankRange(v string) *PlayerServicesUpdateOne { + _u.mutation.SetRankRange(v) + return _u +} + +// SetNillableRankRange sets the "rank_range" field if the given value is not nil. +func (_u *PlayerServicesUpdateOne) SetNillableRankRange(v *string) *PlayerServicesUpdateOne { + if v != nil { + _u.SetRankRange(*v) + } + return _u +} + +// ClearRankRange clears the value of the "rank_range" field. +func (_u *PlayerServicesUpdateOne) ClearRankRange() *PlayerServicesUpdateOne { + _u.mutation.ClearRankRange() + return _u +} + +// SetAvailability sets the "availability" field. +func (_u *PlayerServicesUpdateOne) SetAvailability(v []string) *PlayerServicesUpdateOne { + _u.mutation.SetAvailability(v) + return _u +} + +// AppendAvailability appends value to the "availability" field. +func (_u *PlayerServicesUpdateOne) AppendAvailability(v []string) *PlayerServicesUpdateOne { + _u.mutation.AppendAvailability(v) + return _u +} + +// ClearAvailability clears the value of the "availability" field. +func (_u *PlayerServicesUpdateOne) ClearAvailability() *PlayerServicesUpdateOne { + _u.mutation.ClearAvailability() + return _u +} + +// SetRating sets the "rating" field. +func (_u *PlayerServicesUpdateOne) SetRating(v decimal.Decimal) *PlayerServicesUpdateOne { + _u.mutation.SetRating(v) + return _u +} + +// SetNillableRating sets the "rating" field if the given value is not nil. +func (_u *PlayerServicesUpdateOne) SetNillableRating(v *decimal.Decimal) *PlayerServicesUpdateOne { + if v != nil { + _u.SetRating(*v) + } + return _u +} + +// SetIsActive sets the "is_active" field. +func (_u *PlayerServicesUpdateOne) SetIsActive(v bool) *PlayerServicesUpdateOne { + _u.mutation.SetIsActive(v) + return _u +} + +// SetNillableIsActive sets the "is_active" field if the given value is not nil. +func (_u *PlayerServicesUpdateOne) SetNillableIsActive(v *bool) *PlayerServicesUpdateOne { + if v != nil { + _u.SetIsActive(*v) + } + return _u +} + +// ClearIsActive clears the value of the "is_active" field. +func (_u *PlayerServicesUpdateOne) ClearIsActive() *PlayerServicesUpdateOne { + _u.mutation.ClearIsActive() + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *PlayerServicesUpdateOne) SetUpdatedAt(v time.Time) *PlayerServicesUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// Mutation returns the PlayerServicesMutation object of the builder. +func (_u *PlayerServicesUpdateOne) Mutation() *PlayerServicesMutation { + return _u.mutation +} + +// Where appends a list predicates to the PlayerServicesUpdate builder. +func (_u *PlayerServicesUpdateOne) Where(ps ...predicate.PlayerServices) *PlayerServicesUpdateOne { + _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 *PlayerServicesUpdateOne) Select(field string, fields ...string) *PlayerServicesUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated PlayerServices entity. +func (_u *PlayerServicesUpdateOne) Save(ctx context.Context) (*PlayerServices, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *PlayerServicesUpdateOne) SaveX(ctx context.Context) *PlayerServices { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *PlayerServicesUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *PlayerServicesUpdateOne) 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 *PlayerServicesUpdateOne) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := playerservices.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *PlayerServicesUpdateOne) check() error { + if v, ok := _u.mutation.Title(); ok { + if err := playerservices.TitleValidator(v); err != nil { + return &ValidationError{Name: "title", err: fmt.Errorf(`models: validator failed for field "PlayerServices.title": %w`, err)} + } + } + if v, ok := _u.mutation.Unit(); ok { + if err := playerservices.UnitValidator(v); err != nil { + return &ValidationError{Name: "unit", err: fmt.Errorf(`models: validator failed for field "PlayerServices.unit": %w`, err)} + } + } + if v, ok := _u.mutation.RankRange(); ok { + if err := playerservices.RankRangeValidator(v); err != nil { + return &ValidationError{Name: "rank_range", err: fmt.Errorf(`models: validator failed for field "PlayerServices.rank_range": %w`, err)} + } + } + return nil +} + +func (_u *PlayerServicesUpdateOne) sqlSave(ctx context.Context) (_node *PlayerServices, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(playerservices.Table, playerservices.Columns, sqlgraph.NewFieldSpec(playerservices.FieldID, field.TypeInt64)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "PlayerServices.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, playerservices.FieldID) + for _, f := range fields { + if !playerservices.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)} + } + if f != playerservices.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.PlayerID(); ok { + _spec.SetField(playerservices.FieldPlayerID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedPlayerID(); ok { + _spec.AddField(playerservices.FieldPlayerID, field.TypeInt64, value) + } + if value, ok := _u.mutation.GameID(); ok { + _spec.SetField(playerservices.FieldGameID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedGameID(); ok { + _spec.AddField(playerservices.FieldGameID, field.TypeInt64, value) + } + if value, ok := _u.mutation.Title(); ok { + _spec.SetField(playerservices.FieldTitle, field.TypeString, value) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(playerservices.FieldDescription, field.TypeString, value) + } + if _u.mutation.DescriptionCleared() { + _spec.ClearField(playerservices.FieldDescription, field.TypeString) + } + if value, ok := _u.mutation.Price(); ok { + _spec.SetField(playerservices.FieldPrice, field.TypeOther, value) + } + if value, ok := _u.mutation.Unit(); ok { + _spec.SetField(playerservices.FieldUnit, field.TypeString, value) + } + if value, ok := _u.mutation.RankRange(); ok { + _spec.SetField(playerservices.FieldRankRange, field.TypeString, value) + } + if _u.mutation.RankRangeCleared() { + _spec.ClearField(playerservices.FieldRankRange, field.TypeString) + } + if value, ok := _u.mutation.Availability(); ok { + _spec.SetField(playerservices.FieldAvailability, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedAvailability(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, playerservices.FieldAvailability, value) + }) + } + if _u.mutation.AvailabilityCleared() { + _spec.ClearField(playerservices.FieldAvailability, field.TypeJSON) + } + if value, ok := _u.mutation.Rating(); ok { + _spec.SetField(playerservices.FieldRating, field.TypeOther, value) + } + if value, ok := _u.mutation.IsActive(); ok { + _spec.SetField(playerservices.FieldIsActive, field.TypeBool, value) + } + if _u.mutation.IsActiveCleared() { + _spec.ClearField(playerservices.FieldIsActive, field.TypeBool) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(playerservices.FieldUpdatedAt, field.TypeTime, value) + } + _node = &PlayerServices{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{playerservices.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/app/player/rpc/internal/models/predicate/predicate.go b/app/player/rpc/internal/models/predicate/predicate.go new file mode 100644 index 0000000..3fa8dae --- /dev/null +++ b/app/player/rpc/internal/models/predicate/predicate.go @@ -0,0 +1,13 @@ +// Code generated by ent, DO NOT EDIT. + +package predicate + +import ( + "entgo.io/ent/dialect/sql" +) + +// PlayerServices is the predicate function for playerservices builders. +type PlayerServices func(*sql.Selector) + +// Players is the predicate function for players builders. +type Players func(*sql.Selector) diff --git a/app/player/rpc/internal/models/runtime.go b/app/player/rpc/internal/models/runtime.go new file mode 100644 index 0000000..dbc4938 --- /dev/null +++ b/app/player/rpc/internal/models/runtime.go @@ -0,0 +1,93 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "juwan-backend/app/player/rpc/internal/models/players" + "juwan-backend/app/player/rpc/internal/models/playerservices" + "juwan-backend/app/player/rpc/internal/models/schema" + "time" + + "github.com/lib/pq" + "github.com/shopspring/decimal" +) + +// The init function reads all schema descriptors with runtime code +// (default values, validators, hooks and policies) and stitches it +// to their package variables. +func init() { + playerservicesFields := schema.PlayerServices{}.Fields() + _ = playerservicesFields + // playerservicesDescTitle is the schema descriptor for title field. + playerservicesDescTitle := playerservicesFields[3].Descriptor() + // playerservices.TitleValidator is a validator for the "title" field. It is called by the builders before save. + playerservices.TitleValidator = playerservicesDescTitle.Validators[0].(func(string) error) + // playerservicesDescUnit is the schema descriptor for unit field. + playerservicesDescUnit := playerservicesFields[6].Descriptor() + // playerservices.UnitValidator is a validator for the "unit" field. It is called by the builders before save. + playerservices.UnitValidator = playerservicesDescUnit.Validators[0].(func(string) error) + // playerservicesDescRankRange is the schema descriptor for rank_range field. + playerservicesDescRankRange := playerservicesFields[7].Descriptor() + // playerservices.RankRangeValidator is a validator for the "rank_range" field. It is called by the builders before save. + playerservices.RankRangeValidator = playerservicesDescRankRange.Validators[0].(func(string) error) + // playerservicesDescAvailability is the schema descriptor for availability field. + playerservicesDescAvailability := playerservicesFields[8].Descriptor() + // playerservices.DefaultAvailability holds the default value on creation for the availability field. + playerservices.DefaultAvailability = playerservicesDescAvailability.Default.([]string) + // playerservicesDescRating is the schema descriptor for rating field. + playerservicesDescRating := playerservicesFields[9].Descriptor() + // playerservices.DefaultRating holds the default value on creation for the rating field. + playerservices.DefaultRating = playerservicesDescRating.Default.(decimal.Decimal) + // playerservicesDescIsActive is the schema descriptor for is_active field. + playerservicesDescIsActive := playerservicesFields[10].Descriptor() + // playerservices.DefaultIsActive holds the default value on creation for the is_active field. + playerservices.DefaultIsActive = playerservicesDescIsActive.Default.(bool) + // playerservicesDescCreatedAt is the schema descriptor for created_at field. + playerservicesDescCreatedAt := playerservicesFields[11].Descriptor() + // playerservices.DefaultCreatedAt holds the default value on creation for the created_at field. + playerservices.DefaultCreatedAt = playerservicesDescCreatedAt.Default.(func() time.Time) + // playerservicesDescUpdatedAt is the schema descriptor for updated_at field. + playerservicesDescUpdatedAt := playerservicesFields[12].Descriptor() + // playerservices.DefaultUpdatedAt holds the default value on creation for the updated_at field. + playerservices.DefaultUpdatedAt = playerservicesDescUpdatedAt.Default.(func() time.Time) + // playerservices.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + playerservices.UpdateDefaultUpdatedAt = playerservicesDescUpdatedAt.UpdateDefault.(func() time.Time) + playersFields := schema.Players{}.Fields() + _ = playersFields + // playersDescStatus is the schema descriptor for status field. + playersDescStatus := playersFields[2].Descriptor() + // players.DefaultStatus holds the default value on creation for the status field. + players.DefaultStatus = playersDescStatus.Default.(string) + // players.StatusValidator is a validator for the "status" field. It is called by the builders before save. + players.StatusValidator = playersDescStatus.Validators[0].(func(string) error) + // playersDescRating is the schema descriptor for rating field. + playersDescRating := playersFields[4].Descriptor() + // players.DefaultRating holds the default value on creation for the rating field. + players.DefaultRating = playersDescRating.Default.(decimal.Decimal) + // playersDescTotalOrders is the schema descriptor for total_orders field. + playersDescTotalOrders := playersFields[5].Descriptor() + // players.DefaultTotalOrders holds the default value on creation for the total_orders field. + players.DefaultTotalOrders = playersDescTotalOrders.Default.(int) + // playersDescCompletedOrders is the schema descriptor for completed_orders field. + playersDescCompletedOrders := playersFields[6].Descriptor() + // players.DefaultCompletedOrders holds the default value on creation for the completed_orders field. + players.DefaultCompletedOrders = playersDescCompletedOrders.Default.(int) + // playersDescTags is the schema descriptor for tags field. + playersDescTags := playersFields[8].Descriptor() + // players.DefaultTags holds the default value on creation for the tags field. + players.DefaultTags = playersDescTags.Default.([]string) + // playersDescGames is the schema descriptor for games field. + playersDescGames := playersFields[9].Descriptor() + // players.DefaultGames holds the default value on creation for the games field. + players.DefaultGames = playersDescGames.Default.(pq.Int64Array) + // playersDescCreatedAt is the schema descriptor for created_at field. + playersDescCreatedAt := playersFields[10].Descriptor() + // players.DefaultCreatedAt holds the default value on creation for the created_at field. + players.DefaultCreatedAt = playersDescCreatedAt.Default.(func() time.Time) + // playersDescUpdatedAt is the schema descriptor for updated_at field. + playersDescUpdatedAt := playersFields[11].Descriptor() + // players.DefaultUpdatedAt holds the default value on creation for the updated_at field. + players.DefaultUpdatedAt = playersDescUpdatedAt.Default.(func() time.Time) + // players.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + players.UpdateDefaultUpdatedAt = playersDescUpdatedAt.UpdateDefault.(func() time.Time) +} diff --git a/app/player/rpc/internal/models/runtime/runtime.go b/app/player/rpc/internal/models/runtime/runtime.go new file mode 100644 index 0000000..8a12d17 --- /dev/null +++ b/app/player/rpc/internal/models/runtime/runtime.go @@ -0,0 +1,10 @@ +// Code generated by ent, DO NOT EDIT. + +package runtime + +// The schema-stitching logic is generated in juwan-backend/app/player/rpc/internal/models/runtime.go + +const ( + Version = "v0.14.5" // Version of ent codegen. + Sum = "h1:Rj2WOYJtCkWyFo6a+5wB3EfBRP0rnx1fMk6gGA0UUe4=" // Sum of ent codegen. +) diff --git a/app/player/rpc/internal/models/schema/players.go b/app/player/rpc/internal/models/schema/players.go new file mode 100644 index 0000000..d07bddb --- /dev/null +++ b/app/player/rpc/internal/models/schema/players.go @@ -0,0 +1,51 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/schema/field" + "github.com/lib/pq" + "github.com/shopspring/decimal" +) + +var playerDefaultRating = decimal.RequireFromString("5.00") + +// Players holds the schema definition for the Players entity. +type Players struct { + ent.Schema +} + +// Fields of the Players. +func (Players) Fields() []ent.Field { + return []ent.Field{ + field.Int64("id").Immutable().Unique(), + field.Int64("user_id").Unique(), + field.String("status").MaxLen(20).Default("offline"), + field.Int("gender").Unique(), + field.Other("rating", decimal.Decimal{}). + Optional(). + Default(playerDefaultRating). + SchemaType(map[string]string{ + dialect.Postgres: "decimal(3,2)", + }), + field.Int("total_orders").Optional().Default(0), + field.Int("completed_orders").Optional().Default(0), + field.Int64("shop_id").Optional().Nillable(), + field.Strings("tags").Optional().Default([]string{}), + field.Other("games", pq.Int64Array{}). + Optional(). + Default(pq.Int64Array{}). + SchemaType(map[string]string{ + dialect.Postgres: "bigint[]", + }), + field.Time("created_at").Default(time.Now).Immutable(), + field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now), + } +} + +// Edges of the Players. +func (Players) Edges() []ent.Edge { + return nil +} diff --git a/app/player/rpc/internal/models/schema/playerservices.go b/app/player/rpc/internal/models/schema/playerservices.go new file mode 100644 index 0000000..88b8b87 --- /dev/null +++ b/app/player/rpc/internal/models/schema/playerservices.go @@ -0,0 +1,65 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" + "entgo.io/ent/schema/field" + "github.com/shopspring/decimal" +) + +var ( + decFive = decimal.RequireFromString("5.00") +) + +// PlayerServices holds the schema definition for the PlayerServices entity. +type PlayerServices struct { + ent.Schema +} + +// Annotations of the PlayerServices. +func (PlayerServices) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{ + Table: "player_services", + Checks: map[string]string{ + "chk_price_positive": "price > 0", + "chk_service_rating": "rating >= 0 AND rating <= 5", + }, + }, + } +} + +// Fields of the PlayerServices. +func (PlayerServices) Fields() []ent.Field { + return []ent.Field{ + field.Int64("id").Immutable().Unique(), + field.Int64("player_id"), + field.Int64("game_id"), + field.String("title").MaxLen(200), + field.String("description").Optional().Nillable(), + field.Other("price", decimal.Decimal{}). + SchemaType(map[string]string{ + dialect.Postgres: "decimal(10,2)", + }), + field.String("unit").MaxLen(20), + field.String("rank_range").MaxLen(100).Optional().Nillable(), + field.Strings("availability").Optional().Default([]string{}), + field.Other("rating", decimal.Decimal{}). + Default(decFive). + SchemaType(map[string]string{ + dialect.Postgres: "decimal(3,2)", + }), + 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 PlayerServices. +func (PlayerServices) Edges() []ent.Edge { + return nil +} diff --git a/app/player/rpc/internal/models/tx.go b/app/player/rpc/internal/models/tx.go new file mode 100644 index 0000000..01184ae --- /dev/null +++ b/app/player/rpc/internal/models/tx.go @@ -0,0 +1,213 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "sync" + + "entgo.io/ent/dialect" +) + +// Tx is a transactional client that is created by calling Client.Tx(). +type Tx struct { + config + // PlayerServices is the client for interacting with the PlayerServices builders. + PlayerServices *PlayerServicesClient + // Players is the client for interacting with the Players builders. + Players *PlayersClient + + // lazily loaded. + client *Client + clientOnce sync.Once + // ctx lives for the life of the transaction. It is + // the same context used by the underlying connection. + ctx context.Context +} + +type ( + // Committer is the interface that wraps the Commit method. + Committer interface { + Commit(context.Context, *Tx) error + } + + // The CommitFunc type is an adapter to allow the use of ordinary + // function as a Committer. If f is a function with the appropriate + // signature, CommitFunc(f) is a Committer that calls f. + CommitFunc func(context.Context, *Tx) error + + // CommitHook defines the "commit middleware". A function that gets a Committer + // and returns a Committer. For example: + // + // hook := func(next ent.Committer) ent.Committer { + // return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error { + // // Do some stuff before. + // if err := next.Commit(ctx, tx); err != nil { + // return err + // } + // // Do some stuff after. + // return nil + // }) + // } + // + CommitHook func(Committer) Committer +) + +// Commit calls f(ctx, m). +func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error { + return f(ctx, tx) +} + +// Commit commits the transaction. +func (tx *Tx) Commit() error { + txDriver := tx.config.driver.(*txDriver) + var fn Committer = CommitFunc(func(context.Context, *Tx) error { + return txDriver.tx.Commit() + }) + txDriver.mu.Lock() + hooks := append([]CommitHook(nil), txDriver.onCommit...) + txDriver.mu.Unlock() + for i := len(hooks) - 1; i >= 0; i-- { + fn = hooks[i](fn) + } + return fn.Commit(tx.ctx, tx) +} + +// OnCommit adds a hook to call on commit. +func (tx *Tx) OnCommit(f CommitHook) { + txDriver := tx.config.driver.(*txDriver) + txDriver.mu.Lock() + txDriver.onCommit = append(txDriver.onCommit, f) + txDriver.mu.Unlock() +} + +type ( + // Rollbacker is the interface that wraps the Rollback method. + Rollbacker interface { + Rollback(context.Context, *Tx) error + } + + // The RollbackFunc type is an adapter to allow the use of ordinary + // function as a Rollbacker. If f is a function with the appropriate + // signature, RollbackFunc(f) is a Rollbacker that calls f. + RollbackFunc func(context.Context, *Tx) error + + // RollbackHook defines the "rollback middleware". A function that gets a Rollbacker + // and returns a Rollbacker. For example: + // + // hook := func(next ent.Rollbacker) ent.Rollbacker { + // return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error { + // // Do some stuff before. + // if err := next.Rollback(ctx, tx); err != nil { + // return err + // } + // // Do some stuff after. + // return nil + // }) + // } + // + RollbackHook func(Rollbacker) Rollbacker +) + +// Rollback calls f(ctx, m). +func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error { + return f(ctx, tx) +} + +// Rollback rollbacks the transaction. +func (tx *Tx) Rollback() error { + txDriver := tx.config.driver.(*txDriver) + var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error { + return txDriver.tx.Rollback() + }) + txDriver.mu.Lock() + hooks := append([]RollbackHook(nil), txDriver.onRollback...) + txDriver.mu.Unlock() + for i := len(hooks) - 1; i >= 0; i-- { + fn = hooks[i](fn) + } + return fn.Rollback(tx.ctx, tx) +} + +// OnRollback adds a hook to call on rollback. +func (tx *Tx) OnRollback(f RollbackHook) { + txDriver := tx.config.driver.(*txDriver) + txDriver.mu.Lock() + txDriver.onRollback = append(txDriver.onRollback, f) + txDriver.mu.Unlock() +} + +// Client returns a Client that binds to current transaction. +func (tx *Tx) Client() *Client { + tx.clientOnce.Do(func() { + tx.client = &Client{config: tx.config} + tx.client.init() + }) + return tx.client +} + +func (tx *Tx) init() { + tx.PlayerServices = NewPlayerServicesClient(tx.config) + tx.Players = NewPlayersClient(tx.config) +} + +// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation. +// The idea is to support transactions without adding any extra code to the builders. +// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance. +// Commit and Rollback are nop for the internal builders and the user must call one +// of them in order to commit or rollback the transaction. +// +// If a closed transaction is embedded in one of the generated entities, and the entity +// applies a query, for example: PlayerServices.QueryXXX(), the query will be executed +// through the driver which created this transaction. +// +// Note that txDriver is not goroutine safe. +type txDriver struct { + // the driver we started the transaction from. + drv dialect.Driver + // tx is the underlying transaction. + tx dialect.Tx + // completion hooks. + mu sync.Mutex + onCommit []CommitHook + onRollback []RollbackHook +} + +// newTx creates a new transactional driver. +func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) { + tx, err := drv.Tx(ctx) + if err != nil { + return nil, err + } + return &txDriver{tx: tx, drv: drv}, nil +} + +// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls +// from the internal builders. Should be called only by the internal builders. +func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil } + +// Dialect returns the dialect of the driver we started the transaction from. +func (tx *txDriver) Dialect() string { return tx.drv.Dialect() } + +// Close is a nop close. +func (*txDriver) Close() error { return nil } + +// Commit is a nop commit for the internal builders. +// User must call `Tx.Commit` in order to commit the transaction. +func (*txDriver) Commit() error { return nil } + +// Rollback is a nop rollback for the internal builders. +// User must call `Tx.Rollback` in order to rollback the transaction. +func (*txDriver) Rollback() error { return nil } + +// Exec calls tx.Exec. +func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error { + return tx.tx.Exec(ctx, query, args, v) +} + +// Query calls tx.Query. +func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error { + return tx.tx.Query(ctx, query, args, v) +} + +var _ dialect.Driver = (*txDriver)(nil) diff --git a/app/player/rpc/internal/server/playerServiceServer.go b/app/player/rpc/internal/server/playerServiceServer.go new file mode 100644 index 0000000..e15bf5e --- /dev/null +++ b/app/player/rpc/internal/server/playerServiceServer.go @@ -0,0 +1,76 @@ +// Code generated by goctl. DO NOT EDIT. +// goctl 1.9.2 +// Source: player.proto + +package server + +import ( + "context" + + "juwan-backend/app/player/rpc/internal/logic" + "juwan-backend/app/player/rpc/internal/svc" + "juwan-backend/app/player/rpc/pb" +) + +type PlayerServiceServer struct { + svcCtx *svc.ServiceContext + pb.UnimplementedPlayerServiceServer +} + +func NewPlayerServiceServer(svcCtx *svc.ServiceContext) *PlayerServiceServer { + return &PlayerServiceServer{ + svcCtx: svcCtx, + } +} + +// -----------------------playerServices----------------------- +func (s *PlayerServiceServer) AddPlayerServices(ctx context.Context, in *pb.AddPlayerServicesReq) (*pb.AddPlayerServicesResp, error) { + l := logic.NewAddPlayerServicesLogic(ctx, s.svcCtx) + return l.AddPlayerServices(in) +} + +func (s *PlayerServiceServer) UpdatePlayerServices(ctx context.Context, in *pb.UpdatePlayerServicesReq) (*pb.UpdatePlayerServicesResp, error) { + l := logic.NewUpdatePlayerServicesLogic(ctx, s.svcCtx) + return l.UpdatePlayerServices(in) +} + +func (s *PlayerServiceServer) DelPlayerServices(ctx context.Context, in *pb.DelPlayerServicesReq) (*pb.DelPlayerServicesResp, error) { + l := logic.NewDelPlayerServicesLogic(ctx, s.svcCtx) + return l.DelPlayerServices(in) +} + +func (s *PlayerServiceServer) GetPlayerServicesById(ctx context.Context, in *pb.GetPlayerServicesByIdReq) (*pb.GetPlayerServicesByIdResp, error) { + l := logic.NewGetPlayerServicesByIdLogic(ctx, s.svcCtx) + return l.GetPlayerServicesById(in) +} + +func (s *PlayerServiceServer) SearchPlayerServices(ctx context.Context, in *pb.SearchPlayerServicesReq) (*pb.SearchPlayerServicesResp, error) { + l := logic.NewSearchPlayerServicesLogic(ctx, s.svcCtx) + return l.SearchPlayerServices(in) +} + +// -----------------------players----------------------- +func (s *PlayerServiceServer) AddPlayers(ctx context.Context, in *pb.AddPlayersReq) (*pb.AddPlayersResp, error) { + l := logic.NewAddPlayersLogic(ctx, s.svcCtx) + return l.AddPlayers(in) +} + +func (s *PlayerServiceServer) UpdatePlayers(ctx context.Context, in *pb.UpdatePlayersReq) (*pb.UpdatePlayersResp, error) { + l := logic.NewUpdatePlayersLogic(ctx, s.svcCtx) + return l.UpdatePlayers(in) +} + +func (s *PlayerServiceServer) DelPlayers(ctx context.Context, in *pb.DelPlayersReq) (*pb.DelPlayersResp, error) { + l := logic.NewDelPlayersLogic(ctx, s.svcCtx) + return l.DelPlayers(in) +} + +func (s *PlayerServiceServer) GetPlayersById(ctx context.Context, in *pb.GetPlayersByIdReq) (*pb.GetPlayersByIdResp, error) { + l := logic.NewGetPlayersByIdLogic(ctx, s.svcCtx) + return l.GetPlayersById(in) +} + +func (s *PlayerServiceServer) SearchPlayers(ctx context.Context, in *pb.SearchPlayersReq) (*pb.SearchPlayersResp, error) { + l := logic.NewSearchPlayersLogic(ctx, s.svcCtx) + return l.SearchPlayers(in) +} diff --git a/app/player/rpc/internal/svc/serviceContext.go b/app/player/rpc/internal/svc/serviceContext.go new file mode 100644 index 0000000..97e9d66 --- /dev/null +++ b/app/player/rpc/internal/svc/serviceContext.go @@ -0,0 +1,49 @@ +package svc + +import ( + "juwan-backend/app/player/rpc/internal/config" + "juwan-backend/app/player/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 + PlayerModelRW *models.Client + PlayerModelRO *models.Client + Snowflake snowflake.SnowflakeServiceClient +} + +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) + } + // snowflakex.NewClient(c.SnowflakeRpcConf) + + 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, + PlayerModelRW: models.NewClient(models.Driver(RWDrv)), + PlayerModelRO: models.NewClient(models.Driver(RODrv)), + Snowflake: snowflakex.NewClient(c.SnowflakeRpcConf), + } +} diff --git a/app/player/rpc/pb.go b/app/player/rpc/pb.go new file mode 100644 index 0000000..6d25455 --- /dev/null +++ b/app/player/rpc/pb.go @@ -0,0 +1,39 @@ +package main + +import ( + "flag" + "fmt" + + "juwan-backend/app/player/rpc/internal/config" + "juwan-backend/app/player/rpc/internal/server" + "juwan-backend/app/player/rpc/internal/svc" + "juwan-backend/app/player/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.RegisterPlayerServiceServer(grpcServer, server.NewPlayerServiceServer(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() +} diff --git a/app/player/rpc/pb/player.pb.go b/app/player/rpc/pb/player.pb.go new file mode 100644 index 0000000..d14dd93 --- /dev/null +++ b/app/player/rpc/pb/player.pb.go @@ -0,0 +1,1976 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.11 +// protoc v5.29.6 +// source: player.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) +) + +// --------------------------------playerServices-------------------------------- +type PlayerServices struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id + PlayerId int64 `protobuf:"varint,2,opt,name=playerId,proto3" json:"playerId,omitempty"` //playerId + GameId int64 `protobuf:"varint,3,opt,name=gameId,proto3" json:"gameId,omitempty"` //gameId + Title string `protobuf:"bytes,4,opt,name=title,proto3" json:"title,omitempty"` //title + Description string `protobuf:"bytes,5,opt,name=description,proto3" json:"description,omitempty"` //description + Price float64 `protobuf:"fixed64,6,opt,name=price,proto3" json:"price,omitempty"` //price + Unit string `protobuf:"bytes,7,opt,name=unit,proto3" json:"unit,omitempty"` //unit + RankRange string `protobuf:"bytes,8,opt,name=rankRange,proto3" json:"rankRange,omitempty"` //rankRange + Availability []string `protobuf:"bytes,9,rep,name=availability,proto3" json:"availability,omitempty"` //availability + Rating float64 `protobuf:"fixed64,10,opt,name=rating,proto3" json:"rating,omitempty"` //rating + IsActive bool `protobuf:"varint,11,opt,name=isActive,proto3" json:"isActive,omitempty"` //isActive + CreatedAt int64 `protobuf:"varint,12,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt + UpdatedAt int64 `protobuf:"varint,13,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *PlayerServices) Reset() { + *x = PlayerServices{} + mi := &file_player_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *PlayerServices) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PlayerServices) ProtoMessage() {} + +func (x *PlayerServices) ProtoReflect() protoreflect.Message { + mi := &file_player_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 PlayerServices.ProtoReflect.Descriptor instead. +func (*PlayerServices) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{0} +} + +func (x *PlayerServices) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *PlayerServices) GetPlayerId() int64 { + if x != nil { + return x.PlayerId + } + return 0 +} + +func (x *PlayerServices) GetGameId() int64 { + if x != nil { + return x.GameId + } + return 0 +} + +func (x *PlayerServices) GetTitle() string { + if x != nil { + return x.Title + } + return "" +} + +func (x *PlayerServices) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +func (x *PlayerServices) GetPrice() float64 { + if x != nil { + return x.Price + } + return 0 +} + +func (x *PlayerServices) GetUnit() string { + if x != nil { + return x.Unit + } + return "" +} + +func (x *PlayerServices) GetRankRange() string { + if x != nil { + return x.RankRange + } + return "" +} + +func (x *PlayerServices) GetAvailability() []string { + if x != nil { + return x.Availability + } + return nil +} + +func (x *PlayerServices) GetRating() float64 { + if x != nil { + return x.Rating + } + return 0 +} + +func (x *PlayerServices) GetIsActive() bool { + if x != nil { + return x.IsActive + } + return false +} + +func (x *PlayerServices) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *PlayerServices) GetUpdatedAt() int64 { + if x != nil { + return x.UpdatedAt + } + return 0 +} + +type AddPlayerServicesReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + PlayerId int64 `protobuf:"varint,1,opt,name=playerId,proto3" json:"playerId,omitempty"` //playerId + GameId int64 `protobuf:"varint,2,opt,name=gameId,proto3" json:"gameId,omitempty"` //gameId + Title string `protobuf:"bytes,3,opt,name=title,proto3" json:"title,omitempty"` //title + Description string `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty"` //description + Price float64 `protobuf:"fixed64,5,opt,name=price,proto3" json:"price,omitempty"` //price + Unit string `protobuf:"bytes,6,opt,name=unit,proto3" json:"unit,omitempty"` //unit + RankRange string `protobuf:"bytes,7,opt,name=rankRange,proto3" json:"rankRange,omitempty"` //rankRange + Availability []string `protobuf:"bytes,8,rep,name=availability,proto3" json:"availability,omitempty"` //availability + Rating float64 `protobuf:"fixed64,9,opt,name=rating,proto3" json:"rating,omitempty"` //rating + IsActive bool `protobuf:"varint,10,opt,name=isActive,proto3" json:"isActive,omitempty"` //isActive + CreatedAt int64 `protobuf:"varint,11,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt + UpdatedAt int64 `protobuf:"varint,12,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AddPlayerServicesReq) Reset() { + *x = AddPlayerServicesReq{} + mi := &file_player_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AddPlayerServicesReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AddPlayerServicesReq) ProtoMessage() {} + +func (x *AddPlayerServicesReq) ProtoReflect() protoreflect.Message { + mi := &file_player_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 AddPlayerServicesReq.ProtoReflect.Descriptor instead. +func (*AddPlayerServicesReq) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{1} +} + +func (x *AddPlayerServicesReq) GetPlayerId() int64 { + if x != nil { + return x.PlayerId + } + return 0 +} + +func (x *AddPlayerServicesReq) GetGameId() int64 { + if x != nil { + return x.GameId + } + return 0 +} + +func (x *AddPlayerServicesReq) GetTitle() string { + if x != nil { + return x.Title + } + return "" +} + +func (x *AddPlayerServicesReq) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +func (x *AddPlayerServicesReq) GetPrice() float64 { + if x != nil { + return x.Price + } + return 0 +} + +func (x *AddPlayerServicesReq) GetUnit() string { + if x != nil { + return x.Unit + } + return "" +} + +func (x *AddPlayerServicesReq) GetRankRange() string { + if x != nil { + return x.RankRange + } + return "" +} + +func (x *AddPlayerServicesReq) GetAvailability() []string { + if x != nil { + return x.Availability + } + return nil +} + +func (x *AddPlayerServicesReq) GetRating() float64 { + if x != nil { + return x.Rating + } + return 0 +} + +func (x *AddPlayerServicesReq) GetIsActive() bool { + if x != nil { + return x.IsActive + } + return false +} + +func (x *AddPlayerServicesReq) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *AddPlayerServicesReq) GetUpdatedAt() int64 { + if x != nil { + return x.UpdatedAt + } + return 0 +} + +type AddPlayerServicesResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AddPlayerServicesResp) Reset() { + *x = AddPlayerServicesResp{} + mi := &file_player_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AddPlayerServicesResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AddPlayerServicesResp) ProtoMessage() {} + +func (x *AddPlayerServicesResp) ProtoReflect() protoreflect.Message { + mi := &file_player_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 AddPlayerServicesResp.ProtoReflect.Descriptor instead. +func (*AddPlayerServicesResp) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{2} +} + +type UpdatePlayerServicesReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id + PlayerId *int64 `protobuf:"varint,2,opt,name=playerId,proto3,oneof" json:"playerId,omitempty"` //playerId + GameId *int64 `protobuf:"varint,3,opt,name=gameId,proto3,oneof" json:"gameId,omitempty"` //gameId + Title *string `protobuf:"bytes,4,opt,name=title,proto3,oneof" json:"title,omitempty"` //title + Description *string `protobuf:"bytes,5,opt,name=description,proto3,oneof" json:"description,omitempty"` //description + Price *float64 `protobuf:"fixed64,6,opt,name=price,proto3,oneof" json:"price,omitempty"` //price + Unit *string `protobuf:"bytes,7,opt,name=unit,proto3,oneof" json:"unit,omitempty"` //unit + RankRange *string `protobuf:"bytes,8,opt,name=rankRange,proto3,oneof" json:"rankRange,omitempty"` //rankRange + Availability []string `protobuf:"bytes,9,rep,name=availability,proto3" json:"availability,omitempty"` //availability + Rating *float64 `protobuf:"fixed64,10,opt,name=rating,proto3,oneof" json:"rating,omitempty"` //rating + IsActive *bool `protobuf:"varint,11,opt,name=isActive,proto3,oneof" json:"isActive,omitempty"` //isActive + CreatedAt *int64 `protobuf:"varint,12,opt,name=createdAt,proto3,oneof" json:"createdAt,omitempty"` //createdAt + UpdatedAt *int64 `protobuf:"varint,13,opt,name=updatedAt,proto3,oneof" json:"updatedAt,omitempty"` //updatedAt + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *UpdatePlayerServicesReq) Reset() { + *x = UpdatePlayerServicesReq{} + mi := &file_player_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UpdatePlayerServicesReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdatePlayerServicesReq) ProtoMessage() {} + +func (x *UpdatePlayerServicesReq) ProtoReflect() protoreflect.Message { + mi := &file_player_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 UpdatePlayerServicesReq.ProtoReflect.Descriptor instead. +func (*UpdatePlayerServicesReq) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{3} +} + +func (x *UpdatePlayerServicesReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *UpdatePlayerServicesReq) GetPlayerId() int64 { + if x != nil && x.PlayerId != nil { + return *x.PlayerId + } + return 0 +} + +func (x *UpdatePlayerServicesReq) GetGameId() int64 { + if x != nil && x.GameId != nil { + return *x.GameId + } + return 0 +} + +func (x *UpdatePlayerServicesReq) GetTitle() string { + if x != nil && x.Title != nil { + return *x.Title + } + return "" +} + +func (x *UpdatePlayerServicesReq) GetDescription() string { + if x != nil && x.Description != nil { + return *x.Description + } + return "" +} + +func (x *UpdatePlayerServicesReq) GetPrice() float64 { + if x != nil && x.Price != nil { + return *x.Price + } + return 0 +} + +func (x *UpdatePlayerServicesReq) GetUnit() string { + if x != nil && x.Unit != nil { + return *x.Unit + } + return "" +} + +func (x *UpdatePlayerServicesReq) GetRankRange() string { + if x != nil && x.RankRange != nil { + return *x.RankRange + } + return "" +} + +func (x *UpdatePlayerServicesReq) GetAvailability() []string { + if x != nil { + return x.Availability + } + return nil +} + +func (x *UpdatePlayerServicesReq) GetRating() float64 { + if x != nil && x.Rating != nil { + return *x.Rating + } + return 0 +} + +func (x *UpdatePlayerServicesReq) GetIsActive() bool { + if x != nil && x.IsActive != nil { + return *x.IsActive + } + return false +} + +func (x *UpdatePlayerServicesReq) GetCreatedAt() int64 { + if x != nil && x.CreatedAt != nil { + return *x.CreatedAt + } + return 0 +} + +func (x *UpdatePlayerServicesReq) GetUpdatedAt() int64 { + if x != nil && x.UpdatedAt != nil { + return *x.UpdatedAt + } + return 0 +} + +type UpdatePlayerServicesResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *UpdatePlayerServicesResp) Reset() { + *x = UpdatePlayerServicesResp{} + mi := &file_player_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UpdatePlayerServicesResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdatePlayerServicesResp) ProtoMessage() {} + +func (x *UpdatePlayerServicesResp) ProtoReflect() protoreflect.Message { + mi := &file_player_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 UpdatePlayerServicesResp.ProtoReflect.Descriptor instead. +func (*UpdatePlayerServicesResp) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{4} +} + +type DelPlayerServicesReq 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 *DelPlayerServicesReq) Reset() { + *x = DelPlayerServicesReq{} + mi := &file_player_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DelPlayerServicesReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DelPlayerServicesReq) ProtoMessage() {} + +func (x *DelPlayerServicesReq) ProtoReflect() protoreflect.Message { + mi := &file_player_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 DelPlayerServicesReq.ProtoReflect.Descriptor instead. +func (*DelPlayerServicesReq) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{5} +} + +func (x *DelPlayerServicesReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type DelPlayerServicesResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *DelPlayerServicesResp) Reset() { + *x = DelPlayerServicesResp{} + mi := &file_player_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DelPlayerServicesResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DelPlayerServicesResp) ProtoMessage() {} + +func (x *DelPlayerServicesResp) ProtoReflect() protoreflect.Message { + mi := &file_player_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 DelPlayerServicesResp.ProtoReflect.Descriptor instead. +func (*DelPlayerServicesResp) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{6} +} + +type GetPlayerServicesByIdReq 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 *GetPlayerServicesByIdReq) Reset() { + *x = GetPlayerServicesByIdReq{} + mi := &file_player_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetPlayerServicesByIdReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetPlayerServicesByIdReq) ProtoMessage() {} + +func (x *GetPlayerServicesByIdReq) ProtoReflect() protoreflect.Message { + mi := &file_player_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 GetPlayerServicesByIdReq.ProtoReflect.Descriptor instead. +func (*GetPlayerServicesByIdReq) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{7} +} + +func (x *GetPlayerServicesByIdReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type GetPlayerServicesByIdResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + PlayerServices *PlayerServices `protobuf:"bytes,1,opt,name=playerServices,proto3" json:"playerServices,omitempty"` //playerServices + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *GetPlayerServicesByIdResp) Reset() { + *x = GetPlayerServicesByIdResp{} + mi := &file_player_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetPlayerServicesByIdResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetPlayerServicesByIdResp) ProtoMessage() {} + +func (x *GetPlayerServicesByIdResp) ProtoReflect() protoreflect.Message { + mi := &file_player_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 GetPlayerServicesByIdResp.ProtoReflect.Descriptor instead. +func (*GetPlayerServicesByIdResp) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{8} +} + +func (x *GetPlayerServicesByIdResp) GetPlayerServices() *PlayerServices { + if x != nil { + return x.PlayerServices + } + return nil +} + +type SearchPlayerServicesReq 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 + PlayerId int64 `protobuf:"varint,4,opt,name=playerId,proto3" json:"playerId,omitempty"` //playerId + GameId int64 `protobuf:"varint,5,opt,name=gameId,proto3" json:"gameId,omitempty"` //gameId + Title string `protobuf:"bytes,6,opt,name=title,proto3" json:"title,omitempty"` //title + Description string `protobuf:"bytes,7,opt,name=description,proto3" json:"description,omitempty"` //description + Price float64 `protobuf:"fixed64,8,opt,name=price,proto3" json:"price,omitempty"` //price + Unit string `protobuf:"bytes,9,opt,name=unit,proto3" json:"unit,omitempty"` //unit + RankRange string `protobuf:"bytes,10,opt,name=rankRange,proto3" json:"rankRange,omitempty"` //rankRange + Availability []string `protobuf:"bytes,11,rep,name=availability,proto3" json:"availability,omitempty"` //availability + Rating float64 `protobuf:"fixed64,12,opt,name=rating,proto3" json:"rating,omitempty"` //rating + IsActive bool `protobuf:"varint,13,opt,name=isActive,proto3" json:"isActive,omitempty"` //isActive + CreatedAt int64 `protobuf:"varint,14,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt + UpdatedAt int64 `protobuf:"varint,15,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SearchPlayerServicesReq) Reset() { + *x = SearchPlayerServicesReq{} + mi := &file_player_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SearchPlayerServicesReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SearchPlayerServicesReq) ProtoMessage() {} + +func (x *SearchPlayerServicesReq) ProtoReflect() protoreflect.Message { + mi := &file_player_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 SearchPlayerServicesReq.ProtoReflect.Descriptor instead. +func (*SearchPlayerServicesReq) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{9} +} + +func (x *SearchPlayerServicesReq) GetPage() int64 { + if x != nil { + return x.Page + } + return 0 +} + +func (x *SearchPlayerServicesReq) GetLimit() int64 { + if x != nil { + return x.Limit + } + return 0 +} + +func (x *SearchPlayerServicesReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *SearchPlayerServicesReq) GetPlayerId() int64 { + if x != nil { + return x.PlayerId + } + return 0 +} + +func (x *SearchPlayerServicesReq) GetGameId() int64 { + if x != nil { + return x.GameId + } + return 0 +} + +func (x *SearchPlayerServicesReq) GetTitle() string { + if x != nil { + return x.Title + } + return "" +} + +func (x *SearchPlayerServicesReq) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +func (x *SearchPlayerServicesReq) GetPrice() float64 { + if x != nil { + return x.Price + } + return 0 +} + +func (x *SearchPlayerServicesReq) GetUnit() string { + if x != nil { + return x.Unit + } + return "" +} + +func (x *SearchPlayerServicesReq) GetRankRange() string { + if x != nil { + return x.RankRange + } + return "" +} + +func (x *SearchPlayerServicesReq) GetAvailability() []string { + if x != nil { + return x.Availability + } + return nil +} + +func (x *SearchPlayerServicesReq) GetRating() float64 { + if x != nil { + return x.Rating + } + return 0 +} + +func (x *SearchPlayerServicesReq) GetIsActive() bool { + if x != nil { + return x.IsActive + } + return false +} + +func (x *SearchPlayerServicesReq) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *SearchPlayerServicesReq) GetUpdatedAt() int64 { + if x != nil { + return x.UpdatedAt + } + return 0 +} + +type SearchPlayerServicesResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + PlayerServices []*PlayerServices `protobuf:"bytes,1,rep,name=playerServices,proto3" json:"playerServices,omitempty"` //playerServices + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SearchPlayerServicesResp) Reset() { + *x = SearchPlayerServicesResp{} + mi := &file_player_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SearchPlayerServicesResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SearchPlayerServicesResp) ProtoMessage() {} + +func (x *SearchPlayerServicesResp) ProtoReflect() protoreflect.Message { + mi := &file_player_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 SearchPlayerServicesResp.ProtoReflect.Descriptor instead. +func (*SearchPlayerServicesResp) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{10} +} + +func (x *SearchPlayerServicesResp) GetPlayerServices() []*PlayerServices { + if x != nil { + return x.PlayerServices + } + return nil +} + +// --------------------------------players-------------------------------- +type Players struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id + UserId int64 `protobuf:"varint,2,opt,name=userId,proto3" json:"userId,omitempty"` //userId + Status string `protobuf:"bytes,3,opt,name=status,proto3" json:"status,omitempty"` //status + Rating float64 `protobuf:"fixed64,4,opt,name=rating,proto3" json:"rating,omitempty"` //rating + TotalOrders int64 `protobuf:"varint,5,opt,name=totalOrders,proto3" json:"totalOrders,omitempty"` //totalOrders + CompletedOrders int64 `protobuf:"varint,6,opt,name=completedOrders,proto3" json:"completedOrders,omitempty"` //completedOrders + ShopId int64 `protobuf:"varint,7,opt,name=shopId,proto3" json:"shopId,omitempty"` //shopId + Tags []string `protobuf:"bytes,8,rep,name=tags,proto3" json:"tags,omitempty"` //tags + Games []int64 `protobuf:"varint,9,rep,packed,name=games,proto3" json:"games,omitempty"` //games + CreatedAt int64 `protobuf:"varint,10,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt + UpdatedAt int64 `protobuf:"varint,11,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt + Gender int64 `protobuf:"varint,12,opt,name=gender,proto3" json:"gender,omitempty"` //gender + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Players) Reset() { + *x = Players{} + mi := &file_player_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Players) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Players) ProtoMessage() {} + +func (x *Players) ProtoReflect() protoreflect.Message { + mi := &file_player_proto_msgTypes[11] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Players.ProtoReflect.Descriptor instead. +func (*Players) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{11} +} + +func (x *Players) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *Players) GetUserId() int64 { + if x != nil { + return x.UserId + } + return 0 +} + +func (x *Players) GetStatus() string { + if x != nil { + return x.Status + } + return "" +} + +func (x *Players) GetRating() float64 { + if x != nil { + return x.Rating + } + return 0 +} + +func (x *Players) GetTotalOrders() int64 { + if x != nil { + return x.TotalOrders + } + return 0 +} + +func (x *Players) GetCompletedOrders() int64 { + if x != nil { + return x.CompletedOrders + } + return 0 +} + +func (x *Players) GetShopId() int64 { + if x != nil { + return x.ShopId + } + return 0 +} + +func (x *Players) GetTags() []string { + if x != nil { + return x.Tags + } + return nil +} + +func (x *Players) GetGames() []int64 { + if x != nil { + return x.Games + } + return nil +} + +func (x *Players) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *Players) GetUpdatedAt() int64 { + if x != nil { + return x.UpdatedAt + } + return 0 +} + +func (x *Players) GetGender() int64 { + if x != nil { + return x.Gender + } + return 0 +} + +type AddPlayersReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + UserId int64 `protobuf:"varint,1,opt,name=userId,proto3" json:"userId,omitempty"` //userId + Status string `protobuf:"bytes,2,opt,name=status,proto3" json:"status,omitempty"` //status + Rating float64 `protobuf:"fixed64,3,opt,name=rating,proto3" json:"rating,omitempty"` //rating + TotalOrders int64 `protobuf:"varint,4,opt,name=totalOrders,proto3" json:"totalOrders,omitempty"` //totalOrders + CompletedOrders int64 `protobuf:"varint,5,opt,name=completedOrders,proto3" json:"completedOrders,omitempty"` //completedOrders + ShopId int64 `protobuf:"varint,6,opt,name=shopId,proto3" json:"shopId,omitempty"` //shopId + Tags []string `protobuf:"bytes,7,rep,name=tags,proto3" json:"tags,omitempty"` //tags + Games []int64 `protobuf:"varint,8,rep,packed,name=games,proto3" json:"games,omitempty"` //games + 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 + Gender int64 `protobuf:"varint,11,opt,name=gender,proto3" json:"gender,omitempty"` //gender + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AddPlayersReq) Reset() { + *x = AddPlayersReq{} + mi := &file_player_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AddPlayersReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AddPlayersReq) ProtoMessage() {} + +func (x *AddPlayersReq) ProtoReflect() protoreflect.Message { + mi := &file_player_proto_msgTypes[12] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AddPlayersReq.ProtoReflect.Descriptor instead. +func (*AddPlayersReq) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{12} +} + +func (x *AddPlayersReq) GetUserId() int64 { + if x != nil { + return x.UserId + } + return 0 +} + +func (x *AddPlayersReq) GetStatus() string { + if x != nil { + return x.Status + } + return "" +} + +func (x *AddPlayersReq) GetRating() float64 { + if x != nil { + return x.Rating + } + return 0 +} + +func (x *AddPlayersReq) GetTotalOrders() int64 { + if x != nil { + return x.TotalOrders + } + return 0 +} + +func (x *AddPlayersReq) GetCompletedOrders() int64 { + if x != nil { + return x.CompletedOrders + } + return 0 +} + +func (x *AddPlayersReq) GetShopId() int64 { + if x != nil { + return x.ShopId + } + return 0 +} + +func (x *AddPlayersReq) GetTags() []string { + if x != nil { + return x.Tags + } + return nil +} + +func (x *AddPlayersReq) GetGames() []int64 { + if x != nil { + return x.Games + } + return nil +} + +func (x *AddPlayersReq) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *AddPlayersReq) GetUpdatedAt() int64 { + if x != nil { + return x.UpdatedAt + } + return 0 +} + +func (x *AddPlayersReq) GetGender() int64 { + if x != nil { + return x.Gender + } + return 0 +} + +type AddPlayersResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AddPlayersResp) Reset() { + *x = AddPlayersResp{} + mi := &file_player_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AddPlayersResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AddPlayersResp) ProtoMessage() {} + +func (x *AddPlayersResp) ProtoReflect() protoreflect.Message { + mi := &file_player_proto_msgTypes[13] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AddPlayersResp.ProtoReflect.Descriptor instead. +func (*AddPlayersResp) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{13} +} + +type UpdatePlayersReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id + UserId *int64 `protobuf:"varint,2,opt,name=userId,proto3,oneof" json:"userId,omitempty"` //userId + Status *string `protobuf:"bytes,3,opt,name=status,proto3,oneof" json:"status,omitempty"` //status + Rating *float64 `protobuf:"fixed64,4,opt,name=rating,proto3,oneof" json:"rating,omitempty"` //rating + TotalOrders *int64 `protobuf:"varint,5,opt,name=totalOrders,proto3,oneof" json:"totalOrders,omitempty"` //totalOrders + CompletedOrders *int64 `protobuf:"varint,6,opt,name=completedOrders,proto3,oneof" json:"completedOrders,omitempty"` //completedOrders + ShopId *int64 `protobuf:"varint,7,opt,name=shopId,proto3,oneof" json:"shopId,omitempty"` //shopId + Tags []string `protobuf:"bytes,8,rep,name=tags,proto3" json:"tags,omitempty"` //tags + Games []int64 `protobuf:"varint,9,rep,packed,name=games,proto3" json:"games,omitempty"` //games + CreatedAt *int64 `protobuf:"varint,10,opt,name=createdAt,proto3,oneof" json:"createdAt,omitempty"` //createdAt + UpdatedAt *int64 `protobuf:"varint,11,opt,name=updatedAt,proto3,oneof" json:"updatedAt,omitempty"` //updatedAt + Gender *int64 `protobuf:"varint,12,opt,name=gender,proto3,oneof" json:"gender,omitempty"` //gender + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *UpdatePlayersReq) Reset() { + *x = UpdatePlayersReq{} + mi := &file_player_proto_msgTypes[14] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UpdatePlayersReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdatePlayersReq) ProtoMessage() {} + +func (x *UpdatePlayersReq) ProtoReflect() protoreflect.Message { + mi := &file_player_proto_msgTypes[14] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdatePlayersReq.ProtoReflect.Descriptor instead. +func (*UpdatePlayersReq) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{14} +} + +func (x *UpdatePlayersReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *UpdatePlayersReq) GetUserId() int64 { + if x != nil && x.UserId != nil { + return *x.UserId + } + return 0 +} + +func (x *UpdatePlayersReq) GetStatus() string { + if x != nil && x.Status != nil { + return *x.Status + } + return "" +} + +func (x *UpdatePlayersReq) GetRating() float64 { + if x != nil && x.Rating != nil { + return *x.Rating + } + return 0 +} + +func (x *UpdatePlayersReq) GetTotalOrders() int64 { + if x != nil && x.TotalOrders != nil { + return *x.TotalOrders + } + return 0 +} + +func (x *UpdatePlayersReq) GetCompletedOrders() int64 { + if x != nil && x.CompletedOrders != nil { + return *x.CompletedOrders + } + return 0 +} + +func (x *UpdatePlayersReq) GetShopId() int64 { + if x != nil && x.ShopId != nil { + return *x.ShopId + } + return 0 +} + +func (x *UpdatePlayersReq) GetTags() []string { + if x != nil { + return x.Tags + } + return nil +} + +func (x *UpdatePlayersReq) GetGames() []int64 { + if x != nil { + return x.Games + } + return nil +} + +func (x *UpdatePlayersReq) GetCreatedAt() int64 { + if x != nil && x.CreatedAt != nil { + return *x.CreatedAt + } + return 0 +} + +func (x *UpdatePlayersReq) GetUpdatedAt() int64 { + if x != nil && x.UpdatedAt != nil { + return *x.UpdatedAt + } + return 0 +} + +func (x *UpdatePlayersReq) GetGender() int64 { + if x != nil && x.Gender != nil { + return *x.Gender + } + return 0 +} + +type UpdatePlayersResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *UpdatePlayersResp) Reset() { + *x = UpdatePlayersResp{} + mi := &file_player_proto_msgTypes[15] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UpdatePlayersResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdatePlayersResp) ProtoMessage() {} + +func (x *UpdatePlayersResp) ProtoReflect() protoreflect.Message { + mi := &file_player_proto_msgTypes[15] + 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 UpdatePlayersResp.ProtoReflect.Descriptor instead. +func (*UpdatePlayersResp) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{15} +} + +type DelPlayersReq 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 *DelPlayersReq) Reset() { + *x = DelPlayersReq{} + mi := &file_player_proto_msgTypes[16] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DelPlayersReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DelPlayersReq) ProtoMessage() {} + +func (x *DelPlayersReq) ProtoReflect() protoreflect.Message { + mi := &file_player_proto_msgTypes[16] + 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 DelPlayersReq.ProtoReflect.Descriptor instead. +func (*DelPlayersReq) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{16} +} + +func (x *DelPlayersReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type DelPlayersResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *DelPlayersResp) Reset() { + *x = DelPlayersResp{} + mi := &file_player_proto_msgTypes[17] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DelPlayersResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DelPlayersResp) ProtoMessage() {} + +func (x *DelPlayersResp) ProtoReflect() protoreflect.Message { + mi := &file_player_proto_msgTypes[17] + 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 DelPlayersResp.ProtoReflect.Descriptor instead. +func (*DelPlayersResp) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{17} +} + +type GetPlayersByIdReq 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 *GetPlayersByIdReq) Reset() { + *x = GetPlayersByIdReq{} + mi := &file_player_proto_msgTypes[18] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetPlayersByIdReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetPlayersByIdReq) ProtoMessage() {} + +func (x *GetPlayersByIdReq) ProtoReflect() protoreflect.Message { + mi := &file_player_proto_msgTypes[18] + 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 GetPlayersByIdReq.ProtoReflect.Descriptor instead. +func (*GetPlayersByIdReq) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{18} +} + +func (x *GetPlayersByIdReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type GetPlayersByIdResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + Players *Players `protobuf:"bytes,1,opt,name=players,proto3" json:"players,omitempty"` //players + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *GetPlayersByIdResp) Reset() { + *x = GetPlayersByIdResp{} + mi := &file_player_proto_msgTypes[19] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetPlayersByIdResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetPlayersByIdResp) ProtoMessage() {} + +func (x *GetPlayersByIdResp) ProtoReflect() protoreflect.Message { + mi := &file_player_proto_msgTypes[19] + 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 GetPlayersByIdResp.ProtoReflect.Descriptor instead. +func (*GetPlayersByIdResp) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{19} +} + +func (x *GetPlayersByIdResp) GetPlayers() *Players { + if x != nil { + return x.Players + } + return nil +} + +type SearchPlayersReq 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 + UserId int64 `protobuf:"varint,4,opt,name=userId,proto3" json:"userId,omitempty"` //userId + Status string `protobuf:"bytes,5,opt,name=status,proto3" json:"status,omitempty"` //status + Rating float64 `protobuf:"fixed64,6,opt,name=rating,proto3" json:"rating,omitempty"` //rating + TotalOrders int64 `protobuf:"varint,7,opt,name=totalOrders,proto3" json:"totalOrders,omitempty"` //totalOrders + CompletedOrders int64 `protobuf:"varint,8,opt,name=completedOrders,proto3" json:"completedOrders,omitempty"` //completedOrders + ShopId int64 `protobuf:"varint,9,opt,name=shopId,proto3" json:"shopId,omitempty"` //shopId + Tags []string `protobuf:"bytes,10,rep,name=tags,proto3" json:"tags,omitempty"` //tags + Games []int64 `protobuf:"varint,11,rep,packed,name=games,proto3" json:"games,omitempty"` //games + CreatedAt int64 `protobuf:"varint,12,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt + UpdatedAt int64 `protobuf:"varint,13,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt + Gender int64 `protobuf:"varint,14,opt,name=gender,proto3" json:"gender,omitempty"` //gender + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SearchPlayersReq) Reset() { + *x = SearchPlayersReq{} + mi := &file_player_proto_msgTypes[20] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SearchPlayersReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SearchPlayersReq) ProtoMessage() {} + +func (x *SearchPlayersReq) ProtoReflect() protoreflect.Message { + mi := &file_player_proto_msgTypes[20] + 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 SearchPlayersReq.ProtoReflect.Descriptor instead. +func (*SearchPlayersReq) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{20} +} + +func (x *SearchPlayersReq) GetPage() int64 { + if x != nil { + return x.Page + } + return 0 +} + +func (x *SearchPlayersReq) GetLimit() int64 { + if x != nil { + return x.Limit + } + return 0 +} + +func (x *SearchPlayersReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *SearchPlayersReq) GetUserId() int64 { + if x != nil { + return x.UserId + } + return 0 +} + +func (x *SearchPlayersReq) GetStatus() string { + if x != nil { + return x.Status + } + return "" +} + +func (x *SearchPlayersReq) GetRating() float64 { + if x != nil { + return x.Rating + } + return 0 +} + +func (x *SearchPlayersReq) GetTotalOrders() int64 { + if x != nil { + return x.TotalOrders + } + return 0 +} + +func (x *SearchPlayersReq) GetCompletedOrders() int64 { + if x != nil { + return x.CompletedOrders + } + return 0 +} + +func (x *SearchPlayersReq) GetShopId() int64 { + if x != nil { + return x.ShopId + } + return 0 +} + +func (x *SearchPlayersReq) GetTags() []string { + if x != nil { + return x.Tags + } + return nil +} + +func (x *SearchPlayersReq) GetGames() []int64 { + if x != nil { + return x.Games + } + return nil +} + +func (x *SearchPlayersReq) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *SearchPlayersReq) GetUpdatedAt() int64 { + if x != nil { + return x.UpdatedAt + } + return 0 +} + +func (x *SearchPlayersReq) GetGender() int64 { + if x != nil { + return x.Gender + } + return 0 +} + +type SearchPlayersResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + Players []*Players `protobuf:"bytes,1,rep,name=players,proto3" json:"players,omitempty"` //players + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SearchPlayersResp) Reset() { + *x = SearchPlayersResp{} + mi := &file_player_proto_msgTypes[21] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SearchPlayersResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SearchPlayersResp) ProtoMessage() {} + +func (x *SearchPlayersResp) ProtoReflect() protoreflect.Message { + mi := &file_player_proto_msgTypes[21] + 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 SearchPlayersResp.ProtoReflect.Descriptor instead. +func (*SearchPlayersResp) Descriptor() ([]byte, []int) { + return file_player_proto_rawDescGZIP(), []int{21} +} + +func (x *SearchPlayersResp) GetPlayers() []*Players { + if x != nil { + return x.Players + } + return nil +} + +var File_player_proto protoreflect.FileDescriptor + +const file_player_proto_rawDesc = "" + + "\n" + + "\fplayer.proto\x12\x02pb\"\xe8\x02\n" + + "\x0ePlayerServices\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x1a\n" + + "\bplayerId\x18\x02 \x01(\x03R\bplayerId\x12\x16\n" + + "\x06gameId\x18\x03 \x01(\x03R\x06gameId\x12\x14\n" + + "\x05title\x18\x04 \x01(\tR\x05title\x12 \n" + + "\vdescription\x18\x05 \x01(\tR\vdescription\x12\x14\n" + + "\x05price\x18\x06 \x01(\x01R\x05price\x12\x12\n" + + "\x04unit\x18\a \x01(\tR\x04unit\x12\x1c\n" + + "\trankRange\x18\b \x01(\tR\trankRange\x12\"\n" + + "\favailability\x18\t \x03(\tR\favailability\x12\x16\n" + + "\x06rating\x18\n" + + " \x01(\x01R\x06rating\x12\x1a\n" + + "\bisActive\x18\v \x01(\bR\bisActive\x12\x1c\n" + + "\tcreatedAt\x18\f \x01(\x03R\tcreatedAt\x12\x1c\n" + + "\tupdatedAt\x18\r \x01(\x03R\tupdatedAt\"\xde\x02\n" + + "\x14AddPlayerServicesReq\x12\x1a\n" + + "\bplayerId\x18\x01 \x01(\x03R\bplayerId\x12\x16\n" + + "\x06gameId\x18\x02 \x01(\x03R\x06gameId\x12\x14\n" + + "\x05title\x18\x03 \x01(\tR\x05title\x12 \n" + + "\vdescription\x18\x04 \x01(\tR\vdescription\x12\x14\n" + + "\x05price\x18\x05 \x01(\x01R\x05price\x12\x12\n" + + "\x04unit\x18\x06 \x01(\tR\x04unit\x12\x1c\n" + + "\trankRange\x18\a \x01(\tR\trankRange\x12\"\n" + + "\favailability\x18\b \x03(\tR\favailability\x12\x16\n" + + "\x06rating\x18\t \x01(\x01R\x06rating\x12\x1a\n" + + "\bisActive\x18\n" + + " \x01(\bR\bisActive\x12\x1c\n" + + "\tcreatedAt\x18\v \x01(\x03R\tcreatedAt\x12\x1c\n" + + "\tupdatedAt\x18\f \x01(\x03R\tupdatedAt\"\x17\n" + + "\x15AddPlayerServicesResp\"\xaf\x04\n" + + "\x17UpdatePlayerServicesReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x1f\n" + + "\bplayerId\x18\x02 \x01(\x03H\x00R\bplayerId\x88\x01\x01\x12\x1b\n" + + "\x06gameId\x18\x03 \x01(\x03H\x01R\x06gameId\x88\x01\x01\x12\x19\n" + + "\x05title\x18\x04 \x01(\tH\x02R\x05title\x88\x01\x01\x12%\n" + + "\vdescription\x18\x05 \x01(\tH\x03R\vdescription\x88\x01\x01\x12\x19\n" + + "\x05price\x18\x06 \x01(\x01H\x04R\x05price\x88\x01\x01\x12\x17\n" + + "\x04unit\x18\a \x01(\tH\x05R\x04unit\x88\x01\x01\x12!\n" + + "\trankRange\x18\b \x01(\tH\x06R\trankRange\x88\x01\x01\x12\"\n" + + "\favailability\x18\t \x03(\tR\favailability\x12\x1b\n" + + "\x06rating\x18\n" + + " \x01(\x01H\aR\x06rating\x88\x01\x01\x12\x1f\n" + + "\bisActive\x18\v \x01(\bH\bR\bisActive\x88\x01\x01\x12!\n" + + "\tcreatedAt\x18\f \x01(\x03H\tR\tcreatedAt\x88\x01\x01\x12!\n" + + "\tupdatedAt\x18\r \x01(\x03H\n" + + "R\tupdatedAt\x88\x01\x01B\v\n" + + "\t_playerIdB\t\n" + + "\a_gameIdB\b\n" + + "\x06_titleB\x0e\n" + + "\f_descriptionB\b\n" + + "\x06_priceB\a\n" + + "\x05_unitB\f\n" + + "\n" + + "_rankRangeB\t\n" + + "\a_ratingB\v\n" + + "\t_isActiveB\f\n" + + "\n" + + "_createdAtB\f\n" + + "\n" + + "_updatedAt\"\x1a\n" + + "\x18UpdatePlayerServicesResp\"&\n" + + "\x14DelPlayerServicesReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\"\x17\n" + + "\x15DelPlayerServicesResp\"*\n" + + "\x18GetPlayerServicesByIdReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\"W\n" + + "\x19GetPlayerServicesByIdResp\x12:\n" + + "\x0eplayerServices\x18\x01 \x01(\v2\x12.pb.PlayerServicesR\x0eplayerServices\"\x9b\x03\n" + + "\x17SearchPlayerServicesReq\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\x1a\n" + + "\bplayerId\x18\x04 \x01(\x03R\bplayerId\x12\x16\n" + + "\x06gameId\x18\x05 \x01(\x03R\x06gameId\x12\x14\n" + + "\x05title\x18\x06 \x01(\tR\x05title\x12 \n" + + "\vdescription\x18\a \x01(\tR\vdescription\x12\x14\n" + + "\x05price\x18\b \x01(\x01R\x05price\x12\x12\n" + + "\x04unit\x18\t \x01(\tR\x04unit\x12\x1c\n" + + "\trankRange\x18\n" + + " \x01(\tR\trankRange\x12\"\n" + + "\favailability\x18\v \x03(\tR\favailability\x12\x16\n" + + "\x06rating\x18\f \x01(\x01R\x06rating\x12\x1a\n" + + "\bisActive\x18\r \x01(\bR\bisActive\x12\x1c\n" + + "\tcreatedAt\x18\x0e \x01(\x03R\tcreatedAt\x12\x1c\n" + + "\tupdatedAt\x18\x0f \x01(\x03R\tupdatedAt\"V\n" + + "\x18SearchPlayerServicesResp\x12:\n" + + "\x0eplayerServices\x18\x01 \x03(\v2\x12.pb.PlayerServicesR\x0eplayerServices\"\xc3\x02\n" + + "\aPlayers\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x16\n" + + "\x06userId\x18\x02 \x01(\x03R\x06userId\x12\x16\n" + + "\x06status\x18\x03 \x01(\tR\x06status\x12\x16\n" + + "\x06rating\x18\x04 \x01(\x01R\x06rating\x12 \n" + + "\vtotalOrders\x18\x05 \x01(\x03R\vtotalOrders\x12(\n" + + "\x0fcompletedOrders\x18\x06 \x01(\x03R\x0fcompletedOrders\x12\x16\n" + + "\x06shopId\x18\a \x01(\x03R\x06shopId\x12\x12\n" + + "\x04tags\x18\b \x03(\tR\x04tags\x12\x14\n" + + "\x05games\x18\t \x03(\x03R\x05games\x12\x1c\n" + + "\tcreatedAt\x18\n" + + " \x01(\x03R\tcreatedAt\x12\x1c\n" + + "\tupdatedAt\x18\v \x01(\x03R\tupdatedAt\x12\x16\n" + + "\x06gender\x18\f \x01(\x03R\x06gender\"\xb9\x02\n" + + "\rAddPlayersReq\x12\x16\n" + + "\x06userId\x18\x01 \x01(\x03R\x06userId\x12\x16\n" + + "\x06status\x18\x02 \x01(\tR\x06status\x12\x16\n" + + "\x06rating\x18\x03 \x01(\x01R\x06rating\x12 \n" + + "\vtotalOrders\x18\x04 \x01(\x03R\vtotalOrders\x12(\n" + + "\x0fcompletedOrders\x18\x05 \x01(\x03R\x0fcompletedOrders\x12\x16\n" + + "\x06shopId\x18\x06 \x01(\x03R\x06shopId\x12\x12\n" + + "\x04tags\x18\a \x03(\tR\x04tags\x12\x14\n" + + "\x05games\x18\b \x03(\x03R\x05games\x12\x1c\n" + + "\tcreatedAt\x18\t \x01(\x03R\tcreatedAt\x12\x1c\n" + + "\tupdatedAt\x18\n" + + " \x01(\x03R\tupdatedAt\x12\x16\n" + + "\x06gender\x18\v \x01(\x03R\x06gender\"\x10\n" + + "\x0eAddPlayersResp\"\xf0\x03\n" + + "\x10UpdatePlayersReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x1b\n" + + "\x06userId\x18\x02 \x01(\x03H\x00R\x06userId\x88\x01\x01\x12\x1b\n" + + "\x06status\x18\x03 \x01(\tH\x01R\x06status\x88\x01\x01\x12\x1b\n" + + "\x06rating\x18\x04 \x01(\x01H\x02R\x06rating\x88\x01\x01\x12%\n" + + "\vtotalOrders\x18\x05 \x01(\x03H\x03R\vtotalOrders\x88\x01\x01\x12-\n" + + "\x0fcompletedOrders\x18\x06 \x01(\x03H\x04R\x0fcompletedOrders\x88\x01\x01\x12\x1b\n" + + "\x06shopId\x18\a \x01(\x03H\x05R\x06shopId\x88\x01\x01\x12\x12\n" + + "\x04tags\x18\b \x03(\tR\x04tags\x12\x14\n" + + "\x05games\x18\t \x03(\x03R\x05games\x12!\n" + + "\tcreatedAt\x18\n" + + " \x01(\x03H\x06R\tcreatedAt\x88\x01\x01\x12!\n" + + "\tupdatedAt\x18\v \x01(\x03H\aR\tupdatedAt\x88\x01\x01\x12\x1b\n" + + "\x06gender\x18\f \x01(\x03H\bR\x06gender\x88\x01\x01B\t\n" + + "\a_userIdB\t\n" + + "\a_statusB\t\n" + + "\a_ratingB\x0e\n" + + "\f_totalOrdersB\x12\n" + + "\x10_completedOrdersB\t\n" + + "\a_shopIdB\f\n" + + "\n" + + "_createdAtB\f\n" + + "\n" + + "_updatedAtB\t\n" + + "\a_gender\"\x13\n" + + "\x11UpdatePlayersResp\"\x1f\n" + + "\rDelPlayersReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\"\x10\n" + + "\x0eDelPlayersResp\"#\n" + + "\x11GetPlayersByIdReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\";\n" + + "\x12GetPlayersByIdResp\x12%\n" + + "\aplayers\x18\x01 \x01(\v2\v.pb.PlayersR\aplayers\"\xf6\x02\n" + + "\x10SearchPlayersReq\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\x16\n" + + "\x06userId\x18\x04 \x01(\x03R\x06userId\x12\x16\n" + + "\x06status\x18\x05 \x01(\tR\x06status\x12\x16\n" + + "\x06rating\x18\x06 \x01(\x01R\x06rating\x12 \n" + + "\vtotalOrders\x18\a \x01(\x03R\vtotalOrders\x12(\n" + + "\x0fcompletedOrders\x18\b \x01(\x03R\x0fcompletedOrders\x12\x16\n" + + "\x06shopId\x18\t \x01(\x03R\x06shopId\x12\x12\n" + + "\x04tags\x18\n" + + " \x03(\tR\x04tags\x12\x14\n" + + "\x05games\x18\v \x03(\x03R\x05games\x12\x1c\n" + + "\tcreatedAt\x18\f \x01(\x03R\tcreatedAt\x12\x1c\n" + + "\tupdatedAt\x18\r \x01(\x03R\tupdatedAt\x12\x16\n" + + "\x06gender\x18\x0e \x01(\x03R\x06gender\":\n" + + "\x11SearchPlayersResp\x12%\n" + + "\aplayers\x18\x01 \x03(\v2\v.pb.PlayersR\aplayers2\xc6\x05\n" + + "\rplayerService\x12H\n" + + "\x11AddPlayerServices\x12\x18.pb.AddPlayerServicesReq\x1a\x19.pb.AddPlayerServicesResp\x12Q\n" + + "\x14UpdatePlayerServices\x12\x1b.pb.UpdatePlayerServicesReq\x1a\x1c.pb.UpdatePlayerServicesResp\x12H\n" + + "\x11DelPlayerServices\x12\x18.pb.DelPlayerServicesReq\x1a\x19.pb.DelPlayerServicesResp\x12T\n" + + "\x15GetPlayerServicesById\x12\x1c.pb.GetPlayerServicesByIdReq\x1a\x1d.pb.GetPlayerServicesByIdResp\x12Q\n" + + "\x14SearchPlayerServices\x12\x1b.pb.SearchPlayerServicesReq\x1a\x1c.pb.SearchPlayerServicesResp\x123\n" + + "\n" + + "AddPlayers\x12\x11.pb.AddPlayersReq\x1a\x12.pb.AddPlayersResp\x12<\n" + + "\rUpdatePlayers\x12\x14.pb.UpdatePlayersReq\x1a\x15.pb.UpdatePlayersResp\x123\n" + + "\n" + + "DelPlayers\x12\x11.pb.DelPlayersReq\x1a\x12.pb.DelPlayersResp\x12?\n" + + "\x0eGetPlayersById\x12\x15.pb.GetPlayersByIdReq\x1a\x16.pb.GetPlayersByIdResp\x12<\n" + + "\rSearchPlayers\x12\x14.pb.SearchPlayersReq\x1a\x15.pb.SearchPlayersRespB\x06Z\x04./pbb\x06proto3" + +var ( + file_player_proto_rawDescOnce sync.Once + file_player_proto_rawDescData []byte +) + +func file_player_proto_rawDescGZIP() []byte { + file_player_proto_rawDescOnce.Do(func() { + file_player_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_player_proto_rawDesc), len(file_player_proto_rawDesc))) + }) + return file_player_proto_rawDescData +} + +var file_player_proto_msgTypes = make([]protoimpl.MessageInfo, 22) +var file_player_proto_goTypes = []any{ + (*PlayerServices)(nil), // 0: pb.PlayerServices + (*AddPlayerServicesReq)(nil), // 1: pb.AddPlayerServicesReq + (*AddPlayerServicesResp)(nil), // 2: pb.AddPlayerServicesResp + (*UpdatePlayerServicesReq)(nil), // 3: pb.UpdatePlayerServicesReq + (*UpdatePlayerServicesResp)(nil), // 4: pb.UpdatePlayerServicesResp + (*DelPlayerServicesReq)(nil), // 5: pb.DelPlayerServicesReq + (*DelPlayerServicesResp)(nil), // 6: pb.DelPlayerServicesResp + (*GetPlayerServicesByIdReq)(nil), // 7: pb.GetPlayerServicesByIdReq + (*GetPlayerServicesByIdResp)(nil), // 8: pb.GetPlayerServicesByIdResp + (*SearchPlayerServicesReq)(nil), // 9: pb.SearchPlayerServicesReq + (*SearchPlayerServicesResp)(nil), // 10: pb.SearchPlayerServicesResp + (*Players)(nil), // 11: pb.Players + (*AddPlayersReq)(nil), // 12: pb.AddPlayersReq + (*AddPlayersResp)(nil), // 13: pb.AddPlayersResp + (*UpdatePlayersReq)(nil), // 14: pb.UpdatePlayersReq + (*UpdatePlayersResp)(nil), // 15: pb.UpdatePlayersResp + (*DelPlayersReq)(nil), // 16: pb.DelPlayersReq + (*DelPlayersResp)(nil), // 17: pb.DelPlayersResp + (*GetPlayersByIdReq)(nil), // 18: pb.GetPlayersByIdReq + (*GetPlayersByIdResp)(nil), // 19: pb.GetPlayersByIdResp + (*SearchPlayersReq)(nil), // 20: pb.SearchPlayersReq + (*SearchPlayersResp)(nil), // 21: pb.SearchPlayersResp +} +var file_player_proto_depIdxs = []int32{ + 0, // 0: pb.GetPlayerServicesByIdResp.playerServices:type_name -> pb.PlayerServices + 0, // 1: pb.SearchPlayerServicesResp.playerServices:type_name -> pb.PlayerServices + 11, // 2: pb.GetPlayersByIdResp.players:type_name -> pb.Players + 11, // 3: pb.SearchPlayersResp.players:type_name -> pb.Players + 1, // 4: pb.playerService.AddPlayerServices:input_type -> pb.AddPlayerServicesReq + 3, // 5: pb.playerService.UpdatePlayerServices:input_type -> pb.UpdatePlayerServicesReq + 5, // 6: pb.playerService.DelPlayerServices:input_type -> pb.DelPlayerServicesReq + 7, // 7: pb.playerService.GetPlayerServicesById:input_type -> pb.GetPlayerServicesByIdReq + 9, // 8: pb.playerService.SearchPlayerServices:input_type -> pb.SearchPlayerServicesReq + 12, // 9: pb.playerService.AddPlayers:input_type -> pb.AddPlayersReq + 14, // 10: pb.playerService.UpdatePlayers:input_type -> pb.UpdatePlayersReq + 16, // 11: pb.playerService.DelPlayers:input_type -> pb.DelPlayersReq + 18, // 12: pb.playerService.GetPlayersById:input_type -> pb.GetPlayersByIdReq + 20, // 13: pb.playerService.SearchPlayers:input_type -> pb.SearchPlayersReq + 2, // 14: pb.playerService.AddPlayerServices:output_type -> pb.AddPlayerServicesResp + 4, // 15: pb.playerService.UpdatePlayerServices:output_type -> pb.UpdatePlayerServicesResp + 6, // 16: pb.playerService.DelPlayerServices:output_type -> pb.DelPlayerServicesResp + 8, // 17: pb.playerService.GetPlayerServicesById:output_type -> pb.GetPlayerServicesByIdResp + 10, // 18: pb.playerService.SearchPlayerServices:output_type -> pb.SearchPlayerServicesResp + 13, // 19: pb.playerService.AddPlayers:output_type -> pb.AddPlayersResp + 15, // 20: pb.playerService.UpdatePlayers:output_type -> pb.UpdatePlayersResp + 17, // 21: pb.playerService.DelPlayers:output_type -> pb.DelPlayersResp + 19, // 22: pb.playerService.GetPlayersById:output_type -> pb.GetPlayersByIdResp + 21, // 23: pb.playerService.SearchPlayers:output_type -> pb.SearchPlayersResp + 14, // [14:24] is the sub-list for method output_type + 4, // [4:14] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name +} + +func init() { file_player_proto_init() } +func file_player_proto_init() { + if File_player_proto != nil { + return + } + file_player_proto_msgTypes[3].OneofWrappers = []any{} + file_player_proto_msgTypes[14].OneofWrappers = []any{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_player_proto_rawDesc), len(file_player_proto_rawDesc)), + NumEnums: 0, + NumMessages: 22, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_player_proto_goTypes, + DependencyIndexes: file_player_proto_depIdxs, + MessageInfos: file_player_proto_msgTypes, + }.Build() + File_player_proto = out.File + file_player_proto_goTypes = nil + file_player_proto_depIdxs = nil +} diff --git a/app/player/rpc/pb/player_grpc.pb.go b/app/player/rpc/pb/player_grpc.pb.go new file mode 100644 index 0000000..d7dee8a --- /dev/null +++ b/app/player/rpc/pb/player_grpc.pb.go @@ -0,0 +1,467 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.6.1 +// - protoc v5.29.6 +// source: player.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 ( + PlayerService_AddPlayerServices_FullMethodName = "/pb.playerService/AddPlayerServices" + PlayerService_UpdatePlayerServices_FullMethodName = "/pb.playerService/UpdatePlayerServices" + PlayerService_DelPlayerServices_FullMethodName = "/pb.playerService/DelPlayerServices" + PlayerService_GetPlayerServicesById_FullMethodName = "/pb.playerService/GetPlayerServicesById" + PlayerService_SearchPlayerServices_FullMethodName = "/pb.playerService/SearchPlayerServices" + PlayerService_AddPlayers_FullMethodName = "/pb.playerService/AddPlayers" + PlayerService_UpdatePlayers_FullMethodName = "/pb.playerService/UpdatePlayers" + PlayerService_DelPlayers_FullMethodName = "/pb.playerService/DelPlayers" + PlayerService_GetPlayersById_FullMethodName = "/pb.playerService/GetPlayersById" + PlayerService_SearchPlayers_FullMethodName = "/pb.playerService/SearchPlayers" +) + +// PlayerServiceClient is the client API for PlayerService 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 PlayerServiceClient interface { + // -----------------------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) +} + +type playerServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewPlayerServiceClient(cc grpc.ClientConnInterface) PlayerServiceClient { + return &playerServiceClient{cc} +} + +func (c *playerServiceClient) AddPlayerServices(ctx context.Context, in *AddPlayerServicesReq, opts ...grpc.CallOption) (*AddPlayerServicesResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AddPlayerServicesResp) + err := c.cc.Invoke(ctx, PlayerService_AddPlayerServices_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *playerServiceClient) UpdatePlayerServices(ctx context.Context, in *UpdatePlayerServicesReq, opts ...grpc.CallOption) (*UpdatePlayerServicesResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(UpdatePlayerServicesResp) + err := c.cc.Invoke(ctx, PlayerService_UpdatePlayerServices_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *playerServiceClient) DelPlayerServices(ctx context.Context, in *DelPlayerServicesReq, opts ...grpc.CallOption) (*DelPlayerServicesResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(DelPlayerServicesResp) + err := c.cc.Invoke(ctx, PlayerService_DelPlayerServices_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *playerServiceClient) GetPlayerServicesById(ctx context.Context, in *GetPlayerServicesByIdReq, opts ...grpc.CallOption) (*GetPlayerServicesByIdResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetPlayerServicesByIdResp) + err := c.cc.Invoke(ctx, PlayerService_GetPlayerServicesById_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *playerServiceClient) SearchPlayerServices(ctx context.Context, in *SearchPlayerServicesReq, opts ...grpc.CallOption) (*SearchPlayerServicesResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SearchPlayerServicesResp) + err := c.cc.Invoke(ctx, PlayerService_SearchPlayerServices_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *playerServiceClient) AddPlayers(ctx context.Context, in *AddPlayersReq, opts ...grpc.CallOption) (*AddPlayersResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AddPlayersResp) + err := c.cc.Invoke(ctx, PlayerService_AddPlayers_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *playerServiceClient) UpdatePlayers(ctx context.Context, in *UpdatePlayersReq, opts ...grpc.CallOption) (*UpdatePlayersResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(UpdatePlayersResp) + err := c.cc.Invoke(ctx, PlayerService_UpdatePlayers_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *playerServiceClient) DelPlayers(ctx context.Context, in *DelPlayersReq, opts ...grpc.CallOption) (*DelPlayersResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(DelPlayersResp) + err := c.cc.Invoke(ctx, PlayerService_DelPlayers_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *playerServiceClient) GetPlayersById(ctx context.Context, in *GetPlayersByIdReq, opts ...grpc.CallOption) (*GetPlayersByIdResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetPlayersByIdResp) + err := c.cc.Invoke(ctx, PlayerService_GetPlayersById_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *playerServiceClient) SearchPlayers(ctx context.Context, in *SearchPlayersReq, opts ...grpc.CallOption) (*SearchPlayersResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SearchPlayersResp) + err := c.cc.Invoke(ctx, PlayerService_SearchPlayers_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// PlayerServiceServer is the server API for PlayerService service. +// All implementations must embed UnimplementedPlayerServiceServer +// for forward compatibility. +type PlayerServiceServer interface { + // -----------------------playerServices----------------------- + AddPlayerServices(context.Context, *AddPlayerServicesReq) (*AddPlayerServicesResp, error) + UpdatePlayerServices(context.Context, *UpdatePlayerServicesReq) (*UpdatePlayerServicesResp, error) + DelPlayerServices(context.Context, *DelPlayerServicesReq) (*DelPlayerServicesResp, error) + GetPlayerServicesById(context.Context, *GetPlayerServicesByIdReq) (*GetPlayerServicesByIdResp, error) + SearchPlayerServices(context.Context, *SearchPlayerServicesReq) (*SearchPlayerServicesResp, error) + // -----------------------players----------------------- + AddPlayers(context.Context, *AddPlayersReq) (*AddPlayersResp, error) + UpdatePlayers(context.Context, *UpdatePlayersReq) (*UpdatePlayersResp, error) + DelPlayers(context.Context, *DelPlayersReq) (*DelPlayersResp, error) + GetPlayersById(context.Context, *GetPlayersByIdReq) (*GetPlayersByIdResp, error) + SearchPlayers(context.Context, *SearchPlayersReq) (*SearchPlayersResp, error) + mustEmbedUnimplementedPlayerServiceServer() +} + +// UnimplementedPlayerServiceServer 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 UnimplementedPlayerServiceServer struct{} + +func (UnimplementedPlayerServiceServer) AddPlayerServices(context.Context, *AddPlayerServicesReq) (*AddPlayerServicesResp, error) { + return nil, status.Error(codes.Unimplemented, "method AddPlayerServices not implemented") +} +func (UnimplementedPlayerServiceServer) UpdatePlayerServices(context.Context, *UpdatePlayerServicesReq) (*UpdatePlayerServicesResp, error) { + return nil, status.Error(codes.Unimplemented, "method UpdatePlayerServices not implemented") +} +func (UnimplementedPlayerServiceServer) DelPlayerServices(context.Context, *DelPlayerServicesReq) (*DelPlayerServicesResp, error) { + return nil, status.Error(codes.Unimplemented, "method DelPlayerServices not implemented") +} +func (UnimplementedPlayerServiceServer) GetPlayerServicesById(context.Context, *GetPlayerServicesByIdReq) (*GetPlayerServicesByIdResp, error) { + return nil, status.Error(codes.Unimplemented, "method GetPlayerServicesById not implemented") +} +func (UnimplementedPlayerServiceServer) SearchPlayerServices(context.Context, *SearchPlayerServicesReq) (*SearchPlayerServicesResp, error) { + return nil, status.Error(codes.Unimplemented, "method SearchPlayerServices not implemented") +} +func (UnimplementedPlayerServiceServer) AddPlayers(context.Context, *AddPlayersReq) (*AddPlayersResp, error) { + return nil, status.Error(codes.Unimplemented, "method AddPlayers not implemented") +} +func (UnimplementedPlayerServiceServer) UpdatePlayers(context.Context, *UpdatePlayersReq) (*UpdatePlayersResp, error) { + return nil, status.Error(codes.Unimplemented, "method UpdatePlayers not implemented") +} +func (UnimplementedPlayerServiceServer) DelPlayers(context.Context, *DelPlayersReq) (*DelPlayersResp, error) { + return nil, status.Error(codes.Unimplemented, "method DelPlayers not implemented") +} +func (UnimplementedPlayerServiceServer) GetPlayersById(context.Context, *GetPlayersByIdReq) (*GetPlayersByIdResp, error) { + return nil, status.Error(codes.Unimplemented, "method GetPlayersById not implemented") +} +func (UnimplementedPlayerServiceServer) SearchPlayers(context.Context, *SearchPlayersReq) (*SearchPlayersResp, error) { + return nil, status.Error(codes.Unimplemented, "method SearchPlayers not implemented") +} +func (UnimplementedPlayerServiceServer) mustEmbedUnimplementedPlayerServiceServer() {} +func (UnimplementedPlayerServiceServer) testEmbeddedByValue() {} + +// UnsafePlayerServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to PlayerServiceServer will +// result in compilation errors. +type UnsafePlayerServiceServer interface { + mustEmbedUnimplementedPlayerServiceServer() +} + +func RegisterPlayerServiceServer(s grpc.ServiceRegistrar, srv PlayerServiceServer) { + // If the following call panics, it indicates UnimplementedPlayerServiceServer 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(&PlayerService_ServiceDesc, srv) +} + +func _PlayerService_AddPlayerServices_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AddPlayerServicesReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PlayerServiceServer).AddPlayerServices(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PlayerService_AddPlayerServices_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PlayerServiceServer).AddPlayerServices(ctx, req.(*AddPlayerServicesReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _PlayerService_UpdatePlayerServices_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdatePlayerServicesReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PlayerServiceServer).UpdatePlayerServices(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PlayerService_UpdatePlayerServices_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PlayerServiceServer).UpdatePlayerServices(ctx, req.(*UpdatePlayerServicesReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _PlayerService_DelPlayerServices_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DelPlayerServicesReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PlayerServiceServer).DelPlayerServices(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PlayerService_DelPlayerServices_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PlayerServiceServer).DelPlayerServices(ctx, req.(*DelPlayerServicesReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _PlayerService_GetPlayerServicesById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetPlayerServicesByIdReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PlayerServiceServer).GetPlayerServicesById(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PlayerService_GetPlayerServicesById_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PlayerServiceServer).GetPlayerServicesById(ctx, req.(*GetPlayerServicesByIdReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _PlayerService_SearchPlayerServices_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SearchPlayerServicesReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PlayerServiceServer).SearchPlayerServices(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PlayerService_SearchPlayerServices_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PlayerServiceServer).SearchPlayerServices(ctx, req.(*SearchPlayerServicesReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _PlayerService_AddPlayers_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AddPlayersReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PlayerServiceServer).AddPlayers(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PlayerService_AddPlayers_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PlayerServiceServer).AddPlayers(ctx, req.(*AddPlayersReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _PlayerService_UpdatePlayers_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdatePlayersReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PlayerServiceServer).UpdatePlayers(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PlayerService_UpdatePlayers_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PlayerServiceServer).UpdatePlayers(ctx, req.(*UpdatePlayersReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _PlayerService_DelPlayers_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DelPlayersReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PlayerServiceServer).DelPlayers(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PlayerService_DelPlayers_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PlayerServiceServer).DelPlayers(ctx, req.(*DelPlayersReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _PlayerService_GetPlayersById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetPlayersByIdReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PlayerServiceServer).GetPlayersById(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PlayerService_GetPlayersById_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PlayerServiceServer).GetPlayersById(ctx, req.(*GetPlayersByIdReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _PlayerService_SearchPlayers_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SearchPlayersReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PlayerServiceServer).SearchPlayers(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PlayerService_SearchPlayers_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PlayerServiceServer).SearchPlayers(ctx, req.(*SearchPlayersReq)) + } + return interceptor(ctx, in, info, handler) +} + +// PlayerService_ServiceDesc is the grpc.ServiceDesc for PlayerService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var PlayerService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "pb.playerService", + HandlerType: (*PlayerServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "AddPlayerServices", + Handler: _PlayerService_AddPlayerServices_Handler, + }, + { + MethodName: "UpdatePlayerServices", + Handler: _PlayerService_UpdatePlayerServices_Handler, + }, + { + MethodName: "DelPlayerServices", + Handler: _PlayerService_DelPlayerServices_Handler, + }, + { + MethodName: "GetPlayerServicesById", + Handler: _PlayerService_GetPlayerServicesById_Handler, + }, + { + MethodName: "SearchPlayerServices", + Handler: _PlayerService_SearchPlayerServices_Handler, + }, + { + MethodName: "AddPlayers", + Handler: _PlayerService_AddPlayers_Handler, + }, + { + MethodName: "UpdatePlayers", + Handler: _PlayerService_UpdatePlayers_Handler, + }, + { + MethodName: "DelPlayers", + Handler: _PlayerService_DelPlayers_Handler, + }, + { + MethodName: "GetPlayersById", + Handler: _PlayerService_GetPlayersById_Handler, + }, + { + MethodName: "SearchPlayers", + Handler: _PlayerService_SearchPlayers_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "player.proto", +} diff --git a/app/player/rpc/playerservice/playerService.go b/app/player/rpc/playerservice/playerService.go new file mode 100644 index 0000000..ac121c1 --- /dev/null +++ b/app/player/rpc/playerservice/playerService.go @@ -0,0 +1,116 @@ +// Code generated by goctl. DO NOT EDIT. +// goctl 1.9.2 +// Source: player.proto + +package playerservice + +import ( + "context" + + "juwan-backend/app/player/rpc/pb" + + "github.com/zeromicro/go-zero/zrpc" + "google.golang.org/grpc" +) + +type ( + AddPlayerServicesReq = pb.AddPlayerServicesReq + AddPlayerServicesResp = pb.AddPlayerServicesResp + AddPlayersReq = pb.AddPlayersReq + AddPlayersResp = pb.AddPlayersResp + DelPlayerServicesReq = pb.DelPlayerServicesReq + DelPlayerServicesResp = pb.DelPlayerServicesResp + DelPlayersReq = pb.DelPlayersReq + DelPlayersResp = pb.DelPlayersResp + GetPlayerServicesByIdReq = pb.GetPlayerServicesByIdReq + GetPlayerServicesByIdResp = pb.GetPlayerServicesByIdResp + GetPlayersByIdReq = pb.GetPlayersByIdReq + GetPlayersByIdResp = pb.GetPlayersByIdResp + PlayerServices = pb.PlayerServices + Players = pb.Players + SearchPlayerServicesReq = pb.SearchPlayerServicesReq + SearchPlayerServicesResp = pb.SearchPlayerServicesResp + SearchPlayersReq = pb.SearchPlayersReq + SearchPlayersResp = pb.SearchPlayersResp + UpdatePlayerServicesReq = pb.UpdatePlayerServicesReq + UpdatePlayerServicesResp = pb.UpdatePlayerServicesResp + UpdatePlayersReq = pb.UpdatePlayersReq + UpdatePlayersResp = pb.UpdatePlayersResp + + PlayerService interface { + // -----------------------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) + } + + defaultPlayerService struct { + cli zrpc.Client + } +) + +func NewPlayerService(cli zrpc.Client) PlayerService { + return &defaultPlayerService{ + cli: cli, + } +} + +// -----------------------playerServices----------------------- +func (m *defaultPlayerService) AddPlayerServices(ctx context.Context, in *AddPlayerServicesReq, opts ...grpc.CallOption) (*AddPlayerServicesResp, error) { + client := pb.NewPlayerServiceClient(m.cli.Conn()) + return client.AddPlayerServices(ctx, in, opts...) +} + +func (m *defaultPlayerService) UpdatePlayerServices(ctx context.Context, in *UpdatePlayerServicesReq, opts ...grpc.CallOption) (*UpdatePlayerServicesResp, error) { + client := pb.NewPlayerServiceClient(m.cli.Conn()) + return client.UpdatePlayerServices(ctx, in, opts...) +} + +func (m *defaultPlayerService) DelPlayerServices(ctx context.Context, in *DelPlayerServicesReq, opts ...grpc.CallOption) (*DelPlayerServicesResp, error) { + client := pb.NewPlayerServiceClient(m.cli.Conn()) + return client.DelPlayerServices(ctx, in, opts...) +} + +func (m *defaultPlayerService) GetPlayerServicesById(ctx context.Context, in *GetPlayerServicesByIdReq, opts ...grpc.CallOption) (*GetPlayerServicesByIdResp, error) { + client := pb.NewPlayerServiceClient(m.cli.Conn()) + return client.GetPlayerServicesById(ctx, in, opts...) +} + +func (m *defaultPlayerService) SearchPlayerServices(ctx context.Context, in *SearchPlayerServicesReq, opts ...grpc.CallOption) (*SearchPlayerServicesResp, error) { + client := pb.NewPlayerServiceClient(m.cli.Conn()) + return client.SearchPlayerServices(ctx, in, opts...) +} + +// -----------------------players----------------------- +func (m *defaultPlayerService) AddPlayers(ctx context.Context, in *AddPlayersReq, opts ...grpc.CallOption) (*AddPlayersResp, error) { + client := pb.NewPlayerServiceClient(m.cli.Conn()) + return client.AddPlayers(ctx, in, opts...) +} + +func (m *defaultPlayerService) UpdatePlayers(ctx context.Context, in *UpdatePlayersReq, opts ...grpc.CallOption) (*UpdatePlayersResp, error) { + client := pb.NewPlayerServiceClient(m.cli.Conn()) + return client.UpdatePlayers(ctx, in, opts...) +} + +func (m *defaultPlayerService) DelPlayers(ctx context.Context, in *DelPlayersReq, opts ...grpc.CallOption) (*DelPlayersResp, error) { + client := pb.NewPlayerServiceClient(m.cli.Conn()) + return client.DelPlayers(ctx, in, opts...) +} + +func (m *defaultPlayerService) GetPlayersById(ctx context.Context, in *GetPlayersByIdReq, opts ...grpc.CallOption) (*GetPlayersByIdResp, error) { + client := pb.NewPlayerServiceClient(m.cli.Conn()) + return client.GetPlayersById(ctx, in, opts...) +} + +func (m *defaultPlayerService) SearchPlayers(ctx context.Context, in *SearchPlayersReq, opts ...grpc.CallOption) (*SearchPlayersResp, error) { + client := pb.NewPlayerServiceClient(m.cli.Conn()) + return client.SearchPlayers(ctx, in, opts...) +} diff --git a/app/shop/api/etc/juwan-api.yaml b/app/shop/api/etc/juwan-api.yaml new file mode 100644 index 0000000..2ef25ff --- /dev/null +++ b/app/shop/api/etc/juwan-api.yaml @@ -0,0 +1,14 @@ +Name: juwan-api +Host: 0.0.0.0 +Port: 8888 + +Prometheus: + Host: 0.0.0.0 + Port: 4001 + Path: /metrics + +# k8s://juwan/:8080 + +ShopRpcConf: + Target: k8s://juwan/shop-rpc-svc.juwan:8080 + diff --git a/app/shop/api/internal/config/config.go b/app/shop/api/internal/config/config.go new file mode 100644 index 0000000..b15f22d --- /dev/null +++ b/app/shop/api/internal/config/config.go @@ -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 + ShopRpcConf zrpc.RpcClientConf +} diff --git a/app/shop/api/internal/handler/routes.go b/app/shop/api/internal/handler/routes.go new file mode 100644 index 0000000..760c6d9 --- /dev/null +++ b/app/shop/api/internal/handler/routes.go @@ -0,0 +1,111 @@ +// Code generated by goctl. DO NOT EDIT. +// goctl 1.9.2 + +package handler + +import ( + "net/http" + + shop "juwan-backend/app/shop/api/internal/handler/shop" + "juwan-backend/app/shop/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: "/shops", + Handler: shop.ListShopsHandler(serverCtx), + }, + { + // 获取店铺详情 + Method: http.MethodGet, + Path: "/shops/:id", + Handler: shop.GetShopHandler(serverCtx), + }, + { + // 获取店长的店铺 + Method: http.MethodGet, + Path: "/users/:id/shop", + Handler: shop.GetUserShopHandler(serverCtx), + }, + }, + rest.WithPrefix("/api/v1"), + ) + + server.AddRoutes( + []rest.Route{ + { + // 创建店铺 + Method: http.MethodPost, + Path: "/shops", + Handler: shop.CreateShopHandler(serverCtx), + }, + { + // 更新店铺信息 + Method: http.MethodPut, + Path: "/shops/:id", + Handler: shop.UpdateShopHandler(serverCtx), + }, + { + // 新增店铺公告 + Method: http.MethodPost, + Path: "/shops/:id/announcements", + Handler: shop.AddAnnouncementHandler(serverCtx), + }, + { + // 删除店铺公告 + Method: http.MethodDelete, + Path: "/shops/:id/announcements/:index", + Handler: shop.DeleteAnnouncementHandler(serverCtx), + }, + { + // 获取收入统计 + Method: http.MethodGet, + Path: "/shops/:id/income-stats", + Handler: shop.GetShopIncomeStatsHandler(serverCtx), + }, + { + // 邀请打手 + Method: http.MethodPost, + Path: "/shops/:id/invitations", + Handler: shop.InvitePlayerHandler(serverCtx), + }, + { + // 移除打手 + Method: http.MethodDelete, + Path: "/shops/:id/players/:playerId", + Handler: shop.RemovePlayerHandler(serverCtx), + }, + { + // 更新店铺模板 + Method: http.MethodPut, + Path: "/shops/:id/template", + Handler: shop.UpdateShopTemplateHandler(serverCtx), + }, + { + // 拒绝邀请 + Method: http.MethodDelete, + Path: "/shops/invitations/:id", + Handler: shop.RejectInvitationHandler(serverCtx), + }, + { + // 接受邀请 + Method: http.MethodPost, + Path: "/shops/invitations/:id/accept", + Handler: shop.AcceptInvitationHandler(serverCtx), + }, + { + // 获取当前用户的店铺 + Method: http.MethodGet, + Path: "/shops/mine", + Handler: shop.GetMyShopHandler(serverCtx), + }, + }, + rest.WithPrefix("/api/v1"), + ) +} diff --git a/app/shop/api/internal/handler/shop/acceptInvitationHandler.go b/app/shop/api/internal/handler/shop/acceptInvitationHandler.go new file mode 100644 index 0000000..9a2d3fd --- /dev/null +++ b/app/shop/api/internal/handler/shop/acceptInvitationHandler.go @@ -0,0 +1,32 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "juwan-backend/app/shop/api/internal/logic/shop" + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" +) + +// 接受邀请 +func AcceptInvitationHandler(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 := shop.NewAcceptInvitationLogic(r.Context(), svcCtx) + resp, err := l.AcceptInvitation(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/app/shop/api/internal/handler/shop/addAnnouncementHandler.go b/app/shop/api/internal/handler/shop/addAnnouncementHandler.go new file mode 100644 index 0000000..bbea91e --- /dev/null +++ b/app/shop/api/internal/handler/shop/addAnnouncementHandler.go @@ -0,0 +1,32 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "juwan-backend/app/shop/api/internal/logic/shop" + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" +) + +// 新增店铺公告 +func AddAnnouncementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.AnnouncementReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := shop.NewAddAnnouncementLogic(r.Context(), svcCtx) + resp, err := l.AddAnnouncement(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/app/shop/api/internal/handler/shop/createShopHandler.go b/app/shop/api/internal/handler/shop/createShopHandler.go new file mode 100644 index 0000000..e6635d7 --- /dev/null +++ b/app/shop/api/internal/handler/shop/createShopHandler.go @@ -0,0 +1,32 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "juwan-backend/app/shop/api/internal/logic/shop" + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" +) + +// 创建店铺 +func CreateShopHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.CreateShopReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := shop.NewCreateShopLogic(r.Context(), svcCtx) + resp, err := l.CreateShop(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/app/shop/api/internal/handler/shop/deleteAnnouncementHandler.go b/app/shop/api/internal/handler/shop/deleteAnnouncementHandler.go new file mode 100644 index 0000000..32a2e80 --- /dev/null +++ b/app/shop/api/internal/handler/shop/deleteAnnouncementHandler.go @@ -0,0 +1,32 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "juwan-backend/app/shop/api/internal/logic/shop" + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" +) + +// 删除店铺公告 +func DeleteAnnouncementHandler(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 := shop.NewDeleteAnnouncementLogic(r.Context(), svcCtx) + resp, err := l.DeleteAnnouncement(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/app/shop/api/internal/handler/shop/getMyShopHandler.go b/app/shop/api/internal/handler/shop/getMyShopHandler.go new file mode 100644 index 0000000..37100e4 --- /dev/null +++ b/app/shop/api/internal/handler/shop/getMyShopHandler.go @@ -0,0 +1,32 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "juwan-backend/app/shop/api/internal/logic/shop" + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" +) + +// 获取当前用户的店铺 +func GetMyShopHandler(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 := shop.NewGetMyShopLogic(r.Context(), svcCtx) + resp, err := l.GetMyShop(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/app/shop/api/internal/handler/shop/getShopHandler.go b/app/shop/api/internal/handler/shop/getShopHandler.go new file mode 100644 index 0000000..a739964 --- /dev/null +++ b/app/shop/api/internal/handler/shop/getShopHandler.go @@ -0,0 +1,32 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "juwan-backend/app/shop/api/internal/logic/shop" + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" +) + +// 获取店铺详情 +func GetShopHandler(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 := shop.NewGetShopLogic(r.Context(), svcCtx) + resp, err := l.GetShop(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/app/shop/api/internal/handler/shop/getShopIncomeStatsHandler.go b/app/shop/api/internal/handler/shop/getShopIncomeStatsHandler.go new file mode 100644 index 0000000..1b7913f --- /dev/null +++ b/app/shop/api/internal/handler/shop/getShopIncomeStatsHandler.go @@ -0,0 +1,32 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "juwan-backend/app/shop/api/internal/logic/shop" + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" +) + +// 获取收入统计 +func GetShopIncomeStatsHandler(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 := shop.NewGetShopIncomeStatsLogic(r.Context(), svcCtx) + resp, err := l.GetShopIncomeStats(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/app/shop/api/internal/handler/shop/getUserShopHandler.go b/app/shop/api/internal/handler/shop/getUserShopHandler.go new file mode 100644 index 0000000..5f4f4a4 --- /dev/null +++ b/app/shop/api/internal/handler/shop/getUserShopHandler.go @@ -0,0 +1,32 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "juwan-backend/app/shop/api/internal/logic/shop" + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" +) + +// 获取店长的店铺 +func GetUserShopHandler(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 := shop.NewGetUserShopLogic(r.Context(), svcCtx) + resp, err := l.GetUserShop(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/app/shop/api/internal/handler/shop/invitePlayerHandler.go b/app/shop/api/internal/handler/shop/invitePlayerHandler.go new file mode 100644 index 0000000..2d124af --- /dev/null +++ b/app/shop/api/internal/handler/shop/invitePlayerHandler.go @@ -0,0 +1,32 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "juwan-backend/app/shop/api/internal/logic/shop" + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" +) + +// 邀请打手 +func InvitePlayerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.InvitationReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := shop.NewInvitePlayerLogic(r.Context(), svcCtx) + resp, err := l.InvitePlayer(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/app/shop/api/internal/handler/shop/listShopsHandler.go b/app/shop/api/internal/handler/shop/listShopsHandler.go new file mode 100644 index 0000000..35ad2a2 --- /dev/null +++ b/app/shop/api/internal/handler/shop/listShopsHandler.go @@ -0,0 +1,32 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "juwan-backend/app/shop/api/internal/logic/shop" + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" +) + +// 获取店铺列表 +func ListShopsHandler(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 := shop.NewListShopsLogic(r.Context(), svcCtx) + resp, err := l.ListShops(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/app/shop/api/internal/handler/shop/rejectInvitationHandler.go b/app/shop/api/internal/handler/shop/rejectInvitationHandler.go new file mode 100644 index 0000000..c17e7f0 --- /dev/null +++ b/app/shop/api/internal/handler/shop/rejectInvitationHandler.go @@ -0,0 +1,32 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "juwan-backend/app/shop/api/internal/logic/shop" + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" +) + +// 拒绝邀请 +func RejectInvitationHandler(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 := shop.NewRejectInvitationLogic(r.Context(), svcCtx) + resp, err := l.RejectInvitation(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/app/shop/api/internal/handler/shop/removePlayerHandler.go b/app/shop/api/internal/handler/shop/removePlayerHandler.go new file mode 100644 index 0000000..4108c65 --- /dev/null +++ b/app/shop/api/internal/handler/shop/removePlayerHandler.go @@ -0,0 +1,32 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "juwan-backend/app/shop/api/internal/logic/shop" + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" +) + +// 移除打手 +func RemovePlayerHandler(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 := shop.NewRemovePlayerLogic(r.Context(), svcCtx) + resp, err := l.RemovePlayer(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/app/shop/api/internal/handler/shop/updateShopHandler.go b/app/shop/api/internal/handler/shop/updateShopHandler.go new file mode 100644 index 0000000..0cd39e9 --- /dev/null +++ b/app/shop/api/internal/handler/shop/updateShopHandler.go @@ -0,0 +1,32 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "juwan-backend/app/shop/api/internal/logic/shop" + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" +) + +// 更新店铺信息 +func UpdateShopHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.UpdateShopReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := shop.NewUpdateShopLogic(r.Context(), svcCtx) + resp, err := l.UpdateShop(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/app/shop/api/internal/handler/shop/updateShopTemplateHandler.go b/app/shop/api/internal/handler/shop/updateShopTemplateHandler.go new file mode 100644 index 0000000..08b9e6f --- /dev/null +++ b/app/shop/api/internal/handler/shop/updateShopTemplateHandler.go @@ -0,0 +1,32 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "juwan-backend/app/shop/api/internal/logic/shop" + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" +) + +// 更新店铺模板 +func UpdateShopTemplateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.UpdateTemplateReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := shop.NewUpdateShopTemplateLogic(r.Context(), svcCtx) + resp, err := l.UpdateShopTemplate(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/app/shop/api/internal/logic/shop/acceptInvitationLogic.go b/app/shop/api/internal/logic/shop/acceptInvitationLogic.go new file mode 100644 index 0000000..8c214a9 --- /dev/null +++ b/app/shop/api/internal/logic/shop/acceptInvitationLogic.go @@ -0,0 +1,34 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "context" + + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type AcceptInvitationLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// 接受邀请 +func NewAcceptInvitationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AcceptInvitationLogic { + return &AcceptInvitationLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *AcceptInvitationLogic) AcceptInvitation(req *types.AcceptInvitationReq) (resp *types.EmptyResp, err error) { + // todo: add your logic here and delete this line + AcceptInvitationLogic{} + return +} diff --git a/app/shop/api/internal/logic/shop/addAnnouncementLogic.go b/app/shop/api/internal/logic/shop/addAnnouncementLogic.go new file mode 100644 index 0000000..a273def --- /dev/null +++ b/app/shop/api/internal/logic/shop/addAnnouncementLogic.go @@ -0,0 +1,34 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "context" + + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type AddAnnouncementLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// 新增店铺公告 +func NewAddAnnouncementLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddAnnouncementLogic { + return &AddAnnouncementLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *AddAnnouncementLogic) AddAnnouncement(req *types.AnnouncementReq) (resp *types.EmptyResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/app/shop/api/internal/logic/shop/createShopLogic.go b/app/shop/api/internal/logic/shop/createShopLogic.go new file mode 100644 index 0000000..fffee05 --- /dev/null +++ b/app/shop/api/internal/logic/shop/createShopLogic.go @@ -0,0 +1,34 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "context" + + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type CreateShopLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// 创建店铺 +func NewCreateShopLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateShopLogic { + return &CreateShopLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *CreateShopLogic) CreateShop(req *types.CreateShopReq) (resp *types.ShopProfile, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/app/shop/api/internal/logic/shop/deleteAnnouncementLogic.go b/app/shop/api/internal/logic/shop/deleteAnnouncementLogic.go new file mode 100644 index 0000000..533556c --- /dev/null +++ b/app/shop/api/internal/logic/shop/deleteAnnouncementLogic.go @@ -0,0 +1,34 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "context" + + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type DeleteAnnouncementLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// 删除店铺公告 +func NewDeleteAnnouncementLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteAnnouncementLogic { + return &DeleteAnnouncementLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *DeleteAnnouncementLogic) DeleteAnnouncement(req *types.DeleteAnnouncementReq) (resp *types.EmptyResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/app/shop/api/internal/logic/shop/getMyShopLogic.go b/app/shop/api/internal/logic/shop/getMyShopLogic.go new file mode 100644 index 0000000..709a436 --- /dev/null +++ b/app/shop/api/internal/logic/shop/getMyShopLogic.go @@ -0,0 +1,34 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "context" + + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetMyShopLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// 获取当前用户的店铺 +func NewGetMyShopLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMyShopLogic { + return &GetMyShopLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetMyShopLogic) GetMyShop(req *types.EmptyResp) (resp *types.ShopProfile, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/app/shop/api/internal/logic/shop/getShopIncomeStatsLogic.go b/app/shop/api/internal/logic/shop/getShopIncomeStatsLogic.go new file mode 100644 index 0000000..f5f137e --- /dev/null +++ b/app/shop/api/internal/logic/shop/getShopIncomeStatsLogic.go @@ -0,0 +1,34 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "context" + + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetShopIncomeStatsLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// 获取收入统计 +func NewGetShopIncomeStatsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetShopIncomeStatsLogic { + return &GetShopIncomeStatsLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetShopIncomeStatsLogic) GetShopIncomeStats(req *types.AcceptInvitationReq) (resp *types.IncomeStatsResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/app/shop/api/internal/logic/shop/getShopLogic.go b/app/shop/api/internal/logic/shop/getShopLogic.go new file mode 100644 index 0000000..c3fefdf --- /dev/null +++ b/app/shop/api/internal/logic/shop/getShopLogic.go @@ -0,0 +1,34 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "context" + + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetShopLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// 获取店铺详情 +func NewGetShopLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetShopLogic { + return &GetShopLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetShopLogic) GetShop(req *types.ShopIdReq) (resp *types.ShopProfile, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/app/shop/api/internal/logic/shop/getUserShopLogic.go b/app/shop/api/internal/logic/shop/getUserShopLogic.go new file mode 100644 index 0000000..f2d8ac0 --- /dev/null +++ b/app/shop/api/internal/logic/shop/getUserShopLogic.go @@ -0,0 +1,34 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "context" + + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetUserShopLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// 获取店长的店铺 +func NewGetUserShopLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserShopLogic { + return &GetUserShopLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetUserShopLogic) GetUserShop(req *types.UserIdReq) (resp *types.ShopProfile, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/app/shop/api/internal/logic/shop/invitePlayerLogic.go b/app/shop/api/internal/logic/shop/invitePlayerLogic.go new file mode 100644 index 0000000..7d0b98e --- /dev/null +++ b/app/shop/api/internal/logic/shop/invitePlayerLogic.go @@ -0,0 +1,34 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "context" + + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type InvitePlayerLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// 邀请打手 +func NewInvitePlayerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InvitePlayerLogic { + return &InvitePlayerLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *InvitePlayerLogic) InvitePlayer(req *types.InvitationReq) (resp *types.EmptyResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/app/shop/api/internal/logic/shop/listShopsLogic.go b/app/shop/api/internal/logic/shop/listShopsLogic.go new file mode 100644 index 0000000..e10e730 --- /dev/null +++ b/app/shop/api/internal/logic/shop/listShopsLogic.go @@ -0,0 +1,34 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "context" + + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ListShopsLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// 获取店铺列表 +func NewListShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListShopsLogic { + return &ListShopsLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *ListShopsLogic) ListShops(req *types.PageReq) (resp *types.ShopListResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/app/shop/api/internal/logic/shop/rejectInvitationLogic.go b/app/shop/api/internal/logic/shop/rejectInvitationLogic.go new file mode 100644 index 0000000..e723d97 --- /dev/null +++ b/app/shop/api/internal/logic/shop/rejectInvitationLogic.go @@ -0,0 +1,34 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "context" + + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type RejectInvitationLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// 拒绝邀请 +func NewRejectInvitationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RejectInvitationLogic { + return &RejectInvitationLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *RejectInvitationLogic) RejectInvitation(req *types.AcceptInvitationReq) (resp *types.EmptyResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/app/shop/api/internal/logic/shop/removePlayerLogic.go b/app/shop/api/internal/logic/shop/removePlayerLogic.go new file mode 100644 index 0000000..c81eefd --- /dev/null +++ b/app/shop/api/internal/logic/shop/removePlayerLogic.go @@ -0,0 +1,34 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "context" + + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type RemovePlayerLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// 移除打手 +func NewRemovePlayerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RemovePlayerLogic { + return &RemovePlayerLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *RemovePlayerLogic) RemovePlayer(req *types.InvitationReq) (resp *types.EmptyResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/app/shop/api/internal/logic/shop/updateShopLogic.go b/app/shop/api/internal/logic/shop/updateShopLogic.go new file mode 100644 index 0000000..3c70191 --- /dev/null +++ b/app/shop/api/internal/logic/shop/updateShopLogic.go @@ -0,0 +1,34 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "context" + + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type UpdateShopLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// 更新店铺信息 +func NewUpdateShopLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateShopLogic { + return &UpdateShopLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *UpdateShopLogic) UpdateShop(req *types.ShopIdReq) (resp *types.ShopProfile, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/app/shop/api/internal/logic/shop/updateShopTemplateLogic.go b/app/shop/api/internal/logic/shop/updateShopTemplateLogic.go new file mode 100644 index 0000000..3c75d0d --- /dev/null +++ b/app/shop/api/internal/logic/shop/updateShopTemplateLogic.go @@ -0,0 +1,34 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package shop + +import ( + "context" + + "juwan-backend/app/shop/api/internal/svc" + "juwan-backend/app/shop/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type UpdateShopTemplateLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// 更新店铺模板 +func NewUpdateShopTemplateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateShopTemplateLogic { + return &UpdateShopTemplateLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *UpdateShopTemplateLogic) UpdateShopTemplate(req *types.UpdateTemplateReq) (resp *types.EmptyResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/app/shop/api/internal/svc/serviceContext.go b/app/shop/api/internal/svc/serviceContext.go new file mode 100644 index 0000000..73ee5ec --- /dev/null +++ b/app/shop/api/internal/svc/serviceContext.go @@ -0,0 +1,23 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package svc + +import ( + "juwan-backend/app/shop/api/internal/config" + "juwan-backend/app/shop/rpc/shopservice" + + "github.com/zeromicro/go-zero/zrpc" +) + +type ServiceContext struct { + Config config.Config + ShopRpc shopservice.ShopService +} + +func NewServiceContext(c config.Config) *ServiceContext { + return &ServiceContext{ + Config: c, + ShopRpc: shopservice.NewShopService(zrpc.MustNewClient(c.ShopRpcConf)), + } +} diff --git a/app/shop/api/internal/types/types.go b/app/shop/api/internal/types/types.go new file mode 100644 index 0000000..373d918 --- /dev/null +++ b/app/shop/api/internal/types/types.go @@ -0,0 +1,115 @@ +// Code generated by goctl. DO NOT EDIT. +// goctl 1.9.2 + +package types + +type AcceptInvitationReq struct { + Id int64 `path:"id"` +} + +type AnnouncementReq struct { + Id int64 `path:"id"` + Content string `json:"content"` +} + +type CreateShopReq struct { + Name string `json:"name"` + Description string `json:"description"` + CommissionType string `json:"commissionType"` + CommissionValue float64 `json:"commissionValue"` +} + +type DeleteAnnouncementReq struct { + Id int64 `path:"id"` + Index int64 `path:"index"` +} + +type EmptyResp struct { +} + +type IncomeStatsResp struct { + MonthlyIncome float64 `json:"monthlyIncome"` + PendingSettlement float64 `json:"pendingSettlement"` + TotalWithdrawn float64 `json:"totalWithdrawn"` + TotalOrders int64 `json:"totalOrders"` + CompletedOrders int64 `json:"completedOrders"` +} + +type InvitationReq struct { + Id int64 `path:"id"` + PlayerId int64 `json:"playerId"` +} + +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 ShopIdReq struct { + Id int64 `path:"id"` +} + +type ShopListResp struct { + Items []ShopProfile `json:"items"` + Meta PageMeta `json:"meta"` +} + +type ShopProfile struct { + Id string `json:"id"` + Owner UserProfile `json:"owner"` + Name string `json:"name"` + Banner string `json:"banner,optional"` + Description string `json:"description"` + Rating float64 `json:"rating"` + TotalOrders int64 `json:"totalOrders"` + PlayerCount int64 `json:"playerCount"` + CommissionType string `json:"commissionType"` + CommissionValue float64 `json:"commissionValue"` + Announcements []string `json:"announcements"` + TemplateConfig interface{} `json:"templateConfig"` +} + +type SimpleUser struct { + Id string `json:"id"` + Nickname string `json:"nickname"` + Avatar string `json:"avatar"` +} + +type UpdateShopReq struct { + Id int64 `path:"id"` + Name string `json:"name,optional"` + Description string `json:"description,optional"` + CommissionType string `json:"commissionType,optional"` + CommissionValue float64 `json:"commissionValue,optional"` + AllowMultiShop bool `json:"allowMultiShop,optional"` + AllowIndependentOrders bool `json:"allowIndependentOrders,optional"` + DispatchMode string `json:"dispatchMode,optional"` +} + +type UpdateTemplateReq struct { + Id int64 `path:"id"` + Sections interface{} `json:"sections"` +} + +type UserIdReq struct { + Id int64 `path:"id"` +} + +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"` +} diff --git a/app/shop/api/juwan.go b/app/shop/api/juwan.go new file mode 100644 index 0000000..d103de6 --- /dev/null +++ b/app/shop/api/juwan.go @@ -0,0 +1,34 @@ +// Code scaffolded by goctl. Safe to edit. +// goctl 1.9.2 + +package main + +import ( + "flag" + "fmt" + + "juwan-backend/app/shop/api/internal/config" + "juwan-backend/app/shop/api/internal/handler" + "juwan-backend/app/shop/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() +} diff --git a/app/shop/rpc/etc/pb.yaml b/app/shop/rpc/etc/pb.yaml new file mode 100644 index 0000000..1b56cb7 --- /dev/null +++ b/app/shop/rpc/etc/pb.yaml @@ -0,0 +1,35 @@ +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/.: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 diff --git a/app/shop/rpc/internal/config/config.go b/app/shop/rpc/internal/config/config.go new file mode 100644 index 0000000..99ce632 --- /dev/null +++ b/app/shop/rpc/internal/config/config.go @@ -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 +} diff --git a/app/shop/rpc/internal/logic/addShopInvitationsLogic.go b/app/shop/rpc/internal/logic/addShopInvitationsLogic.go new file mode 100644 index 0000000..7cb6296 --- /dev/null +++ b/app/shop/rpc/internal/logic/addShopInvitationsLogic.go @@ -0,0 +1,48 @@ +package logic + +import ( + "context" + "errors" + "juwan-backend/app/snowflake/rpc/snowflake" + + "juwan-backend/app/shop/rpc/internal/svc" + "juwan-backend/app/shop/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type AddShopInvitationsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewAddShopInvitationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddShopInvitationsLogic { + return &AddShopInvitationsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// -----------------------shopInvitations----------------------- +func (l *AddShopInvitationsLogic) AddShopInvitations(in *pb.AddShopInvitationsReq) (*pb.AddShopInvitationsResp, 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.ShopModelRW.ShopInvitations.Create(). + SetID(idResp.Id). + SetShopID(in.ShopId). + SetPlayerID(in.PlayerId). + SetStatus(in.Status). + SetInvitedBy(in.InvitedBy). + Save(l.ctx) + + if err != nil { + return nil, errors.New("add shop invitation failed") + } + return &pb.AddShopInvitationsResp{}, nil +} diff --git a/app/shop/rpc/internal/logic/addShopPlayersLogic.go b/app/shop/rpc/internal/logic/addShopPlayersLogic.go new file mode 100644 index 0000000..94fe641 --- /dev/null +++ b/app/shop/rpc/internal/logic/addShopPlayersLogic.go @@ -0,0 +1,48 @@ +package logic + +import ( + "context" + "errors" + "juwan-backend/app/snowflake/rpc/snowflake" + + "juwan-backend/app/shop/rpc/internal/svc" + "juwan-backend/app/shop/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type AddShopPlayersLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewAddShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddShopPlayersLogic { + return &AddShopPlayersLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// -----------------------shopPlayers----------------------- +func (l *AddShopPlayersLogic) AddShopPlayers(in *pb.AddShopPlayersReq) (*pb.AddShopPlayersResp, 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.ShopModelRW.ShopPlayers.Create(). + SetID(idResp.Id). + SetShopID(in.ShopId). + SetPlayerID(in.PlayerId). + SetIsPrimary(in.IsPrimary). + Save(l.ctx) + if err != nil { + logx.Errorf("addPlayerServices err:%v", err) + return nil, errors.New("add player service failed") + } + + return &pb.AddShopPlayersResp{}, nil +} diff --git a/app/shop/rpc/internal/logic/addShopsLogic.go b/app/shop/rpc/internal/logic/addShopsLogic.go new file mode 100644 index 0000000..d70f763 --- /dev/null +++ b/app/shop/rpc/internal/logic/addShopsLogic.go @@ -0,0 +1,68 @@ +package logic + +import ( + "context" + "encoding/json" + "errors" + "juwan-backend/app/snowflake/rpc/snowflake" + + "juwan-backend/app/shop/rpc/internal/svc" + "juwan-backend/app/shop/rpc/pb" + + "github.com/shopspring/decimal" + "github.com/zeromicro/go-zero/core/logx" +) + +type AddShopsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewAddShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddShopsLogic { + return &AddShopsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// -----------------------shops----------------------- +func (l *AddShopsLogic) AddShops(in *pb.AddShopsReq) (*pb.AddShopsResp, 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") + } + + var templateConfig map[string]interface{} + err = json.Unmarshal([]byte(in.TemplateConfig), &templateConfig) + if err != nil { + logx.Errorf("addPlayerServices err:%v", err) + return nil, errors.New("invalid template config") + } + + _, err = l.svcCtx.ShopModelRO.Shops.Create(). + SetID(idResp.Id). + SetOwnerID(in.OwnerId). + SetName(in.Name). + SetBanner(in.Banner). + SetDescription(in.Description). + SetRating(decimal.NewFromFloat(in.Rating)). + SetTotalOrders(int(in.TotalOrders)). + SetPlayerCount(int(in.PlayerCount)). + SetNillableCommissionType(&in.CommissionType). + SetCommissionValue(decimal.NewFromFloat(in.CommissionValue)). + SetAllowMultiShop(in.AllowMultiShop). + SetAllowIndependentOrders(in.AllowIndependentOrders). + SetDispatchMode(in.DispatchMode). + SetAnnouncements(in.Announcements). + SetTemplateConfig(templateConfig). + Save(l.ctx) + + if err != nil { + logx.Errorf("addPlayerServices err:%v", err) + return nil, errors.New("add player service failed") + } + return &pb.AddShopsResp{}, nil +} diff --git a/app/shop/rpc/internal/logic/delShopInvitationsLogic.go b/app/shop/rpc/internal/logic/delShopInvitationsLogic.go new file mode 100644 index 0000000..b3d8689 --- /dev/null +++ b/app/shop/rpc/internal/logic/delShopInvitationsLogic.go @@ -0,0 +1,35 @@ +package logic + +import ( + "context" + "errors" + + "juwan-backend/app/shop/rpc/internal/svc" + "juwan-backend/app/shop/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type DelShopInvitationsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewDelShopInvitationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelShopInvitationsLogic { + return &DelShopInvitationsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *DelShopInvitationsLogic) DelShopInvitations(in *pb.DelShopInvitationsReq) (*pb.DelShopInvitationsResp, error) { + err := l.svcCtx.ShopModelRW.ShopInvitations.DeleteOneID(in.Id).Exec(l.ctx) + if err != nil { + logx.Errorf("delete shop invitations failed, %s", err.Error()) + return nil, errors.New("delete failed") + } + + return &pb.DelShopInvitationsResp{}, nil +} diff --git a/app/shop/rpc/internal/logic/delShopPlayersLogic.go b/app/shop/rpc/internal/logic/delShopPlayersLogic.go new file mode 100644 index 0000000..a3020f3 --- /dev/null +++ b/app/shop/rpc/internal/logic/delShopPlayersLogic.go @@ -0,0 +1,35 @@ +package logic + +import ( + "context" + "errors" + + "juwan-backend/app/shop/rpc/internal/svc" + "juwan-backend/app/shop/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type DelShopPlayersLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewDelShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelShopPlayersLogic { + return &DelShopPlayersLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *DelShopPlayersLogic) DelShopPlayers(in *pb.DelShopPlayersReq) (*pb.DelShopPlayersResp, error) { + err := l.svcCtx.ShopModelRO.ShopPlayers.DeleteOneID(in.Id).Exec(l.ctx) + if err != nil { + logx.Errorf("delete shop players failed, %s", err.Error()) + return nil, errors.New("delete failed") + } + + return &pb.DelShopPlayersResp{}, nil +} diff --git a/app/shop/rpc/internal/logic/delShopsLogic.go b/app/shop/rpc/internal/logic/delShopsLogic.go new file mode 100644 index 0000000..30c1b82 --- /dev/null +++ b/app/shop/rpc/internal/logic/delShopsLogic.go @@ -0,0 +1,35 @@ +package logic + +import ( + "context" + "errors" + + "juwan-backend/app/shop/rpc/internal/svc" + "juwan-backend/app/shop/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type DelShopsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewDelShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelShopsLogic { + return &DelShopsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *DelShopsLogic) DelShops(in *pb.DelShopsReq) (*pb.DelShopsResp, error) { + err := l.svcCtx.ShopModelRO.Shops.DeleteOneID(in.Id).Exec(l.ctx) + if err != nil { + logx.Errorf("delete shop failed, %s", err.Error()) + return nil, errors.New("delete failed") + } + + return &pb.DelShopsResp{}, nil +} diff --git a/app/shop/rpc/internal/logic/getShopInvitationsByIdLogic.go b/app/shop/rpc/internal/logic/getShopInvitationsByIdLogic.go new file mode 100644 index 0000000..b63eba4 --- /dev/null +++ b/app/shop/rpc/internal/logic/getShopInvitationsByIdLogic.go @@ -0,0 +1,50 @@ +package logic + +import ( + "context" + "errors" + "juwan-backend/app/shop/rpc/internal/models/shopinvitations" + + //"juwan-backend/app/game/rpc/internal/models/shopinvitations" + + "juwan-backend/app/shop/rpc/internal/svc" + "juwan-backend/app/shop/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetShopInvitationsByIdLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewGetShopInvitationsByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetShopInvitationsByIdLogic { + return &GetShopInvitationsByIdLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *GetShopInvitationsByIdLogic) GetShopInvitationsById(in *pb.GetShopInvitationsByIdReq) (*pb.GetShopInvitationsByIdResp, error) { + shopInvitation, err := l.svcCtx.ShopModelRO.ShopInvitations.Query().Where(shopinvitations.IDEQ(in.Id)).First(l.ctx) + if err != nil { + logx.WithContext(l.ctx).Errorf("GetShopInvitationsByIdLogic err: %v", err) + return nil, errors.New("get shop invitations by id failed") + } + + pbShopInvitation := pb.ShopInvitations{ + Id: shopInvitation.ID, + ShopId: shopInvitation.ShopID, + PlayerId: shopInvitation.PlayerID, + Status: shopInvitation.Status, + InvitedBy: shopInvitation.InvitedBy, + CreatedAt: shopInvitation.CreatedAt.Unix(), + } + if shopInvitation.RespondedAt != nil { + pbShopInvitation.RespondedAt = shopInvitation.RespondedAt.Unix() + } + + return &pb.GetShopInvitationsByIdResp{ShopInvitations: &pbShopInvitation}, nil +} diff --git a/app/shop/rpc/internal/logic/getShopPlayersByIdLogic.go b/app/shop/rpc/internal/logic/getShopPlayersByIdLogic.go new file mode 100644 index 0000000..b2e2ec6 --- /dev/null +++ b/app/shop/rpc/internal/logic/getShopPlayersByIdLogic.go @@ -0,0 +1,46 @@ +package logic + +import ( + "context" + "errors" + "juwan-backend/app/shop/rpc/internal/models/shopplayers" + + "juwan-backend/app/shop/rpc/internal/svc" + "juwan-backend/app/shop/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetShopPlayersByIdLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewGetShopPlayersByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetShopPlayersByIdLogic { + return &GetShopPlayersByIdLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *GetShopPlayersByIdLogic) GetShopPlayersById(in *pb.GetShopPlayersByIdReq) (*pb.GetShopPlayersByIdResp, error) { + shopPlayer, err := l.svcCtx.ShopModelRO.ShopPlayers.Query().Where(shopplayers.IDEQ(in.Id)).First(l.ctx) + if err != nil { + logx.WithContext(l.ctx).Errorf("GetShopPlayersByIdLogic err: %v", err) + return nil, errors.New("get shop players by id failed") + } + + pbShopPlayer := pb.ShopPlayers{ + ShopId: shopPlayer.ShopID, + PlayerId: shopPlayer.PlayerID, + IsPrimary: shopPlayer.IsPrimary, + JoinedAt: shopPlayer.JoinedAt.Unix(), + } + if shopPlayer.LeftAt != nil { + pbShopPlayer.LeftAt = shopPlayer.LeftAt.Unix() + } + + return &pb.GetShopPlayersByIdResp{ShopPlayers: &pbShopPlayer}, nil +} diff --git a/app/shop/rpc/internal/logic/getShopsByIdLogic.go b/app/shop/rpc/internal/logic/getShopsByIdLogic.go new file mode 100644 index 0000000..a6d8c4e --- /dev/null +++ b/app/shop/rpc/internal/logic/getShopsByIdLogic.go @@ -0,0 +1,67 @@ +package logic + +import ( + "context" + "encoding/json" + "errors" + "juwan-backend/app/shop/rpc/internal/models/shops" + + "juwan-backend/app/shop/rpc/internal/svc" + "juwan-backend/app/shop/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetShopsByIdLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewGetShopsByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetShopsByIdLogic { + return &GetShopsByIdLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *GetShopsByIdLogic) GetShopsById(in *pb.GetShopsByIdReq) (*pb.GetShopsByIdResp, error) { + shop, err := l.svcCtx.ShopModelRO.Shops.Query().Where(shops.IDEQ(in.Id)).First(l.ctx) + if err != nil { + logx.WithContext(l.ctx).Errorf("GetShopsByIdLogic err: %v", err) + return nil, errors.New("get shops by id failed") + } + + templateConfigBytes, err := json.Marshal(shop.TemplateConfig) + if err != nil { + logx.WithContext(l.ctx).Errorf("GetShopsByIdLogic marshal template config err: %v", err) + return nil, errors.New("get shops by id failed") + } + + pbShop := pb.Shops{ + Id: shop.ID, + OwnerId: shop.OwnerID, + Name: shop.Name, + Rating: shop.Rating.InexactFloat64(), + TotalOrders: int64(shop.TotalOrders), + PlayerCount: int64(shop.PlayerCount), + CommissionType: shop.CommissionType, + CommissionValue: shop.CommissionValue.InexactFloat64(), + AllowMultiShop: shop.AllowMultiShop, + AllowIndependentOrders: shop.AllowIndependentOrders, + DispatchMode: shop.DispatchMode, + Announcements: shop.Announcements, + TemplateConfig: string(templateConfigBytes), + CreatedAt: shop.CreatedAt.Unix(), + UpdatedAt: shop.UpdatedAt.Unix(), + } + if shop.Banner != nil { + pbShop.Banner = *shop.Banner + } + if shop.Description != nil { + pbShop.Description = *shop.Description + } + + return &pb.GetShopsByIdResp{Shops: &pbShop}, nil +} diff --git a/app/shop/rpc/internal/logic/searchShopInvitationsLogic.go b/app/shop/rpc/internal/logic/searchShopInvitationsLogic.go new file mode 100644 index 0000000..ce9d14a --- /dev/null +++ b/app/shop/rpc/internal/logic/searchShopInvitationsLogic.go @@ -0,0 +1,28 @@ +package logic + +import ( + "context" + "juwan-backend/app/shop/rpc/internal/svc" + "juwan-backend/app/shop/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type SearchShopInvitationsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewSearchShopInvitationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchShopInvitationsLogic { + return &SearchShopInvitationsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *SearchShopInvitationsLogic) SearchShopInvitations(in *pb.SearchShopInvitationsReq) (*pb.SearchShopInvitationsResp, error) { + // TODO: implement search logic based on the provided criteria in the request + return &pb.SearchShopInvitationsResp{}, nil +} diff --git a/app/shop/rpc/internal/logic/searchShopPlayersLogic.go b/app/shop/rpc/internal/logic/searchShopPlayersLogic.go new file mode 100644 index 0000000..59029df --- /dev/null +++ b/app/shop/rpc/internal/logic/searchShopPlayersLogic.go @@ -0,0 +1,26 @@ +package logic + +import ( + "context" + "juwan-backend/app/shop/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type SearchShopPlayersLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewSearchShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchShopPlayersLogic { + return &SearchShopPlayersLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *SearchShopPlayersLogic) SearchShopPlayers(in *pb.SearchShopPlayersReq) (*pb.SearchShopPlayersResp, error) { + +} diff --git a/app/shop/rpc/internal/logic/searchShopsLogic.go b/app/shop/rpc/internal/logic/searchShopsLogic.go new file mode 100644 index 0000000..f968368 --- /dev/null +++ b/app/shop/rpc/internal/logic/searchShopsLogic.go @@ -0,0 +1,27 @@ +package logic + +import ( + "context" + "juwan-backend/app/shop/rpc/internal/svc" + "juwan-backend/app/shop/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type SearchShopsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewSearchShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchShopsLogic { + return &SearchShopsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *SearchShopsLogic) SearchShops(in *pb.SearchShopsReq) (*pb.SearchShopsResp, error) { + +} diff --git a/app/shop/rpc/internal/logic/updateShopInvitationsLogic.go b/app/shop/rpc/internal/logic/updateShopInvitationsLogic.go new file mode 100644 index 0000000..9b9360c --- /dev/null +++ b/app/shop/rpc/internal/logic/updateShopInvitationsLogic.go @@ -0,0 +1,30 @@ +package logic + +import ( + "context" + "errors" + "time" + + "juwan-backend/app/shop/rpc/internal/svc" + "juwan-backend/app/shop/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type UpdateShopInvitationsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewUpdateShopInvitationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateShopInvitationsLogic { + return &UpdateShopInvitationsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *UpdateShopInvitationsLogic) UpdateShopInvitations(in *pb.UpdateShopInvitationsReq) (*pb.UpdateShopInvitationsResp, error) { + +} diff --git a/app/shop/rpc/internal/logic/updateShopPlayersLogic.go b/app/shop/rpc/internal/logic/updateShopPlayersLogic.go new file mode 100644 index 0000000..08a1642 --- /dev/null +++ b/app/shop/rpc/internal/logic/updateShopPlayersLogic.go @@ -0,0 +1,32 @@ +package logic + +import ( + "context" + "errors" + "juwan-backend/app/shop/rpc/internal/models" + "juwan-backend/app/shop/rpc/internal/models/shopplayers" + "time" + + "juwan-backend/app/shop/rpc/internal/svc" + "juwan-backend/app/shop/rpc/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +type UpdateShopPlayersLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewUpdateShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateShopPlayersLogic { + return &UpdateShopPlayersLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *UpdateShopPlayersLogic) UpdateShopPlayers(in *pb.UpdateShopPlayersReq) (*pb.UpdateShopPlayersResp, error) { + +} diff --git a/app/shop/rpc/internal/logic/updateShopsLogic.go b/app/shop/rpc/internal/logic/updateShopsLogic.go new file mode 100644 index 0000000..698ccdc --- /dev/null +++ b/app/shop/rpc/internal/logic/updateShopsLogic.go @@ -0,0 +1,32 @@ +package logic + +import ( + "context" + "encoding/json" + "errors" + "time" + + "juwan-backend/app/shop/rpc/internal/svc" + "juwan-backend/app/shop/rpc/pb" + + "github.com/shopspring/decimal" + "github.com/zeromicro/go-zero/core/logx" +) + +type UpdateShopsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewUpdateShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateShopsLogic { + return &UpdateShopsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *UpdateShopsLogic) UpdateShops(in *pb.UpdateShopsReq) (*pb.UpdateShopsResp, error) { + +} diff --git a/app/shop/rpc/internal/models/client.go b/app/shop/rpc/internal/models/client.go new file mode 100644 index 0000000..2c365ab --- /dev/null +++ b/app/shop/rpc/internal/models/client.go @@ -0,0 +1,627 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "errors" + "fmt" + "log" + "reflect" + + "juwan-backend/app/shop/rpc/internal/models/migrate" + + "juwan-backend/app/shop/rpc/internal/models/shopinvitations" + "juwan-backend/app/shop/rpc/internal/models/shopplayers" + "juwan-backend/app/shop/rpc/internal/models/shops" + + "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 + // ShopInvitations is the client for interacting with the ShopInvitations builders. + ShopInvitations *ShopInvitationsClient + // ShopPlayers is the client for interacting with the ShopPlayers builders. + ShopPlayers *ShopPlayersClient + // Shops is the client for interacting with the Shops builders. + Shops *ShopsClient +} + +// 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.ShopInvitations = NewShopInvitationsClient(c.config) + c.ShopPlayers = NewShopPlayersClient(c.config) + c.Shops = NewShopsClient(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, + ShopInvitations: NewShopInvitationsClient(cfg), + ShopPlayers: NewShopPlayersClient(cfg), + Shops: NewShopsClient(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, + ShopInvitations: NewShopInvitationsClient(cfg), + ShopPlayers: NewShopPlayersClient(cfg), + Shops: NewShopsClient(cfg), + }, nil +} + +// Debug returns a new debug-client. It's used to get verbose logging on specific operations. +// +// client.Debug(). +// ShopInvitations. +// 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.ShopInvitations.Use(hooks...) + c.ShopPlayers.Use(hooks...) + c.Shops.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.ShopInvitations.Intercept(interceptors...) + c.ShopPlayers.Intercept(interceptors...) + c.Shops.Intercept(interceptors...) +} + +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *ShopInvitationsMutation: + return c.ShopInvitations.mutate(ctx, m) + case *ShopPlayersMutation: + return c.ShopPlayers.mutate(ctx, m) + case *ShopsMutation: + return c.Shops.mutate(ctx, m) + default: + return nil, fmt.Errorf("models: unknown mutation type %T", m) + } +} + +// ShopInvitationsClient is a client for the ShopInvitations schema. +type ShopInvitationsClient struct { + config +} + +// NewShopInvitationsClient returns a client for the ShopInvitations from the given config. +func NewShopInvitationsClient(c config) *ShopInvitationsClient { + return &ShopInvitationsClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `shopinvitations.Hooks(f(g(h())))`. +func (c *ShopInvitationsClient) Use(hooks ...Hook) { + c.hooks.ShopInvitations = append(c.hooks.ShopInvitations, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `shopinvitations.Intercept(f(g(h())))`. +func (c *ShopInvitationsClient) Intercept(interceptors ...Interceptor) { + c.inters.ShopInvitations = append(c.inters.ShopInvitations, interceptors...) +} + +// Create returns a builder for creating a ShopInvitations entity. +func (c *ShopInvitationsClient) Create() *ShopInvitationsCreate { + mutation := newShopInvitationsMutation(c.config, OpCreate) + return &ShopInvitationsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of ShopInvitations entities. +func (c *ShopInvitationsClient) CreateBulk(builders ...*ShopInvitationsCreate) *ShopInvitationsCreateBulk { + return &ShopInvitationsCreateBulk{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 *ShopInvitationsClient) MapCreateBulk(slice any, setFunc func(*ShopInvitationsCreate, int)) *ShopInvitationsCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &ShopInvitationsCreateBulk{err: fmt.Errorf("calling to ShopInvitationsClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*ShopInvitationsCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &ShopInvitationsCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for ShopInvitations. +func (c *ShopInvitationsClient) Update() *ShopInvitationsUpdate { + mutation := newShopInvitationsMutation(c.config, OpUpdate) + return &ShopInvitationsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *ShopInvitationsClient) UpdateOne(_m *ShopInvitations) *ShopInvitationsUpdateOne { + mutation := newShopInvitationsMutation(c.config, OpUpdateOne, withShopInvitations(_m)) + return &ShopInvitationsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *ShopInvitationsClient) UpdateOneID(id int64) *ShopInvitationsUpdateOne { + mutation := newShopInvitationsMutation(c.config, OpUpdateOne, withShopInvitationsID(id)) + return &ShopInvitationsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for ShopInvitations. +func (c *ShopInvitationsClient) Delete() *ShopInvitationsDelete { + mutation := newShopInvitationsMutation(c.config, OpDelete) + return &ShopInvitationsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *ShopInvitationsClient) DeleteOne(_m *ShopInvitations) *ShopInvitationsDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *ShopInvitationsClient) DeleteOneID(id int64) *ShopInvitationsDeleteOne { + builder := c.Delete().Where(shopinvitations.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &ShopInvitationsDeleteOne{builder} +} + +// Query returns a query builder for ShopInvitations. +func (c *ShopInvitationsClient) Query() *ShopInvitationsQuery { + return &ShopInvitationsQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeShopInvitations}, + inters: c.Interceptors(), + } +} + +// Get returns a ShopInvitations entity by its id. +func (c *ShopInvitationsClient) Get(ctx context.Context, id int64) (*ShopInvitations, error) { + return c.Query().Where(shopinvitations.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *ShopInvitationsClient) GetX(ctx context.Context, id int64) *ShopInvitations { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *ShopInvitationsClient) Hooks() []Hook { + return c.hooks.ShopInvitations +} + +// Interceptors returns the client interceptors. +func (c *ShopInvitationsClient) Interceptors() []Interceptor { + return c.inters.ShopInvitations +} + +func (c *ShopInvitationsClient) mutate(ctx context.Context, m *ShopInvitationsMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ShopInvitationsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ShopInvitationsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ShopInvitationsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ShopInvitationsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("models: unknown ShopInvitations mutation op: %q", m.Op()) + } +} + +// ShopPlayersClient is a client for the ShopPlayers schema. +type ShopPlayersClient struct { + config +} + +// NewShopPlayersClient returns a client for the ShopPlayers from the given config. +func NewShopPlayersClient(c config) *ShopPlayersClient { + return &ShopPlayersClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `shopplayers.Hooks(f(g(h())))`. +func (c *ShopPlayersClient) Use(hooks ...Hook) { + c.hooks.ShopPlayers = append(c.hooks.ShopPlayers, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `shopplayers.Intercept(f(g(h())))`. +func (c *ShopPlayersClient) Intercept(interceptors ...Interceptor) { + c.inters.ShopPlayers = append(c.inters.ShopPlayers, interceptors...) +} + +// Create returns a builder for creating a ShopPlayers entity. +func (c *ShopPlayersClient) Create() *ShopPlayersCreate { + mutation := newShopPlayersMutation(c.config, OpCreate) + return &ShopPlayersCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of ShopPlayers entities. +func (c *ShopPlayersClient) CreateBulk(builders ...*ShopPlayersCreate) *ShopPlayersCreateBulk { + return &ShopPlayersCreateBulk{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 *ShopPlayersClient) MapCreateBulk(slice any, setFunc func(*ShopPlayersCreate, int)) *ShopPlayersCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &ShopPlayersCreateBulk{err: fmt.Errorf("calling to ShopPlayersClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*ShopPlayersCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &ShopPlayersCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for ShopPlayers. +func (c *ShopPlayersClient) Update() *ShopPlayersUpdate { + mutation := newShopPlayersMutation(c.config, OpUpdate) + return &ShopPlayersUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *ShopPlayersClient) UpdateOne(_m *ShopPlayers) *ShopPlayersUpdateOne { + mutation := newShopPlayersMutation(c.config, OpUpdateOne, withShopPlayers(_m)) + return &ShopPlayersUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *ShopPlayersClient) UpdateOneID(id int64) *ShopPlayersUpdateOne { + mutation := newShopPlayersMutation(c.config, OpUpdateOne, withShopPlayersID(id)) + return &ShopPlayersUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for ShopPlayers. +func (c *ShopPlayersClient) Delete() *ShopPlayersDelete { + mutation := newShopPlayersMutation(c.config, OpDelete) + return &ShopPlayersDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *ShopPlayersClient) DeleteOne(_m *ShopPlayers) *ShopPlayersDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *ShopPlayersClient) DeleteOneID(id int64) *ShopPlayersDeleteOne { + builder := c.Delete().Where(shopplayers.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &ShopPlayersDeleteOne{builder} +} + +// Query returns a query builder for ShopPlayers. +func (c *ShopPlayersClient) Query() *ShopPlayersQuery { + return &ShopPlayersQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeShopPlayers}, + inters: c.Interceptors(), + } +} + +// Get returns a ShopPlayers entity by its id. +func (c *ShopPlayersClient) Get(ctx context.Context, id int64) (*ShopPlayers, error) { + return c.Query().Where(shopplayers.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *ShopPlayersClient) GetX(ctx context.Context, id int64) *ShopPlayers { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *ShopPlayersClient) Hooks() []Hook { + return c.hooks.ShopPlayers +} + +// Interceptors returns the client interceptors. +func (c *ShopPlayersClient) Interceptors() []Interceptor { + return c.inters.ShopPlayers +} + +func (c *ShopPlayersClient) mutate(ctx context.Context, m *ShopPlayersMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ShopPlayersCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ShopPlayersUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ShopPlayersUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ShopPlayersDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("models: unknown ShopPlayers mutation op: %q", m.Op()) + } +} + +// ShopsClient is a client for the Shops schema. +type ShopsClient struct { + config +} + +// NewShopsClient returns a client for the Shops from the given config. +func NewShopsClient(c config) *ShopsClient { + return &ShopsClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `shops.Hooks(f(g(h())))`. +func (c *ShopsClient) Use(hooks ...Hook) { + c.hooks.Shops = append(c.hooks.Shops, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `shops.Intercept(f(g(h())))`. +func (c *ShopsClient) Intercept(interceptors ...Interceptor) { + c.inters.Shops = append(c.inters.Shops, interceptors...) +} + +// Create returns a builder for creating a Shops entity. +func (c *ShopsClient) Create() *ShopsCreate { + mutation := newShopsMutation(c.config, OpCreate) + return &ShopsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Shops entities. +func (c *ShopsClient) CreateBulk(builders ...*ShopsCreate) *ShopsCreateBulk { + return &ShopsCreateBulk{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 *ShopsClient) MapCreateBulk(slice any, setFunc func(*ShopsCreate, int)) *ShopsCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &ShopsCreateBulk{err: fmt.Errorf("calling to ShopsClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*ShopsCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &ShopsCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Shops. +func (c *ShopsClient) Update() *ShopsUpdate { + mutation := newShopsMutation(c.config, OpUpdate) + return &ShopsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *ShopsClient) UpdateOne(_m *Shops) *ShopsUpdateOne { + mutation := newShopsMutation(c.config, OpUpdateOne, withShops(_m)) + return &ShopsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *ShopsClient) UpdateOneID(id int64) *ShopsUpdateOne { + mutation := newShopsMutation(c.config, OpUpdateOne, withShopsID(id)) + return &ShopsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Shops. +func (c *ShopsClient) Delete() *ShopsDelete { + mutation := newShopsMutation(c.config, OpDelete) + return &ShopsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *ShopsClient) DeleteOne(_m *Shops) *ShopsDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *ShopsClient) DeleteOneID(id int64) *ShopsDeleteOne { + builder := c.Delete().Where(shops.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &ShopsDeleteOne{builder} +} + +// Query returns a query builder for Shops. +func (c *ShopsClient) Query() *ShopsQuery { + return &ShopsQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeShops}, + inters: c.Interceptors(), + } +} + +// Get returns a Shops entity by its id. +func (c *ShopsClient) Get(ctx context.Context, id int64) (*Shops, error) { + return c.Query().Where(shops.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *ShopsClient) GetX(ctx context.Context, id int64) *Shops { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *ShopsClient) Hooks() []Hook { + return c.hooks.Shops +} + +// Interceptors returns the client interceptors. +func (c *ShopsClient) Interceptors() []Interceptor { + return c.inters.Shops +} + +func (c *ShopsClient) mutate(ctx context.Context, m *ShopsMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ShopsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ShopsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ShopsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ShopsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("models: unknown Shops mutation op: %q", m.Op()) + } +} + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + ShopInvitations, ShopPlayers, Shops []ent.Hook + } + inters struct { + ShopInvitations, ShopPlayers, Shops []ent.Interceptor + } +) diff --git a/app/shop/rpc/internal/models/ent.go b/app/shop/rpc/internal/models/ent.go new file mode 100644 index 0000000..ba90189 --- /dev/null +++ b/app/shop/rpc/internal/models/ent.go @@ -0,0 +1,612 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "errors" + "fmt" + "juwan-backend/app/shop/rpc/internal/models/shopinvitations" + "juwan-backend/app/shop/rpc/internal/models/shopplayers" + "juwan-backend/app/shop/rpc/internal/models/shops" + "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{ + shopinvitations.Table: shopinvitations.ValidColumn, + shopplayers.Table: shopplayers.ValidColumn, + shops.Table: shops.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) diff --git a/app/shop/rpc/internal/models/enttest/enttest.go b/app/shop/rpc/internal/models/enttest/enttest.go new file mode 100644 index 0000000..e64e74c --- /dev/null +++ b/app/shop/rpc/internal/models/enttest/enttest.go @@ -0,0 +1,85 @@ +// Code generated by ent, DO NOT EDIT. + +package enttest + +import ( + "context" + + "juwan-backend/app/shop/rpc/internal/models" + // required by schema hooks. + _ "juwan-backend/app/shop/rpc/internal/models/runtime" + + "juwan-backend/app/shop/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() + } +} diff --git a/app/shop/rpc/internal/models/hook/hook.go b/app/shop/rpc/internal/models/hook/hook.go new file mode 100644 index 0000000..527ceff --- /dev/null +++ b/app/shop/rpc/internal/models/hook/hook.go @@ -0,0 +1,222 @@ +// Code generated by ent, DO NOT EDIT. + +package hook + +import ( + "context" + "fmt" + "juwan-backend/app/shop/rpc/internal/models" +) + +// The ShopInvitationsFunc type is an adapter to allow the use of ordinary +// function as ShopInvitations mutator. +type ShopInvitationsFunc func(context.Context, *models.ShopInvitationsMutation) (models.Value, error) + +// Mutate calls f(ctx, m). +func (f ShopInvitationsFunc) Mutate(ctx context.Context, m models.Mutation) (models.Value, error) { + if mv, ok := m.(*models.ShopInvitationsMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *models.ShopInvitationsMutation", m) +} + +// The ShopPlayersFunc type is an adapter to allow the use of ordinary +// function as ShopPlayers mutator. +type ShopPlayersFunc func(context.Context, *models.ShopPlayersMutation) (models.Value, error) + +// Mutate calls f(ctx, m). +func (f ShopPlayersFunc) Mutate(ctx context.Context, m models.Mutation) (models.Value, error) { + if mv, ok := m.(*models.ShopPlayersMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *models.ShopPlayersMutation", m) +} + +// The ShopsFunc type is an adapter to allow the use of ordinary +// function as Shops mutator. +type ShopsFunc func(context.Context, *models.ShopsMutation) (models.Value, error) + +// Mutate calls f(ctx, m). +func (f ShopsFunc) Mutate(ctx context.Context, m models.Mutation) (models.Value, error) { + if mv, ok := m.(*models.ShopsMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *models.ShopsMutation", 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...) +} diff --git a/app/shop/rpc/internal/models/migrate/migrate.go b/app/shop/rpc/internal/models/migrate/migrate.go new file mode 100644 index 0000000..1956a6b --- /dev/null +++ b/app/shop/rpc/internal/models/migrate/migrate.go @@ -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...) +} diff --git a/app/shop/rpc/internal/models/migrate/schema.go b/app/shop/rpc/internal/models/migrate/schema.go new file mode 100644 index 0000000..687937b --- /dev/null +++ b/app/shop/rpc/internal/models/migrate/schema.go @@ -0,0 +1,131 @@ +// 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 ( + // ShopInvitationsColumns holds the columns for the "shop_invitations" table. + ShopInvitationsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt64, Increment: true}, + {Name: "shop_id", Type: field.TypeInt64}, + {Name: "player_id", Type: field.TypeInt64}, + {Name: "status", Type: field.TypeString, Size: 20, Default: "pending"}, + {Name: "invited_by", Type: field.TypeInt64}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "responded_at", Type: field.TypeTime, Nullable: true}, + } + // ShopInvitationsTable holds the schema information for the "shop_invitations" table. + ShopInvitationsTable = &schema.Table{ + Name: "shop_invitations", + Columns: ShopInvitationsColumns, + PrimaryKey: []*schema.Column{ShopInvitationsColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "shopinvitations_shop_id", + Unique: false, + Columns: []*schema.Column{ShopInvitationsColumns[1]}, + }, + { + Name: "shopinvitations_player_id", + Unique: false, + Columns: []*schema.Column{ShopInvitationsColumns[2]}, + }, + { + Name: "shopinvitations_player_id_status_created_at", + Unique: false, + Columns: []*schema.Column{ShopInvitationsColumns[2], ShopInvitationsColumns[3], ShopInvitationsColumns[5]}, + }, + { + Name: "shopinvitations_shop_id_status_created_at", + Unique: false, + Columns: []*schema.Column{ShopInvitationsColumns[1], ShopInvitationsColumns[3], ShopInvitationsColumns[5]}, + }, + }, + } + // ShopPlayersColumns holds the columns for the "shop_players" table. + ShopPlayersColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt64, Increment: true}, + {Name: "shop_id", Type: field.TypeInt64}, + {Name: "player_id", Type: field.TypeInt64}, + {Name: "is_primary", Type: field.TypeBool, Nullable: true, Default: false}, + {Name: "joined_at", Type: field.TypeTime}, + {Name: "left_at", Type: field.TypeTime, Nullable: true}, + } + // ShopPlayersTable holds the schema information for the "shop_players" table. + ShopPlayersTable = &schema.Table{ + Name: "shop_players", + Columns: ShopPlayersColumns, + PrimaryKey: []*schema.Column{ShopPlayersColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "shopplayers_shop_id_player_id", + Unique: true, + Columns: []*schema.Column{ShopPlayersColumns[1], ShopPlayersColumns[2]}, + }, + { + Name: "shopplayers_player_id", + Unique: false, + Columns: []*schema.Column{ShopPlayersColumns[2]}, + }, + { + Name: "shopplayers_shop_id_joined_at", + Unique: false, + Columns: []*schema.Column{ShopPlayersColumns[1], ShopPlayersColumns[4]}, + }, + }, + } + // ShopsColumns holds the columns for the "shops" table. + ShopsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt64, Increment: true}, + {Name: "owner_id", Type: field.TypeInt64, Unique: true}, + {Name: "name", Type: field.TypeString, Size: 200}, + {Name: "banner", Type: field.TypeString, Nullable: true}, + {Name: "description", Type: field.TypeString, Nullable: 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: "player_count", Type: field.TypeInt, Nullable: true, Default: 0}, + {Name: "commission_type", Type: field.TypeString, Size: 20, Default: "percentage"}, + {Name: "commission_value", Type: field.TypeOther, SchemaType: map[string]string{"postgres": "decimal(10,2)"}}, + {Name: "allow_multi_shop", Type: field.TypeBool, Nullable: true, Default: false}, + {Name: "allow_independent_orders", Type: field.TypeBool, Nullable: true, Default: true}, + {Name: "dispatch_mode", Type: field.TypeString, Size: 20, Default: "manual"}, + {Name: "announcements", Type: field.TypeJSON, Nullable: true}, + {Name: "template_config", Type: field.TypeJSON, Nullable: true}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + } + // ShopsTable holds the schema information for the "shops" table. + ShopsTable = &schema.Table{ + Name: "shops", + Columns: ShopsColumns, + PrimaryKey: []*schema.Column{ShopsColumns[0]}, + } + // Tables holds all the tables in the schema. + Tables = []*schema.Table{ + ShopInvitationsTable, + ShopPlayersTable, + ShopsTable, + } +) + +func init() { + ShopInvitationsTable.Annotation = &entsql.Annotation{ + Table: "shop_invitations", + } + ShopInvitationsTable.Annotation.Checks = map[string]string{ + "chk_invitation_status": "status IN ('pending', 'accepted', 'rejected', 'cancelled')", + } + ShopsTable.Annotation = &entsql.Annotation{ + Table: "shops", + } + ShopsTable.Annotation.Checks = map[string]string{ + "chk_commission_type": "commission_type IN ('fixed', 'percentage')", + "chk_dispatch_mode": "dispatch_mode IN ('manual', 'auto')", + "chk_rating_range": "rating >= 0 AND rating <= 5", + } +} diff --git a/app/shop/rpc/internal/models/mutation.go b/app/shop/rpc/internal/models/mutation.go new file mode 100644 index 0000000..68ebac4 --- /dev/null +++ b/app/shop/rpc/internal/models/mutation.go @@ -0,0 +1,2854 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "errors" + "fmt" + "juwan-backend/app/shop/rpc/internal/models/predicate" + "juwan-backend/app/shop/rpc/internal/models/shopinvitations" + "juwan-backend/app/shop/rpc/internal/models/shopplayers" + "juwan-backend/app/shop/rpc/internal/models/shops" + "sync" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/shopspring/decimal" +) + +const ( + // Operation types. + OpCreate = ent.OpCreate + OpDelete = ent.OpDelete + OpDeleteOne = ent.OpDeleteOne + OpUpdate = ent.OpUpdate + OpUpdateOne = ent.OpUpdateOne + + // Node types. + TypeShopInvitations = "ShopInvitations" + TypeShopPlayers = "ShopPlayers" + TypeShops = "Shops" +) + +// ShopInvitationsMutation represents an operation that mutates the ShopInvitations nodes in the graph. +type ShopInvitationsMutation struct { + config + op Op + typ string + id *int64 + shop_id *int64 + addshop_id *int64 + player_id *int64 + addplayer_id *int64 + status *string + invited_by *int64 + addinvited_by *int64 + created_at *time.Time + responded_at *time.Time + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*ShopInvitations, error) + predicates []predicate.ShopInvitations +} + +var _ ent.Mutation = (*ShopInvitationsMutation)(nil) + +// shopinvitationsOption allows management of the mutation configuration using functional options. +type shopinvitationsOption func(*ShopInvitationsMutation) + +// newShopInvitationsMutation creates new mutation for the ShopInvitations entity. +func newShopInvitationsMutation(c config, op Op, opts ...shopinvitationsOption) *ShopInvitationsMutation { + m := &ShopInvitationsMutation{ + config: c, + op: op, + typ: TypeShopInvitations, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withShopInvitationsID sets the ID field of the mutation. +func withShopInvitationsID(id int64) shopinvitationsOption { + return func(m *ShopInvitationsMutation) { + var ( + err error + once sync.Once + value *ShopInvitations + ) + m.oldValue = func(ctx context.Context) (*ShopInvitations, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().ShopInvitations.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withShopInvitations sets the old ShopInvitations of the mutation. +func withShopInvitations(node *ShopInvitations) shopinvitationsOption { + return func(m *ShopInvitationsMutation) { + m.oldValue = func(context.Context) (*ShopInvitations, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m ShopInvitationsMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m ShopInvitationsMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("models: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of ShopInvitations entities. +func (m *ShopInvitationsMutation) SetID(id int64) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *ShopInvitationsMutation) ID() (id int64, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *ShopInvitationsMutation) IDs(ctx context.Context) ([]int64, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int64{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().ShopInvitations.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetShopID sets the "shop_id" field. +func (m *ShopInvitationsMutation) SetShopID(i int64) { + m.shop_id = &i + m.addshop_id = nil +} + +// ShopID returns the value of the "shop_id" field in the mutation. +func (m *ShopInvitationsMutation) ShopID() (r int64, exists bool) { + v := m.shop_id + if v == nil { + return + } + return *v, true +} + +// OldShopID returns the old "shop_id" field's value of the ShopInvitations entity. +// If the ShopInvitations object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopInvitationsMutation) OldShopID(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldShopID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldShopID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldShopID: %w", err) + } + return oldValue.ShopID, nil +} + +// AddShopID adds i to the "shop_id" field. +func (m *ShopInvitationsMutation) AddShopID(i int64) { + if m.addshop_id != nil { + *m.addshop_id += i + } else { + m.addshop_id = &i + } +} + +// AddedShopID returns the value that was added to the "shop_id" field in this mutation. +func (m *ShopInvitationsMutation) AddedShopID() (r int64, exists bool) { + v := m.addshop_id + if v == nil { + return + } + return *v, true +} + +// ResetShopID resets all changes to the "shop_id" field. +func (m *ShopInvitationsMutation) ResetShopID() { + m.shop_id = nil + m.addshop_id = nil +} + +// SetPlayerID sets the "player_id" field. +func (m *ShopInvitationsMutation) SetPlayerID(i int64) { + m.player_id = &i + m.addplayer_id = nil +} + +// PlayerID returns the value of the "player_id" field in the mutation. +func (m *ShopInvitationsMutation) PlayerID() (r int64, exists bool) { + v := m.player_id + if v == nil { + return + } + return *v, true +} + +// OldPlayerID returns the old "player_id" field's value of the ShopInvitations entity. +// If the ShopInvitations object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopInvitationsMutation) OldPlayerID(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPlayerID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPlayerID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPlayerID: %w", err) + } + return oldValue.PlayerID, nil +} + +// AddPlayerID adds i to the "player_id" field. +func (m *ShopInvitationsMutation) AddPlayerID(i int64) { + if m.addplayer_id != nil { + *m.addplayer_id += i + } else { + m.addplayer_id = &i + } +} + +// AddedPlayerID returns the value that was added to the "player_id" field in this mutation. +func (m *ShopInvitationsMutation) AddedPlayerID() (r int64, exists bool) { + v := m.addplayer_id + if v == nil { + return + } + return *v, true +} + +// ResetPlayerID resets all changes to the "player_id" field. +func (m *ShopInvitationsMutation) ResetPlayerID() { + m.player_id = nil + m.addplayer_id = nil +} + +// SetStatus sets the "status" field. +func (m *ShopInvitationsMutation) SetStatus(s string) { + m.status = &s +} + +// Status returns the value of the "status" field in the mutation. +func (m *ShopInvitationsMutation) Status() (r string, exists bool) { + v := m.status + if v == nil { + return + } + return *v, true +} + +// OldStatus returns the old "status" field's value of the ShopInvitations entity. +// If the ShopInvitations object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopInvitationsMutation) OldStatus(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStatus is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStatus requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStatus: %w", err) + } + return oldValue.Status, nil +} + +// ResetStatus resets all changes to the "status" field. +func (m *ShopInvitationsMutation) ResetStatus() { + m.status = nil +} + +// SetInvitedBy sets the "invited_by" field. +func (m *ShopInvitationsMutation) SetInvitedBy(i int64) { + m.invited_by = &i + m.addinvited_by = nil +} + +// InvitedBy returns the value of the "invited_by" field in the mutation. +func (m *ShopInvitationsMutation) InvitedBy() (r int64, exists bool) { + v := m.invited_by + if v == nil { + return + } + return *v, true +} + +// OldInvitedBy returns the old "invited_by" field's value of the ShopInvitations entity. +// If the ShopInvitations object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopInvitationsMutation) OldInvitedBy(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldInvitedBy is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldInvitedBy requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldInvitedBy: %w", err) + } + return oldValue.InvitedBy, nil +} + +// AddInvitedBy adds i to the "invited_by" field. +func (m *ShopInvitationsMutation) AddInvitedBy(i int64) { + if m.addinvited_by != nil { + *m.addinvited_by += i + } else { + m.addinvited_by = &i + } +} + +// AddedInvitedBy returns the value that was added to the "invited_by" field in this mutation. +func (m *ShopInvitationsMutation) AddedInvitedBy() (r int64, exists bool) { + v := m.addinvited_by + if v == nil { + return + } + return *v, true +} + +// ResetInvitedBy resets all changes to the "invited_by" field. +func (m *ShopInvitationsMutation) ResetInvitedBy() { + m.invited_by = nil + m.addinvited_by = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *ShopInvitationsMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *ShopInvitationsMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the ShopInvitations entity. +// If the ShopInvitations object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopInvitationsMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *ShopInvitationsMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetRespondedAt sets the "responded_at" field. +func (m *ShopInvitationsMutation) SetRespondedAt(t time.Time) { + m.responded_at = &t +} + +// RespondedAt returns the value of the "responded_at" field in the mutation. +func (m *ShopInvitationsMutation) RespondedAt() (r time.Time, exists bool) { + v := m.responded_at + if v == nil { + return + } + return *v, true +} + +// OldRespondedAt returns the old "responded_at" field's value of the ShopInvitations entity. +// If the ShopInvitations object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopInvitationsMutation) OldRespondedAt(ctx context.Context) (v *time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRespondedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRespondedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRespondedAt: %w", err) + } + return oldValue.RespondedAt, nil +} + +// ClearRespondedAt clears the value of the "responded_at" field. +func (m *ShopInvitationsMutation) ClearRespondedAt() { + m.responded_at = nil + m.clearedFields[shopinvitations.FieldRespondedAt] = struct{}{} +} + +// RespondedAtCleared returns if the "responded_at" field was cleared in this mutation. +func (m *ShopInvitationsMutation) RespondedAtCleared() bool { + _, ok := m.clearedFields[shopinvitations.FieldRespondedAt] + return ok +} + +// ResetRespondedAt resets all changes to the "responded_at" field. +func (m *ShopInvitationsMutation) ResetRespondedAt() { + m.responded_at = nil + delete(m.clearedFields, shopinvitations.FieldRespondedAt) +} + +// Where appends a list predicates to the ShopInvitationsMutation builder. +func (m *ShopInvitationsMutation) Where(ps ...predicate.ShopInvitations) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the ShopInvitationsMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ShopInvitationsMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ShopInvitations, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *ShopInvitationsMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *ShopInvitationsMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (ShopInvitations). +func (m *ShopInvitationsMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *ShopInvitationsMutation) Fields() []string { + fields := make([]string, 0, 6) + if m.shop_id != nil { + fields = append(fields, shopinvitations.FieldShopID) + } + if m.player_id != nil { + fields = append(fields, shopinvitations.FieldPlayerID) + } + if m.status != nil { + fields = append(fields, shopinvitations.FieldStatus) + } + if m.invited_by != nil { + fields = append(fields, shopinvitations.FieldInvitedBy) + } + if m.created_at != nil { + fields = append(fields, shopinvitations.FieldCreatedAt) + } + if m.responded_at != nil { + fields = append(fields, shopinvitations.FieldRespondedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *ShopInvitationsMutation) Field(name string) (ent.Value, bool) { + switch name { + case shopinvitations.FieldShopID: + return m.ShopID() + case shopinvitations.FieldPlayerID: + return m.PlayerID() + case shopinvitations.FieldStatus: + return m.Status() + case shopinvitations.FieldInvitedBy: + return m.InvitedBy() + case shopinvitations.FieldCreatedAt: + return m.CreatedAt() + case shopinvitations.FieldRespondedAt: + return m.RespondedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *ShopInvitationsMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case shopinvitations.FieldShopID: + return m.OldShopID(ctx) + case shopinvitations.FieldPlayerID: + return m.OldPlayerID(ctx) + case shopinvitations.FieldStatus: + return m.OldStatus(ctx) + case shopinvitations.FieldInvitedBy: + return m.OldInvitedBy(ctx) + case shopinvitations.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case shopinvitations.FieldRespondedAt: + return m.OldRespondedAt(ctx) + } + return nil, fmt.Errorf("unknown ShopInvitations field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *ShopInvitationsMutation) SetField(name string, value ent.Value) error { + switch name { + case shopinvitations.FieldShopID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetShopID(v) + return nil + case shopinvitations.FieldPlayerID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPlayerID(v) + return nil + case shopinvitations.FieldStatus: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStatus(v) + return nil + case shopinvitations.FieldInvitedBy: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetInvitedBy(v) + return nil + case shopinvitations.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case shopinvitations.FieldRespondedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRespondedAt(v) + return nil + } + return fmt.Errorf("unknown ShopInvitations field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *ShopInvitationsMutation) AddedFields() []string { + var fields []string + if m.addshop_id != nil { + fields = append(fields, shopinvitations.FieldShopID) + } + if m.addplayer_id != nil { + fields = append(fields, shopinvitations.FieldPlayerID) + } + if m.addinvited_by != nil { + fields = append(fields, shopinvitations.FieldInvitedBy) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *ShopInvitationsMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case shopinvitations.FieldShopID: + return m.AddedShopID() + case shopinvitations.FieldPlayerID: + return m.AddedPlayerID() + case shopinvitations.FieldInvitedBy: + return m.AddedInvitedBy() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *ShopInvitationsMutation) AddField(name string, value ent.Value) error { + switch name { + case shopinvitations.FieldShopID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddShopID(v) + return nil + case shopinvitations.FieldPlayerID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddPlayerID(v) + return nil + case shopinvitations.FieldInvitedBy: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddInvitedBy(v) + return nil + } + return fmt.Errorf("unknown ShopInvitations numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *ShopInvitationsMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(shopinvitations.FieldRespondedAt) { + fields = append(fields, shopinvitations.FieldRespondedAt) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *ShopInvitationsMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *ShopInvitationsMutation) ClearField(name string) error { + switch name { + case shopinvitations.FieldRespondedAt: + m.ClearRespondedAt() + return nil + } + return fmt.Errorf("unknown ShopInvitations nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *ShopInvitationsMutation) ResetField(name string) error { + switch name { + case shopinvitations.FieldShopID: + m.ResetShopID() + return nil + case shopinvitations.FieldPlayerID: + m.ResetPlayerID() + return nil + case shopinvitations.FieldStatus: + m.ResetStatus() + return nil + case shopinvitations.FieldInvitedBy: + m.ResetInvitedBy() + return nil + case shopinvitations.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case shopinvitations.FieldRespondedAt: + m.ResetRespondedAt() + return nil + } + return fmt.Errorf("unknown ShopInvitations field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *ShopInvitationsMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *ShopInvitationsMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *ShopInvitationsMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *ShopInvitationsMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *ShopInvitationsMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *ShopInvitationsMutation) EdgeCleared(name string) bool { + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *ShopInvitationsMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown ShopInvitations unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *ShopInvitationsMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown ShopInvitations edge %s", name) +} + +// ShopPlayersMutation represents an operation that mutates the ShopPlayers nodes in the graph. +type ShopPlayersMutation struct { + config + op Op + typ string + id *int64 + shop_id *int64 + addshop_id *int64 + player_id *int64 + addplayer_id *int64 + is_primary *bool + joined_at *time.Time + left_at *time.Time + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*ShopPlayers, error) + predicates []predicate.ShopPlayers +} + +var _ ent.Mutation = (*ShopPlayersMutation)(nil) + +// shopplayersOption allows management of the mutation configuration using functional options. +type shopplayersOption func(*ShopPlayersMutation) + +// newShopPlayersMutation creates new mutation for the ShopPlayers entity. +func newShopPlayersMutation(c config, op Op, opts ...shopplayersOption) *ShopPlayersMutation { + m := &ShopPlayersMutation{ + config: c, + op: op, + typ: TypeShopPlayers, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withShopPlayersID sets the ID field of the mutation. +func withShopPlayersID(id int64) shopplayersOption { + return func(m *ShopPlayersMutation) { + var ( + err error + once sync.Once + value *ShopPlayers + ) + m.oldValue = func(ctx context.Context) (*ShopPlayers, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().ShopPlayers.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withShopPlayers sets the old ShopPlayers of the mutation. +func withShopPlayers(node *ShopPlayers) shopplayersOption { + return func(m *ShopPlayersMutation) { + m.oldValue = func(context.Context) (*ShopPlayers, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m ShopPlayersMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m ShopPlayersMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("models: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of ShopPlayers entities. +func (m *ShopPlayersMutation) SetID(id int64) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *ShopPlayersMutation) ID() (id int64, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *ShopPlayersMutation) IDs(ctx context.Context) ([]int64, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int64{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().ShopPlayers.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetShopID sets the "shop_id" field. +func (m *ShopPlayersMutation) SetShopID(i int64) { + m.shop_id = &i + m.addshop_id = nil +} + +// ShopID returns the value of the "shop_id" field in the mutation. +func (m *ShopPlayersMutation) ShopID() (r int64, exists bool) { + v := m.shop_id + if v == nil { + return + } + return *v, true +} + +// OldShopID returns the old "shop_id" field's value of the ShopPlayers entity. +// If the ShopPlayers object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopPlayersMutation) OldShopID(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldShopID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldShopID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldShopID: %w", err) + } + return oldValue.ShopID, nil +} + +// AddShopID adds i to the "shop_id" field. +func (m *ShopPlayersMutation) AddShopID(i int64) { + if m.addshop_id != nil { + *m.addshop_id += i + } else { + m.addshop_id = &i + } +} + +// AddedShopID returns the value that was added to the "shop_id" field in this mutation. +func (m *ShopPlayersMutation) AddedShopID() (r int64, exists bool) { + v := m.addshop_id + if v == nil { + return + } + return *v, true +} + +// ResetShopID resets all changes to the "shop_id" field. +func (m *ShopPlayersMutation) ResetShopID() { + m.shop_id = nil + m.addshop_id = nil +} + +// SetPlayerID sets the "player_id" field. +func (m *ShopPlayersMutation) SetPlayerID(i int64) { + m.player_id = &i + m.addplayer_id = nil +} + +// PlayerID returns the value of the "player_id" field in the mutation. +func (m *ShopPlayersMutation) PlayerID() (r int64, exists bool) { + v := m.player_id + if v == nil { + return + } + return *v, true +} + +// OldPlayerID returns the old "player_id" field's value of the ShopPlayers entity. +// If the ShopPlayers object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopPlayersMutation) OldPlayerID(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPlayerID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPlayerID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPlayerID: %w", err) + } + return oldValue.PlayerID, nil +} + +// AddPlayerID adds i to the "player_id" field. +func (m *ShopPlayersMutation) AddPlayerID(i int64) { + if m.addplayer_id != nil { + *m.addplayer_id += i + } else { + m.addplayer_id = &i + } +} + +// AddedPlayerID returns the value that was added to the "player_id" field in this mutation. +func (m *ShopPlayersMutation) AddedPlayerID() (r int64, exists bool) { + v := m.addplayer_id + if v == nil { + return + } + return *v, true +} + +// ResetPlayerID resets all changes to the "player_id" field. +func (m *ShopPlayersMutation) ResetPlayerID() { + m.player_id = nil + m.addplayer_id = nil +} + +// SetIsPrimary sets the "is_primary" field. +func (m *ShopPlayersMutation) SetIsPrimary(b bool) { + m.is_primary = &b +} + +// IsPrimary returns the value of the "is_primary" field in the mutation. +func (m *ShopPlayersMutation) IsPrimary() (r bool, exists bool) { + v := m.is_primary + if v == nil { + return + } + return *v, true +} + +// OldIsPrimary returns the old "is_primary" field's value of the ShopPlayers entity. +// If the ShopPlayers object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopPlayersMutation) OldIsPrimary(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldIsPrimary is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldIsPrimary requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIsPrimary: %w", err) + } + return oldValue.IsPrimary, nil +} + +// ClearIsPrimary clears the value of the "is_primary" field. +func (m *ShopPlayersMutation) ClearIsPrimary() { + m.is_primary = nil + m.clearedFields[shopplayers.FieldIsPrimary] = struct{}{} +} + +// IsPrimaryCleared returns if the "is_primary" field was cleared in this mutation. +func (m *ShopPlayersMutation) IsPrimaryCleared() bool { + _, ok := m.clearedFields[shopplayers.FieldIsPrimary] + return ok +} + +// ResetIsPrimary resets all changes to the "is_primary" field. +func (m *ShopPlayersMutation) ResetIsPrimary() { + m.is_primary = nil + delete(m.clearedFields, shopplayers.FieldIsPrimary) +} + +// SetJoinedAt sets the "joined_at" field. +func (m *ShopPlayersMutation) SetJoinedAt(t time.Time) { + m.joined_at = &t +} + +// JoinedAt returns the value of the "joined_at" field in the mutation. +func (m *ShopPlayersMutation) JoinedAt() (r time.Time, exists bool) { + v := m.joined_at + if v == nil { + return + } + return *v, true +} + +// OldJoinedAt returns the old "joined_at" field's value of the ShopPlayers entity. +// If the ShopPlayers object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopPlayersMutation) OldJoinedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldJoinedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldJoinedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldJoinedAt: %w", err) + } + return oldValue.JoinedAt, nil +} + +// ResetJoinedAt resets all changes to the "joined_at" field. +func (m *ShopPlayersMutation) ResetJoinedAt() { + m.joined_at = nil +} + +// SetLeftAt sets the "left_at" field. +func (m *ShopPlayersMutation) SetLeftAt(t time.Time) { + m.left_at = &t +} + +// LeftAt returns the value of the "left_at" field in the mutation. +func (m *ShopPlayersMutation) LeftAt() (r time.Time, exists bool) { + v := m.left_at + if v == nil { + return + } + return *v, true +} + +// OldLeftAt returns the old "left_at" field's value of the ShopPlayers entity. +// If the ShopPlayers object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopPlayersMutation) OldLeftAt(ctx context.Context) (v *time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldLeftAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldLeftAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldLeftAt: %w", err) + } + return oldValue.LeftAt, nil +} + +// ClearLeftAt clears the value of the "left_at" field. +func (m *ShopPlayersMutation) ClearLeftAt() { + m.left_at = nil + m.clearedFields[shopplayers.FieldLeftAt] = struct{}{} +} + +// LeftAtCleared returns if the "left_at" field was cleared in this mutation. +func (m *ShopPlayersMutation) LeftAtCleared() bool { + _, ok := m.clearedFields[shopplayers.FieldLeftAt] + return ok +} + +// ResetLeftAt resets all changes to the "left_at" field. +func (m *ShopPlayersMutation) ResetLeftAt() { + m.left_at = nil + delete(m.clearedFields, shopplayers.FieldLeftAt) +} + +// Where appends a list predicates to the ShopPlayersMutation builder. +func (m *ShopPlayersMutation) Where(ps ...predicate.ShopPlayers) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the ShopPlayersMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ShopPlayersMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ShopPlayers, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *ShopPlayersMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *ShopPlayersMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (ShopPlayers). +func (m *ShopPlayersMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *ShopPlayersMutation) Fields() []string { + fields := make([]string, 0, 5) + if m.shop_id != nil { + fields = append(fields, shopplayers.FieldShopID) + } + if m.player_id != nil { + fields = append(fields, shopplayers.FieldPlayerID) + } + if m.is_primary != nil { + fields = append(fields, shopplayers.FieldIsPrimary) + } + if m.joined_at != nil { + fields = append(fields, shopplayers.FieldJoinedAt) + } + if m.left_at != nil { + fields = append(fields, shopplayers.FieldLeftAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *ShopPlayersMutation) Field(name string) (ent.Value, bool) { + switch name { + case shopplayers.FieldShopID: + return m.ShopID() + case shopplayers.FieldPlayerID: + return m.PlayerID() + case shopplayers.FieldIsPrimary: + return m.IsPrimary() + case shopplayers.FieldJoinedAt: + return m.JoinedAt() + case shopplayers.FieldLeftAt: + return m.LeftAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *ShopPlayersMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case shopplayers.FieldShopID: + return m.OldShopID(ctx) + case shopplayers.FieldPlayerID: + return m.OldPlayerID(ctx) + case shopplayers.FieldIsPrimary: + return m.OldIsPrimary(ctx) + case shopplayers.FieldJoinedAt: + return m.OldJoinedAt(ctx) + case shopplayers.FieldLeftAt: + return m.OldLeftAt(ctx) + } + return nil, fmt.Errorf("unknown ShopPlayers field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *ShopPlayersMutation) SetField(name string, value ent.Value) error { + switch name { + case shopplayers.FieldShopID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetShopID(v) + return nil + case shopplayers.FieldPlayerID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPlayerID(v) + return nil + case shopplayers.FieldIsPrimary: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetIsPrimary(v) + return nil + case shopplayers.FieldJoinedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetJoinedAt(v) + return nil + case shopplayers.FieldLeftAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetLeftAt(v) + return nil + } + return fmt.Errorf("unknown ShopPlayers field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *ShopPlayersMutation) AddedFields() []string { + var fields []string + if m.addshop_id != nil { + fields = append(fields, shopplayers.FieldShopID) + } + if m.addplayer_id != nil { + fields = append(fields, shopplayers.FieldPlayerID) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *ShopPlayersMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case shopplayers.FieldShopID: + return m.AddedShopID() + case shopplayers.FieldPlayerID: + return m.AddedPlayerID() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *ShopPlayersMutation) AddField(name string, value ent.Value) error { + switch name { + case shopplayers.FieldShopID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddShopID(v) + return nil + case shopplayers.FieldPlayerID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddPlayerID(v) + return nil + } + return fmt.Errorf("unknown ShopPlayers numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *ShopPlayersMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(shopplayers.FieldIsPrimary) { + fields = append(fields, shopplayers.FieldIsPrimary) + } + if m.FieldCleared(shopplayers.FieldLeftAt) { + fields = append(fields, shopplayers.FieldLeftAt) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *ShopPlayersMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *ShopPlayersMutation) ClearField(name string) error { + switch name { + case shopplayers.FieldIsPrimary: + m.ClearIsPrimary() + return nil + case shopplayers.FieldLeftAt: + m.ClearLeftAt() + return nil + } + return fmt.Errorf("unknown ShopPlayers nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *ShopPlayersMutation) ResetField(name string) error { + switch name { + case shopplayers.FieldShopID: + m.ResetShopID() + return nil + case shopplayers.FieldPlayerID: + m.ResetPlayerID() + return nil + case shopplayers.FieldIsPrimary: + m.ResetIsPrimary() + return nil + case shopplayers.FieldJoinedAt: + m.ResetJoinedAt() + return nil + case shopplayers.FieldLeftAt: + m.ResetLeftAt() + return nil + } + return fmt.Errorf("unknown ShopPlayers field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *ShopPlayersMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *ShopPlayersMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *ShopPlayersMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *ShopPlayersMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *ShopPlayersMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *ShopPlayersMutation) EdgeCleared(name string) bool { + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *ShopPlayersMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown ShopPlayers unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *ShopPlayersMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown ShopPlayers edge %s", name) +} + +// ShopsMutation represents an operation that mutates the Shops nodes in the graph. +type ShopsMutation struct { + config + op Op + typ string + id *int64 + owner_id *int64 + addowner_id *int64 + name *string + banner *string + description *string + rating *decimal.Decimal + total_orders *int + addtotal_orders *int + player_count *int + addplayer_count *int + commission_type *string + commission_value *decimal.Decimal + allow_multi_shop *bool + allow_independent_orders *bool + dispatch_mode *string + announcements *[]string + appendannouncements []string + template_config *map[string]interface{} + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*Shops, error) + predicates []predicate.Shops +} + +var _ ent.Mutation = (*ShopsMutation)(nil) + +// shopsOption allows management of the mutation configuration using functional options. +type shopsOption func(*ShopsMutation) + +// newShopsMutation creates new mutation for the Shops entity. +func newShopsMutation(c config, op Op, opts ...shopsOption) *ShopsMutation { + m := &ShopsMutation{ + config: c, + op: op, + typ: TypeShops, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withShopsID sets the ID field of the mutation. +func withShopsID(id int64) shopsOption { + return func(m *ShopsMutation) { + var ( + err error + once sync.Once + value *Shops + ) + m.oldValue = func(ctx context.Context) (*Shops, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Shops.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withShops sets the old Shops of the mutation. +func withShops(node *Shops) shopsOption { + return func(m *ShopsMutation) { + m.oldValue = func(context.Context) (*Shops, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m ShopsMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m ShopsMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("models: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of Shops entities. +func (m *ShopsMutation) SetID(id int64) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *ShopsMutation) ID() (id int64, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *ShopsMutation) IDs(ctx context.Context) ([]int64, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int64{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Shops.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetOwnerID sets the "owner_id" field. +func (m *ShopsMutation) SetOwnerID(i int64) { + m.owner_id = &i + m.addowner_id = nil +} + +// OwnerID returns the value of the "owner_id" field in the mutation. +func (m *ShopsMutation) OwnerID() (r int64, exists bool) { + v := m.owner_id + if v == nil { + return + } + return *v, true +} + +// OldOwnerID returns the old "owner_id" field's value of the Shops entity. +// If the Shops object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopsMutation) OldOwnerID(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldOwnerID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldOwnerID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldOwnerID: %w", err) + } + return oldValue.OwnerID, nil +} + +// AddOwnerID adds i to the "owner_id" field. +func (m *ShopsMutation) AddOwnerID(i int64) { + if m.addowner_id != nil { + *m.addowner_id += i + } else { + m.addowner_id = &i + } +} + +// AddedOwnerID returns the value that was added to the "owner_id" field in this mutation. +func (m *ShopsMutation) AddedOwnerID() (r int64, exists bool) { + v := m.addowner_id + if v == nil { + return + } + return *v, true +} + +// ResetOwnerID resets all changes to the "owner_id" field. +func (m *ShopsMutation) ResetOwnerID() { + m.owner_id = nil + m.addowner_id = nil +} + +// SetName sets the "name" field. +func (m *ShopsMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *ShopsMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" field's value of the Shops entity. +// If the Shops object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopsMutation) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ResetName resets all changes to the "name" field. +func (m *ShopsMutation) ResetName() { + m.name = nil +} + +// SetBanner sets the "banner" field. +func (m *ShopsMutation) SetBanner(s string) { + m.banner = &s +} + +// Banner returns the value of the "banner" field in the mutation. +func (m *ShopsMutation) Banner() (r string, exists bool) { + v := m.banner + if v == nil { + return + } + return *v, true +} + +// OldBanner returns the old "banner" field's value of the Shops entity. +// If the Shops object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopsMutation) OldBanner(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldBanner is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldBanner requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldBanner: %w", err) + } + return oldValue.Banner, nil +} + +// ClearBanner clears the value of the "banner" field. +func (m *ShopsMutation) ClearBanner() { + m.banner = nil + m.clearedFields[shops.FieldBanner] = struct{}{} +} + +// BannerCleared returns if the "banner" field was cleared in this mutation. +func (m *ShopsMutation) BannerCleared() bool { + _, ok := m.clearedFields[shops.FieldBanner] + return ok +} + +// ResetBanner resets all changes to the "banner" field. +func (m *ShopsMutation) ResetBanner() { + m.banner = nil + delete(m.clearedFields, shops.FieldBanner) +} + +// SetDescription sets the "description" field. +func (m *ShopsMutation) SetDescription(s string) { + m.description = &s +} + +// Description returns the value of the "description" field in the mutation. +func (m *ShopsMutation) Description() (r string, exists bool) { + v := m.description + if v == nil { + return + } + return *v, true +} + +// OldDescription returns the old "description" field's value of the Shops entity. +// If the Shops object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopsMutation) OldDescription(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDescription is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDescription requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDescription: %w", err) + } + return oldValue.Description, nil +} + +// ClearDescription clears the value of the "description" field. +func (m *ShopsMutation) ClearDescription() { + m.description = nil + m.clearedFields[shops.FieldDescription] = struct{}{} +} + +// DescriptionCleared returns if the "description" field was cleared in this mutation. +func (m *ShopsMutation) DescriptionCleared() bool { + _, ok := m.clearedFields[shops.FieldDescription] + return ok +} + +// ResetDescription resets all changes to the "description" field. +func (m *ShopsMutation) ResetDescription() { + m.description = nil + delete(m.clearedFields, shops.FieldDescription) +} + +// SetRating sets the "rating" field. +func (m *ShopsMutation) SetRating(d decimal.Decimal) { + m.rating = &d +} + +// Rating returns the value of the "rating" field in the mutation. +func (m *ShopsMutation) Rating() (r decimal.Decimal, exists bool) { + v := m.rating + if v == nil { + return + } + return *v, true +} + +// OldRating returns the old "rating" field's value of the Shops entity. +// If the Shops object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopsMutation) OldRating(ctx context.Context) (v decimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRating is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRating requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRating: %w", err) + } + return oldValue.Rating, nil +} + +// ClearRating clears the value of the "rating" field. +func (m *ShopsMutation) ClearRating() { + m.rating = nil + m.clearedFields[shops.FieldRating] = struct{}{} +} + +// RatingCleared returns if the "rating" field was cleared in this mutation. +func (m *ShopsMutation) RatingCleared() bool { + _, ok := m.clearedFields[shops.FieldRating] + return ok +} + +// ResetRating resets all changes to the "rating" field. +func (m *ShopsMutation) ResetRating() { + m.rating = nil + delete(m.clearedFields, shops.FieldRating) +} + +// SetTotalOrders sets the "total_orders" field. +func (m *ShopsMutation) SetTotalOrders(i int) { + m.total_orders = &i + m.addtotal_orders = nil +} + +// TotalOrders returns the value of the "total_orders" field in the mutation. +func (m *ShopsMutation) TotalOrders() (r int, exists bool) { + v := m.total_orders + if v == nil { + return + } + return *v, true +} + +// OldTotalOrders returns the old "total_orders" field's value of the Shops entity. +// If the Shops object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopsMutation) OldTotalOrders(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTotalOrders is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTotalOrders requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTotalOrders: %w", err) + } + return oldValue.TotalOrders, nil +} + +// AddTotalOrders adds i to the "total_orders" field. +func (m *ShopsMutation) AddTotalOrders(i int) { + if m.addtotal_orders != nil { + *m.addtotal_orders += i + } else { + m.addtotal_orders = &i + } +} + +// AddedTotalOrders returns the value that was added to the "total_orders" field in this mutation. +func (m *ShopsMutation) AddedTotalOrders() (r int, exists bool) { + v := m.addtotal_orders + if v == nil { + return + } + return *v, true +} + +// ClearTotalOrders clears the value of the "total_orders" field. +func (m *ShopsMutation) ClearTotalOrders() { + m.total_orders = nil + m.addtotal_orders = nil + m.clearedFields[shops.FieldTotalOrders] = struct{}{} +} + +// TotalOrdersCleared returns if the "total_orders" field was cleared in this mutation. +func (m *ShopsMutation) TotalOrdersCleared() bool { + _, ok := m.clearedFields[shops.FieldTotalOrders] + return ok +} + +// ResetTotalOrders resets all changes to the "total_orders" field. +func (m *ShopsMutation) ResetTotalOrders() { + m.total_orders = nil + m.addtotal_orders = nil + delete(m.clearedFields, shops.FieldTotalOrders) +} + +// SetPlayerCount sets the "player_count" field. +func (m *ShopsMutation) SetPlayerCount(i int) { + m.player_count = &i + m.addplayer_count = nil +} + +// PlayerCount returns the value of the "player_count" field in the mutation. +func (m *ShopsMutation) PlayerCount() (r int, exists bool) { + v := m.player_count + if v == nil { + return + } + return *v, true +} + +// OldPlayerCount returns the old "player_count" field's value of the Shops entity. +// If the Shops object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopsMutation) OldPlayerCount(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPlayerCount is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPlayerCount requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPlayerCount: %w", err) + } + return oldValue.PlayerCount, nil +} + +// AddPlayerCount adds i to the "player_count" field. +func (m *ShopsMutation) AddPlayerCount(i int) { + if m.addplayer_count != nil { + *m.addplayer_count += i + } else { + m.addplayer_count = &i + } +} + +// AddedPlayerCount returns the value that was added to the "player_count" field in this mutation. +func (m *ShopsMutation) AddedPlayerCount() (r int, exists bool) { + v := m.addplayer_count + if v == nil { + return + } + return *v, true +} + +// ClearPlayerCount clears the value of the "player_count" field. +func (m *ShopsMutation) ClearPlayerCount() { + m.player_count = nil + m.addplayer_count = nil + m.clearedFields[shops.FieldPlayerCount] = struct{}{} +} + +// PlayerCountCleared returns if the "player_count" field was cleared in this mutation. +func (m *ShopsMutation) PlayerCountCleared() bool { + _, ok := m.clearedFields[shops.FieldPlayerCount] + return ok +} + +// ResetPlayerCount resets all changes to the "player_count" field. +func (m *ShopsMutation) ResetPlayerCount() { + m.player_count = nil + m.addplayer_count = nil + delete(m.clearedFields, shops.FieldPlayerCount) +} + +// SetCommissionType sets the "commission_type" field. +func (m *ShopsMutation) SetCommissionType(s string) { + m.commission_type = &s +} + +// CommissionType returns the value of the "commission_type" field in the mutation. +func (m *ShopsMutation) CommissionType() (r string, exists bool) { + v := m.commission_type + if v == nil { + return + } + return *v, true +} + +// OldCommissionType returns the old "commission_type" field's value of the Shops entity. +// If the Shops object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopsMutation) OldCommissionType(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCommissionType is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCommissionType requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCommissionType: %w", err) + } + return oldValue.CommissionType, nil +} + +// ResetCommissionType resets all changes to the "commission_type" field. +func (m *ShopsMutation) ResetCommissionType() { + m.commission_type = nil +} + +// SetCommissionValue sets the "commission_value" field. +func (m *ShopsMutation) SetCommissionValue(d decimal.Decimal) { + m.commission_value = &d +} + +// CommissionValue returns the value of the "commission_value" field in the mutation. +func (m *ShopsMutation) CommissionValue() (r decimal.Decimal, exists bool) { + v := m.commission_value + if v == nil { + return + } + return *v, true +} + +// OldCommissionValue returns the old "commission_value" field's value of the Shops entity. +// If the Shops object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopsMutation) OldCommissionValue(ctx context.Context) (v decimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCommissionValue is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCommissionValue requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCommissionValue: %w", err) + } + return oldValue.CommissionValue, nil +} + +// ResetCommissionValue resets all changes to the "commission_value" field. +func (m *ShopsMutation) ResetCommissionValue() { + m.commission_value = nil +} + +// SetAllowMultiShop sets the "allow_multi_shop" field. +func (m *ShopsMutation) SetAllowMultiShop(b bool) { + m.allow_multi_shop = &b +} + +// AllowMultiShop returns the value of the "allow_multi_shop" field in the mutation. +func (m *ShopsMutation) AllowMultiShop() (r bool, exists bool) { + v := m.allow_multi_shop + if v == nil { + return + } + return *v, true +} + +// OldAllowMultiShop returns the old "allow_multi_shop" field's value of the Shops entity. +// If the Shops object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopsMutation) OldAllowMultiShop(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAllowMultiShop is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAllowMultiShop requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAllowMultiShop: %w", err) + } + return oldValue.AllowMultiShop, nil +} + +// ClearAllowMultiShop clears the value of the "allow_multi_shop" field. +func (m *ShopsMutation) ClearAllowMultiShop() { + m.allow_multi_shop = nil + m.clearedFields[shops.FieldAllowMultiShop] = struct{}{} +} + +// AllowMultiShopCleared returns if the "allow_multi_shop" field was cleared in this mutation. +func (m *ShopsMutation) AllowMultiShopCleared() bool { + _, ok := m.clearedFields[shops.FieldAllowMultiShop] + return ok +} + +// ResetAllowMultiShop resets all changes to the "allow_multi_shop" field. +func (m *ShopsMutation) ResetAllowMultiShop() { + m.allow_multi_shop = nil + delete(m.clearedFields, shops.FieldAllowMultiShop) +} + +// SetAllowIndependentOrders sets the "allow_independent_orders" field. +func (m *ShopsMutation) SetAllowIndependentOrders(b bool) { + m.allow_independent_orders = &b +} + +// AllowIndependentOrders returns the value of the "allow_independent_orders" field in the mutation. +func (m *ShopsMutation) AllowIndependentOrders() (r bool, exists bool) { + v := m.allow_independent_orders + if v == nil { + return + } + return *v, true +} + +// OldAllowIndependentOrders returns the old "allow_independent_orders" field's value of the Shops entity. +// If the Shops object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopsMutation) OldAllowIndependentOrders(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAllowIndependentOrders is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAllowIndependentOrders requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAllowIndependentOrders: %w", err) + } + return oldValue.AllowIndependentOrders, nil +} + +// ClearAllowIndependentOrders clears the value of the "allow_independent_orders" field. +func (m *ShopsMutation) ClearAllowIndependentOrders() { + m.allow_independent_orders = nil + m.clearedFields[shops.FieldAllowIndependentOrders] = struct{}{} +} + +// AllowIndependentOrdersCleared returns if the "allow_independent_orders" field was cleared in this mutation. +func (m *ShopsMutation) AllowIndependentOrdersCleared() bool { + _, ok := m.clearedFields[shops.FieldAllowIndependentOrders] + return ok +} + +// ResetAllowIndependentOrders resets all changes to the "allow_independent_orders" field. +func (m *ShopsMutation) ResetAllowIndependentOrders() { + m.allow_independent_orders = nil + delete(m.clearedFields, shops.FieldAllowIndependentOrders) +} + +// SetDispatchMode sets the "dispatch_mode" field. +func (m *ShopsMutation) SetDispatchMode(s string) { + m.dispatch_mode = &s +} + +// DispatchMode returns the value of the "dispatch_mode" field in the mutation. +func (m *ShopsMutation) DispatchMode() (r string, exists bool) { + v := m.dispatch_mode + if v == nil { + return + } + return *v, true +} + +// OldDispatchMode returns the old "dispatch_mode" field's value of the Shops entity. +// If the Shops object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopsMutation) OldDispatchMode(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDispatchMode is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDispatchMode requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDispatchMode: %w", err) + } + return oldValue.DispatchMode, nil +} + +// ResetDispatchMode resets all changes to the "dispatch_mode" field. +func (m *ShopsMutation) ResetDispatchMode() { + m.dispatch_mode = nil +} + +// SetAnnouncements sets the "announcements" field. +func (m *ShopsMutation) SetAnnouncements(s []string) { + m.announcements = &s + m.appendannouncements = nil +} + +// Announcements returns the value of the "announcements" field in the mutation. +func (m *ShopsMutation) Announcements() (r []string, exists bool) { + v := m.announcements + if v == nil { + return + } + return *v, true +} + +// OldAnnouncements returns the old "announcements" field's value of the Shops entity. +// If the Shops object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopsMutation) OldAnnouncements(ctx context.Context) (v []string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAnnouncements is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAnnouncements requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAnnouncements: %w", err) + } + return oldValue.Announcements, nil +} + +// AppendAnnouncements adds s to the "announcements" field. +func (m *ShopsMutation) AppendAnnouncements(s []string) { + m.appendannouncements = append(m.appendannouncements, s...) +} + +// AppendedAnnouncements returns the list of values that were appended to the "announcements" field in this mutation. +func (m *ShopsMutation) AppendedAnnouncements() ([]string, bool) { + if len(m.appendannouncements) == 0 { + return nil, false + } + return m.appendannouncements, true +} + +// ClearAnnouncements clears the value of the "announcements" field. +func (m *ShopsMutation) ClearAnnouncements() { + m.announcements = nil + m.appendannouncements = nil + m.clearedFields[shops.FieldAnnouncements] = struct{}{} +} + +// AnnouncementsCleared returns if the "announcements" field was cleared in this mutation. +func (m *ShopsMutation) AnnouncementsCleared() bool { + _, ok := m.clearedFields[shops.FieldAnnouncements] + return ok +} + +// ResetAnnouncements resets all changes to the "announcements" field. +func (m *ShopsMutation) ResetAnnouncements() { + m.announcements = nil + m.appendannouncements = nil + delete(m.clearedFields, shops.FieldAnnouncements) +} + +// SetTemplateConfig sets the "template_config" field. +func (m *ShopsMutation) SetTemplateConfig(value map[string]interface{}) { + m.template_config = &value +} + +// TemplateConfig returns the value of the "template_config" field in the mutation. +func (m *ShopsMutation) TemplateConfig() (r map[string]interface{}, exists bool) { + v := m.template_config + if v == nil { + return + } + return *v, true +} + +// OldTemplateConfig returns the old "template_config" field's value of the Shops entity. +// If the Shops object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopsMutation) OldTemplateConfig(ctx context.Context) (v map[string]interface{}, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTemplateConfig is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTemplateConfig requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTemplateConfig: %w", err) + } + return oldValue.TemplateConfig, nil +} + +// ClearTemplateConfig clears the value of the "template_config" field. +func (m *ShopsMutation) ClearTemplateConfig() { + m.template_config = nil + m.clearedFields[shops.FieldTemplateConfig] = struct{}{} +} + +// TemplateConfigCleared returns if the "template_config" field was cleared in this mutation. +func (m *ShopsMutation) TemplateConfigCleared() bool { + _, ok := m.clearedFields[shops.FieldTemplateConfig] + return ok +} + +// ResetTemplateConfig resets all changes to the "template_config" field. +func (m *ShopsMutation) ResetTemplateConfig() { + m.template_config = nil + delete(m.clearedFields, shops.FieldTemplateConfig) +} + +// SetCreatedAt sets the "created_at" field. +func (m *ShopsMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *ShopsMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the Shops entity. +// If the Shops object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopsMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *ShopsMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *ShopsMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *ShopsMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the Shops entity. +// If the Shops object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ShopsMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *ShopsMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// Where appends a list predicates to the ShopsMutation builder. +func (m *ShopsMutation) Where(ps ...predicate.Shops) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the ShopsMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ShopsMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Shops, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *ShopsMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *ShopsMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (Shops). +func (m *ShopsMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *ShopsMutation) Fields() []string { + fields := make([]string, 0, 16) + if m.owner_id != nil { + fields = append(fields, shops.FieldOwnerID) + } + if m.name != nil { + fields = append(fields, shops.FieldName) + } + if m.banner != nil { + fields = append(fields, shops.FieldBanner) + } + if m.description != nil { + fields = append(fields, shops.FieldDescription) + } + if m.rating != nil { + fields = append(fields, shops.FieldRating) + } + if m.total_orders != nil { + fields = append(fields, shops.FieldTotalOrders) + } + if m.player_count != nil { + fields = append(fields, shops.FieldPlayerCount) + } + if m.commission_type != nil { + fields = append(fields, shops.FieldCommissionType) + } + if m.commission_value != nil { + fields = append(fields, shops.FieldCommissionValue) + } + if m.allow_multi_shop != nil { + fields = append(fields, shops.FieldAllowMultiShop) + } + if m.allow_independent_orders != nil { + fields = append(fields, shops.FieldAllowIndependentOrders) + } + if m.dispatch_mode != nil { + fields = append(fields, shops.FieldDispatchMode) + } + if m.announcements != nil { + fields = append(fields, shops.FieldAnnouncements) + } + if m.template_config != nil { + fields = append(fields, shops.FieldTemplateConfig) + } + if m.created_at != nil { + fields = append(fields, shops.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, shops.FieldUpdatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *ShopsMutation) Field(name string) (ent.Value, bool) { + switch name { + case shops.FieldOwnerID: + return m.OwnerID() + case shops.FieldName: + return m.Name() + case shops.FieldBanner: + return m.Banner() + case shops.FieldDescription: + return m.Description() + case shops.FieldRating: + return m.Rating() + case shops.FieldTotalOrders: + return m.TotalOrders() + case shops.FieldPlayerCount: + return m.PlayerCount() + case shops.FieldCommissionType: + return m.CommissionType() + case shops.FieldCommissionValue: + return m.CommissionValue() + case shops.FieldAllowMultiShop: + return m.AllowMultiShop() + case shops.FieldAllowIndependentOrders: + return m.AllowIndependentOrders() + case shops.FieldDispatchMode: + return m.DispatchMode() + case shops.FieldAnnouncements: + return m.Announcements() + case shops.FieldTemplateConfig: + return m.TemplateConfig() + case shops.FieldCreatedAt: + return m.CreatedAt() + case shops.FieldUpdatedAt: + return m.UpdatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *ShopsMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case shops.FieldOwnerID: + return m.OldOwnerID(ctx) + case shops.FieldName: + return m.OldName(ctx) + case shops.FieldBanner: + return m.OldBanner(ctx) + case shops.FieldDescription: + return m.OldDescription(ctx) + case shops.FieldRating: + return m.OldRating(ctx) + case shops.FieldTotalOrders: + return m.OldTotalOrders(ctx) + case shops.FieldPlayerCount: + return m.OldPlayerCount(ctx) + case shops.FieldCommissionType: + return m.OldCommissionType(ctx) + case shops.FieldCommissionValue: + return m.OldCommissionValue(ctx) + case shops.FieldAllowMultiShop: + return m.OldAllowMultiShop(ctx) + case shops.FieldAllowIndependentOrders: + return m.OldAllowIndependentOrders(ctx) + case shops.FieldDispatchMode: + return m.OldDispatchMode(ctx) + case shops.FieldAnnouncements: + return m.OldAnnouncements(ctx) + case shops.FieldTemplateConfig: + return m.OldTemplateConfig(ctx) + case shops.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case shops.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown Shops field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *ShopsMutation) SetField(name string, value ent.Value) error { + switch name { + case shops.FieldOwnerID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetOwnerID(v) + return nil + case shops.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case shops.FieldBanner: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetBanner(v) + return nil + case shops.FieldDescription: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDescription(v) + return nil + case shops.FieldRating: + v, ok := value.(decimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRating(v) + return nil + case shops.FieldTotalOrders: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTotalOrders(v) + return nil + case shops.FieldPlayerCount: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPlayerCount(v) + return nil + case shops.FieldCommissionType: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCommissionType(v) + return nil + case shops.FieldCommissionValue: + v, ok := value.(decimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCommissionValue(v) + return nil + case shops.FieldAllowMultiShop: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAllowMultiShop(v) + return nil + case shops.FieldAllowIndependentOrders: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAllowIndependentOrders(v) + return nil + case shops.FieldDispatchMode: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDispatchMode(v) + return nil + case shops.FieldAnnouncements: + v, ok := value.([]string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAnnouncements(v) + return nil + case shops.FieldTemplateConfig: + v, ok := value.(map[string]interface{}) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTemplateConfig(v) + return nil + case shops.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case shops.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown Shops field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *ShopsMutation) AddedFields() []string { + var fields []string + if m.addowner_id != nil { + fields = append(fields, shops.FieldOwnerID) + } + if m.addtotal_orders != nil { + fields = append(fields, shops.FieldTotalOrders) + } + if m.addplayer_count != nil { + fields = append(fields, shops.FieldPlayerCount) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *ShopsMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case shops.FieldOwnerID: + return m.AddedOwnerID() + case shops.FieldTotalOrders: + return m.AddedTotalOrders() + case shops.FieldPlayerCount: + return m.AddedPlayerCount() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *ShopsMutation) AddField(name string, value ent.Value) error { + switch name { + case shops.FieldOwnerID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddOwnerID(v) + return nil + case shops.FieldTotalOrders: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddTotalOrders(v) + return nil + case shops.FieldPlayerCount: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddPlayerCount(v) + return nil + } + return fmt.Errorf("unknown Shops numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *ShopsMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(shops.FieldBanner) { + fields = append(fields, shops.FieldBanner) + } + if m.FieldCleared(shops.FieldDescription) { + fields = append(fields, shops.FieldDescription) + } + if m.FieldCleared(shops.FieldRating) { + fields = append(fields, shops.FieldRating) + } + if m.FieldCleared(shops.FieldTotalOrders) { + fields = append(fields, shops.FieldTotalOrders) + } + if m.FieldCleared(shops.FieldPlayerCount) { + fields = append(fields, shops.FieldPlayerCount) + } + if m.FieldCleared(shops.FieldAllowMultiShop) { + fields = append(fields, shops.FieldAllowMultiShop) + } + if m.FieldCleared(shops.FieldAllowIndependentOrders) { + fields = append(fields, shops.FieldAllowIndependentOrders) + } + if m.FieldCleared(shops.FieldAnnouncements) { + fields = append(fields, shops.FieldAnnouncements) + } + if m.FieldCleared(shops.FieldTemplateConfig) { + fields = append(fields, shops.FieldTemplateConfig) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *ShopsMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *ShopsMutation) ClearField(name string) error { + switch name { + case shops.FieldBanner: + m.ClearBanner() + return nil + case shops.FieldDescription: + m.ClearDescription() + return nil + case shops.FieldRating: + m.ClearRating() + return nil + case shops.FieldTotalOrders: + m.ClearTotalOrders() + return nil + case shops.FieldPlayerCount: + m.ClearPlayerCount() + return nil + case shops.FieldAllowMultiShop: + m.ClearAllowMultiShop() + return nil + case shops.FieldAllowIndependentOrders: + m.ClearAllowIndependentOrders() + return nil + case shops.FieldAnnouncements: + m.ClearAnnouncements() + return nil + case shops.FieldTemplateConfig: + m.ClearTemplateConfig() + return nil + } + return fmt.Errorf("unknown Shops nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *ShopsMutation) ResetField(name string) error { + switch name { + case shops.FieldOwnerID: + m.ResetOwnerID() + return nil + case shops.FieldName: + m.ResetName() + return nil + case shops.FieldBanner: + m.ResetBanner() + return nil + case shops.FieldDescription: + m.ResetDescription() + return nil + case shops.FieldRating: + m.ResetRating() + return nil + case shops.FieldTotalOrders: + m.ResetTotalOrders() + return nil + case shops.FieldPlayerCount: + m.ResetPlayerCount() + return nil + case shops.FieldCommissionType: + m.ResetCommissionType() + return nil + case shops.FieldCommissionValue: + m.ResetCommissionValue() + return nil + case shops.FieldAllowMultiShop: + m.ResetAllowMultiShop() + return nil + case shops.FieldAllowIndependentOrders: + m.ResetAllowIndependentOrders() + return nil + case shops.FieldDispatchMode: + m.ResetDispatchMode() + return nil + case shops.FieldAnnouncements: + m.ResetAnnouncements() + return nil + case shops.FieldTemplateConfig: + m.ResetTemplateConfig() + return nil + case shops.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case shops.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown Shops field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *ShopsMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *ShopsMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *ShopsMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *ShopsMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *ShopsMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *ShopsMutation) EdgeCleared(name string) bool { + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *ShopsMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown Shops unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *ShopsMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown Shops edge %s", name) +} diff --git a/app/shop/rpc/internal/models/predicate/predicate.go b/app/shop/rpc/internal/models/predicate/predicate.go new file mode 100644 index 0000000..6775125 --- /dev/null +++ b/app/shop/rpc/internal/models/predicate/predicate.go @@ -0,0 +1,16 @@ +// Code generated by ent, DO NOT EDIT. + +package predicate + +import ( + "entgo.io/ent/dialect/sql" +) + +// ShopInvitations is the predicate function for shopinvitations builders. +type ShopInvitations func(*sql.Selector) + +// ShopPlayers is the predicate function for shopplayers builders. +type ShopPlayers func(*sql.Selector) + +// Shops is the predicate function for shops builders. +type Shops func(*sql.Selector) diff --git a/app/shop/rpc/internal/models/runtime.go b/app/shop/rpc/internal/models/runtime.go new file mode 100644 index 0000000..c4c9bdb --- /dev/null +++ b/app/shop/rpc/internal/models/runtime.go @@ -0,0 +1,93 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "juwan-backend/app/shop/rpc/internal/models/schema" + "juwan-backend/app/shop/rpc/internal/models/shopinvitations" + "juwan-backend/app/shop/rpc/internal/models/shopplayers" + "juwan-backend/app/shop/rpc/internal/models/shops" + "time" + + "github.com/shopspring/decimal" +) + +// The init function reads all schema descriptors with runtime code +// (default values, validators, hooks and policies) and stitches it +// to their package variables. +func init() { + shopinvitationsFields := schema.ShopInvitations{}.Fields() + _ = shopinvitationsFields + // shopinvitationsDescStatus is the schema descriptor for status field. + shopinvitationsDescStatus := shopinvitationsFields[3].Descriptor() + // shopinvitations.DefaultStatus holds the default value on creation for the status field. + shopinvitations.DefaultStatus = shopinvitationsDescStatus.Default.(string) + // shopinvitations.StatusValidator is a validator for the "status" field. It is called by the builders before save. + shopinvitations.StatusValidator = shopinvitationsDescStatus.Validators[0].(func(string) error) + // shopinvitationsDescCreatedAt is the schema descriptor for created_at field. + shopinvitationsDescCreatedAt := shopinvitationsFields[5].Descriptor() + // shopinvitations.DefaultCreatedAt holds the default value on creation for the created_at field. + shopinvitations.DefaultCreatedAt = shopinvitationsDescCreatedAt.Default.(func() time.Time) + shopplayersFields := schema.ShopPlayers{}.Fields() + _ = shopplayersFields + // shopplayersDescIsPrimary is the schema descriptor for is_primary field. + shopplayersDescIsPrimary := shopplayersFields[3].Descriptor() + // shopplayers.DefaultIsPrimary holds the default value on creation for the is_primary field. + shopplayers.DefaultIsPrimary = shopplayersDescIsPrimary.Default.(bool) + // shopplayersDescJoinedAt is the schema descriptor for joined_at field. + shopplayersDescJoinedAt := shopplayersFields[4].Descriptor() + // shopplayers.DefaultJoinedAt holds the default value on creation for the joined_at field. + shopplayers.DefaultJoinedAt = shopplayersDescJoinedAt.Default.(func() time.Time) + shopsFields := schema.Shops{}.Fields() + _ = shopsFields + // shopsDescName is the schema descriptor for name field. + shopsDescName := shopsFields[2].Descriptor() + // shops.NameValidator is a validator for the "name" field. It is called by the builders before save. + shops.NameValidator = shopsDescName.Validators[0].(func(string) error) + // shopsDescRating is the schema descriptor for rating field. + shopsDescRating := shopsFields[5].Descriptor() + // shops.DefaultRating holds the default value on creation for the rating field. + shops.DefaultRating = shopsDescRating.Default.(decimal.Decimal) + // shopsDescTotalOrders is the schema descriptor for total_orders field. + shopsDescTotalOrders := shopsFields[6].Descriptor() + // shops.DefaultTotalOrders holds the default value on creation for the total_orders field. + shops.DefaultTotalOrders = shopsDescTotalOrders.Default.(int) + // shopsDescPlayerCount is the schema descriptor for player_count field. + shopsDescPlayerCount := shopsFields[7].Descriptor() + // shops.DefaultPlayerCount holds the default value on creation for the player_count field. + shops.DefaultPlayerCount = shopsDescPlayerCount.Default.(int) + // shopsDescCommissionType is the schema descriptor for commission_type field. + shopsDescCommissionType := shopsFields[8].Descriptor() + // shops.DefaultCommissionType holds the default value on creation for the commission_type field. + shops.DefaultCommissionType = shopsDescCommissionType.Default.(string) + // shops.CommissionTypeValidator is a validator for the "commission_type" field. It is called by the builders before save. + shops.CommissionTypeValidator = shopsDescCommissionType.Validators[0].(func(string) error) + // shopsDescAllowMultiShop is the schema descriptor for allow_multi_shop field. + shopsDescAllowMultiShop := shopsFields[10].Descriptor() + // shops.DefaultAllowMultiShop holds the default value on creation for the allow_multi_shop field. + shops.DefaultAllowMultiShop = shopsDescAllowMultiShop.Default.(bool) + // shopsDescAllowIndependentOrders is the schema descriptor for allow_independent_orders field. + shopsDescAllowIndependentOrders := shopsFields[11].Descriptor() + // shops.DefaultAllowIndependentOrders holds the default value on creation for the allow_independent_orders field. + shops.DefaultAllowIndependentOrders = shopsDescAllowIndependentOrders.Default.(bool) + // shopsDescDispatchMode is the schema descriptor for dispatch_mode field. + shopsDescDispatchMode := shopsFields[12].Descriptor() + // shops.DefaultDispatchMode holds the default value on creation for the dispatch_mode field. + shops.DefaultDispatchMode = shopsDescDispatchMode.Default.(string) + // shops.DispatchModeValidator is a validator for the "dispatch_mode" field. It is called by the builders before save. + shops.DispatchModeValidator = shopsDescDispatchMode.Validators[0].(func(string) error) + // shopsDescAnnouncements is the schema descriptor for announcements field. + shopsDescAnnouncements := shopsFields[13].Descriptor() + // shops.DefaultAnnouncements holds the default value on creation for the announcements field. + shops.DefaultAnnouncements = shopsDescAnnouncements.Default.([]string) + // shopsDescCreatedAt is the schema descriptor for created_at field. + shopsDescCreatedAt := shopsFields[15].Descriptor() + // shops.DefaultCreatedAt holds the default value on creation for the created_at field. + shops.DefaultCreatedAt = shopsDescCreatedAt.Default.(func() time.Time) + // shopsDescUpdatedAt is the schema descriptor for updated_at field. + shopsDescUpdatedAt := shopsFields[16].Descriptor() + // shops.DefaultUpdatedAt holds the default value on creation for the updated_at field. + shops.DefaultUpdatedAt = shopsDescUpdatedAt.Default.(func() time.Time) + // shops.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + shops.UpdateDefaultUpdatedAt = shopsDescUpdatedAt.UpdateDefault.(func() time.Time) +} diff --git a/app/shop/rpc/internal/models/runtime/runtime.go b/app/shop/rpc/internal/models/runtime/runtime.go new file mode 100644 index 0000000..1ff4fe2 --- /dev/null +++ b/app/shop/rpc/internal/models/runtime/runtime.go @@ -0,0 +1,10 @@ +// Code generated by ent, DO NOT EDIT. + +package runtime + +// The schema-stitching logic is generated in juwan-backend/app/shop/rpc/internal/models/runtime.go + +const ( + Version = "v0.14.5" // Version of ent codegen. + Sum = "h1:Rj2WOYJtCkWyFo6a+5wB3EfBRP0rnx1fMk6gGA0UUe4=" // Sum of ent codegen. +) diff --git a/app/shop/rpc/internal/models/schema/shopinvitations.go b/app/shop/rpc/internal/models/schema/shopinvitations.go new file mode 100644 index 0000000..d4beb88 --- /dev/null +++ b/app/shop/rpc/internal/models/schema/shopinvitations.go @@ -0,0 +1,56 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" +) + +// ShopInvitations holds the schema definition for the ShopInvitations entity. +type ShopInvitations struct { + ent.Schema +} + +// Annotations of the ShopInvitations. +func (ShopInvitations) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{ + Table: "shop_invitations", + Checks: map[string]string{ + "chk_invitation_status": "status IN ('pending', 'accepted', 'rejected', 'cancelled')", + }, + }, + } +} + +// Fields of the ShopInvitations. +func (ShopInvitations) Fields() []ent.Field { + return []ent.Field{ + field.Int64("id").Immutable().Unique(), + field.Int64("shop_id"), + field.Int64("player_id"), + field.String("status").MaxLen(20).Default("pending"), + field.Int64("invited_by"), + field.Time("created_at").Default(time.Now).Immutable(), + field.Time("responded_at").Optional().Nillable(), + } +} + +// Indexes of the ShopInvitations. +func (ShopInvitations) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("shop_id"), + index.Fields("player_id"), + index.Fields("player_id", "status", "created_at"), + index.Fields("shop_id", "status", "created_at"), + } +} + +// Edges of the ShopInvitations. +func (ShopInvitations) Edges() []ent.Edge { + return nil +} diff --git a/app/shop/rpc/internal/models/schema/shopplayers.go b/app/shop/rpc/internal/models/schema/shopplayers.go new file mode 100644 index 0000000..af6db49 --- /dev/null +++ b/app/shop/rpc/internal/models/schema/shopplayers.go @@ -0,0 +1,40 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" +) + +// ShopPlayers holds the schema definition for the ShopPlayers entity. +type ShopPlayers struct { + ent.Schema +} + +// Fields of the ShopPlayers. +func (ShopPlayers) Fields() []ent.Field { + return []ent.Field{ + field.Int64("id").Immutable().Unique(), + field.Int64("shop_id"), + field.Int64("player_id"), + field.Bool("is_primary").Optional().Default(false), + field.Time("joined_at").Default(time.Now).Immutable(), + field.Time("left_at").Optional().Nillable(), + } +} + +// Indexes of the ShopPlayers. +func (ShopPlayers) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("shop_id", "player_id").Unique(), + index.Fields("player_id"), + index.Fields("shop_id", "joined_at"), + } +} + +// Edges of the ShopPlayers. +func (ShopPlayers) Edges() []ent.Edge { + return nil +} diff --git a/app/shop/rpc/internal/models/schema/shops.go b/app/shop/rpc/internal/models/schema/shops.go new file mode 100644 index 0000000..e4a4c5c --- /dev/null +++ b/app/shop/rpc/internal/models/schema/shops.go @@ -0,0 +1,69 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" + "entgo.io/ent/schema/field" + "github.com/shopspring/decimal" +) + +var shopDefaultRating = decimal.RequireFromString("5.00") + +// Shops holds the schema definition for the Shops entity. +type Shops struct { + ent.Schema +} + +// Annotations of the Shops. +func (Shops) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{ + Table: "shops", + Checks: map[string]string{ + "chk_commission_type": "commission_type IN ('fixed', 'percentage')", + "chk_dispatch_mode": "dispatch_mode IN ('manual', 'auto')", + "chk_rating_range": "rating >= 0 AND rating <= 5", + }, + }, + } +} + +// Fields of the Shops. +func (Shops) Fields() []ent.Field { + return []ent.Field{ + field.Int64("id").Immutable().Unique(), + field.Int64("owner_id").Unique(), + field.String("name").MaxLen(200), + field.String("banner").Optional().Nillable(), + field.String("description").Optional().Nillable(), + field.Other("rating", decimal.Decimal{}). + Optional(). + Default(shopDefaultRating). + SchemaType(map[string]string{ + dialect.Postgres: "decimal(3,2)", + }), + field.Int("total_orders").Optional().Default(0), + field.Int("player_count").Optional().Default(0), + field.String("commission_type").MaxLen(20).Default("percentage"), + field.Other("commission_value", decimal.Decimal{}). + SchemaType(map[string]string{ + dialect.Postgres: "decimal(10,2)", + }), + field.Bool("allow_multi_shop").Optional().Default(false), + field.Bool("allow_independent_orders").Optional().Default(true), + field.String("dispatch_mode").MaxLen(20).Default("manual"), + field.Strings("announcements").Optional().Default([]string{}), + field.JSON("template_config", map[string]any{}).Optional(), + field.Time("created_at").Default(time.Now).Immutable(), + field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now), + } +} + +// Edges of the Shops. +func (Shops) Edges() []ent.Edge { + return nil +} diff --git a/app/shop/rpc/internal/models/shopinvitations.go b/app/shop/rpc/internal/models/shopinvitations.go new file mode 100644 index 0000000..1c8663b --- /dev/null +++ b/app/shop/rpc/internal/models/shopinvitations.go @@ -0,0 +1,164 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "fmt" + "juwan-backend/app/shop/rpc/internal/models/shopinvitations" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" +) + +// ShopInvitations is the model entity for the ShopInvitations schema. +type ShopInvitations struct { + config `json:"-"` + // ID of the ent. + ID int64 `json:"id,omitempty"` + // ShopID holds the value of the "shop_id" field. + ShopID int64 `json:"shop_id,omitempty"` + // PlayerID holds the value of the "player_id" field. + PlayerID int64 `json:"player_id,omitempty"` + // Status holds the value of the "status" field. + Status string `json:"status,omitempty"` + // InvitedBy holds the value of the "invited_by" field. + InvitedBy int64 `json:"invited_by,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + // RespondedAt holds the value of the "responded_at" field. + RespondedAt *time.Time `json:"responded_at,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*ShopInvitations) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case shopinvitations.FieldID, shopinvitations.FieldShopID, shopinvitations.FieldPlayerID, shopinvitations.FieldInvitedBy: + values[i] = new(sql.NullInt64) + case shopinvitations.FieldStatus: + values[i] = new(sql.NullString) + case shopinvitations.FieldCreatedAt, shopinvitations.FieldRespondedAt: + 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 ShopInvitations fields. +func (_m *ShopInvitations) 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 shopinvitations.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 shopinvitations.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 = value.Int64 + } + case shopinvitations.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 shopinvitations.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 shopinvitations.FieldInvitedBy: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field invited_by", values[i]) + } else if value.Valid { + _m.InvitedBy = value.Int64 + } + case shopinvitations.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 shopinvitations.FieldRespondedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field responded_at", values[i]) + } else if value.Valid { + _m.RespondedAt = new(time.Time) + *_m.RespondedAt = 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 ShopInvitations. +// This includes values selected through modifiers, order, etc. +func (_m *ShopInvitations) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// Update returns a builder for updating this ShopInvitations. +// Note that you need to call ShopInvitations.Unwrap() before calling this method if this ShopInvitations +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *ShopInvitations) Update() *ShopInvitationsUpdateOne { + return NewShopInvitationsClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the ShopInvitations 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 *ShopInvitations) Unwrap() *ShopInvitations { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("models: ShopInvitations is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *ShopInvitations) String() string { + var builder strings.Builder + builder.WriteString("ShopInvitations(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("shop_id=") + builder.WriteString(fmt.Sprintf("%v", _m.ShopID)) + builder.WriteString(", ") + builder.WriteString("player_id=") + builder.WriteString(fmt.Sprintf("%v", _m.PlayerID)) + builder.WriteString(", ") + builder.WriteString("status=") + builder.WriteString(_m.Status) + builder.WriteString(", ") + builder.WriteString("invited_by=") + builder.WriteString(fmt.Sprintf("%v", _m.InvitedBy)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + if v := _m.RespondedAt; v != nil { + builder.WriteString("responded_at=") + builder.WriteString(v.Format(time.ANSIC)) + } + builder.WriteByte(')') + return builder.String() +} + +// ShopInvitationsSlice is a parsable slice of ShopInvitations. +type ShopInvitationsSlice []*ShopInvitations diff --git a/app/shop/rpc/internal/models/shopinvitations/shopinvitations.go b/app/shop/rpc/internal/models/shopinvitations/shopinvitations.go new file mode 100644 index 0000000..bab4232 --- /dev/null +++ b/app/shop/rpc/internal/models/shopinvitations/shopinvitations.go @@ -0,0 +1,98 @@ +// Code generated by ent, DO NOT EDIT. + +package shopinvitations + +import ( + "time" + + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the shopinvitations type in the database. + Label = "shop_invitations" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldShopID holds the string denoting the shop_id field in the database. + FieldShopID = "shop_id" + // FieldPlayerID holds the string denoting the player_id field in the database. + FieldPlayerID = "player_id" + // FieldStatus holds the string denoting the status field in the database. + FieldStatus = "status" + // FieldInvitedBy holds the string denoting the invited_by field in the database. + FieldInvitedBy = "invited_by" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldRespondedAt holds the string denoting the responded_at field in the database. + FieldRespondedAt = "responded_at" + // Table holds the table name of the shopinvitations in the database. + Table = "shop_invitations" +) + +// Columns holds all SQL columns for shopinvitations fields. +var Columns = []string{ + FieldID, + FieldShopID, + FieldPlayerID, + FieldStatus, + FieldInvitedBy, + FieldCreatedAt, + FieldRespondedAt, +} + +// 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 + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time +) + +// OrderOption defines the ordering options for the ShopInvitations 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() +} + +// ByShopID orders the results by the shop_id field. +func ByShopID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldShopID, opts...).ToFunc() +} + +// ByPlayerID orders the results by the player_id field. +func ByPlayerID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPlayerID, opts...).ToFunc() +} + +// ByStatus orders the results by the status field. +func ByStatus(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStatus, opts...).ToFunc() +} + +// ByInvitedBy orders the results by the invited_by field. +func ByInvitedBy(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldInvitedBy, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByRespondedAt orders the results by the responded_at field. +func ByRespondedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRespondedAt, opts...).ToFunc() +} diff --git a/app/shop/rpc/internal/models/shopinvitations/where.go b/app/shop/rpc/internal/models/shopinvitations/where.go new file mode 100644 index 0000000..c4aa278 --- /dev/null +++ b/app/shop/rpc/internal/models/shopinvitations/where.go @@ -0,0 +1,375 @@ +// Code generated by ent, DO NOT EDIT. + +package shopinvitations + +import ( + "juwan-backend/app/shop/rpc/internal/models/predicate" + "time" + + "entgo.io/ent/dialect/sql" +) + +// ID filters vertices based on their ID field. +func ID(id int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldLTE(FieldID, id)) +} + +// ShopID applies equality check predicate on the "shop_id" field. It's identical to ShopIDEQ. +func ShopID(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldEQ(FieldShopID, v)) +} + +// PlayerID applies equality check predicate on the "player_id" field. It's identical to PlayerIDEQ. +func PlayerID(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldEQ(FieldPlayerID, v)) +} + +// Status applies equality check predicate on the "status" field. It's identical to StatusEQ. +func Status(v string) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldEQ(FieldStatus, v)) +} + +// InvitedBy applies equality check predicate on the "invited_by" field. It's identical to InvitedByEQ. +func InvitedBy(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldEQ(FieldInvitedBy, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldEQ(FieldCreatedAt, v)) +} + +// RespondedAt applies equality check predicate on the "responded_at" field. It's identical to RespondedAtEQ. +func RespondedAt(v time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldEQ(FieldRespondedAt, v)) +} + +// ShopIDEQ applies the EQ predicate on the "shop_id" field. +func ShopIDEQ(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldEQ(FieldShopID, v)) +} + +// ShopIDNEQ applies the NEQ predicate on the "shop_id" field. +func ShopIDNEQ(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldNEQ(FieldShopID, v)) +} + +// ShopIDIn applies the In predicate on the "shop_id" field. +func ShopIDIn(vs ...int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldIn(FieldShopID, vs...)) +} + +// ShopIDNotIn applies the NotIn predicate on the "shop_id" field. +func ShopIDNotIn(vs ...int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldNotIn(FieldShopID, vs...)) +} + +// ShopIDGT applies the GT predicate on the "shop_id" field. +func ShopIDGT(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldGT(FieldShopID, v)) +} + +// ShopIDGTE applies the GTE predicate on the "shop_id" field. +func ShopIDGTE(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldGTE(FieldShopID, v)) +} + +// ShopIDLT applies the LT predicate on the "shop_id" field. +func ShopIDLT(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldLT(FieldShopID, v)) +} + +// ShopIDLTE applies the LTE predicate on the "shop_id" field. +func ShopIDLTE(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldLTE(FieldShopID, v)) +} + +// PlayerIDEQ applies the EQ predicate on the "player_id" field. +func PlayerIDEQ(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldEQ(FieldPlayerID, v)) +} + +// PlayerIDNEQ applies the NEQ predicate on the "player_id" field. +func PlayerIDNEQ(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldNEQ(FieldPlayerID, v)) +} + +// PlayerIDIn applies the In predicate on the "player_id" field. +func PlayerIDIn(vs ...int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldIn(FieldPlayerID, vs...)) +} + +// PlayerIDNotIn applies the NotIn predicate on the "player_id" field. +func PlayerIDNotIn(vs ...int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldNotIn(FieldPlayerID, vs...)) +} + +// PlayerIDGT applies the GT predicate on the "player_id" field. +func PlayerIDGT(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldGT(FieldPlayerID, v)) +} + +// PlayerIDGTE applies the GTE predicate on the "player_id" field. +func PlayerIDGTE(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldGTE(FieldPlayerID, v)) +} + +// PlayerIDLT applies the LT predicate on the "player_id" field. +func PlayerIDLT(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldLT(FieldPlayerID, v)) +} + +// PlayerIDLTE applies the LTE predicate on the "player_id" field. +func PlayerIDLTE(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldLTE(FieldPlayerID, v)) +} + +// StatusEQ applies the EQ predicate on the "status" field. +func StatusEQ(v string) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldEQ(FieldStatus, v)) +} + +// StatusNEQ applies the NEQ predicate on the "status" field. +func StatusNEQ(v string) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldNEQ(FieldStatus, v)) +} + +// StatusIn applies the In predicate on the "status" field. +func StatusIn(vs ...string) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldIn(FieldStatus, vs...)) +} + +// StatusNotIn applies the NotIn predicate on the "status" field. +func StatusNotIn(vs ...string) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldNotIn(FieldStatus, vs...)) +} + +// StatusGT applies the GT predicate on the "status" field. +func StatusGT(v string) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldGT(FieldStatus, v)) +} + +// StatusGTE applies the GTE predicate on the "status" field. +func StatusGTE(v string) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldGTE(FieldStatus, v)) +} + +// StatusLT applies the LT predicate on the "status" field. +func StatusLT(v string) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldLT(FieldStatus, v)) +} + +// StatusLTE applies the LTE predicate on the "status" field. +func StatusLTE(v string) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldLTE(FieldStatus, v)) +} + +// StatusContains applies the Contains predicate on the "status" field. +func StatusContains(v string) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldContains(FieldStatus, v)) +} + +// StatusHasPrefix applies the HasPrefix predicate on the "status" field. +func StatusHasPrefix(v string) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldHasPrefix(FieldStatus, v)) +} + +// StatusHasSuffix applies the HasSuffix predicate on the "status" field. +func StatusHasSuffix(v string) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldHasSuffix(FieldStatus, v)) +} + +// StatusEqualFold applies the EqualFold predicate on the "status" field. +func StatusEqualFold(v string) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldEqualFold(FieldStatus, v)) +} + +// StatusContainsFold applies the ContainsFold predicate on the "status" field. +func StatusContainsFold(v string) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldContainsFold(FieldStatus, v)) +} + +// InvitedByEQ applies the EQ predicate on the "invited_by" field. +func InvitedByEQ(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldEQ(FieldInvitedBy, v)) +} + +// InvitedByNEQ applies the NEQ predicate on the "invited_by" field. +func InvitedByNEQ(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldNEQ(FieldInvitedBy, v)) +} + +// InvitedByIn applies the In predicate on the "invited_by" field. +func InvitedByIn(vs ...int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldIn(FieldInvitedBy, vs...)) +} + +// InvitedByNotIn applies the NotIn predicate on the "invited_by" field. +func InvitedByNotIn(vs ...int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldNotIn(FieldInvitedBy, vs...)) +} + +// InvitedByGT applies the GT predicate on the "invited_by" field. +func InvitedByGT(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldGT(FieldInvitedBy, v)) +} + +// InvitedByGTE applies the GTE predicate on the "invited_by" field. +func InvitedByGTE(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldGTE(FieldInvitedBy, v)) +} + +// InvitedByLT applies the LT predicate on the "invited_by" field. +func InvitedByLT(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldLT(FieldInvitedBy, v)) +} + +// InvitedByLTE applies the LTE predicate on the "invited_by" field. +func InvitedByLTE(v int64) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldLTE(FieldInvitedBy, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldLTE(FieldCreatedAt, v)) +} + +// RespondedAtEQ applies the EQ predicate on the "responded_at" field. +func RespondedAtEQ(v time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldEQ(FieldRespondedAt, v)) +} + +// RespondedAtNEQ applies the NEQ predicate on the "responded_at" field. +func RespondedAtNEQ(v time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldNEQ(FieldRespondedAt, v)) +} + +// RespondedAtIn applies the In predicate on the "responded_at" field. +func RespondedAtIn(vs ...time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldIn(FieldRespondedAt, vs...)) +} + +// RespondedAtNotIn applies the NotIn predicate on the "responded_at" field. +func RespondedAtNotIn(vs ...time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldNotIn(FieldRespondedAt, vs...)) +} + +// RespondedAtGT applies the GT predicate on the "responded_at" field. +func RespondedAtGT(v time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldGT(FieldRespondedAt, v)) +} + +// RespondedAtGTE applies the GTE predicate on the "responded_at" field. +func RespondedAtGTE(v time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldGTE(FieldRespondedAt, v)) +} + +// RespondedAtLT applies the LT predicate on the "responded_at" field. +func RespondedAtLT(v time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldLT(FieldRespondedAt, v)) +} + +// RespondedAtLTE applies the LTE predicate on the "responded_at" field. +func RespondedAtLTE(v time.Time) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldLTE(FieldRespondedAt, v)) +} + +// RespondedAtIsNil applies the IsNil predicate on the "responded_at" field. +func RespondedAtIsNil() predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldIsNull(FieldRespondedAt)) +} + +// RespondedAtNotNil applies the NotNil predicate on the "responded_at" field. +func RespondedAtNotNil() predicate.ShopInvitations { + return predicate.ShopInvitations(sql.FieldNotNull(FieldRespondedAt)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.ShopInvitations) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.ShopInvitations) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.ShopInvitations) predicate.ShopInvitations { + return predicate.ShopInvitations(sql.NotPredicates(p)) +} diff --git a/app/shop/rpc/internal/models/shopinvitations_create.go b/app/shop/rpc/internal/models/shopinvitations_create.go new file mode 100644 index 0000000..59e66c7 --- /dev/null +++ b/app/shop/rpc/internal/models/shopinvitations_create.go @@ -0,0 +1,301 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "errors" + "fmt" + "juwan-backend/app/shop/rpc/internal/models/shopinvitations" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// ShopInvitationsCreate is the builder for creating a ShopInvitations entity. +type ShopInvitationsCreate struct { + config + mutation *ShopInvitationsMutation + hooks []Hook +} + +// SetShopID sets the "shop_id" field. +func (_c *ShopInvitationsCreate) SetShopID(v int64) *ShopInvitationsCreate { + _c.mutation.SetShopID(v) + return _c +} + +// SetPlayerID sets the "player_id" field. +func (_c *ShopInvitationsCreate) SetPlayerID(v int64) *ShopInvitationsCreate { + _c.mutation.SetPlayerID(v) + return _c +} + +// SetStatus sets the "status" field. +func (_c *ShopInvitationsCreate) SetStatus(v string) *ShopInvitationsCreate { + _c.mutation.SetStatus(v) + return _c +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (_c *ShopInvitationsCreate) SetNillableStatus(v *string) *ShopInvitationsCreate { + if v != nil { + _c.SetStatus(*v) + } + return _c +} + +// SetInvitedBy sets the "invited_by" field. +func (_c *ShopInvitationsCreate) SetInvitedBy(v int64) *ShopInvitationsCreate { + _c.mutation.SetInvitedBy(v) + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *ShopInvitationsCreate) SetCreatedAt(v time.Time) *ShopInvitationsCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *ShopInvitationsCreate) SetNillableCreatedAt(v *time.Time) *ShopInvitationsCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetRespondedAt sets the "responded_at" field. +func (_c *ShopInvitationsCreate) SetRespondedAt(v time.Time) *ShopInvitationsCreate { + _c.mutation.SetRespondedAt(v) + return _c +} + +// SetNillableRespondedAt sets the "responded_at" field if the given value is not nil. +func (_c *ShopInvitationsCreate) SetNillableRespondedAt(v *time.Time) *ShopInvitationsCreate { + if v != nil { + _c.SetRespondedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *ShopInvitationsCreate) SetID(v int64) *ShopInvitationsCreate { + _c.mutation.SetID(v) + return _c +} + +// Mutation returns the ShopInvitationsMutation object of the builder. +func (_c *ShopInvitationsCreate) Mutation() *ShopInvitationsMutation { + return _c.mutation +} + +// Save creates the ShopInvitations in the database. +func (_c *ShopInvitationsCreate) Save(ctx context.Context) (*ShopInvitations, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *ShopInvitationsCreate) SaveX(ctx context.Context) *ShopInvitations { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ShopInvitationsCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ShopInvitationsCreate) 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 *ShopInvitationsCreate) defaults() { + if _, ok := _c.mutation.Status(); !ok { + v := shopinvitations.DefaultStatus + _c.mutation.SetStatus(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := shopinvitations.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *ShopInvitationsCreate) check() error { + if _, ok := _c.mutation.ShopID(); !ok { + return &ValidationError{Name: "shop_id", err: errors.New(`models: missing required field "ShopInvitations.shop_id"`)} + } + if _, ok := _c.mutation.PlayerID(); !ok { + return &ValidationError{Name: "player_id", err: errors.New(`models: missing required field "ShopInvitations.player_id"`)} + } + if _, ok := _c.mutation.Status(); !ok { + return &ValidationError{Name: "status", err: errors.New(`models: missing required field "ShopInvitations.status"`)} + } + if v, ok := _c.mutation.Status(); ok { + if err := shopinvitations.StatusValidator(v); err != nil { + return &ValidationError{Name: "status", err: fmt.Errorf(`models: validator failed for field "ShopInvitations.status": %w`, err)} + } + } + if _, ok := _c.mutation.InvitedBy(); !ok { + return &ValidationError{Name: "invited_by", err: errors.New(`models: missing required field "ShopInvitations.invited_by"`)} + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`models: missing required field "ShopInvitations.created_at"`)} + } + return nil +} + +func (_c *ShopInvitationsCreate) sqlSave(ctx context.Context) (*ShopInvitations, 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 *ShopInvitationsCreate) createSpec() (*ShopInvitations, *sqlgraph.CreateSpec) { + var ( + _node = &ShopInvitations{config: _c.config} + _spec = sqlgraph.NewCreateSpec(shopinvitations.Table, sqlgraph.NewFieldSpec(shopinvitations.FieldID, field.TypeInt64)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := _c.mutation.ShopID(); ok { + _spec.SetField(shopinvitations.FieldShopID, field.TypeInt64, value) + _node.ShopID = value + } + if value, ok := _c.mutation.PlayerID(); ok { + _spec.SetField(shopinvitations.FieldPlayerID, field.TypeInt64, value) + _node.PlayerID = value + } + if value, ok := _c.mutation.Status(); ok { + _spec.SetField(shopinvitations.FieldStatus, field.TypeString, value) + _node.Status = value + } + if value, ok := _c.mutation.InvitedBy(); ok { + _spec.SetField(shopinvitations.FieldInvitedBy, field.TypeInt64, value) + _node.InvitedBy = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(shopinvitations.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.RespondedAt(); ok { + _spec.SetField(shopinvitations.FieldRespondedAt, field.TypeTime, value) + _node.RespondedAt = &value + } + return _node, _spec +} + +// ShopInvitationsCreateBulk is the builder for creating many ShopInvitations entities in bulk. +type ShopInvitationsCreateBulk struct { + config + err error + builders []*ShopInvitationsCreate +} + +// Save creates the ShopInvitations entities in the database. +func (_c *ShopInvitationsCreateBulk) Save(ctx context.Context) ([]*ShopInvitations, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*ShopInvitations, 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.(*ShopInvitationsMutation) + 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 *ShopInvitationsCreateBulk) SaveX(ctx context.Context) []*ShopInvitations { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ShopInvitationsCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ShopInvitationsCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/app/shop/rpc/internal/models/shopinvitations_delete.go b/app/shop/rpc/internal/models/shopinvitations_delete.go new file mode 100644 index 0000000..ad1162d --- /dev/null +++ b/app/shop/rpc/internal/models/shopinvitations_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "juwan-backend/app/shop/rpc/internal/models/predicate" + "juwan-backend/app/shop/rpc/internal/models/shopinvitations" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// ShopInvitationsDelete is the builder for deleting a ShopInvitations entity. +type ShopInvitationsDelete struct { + config + hooks []Hook + mutation *ShopInvitationsMutation +} + +// Where appends a list predicates to the ShopInvitationsDelete builder. +func (_d *ShopInvitationsDelete) Where(ps ...predicate.ShopInvitations) *ShopInvitationsDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *ShopInvitationsDelete) 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 *ShopInvitationsDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *ShopInvitationsDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(shopinvitations.Table, sqlgraph.NewFieldSpec(shopinvitations.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 +} + +// ShopInvitationsDeleteOne is the builder for deleting a single ShopInvitations entity. +type ShopInvitationsDeleteOne struct { + _d *ShopInvitationsDelete +} + +// Where appends a list predicates to the ShopInvitationsDelete builder. +func (_d *ShopInvitationsDeleteOne) Where(ps ...predicate.ShopInvitations) *ShopInvitationsDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *ShopInvitationsDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{shopinvitations.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *ShopInvitationsDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/app/shop/rpc/internal/models/shopinvitations_query.go b/app/shop/rpc/internal/models/shopinvitations_query.go new file mode 100644 index 0000000..6c81ea7 --- /dev/null +++ b/app/shop/rpc/internal/models/shopinvitations_query.go @@ -0,0 +1,527 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "fmt" + "juwan-backend/app/shop/rpc/internal/models/predicate" + "juwan-backend/app/shop/rpc/internal/models/shopinvitations" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// ShopInvitationsQuery is the builder for querying ShopInvitations entities. +type ShopInvitationsQuery struct { + config + ctx *QueryContext + order []shopinvitations.OrderOption + inters []Interceptor + predicates []predicate.ShopInvitations + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the ShopInvitationsQuery builder. +func (_q *ShopInvitationsQuery) Where(ps ...predicate.ShopInvitations) *ShopInvitationsQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *ShopInvitationsQuery) Limit(limit int) *ShopInvitationsQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *ShopInvitationsQuery) Offset(offset int) *ShopInvitationsQuery { + _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 *ShopInvitationsQuery) Unique(unique bool) *ShopInvitationsQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *ShopInvitationsQuery) Order(o ...shopinvitations.OrderOption) *ShopInvitationsQuery { + _q.order = append(_q.order, o...) + return _q +} + +// First returns the first ShopInvitations entity from the query. +// Returns a *NotFoundError when no ShopInvitations was found. +func (_q *ShopInvitationsQuery) First(ctx context.Context) (*ShopInvitations, 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{shopinvitations.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *ShopInvitationsQuery) FirstX(ctx context.Context) *ShopInvitations { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first ShopInvitations ID from the query. +// Returns a *NotFoundError when no ShopInvitations ID was found. +func (_q *ShopInvitationsQuery) 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{shopinvitations.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *ShopInvitationsQuery) FirstIDX(ctx context.Context) int64 { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single ShopInvitations entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one ShopInvitations entity is found. +// Returns a *NotFoundError when no ShopInvitations entities are found. +func (_q *ShopInvitationsQuery) Only(ctx context.Context) (*ShopInvitations, 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{shopinvitations.Label} + default: + return nil, &NotSingularError{shopinvitations.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *ShopInvitationsQuery) OnlyX(ctx context.Context) *ShopInvitations { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only ShopInvitations ID in the query. +// Returns a *NotSingularError when more than one ShopInvitations ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *ShopInvitationsQuery) 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{shopinvitations.Label} + default: + err = &NotSingularError{shopinvitations.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *ShopInvitationsQuery) 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 ShopInvitationsSlice. +func (_q *ShopInvitationsQuery) All(ctx context.Context) ([]*ShopInvitations, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*ShopInvitations, *ShopInvitationsQuery]() + return withInterceptors[[]*ShopInvitations](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *ShopInvitationsQuery) AllX(ctx context.Context) []*ShopInvitations { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of ShopInvitations IDs. +func (_q *ShopInvitationsQuery) 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(shopinvitations.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *ShopInvitationsQuery) 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 *ShopInvitationsQuery) 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[*ShopInvitationsQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *ShopInvitationsQuery) 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 *ShopInvitationsQuery) 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 *ShopInvitationsQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the ShopInvitationsQuery 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 *ShopInvitationsQuery) Clone() *ShopInvitationsQuery { + if _q == nil { + return nil + } + return &ShopInvitationsQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]shopinvitations.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.ShopInvitations{}, _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 { +// ShopID int64 `json:"shop_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.ShopInvitations.Query(). +// GroupBy(shopinvitations.FieldShopID). +// Aggregate(models.Count()). +// Scan(ctx, &v) +func (_q *ShopInvitationsQuery) GroupBy(field string, fields ...string) *ShopInvitationsGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &ShopInvitationsGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = shopinvitations.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 { +// ShopID int64 `json:"shop_id,omitempty"` +// } +// +// client.ShopInvitations.Query(). +// Select(shopinvitations.FieldShopID). +// Scan(ctx, &v) +func (_q *ShopInvitationsQuery) Select(fields ...string) *ShopInvitationsSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &ShopInvitationsSelect{ShopInvitationsQuery: _q} + sbuild.label = shopinvitations.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a ShopInvitationsSelect configured with the given aggregations. +func (_q *ShopInvitationsQuery) Aggregate(fns ...AggregateFunc) *ShopInvitationsSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *ShopInvitationsQuery) 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 !shopinvitations.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 *ShopInvitationsQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ShopInvitations, error) { + var ( + nodes = []*ShopInvitations{} + _spec = _q.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*ShopInvitations).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &ShopInvitations{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 *ShopInvitationsQuery) 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 *ShopInvitationsQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(shopinvitations.Table, shopinvitations.Columns, sqlgraph.NewFieldSpec(shopinvitations.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, shopinvitations.FieldID) + for i := range fields { + if fields[i] != shopinvitations.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 *ShopInvitationsQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(shopinvitations.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = shopinvitations.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 +} + +// ShopInvitationsGroupBy is the group-by builder for ShopInvitations entities. +type ShopInvitationsGroupBy struct { + selector + build *ShopInvitationsQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *ShopInvitationsGroupBy) Aggregate(fns ...AggregateFunc) *ShopInvitationsGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *ShopInvitationsGroupBy) 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[*ShopInvitationsQuery, *ShopInvitationsGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *ShopInvitationsGroupBy) sqlScan(ctx context.Context, root *ShopInvitationsQuery, 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) +} + +// ShopInvitationsSelect is the builder for selecting fields of ShopInvitations entities. +type ShopInvitationsSelect struct { + *ShopInvitationsQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *ShopInvitationsSelect) Aggregate(fns ...AggregateFunc) *ShopInvitationsSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *ShopInvitationsSelect) 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[*ShopInvitationsQuery, *ShopInvitationsSelect](ctx, _s.ShopInvitationsQuery, _s, _s.inters, v) +} + +func (_s *ShopInvitationsSelect) sqlScan(ctx context.Context, root *ShopInvitationsQuery, 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) +} diff --git a/app/shop/rpc/internal/models/shopinvitations_update.go b/app/shop/rpc/internal/models/shopinvitations_update.go new file mode 100644 index 0000000..d361fa8 --- /dev/null +++ b/app/shop/rpc/internal/models/shopinvitations_update.go @@ -0,0 +1,450 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "errors" + "fmt" + "juwan-backend/app/shop/rpc/internal/models/predicate" + "juwan-backend/app/shop/rpc/internal/models/shopinvitations" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// ShopInvitationsUpdate is the builder for updating ShopInvitations entities. +type ShopInvitationsUpdate struct { + config + hooks []Hook + mutation *ShopInvitationsMutation +} + +// Where appends a list predicates to the ShopInvitationsUpdate builder. +func (_u *ShopInvitationsUpdate) Where(ps ...predicate.ShopInvitations) *ShopInvitationsUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetShopID sets the "shop_id" field. +func (_u *ShopInvitationsUpdate) SetShopID(v int64) *ShopInvitationsUpdate { + _u.mutation.ResetShopID() + _u.mutation.SetShopID(v) + return _u +} + +// SetNillableShopID sets the "shop_id" field if the given value is not nil. +func (_u *ShopInvitationsUpdate) SetNillableShopID(v *int64) *ShopInvitationsUpdate { + if v != nil { + _u.SetShopID(*v) + } + return _u +} + +// AddShopID adds value to the "shop_id" field. +func (_u *ShopInvitationsUpdate) AddShopID(v int64) *ShopInvitationsUpdate { + _u.mutation.AddShopID(v) + return _u +} + +// SetPlayerID sets the "player_id" field. +func (_u *ShopInvitationsUpdate) SetPlayerID(v int64) *ShopInvitationsUpdate { + _u.mutation.ResetPlayerID() + _u.mutation.SetPlayerID(v) + return _u +} + +// SetNillablePlayerID sets the "player_id" field if the given value is not nil. +func (_u *ShopInvitationsUpdate) SetNillablePlayerID(v *int64) *ShopInvitationsUpdate { + if v != nil { + _u.SetPlayerID(*v) + } + return _u +} + +// AddPlayerID adds value to the "player_id" field. +func (_u *ShopInvitationsUpdate) AddPlayerID(v int64) *ShopInvitationsUpdate { + _u.mutation.AddPlayerID(v) + return _u +} + +// SetStatus sets the "status" field. +func (_u *ShopInvitationsUpdate) SetStatus(v string) *ShopInvitationsUpdate { + _u.mutation.SetStatus(v) + return _u +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (_u *ShopInvitationsUpdate) SetNillableStatus(v *string) *ShopInvitationsUpdate { + if v != nil { + _u.SetStatus(*v) + } + return _u +} + +// SetInvitedBy sets the "invited_by" field. +func (_u *ShopInvitationsUpdate) SetInvitedBy(v int64) *ShopInvitationsUpdate { + _u.mutation.ResetInvitedBy() + _u.mutation.SetInvitedBy(v) + return _u +} + +// SetNillableInvitedBy sets the "invited_by" field if the given value is not nil. +func (_u *ShopInvitationsUpdate) SetNillableInvitedBy(v *int64) *ShopInvitationsUpdate { + if v != nil { + _u.SetInvitedBy(*v) + } + return _u +} + +// AddInvitedBy adds value to the "invited_by" field. +func (_u *ShopInvitationsUpdate) AddInvitedBy(v int64) *ShopInvitationsUpdate { + _u.mutation.AddInvitedBy(v) + return _u +} + +// SetRespondedAt sets the "responded_at" field. +func (_u *ShopInvitationsUpdate) SetRespondedAt(v time.Time) *ShopInvitationsUpdate { + _u.mutation.SetRespondedAt(v) + return _u +} + +// SetNillableRespondedAt sets the "responded_at" field if the given value is not nil. +func (_u *ShopInvitationsUpdate) SetNillableRespondedAt(v *time.Time) *ShopInvitationsUpdate { + if v != nil { + _u.SetRespondedAt(*v) + } + return _u +} + +// ClearRespondedAt clears the value of the "responded_at" field. +func (_u *ShopInvitationsUpdate) ClearRespondedAt() *ShopInvitationsUpdate { + _u.mutation.ClearRespondedAt() + return _u +} + +// Mutation returns the ShopInvitationsMutation object of the builder. +func (_u *ShopInvitationsUpdate) Mutation() *ShopInvitationsMutation { + return _u.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *ShopInvitationsUpdate) Save(ctx context.Context) (int, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *ShopInvitationsUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *ShopInvitationsUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ShopInvitationsUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ShopInvitationsUpdate) check() error { + if v, ok := _u.mutation.Status(); ok { + if err := shopinvitations.StatusValidator(v); err != nil { + return &ValidationError{Name: "status", err: fmt.Errorf(`models: validator failed for field "ShopInvitations.status": %w`, err)} + } + } + return nil +} + +func (_u *ShopInvitationsUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(shopinvitations.Table, shopinvitations.Columns, sqlgraph.NewFieldSpec(shopinvitations.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.ShopID(); ok { + _spec.SetField(shopinvitations.FieldShopID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedShopID(); ok { + _spec.AddField(shopinvitations.FieldShopID, field.TypeInt64, value) + } + if value, ok := _u.mutation.PlayerID(); ok { + _spec.SetField(shopinvitations.FieldPlayerID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedPlayerID(); ok { + _spec.AddField(shopinvitations.FieldPlayerID, field.TypeInt64, value) + } + if value, ok := _u.mutation.Status(); ok { + _spec.SetField(shopinvitations.FieldStatus, field.TypeString, value) + } + if value, ok := _u.mutation.InvitedBy(); ok { + _spec.SetField(shopinvitations.FieldInvitedBy, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedInvitedBy(); ok { + _spec.AddField(shopinvitations.FieldInvitedBy, field.TypeInt64, value) + } + if value, ok := _u.mutation.RespondedAt(); ok { + _spec.SetField(shopinvitations.FieldRespondedAt, field.TypeTime, value) + } + if _u.mutation.RespondedAtCleared() { + _spec.ClearField(shopinvitations.FieldRespondedAt, field.TypeTime) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{shopinvitations.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// ShopInvitationsUpdateOne is the builder for updating a single ShopInvitations entity. +type ShopInvitationsUpdateOne struct { + config + fields []string + hooks []Hook + mutation *ShopInvitationsMutation +} + +// SetShopID sets the "shop_id" field. +func (_u *ShopInvitationsUpdateOne) SetShopID(v int64) *ShopInvitationsUpdateOne { + _u.mutation.ResetShopID() + _u.mutation.SetShopID(v) + return _u +} + +// SetNillableShopID sets the "shop_id" field if the given value is not nil. +func (_u *ShopInvitationsUpdateOne) SetNillableShopID(v *int64) *ShopInvitationsUpdateOne { + if v != nil { + _u.SetShopID(*v) + } + return _u +} + +// AddShopID adds value to the "shop_id" field. +func (_u *ShopInvitationsUpdateOne) AddShopID(v int64) *ShopInvitationsUpdateOne { + _u.mutation.AddShopID(v) + return _u +} + +// SetPlayerID sets the "player_id" field. +func (_u *ShopInvitationsUpdateOne) SetPlayerID(v int64) *ShopInvitationsUpdateOne { + _u.mutation.ResetPlayerID() + _u.mutation.SetPlayerID(v) + return _u +} + +// SetNillablePlayerID sets the "player_id" field if the given value is not nil. +func (_u *ShopInvitationsUpdateOne) SetNillablePlayerID(v *int64) *ShopInvitationsUpdateOne { + if v != nil { + _u.SetPlayerID(*v) + } + return _u +} + +// AddPlayerID adds value to the "player_id" field. +func (_u *ShopInvitationsUpdateOne) AddPlayerID(v int64) *ShopInvitationsUpdateOne { + _u.mutation.AddPlayerID(v) + return _u +} + +// SetStatus sets the "status" field. +func (_u *ShopInvitationsUpdateOne) SetStatus(v string) *ShopInvitationsUpdateOne { + _u.mutation.SetStatus(v) + return _u +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (_u *ShopInvitationsUpdateOne) SetNillableStatus(v *string) *ShopInvitationsUpdateOne { + if v != nil { + _u.SetStatus(*v) + } + return _u +} + +// SetInvitedBy sets the "invited_by" field. +func (_u *ShopInvitationsUpdateOne) SetInvitedBy(v int64) *ShopInvitationsUpdateOne { + _u.mutation.ResetInvitedBy() + _u.mutation.SetInvitedBy(v) + return _u +} + +// SetNillableInvitedBy sets the "invited_by" field if the given value is not nil. +func (_u *ShopInvitationsUpdateOne) SetNillableInvitedBy(v *int64) *ShopInvitationsUpdateOne { + if v != nil { + _u.SetInvitedBy(*v) + } + return _u +} + +// AddInvitedBy adds value to the "invited_by" field. +func (_u *ShopInvitationsUpdateOne) AddInvitedBy(v int64) *ShopInvitationsUpdateOne { + _u.mutation.AddInvitedBy(v) + return _u +} + +// SetRespondedAt sets the "responded_at" field. +func (_u *ShopInvitationsUpdateOne) SetRespondedAt(v time.Time) *ShopInvitationsUpdateOne { + _u.mutation.SetRespondedAt(v) + return _u +} + +// SetNillableRespondedAt sets the "responded_at" field if the given value is not nil. +func (_u *ShopInvitationsUpdateOne) SetNillableRespondedAt(v *time.Time) *ShopInvitationsUpdateOne { + if v != nil { + _u.SetRespondedAt(*v) + } + return _u +} + +// ClearRespondedAt clears the value of the "responded_at" field. +func (_u *ShopInvitationsUpdateOne) ClearRespondedAt() *ShopInvitationsUpdateOne { + _u.mutation.ClearRespondedAt() + return _u +} + +// Mutation returns the ShopInvitationsMutation object of the builder. +func (_u *ShopInvitationsUpdateOne) Mutation() *ShopInvitationsMutation { + return _u.mutation +} + +// Where appends a list predicates to the ShopInvitationsUpdate builder. +func (_u *ShopInvitationsUpdateOne) Where(ps ...predicate.ShopInvitations) *ShopInvitationsUpdateOne { + _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 *ShopInvitationsUpdateOne) Select(field string, fields ...string) *ShopInvitationsUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated ShopInvitations entity. +func (_u *ShopInvitationsUpdateOne) Save(ctx context.Context) (*ShopInvitations, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *ShopInvitationsUpdateOne) SaveX(ctx context.Context) *ShopInvitations { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *ShopInvitationsUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ShopInvitationsUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ShopInvitationsUpdateOne) check() error { + if v, ok := _u.mutation.Status(); ok { + if err := shopinvitations.StatusValidator(v); err != nil { + return &ValidationError{Name: "status", err: fmt.Errorf(`models: validator failed for field "ShopInvitations.status": %w`, err)} + } + } + return nil +} + +func (_u *ShopInvitationsUpdateOne) sqlSave(ctx context.Context) (_node *ShopInvitations, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(shopinvitations.Table, shopinvitations.Columns, sqlgraph.NewFieldSpec(shopinvitations.FieldID, field.TypeInt64)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "ShopInvitations.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, shopinvitations.FieldID) + for _, f := range fields { + if !shopinvitations.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)} + } + if f != shopinvitations.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.ShopID(); ok { + _spec.SetField(shopinvitations.FieldShopID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedShopID(); ok { + _spec.AddField(shopinvitations.FieldShopID, field.TypeInt64, value) + } + if value, ok := _u.mutation.PlayerID(); ok { + _spec.SetField(shopinvitations.FieldPlayerID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedPlayerID(); ok { + _spec.AddField(shopinvitations.FieldPlayerID, field.TypeInt64, value) + } + if value, ok := _u.mutation.Status(); ok { + _spec.SetField(shopinvitations.FieldStatus, field.TypeString, value) + } + if value, ok := _u.mutation.InvitedBy(); ok { + _spec.SetField(shopinvitations.FieldInvitedBy, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedInvitedBy(); ok { + _spec.AddField(shopinvitations.FieldInvitedBy, field.TypeInt64, value) + } + if value, ok := _u.mutation.RespondedAt(); ok { + _spec.SetField(shopinvitations.FieldRespondedAt, field.TypeTime, value) + } + if _u.mutation.RespondedAtCleared() { + _spec.ClearField(shopinvitations.FieldRespondedAt, field.TypeTime) + } + _node = &ShopInvitations{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{shopinvitations.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/app/shop/rpc/internal/models/shopplayers.go b/app/shop/rpc/internal/models/shopplayers.go new file mode 100644 index 0000000..51cee24 --- /dev/null +++ b/app/shop/rpc/internal/models/shopplayers.go @@ -0,0 +1,153 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "fmt" + "juwan-backend/app/shop/rpc/internal/models/shopplayers" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" +) + +// ShopPlayers is the model entity for the ShopPlayers schema. +type ShopPlayers struct { + config `json:"-"` + // ID of the ent. + ID int64 `json:"id,omitempty"` + // ShopID holds the value of the "shop_id" field. + ShopID int64 `json:"shop_id,omitempty"` + // PlayerID holds the value of the "player_id" field. + PlayerID int64 `json:"player_id,omitempty"` + // IsPrimary holds the value of the "is_primary" field. + IsPrimary bool `json:"is_primary,omitempty"` + // JoinedAt holds the value of the "joined_at" field. + JoinedAt time.Time `json:"joined_at,omitempty"` + // LeftAt holds the value of the "left_at" field. + LeftAt *time.Time `json:"left_at,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*ShopPlayers) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case shopplayers.FieldIsPrimary: + values[i] = new(sql.NullBool) + case shopplayers.FieldID, shopplayers.FieldShopID, shopplayers.FieldPlayerID: + values[i] = new(sql.NullInt64) + case shopplayers.FieldJoinedAt, shopplayers.FieldLeftAt: + 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 ShopPlayers fields. +func (_m *ShopPlayers) 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 shopplayers.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 shopplayers.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 = value.Int64 + } + case shopplayers.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 shopplayers.FieldIsPrimary: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field is_primary", values[i]) + } else if value.Valid { + _m.IsPrimary = value.Bool + } + case shopplayers.FieldJoinedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field joined_at", values[i]) + } else if value.Valid { + _m.JoinedAt = value.Time + } + case shopplayers.FieldLeftAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field left_at", values[i]) + } else if value.Valid { + _m.LeftAt = new(time.Time) + *_m.LeftAt = 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 ShopPlayers. +// This includes values selected through modifiers, order, etc. +func (_m *ShopPlayers) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// Update returns a builder for updating this ShopPlayers. +// Note that you need to call ShopPlayers.Unwrap() before calling this method if this ShopPlayers +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *ShopPlayers) Update() *ShopPlayersUpdateOne { + return NewShopPlayersClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the ShopPlayers 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 *ShopPlayers) Unwrap() *ShopPlayers { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("models: ShopPlayers is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *ShopPlayers) String() string { + var builder strings.Builder + builder.WriteString("ShopPlayers(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("shop_id=") + builder.WriteString(fmt.Sprintf("%v", _m.ShopID)) + builder.WriteString(", ") + builder.WriteString("player_id=") + builder.WriteString(fmt.Sprintf("%v", _m.PlayerID)) + builder.WriteString(", ") + builder.WriteString("is_primary=") + builder.WriteString(fmt.Sprintf("%v", _m.IsPrimary)) + builder.WriteString(", ") + builder.WriteString("joined_at=") + builder.WriteString(_m.JoinedAt.Format(time.ANSIC)) + builder.WriteString(", ") + if v := _m.LeftAt; v != nil { + builder.WriteString("left_at=") + builder.WriteString(v.Format(time.ANSIC)) + } + builder.WriteByte(')') + return builder.String() +} + +// ShopPlayersSlice is a parsable slice of ShopPlayers. +type ShopPlayersSlice []*ShopPlayers diff --git a/app/shop/rpc/internal/models/shopplayers/shopplayers.go b/app/shop/rpc/internal/models/shopplayers/shopplayers.go new file mode 100644 index 0000000..1d7eae6 --- /dev/null +++ b/app/shop/rpc/internal/models/shopplayers/shopplayers.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package shopplayers + +import ( + "time" + + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the shopplayers type in the database. + Label = "shop_players" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldShopID holds the string denoting the shop_id field in the database. + FieldShopID = "shop_id" + // FieldPlayerID holds the string denoting the player_id field in the database. + FieldPlayerID = "player_id" + // FieldIsPrimary holds the string denoting the is_primary field in the database. + FieldIsPrimary = "is_primary" + // FieldJoinedAt holds the string denoting the joined_at field in the database. + FieldJoinedAt = "joined_at" + // FieldLeftAt holds the string denoting the left_at field in the database. + FieldLeftAt = "left_at" + // Table holds the table name of the shopplayers in the database. + Table = "shop_players" +) + +// Columns holds all SQL columns for shopplayers fields. +var Columns = []string{ + FieldID, + FieldShopID, + FieldPlayerID, + FieldIsPrimary, + FieldJoinedAt, + FieldLeftAt, +} + +// 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 ( + // DefaultIsPrimary holds the default value on creation for the "is_primary" field. + DefaultIsPrimary bool + // DefaultJoinedAt holds the default value on creation for the "joined_at" field. + DefaultJoinedAt func() time.Time +) + +// OrderOption defines the ordering options for the ShopPlayers 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() +} + +// ByShopID orders the results by the shop_id field. +func ByShopID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldShopID, opts...).ToFunc() +} + +// ByPlayerID orders the results by the player_id field. +func ByPlayerID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPlayerID, opts...).ToFunc() +} + +// ByIsPrimary orders the results by the is_primary field. +func ByIsPrimary(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIsPrimary, opts...).ToFunc() +} + +// ByJoinedAt orders the results by the joined_at field. +func ByJoinedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldJoinedAt, opts...).ToFunc() +} + +// ByLeftAt orders the results by the left_at field. +func ByLeftAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldLeftAt, opts...).ToFunc() +} diff --git a/app/shop/rpc/internal/models/shopplayers/where.go b/app/shop/rpc/internal/models/shopplayers/where.go new file mode 100644 index 0000000..42c4523 --- /dev/null +++ b/app/shop/rpc/internal/models/shopplayers/where.go @@ -0,0 +1,285 @@ +// Code generated by ent, DO NOT EDIT. + +package shopplayers + +import ( + "juwan-backend/app/shop/rpc/internal/models/predicate" + "time" + + "entgo.io/ent/dialect/sql" +) + +// ID filters vertices based on their ID field. +func ID(id int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldLTE(FieldID, id)) +} + +// ShopID applies equality check predicate on the "shop_id" field. It's identical to ShopIDEQ. +func ShopID(v int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldEQ(FieldShopID, v)) +} + +// PlayerID applies equality check predicate on the "player_id" field. It's identical to PlayerIDEQ. +func PlayerID(v int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldEQ(FieldPlayerID, v)) +} + +// IsPrimary applies equality check predicate on the "is_primary" field. It's identical to IsPrimaryEQ. +func IsPrimary(v bool) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldEQ(FieldIsPrimary, v)) +} + +// JoinedAt applies equality check predicate on the "joined_at" field. It's identical to JoinedAtEQ. +func JoinedAt(v time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldEQ(FieldJoinedAt, v)) +} + +// LeftAt applies equality check predicate on the "left_at" field. It's identical to LeftAtEQ. +func LeftAt(v time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldEQ(FieldLeftAt, v)) +} + +// ShopIDEQ applies the EQ predicate on the "shop_id" field. +func ShopIDEQ(v int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldEQ(FieldShopID, v)) +} + +// ShopIDNEQ applies the NEQ predicate on the "shop_id" field. +func ShopIDNEQ(v int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldNEQ(FieldShopID, v)) +} + +// ShopIDIn applies the In predicate on the "shop_id" field. +func ShopIDIn(vs ...int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldIn(FieldShopID, vs...)) +} + +// ShopIDNotIn applies the NotIn predicate on the "shop_id" field. +func ShopIDNotIn(vs ...int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldNotIn(FieldShopID, vs...)) +} + +// ShopIDGT applies the GT predicate on the "shop_id" field. +func ShopIDGT(v int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldGT(FieldShopID, v)) +} + +// ShopIDGTE applies the GTE predicate on the "shop_id" field. +func ShopIDGTE(v int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldGTE(FieldShopID, v)) +} + +// ShopIDLT applies the LT predicate on the "shop_id" field. +func ShopIDLT(v int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldLT(FieldShopID, v)) +} + +// ShopIDLTE applies the LTE predicate on the "shop_id" field. +func ShopIDLTE(v int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldLTE(FieldShopID, v)) +} + +// PlayerIDEQ applies the EQ predicate on the "player_id" field. +func PlayerIDEQ(v int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldEQ(FieldPlayerID, v)) +} + +// PlayerIDNEQ applies the NEQ predicate on the "player_id" field. +func PlayerIDNEQ(v int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldNEQ(FieldPlayerID, v)) +} + +// PlayerIDIn applies the In predicate on the "player_id" field. +func PlayerIDIn(vs ...int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldIn(FieldPlayerID, vs...)) +} + +// PlayerIDNotIn applies the NotIn predicate on the "player_id" field. +func PlayerIDNotIn(vs ...int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldNotIn(FieldPlayerID, vs...)) +} + +// PlayerIDGT applies the GT predicate on the "player_id" field. +func PlayerIDGT(v int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldGT(FieldPlayerID, v)) +} + +// PlayerIDGTE applies the GTE predicate on the "player_id" field. +func PlayerIDGTE(v int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldGTE(FieldPlayerID, v)) +} + +// PlayerIDLT applies the LT predicate on the "player_id" field. +func PlayerIDLT(v int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldLT(FieldPlayerID, v)) +} + +// PlayerIDLTE applies the LTE predicate on the "player_id" field. +func PlayerIDLTE(v int64) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldLTE(FieldPlayerID, v)) +} + +// IsPrimaryEQ applies the EQ predicate on the "is_primary" field. +func IsPrimaryEQ(v bool) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldEQ(FieldIsPrimary, v)) +} + +// IsPrimaryNEQ applies the NEQ predicate on the "is_primary" field. +func IsPrimaryNEQ(v bool) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldNEQ(FieldIsPrimary, v)) +} + +// IsPrimaryIsNil applies the IsNil predicate on the "is_primary" field. +func IsPrimaryIsNil() predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldIsNull(FieldIsPrimary)) +} + +// IsPrimaryNotNil applies the NotNil predicate on the "is_primary" field. +func IsPrimaryNotNil() predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldNotNull(FieldIsPrimary)) +} + +// JoinedAtEQ applies the EQ predicate on the "joined_at" field. +func JoinedAtEQ(v time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldEQ(FieldJoinedAt, v)) +} + +// JoinedAtNEQ applies the NEQ predicate on the "joined_at" field. +func JoinedAtNEQ(v time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldNEQ(FieldJoinedAt, v)) +} + +// JoinedAtIn applies the In predicate on the "joined_at" field. +func JoinedAtIn(vs ...time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldIn(FieldJoinedAt, vs...)) +} + +// JoinedAtNotIn applies the NotIn predicate on the "joined_at" field. +func JoinedAtNotIn(vs ...time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldNotIn(FieldJoinedAt, vs...)) +} + +// JoinedAtGT applies the GT predicate on the "joined_at" field. +func JoinedAtGT(v time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldGT(FieldJoinedAt, v)) +} + +// JoinedAtGTE applies the GTE predicate on the "joined_at" field. +func JoinedAtGTE(v time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldGTE(FieldJoinedAt, v)) +} + +// JoinedAtLT applies the LT predicate on the "joined_at" field. +func JoinedAtLT(v time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldLT(FieldJoinedAt, v)) +} + +// JoinedAtLTE applies the LTE predicate on the "joined_at" field. +func JoinedAtLTE(v time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldLTE(FieldJoinedAt, v)) +} + +// LeftAtEQ applies the EQ predicate on the "left_at" field. +func LeftAtEQ(v time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldEQ(FieldLeftAt, v)) +} + +// LeftAtNEQ applies the NEQ predicate on the "left_at" field. +func LeftAtNEQ(v time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldNEQ(FieldLeftAt, v)) +} + +// LeftAtIn applies the In predicate on the "left_at" field. +func LeftAtIn(vs ...time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldIn(FieldLeftAt, vs...)) +} + +// LeftAtNotIn applies the NotIn predicate on the "left_at" field. +func LeftAtNotIn(vs ...time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldNotIn(FieldLeftAt, vs...)) +} + +// LeftAtGT applies the GT predicate on the "left_at" field. +func LeftAtGT(v time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldGT(FieldLeftAt, v)) +} + +// LeftAtGTE applies the GTE predicate on the "left_at" field. +func LeftAtGTE(v time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldGTE(FieldLeftAt, v)) +} + +// LeftAtLT applies the LT predicate on the "left_at" field. +func LeftAtLT(v time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldLT(FieldLeftAt, v)) +} + +// LeftAtLTE applies the LTE predicate on the "left_at" field. +func LeftAtLTE(v time.Time) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldLTE(FieldLeftAt, v)) +} + +// LeftAtIsNil applies the IsNil predicate on the "left_at" field. +func LeftAtIsNil() predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldIsNull(FieldLeftAt)) +} + +// LeftAtNotNil applies the NotNil predicate on the "left_at" field. +func LeftAtNotNil() predicate.ShopPlayers { + return predicate.ShopPlayers(sql.FieldNotNull(FieldLeftAt)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.ShopPlayers) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.ShopPlayers) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.ShopPlayers) predicate.ShopPlayers { + return predicate.ShopPlayers(sql.NotPredicates(p)) +} diff --git a/app/shop/rpc/internal/models/shopplayers_create.go b/app/shop/rpc/internal/models/shopplayers_create.go new file mode 100644 index 0000000..d21016f --- /dev/null +++ b/app/shop/rpc/internal/models/shopplayers_create.go @@ -0,0 +1,280 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "errors" + "fmt" + "juwan-backend/app/shop/rpc/internal/models/shopplayers" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// ShopPlayersCreate is the builder for creating a ShopPlayers entity. +type ShopPlayersCreate struct { + config + mutation *ShopPlayersMutation + hooks []Hook +} + +// SetShopID sets the "shop_id" field. +func (_c *ShopPlayersCreate) SetShopID(v int64) *ShopPlayersCreate { + _c.mutation.SetShopID(v) + return _c +} + +// SetPlayerID sets the "player_id" field. +func (_c *ShopPlayersCreate) SetPlayerID(v int64) *ShopPlayersCreate { + _c.mutation.SetPlayerID(v) + return _c +} + +// SetIsPrimary sets the "is_primary" field. +func (_c *ShopPlayersCreate) SetIsPrimary(v bool) *ShopPlayersCreate { + _c.mutation.SetIsPrimary(v) + return _c +} + +// SetNillableIsPrimary sets the "is_primary" field if the given value is not nil. +func (_c *ShopPlayersCreate) SetNillableIsPrimary(v *bool) *ShopPlayersCreate { + if v != nil { + _c.SetIsPrimary(*v) + } + return _c +} + +// SetJoinedAt sets the "joined_at" field. +func (_c *ShopPlayersCreate) SetJoinedAt(v time.Time) *ShopPlayersCreate { + _c.mutation.SetJoinedAt(v) + return _c +} + +// SetNillableJoinedAt sets the "joined_at" field if the given value is not nil. +func (_c *ShopPlayersCreate) SetNillableJoinedAt(v *time.Time) *ShopPlayersCreate { + if v != nil { + _c.SetJoinedAt(*v) + } + return _c +} + +// SetLeftAt sets the "left_at" field. +func (_c *ShopPlayersCreate) SetLeftAt(v time.Time) *ShopPlayersCreate { + _c.mutation.SetLeftAt(v) + return _c +} + +// SetNillableLeftAt sets the "left_at" field if the given value is not nil. +func (_c *ShopPlayersCreate) SetNillableLeftAt(v *time.Time) *ShopPlayersCreate { + if v != nil { + _c.SetLeftAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *ShopPlayersCreate) SetID(v int64) *ShopPlayersCreate { + _c.mutation.SetID(v) + return _c +} + +// Mutation returns the ShopPlayersMutation object of the builder. +func (_c *ShopPlayersCreate) Mutation() *ShopPlayersMutation { + return _c.mutation +} + +// Save creates the ShopPlayers in the database. +func (_c *ShopPlayersCreate) Save(ctx context.Context) (*ShopPlayers, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *ShopPlayersCreate) SaveX(ctx context.Context) *ShopPlayers { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ShopPlayersCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ShopPlayersCreate) 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 *ShopPlayersCreate) defaults() { + if _, ok := _c.mutation.IsPrimary(); !ok { + v := shopplayers.DefaultIsPrimary + _c.mutation.SetIsPrimary(v) + } + if _, ok := _c.mutation.JoinedAt(); !ok { + v := shopplayers.DefaultJoinedAt() + _c.mutation.SetJoinedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *ShopPlayersCreate) check() error { + if _, ok := _c.mutation.ShopID(); !ok { + return &ValidationError{Name: "shop_id", err: errors.New(`models: missing required field "ShopPlayers.shop_id"`)} + } + if _, ok := _c.mutation.PlayerID(); !ok { + return &ValidationError{Name: "player_id", err: errors.New(`models: missing required field "ShopPlayers.player_id"`)} + } + if _, ok := _c.mutation.JoinedAt(); !ok { + return &ValidationError{Name: "joined_at", err: errors.New(`models: missing required field "ShopPlayers.joined_at"`)} + } + return nil +} + +func (_c *ShopPlayersCreate) sqlSave(ctx context.Context) (*ShopPlayers, 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 *ShopPlayersCreate) createSpec() (*ShopPlayers, *sqlgraph.CreateSpec) { + var ( + _node = &ShopPlayers{config: _c.config} + _spec = sqlgraph.NewCreateSpec(shopplayers.Table, sqlgraph.NewFieldSpec(shopplayers.FieldID, field.TypeInt64)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := _c.mutation.ShopID(); ok { + _spec.SetField(shopplayers.FieldShopID, field.TypeInt64, value) + _node.ShopID = value + } + if value, ok := _c.mutation.PlayerID(); ok { + _spec.SetField(shopplayers.FieldPlayerID, field.TypeInt64, value) + _node.PlayerID = value + } + if value, ok := _c.mutation.IsPrimary(); ok { + _spec.SetField(shopplayers.FieldIsPrimary, field.TypeBool, value) + _node.IsPrimary = value + } + if value, ok := _c.mutation.JoinedAt(); ok { + _spec.SetField(shopplayers.FieldJoinedAt, field.TypeTime, value) + _node.JoinedAt = value + } + if value, ok := _c.mutation.LeftAt(); ok { + _spec.SetField(shopplayers.FieldLeftAt, field.TypeTime, value) + _node.LeftAt = &value + } + return _node, _spec +} + +// ShopPlayersCreateBulk is the builder for creating many ShopPlayers entities in bulk. +type ShopPlayersCreateBulk struct { + config + err error + builders []*ShopPlayersCreate +} + +// Save creates the ShopPlayers entities in the database. +func (_c *ShopPlayersCreateBulk) Save(ctx context.Context) ([]*ShopPlayers, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*ShopPlayers, 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.(*ShopPlayersMutation) + 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 *ShopPlayersCreateBulk) SaveX(ctx context.Context) []*ShopPlayers { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ShopPlayersCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ShopPlayersCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/app/shop/rpc/internal/models/shopplayers_delete.go b/app/shop/rpc/internal/models/shopplayers_delete.go new file mode 100644 index 0000000..0517b17 --- /dev/null +++ b/app/shop/rpc/internal/models/shopplayers_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "juwan-backend/app/shop/rpc/internal/models/predicate" + "juwan-backend/app/shop/rpc/internal/models/shopplayers" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// ShopPlayersDelete is the builder for deleting a ShopPlayers entity. +type ShopPlayersDelete struct { + config + hooks []Hook + mutation *ShopPlayersMutation +} + +// Where appends a list predicates to the ShopPlayersDelete builder. +func (_d *ShopPlayersDelete) Where(ps ...predicate.ShopPlayers) *ShopPlayersDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *ShopPlayersDelete) 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 *ShopPlayersDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *ShopPlayersDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(shopplayers.Table, sqlgraph.NewFieldSpec(shopplayers.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 +} + +// ShopPlayersDeleteOne is the builder for deleting a single ShopPlayers entity. +type ShopPlayersDeleteOne struct { + _d *ShopPlayersDelete +} + +// Where appends a list predicates to the ShopPlayersDelete builder. +func (_d *ShopPlayersDeleteOne) Where(ps ...predicate.ShopPlayers) *ShopPlayersDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *ShopPlayersDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{shopplayers.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *ShopPlayersDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/app/shop/rpc/internal/models/shopplayers_query.go b/app/shop/rpc/internal/models/shopplayers_query.go new file mode 100644 index 0000000..caf5c4c --- /dev/null +++ b/app/shop/rpc/internal/models/shopplayers_query.go @@ -0,0 +1,527 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "fmt" + "juwan-backend/app/shop/rpc/internal/models/predicate" + "juwan-backend/app/shop/rpc/internal/models/shopplayers" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// ShopPlayersQuery is the builder for querying ShopPlayers entities. +type ShopPlayersQuery struct { + config + ctx *QueryContext + order []shopplayers.OrderOption + inters []Interceptor + predicates []predicate.ShopPlayers + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the ShopPlayersQuery builder. +func (_q *ShopPlayersQuery) Where(ps ...predicate.ShopPlayers) *ShopPlayersQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *ShopPlayersQuery) Limit(limit int) *ShopPlayersQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *ShopPlayersQuery) Offset(offset int) *ShopPlayersQuery { + _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 *ShopPlayersQuery) Unique(unique bool) *ShopPlayersQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *ShopPlayersQuery) Order(o ...shopplayers.OrderOption) *ShopPlayersQuery { + _q.order = append(_q.order, o...) + return _q +} + +// First returns the first ShopPlayers entity from the query. +// Returns a *NotFoundError when no ShopPlayers was found. +func (_q *ShopPlayersQuery) First(ctx context.Context) (*ShopPlayers, 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{shopplayers.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *ShopPlayersQuery) FirstX(ctx context.Context) *ShopPlayers { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first ShopPlayers ID from the query. +// Returns a *NotFoundError when no ShopPlayers ID was found. +func (_q *ShopPlayersQuery) 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{shopplayers.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *ShopPlayersQuery) FirstIDX(ctx context.Context) int64 { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single ShopPlayers entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one ShopPlayers entity is found. +// Returns a *NotFoundError when no ShopPlayers entities are found. +func (_q *ShopPlayersQuery) Only(ctx context.Context) (*ShopPlayers, 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{shopplayers.Label} + default: + return nil, &NotSingularError{shopplayers.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *ShopPlayersQuery) OnlyX(ctx context.Context) *ShopPlayers { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only ShopPlayers ID in the query. +// Returns a *NotSingularError when more than one ShopPlayers ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *ShopPlayersQuery) 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{shopplayers.Label} + default: + err = &NotSingularError{shopplayers.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *ShopPlayersQuery) 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 ShopPlayersSlice. +func (_q *ShopPlayersQuery) All(ctx context.Context) ([]*ShopPlayers, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*ShopPlayers, *ShopPlayersQuery]() + return withInterceptors[[]*ShopPlayers](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *ShopPlayersQuery) AllX(ctx context.Context) []*ShopPlayers { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of ShopPlayers IDs. +func (_q *ShopPlayersQuery) 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(shopplayers.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *ShopPlayersQuery) 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 *ShopPlayersQuery) 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[*ShopPlayersQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *ShopPlayersQuery) 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 *ShopPlayersQuery) 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 *ShopPlayersQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the ShopPlayersQuery 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 *ShopPlayersQuery) Clone() *ShopPlayersQuery { + if _q == nil { + return nil + } + return &ShopPlayersQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]shopplayers.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.ShopPlayers{}, _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 { +// ShopID int64 `json:"shop_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.ShopPlayers.Query(). +// GroupBy(shopplayers.FieldShopID). +// Aggregate(models.Count()). +// Scan(ctx, &v) +func (_q *ShopPlayersQuery) GroupBy(field string, fields ...string) *ShopPlayersGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &ShopPlayersGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = shopplayers.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 { +// ShopID int64 `json:"shop_id,omitempty"` +// } +// +// client.ShopPlayers.Query(). +// Select(shopplayers.FieldShopID). +// Scan(ctx, &v) +func (_q *ShopPlayersQuery) Select(fields ...string) *ShopPlayersSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &ShopPlayersSelect{ShopPlayersQuery: _q} + sbuild.label = shopplayers.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a ShopPlayersSelect configured with the given aggregations. +func (_q *ShopPlayersQuery) Aggregate(fns ...AggregateFunc) *ShopPlayersSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *ShopPlayersQuery) 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 !shopplayers.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 *ShopPlayersQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ShopPlayers, error) { + var ( + nodes = []*ShopPlayers{} + _spec = _q.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*ShopPlayers).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &ShopPlayers{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 *ShopPlayersQuery) 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 *ShopPlayersQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(shopplayers.Table, shopplayers.Columns, sqlgraph.NewFieldSpec(shopplayers.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, shopplayers.FieldID) + for i := range fields { + if fields[i] != shopplayers.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 *ShopPlayersQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(shopplayers.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = shopplayers.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 +} + +// ShopPlayersGroupBy is the group-by builder for ShopPlayers entities. +type ShopPlayersGroupBy struct { + selector + build *ShopPlayersQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *ShopPlayersGroupBy) Aggregate(fns ...AggregateFunc) *ShopPlayersGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *ShopPlayersGroupBy) 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[*ShopPlayersQuery, *ShopPlayersGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *ShopPlayersGroupBy) sqlScan(ctx context.Context, root *ShopPlayersQuery, 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) +} + +// ShopPlayersSelect is the builder for selecting fields of ShopPlayers entities. +type ShopPlayersSelect struct { + *ShopPlayersQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *ShopPlayersSelect) Aggregate(fns ...AggregateFunc) *ShopPlayersSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *ShopPlayersSelect) 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[*ShopPlayersQuery, *ShopPlayersSelect](ctx, _s.ShopPlayersQuery, _s, _s.inters, v) +} + +func (_s *ShopPlayersSelect) sqlScan(ctx context.Context, root *ShopPlayersQuery, 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) +} diff --git a/app/shop/rpc/internal/models/shopplayers_update.go b/app/shop/rpc/internal/models/shopplayers_update.go new file mode 100644 index 0000000..c2d0af2 --- /dev/null +++ b/app/shop/rpc/internal/models/shopplayers_update.go @@ -0,0 +1,388 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "errors" + "fmt" + "juwan-backend/app/shop/rpc/internal/models/predicate" + "juwan-backend/app/shop/rpc/internal/models/shopplayers" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// ShopPlayersUpdate is the builder for updating ShopPlayers entities. +type ShopPlayersUpdate struct { + config + hooks []Hook + mutation *ShopPlayersMutation +} + +// Where appends a list predicates to the ShopPlayersUpdate builder. +func (_u *ShopPlayersUpdate) Where(ps ...predicate.ShopPlayers) *ShopPlayersUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetShopID sets the "shop_id" field. +func (_u *ShopPlayersUpdate) SetShopID(v int64) *ShopPlayersUpdate { + _u.mutation.ResetShopID() + _u.mutation.SetShopID(v) + return _u +} + +// SetNillableShopID sets the "shop_id" field if the given value is not nil. +func (_u *ShopPlayersUpdate) SetNillableShopID(v *int64) *ShopPlayersUpdate { + if v != nil { + _u.SetShopID(*v) + } + return _u +} + +// AddShopID adds value to the "shop_id" field. +func (_u *ShopPlayersUpdate) AddShopID(v int64) *ShopPlayersUpdate { + _u.mutation.AddShopID(v) + return _u +} + +// SetPlayerID sets the "player_id" field. +func (_u *ShopPlayersUpdate) SetPlayerID(v int64) *ShopPlayersUpdate { + _u.mutation.ResetPlayerID() + _u.mutation.SetPlayerID(v) + return _u +} + +// SetNillablePlayerID sets the "player_id" field if the given value is not nil. +func (_u *ShopPlayersUpdate) SetNillablePlayerID(v *int64) *ShopPlayersUpdate { + if v != nil { + _u.SetPlayerID(*v) + } + return _u +} + +// AddPlayerID adds value to the "player_id" field. +func (_u *ShopPlayersUpdate) AddPlayerID(v int64) *ShopPlayersUpdate { + _u.mutation.AddPlayerID(v) + return _u +} + +// SetIsPrimary sets the "is_primary" field. +func (_u *ShopPlayersUpdate) SetIsPrimary(v bool) *ShopPlayersUpdate { + _u.mutation.SetIsPrimary(v) + return _u +} + +// SetNillableIsPrimary sets the "is_primary" field if the given value is not nil. +func (_u *ShopPlayersUpdate) SetNillableIsPrimary(v *bool) *ShopPlayersUpdate { + if v != nil { + _u.SetIsPrimary(*v) + } + return _u +} + +// ClearIsPrimary clears the value of the "is_primary" field. +func (_u *ShopPlayersUpdate) ClearIsPrimary() *ShopPlayersUpdate { + _u.mutation.ClearIsPrimary() + return _u +} + +// SetLeftAt sets the "left_at" field. +func (_u *ShopPlayersUpdate) SetLeftAt(v time.Time) *ShopPlayersUpdate { + _u.mutation.SetLeftAt(v) + return _u +} + +// SetNillableLeftAt sets the "left_at" field if the given value is not nil. +func (_u *ShopPlayersUpdate) SetNillableLeftAt(v *time.Time) *ShopPlayersUpdate { + if v != nil { + _u.SetLeftAt(*v) + } + return _u +} + +// ClearLeftAt clears the value of the "left_at" field. +func (_u *ShopPlayersUpdate) ClearLeftAt() *ShopPlayersUpdate { + _u.mutation.ClearLeftAt() + return _u +} + +// Mutation returns the ShopPlayersMutation object of the builder. +func (_u *ShopPlayersUpdate) Mutation() *ShopPlayersMutation { + return _u.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *ShopPlayersUpdate) Save(ctx context.Context) (int, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *ShopPlayersUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *ShopPlayersUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ShopPlayersUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +func (_u *ShopPlayersUpdate) sqlSave(ctx context.Context) (_node int, err error) { + _spec := sqlgraph.NewUpdateSpec(shopplayers.Table, shopplayers.Columns, sqlgraph.NewFieldSpec(shopplayers.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.ShopID(); ok { + _spec.SetField(shopplayers.FieldShopID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedShopID(); ok { + _spec.AddField(shopplayers.FieldShopID, field.TypeInt64, value) + } + if value, ok := _u.mutation.PlayerID(); ok { + _spec.SetField(shopplayers.FieldPlayerID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedPlayerID(); ok { + _spec.AddField(shopplayers.FieldPlayerID, field.TypeInt64, value) + } + if value, ok := _u.mutation.IsPrimary(); ok { + _spec.SetField(shopplayers.FieldIsPrimary, field.TypeBool, value) + } + if _u.mutation.IsPrimaryCleared() { + _spec.ClearField(shopplayers.FieldIsPrimary, field.TypeBool) + } + if value, ok := _u.mutation.LeftAt(); ok { + _spec.SetField(shopplayers.FieldLeftAt, field.TypeTime, value) + } + if _u.mutation.LeftAtCleared() { + _spec.ClearField(shopplayers.FieldLeftAt, field.TypeTime) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{shopplayers.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// ShopPlayersUpdateOne is the builder for updating a single ShopPlayers entity. +type ShopPlayersUpdateOne struct { + config + fields []string + hooks []Hook + mutation *ShopPlayersMutation +} + +// SetShopID sets the "shop_id" field. +func (_u *ShopPlayersUpdateOne) SetShopID(v int64) *ShopPlayersUpdateOne { + _u.mutation.ResetShopID() + _u.mutation.SetShopID(v) + return _u +} + +// SetNillableShopID sets the "shop_id" field if the given value is not nil. +func (_u *ShopPlayersUpdateOne) SetNillableShopID(v *int64) *ShopPlayersUpdateOne { + if v != nil { + _u.SetShopID(*v) + } + return _u +} + +// AddShopID adds value to the "shop_id" field. +func (_u *ShopPlayersUpdateOne) AddShopID(v int64) *ShopPlayersUpdateOne { + _u.mutation.AddShopID(v) + return _u +} + +// SetPlayerID sets the "player_id" field. +func (_u *ShopPlayersUpdateOne) SetPlayerID(v int64) *ShopPlayersUpdateOne { + _u.mutation.ResetPlayerID() + _u.mutation.SetPlayerID(v) + return _u +} + +// SetNillablePlayerID sets the "player_id" field if the given value is not nil. +func (_u *ShopPlayersUpdateOne) SetNillablePlayerID(v *int64) *ShopPlayersUpdateOne { + if v != nil { + _u.SetPlayerID(*v) + } + return _u +} + +// AddPlayerID adds value to the "player_id" field. +func (_u *ShopPlayersUpdateOne) AddPlayerID(v int64) *ShopPlayersUpdateOne { + _u.mutation.AddPlayerID(v) + return _u +} + +// SetIsPrimary sets the "is_primary" field. +func (_u *ShopPlayersUpdateOne) SetIsPrimary(v bool) *ShopPlayersUpdateOne { + _u.mutation.SetIsPrimary(v) + return _u +} + +// SetNillableIsPrimary sets the "is_primary" field if the given value is not nil. +func (_u *ShopPlayersUpdateOne) SetNillableIsPrimary(v *bool) *ShopPlayersUpdateOne { + if v != nil { + _u.SetIsPrimary(*v) + } + return _u +} + +// ClearIsPrimary clears the value of the "is_primary" field. +func (_u *ShopPlayersUpdateOne) ClearIsPrimary() *ShopPlayersUpdateOne { + _u.mutation.ClearIsPrimary() + return _u +} + +// SetLeftAt sets the "left_at" field. +func (_u *ShopPlayersUpdateOne) SetLeftAt(v time.Time) *ShopPlayersUpdateOne { + _u.mutation.SetLeftAt(v) + return _u +} + +// SetNillableLeftAt sets the "left_at" field if the given value is not nil. +func (_u *ShopPlayersUpdateOne) SetNillableLeftAt(v *time.Time) *ShopPlayersUpdateOne { + if v != nil { + _u.SetLeftAt(*v) + } + return _u +} + +// ClearLeftAt clears the value of the "left_at" field. +func (_u *ShopPlayersUpdateOne) ClearLeftAt() *ShopPlayersUpdateOne { + _u.mutation.ClearLeftAt() + return _u +} + +// Mutation returns the ShopPlayersMutation object of the builder. +func (_u *ShopPlayersUpdateOne) Mutation() *ShopPlayersMutation { + return _u.mutation +} + +// Where appends a list predicates to the ShopPlayersUpdate builder. +func (_u *ShopPlayersUpdateOne) Where(ps ...predicate.ShopPlayers) *ShopPlayersUpdateOne { + _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 *ShopPlayersUpdateOne) Select(field string, fields ...string) *ShopPlayersUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated ShopPlayers entity. +func (_u *ShopPlayersUpdateOne) Save(ctx context.Context) (*ShopPlayers, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *ShopPlayersUpdateOne) SaveX(ctx context.Context) *ShopPlayers { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *ShopPlayersUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ShopPlayersUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +func (_u *ShopPlayersUpdateOne) sqlSave(ctx context.Context) (_node *ShopPlayers, err error) { + _spec := sqlgraph.NewUpdateSpec(shopplayers.Table, shopplayers.Columns, sqlgraph.NewFieldSpec(shopplayers.FieldID, field.TypeInt64)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "ShopPlayers.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, shopplayers.FieldID) + for _, f := range fields { + if !shopplayers.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)} + } + if f != shopplayers.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.ShopID(); ok { + _spec.SetField(shopplayers.FieldShopID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedShopID(); ok { + _spec.AddField(shopplayers.FieldShopID, field.TypeInt64, value) + } + if value, ok := _u.mutation.PlayerID(); ok { + _spec.SetField(shopplayers.FieldPlayerID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedPlayerID(); ok { + _spec.AddField(shopplayers.FieldPlayerID, field.TypeInt64, value) + } + if value, ok := _u.mutation.IsPrimary(); ok { + _spec.SetField(shopplayers.FieldIsPrimary, field.TypeBool, value) + } + if _u.mutation.IsPrimaryCleared() { + _spec.ClearField(shopplayers.FieldIsPrimary, field.TypeBool) + } + if value, ok := _u.mutation.LeftAt(); ok { + _spec.SetField(shopplayers.FieldLeftAt, field.TypeTime, value) + } + if _u.mutation.LeftAtCleared() { + _spec.ClearField(shopplayers.FieldLeftAt, field.TypeTime) + } + _node = &ShopPlayers{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{shopplayers.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/app/shop/rpc/internal/models/shops.go b/app/shop/rpc/internal/models/shops.go new file mode 100644 index 0000000..2c4d101 --- /dev/null +++ b/app/shop/rpc/internal/models/shops.go @@ -0,0 +1,289 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "encoding/json" + "fmt" + "juwan-backend/app/shop/rpc/internal/models/shops" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/shopspring/decimal" +) + +// Shops is the model entity for the Shops schema. +type Shops struct { + config `json:"-"` + // ID of the ent. + ID int64 `json:"id,omitempty"` + // OwnerID holds the value of the "owner_id" field. + OwnerID int64 `json:"owner_id,omitempty"` + // Name holds the value of the "name" field. + Name string `json:"name,omitempty"` + // Banner holds the value of the "banner" field. + Banner *string `json:"banner,omitempty"` + // Description holds the value of the "description" field. + Description *string `json:"description,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"` + // PlayerCount holds the value of the "player_count" field. + PlayerCount int `json:"player_count,omitempty"` + // CommissionType holds the value of the "commission_type" field. + CommissionType string `json:"commission_type,omitempty"` + // CommissionValue holds the value of the "commission_value" field. + CommissionValue decimal.Decimal `json:"commission_value,omitempty"` + // AllowMultiShop holds the value of the "allow_multi_shop" field. + AllowMultiShop bool `json:"allow_multi_shop,omitempty"` + // AllowIndependentOrders holds the value of the "allow_independent_orders" field. + AllowIndependentOrders bool `json:"allow_independent_orders,omitempty"` + // DispatchMode holds the value of the "dispatch_mode" field. + DispatchMode string `json:"dispatch_mode,omitempty"` + // Announcements holds the value of the "announcements" field. + Announcements []string `json:"announcements,omitempty"` + // TemplateConfig holds the value of the "template_config" field. + TemplateConfig map[string]interface{} `json:"template_config,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 (*Shops) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case shops.FieldAnnouncements, shops.FieldTemplateConfig: + values[i] = new([]byte) + case shops.FieldRating, shops.FieldCommissionValue: + values[i] = new(decimal.Decimal) + case shops.FieldAllowMultiShop, shops.FieldAllowIndependentOrders: + values[i] = new(sql.NullBool) + case shops.FieldID, shops.FieldOwnerID, shops.FieldTotalOrders, shops.FieldPlayerCount: + values[i] = new(sql.NullInt64) + case shops.FieldName, shops.FieldBanner, shops.FieldDescription, shops.FieldCommissionType, shops.FieldDispatchMode: + values[i] = new(sql.NullString) + case shops.FieldCreatedAt, shops.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 Shops fields. +func (_m *Shops) 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 shops.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 shops.FieldOwnerID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field owner_id", values[i]) + } else if value.Valid { + _m.OwnerID = value.Int64 + } + case shops.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + _m.Name = value.String + } + case shops.FieldBanner: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field banner", values[i]) + } else if value.Valid { + _m.Banner = new(string) + *_m.Banner = value.String + } + case shops.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 shops.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 shops.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 shops.FieldPlayerCount: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field player_count", values[i]) + } else if value.Valid { + _m.PlayerCount = int(value.Int64) + } + case shops.FieldCommissionType: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field commission_type", values[i]) + } else if value.Valid { + _m.CommissionType = value.String + } + case shops.FieldCommissionValue: + if value, ok := values[i].(*decimal.Decimal); !ok { + return fmt.Errorf("unexpected type %T for field commission_value", values[i]) + } else if value != nil { + _m.CommissionValue = *value + } + case shops.FieldAllowMultiShop: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field allow_multi_shop", values[i]) + } else if value.Valid { + _m.AllowMultiShop = value.Bool + } + case shops.FieldAllowIndependentOrders: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field allow_independent_orders", values[i]) + } else if value.Valid { + _m.AllowIndependentOrders = value.Bool + } + case shops.FieldDispatchMode: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field dispatch_mode", values[i]) + } else if value.Valid { + _m.DispatchMode = value.String + } + case shops.FieldAnnouncements: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field announcements", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.Announcements); err != nil { + return fmt.Errorf("unmarshal field announcements: %w", err) + } + } + case shops.FieldTemplateConfig: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field template_config", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.TemplateConfig); err != nil { + return fmt.Errorf("unmarshal field template_config: %w", err) + } + } + case shops.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 shops.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 Shops. +// This includes values selected through modifiers, order, etc. +func (_m *Shops) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// Update returns a builder for updating this Shops. +// Note that you need to call Shops.Unwrap() before calling this method if this Shops +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *Shops) Update() *ShopsUpdateOne { + return NewShopsClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the Shops 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 *Shops) Unwrap() *Shops { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("models: Shops is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *Shops) String() string { + var builder strings.Builder + builder.WriteString("Shops(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("owner_id=") + builder.WriteString(fmt.Sprintf("%v", _m.OwnerID)) + builder.WriteString(", ") + builder.WriteString("name=") + builder.WriteString(_m.Name) + builder.WriteString(", ") + if v := _m.Banner; v != nil { + builder.WriteString("banner=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.Description; v != nil { + builder.WriteString("description=") + builder.WriteString(*v) + } + 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("player_count=") + builder.WriteString(fmt.Sprintf("%v", _m.PlayerCount)) + builder.WriteString(", ") + builder.WriteString("commission_type=") + builder.WriteString(_m.CommissionType) + builder.WriteString(", ") + builder.WriteString("commission_value=") + builder.WriteString(fmt.Sprintf("%v", _m.CommissionValue)) + builder.WriteString(", ") + builder.WriteString("allow_multi_shop=") + builder.WriteString(fmt.Sprintf("%v", _m.AllowMultiShop)) + builder.WriteString(", ") + builder.WriteString("allow_independent_orders=") + builder.WriteString(fmt.Sprintf("%v", _m.AllowIndependentOrders)) + builder.WriteString(", ") + builder.WriteString("dispatch_mode=") + builder.WriteString(_m.DispatchMode) + builder.WriteString(", ") + builder.WriteString("announcements=") + builder.WriteString(fmt.Sprintf("%v", _m.Announcements)) + builder.WriteString(", ") + builder.WriteString("template_config=") + builder.WriteString(fmt.Sprintf("%v", _m.TemplateConfig)) + 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() +} + +// ShopsSlice is a parsable slice of Shops. +type ShopsSlice []*Shops diff --git a/app/shop/rpc/internal/models/shops/shops.go b/app/shop/rpc/internal/models/shops/shops.go new file mode 100644 index 0000000..cf0fa22 --- /dev/null +++ b/app/shop/rpc/internal/models/shops/shops.go @@ -0,0 +1,191 @@ +// Code generated by ent, DO NOT EDIT. + +package shops + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "github.com/shopspring/decimal" +) + +const ( + // Label holds the string label denoting the shops type in the database. + Label = "shops" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldOwnerID holds the string denoting the owner_id field in the database. + FieldOwnerID = "owner_id" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldBanner holds the string denoting the banner field in the database. + FieldBanner = "banner" + // FieldDescription holds the string denoting the description field in the database. + FieldDescription = "description" + // 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" + // FieldPlayerCount holds the string denoting the player_count field in the database. + FieldPlayerCount = "player_count" + // FieldCommissionType holds the string denoting the commission_type field in the database. + FieldCommissionType = "commission_type" + // FieldCommissionValue holds the string denoting the commission_value field in the database. + FieldCommissionValue = "commission_value" + // FieldAllowMultiShop holds the string denoting the allow_multi_shop field in the database. + FieldAllowMultiShop = "allow_multi_shop" + // FieldAllowIndependentOrders holds the string denoting the allow_independent_orders field in the database. + FieldAllowIndependentOrders = "allow_independent_orders" + // FieldDispatchMode holds the string denoting the dispatch_mode field in the database. + FieldDispatchMode = "dispatch_mode" + // FieldAnnouncements holds the string denoting the announcements field in the database. + FieldAnnouncements = "announcements" + // FieldTemplateConfig holds the string denoting the template_config field in the database. + FieldTemplateConfig = "template_config" + // 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 shops in the database. + Table = "shops" +) + +// Columns holds all SQL columns for shops fields. +var Columns = []string{ + FieldID, + FieldOwnerID, + FieldName, + FieldBanner, + FieldDescription, + FieldRating, + FieldTotalOrders, + FieldPlayerCount, + FieldCommissionType, + FieldCommissionValue, + FieldAllowMultiShop, + FieldAllowIndependentOrders, + FieldDispatchMode, + FieldAnnouncements, + FieldTemplateConfig, + FieldCreatedAt, + FieldUpdatedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // NameValidator is a validator for the "name" field. It is called by the builders before save. + NameValidator func(string) error + // 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 + // DefaultPlayerCount holds the default value on creation for the "player_count" field. + DefaultPlayerCount int + // DefaultCommissionType holds the default value on creation for the "commission_type" field. + DefaultCommissionType string + // CommissionTypeValidator is a validator for the "commission_type" field. It is called by the builders before save. + CommissionTypeValidator func(string) error + // DefaultAllowMultiShop holds the default value on creation for the "allow_multi_shop" field. + DefaultAllowMultiShop bool + // DefaultAllowIndependentOrders holds the default value on creation for the "allow_independent_orders" field. + DefaultAllowIndependentOrders bool + // DefaultDispatchMode holds the default value on creation for the "dispatch_mode" field. + DefaultDispatchMode string + // DispatchModeValidator is a validator for the "dispatch_mode" field. It is called by the builders before save. + DispatchModeValidator func(string) error + // DefaultAnnouncements holds the default value on creation for the "announcements" field. + DefaultAnnouncements []string + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt 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 Shops 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() +} + +// ByOwnerID orders the results by the owner_id field. +func ByOwnerID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldOwnerID, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByBanner orders the results by the banner field. +func ByBanner(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldBanner, opts...).ToFunc() +} + +// ByDescription orders the results by the description field. +func ByDescription(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDescription, 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() +} + +// ByPlayerCount orders the results by the player_count field. +func ByPlayerCount(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPlayerCount, opts...).ToFunc() +} + +// ByCommissionType orders the results by the commission_type field. +func ByCommissionType(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCommissionType, opts...).ToFunc() +} + +// ByCommissionValue orders the results by the commission_value field. +func ByCommissionValue(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCommissionValue, opts...).ToFunc() +} + +// ByAllowMultiShop orders the results by the allow_multi_shop field. +func ByAllowMultiShop(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAllowMultiShop, opts...).ToFunc() +} + +// ByAllowIndependentOrders orders the results by the allow_independent_orders field. +func ByAllowIndependentOrders(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAllowIndependentOrders, opts...).ToFunc() +} + +// ByDispatchMode orders the results by the dispatch_mode field. +func ByDispatchMode(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDispatchMode, 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() +} diff --git a/app/shop/rpc/internal/models/shops/where.go b/app/shop/rpc/internal/models/shops/where.go new file mode 100644 index 0000000..13072b8 --- /dev/null +++ b/app/shop/rpc/internal/models/shops/where.go @@ -0,0 +1,856 @@ +// Code generated by ent, DO NOT EDIT. + +package shops + +import ( + "juwan-backend/app/shop/rpc/internal/models/predicate" + "time" + + "entgo.io/ent/dialect/sql" + "github.com/shopspring/decimal" +) + +// ID filters vertices based on their ID field. +func ID(id int64) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int64) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int64) predicate.Shops { + return predicate.Shops(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int64) predicate.Shops { + return predicate.Shops(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int64) predicate.Shops { + return predicate.Shops(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int64) predicate.Shops { + return predicate.Shops(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int64) predicate.Shops { + return predicate.Shops(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int64) predicate.Shops { + return predicate.Shops(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int64) predicate.Shops { + return predicate.Shops(sql.FieldLTE(FieldID, id)) +} + +// OwnerID applies equality check predicate on the "owner_id" field. It's identical to OwnerIDEQ. +func OwnerID(v int64) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldOwnerID, v)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldName, v)) +} + +// Banner applies equality check predicate on the "banner" field. It's identical to BannerEQ. +func Banner(v string) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldBanner, v)) +} + +// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. +func Description(v string) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldDescription, v)) +} + +// Rating applies equality check predicate on the "rating" field. It's identical to RatingEQ. +func Rating(v decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldRating, v)) +} + +// TotalOrders applies equality check predicate on the "total_orders" field. It's identical to TotalOrdersEQ. +func TotalOrders(v int) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldTotalOrders, v)) +} + +// PlayerCount applies equality check predicate on the "player_count" field. It's identical to PlayerCountEQ. +func PlayerCount(v int) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldPlayerCount, v)) +} + +// CommissionType applies equality check predicate on the "commission_type" field. It's identical to CommissionTypeEQ. +func CommissionType(v string) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldCommissionType, v)) +} + +// CommissionValue applies equality check predicate on the "commission_value" field. It's identical to CommissionValueEQ. +func CommissionValue(v decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldCommissionValue, v)) +} + +// AllowMultiShop applies equality check predicate on the "allow_multi_shop" field. It's identical to AllowMultiShopEQ. +func AllowMultiShop(v bool) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldAllowMultiShop, v)) +} + +// AllowIndependentOrders applies equality check predicate on the "allow_independent_orders" field. It's identical to AllowIndependentOrdersEQ. +func AllowIndependentOrders(v bool) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldAllowIndependentOrders, v)) +} + +// DispatchMode applies equality check predicate on the "dispatch_mode" field. It's identical to DispatchModeEQ. +func DispatchMode(v string) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldDispatchMode, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.Shops { + return predicate.Shops(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.Shops { + return predicate.Shops(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// OwnerIDEQ applies the EQ predicate on the "owner_id" field. +func OwnerIDEQ(v int64) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldOwnerID, v)) +} + +// OwnerIDNEQ applies the NEQ predicate on the "owner_id" field. +func OwnerIDNEQ(v int64) predicate.Shops { + return predicate.Shops(sql.FieldNEQ(FieldOwnerID, v)) +} + +// OwnerIDIn applies the In predicate on the "owner_id" field. +func OwnerIDIn(vs ...int64) predicate.Shops { + return predicate.Shops(sql.FieldIn(FieldOwnerID, vs...)) +} + +// OwnerIDNotIn applies the NotIn predicate on the "owner_id" field. +func OwnerIDNotIn(vs ...int64) predicate.Shops { + return predicate.Shops(sql.FieldNotIn(FieldOwnerID, vs...)) +} + +// OwnerIDGT applies the GT predicate on the "owner_id" field. +func OwnerIDGT(v int64) predicate.Shops { + return predicate.Shops(sql.FieldGT(FieldOwnerID, v)) +} + +// OwnerIDGTE applies the GTE predicate on the "owner_id" field. +func OwnerIDGTE(v int64) predicate.Shops { + return predicate.Shops(sql.FieldGTE(FieldOwnerID, v)) +} + +// OwnerIDLT applies the LT predicate on the "owner_id" field. +func OwnerIDLT(v int64) predicate.Shops { + return predicate.Shops(sql.FieldLT(FieldOwnerID, v)) +} + +// OwnerIDLTE applies the LTE predicate on the "owner_id" field. +func OwnerIDLTE(v int64) predicate.Shops { + return predicate.Shops(sql.FieldLTE(FieldOwnerID, v)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.Shops { + return predicate.Shops(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.Shops { + return predicate.Shops(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.Shops { + return predicate.Shops(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.Shops { + return predicate.Shops(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.Shops { + return predicate.Shops(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.Shops { + return predicate.Shops(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.Shops { + return predicate.Shops(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.Shops { + return predicate.Shops(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.Shops { + return predicate.Shops(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.Shops { + return predicate.Shops(sql.FieldHasSuffix(FieldName, v)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.Shops { + return predicate.Shops(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.Shops { + return predicate.Shops(sql.FieldContainsFold(FieldName, v)) +} + +// BannerEQ applies the EQ predicate on the "banner" field. +func BannerEQ(v string) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldBanner, v)) +} + +// BannerNEQ applies the NEQ predicate on the "banner" field. +func BannerNEQ(v string) predicate.Shops { + return predicate.Shops(sql.FieldNEQ(FieldBanner, v)) +} + +// BannerIn applies the In predicate on the "banner" field. +func BannerIn(vs ...string) predicate.Shops { + return predicate.Shops(sql.FieldIn(FieldBanner, vs...)) +} + +// BannerNotIn applies the NotIn predicate on the "banner" field. +func BannerNotIn(vs ...string) predicate.Shops { + return predicate.Shops(sql.FieldNotIn(FieldBanner, vs...)) +} + +// BannerGT applies the GT predicate on the "banner" field. +func BannerGT(v string) predicate.Shops { + return predicate.Shops(sql.FieldGT(FieldBanner, v)) +} + +// BannerGTE applies the GTE predicate on the "banner" field. +func BannerGTE(v string) predicate.Shops { + return predicate.Shops(sql.FieldGTE(FieldBanner, v)) +} + +// BannerLT applies the LT predicate on the "banner" field. +func BannerLT(v string) predicate.Shops { + return predicate.Shops(sql.FieldLT(FieldBanner, v)) +} + +// BannerLTE applies the LTE predicate on the "banner" field. +func BannerLTE(v string) predicate.Shops { + return predicate.Shops(sql.FieldLTE(FieldBanner, v)) +} + +// BannerContains applies the Contains predicate on the "banner" field. +func BannerContains(v string) predicate.Shops { + return predicate.Shops(sql.FieldContains(FieldBanner, v)) +} + +// BannerHasPrefix applies the HasPrefix predicate on the "banner" field. +func BannerHasPrefix(v string) predicate.Shops { + return predicate.Shops(sql.FieldHasPrefix(FieldBanner, v)) +} + +// BannerHasSuffix applies the HasSuffix predicate on the "banner" field. +func BannerHasSuffix(v string) predicate.Shops { + return predicate.Shops(sql.FieldHasSuffix(FieldBanner, v)) +} + +// BannerIsNil applies the IsNil predicate on the "banner" field. +func BannerIsNil() predicate.Shops { + return predicate.Shops(sql.FieldIsNull(FieldBanner)) +} + +// BannerNotNil applies the NotNil predicate on the "banner" field. +func BannerNotNil() predicate.Shops { + return predicate.Shops(sql.FieldNotNull(FieldBanner)) +} + +// BannerEqualFold applies the EqualFold predicate on the "banner" field. +func BannerEqualFold(v string) predicate.Shops { + return predicate.Shops(sql.FieldEqualFold(FieldBanner, v)) +} + +// BannerContainsFold applies the ContainsFold predicate on the "banner" field. +func BannerContainsFold(v string) predicate.Shops { + return predicate.Shops(sql.FieldContainsFold(FieldBanner, v)) +} + +// DescriptionEQ applies the EQ predicate on the "description" field. +func DescriptionEQ(v string) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldDescription, v)) +} + +// DescriptionNEQ applies the NEQ predicate on the "description" field. +func DescriptionNEQ(v string) predicate.Shops { + return predicate.Shops(sql.FieldNEQ(FieldDescription, v)) +} + +// DescriptionIn applies the In predicate on the "description" field. +func DescriptionIn(vs ...string) predicate.Shops { + return predicate.Shops(sql.FieldIn(FieldDescription, vs...)) +} + +// DescriptionNotIn applies the NotIn predicate on the "description" field. +func DescriptionNotIn(vs ...string) predicate.Shops { + return predicate.Shops(sql.FieldNotIn(FieldDescription, vs...)) +} + +// DescriptionGT applies the GT predicate on the "description" field. +func DescriptionGT(v string) predicate.Shops { + return predicate.Shops(sql.FieldGT(FieldDescription, v)) +} + +// DescriptionGTE applies the GTE predicate on the "description" field. +func DescriptionGTE(v string) predicate.Shops { + return predicate.Shops(sql.FieldGTE(FieldDescription, v)) +} + +// DescriptionLT applies the LT predicate on the "description" field. +func DescriptionLT(v string) predicate.Shops { + return predicate.Shops(sql.FieldLT(FieldDescription, v)) +} + +// DescriptionLTE applies the LTE predicate on the "description" field. +func DescriptionLTE(v string) predicate.Shops { + return predicate.Shops(sql.FieldLTE(FieldDescription, v)) +} + +// DescriptionContains applies the Contains predicate on the "description" field. +func DescriptionContains(v string) predicate.Shops { + return predicate.Shops(sql.FieldContains(FieldDescription, v)) +} + +// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. +func DescriptionHasPrefix(v string) predicate.Shops { + return predicate.Shops(sql.FieldHasPrefix(FieldDescription, v)) +} + +// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. +func DescriptionHasSuffix(v string) predicate.Shops { + return predicate.Shops(sql.FieldHasSuffix(FieldDescription, v)) +} + +// DescriptionIsNil applies the IsNil predicate on the "description" field. +func DescriptionIsNil() predicate.Shops { + return predicate.Shops(sql.FieldIsNull(FieldDescription)) +} + +// DescriptionNotNil applies the NotNil predicate on the "description" field. +func DescriptionNotNil() predicate.Shops { + return predicate.Shops(sql.FieldNotNull(FieldDescription)) +} + +// DescriptionEqualFold applies the EqualFold predicate on the "description" field. +func DescriptionEqualFold(v string) predicate.Shops { + return predicate.Shops(sql.FieldEqualFold(FieldDescription, v)) +} + +// DescriptionContainsFold applies the ContainsFold predicate on the "description" field. +func DescriptionContainsFold(v string) predicate.Shops { + return predicate.Shops(sql.FieldContainsFold(FieldDescription, v)) +} + +// RatingEQ applies the EQ predicate on the "rating" field. +func RatingEQ(v decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldRating, v)) +} + +// RatingNEQ applies the NEQ predicate on the "rating" field. +func RatingNEQ(v decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldNEQ(FieldRating, v)) +} + +// RatingIn applies the In predicate on the "rating" field. +func RatingIn(vs ...decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldIn(FieldRating, vs...)) +} + +// RatingNotIn applies the NotIn predicate on the "rating" field. +func RatingNotIn(vs ...decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldNotIn(FieldRating, vs...)) +} + +// RatingGT applies the GT predicate on the "rating" field. +func RatingGT(v decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldGT(FieldRating, v)) +} + +// RatingGTE applies the GTE predicate on the "rating" field. +func RatingGTE(v decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldGTE(FieldRating, v)) +} + +// RatingLT applies the LT predicate on the "rating" field. +func RatingLT(v decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldLT(FieldRating, v)) +} + +// RatingLTE applies the LTE predicate on the "rating" field. +func RatingLTE(v decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldLTE(FieldRating, v)) +} + +// RatingIsNil applies the IsNil predicate on the "rating" field. +func RatingIsNil() predicate.Shops { + return predicate.Shops(sql.FieldIsNull(FieldRating)) +} + +// RatingNotNil applies the NotNil predicate on the "rating" field. +func RatingNotNil() predicate.Shops { + return predicate.Shops(sql.FieldNotNull(FieldRating)) +} + +// TotalOrdersEQ applies the EQ predicate on the "total_orders" field. +func TotalOrdersEQ(v int) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldTotalOrders, v)) +} + +// TotalOrdersNEQ applies the NEQ predicate on the "total_orders" field. +func TotalOrdersNEQ(v int) predicate.Shops { + return predicate.Shops(sql.FieldNEQ(FieldTotalOrders, v)) +} + +// TotalOrdersIn applies the In predicate on the "total_orders" field. +func TotalOrdersIn(vs ...int) predicate.Shops { + return predicate.Shops(sql.FieldIn(FieldTotalOrders, vs...)) +} + +// TotalOrdersNotIn applies the NotIn predicate on the "total_orders" field. +func TotalOrdersNotIn(vs ...int) predicate.Shops { + return predicate.Shops(sql.FieldNotIn(FieldTotalOrders, vs...)) +} + +// TotalOrdersGT applies the GT predicate on the "total_orders" field. +func TotalOrdersGT(v int) predicate.Shops { + return predicate.Shops(sql.FieldGT(FieldTotalOrders, v)) +} + +// TotalOrdersGTE applies the GTE predicate on the "total_orders" field. +func TotalOrdersGTE(v int) predicate.Shops { + return predicate.Shops(sql.FieldGTE(FieldTotalOrders, v)) +} + +// TotalOrdersLT applies the LT predicate on the "total_orders" field. +func TotalOrdersLT(v int) predicate.Shops { + return predicate.Shops(sql.FieldLT(FieldTotalOrders, v)) +} + +// TotalOrdersLTE applies the LTE predicate on the "total_orders" field. +func TotalOrdersLTE(v int) predicate.Shops { + return predicate.Shops(sql.FieldLTE(FieldTotalOrders, v)) +} + +// TotalOrdersIsNil applies the IsNil predicate on the "total_orders" field. +func TotalOrdersIsNil() predicate.Shops { + return predicate.Shops(sql.FieldIsNull(FieldTotalOrders)) +} + +// TotalOrdersNotNil applies the NotNil predicate on the "total_orders" field. +func TotalOrdersNotNil() predicate.Shops { + return predicate.Shops(sql.FieldNotNull(FieldTotalOrders)) +} + +// PlayerCountEQ applies the EQ predicate on the "player_count" field. +func PlayerCountEQ(v int) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldPlayerCount, v)) +} + +// PlayerCountNEQ applies the NEQ predicate on the "player_count" field. +func PlayerCountNEQ(v int) predicate.Shops { + return predicate.Shops(sql.FieldNEQ(FieldPlayerCount, v)) +} + +// PlayerCountIn applies the In predicate on the "player_count" field. +func PlayerCountIn(vs ...int) predicate.Shops { + return predicate.Shops(sql.FieldIn(FieldPlayerCount, vs...)) +} + +// PlayerCountNotIn applies the NotIn predicate on the "player_count" field. +func PlayerCountNotIn(vs ...int) predicate.Shops { + return predicate.Shops(sql.FieldNotIn(FieldPlayerCount, vs...)) +} + +// PlayerCountGT applies the GT predicate on the "player_count" field. +func PlayerCountGT(v int) predicate.Shops { + return predicate.Shops(sql.FieldGT(FieldPlayerCount, v)) +} + +// PlayerCountGTE applies the GTE predicate on the "player_count" field. +func PlayerCountGTE(v int) predicate.Shops { + return predicate.Shops(sql.FieldGTE(FieldPlayerCount, v)) +} + +// PlayerCountLT applies the LT predicate on the "player_count" field. +func PlayerCountLT(v int) predicate.Shops { + return predicate.Shops(sql.FieldLT(FieldPlayerCount, v)) +} + +// PlayerCountLTE applies the LTE predicate on the "player_count" field. +func PlayerCountLTE(v int) predicate.Shops { + return predicate.Shops(sql.FieldLTE(FieldPlayerCount, v)) +} + +// PlayerCountIsNil applies the IsNil predicate on the "player_count" field. +func PlayerCountIsNil() predicate.Shops { + return predicate.Shops(sql.FieldIsNull(FieldPlayerCount)) +} + +// PlayerCountNotNil applies the NotNil predicate on the "player_count" field. +func PlayerCountNotNil() predicate.Shops { + return predicate.Shops(sql.FieldNotNull(FieldPlayerCount)) +} + +// CommissionTypeEQ applies the EQ predicate on the "commission_type" field. +func CommissionTypeEQ(v string) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldCommissionType, v)) +} + +// CommissionTypeNEQ applies the NEQ predicate on the "commission_type" field. +func CommissionTypeNEQ(v string) predicate.Shops { + return predicate.Shops(sql.FieldNEQ(FieldCommissionType, v)) +} + +// CommissionTypeIn applies the In predicate on the "commission_type" field. +func CommissionTypeIn(vs ...string) predicate.Shops { + return predicate.Shops(sql.FieldIn(FieldCommissionType, vs...)) +} + +// CommissionTypeNotIn applies the NotIn predicate on the "commission_type" field. +func CommissionTypeNotIn(vs ...string) predicate.Shops { + return predicate.Shops(sql.FieldNotIn(FieldCommissionType, vs...)) +} + +// CommissionTypeGT applies the GT predicate on the "commission_type" field. +func CommissionTypeGT(v string) predicate.Shops { + return predicate.Shops(sql.FieldGT(FieldCommissionType, v)) +} + +// CommissionTypeGTE applies the GTE predicate on the "commission_type" field. +func CommissionTypeGTE(v string) predicate.Shops { + return predicate.Shops(sql.FieldGTE(FieldCommissionType, v)) +} + +// CommissionTypeLT applies the LT predicate on the "commission_type" field. +func CommissionTypeLT(v string) predicate.Shops { + return predicate.Shops(sql.FieldLT(FieldCommissionType, v)) +} + +// CommissionTypeLTE applies the LTE predicate on the "commission_type" field. +func CommissionTypeLTE(v string) predicate.Shops { + return predicate.Shops(sql.FieldLTE(FieldCommissionType, v)) +} + +// CommissionTypeContains applies the Contains predicate on the "commission_type" field. +func CommissionTypeContains(v string) predicate.Shops { + return predicate.Shops(sql.FieldContains(FieldCommissionType, v)) +} + +// CommissionTypeHasPrefix applies the HasPrefix predicate on the "commission_type" field. +func CommissionTypeHasPrefix(v string) predicate.Shops { + return predicate.Shops(sql.FieldHasPrefix(FieldCommissionType, v)) +} + +// CommissionTypeHasSuffix applies the HasSuffix predicate on the "commission_type" field. +func CommissionTypeHasSuffix(v string) predicate.Shops { + return predicate.Shops(sql.FieldHasSuffix(FieldCommissionType, v)) +} + +// CommissionTypeEqualFold applies the EqualFold predicate on the "commission_type" field. +func CommissionTypeEqualFold(v string) predicate.Shops { + return predicate.Shops(sql.FieldEqualFold(FieldCommissionType, v)) +} + +// CommissionTypeContainsFold applies the ContainsFold predicate on the "commission_type" field. +func CommissionTypeContainsFold(v string) predicate.Shops { + return predicate.Shops(sql.FieldContainsFold(FieldCommissionType, v)) +} + +// CommissionValueEQ applies the EQ predicate on the "commission_value" field. +func CommissionValueEQ(v decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldCommissionValue, v)) +} + +// CommissionValueNEQ applies the NEQ predicate on the "commission_value" field. +func CommissionValueNEQ(v decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldNEQ(FieldCommissionValue, v)) +} + +// CommissionValueIn applies the In predicate on the "commission_value" field. +func CommissionValueIn(vs ...decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldIn(FieldCommissionValue, vs...)) +} + +// CommissionValueNotIn applies the NotIn predicate on the "commission_value" field. +func CommissionValueNotIn(vs ...decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldNotIn(FieldCommissionValue, vs...)) +} + +// CommissionValueGT applies the GT predicate on the "commission_value" field. +func CommissionValueGT(v decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldGT(FieldCommissionValue, v)) +} + +// CommissionValueGTE applies the GTE predicate on the "commission_value" field. +func CommissionValueGTE(v decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldGTE(FieldCommissionValue, v)) +} + +// CommissionValueLT applies the LT predicate on the "commission_value" field. +func CommissionValueLT(v decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldLT(FieldCommissionValue, v)) +} + +// CommissionValueLTE applies the LTE predicate on the "commission_value" field. +func CommissionValueLTE(v decimal.Decimal) predicate.Shops { + return predicate.Shops(sql.FieldLTE(FieldCommissionValue, v)) +} + +// AllowMultiShopEQ applies the EQ predicate on the "allow_multi_shop" field. +func AllowMultiShopEQ(v bool) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldAllowMultiShop, v)) +} + +// AllowMultiShopNEQ applies the NEQ predicate on the "allow_multi_shop" field. +func AllowMultiShopNEQ(v bool) predicate.Shops { + return predicate.Shops(sql.FieldNEQ(FieldAllowMultiShop, v)) +} + +// AllowMultiShopIsNil applies the IsNil predicate on the "allow_multi_shop" field. +func AllowMultiShopIsNil() predicate.Shops { + return predicate.Shops(sql.FieldIsNull(FieldAllowMultiShop)) +} + +// AllowMultiShopNotNil applies the NotNil predicate on the "allow_multi_shop" field. +func AllowMultiShopNotNil() predicate.Shops { + return predicate.Shops(sql.FieldNotNull(FieldAllowMultiShop)) +} + +// AllowIndependentOrdersEQ applies the EQ predicate on the "allow_independent_orders" field. +func AllowIndependentOrdersEQ(v bool) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldAllowIndependentOrders, v)) +} + +// AllowIndependentOrdersNEQ applies the NEQ predicate on the "allow_independent_orders" field. +func AllowIndependentOrdersNEQ(v bool) predicate.Shops { + return predicate.Shops(sql.FieldNEQ(FieldAllowIndependentOrders, v)) +} + +// AllowIndependentOrdersIsNil applies the IsNil predicate on the "allow_independent_orders" field. +func AllowIndependentOrdersIsNil() predicate.Shops { + return predicate.Shops(sql.FieldIsNull(FieldAllowIndependentOrders)) +} + +// AllowIndependentOrdersNotNil applies the NotNil predicate on the "allow_independent_orders" field. +func AllowIndependentOrdersNotNil() predicate.Shops { + return predicate.Shops(sql.FieldNotNull(FieldAllowIndependentOrders)) +} + +// DispatchModeEQ applies the EQ predicate on the "dispatch_mode" field. +func DispatchModeEQ(v string) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldDispatchMode, v)) +} + +// DispatchModeNEQ applies the NEQ predicate on the "dispatch_mode" field. +func DispatchModeNEQ(v string) predicate.Shops { + return predicate.Shops(sql.FieldNEQ(FieldDispatchMode, v)) +} + +// DispatchModeIn applies the In predicate on the "dispatch_mode" field. +func DispatchModeIn(vs ...string) predicate.Shops { + return predicate.Shops(sql.FieldIn(FieldDispatchMode, vs...)) +} + +// DispatchModeNotIn applies the NotIn predicate on the "dispatch_mode" field. +func DispatchModeNotIn(vs ...string) predicate.Shops { + return predicate.Shops(sql.FieldNotIn(FieldDispatchMode, vs...)) +} + +// DispatchModeGT applies the GT predicate on the "dispatch_mode" field. +func DispatchModeGT(v string) predicate.Shops { + return predicate.Shops(sql.FieldGT(FieldDispatchMode, v)) +} + +// DispatchModeGTE applies the GTE predicate on the "dispatch_mode" field. +func DispatchModeGTE(v string) predicate.Shops { + return predicate.Shops(sql.FieldGTE(FieldDispatchMode, v)) +} + +// DispatchModeLT applies the LT predicate on the "dispatch_mode" field. +func DispatchModeLT(v string) predicate.Shops { + return predicate.Shops(sql.FieldLT(FieldDispatchMode, v)) +} + +// DispatchModeLTE applies the LTE predicate on the "dispatch_mode" field. +func DispatchModeLTE(v string) predicate.Shops { + return predicate.Shops(sql.FieldLTE(FieldDispatchMode, v)) +} + +// DispatchModeContains applies the Contains predicate on the "dispatch_mode" field. +func DispatchModeContains(v string) predicate.Shops { + return predicate.Shops(sql.FieldContains(FieldDispatchMode, v)) +} + +// DispatchModeHasPrefix applies the HasPrefix predicate on the "dispatch_mode" field. +func DispatchModeHasPrefix(v string) predicate.Shops { + return predicate.Shops(sql.FieldHasPrefix(FieldDispatchMode, v)) +} + +// DispatchModeHasSuffix applies the HasSuffix predicate on the "dispatch_mode" field. +func DispatchModeHasSuffix(v string) predicate.Shops { + return predicate.Shops(sql.FieldHasSuffix(FieldDispatchMode, v)) +} + +// DispatchModeEqualFold applies the EqualFold predicate on the "dispatch_mode" field. +func DispatchModeEqualFold(v string) predicate.Shops { + return predicate.Shops(sql.FieldEqualFold(FieldDispatchMode, v)) +} + +// DispatchModeContainsFold applies the ContainsFold predicate on the "dispatch_mode" field. +func DispatchModeContainsFold(v string) predicate.Shops { + return predicate.Shops(sql.FieldContainsFold(FieldDispatchMode, v)) +} + +// AnnouncementsIsNil applies the IsNil predicate on the "announcements" field. +func AnnouncementsIsNil() predicate.Shops { + return predicate.Shops(sql.FieldIsNull(FieldAnnouncements)) +} + +// AnnouncementsNotNil applies the NotNil predicate on the "announcements" field. +func AnnouncementsNotNil() predicate.Shops { + return predicate.Shops(sql.FieldNotNull(FieldAnnouncements)) +} + +// TemplateConfigIsNil applies the IsNil predicate on the "template_config" field. +func TemplateConfigIsNil() predicate.Shops { + return predicate.Shops(sql.FieldIsNull(FieldTemplateConfig)) +} + +// TemplateConfigNotNil applies the NotNil predicate on the "template_config" field. +func TemplateConfigNotNil() predicate.Shops { + return predicate.Shops(sql.FieldNotNull(FieldTemplateConfig)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.Shops { + return predicate.Shops(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.Shops { + return predicate.Shops(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.Shops { + return predicate.Shops(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.Shops { + return predicate.Shops(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.Shops { + return predicate.Shops(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.Shops { + return predicate.Shops(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.Shops { + return predicate.Shops(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.Shops { + return predicate.Shops(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.Shops { + return predicate.Shops(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.Shops { + return predicate.Shops(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.Shops { + return predicate.Shops(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.Shops { + return predicate.Shops(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.Shops { + return predicate.Shops(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.Shops { + return predicate.Shops(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.Shops { + return predicate.Shops(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Shops) predicate.Shops { + return predicate.Shops(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Shops) predicate.Shops { + return predicate.Shops(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Shops) predicate.Shops { + return predicate.Shops(sql.NotPredicates(p)) +} diff --git a/app/shop/rpc/internal/models/shops_create.go b/app/shop/rpc/internal/models/shops_create.go new file mode 100644 index 0000000..79da509 --- /dev/null +++ b/app/shop/rpc/internal/models/shops_create.go @@ -0,0 +1,514 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "errors" + "fmt" + "juwan-backend/app/shop/rpc/internal/models/shops" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/shopspring/decimal" +) + +// ShopsCreate is the builder for creating a Shops entity. +type ShopsCreate struct { + config + mutation *ShopsMutation + hooks []Hook +} + +// SetOwnerID sets the "owner_id" field. +func (_c *ShopsCreate) SetOwnerID(v int64) *ShopsCreate { + _c.mutation.SetOwnerID(v) + return _c +} + +// SetName sets the "name" field. +func (_c *ShopsCreate) SetName(v string) *ShopsCreate { + _c.mutation.SetName(v) + return _c +} + +// SetBanner sets the "banner" field. +func (_c *ShopsCreate) SetBanner(v string) *ShopsCreate { + _c.mutation.SetBanner(v) + return _c +} + +// SetNillableBanner sets the "banner" field if the given value is not nil. +func (_c *ShopsCreate) SetNillableBanner(v *string) *ShopsCreate { + if v != nil { + _c.SetBanner(*v) + } + return _c +} + +// SetDescription sets the "description" field. +func (_c *ShopsCreate) SetDescription(v string) *ShopsCreate { + _c.mutation.SetDescription(v) + return _c +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_c *ShopsCreate) SetNillableDescription(v *string) *ShopsCreate { + if v != nil { + _c.SetDescription(*v) + } + return _c +} + +// SetRating sets the "rating" field. +func (_c *ShopsCreate) SetRating(v decimal.Decimal) *ShopsCreate { + _c.mutation.SetRating(v) + return _c +} + +// SetNillableRating sets the "rating" field if the given value is not nil. +func (_c *ShopsCreate) SetNillableRating(v *decimal.Decimal) *ShopsCreate { + if v != nil { + _c.SetRating(*v) + } + return _c +} + +// SetTotalOrders sets the "total_orders" field. +func (_c *ShopsCreate) SetTotalOrders(v int) *ShopsCreate { + _c.mutation.SetTotalOrders(v) + return _c +} + +// SetNillableTotalOrders sets the "total_orders" field if the given value is not nil. +func (_c *ShopsCreate) SetNillableTotalOrders(v *int) *ShopsCreate { + if v != nil { + _c.SetTotalOrders(*v) + } + return _c +} + +// SetPlayerCount sets the "player_count" field. +func (_c *ShopsCreate) SetPlayerCount(v int) *ShopsCreate { + _c.mutation.SetPlayerCount(v) + return _c +} + +// SetNillablePlayerCount sets the "player_count" field if the given value is not nil. +func (_c *ShopsCreate) SetNillablePlayerCount(v *int) *ShopsCreate { + if v != nil { + _c.SetPlayerCount(*v) + } + return _c +} + +// SetCommissionType sets the "commission_type" field. +func (_c *ShopsCreate) SetCommissionType(v string) *ShopsCreate { + _c.mutation.SetCommissionType(v) + return _c +} + +// SetNillableCommissionType sets the "commission_type" field if the given value is not nil. +func (_c *ShopsCreate) SetNillableCommissionType(v *string) *ShopsCreate { + if v != nil { + _c.SetCommissionType(*v) + } + return _c +} + +// SetCommissionValue sets the "commission_value" field. +func (_c *ShopsCreate) SetCommissionValue(v decimal.Decimal) *ShopsCreate { + _c.mutation.SetCommissionValue(v) + return _c +} + +// SetAllowMultiShop sets the "allow_multi_shop" field. +func (_c *ShopsCreate) SetAllowMultiShop(v bool) *ShopsCreate { + _c.mutation.SetAllowMultiShop(v) + return _c +} + +// SetNillableAllowMultiShop sets the "allow_multi_shop" field if the given value is not nil. +func (_c *ShopsCreate) SetNillableAllowMultiShop(v *bool) *ShopsCreate { + if v != nil { + _c.SetAllowMultiShop(*v) + } + return _c +} + +// SetAllowIndependentOrders sets the "allow_independent_orders" field. +func (_c *ShopsCreate) SetAllowIndependentOrders(v bool) *ShopsCreate { + _c.mutation.SetAllowIndependentOrders(v) + return _c +} + +// SetNillableAllowIndependentOrders sets the "allow_independent_orders" field if the given value is not nil. +func (_c *ShopsCreate) SetNillableAllowIndependentOrders(v *bool) *ShopsCreate { + if v != nil { + _c.SetAllowIndependentOrders(*v) + } + return _c +} + +// SetDispatchMode sets the "dispatch_mode" field. +func (_c *ShopsCreate) SetDispatchMode(v string) *ShopsCreate { + _c.mutation.SetDispatchMode(v) + return _c +} + +// SetNillableDispatchMode sets the "dispatch_mode" field if the given value is not nil. +func (_c *ShopsCreate) SetNillableDispatchMode(v *string) *ShopsCreate { + if v != nil { + _c.SetDispatchMode(*v) + } + return _c +} + +// SetAnnouncements sets the "announcements" field. +func (_c *ShopsCreate) SetAnnouncements(v []string) *ShopsCreate { + _c.mutation.SetAnnouncements(v) + return _c +} + +// SetTemplateConfig sets the "template_config" field. +func (_c *ShopsCreate) SetTemplateConfig(v map[string]interface{}) *ShopsCreate { + _c.mutation.SetTemplateConfig(v) + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *ShopsCreate) SetCreatedAt(v time.Time) *ShopsCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *ShopsCreate) SetNillableCreatedAt(v *time.Time) *ShopsCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *ShopsCreate) SetUpdatedAt(v time.Time) *ShopsCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *ShopsCreate) SetNillableUpdatedAt(v *time.Time) *ShopsCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *ShopsCreate) SetID(v int64) *ShopsCreate { + _c.mutation.SetID(v) + return _c +} + +// Mutation returns the ShopsMutation object of the builder. +func (_c *ShopsCreate) Mutation() *ShopsMutation { + return _c.mutation +} + +// Save creates the Shops in the database. +func (_c *ShopsCreate) Save(ctx context.Context) (*Shops, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *ShopsCreate) SaveX(ctx context.Context) *Shops { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ShopsCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ShopsCreate) 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 *ShopsCreate) defaults() { + if _, ok := _c.mutation.Rating(); !ok { + v := shops.DefaultRating + _c.mutation.SetRating(v) + } + if _, ok := _c.mutation.TotalOrders(); !ok { + v := shops.DefaultTotalOrders + _c.mutation.SetTotalOrders(v) + } + if _, ok := _c.mutation.PlayerCount(); !ok { + v := shops.DefaultPlayerCount + _c.mutation.SetPlayerCount(v) + } + if _, ok := _c.mutation.CommissionType(); !ok { + v := shops.DefaultCommissionType + _c.mutation.SetCommissionType(v) + } + if _, ok := _c.mutation.AllowMultiShop(); !ok { + v := shops.DefaultAllowMultiShop + _c.mutation.SetAllowMultiShop(v) + } + if _, ok := _c.mutation.AllowIndependentOrders(); !ok { + v := shops.DefaultAllowIndependentOrders + _c.mutation.SetAllowIndependentOrders(v) + } + if _, ok := _c.mutation.DispatchMode(); !ok { + v := shops.DefaultDispatchMode + _c.mutation.SetDispatchMode(v) + } + if _, ok := _c.mutation.Announcements(); !ok { + v := shops.DefaultAnnouncements + _c.mutation.SetAnnouncements(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := shops.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := shops.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *ShopsCreate) check() error { + if _, ok := _c.mutation.OwnerID(); !ok { + return &ValidationError{Name: "owner_id", err: errors.New(`models: missing required field "Shops.owner_id"`)} + } + if _, ok := _c.mutation.Name(); !ok { + return &ValidationError{Name: "name", err: errors.New(`models: missing required field "Shops.name"`)} + } + if v, ok := _c.mutation.Name(); ok { + if err := shops.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`models: validator failed for field "Shops.name": %w`, err)} + } + } + if _, ok := _c.mutation.CommissionType(); !ok { + return &ValidationError{Name: "commission_type", err: errors.New(`models: missing required field "Shops.commission_type"`)} + } + if v, ok := _c.mutation.CommissionType(); ok { + if err := shops.CommissionTypeValidator(v); err != nil { + return &ValidationError{Name: "commission_type", err: fmt.Errorf(`models: validator failed for field "Shops.commission_type": %w`, err)} + } + } + if _, ok := _c.mutation.CommissionValue(); !ok { + return &ValidationError{Name: "commission_value", err: errors.New(`models: missing required field "Shops.commission_value"`)} + } + if _, ok := _c.mutation.DispatchMode(); !ok { + return &ValidationError{Name: "dispatch_mode", err: errors.New(`models: missing required field "Shops.dispatch_mode"`)} + } + if v, ok := _c.mutation.DispatchMode(); ok { + if err := shops.DispatchModeValidator(v); err != nil { + return &ValidationError{Name: "dispatch_mode", err: fmt.Errorf(`models: validator failed for field "Shops.dispatch_mode": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`models: missing required field "Shops.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`models: missing required field "Shops.updated_at"`)} + } + return nil +} + +func (_c *ShopsCreate) sqlSave(ctx context.Context) (*Shops, 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 *ShopsCreate) createSpec() (*Shops, *sqlgraph.CreateSpec) { + var ( + _node = &Shops{config: _c.config} + _spec = sqlgraph.NewCreateSpec(shops.Table, sqlgraph.NewFieldSpec(shops.FieldID, field.TypeInt64)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := _c.mutation.OwnerID(); ok { + _spec.SetField(shops.FieldOwnerID, field.TypeInt64, value) + _node.OwnerID = value + } + if value, ok := _c.mutation.Name(); ok { + _spec.SetField(shops.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := _c.mutation.Banner(); ok { + _spec.SetField(shops.FieldBanner, field.TypeString, value) + _node.Banner = &value + } + if value, ok := _c.mutation.Description(); ok { + _spec.SetField(shops.FieldDescription, field.TypeString, value) + _node.Description = &value + } + if value, ok := _c.mutation.Rating(); ok { + _spec.SetField(shops.FieldRating, field.TypeOther, value) + _node.Rating = value + } + if value, ok := _c.mutation.TotalOrders(); ok { + _spec.SetField(shops.FieldTotalOrders, field.TypeInt, value) + _node.TotalOrders = value + } + if value, ok := _c.mutation.PlayerCount(); ok { + _spec.SetField(shops.FieldPlayerCount, field.TypeInt, value) + _node.PlayerCount = value + } + if value, ok := _c.mutation.CommissionType(); ok { + _spec.SetField(shops.FieldCommissionType, field.TypeString, value) + _node.CommissionType = value + } + if value, ok := _c.mutation.CommissionValue(); ok { + _spec.SetField(shops.FieldCommissionValue, field.TypeOther, value) + _node.CommissionValue = value + } + if value, ok := _c.mutation.AllowMultiShop(); ok { + _spec.SetField(shops.FieldAllowMultiShop, field.TypeBool, value) + _node.AllowMultiShop = value + } + if value, ok := _c.mutation.AllowIndependentOrders(); ok { + _spec.SetField(shops.FieldAllowIndependentOrders, field.TypeBool, value) + _node.AllowIndependentOrders = value + } + if value, ok := _c.mutation.DispatchMode(); ok { + _spec.SetField(shops.FieldDispatchMode, field.TypeString, value) + _node.DispatchMode = value + } + if value, ok := _c.mutation.Announcements(); ok { + _spec.SetField(shops.FieldAnnouncements, field.TypeJSON, value) + _node.Announcements = value + } + if value, ok := _c.mutation.TemplateConfig(); ok { + _spec.SetField(shops.FieldTemplateConfig, field.TypeJSON, value) + _node.TemplateConfig = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(shops.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(shops.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + return _node, _spec +} + +// ShopsCreateBulk is the builder for creating many Shops entities in bulk. +type ShopsCreateBulk struct { + config + err error + builders []*ShopsCreate +} + +// Save creates the Shops entities in the database. +func (_c *ShopsCreateBulk) Save(ctx context.Context) ([]*Shops, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*Shops, 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.(*ShopsMutation) + 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 *ShopsCreateBulk) SaveX(ctx context.Context) []*Shops { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ShopsCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ShopsCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/app/shop/rpc/internal/models/shops_delete.go b/app/shop/rpc/internal/models/shops_delete.go new file mode 100644 index 0000000..06f0528 --- /dev/null +++ b/app/shop/rpc/internal/models/shops_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "juwan-backend/app/shop/rpc/internal/models/predicate" + "juwan-backend/app/shop/rpc/internal/models/shops" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// ShopsDelete is the builder for deleting a Shops entity. +type ShopsDelete struct { + config + hooks []Hook + mutation *ShopsMutation +} + +// Where appends a list predicates to the ShopsDelete builder. +func (_d *ShopsDelete) Where(ps ...predicate.Shops) *ShopsDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *ShopsDelete) 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 *ShopsDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *ShopsDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(shops.Table, sqlgraph.NewFieldSpec(shops.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 +} + +// ShopsDeleteOne is the builder for deleting a single Shops entity. +type ShopsDeleteOne struct { + _d *ShopsDelete +} + +// Where appends a list predicates to the ShopsDelete builder. +func (_d *ShopsDeleteOne) Where(ps ...predicate.Shops) *ShopsDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *ShopsDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{shops.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *ShopsDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/app/shop/rpc/internal/models/shops_query.go b/app/shop/rpc/internal/models/shops_query.go new file mode 100644 index 0000000..3600115 --- /dev/null +++ b/app/shop/rpc/internal/models/shops_query.go @@ -0,0 +1,527 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "fmt" + "juwan-backend/app/shop/rpc/internal/models/predicate" + "juwan-backend/app/shop/rpc/internal/models/shops" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// ShopsQuery is the builder for querying Shops entities. +type ShopsQuery struct { + config + ctx *QueryContext + order []shops.OrderOption + inters []Interceptor + predicates []predicate.Shops + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the ShopsQuery builder. +func (_q *ShopsQuery) Where(ps ...predicate.Shops) *ShopsQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *ShopsQuery) Limit(limit int) *ShopsQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *ShopsQuery) Offset(offset int) *ShopsQuery { + _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 *ShopsQuery) Unique(unique bool) *ShopsQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *ShopsQuery) Order(o ...shops.OrderOption) *ShopsQuery { + _q.order = append(_q.order, o...) + return _q +} + +// First returns the first Shops entity from the query. +// Returns a *NotFoundError when no Shops was found. +func (_q *ShopsQuery) First(ctx context.Context) (*Shops, 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{shops.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *ShopsQuery) FirstX(ctx context.Context) *Shops { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Shops ID from the query. +// Returns a *NotFoundError when no Shops ID was found. +func (_q *ShopsQuery) 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{shops.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *ShopsQuery) FirstIDX(ctx context.Context) int64 { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Shops entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Shops entity is found. +// Returns a *NotFoundError when no Shops entities are found. +func (_q *ShopsQuery) Only(ctx context.Context) (*Shops, 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{shops.Label} + default: + return nil, &NotSingularError{shops.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *ShopsQuery) OnlyX(ctx context.Context) *Shops { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Shops ID in the query. +// Returns a *NotSingularError when more than one Shops ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *ShopsQuery) 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{shops.Label} + default: + err = &NotSingularError{shops.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *ShopsQuery) 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 ShopsSlice. +func (_q *ShopsQuery) All(ctx context.Context) ([]*Shops, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*Shops, *ShopsQuery]() + return withInterceptors[[]*Shops](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *ShopsQuery) AllX(ctx context.Context) []*Shops { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Shops IDs. +func (_q *ShopsQuery) 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(shops.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *ShopsQuery) 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 *ShopsQuery) 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[*ShopsQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *ShopsQuery) 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 *ShopsQuery) 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 *ShopsQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the ShopsQuery 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 *ShopsQuery) Clone() *ShopsQuery { + if _q == nil { + return nil + } + return &ShopsQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]shops.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.Shops{}, _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 { +// OwnerID int64 `json:"owner_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Shops.Query(). +// GroupBy(shops.FieldOwnerID). +// Aggregate(models.Count()). +// Scan(ctx, &v) +func (_q *ShopsQuery) GroupBy(field string, fields ...string) *ShopsGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &ShopsGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = shops.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 { +// OwnerID int64 `json:"owner_id,omitempty"` +// } +// +// client.Shops.Query(). +// Select(shops.FieldOwnerID). +// Scan(ctx, &v) +func (_q *ShopsQuery) Select(fields ...string) *ShopsSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &ShopsSelect{ShopsQuery: _q} + sbuild.label = shops.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a ShopsSelect configured with the given aggregations. +func (_q *ShopsQuery) Aggregate(fns ...AggregateFunc) *ShopsSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *ShopsQuery) 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 !shops.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 *ShopsQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Shops, error) { + var ( + nodes = []*Shops{} + _spec = _q.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*Shops).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &Shops{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 *ShopsQuery) 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 *ShopsQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(shops.Table, shops.Columns, sqlgraph.NewFieldSpec(shops.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, shops.FieldID) + for i := range fields { + if fields[i] != shops.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 *ShopsQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(shops.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = shops.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 +} + +// ShopsGroupBy is the group-by builder for Shops entities. +type ShopsGroupBy struct { + selector + build *ShopsQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *ShopsGroupBy) Aggregate(fns ...AggregateFunc) *ShopsGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *ShopsGroupBy) 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[*ShopsQuery, *ShopsGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *ShopsGroupBy) sqlScan(ctx context.Context, root *ShopsQuery, 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) +} + +// ShopsSelect is the builder for selecting fields of Shops entities. +type ShopsSelect struct { + *ShopsQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *ShopsSelect) Aggregate(fns ...AggregateFunc) *ShopsSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *ShopsSelect) 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[*ShopsQuery, *ShopsSelect](ctx, _s.ShopsQuery, _s, _s.inters, v) +} + +func (_s *ShopsSelect) sqlScan(ctx context.Context, root *ShopsQuery, 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) +} diff --git a/app/shop/rpc/internal/models/shops_update.go b/app/shop/rpc/internal/models/shops_update.go new file mode 100644 index 0000000..b0282d9 --- /dev/null +++ b/app/shop/rpc/internal/models/shops_update.go @@ -0,0 +1,948 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "errors" + "fmt" + "juwan-backend/app/shop/rpc/internal/models/predicate" + "juwan-backend/app/shop/rpc/internal/models/shops" + "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/shopspring/decimal" +) + +// ShopsUpdate is the builder for updating Shops entities. +type ShopsUpdate struct { + config + hooks []Hook + mutation *ShopsMutation +} + +// Where appends a list predicates to the ShopsUpdate builder. +func (_u *ShopsUpdate) Where(ps ...predicate.Shops) *ShopsUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetOwnerID sets the "owner_id" field. +func (_u *ShopsUpdate) SetOwnerID(v int64) *ShopsUpdate { + _u.mutation.ResetOwnerID() + _u.mutation.SetOwnerID(v) + return _u +} + +// SetNillableOwnerID sets the "owner_id" field if the given value is not nil. +func (_u *ShopsUpdate) SetNillableOwnerID(v *int64) *ShopsUpdate { + if v != nil { + _u.SetOwnerID(*v) + } + return _u +} + +// AddOwnerID adds value to the "owner_id" field. +func (_u *ShopsUpdate) AddOwnerID(v int64) *ShopsUpdate { + _u.mutation.AddOwnerID(v) + return _u +} + +// SetName sets the "name" field. +func (_u *ShopsUpdate) SetName(v string) *ShopsUpdate { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *ShopsUpdate) SetNillableName(v *string) *ShopsUpdate { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetBanner sets the "banner" field. +func (_u *ShopsUpdate) SetBanner(v string) *ShopsUpdate { + _u.mutation.SetBanner(v) + return _u +} + +// SetNillableBanner sets the "banner" field if the given value is not nil. +func (_u *ShopsUpdate) SetNillableBanner(v *string) *ShopsUpdate { + if v != nil { + _u.SetBanner(*v) + } + return _u +} + +// ClearBanner clears the value of the "banner" field. +func (_u *ShopsUpdate) ClearBanner() *ShopsUpdate { + _u.mutation.ClearBanner() + return _u +} + +// SetDescription sets the "description" field. +func (_u *ShopsUpdate) SetDescription(v string) *ShopsUpdate { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *ShopsUpdate) SetNillableDescription(v *string) *ShopsUpdate { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// ClearDescription clears the value of the "description" field. +func (_u *ShopsUpdate) ClearDescription() *ShopsUpdate { + _u.mutation.ClearDescription() + return _u +} + +// SetRating sets the "rating" field. +func (_u *ShopsUpdate) SetRating(v decimal.Decimal) *ShopsUpdate { + _u.mutation.SetRating(v) + return _u +} + +// SetNillableRating sets the "rating" field if the given value is not nil. +func (_u *ShopsUpdate) SetNillableRating(v *decimal.Decimal) *ShopsUpdate { + if v != nil { + _u.SetRating(*v) + } + return _u +} + +// ClearRating clears the value of the "rating" field. +func (_u *ShopsUpdate) ClearRating() *ShopsUpdate { + _u.mutation.ClearRating() + return _u +} + +// SetTotalOrders sets the "total_orders" field. +func (_u *ShopsUpdate) SetTotalOrders(v int) *ShopsUpdate { + _u.mutation.ResetTotalOrders() + _u.mutation.SetTotalOrders(v) + return _u +} + +// SetNillableTotalOrders sets the "total_orders" field if the given value is not nil. +func (_u *ShopsUpdate) SetNillableTotalOrders(v *int) *ShopsUpdate { + if v != nil { + _u.SetTotalOrders(*v) + } + return _u +} + +// AddTotalOrders adds value to the "total_orders" field. +func (_u *ShopsUpdate) AddTotalOrders(v int) *ShopsUpdate { + _u.mutation.AddTotalOrders(v) + return _u +} + +// ClearTotalOrders clears the value of the "total_orders" field. +func (_u *ShopsUpdate) ClearTotalOrders() *ShopsUpdate { + _u.mutation.ClearTotalOrders() + return _u +} + +// SetPlayerCount sets the "player_count" field. +func (_u *ShopsUpdate) SetPlayerCount(v int) *ShopsUpdate { + _u.mutation.ResetPlayerCount() + _u.mutation.SetPlayerCount(v) + return _u +} + +// SetNillablePlayerCount sets the "player_count" field if the given value is not nil. +func (_u *ShopsUpdate) SetNillablePlayerCount(v *int) *ShopsUpdate { + if v != nil { + _u.SetPlayerCount(*v) + } + return _u +} + +// AddPlayerCount adds value to the "player_count" field. +func (_u *ShopsUpdate) AddPlayerCount(v int) *ShopsUpdate { + _u.mutation.AddPlayerCount(v) + return _u +} + +// ClearPlayerCount clears the value of the "player_count" field. +func (_u *ShopsUpdate) ClearPlayerCount() *ShopsUpdate { + _u.mutation.ClearPlayerCount() + return _u +} + +// SetCommissionType sets the "commission_type" field. +func (_u *ShopsUpdate) SetCommissionType(v string) *ShopsUpdate { + _u.mutation.SetCommissionType(v) + return _u +} + +// SetNillableCommissionType sets the "commission_type" field if the given value is not nil. +func (_u *ShopsUpdate) SetNillableCommissionType(v *string) *ShopsUpdate { + if v != nil { + _u.SetCommissionType(*v) + } + return _u +} + +// SetCommissionValue sets the "commission_value" field. +func (_u *ShopsUpdate) SetCommissionValue(v decimal.Decimal) *ShopsUpdate { + _u.mutation.SetCommissionValue(v) + return _u +} + +// SetNillableCommissionValue sets the "commission_value" field if the given value is not nil. +func (_u *ShopsUpdate) SetNillableCommissionValue(v *decimal.Decimal) *ShopsUpdate { + if v != nil { + _u.SetCommissionValue(*v) + } + return _u +} + +// SetAllowMultiShop sets the "allow_multi_shop" field. +func (_u *ShopsUpdate) SetAllowMultiShop(v bool) *ShopsUpdate { + _u.mutation.SetAllowMultiShop(v) + return _u +} + +// SetNillableAllowMultiShop sets the "allow_multi_shop" field if the given value is not nil. +func (_u *ShopsUpdate) SetNillableAllowMultiShop(v *bool) *ShopsUpdate { + if v != nil { + _u.SetAllowMultiShop(*v) + } + return _u +} + +// ClearAllowMultiShop clears the value of the "allow_multi_shop" field. +func (_u *ShopsUpdate) ClearAllowMultiShop() *ShopsUpdate { + _u.mutation.ClearAllowMultiShop() + return _u +} + +// SetAllowIndependentOrders sets the "allow_independent_orders" field. +func (_u *ShopsUpdate) SetAllowIndependentOrders(v bool) *ShopsUpdate { + _u.mutation.SetAllowIndependentOrders(v) + return _u +} + +// SetNillableAllowIndependentOrders sets the "allow_independent_orders" field if the given value is not nil. +func (_u *ShopsUpdate) SetNillableAllowIndependentOrders(v *bool) *ShopsUpdate { + if v != nil { + _u.SetAllowIndependentOrders(*v) + } + return _u +} + +// ClearAllowIndependentOrders clears the value of the "allow_independent_orders" field. +func (_u *ShopsUpdate) ClearAllowIndependentOrders() *ShopsUpdate { + _u.mutation.ClearAllowIndependentOrders() + return _u +} + +// SetDispatchMode sets the "dispatch_mode" field. +func (_u *ShopsUpdate) SetDispatchMode(v string) *ShopsUpdate { + _u.mutation.SetDispatchMode(v) + return _u +} + +// SetNillableDispatchMode sets the "dispatch_mode" field if the given value is not nil. +func (_u *ShopsUpdate) SetNillableDispatchMode(v *string) *ShopsUpdate { + if v != nil { + _u.SetDispatchMode(*v) + } + return _u +} + +// SetAnnouncements sets the "announcements" field. +func (_u *ShopsUpdate) SetAnnouncements(v []string) *ShopsUpdate { + _u.mutation.SetAnnouncements(v) + return _u +} + +// AppendAnnouncements appends value to the "announcements" field. +func (_u *ShopsUpdate) AppendAnnouncements(v []string) *ShopsUpdate { + _u.mutation.AppendAnnouncements(v) + return _u +} + +// ClearAnnouncements clears the value of the "announcements" field. +func (_u *ShopsUpdate) ClearAnnouncements() *ShopsUpdate { + _u.mutation.ClearAnnouncements() + return _u +} + +// SetTemplateConfig sets the "template_config" field. +func (_u *ShopsUpdate) SetTemplateConfig(v map[string]interface{}) *ShopsUpdate { + _u.mutation.SetTemplateConfig(v) + return _u +} + +// ClearTemplateConfig clears the value of the "template_config" field. +func (_u *ShopsUpdate) ClearTemplateConfig() *ShopsUpdate { + _u.mutation.ClearTemplateConfig() + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *ShopsUpdate) SetUpdatedAt(v time.Time) *ShopsUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// Mutation returns the ShopsMutation object of the builder. +func (_u *ShopsUpdate) Mutation() *ShopsMutation { + return _u.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *ShopsUpdate) 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 *ShopsUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *ShopsUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ShopsUpdate) 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 *ShopsUpdate) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := shops.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ShopsUpdate) check() error { + if v, ok := _u.mutation.Name(); ok { + if err := shops.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`models: validator failed for field "Shops.name": %w`, err)} + } + } + if v, ok := _u.mutation.CommissionType(); ok { + if err := shops.CommissionTypeValidator(v); err != nil { + return &ValidationError{Name: "commission_type", err: fmt.Errorf(`models: validator failed for field "Shops.commission_type": %w`, err)} + } + } + if v, ok := _u.mutation.DispatchMode(); ok { + if err := shops.DispatchModeValidator(v); err != nil { + return &ValidationError{Name: "dispatch_mode", err: fmt.Errorf(`models: validator failed for field "Shops.dispatch_mode": %w`, err)} + } + } + return nil +} + +func (_u *ShopsUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(shops.Table, shops.Columns, sqlgraph.NewFieldSpec(shops.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.OwnerID(); ok { + _spec.SetField(shops.FieldOwnerID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedOwnerID(); ok { + _spec.AddField(shops.FieldOwnerID, field.TypeInt64, value) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(shops.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.Banner(); ok { + _spec.SetField(shops.FieldBanner, field.TypeString, value) + } + if _u.mutation.BannerCleared() { + _spec.ClearField(shops.FieldBanner, field.TypeString) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(shops.FieldDescription, field.TypeString, value) + } + if _u.mutation.DescriptionCleared() { + _spec.ClearField(shops.FieldDescription, field.TypeString) + } + if value, ok := _u.mutation.Rating(); ok { + _spec.SetField(shops.FieldRating, field.TypeOther, value) + } + if _u.mutation.RatingCleared() { + _spec.ClearField(shops.FieldRating, field.TypeOther) + } + if value, ok := _u.mutation.TotalOrders(); ok { + _spec.SetField(shops.FieldTotalOrders, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedTotalOrders(); ok { + _spec.AddField(shops.FieldTotalOrders, field.TypeInt, value) + } + if _u.mutation.TotalOrdersCleared() { + _spec.ClearField(shops.FieldTotalOrders, field.TypeInt) + } + if value, ok := _u.mutation.PlayerCount(); ok { + _spec.SetField(shops.FieldPlayerCount, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedPlayerCount(); ok { + _spec.AddField(shops.FieldPlayerCount, field.TypeInt, value) + } + if _u.mutation.PlayerCountCleared() { + _spec.ClearField(shops.FieldPlayerCount, field.TypeInt) + } + if value, ok := _u.mutation.CommissionType(); ok { + _spec.SetField(shops.FieldCommissionType, field.TypeString, value) + } + if value, ok := _u.mutation.CommissionValue(); ok { + _spec.SetField(shops.FieldCommissionValue, field.TypeOther, value) + } + if value, ok := _u.mutation.AllowMultiShop(); ok { + _spec.SetField(shops.FieldAllowMultiShop, field.TypeBool, value) + } + if _u.mutation.AllowMultiShopCleared() { + _spec.ClearField(shops.FieldAllowMultiShop, field.TypeBool) + } + if value, ok := _u.mutation.AllowIndependentOrders(); ok { + _spec.SetField(shops.FieldAllowIndependentOrders, field.TypeBool, value) + } + if _u.mutation.AllowIndependentOrdersCleared() { + _spec.ClearField(shops.FieldAllowIndependentOrders, field.TypeBool) + } + if value, ok := _u.mutation.DispatchMode(); ok { + _spec.SetField(shops.FieldDispatchMode, field.TypeString, value) + } + if value, ok := _u.mutation.Announcements(); ok { + _spec.SetField(shops.FieldAnnouncements, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedAnnouncements(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, shops.FieldAnnouncements, value) + }) + } + if _u.mutation.AnnouncementsCleared() { + _spec.ClearField(shops.FieldAnnouncements, field.TypeJSON) + } + if value, ok := _u.mutation.TemplateConfig(); ok { + _spec.SetField(shops.FieldTemplateConfig, field.TypeJSON, value) + } + if _u.mutation.TemplateConfigCleared() { + _spec.ClearField(shops.FieldTemplateConfig, field.TypeJSON) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(shops.FieldUpdatedAt, field.TypeTime, value) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{shops.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// ShopsUpdateOne is the builder for updating a single Shops entity. +type ShopsUpdateOne struct { + config + fields []string + hooks []Hook + mutation *ShopsMutation +} + +// SetOwnerID sets the "owner_id" field. +func (_u *ShopsUpdateOne) SetOwnerID(v int64) *ShopsUpdateOne { + _u.mutation.ResetOwnerID() + _u.mutation.SetOwnerID(v) + return _u +} + +// SetNillableOwnerID sets the "owner_id" field if the given value is not nil. +func (_u *ShopsUpdateOne) SetNillableOwnerID(v *int64) *ShopsUpdateOne { + if v != nil { + _u.SetOwnerID(*v) + } + return _u +} + +// AddOwnerID adds value to the "owner_id" field. +func (_u *ShopsUpdateOne) AddOwnerID(v int64) *ShopsUpdateOne { + _u.mutation.AddOwnerID(v) + return _u +} + +// SetName sets the "name" field. +func (_u *ShopsUpdateOne) SetName(v string) *ShopsUpdateOne { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *ShopsUpdateOne) SetNillableName(v *string) *ShopsUpdateOne { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetBanner sets the "banner" field. +func (_u *ShopsUpdateOne) SetBanner(v string) *ShopsUpdateOne { + _u.mutation.SetBanner(v) + return _u +} + +// SetNillableBanner sets the "banner" field if the given value is not nil. +func (_u *ShopsUpdateOne) SetNillableBanner(v *string) *ShopsUpdateOne { + if v != nil { + _u.SetBanner(*v) + } + return _u +} + +// ClearBanner clears the value of the "banner" field. +func (_u *ShopsUpdateOne) ClearBanner() *ShopsUpdateOne { + _u.mutation.ClearBanner() + return _u +} + +// SetDescription sets the "description" field. +func (_u *ShopsUpdateOne) SetDescription(v string) *ShopsUpdateOne { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *ShopsUpdateOne) SetNillableDescription(v *string) *ShopsUpdateOne { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// ClearDescription clears the value of the "description" field. +func (_u *ShopsUpdateOne) ClearDescription() *ShopsUpdateOne { + _u.mutation.ClearDescription() + return _u +} + +// SetRating sets the "rating" field. +func (_u *ShopsUpdateOne) SetRating(v decimal.Decimal) *ShopsUpdateOne { + _u.mutation.SetRating(v) + return _u +} + +// SetNillableRating sets the "rating" field if the given value is not nil. +func (_u *ShopsUpdateOne) SetNillableRating(v *decimal.Decimal) *ShopsUpdateOne { + if v != nil { + _u.SetRating(*v) + } + return _u +} + +// ClearRating clears the value of the "rating" field. +func (_u *ShopsUpdateOne) ClearRating() *ShopsUpdateOne { + _u.mutation.ClearRating() + return _u +} + +// SetTotalOrders sets the "total_orders" field. +func (_u *ShopsUpdateOne) SetTotalOrders(v int) *ShopsUpdateOne { + _u.mutation.ResetTotalOrders() + _u.mutation.SetTotalOrders(v) + return _u +} + +// SetNillableTotalOrders sets the "total_orders" field if the given value is not nil. +func (_u *ShopsUpdateOne) SetNillableTotalOrders(v *int) *ShopsUpdateOne { + if v != nil { + _u.SetTotalOrders(*v) + } + return _u +} + +// AddTotalOrders adds value to the "total_orders" field. +func (_u *ShopsUpdateOne) AddTotalOrders(v int) *ShopsUpdateOne { + _u.mutation.AddTotalOrders(v) + return _u +} + +// ClearTotalOrders clears the value of the "total_orders" field. +func (_u *ShopsUpdateOne) ClearTotalOrders() *ShopsUpdateOne { + _u.mutation.ClearTotalOrders() + return _u +} + +// SetPlayerCount sets the "player_count" field. +func (_u *ShopsUpdateOne) SetPlayerCount(v int) *ShopsUpdateOne { + _u.mutation.ResetPlayerCount() + _u.mutation.SetPlayerCount(v) + return _u +} + +// SetNillablePlayerCount sets the "player_count" field if the given value is not nil. +func (_u *ShopsUpdateOne) SetNillablePlayerCount(v *int) *ShopsUpdateOne { + if v != nil { + _u.SetPlayerCount(*v) + } + return _u +} + +// AddPlayerCount adds value to the "player_count" field. +func (_u *ShopsUpdateOne) AddPlayerCount(v int) *ShopsUpdateOne { + _u.mutation.AddPlayerCount(v) + return _u +} + +// ClearPlayerCount clears the value of the "player_count" field. +func (_u *ShopsUpdateOne) ClearPlayerCount() *ShopsUpdateOne { + _u.mutation.ClearPlayerCount() + return _u +} + +// SetCommissionType sets the "commission_type" field. +func (_u *ShopsUpdateOne) SetCommissionType(v string) *ShopsUpdateOne { + _u.mutation.SetCommissionType(v) + return _u +} + +// SetNillableCommissionType sets the "commission_type" field if the given value is not nil. +func (_u *ShopsUpdateOne) SetNillableCommissionType(v *string) *ShopsUpdateOne { + if v != nil { + _u.SetCommissionType(*v) + } + return _u +} + +// SetCommissionValue sets the "commission_value" field. +func (_u *ShopsUpdateOne) SetCommissionValue(v decimal.Decimal) *ShopsUpdateOne { + _u.mutation.SetCommissionValue(v) + return _u +} + +// SetNillableCommissionValue sets the "commission_value" field if the given value is not nil. +func (_u *ShopsUpdateOne) SetNillableCommissionValue(v *decimal.Decimal) *ShopsUpdateOne { + if v != nil { + _u.SetCommissionValue(*v) + } + return _u +} + +// SetAllowMultiShop sets the "allow_multi_shop" field. +func (_u *ShopsUpdateOne) SetAllowMultiShop(v bool) *ShopsUpdateOne { + _u.mutation.SetAllowMultiShop(v) + return _u +} + +// SetNillableAllowMultiShop sets the "allow_multi_shop" field if the given value is not nil. +func (_u *ShopsUpdateOne) SetNillableAllowMultiShop(v *bool) *ShopsUpdateOne { + if v != nil { + _u.SetAllowMultiShop(*v) + } + return _u +} + +// ClearAllowMultiShop clears the value of the "allow_multi_shop" field. +func (_u *ShopsUpdateOne) ClearAllowMultiShop() *ShopsUpdateOne { + _u.mutation.ClearAllowMultiShop() + return _u +} + +// SetAllowIndependentOrders sets the "allow_independent_orders" field. +func (_u *ShopsUpdateOne) SetAllowIndependentOrders(v bool) *ShopsUpdateOne { + _u.mutation.SetAllowIndependentOrders(v) + return _u +} + +// SetNillableAllowIndependentOrders sets the "allow_independent_orders" field if the given value is not nil. +func (_u *ShopsUpdateOne) SetNillableAllowIndependentOrders(v *bool) *ShopsUpdateOne { + if v != nil { + _u.SetAllowIndependentOrders(*v) + } + return _u +} + +// ClearAllowIndependentOrders clears the value of the "allow_independent_orders" field. +func (_u *ShopsUpdateOne) ClearAllowIndependentOrders() *ShopsUpdateOne { + _u.mutation.ClearAllowIndependentOrders() + return _u +} + +// SetDispatchMode sets the "dispatch_mode" field. +func (_u *ShopsUpdateOne) SetDispatchMode(v string) *ShopsUpdateOne { + _u.mutation.SetDispatchMode(v) + return _u +} + +// SetNillableDispatchMode sets the "dispatch_mode" field if the given value is not nil. +func (_u *ShopsUpdateOne) SetNillableDispatchMode(v *string) *ShopsUpdateOne { + if v != nil { + _u.SetDispatchMode(*v) + } + return _u +} + +// SetAnnouncements sets the "announcements" field. +func (_u *ShopsUpdateOne) SetAnnouncements(v []string) *ShopsUpdateOne { + _u.mutation.SetAnnouncements(v) + return _u +} + +// AppendAnnouncements appends value to the "announcements" field. +func (_u *ShopsUpdateOne) AppendAnnouncements(v []string) *ShopsUpdateOne { + _u.mutation.AppendAnnouncements(v) + return _u +} + +// ClearAnnouncements clears the value of the "announcements" field. +func (_u *ShopsUpdateOne) ClearAnnouncements() *ShopsUpdateOne { + _u.mutation.ClearAnnouncements() + return _u +} + +// SetTemplateConfig sets the "template_config" field. +func (_u *ShopsUpdateOne) SetTemplateConfig(v map[string]interface{}) *ShopsUpdateOne { + _u.mutation.SetTemplateConfig(v) + return _u +} + +// ClearTemplateConfig clears the value of the "template_config" field. +func (_u *ShopsUpdateOne) ClearTemplateConfig() *ShopsUpdateOne { + _u.mutation.ClearTemplateConfig() + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *ShopsUpdateOne) SetUpdatedAt(v time.Time) *ShopsUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// Mutation returns the ShopsMutation object of the builder. +func (_u *ShopsUpdateOne) Mutation() *ShopsMutation { + return _u.mutation +} + +// Where appends a list predicates to the ShopsUpdate builder. +func (_u *ShopsUpdateOne) Where(ps ...predicate.Shops) *ShopsUpdateOne { + _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 *ShopsUpdateOne) Select(field string, fields ...string) *ShopsUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated Shops entity. +func (_u *ShopsUpdateOne) Save(ctx context.Context) (*Shops, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *ShopsUpdateOne) SaveX(ctx context.Context) *Shops { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *ShopsUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ShopsUpdateOne) 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 *ShopsUpdateOne) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := shops.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ShopsUpdateOne) check() error { + if v, ok := _u.mutation.Name(); ok { + if err := shops.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`models: validator failed for field "Shops.name": %w`, err)} + } + } + if v, ok := _u.mutation.CommissionType(); ok { + if err := shops.CommissionTypeValidator(v); err != nil { + return &ValidationError{Name: "commission_type", err: fmt.Errorf(`models: validator failed for field "Shops.commission_type": %w`, err)} + } + } + if v, ok := _u.mutation.DispatchMode(); ok { + if err := shops.DispatchModeValidator(v); err != nil { + return &ValidationError{Name: "dispatch_mode", err: fmt.Errorf(`models: validator failed for field "Shops.dispatch_mode": %w`, err)} + } + } + return nil +} + +func (_u *ShopsUpdateOne) sqlSave(ctx context.Context) (_node *Shops, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(shops.Table, shops.Columns, sqlgraph.NewFieldSpec(shops.FieldID, field.TypeInt64)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "Shops.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, shops.FieldID) + for _, f := range fields { + if !shops.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)} + } + if f != shops.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.OwnerID(); ok { + _spec.SetField(shops.FieldOwnerID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedOwnerID(); ok { + _spec.AddField(shops.FieldOwnerID, field.TypeInt64, value) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(shops.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.Banner(); ok { + _spec.SetField(shops.FieldBanner, field.TypeString, value) + } + if _u.mutation.BannerCleared() { + _spec.ClearField(shops.FieldBanner, field.TypeString) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(shops.FieldDescription, field.TypeString, value) + } + if _u.mutation.DescriptionCleared() { + _spec.ClearField(shops.FieldDescription, field.TypeString) + } + if value, ok := _u.mutation.Rating(); ok { + _spec.SetField(shops.FieldRating, field.TypeOther, value) + } + if _u.mutation.RatingCleared() { + _spec.ClearField(shops.FieldRating, field.TypeOther) + } + if value, ok := _u.mutation.TotalOrders(); ok { + _spec.SetField(shops.FieldTotalOrders, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedTotalOrders(); ok { + _spec.AddField(shops.FieldTotalOrders, field.TypeInt, value) + } + if _u.mutation.TotalOrdersCleared() { + _spec.ClearField(shops.FieldTotalOrders, field.TypeInt) + } + if value, ok := _u.mutation.PlayerCount(); ok { + _spec.SetField(shops.FieldPlayerCount, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedPlayerCount(); ok { + _spec.AddField(shops.FieldPlayerCount, field.TypeInt, value) + } + if _u.mutation.PlayerCountCleared() { + _spec.ClearField(shops.FieldPlayerCount, field.TypeInt) + } + if value, ok := _u.mutation.CommissionType(); ok { + _spec.SetField(shops.FieldCommissionType, field.TypeString, value) + } + if value, ok := _u.mutation.CommissionValue(); ok { + _spec.SetField(shops.FieldCommissionValue, field.TypeOther, value) + } + if value, ok := _u.mutation.AllowMultiShop(); ok { + _spec.SetField(shops.FieldAllowMultiShop, field.TypeBool, value) + } + if _u.mutation.AllowMultiShopCleared() { + _spec.ClearField(shops.FieldAllowMultiShop, field.TypeBool) + } + if value, ok := _u.mutation.AllowIndependentOrders(); ok { + _spec.SetField(shops.FieldAllowIndependentOrders, field.TypeBool, value) + } + if _u.mutation.AllowIndependentOrdersCleared() { + _spec.ClearField(shops.FieldAllowIndependentOrders, field.TypeBool) + } + if value, ok := _u.mutation.DispatchMode(); ok { + _spec.SetField(shops.FieldDispatchMode, field.TypeString, value) + } + if value, ok := _u.mutation.Announcements(); ok { + _spec.SetField(shops.FieldAnnouncements, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedAnnouncements(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, shops.FieldAnnouncements, value) + }) + } + if _u.mutation.AnnouncementsCleared() { + _spec.ClearField(shops.FieldAnnouncements, field.TypeJSON) + } + if value, ok := _u.mutation.TemplateConfig(); ok { + _spec.SetField(shops.FieldTemplateConfig, field.TypeJSON, value) + } + if _u.mutation.TemplateConfigCleared() { + _spec.ClearField(shops.FieldTemplateConfig, field.TypeJSON) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(shops.FieldUpdatedAt, field.TypeTime, value) + } + _node = &Shops{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{shops.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/app/shop/rpc/internal/models/tx.go b/app/shop/rpc/internal/models/tx.go new file mode 100644 index 0000000..4fe4c62 --- /dev/null +++ b/app/shop/rpc/internal/models/tx.go @@ -0,0 +1,216 @@ +// Code generated by ent, DO NOT EDIT. + +package models + +import ( + "context" + "sync" + + "entgo.io/ent/dialect" +) + +// Tx is a transactional client that is created by calling Client.Tx(). +type Tx struct { + config + // ShopInvitations is the client for interacting with the ShopInvitations builders. + ShopInvitations *ShopInvitationsClient + // ShopPlayers is the client for interacting with the ShopPlayers builders. + ShopPlayers *ShopPlayersClient + // Shops is the client for interacting with the Shops builders. + Shops *ShopsClient + + // lazily loaded. + client *Client + clientOnce sync.Once + // ctx lives for the life of the transaction. It is + // the same context used by the underlying connection. + ctx context.Context +} + +type ( + // Committer is the interface that wraps the Commit method. + Committer interface { + Commit(context.Context, *Tx) error + } + + // The CommitFunc type is an adapter to allow the use of ordinary + // function as a Committer. If f is a function with the appropriate + // signature, CommitFunc(f) is a Committer that calls f. + CommitFunc func(context.Context, *Tx) error + + // CommitHook defines the "commit middleware". A function that gets a Committer + // and returns a Committer. For example: + // + // hook := func(next ent.Committer) ent.Committer { + // return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error { + // // Do some stuff before. + // if err := next.Commit(ctx, tx); err != nil { + // return err + // } + // // Do some stuff after. + // return nil + // }) + // } + // + CommitHook func(Committer) Committer +) + +// Commit calls f(ctx, m). +func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error { + return f(ctx, tx) +} + +// Commit commits the transaction. +func (tx *Tx) Commit() error { + txDriver := tx.config.driver.(*txDriver) + var fn Committer = CommitFunc(func(context.Context, *Tx) error { + return txDriver.tx.Commit() + }) + txDriver.mu.Lock() + hooks := append([]CommitHook(nil), txDriver.onCommit...) + txDriver.mu.Unlock() + for i := len(hooks) - 1; i >= 0; i-- { + fn = hooks[i](fn) + } + return fn.Commit(tx.ctx, tx) +} + +// OnCommit adds a hook to call on commit. +func (tx *Tx) OnCommit(f CommitHook) { + txDriver := tx.config.driver.(*txDriver) + txDriver.mu.Lock() + txDriver.onCommit = append(txDriver.onCommit, f) + txDriver.mu.Unlock() +} + +type ( + // Rollbacker is the interface that wraps the Rollback method. + Rollbacker interface { + Rollback(context.Context, *Tx) error + } + + // The RollbackFunc type is an adapter to allow the use of ordinary + // function as a Rollbacker. If f is a function with the appropriate + // signature, RollbackFunc(f) is a Rollbacker that calls f. + RollbackFunc func(context.Context, *Tx) error + + // RollbackHook defines the "rollback middleware". A function that gets a Rollbacker + // and returns a Rollbacker. For example: + // + // hook := func(next ent.Rollbacker) ent.Rollbacker { + // return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error { + // // Do some stuff before. + // if err := next.Rollback(ctx, tx); err != nil { + // return err + // } + // // Do some stuff after. + // return nil + // }) + // } + // + RollbackHook func(Rollbacker) Rollbacker +) + +// Rollback calls f(ctx, m). +func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error { + return f(ctx, tx) +} + +// Rollback rollbacks the transaction. +func (tx *Tx) Rollback() error { + txDriver := tx.config.driver.(*txDriver) + var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error { + return txDriver.tx.Rollback() + }) + txDriver.mu.Lock() + hooks := append([]RollbackHook(nil), txDriver.onRollback...) + txDriver.mu.Unlock() + for i := len(hooks) - 1; i >= 0; i-- { + fn = hooks[i](fn) + } + return fn.Rollback(tx.ctx, tx) +} + +// OnRollback adds a hook to call on rollback. +func (tx *Tx) OnRollback(f RollbackHook) { + txDriver := tx.config.driver.(*txDriver) + txDriver.mu.Lock() + txDriver.onRollback = append(txDriver.onRollback, f) + txDriver.mu.Unlock() +} + +// Client returns a Client that binds to current transaction. +func (tx *Tx) Client() *Client { + tx.clientOnce.Do(func() { + tx.client = &Client{config: tx.config} + tx.client.init() + }) + return tx.client +} + +func (tx *Tx) init() { + tx.ShopInvitations = NewShopInvitationsClient(tx.config) + tx.ShopPlayers = NewShopPlayersClient(tx.config) + tx.Shops = NewShopsClient(tx.config) +} + +// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation. +// The idea is to support transactions without adding any extra code to the builders. +// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance. +// Commit and Rollback are nop for the internal builders and the user must call one +// of them in order to commit or rollback the transaction. +// +// If a closed transaction is embedded in one of the generated entities, and the entity +// applies a query, for example: ShopInvitations.QueryXXX(), the query will be executed +// through the driver which created this transaction. +// +// Note that txDriver is not goroutine safe. +type txDriver struct { + // the driver we started the transaction from. + drv dialect.Driver + // tx is the underlying transaction. + tx dialect.Tx + // completion hooks. + mu sync.Mutex + onCommit []CommitHook + onRollback []RollbackHook +} + +// newTx creates a new transactional driver. +func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) { + tx, err := drv.Tx(ctx) + if err != nil { + return nil, err + } + return &txDriver{tx: tx, drv: drv}, nil +} + +// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls +// from the internal builders. Should be called only by the internal builders. +func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil } + +// Dialect returns the dialect of the driver we started the transaction from. +func (tx *txDriver) Dialect() string { return tx.drv.Dialect() } + +// Close is a nop close. +func (*txDriver) Close() error { return nil } + +// Commit is a nop commit for the internal builders. +// User must call `Tx.Commit` in order to commit the transaction. +func (*txDriver) Commit() error { return nil } + +// Rollback is a nop rollback for the internal builders. +// User must call `Tx.Rollback` in order to rollback the transaction. +func (*txDriver) Rollback() error { return nil } + +// Exec calls tx.Exec. +func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error { + return tx.tx.Exec(ctx, query, args, v) +} + +// Query calls tx.Query. +func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error { + return tx.tx.Query(ctx, query, args, v) +} + +var _ dialect.Driver = (*txDriver)(nil) diff --git a/app/shop/rpc/internal/server/shopServiceServer.go b/app/shop/rpc/internal/server/shopServiceServer.go new file mode 100644 index 0000000..c724ba1 --- /dev/null +++ b/app/shop/rpc/internal/server/shopServiceServer.go @@ -0,0 +1,102 @@ +// Code generated by goctl. DO NOT EDIT. +// goctl 1.9.2 +// Source: shop.proto + +package server + +import ( + "context" + + "juwan-backend/app/shop/rpc/internal/logic" + "juwan-backend/app/shop/rpc/internal/svc" + "juwan-backend/app/shop/rpc/pb" +) + +type ShopServiceServer struct { + svcCtx *svc.ServiceContext + pb.UnimplementedShopServiceServer +} + +func NewShopServiceServer(svcCtx *svc.ServiceContext) *ShopServiceServer { + return &ShopServiceServer{ + svcCtx: svcCtx, + } +} + +// -----------------------shopInvitations----------------------- +func (s *ShopServiceServer) AddShopInvitations(ctx context.Context, in *pb.AddShopInvitationsReq) (*pb.AddShopInvitationsResp, error) { + l := logic.NewAddShopInvitationsLogic(ctx, s.svcCtx) + return l.AddShopInvitations(in) +} + +func (s *ShopServiceServer) UpdateShopInvitations(ctx context.Context, in *pb.UpdateShopInvitationsReq) (*pb.UpdateShopInvitationsResp, error) { + l := logic.NewUpdateShopInvitationsLogic(ctx, s.svcCtx) + return l.UpdateShopInvitations(in) +} + +func (s *ShopServiceServer) DelShopInvitations(ctx context.Context, in *pb.DelShopInvitationsReq) (*pb.DelShopInvitationsResp, error) { + l := logic.NewDelShopInvitationsLogic(ctx, s.svcCtx) + return l.DelShopInvitations(in) +} + +func (s *ShopServiceServer) GetShopInvitationsById(ctx context.Context, in *pb.GetShopInvitationsByIdReq) (*pb.GetShopInvitationsByIdResp, error) { + l := logic.NewGetShopInvitationsByIdLogic(ctx, s.svcCtx) + return l.GetShopInvitationsById(in) +} + +func (s *ShopServiceServer) SearchShopInvitations(ctx context.Context, in *pb.SearchShopInvitationsReq) (*pb.SearchShopInvitationsResp, error) { + l := logic.NewSearchShopInvitationsLogic(ctx, s.svcCtx) + return l.SearchShopInvitations(in) +} + +// -----------------------shopPlayers----------------------- +func (s *ShopServiceServer) AddShopPlayers(ctx context.Context, in *pb.AddShopPlayersReq) (*pb.AddShopPlayersResp, error) { + l := logic.NewAddShopPlayersLogic(ctx, s.svcCtx) + return l.AddShopPlayers(in) +} + +func (s *ShopServiceServer) UpdateShopPlayers(ctx context.Context, in *pb.UpdateShopPlayersReq) (*pb.UpdateShopPlayersResp, error) { + l := logic.NewUpdateShopPlayersLogic(ctx, s.svcCtx) + return l.UpdateShopPlayers(in) +} + +func (s *ShopServiceServer) DelShopPlayers(ctx context.Context, in *pb.DelShopPlayersReq) (*pb.DelShopPlayersResp, error) { + l := logic.NewDelShopPlayersLogic(ctx, s.svcCtx) + return l.DelShopPlayers(in) +} + +func (s *ShopServiceServer) GetShopPlayersById(ctx context.Context, in *pb.GetShopPlayersByIdReq) (*pb.GetShopPlayersByIdResp, error) { + l := logic.NewGetShopPlayersByIdLogic(ctx, s.svcCtx) + return l.GetShopPlayersById(in) +} + +func (s *ShopServiceServer) SearchShopPlayers(ctx context.Context, in *pb.SearchShopPlayersReq) (*pb.SearchShopPlayersResp, error) { + l := logic.NewSearchShopPlayersLogic(ctx, s.svcCtx) + return l.SearchShopPlayers(in) +} + +// -----------------------shops----------------------- +func (s *ShopServiceServer) AddShops(ctx context.Context, in *pb.AddShopsReq) (*pb.AddShopsResp, error) { + l := logic.NewAddShopsLogic(ctx, s.svcCtx) + return l.AddShops(in) +} + +func (s *ShopServiceServer) UpdateShops(ctx context.Context, in *pb.UpdateShopsReq) (*pb.UpdateShopsResp, error) { + l := logic.NewUpdateShopsLogic(ctx, s.svcCtx) + return l.UpdateShops(in) +} + +func (s *ShopServiceServer) DelShops(ctx context.Context, in *pb.DelShopsReq) (*pb.DelShopsResp, error) { + l := logic.NewDelShopsLogic(ctx, s.svcCtx) + return l.DelShops(in) +} + +func (s *ShopServiceServer) GetShopsById(ctx context.Context, in *pb.GetShopsByIdReq) (*pb.GetShopsByIdResp, error) { + l := logic.NewGetShopsByIdLogic(ctx, s.svcCtx) + return l.GetShopsById(in) +} + +func (s *ShopServiceServer) SearchShops(ctx context.Context, in *pb.SearchShopsReq) (*pb.SearchShopsResp, error) { + l := logic.NewSearchShopsLogic(ctx, s.svcCtx) + return l.SearchShops(in) +} diff --git a/app/shop/rpc/internal/svc/serviceContext.go b/app/shop/rpc/internal/svc/serviceContext.go new file mode 100644 index 0000000..86db977 --- /dev/null +++ b/app/shop/rpc/internal/svc/serviceContext.go @@ -0,0 +1,49 @@ +package svc + +import ( + "juwan-backend/app/shop/rpc/internal/config" + "juwan-backend/app/shop/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 + ShopModelRW *models.Client + ShopModelRO *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) + } + // snowflakex.NewClient(c.SnowflakeRpcConf) + + 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, + Snowflake: snowflakex.NewClient(c.SnowflakeRpcConf), + ShopModelRO: models.NewClient(models.Driver(RODrv)), + ShopModelRW: models.NewClient(models.Driver(RWDrv)), + } +} diff --git a/app/shop/rpc/pb.go b/app/shop/rpc/pb.go new file mode 100644 index 0000000..09a35aa --- /dev/null +++ b/app/shop/rpc/pb.go @@ -0,0 +1,39 @@ +package main + +import ( + "flag" + "fmt" + + "juwan-backend/app/shop/rpc/internal/config" + "juwan-backend/app/shop/rpc/internal/server" + "juwan-backend/app/shop/rpc/internal/svc" + "juwan-backend/app/shop/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.RegisterShopServiceServer(grpcServer, server.NewShopServiceServer(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() +} diff --git a/app/shop/rpc/pb/shop.pb.go b/app/shop/rpc/pb/shop.pb.go new file mode 100644 index 0000000..cac520c --- /dev/null +++ b/app/shop/rpc/pb/shop.pb.go @@ -0,0 +1,2577 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.11 +// protoc v5.29.6 +// source: shop.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) +) + +// --------------------------------shopInvitations-------------------------------- +type ShopInvitations struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id + ShopId int64 `protobuf:"varint,2,opt,name=shopId,proto3" json:"shopId,omitempty"` //shopId + PlayerId int64 `protobuf:"varint,3,opt,name=playerId,proto3" json:"playerId,omitempty"` //playerId + Status string `protobuf:"bytes,4,opt,name=status,proto3" json:"status,omitempty"` //status + InvitedBy int64 `protobuf:"varint,5,opt,name=invitedBy,proto3" json:"invitedBy,omitempty"` //invitedBy + CreatedAt int64 `protobuf:"varint,6,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt + RespondedAt int64 `protobuf:"varint,7,opt,name=respondedAt,proto3" json:"respondedAt,omitempty"` //respondedAt + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ShopInvitations) Reset() { + *x = ShopInvitations{} + mi := &file_shop_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ShopInvitations) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShopInvitations) ProtoMessage() {} + +func (x *ShopInvitations) ProtoReflect() protoreflect.Message { + mi := &file_shop_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 ShopInvitations.ProtoReflect.Descriptor instead. +func (*ShopInvitations) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{0} +} + +func (x *ShopInvitations) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *ShopInvitations) GetShopId() int64 { + if x != nil { + return x.ShopId + } + return 0 +} + +func (x *ShopInvitations) GetPlayerId() int64 { + if x != nil { + return x.PlayerId + } + return 0 +} + +func (x *ShopInvitations) GetStatus() string { + if x != nil { + return x.Status + } + return "" +} + +func (x *ShopInvitations) GetInvitedBy() int64 { + if x != nil { + return x.InvitedBy + } + return 0 +} + +func (x *ShopInvitations) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *ShopInvitations) GetRespondedAt() int64 { + if x != nil { + return x.RespondedAt + } + return 0 +} + +type AddShopInvitationsReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + ShopId int64 `protobuf:"varint,1,opt,name=shopId,proto3" json:"shopId,omitempty"` //shopId + PlayerId int64 `protobuf:"varint,2,opt,name=playerId,proto3" json:"playerId,omitempty"` //playerId + Status string `protobuf:"bytes,3,opt,name=status,proto3" json:"status,omitempty"` //status + InvitedBy int64 `protobuf:"varint,4,opt,name=invitedBy,proto3" json:"invitedBy,omitempty"` //invitedBy + CreatedAt int64 `protobuf:"varint,5,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt + RespondedAt int64 `protobuf:"varint,6,opt,name=respondedAt,proto3" json:"respondedAt,omitempty"` //respondedAt + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AddShopInvitationsReq) Reset() { + *x = AddShopInvitationsReq{} + mi := &file_shop_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AddShopInvitationsReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AddShopInvitationsReq) ProtoMessage() {} + +func (x *AddShopInvitationsReq) ProtoReflect() protoreflect.Message { + mi := &file_shop_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 AddShopInvitationsReq.ProtoReflect.Descriptor instead. +func (*AddShopInvitationsReq) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{1} +} + +func (x *AddShopInvitationsReq) GetShopId() int64 { + if x != nil { + return x.ShopId + } + return 0 +} + +func (x *AddShopInvitationsReq) GetPlayerId() int64 { + if x != nil { + return x.PlayerId + } + return 0 +} + +func (x *AddShopInvitationsReq) GetStatus() string { + if x != nil { + return x.Status + } + return "" +} + +func (x *AddShopInvitationsReq) GetInvitedBy() int64 { + if x != nil { + return x.InvitedBy + } + return 0 +} + +func (x *AddShopInvitationsReq) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *AddShopInvitationsReq) GetRespondedAt() int64 { + if x != nil { + return x.RespondedAt + } + return 0 +} + +type AddShopInvitationsResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AddShopInvitationsResp) Reset() { + *x = AddShopInvitationsResp{} + mi := &file_shop_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AddShopInvitationsResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AddShopInvitationsResp) ProtoMessage() {} + +func (x *AddShopInvitationsResp) ProtoReflect() protoreflect.Message { + mi := &file_shop_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 AddShopInvitationsResp.ProtoReflect.Descriptor instead. +func (*AddShopInvitationsResp) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{2} +} + +type UpdateShopInvitationsReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id + ShopId int64 `protobuf:"varint,2,opt,name=shopId,proto3" json:"shopId,omitempty"` //shopId + PlayerId int64 `protobuf:"varint,3,opt,name=playerId,proto3" json:"playerId,omitempty"` //playerId + Status string `protobuf:"bytes,4,opt,name=status,proto3" json:"status,omitempty"` //status + InvitedBy int64 `protobuf:"varint,5,opt,name=invitedBy,proto3" json:"invitedBy,omitempty"` //invitedBy + CreatedAt int64 `protobuf:"varint,6,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt + RespondedAt int64 `protobuf:"varint,7,opt,name=respondedAt,proto3" json:"respondedAt,omitempty"` //respondedAt + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *UpdateShopInvitationsReq) Reset() { + *x = UpdateShopInvitationsReq{} + mi := &file_shop_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UpdateShopInvitationsReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateShopInvitationsReq) ProtoMessage() {} + +func (x *UpdateShopInvitationsReq) ProtoReflect() protoreflect.Message { + mi := &file_shop_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 UpdateShopInvitationsReq.ProtoReflect.Descriptor instead. +func (*UpdateShopInvitationsReq) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{3} +} + +func (x *UpdateShopInvitationsReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *UpdateShopInvitationsReq) GetShopId() int64 { + if x != nil { + return x.ShopId + } + return 0 +} + +func (x *UpdateShopInvitationsReq) GetPlayerId() int64 { + if x != nil { + return x.PlayerId + } + return 0 +} + +func (x *UpdateShopInvitationsReq) GetStatus() string { + if x != nil { + return x.Status + } + return "" +} + +func (x *UpdateShopInvitationsReq) GetInvitedBy() int64 { + if x != nil { + return x.InvitedBy + } + return 0 +} + +func (x *UpdateShopInvitationsReq) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *UpdateShopInvitationsReq) GetRespondedAt() int64 { + if x != nil { + return x.RespondedAt + } + return 0 +} + +type UpdateShopInvitationsResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *UpdateShopInvitationsResp) Reset() { + *x = UpdateShopInvitationsResp{} + mi := &file_shop_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UpdateShopInvitationsResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateShopInvitationsResp) ProtoMessage() {} + +func (x *UpdateShopInvitationsResp) ProtoReflect() protoreflect.Message { + mi := &file_shop_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 UpdateShopInvitationsResp.ProtoReflect.Descriptor instead. +func (*UpdateShopInvitationsResp) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{4} +} + +type DelShopInvitationsReq 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 *DelShopInvitationsReq) Reset() { + *x = DelShopInvitationsReq{} + mi := &file_shop_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DelShopInvitationsReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DelShopInvitationsReq) ProtoMessage() {} + +func (x *DelShopInvitationsReq) ProtoReflect() protoreflect.Message { + mi := &file_shop_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 DelShopInvitationsReq.ProtoReflect.Descriptor instead. +func (*DelShopInvitationsReq) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{5} +} + +func (x *DelShopInvitationsReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type DelShopInvitationsResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *DelShopInvitationsResp) Reset() { + *x = DelShopInvitationsResp{} + mi := &file_shop_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DelShopInvitationsResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DelShopInvitationsResp) ProtoMessage() {} + +func (x *DelShopInvitationsResp) ProtoReflect() protoreflect.Message { + mi := &file_shop_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 DelShopInvitationsResp.ProtoReflect.Descriptor instead. +func (*DelShopInvitationsResp) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{6} +} + +type GetShopInvitationsByIdReq 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 *GetShopInvitationsByIdReq) Reset() { + *x = GetShopInvitationsByIdReq{} + mi := &file_shop_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetShopInvitationsByIdReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetShopInvitationsByIdReq) ProtoMessage() {} + +func (x *GetShopInvitationsByIdReq) ProtoReflect() protoreflect.Message { + mi := &file_shop_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 GetShopInvitationsByIdReq.ProtoReflect.Descriptor instead. +func (*GetShopInvitationsByIdReq) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{7} +} + +func (x *GetShopInvitationsByIdReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type GetShopInvitationsByIdResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + ShopInvitations *ShopInvitations `protobuf:"bytes,1,opt,name=shopInvitations,proto3" json:"shopInvitations,omitempty"` //shopInvitations + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *GetShopInvitationsByIdResp) Reset() { + *x = GetShopInvitationsByIdResp{} + mi := &file_shop_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetShopInvitationsByIdResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetShopInvitationsByIdResp) ProtoMessage() {} + +func (x *GetShopInvitationsByIdResp) ProtoReflect() protoreflect.Message { + mi := &file_shop_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 GetShopInvitationsByIdResp.ProtoReflect.Descriptor instead. +func (*GetShopInvitationsByIdResp) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{8} +} + +func (x *GetShopInvitationsByIdResp) GetShopInvitations() *ShopInvitations { + if x != nil { + return x.ShopInvitations + } + return nil +} + +type SearchShopInvitationsReq 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 + ShopId int64 `protobuf:"varint,4,opt,name=shopId,proto3" json:"shopId,omitempty"` //shopId + PlayerId int64 `protobuf:"varint,5,opt,name=playerId,proto3" json:"playerId,omitempty"` //playerId + Status string `protobuf:"bytes,6,opt,name=status,proto3" json:"status,omitempty"` //status + InvitedBy int64 `protobuf:"varint,7,opt,name=invitedBy,proto3" json:"invitedBy,omitempty"` //invitedBy + CreatedAt int64 `protobuf:"varint,8,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt + RespondedAt int64 `protobuf:"varint,9,opt,name=respondedAt,proto3" json:"respondedAt,omitempty"` //respondedAt + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SearchShopInvitationsReq) Reset() { + *x = SearchShopInvitationsReq{} + mi := &file_shop_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SearchShopInvitationsReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SearchShopInvitationsReq) ProtoMessage() {} + +func (x *SearchShopInvitationsReq) ProtoReflect() protoreflect.Message { + mi := &file_shop_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 SearchShopInvitationsReq.ProtoReflect.Descriptor instead. +func (*SearchShopInvitationsReq) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{9} +} + +func (x *SearchShopInvitationsReq) GetPage() int64 { + if x != nil { + return x.Page + } + return 0 +} + +func (x *SearchShopInvitationsReq) GetLimit() int64 { + if x != nil { + return x.Limit + } + return 0 +} + +func (x *SearchShopInvitationsReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *SearchShopInvitationsReq) GetShopId() int64 { + if x != nil { + return x.ShopId + } + return 0 +} + +func (x *SearchShopInvitationsReq) GetPlayerId() int64 { + if x != nil { + return x.PlayerId + } + return 0 +} + +func (x *SearchShopInvitationsReq) GetStatus() string { + if x != nil { + return x.Status + } + return "" +} + +func (x *SearchShopInvitationsReq) GetInvitedBy() int64 { + if x != nil { + return x.InvitedBy + } + return 0 +} + +func (x *SearchShopInvitationsReq) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *SearchShopInvitationsReq) GetRespondedAt() int64 { + if x != nil { + return x.RespondedAt + } + return 0 +} + +type SearchShopInvitationsResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + ShopInvitations []*ShopInvitations `protobuf:"bytes,1,rep,name=shopInvitations,proto3" json:"shopInvitations,omitempty"` //shopInvitations + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SearchShopInvitationsResp) Reset() { + *x = SearchShopInvitationsResp{} + mi := &file_shop_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SearchShopInvitationsResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SearchShopInvitationsResp) ProtoMessage() {} + +func (x *SearchShopInvitationsResp) ProtoReflect() protoreflect.Message { + mi := &file_shop_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 SearchShopInvitationsResp.ProtoReflect.Descriptor instead. +func (*SearchShopInvitationsResp) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{10} +} + +func (x *SearchShopInvitationsResp) GetShopInvitations() []*ShopInvitations { + if x != nil { + return x.ShopInvitations + } + return nil +} + +// --------------------------------shopPlayers-------------------------------- +type ShopPlayers struct { + state protoimpl.MessageState `protogen:"open.v1"` + ShopId int64 `protobuf:"varint,1,opt,name=shopId,proto3" json:"shopId,omitempty"` //shopId + PlayerId int64 `protobuf:"varint,2,opt,name=playerId,proto3" json:"playerId,omitempty"` //playerId + IsPrimary bool `protobuf:"varint,3,opt,name=isPrimary,proto3" json:"isPrimary,omitempty"` //isPrimary + JoinedAt int64 `protobuf:"varint,4,opt,name=joinedAt,proto3" json:"joinedAt,omitempty"` //joinedAt + LeftAt int64 `protobuf:"varint,5,opt,name=leftAt,proto3" json:"leftAt,omitempty"` //leftAt + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ShopPlayers) Reset() { + *x = ShopPlayers{} + mi := &file_shop_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ShopPlayers) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShopPlayers) ProtoMessage() {} + +func (x *ShopPlayers) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[11] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShopPlayers.ProtoReflect.Descriptor instead. +func (*ShopPlayers) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{11} +} + +func (x *ShopPlayers) GetShopId() int64 { + if x != nil { + return x.ShopId + } + return 0 +} + +func (x *ShopPlayers) GetPlayerId() int64 { + if x != nil { + return x.PlayerId + } + return 0 +} + +func (x *ShopPlayers) GetIsPrimary() bool { + if x != nil { + return x.IsPrimary + } + return false +} + +func (x *ShopPlayers) GetJoinedAt() int64 { + if x != nil { + return x.JoinedAt + } + return 0 +} + +func (x *ShopPlayers) GetLeftAt() int64 { + if x != nil { + return x.LeftAt + } + return 0 +} + +type AddShopPlayersReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + ShopId int64 `protobuf:"varint,1,opt,name=shopId,proto3" json:"shopId,omitempty"` //shopId + PlayerId int64 `protobuf:"varint,2,opt,name=playerId,proto3" json:"playerId,omitempty"` //playerId + IsPrimary bool `protobuf:"varint,3,opt,name=isPrimary,proto3" json:"isPrimary,omitempty"` //isPrimary + JoinedAt int64 `protobuf:"varint,4,opt,name=joinedAt,proto3" json:"joinedAt,omitempty"` //joinedAt + LeftAt int64 `protobuf:"varint,5,opt,name=leftAt,proto3" json:"leftAt,omitempty"` //leftAt + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AddShopPlayersReq) Reset() { + *x = AddShopPlayersReq{} + mi := &file_shop_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AddShopPlayersReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AddShopPlayersReq) ProtoMessage() {} + +func (x *AddShopPlayersReq) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[12] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AddShopPlayersReq.ProtoReflect.Descriptor instead. +func (*AddShopPlayersReq) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{12} +} + +func (x *AddShopPlayersReq) GetShopId() int64 { + if x != nil { + return x.ShopId + } + return 0 +} + +func (x *AddShopPlayersReq) GetPlayerId() int64 { + if x != nil { + return x.PlayerId + } + return 0 +} + +func (x *AddShopPlayersReq) GetIsPrimary() bool { + if x != nil { + return x.IsPrimary + } + return false +} + +func (x *AddShopPlayersReq) GetJoinedAt() int64 { + if x != nil { + return x.JoinedAt + } + return 0 +} + +func (x *AddShopPlayersReq) GetLeftAt() int64 { + if x != nil { + return x.LeftAt + } + return 0 +} + +type AddShopPlayersResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AddShopPlayersResp) Reset() { + *x = AddShopPlayersResp{} + mi := &file_shop_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AddShopPlayersResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AddShopPlayersResp) ProtoMessage() {} + +func (x *AddShopPlayersResp) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[13] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AddShopPlayersResp.ProtoReflect.Descriptor instead. +func (*AddShopPlayersResp) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{13} +} + +type UpdateShopPlayersReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + ShopId int64 `protobuf:"varint,1,opt,name=shopId,proto3" json:"shopId,omitempty"` //shopId + PlayerId int64 `protobuf:"varint,2,opt,name=playerId,proto3" json:"playerId,omitempty"` //playerId + IsPrimary bool `protobuf:"varint,3,opt,name=isPrimary,proto3" json:"isPrimary,omitempty"` //isPrimary + JoinedAt int64 `protobuf:"varint,4,opt,name=joinedAt,proto3" json:"joinedAt,omitempty"` //joinedAt + LeftAt int64 `protobuf:"varint,5,opt,name=leftAt,proto3" json:"leftAt,omitempty"` //leftAt + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *UpdateShopPlayersReq) Reset() { + *x = UpdateShopPlayersReq{} + mi := &file_shop_proto_msgTypes[14] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UpdateShopPlayersReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateShopPlayersReq) ProtoMessage() {} + +func (x *UpdateShopPlayersReq) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[14] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateShopPlayersReq.ProtoReflect.Descriptor instead. +func (*UpdateShopPlayersReq) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{14} +} + +func (x *UpdateShopPlayersReq) GetShopId() int64 { + if x != nil { + return x.ShopId + } + return 0 +} + +func (x *UpdateShopPlayersReq) GetPlayerId() int64 { + if x != nil { + return x.PlayerId + } + return 0 +} + +func (x *UpdateShopPlayersReq) GetIsPrimary() bool { + if x != nil { + return x.IsPrimary + } + return false +} + +func (x *UpdateShopPlayersReq) GetJoinedAt() int64 { + if x != nil { + return x.JoinedAt + } + return 0 +} + +func (x *UpdateShopPlayersReq) GetLeftAt() int64 { + if x != nil { + return x.LeftAt + } + return 0 +} + +type UpdateShopPlayersResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *UpdateShopPlayersResp) Reset() { + *x = UpdateShopPlayersResp{} + mi := &file_shop_proto_msgTypes[15] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UpdateShopPlayersResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateShopPlayersResp) ProtoMessage() {} + +func (x *UpdateShopPlayersResp) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[15] + 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 UpdateShopPlayersResp.ProtoReflect.Descriptor instead. +func (*UpdateShopPlayersResp) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{15} +} + +type DelShopPlayersReq 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 *DelShopPlayersReq) Reset() { + *x = DelShopPlayersReq{} + mi := &file_shop_proto_msgTypes[16] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DelShopPlayersReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DelShopPlayersReq) ProtoMessage() {} + +func (x *DelShopPlayersReq) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[16] + 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 DelShopPlayersReq.ProtoReflect.Descriptor instead. +func (*DelShopPlayersReq) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{16} +} + +func (x *DelShopPlayersReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type DelShopPlayersResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *DelShopPlayersResp) Reset() { + *x = DelShopPlayersResp{} + mi := &file_shop_proto_msgTypes[17] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DelShopPlayersResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DelShopPlayersResp) ProtoMessage() {} + +func (x *DelShopPlayersResp) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[17] + 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 DelShopPlayersResp.ProtoReflect.Descriptor instead. +func (*DelShopPlayersResp) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{17} +} + +type GetShopPlayersByIdReq 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 *GetShopPlayersByIdReq) Reset() { + *x = GetShopPlayersByIdReq{} + mi := &file_shop_proto_msgTypes[18] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetShopPlayersByIdReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetShopPlayersByIdReq) ProtoMessage() {} + +func (x *GetShopPlayersByIdReq) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[18] + 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 GetShopPlayersByIdReq.ProtoReflect.Descriptor instead. +func (*GetShopPlayersByIdReq) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{18} +} + +func (x *GetShopPlayersByIdReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type GetShopPlayersByIdResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + ShopPlayers *ShopPlayers `protobuf:"bytes,1,opt,name=shopPlayers,proto3" json:"shopPlayers,omitempty"` //shopPlayers + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *GetShopPlayersByIdResp) Reset() { + *x = GetShopPlayersByIdResp{} + mi := &file_shop_proto_msgTypes[19] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetShopPlayersByIdResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetShopPlayersByIdResp) ProtoMessage() {} + +func (x *GetShopPlayersByIdResp) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[19] + 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 GetShopPlayersByIdResp.ProtoReflect.Descriptor instead. +func (*GetShopPlayersByIdResp) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{19} +} + +func (x *GetShopPlayersByIdResp) GetShopPlayers() *ShopPlayers { + if x != nil { + return x.ShopPlayers + } + return nil +} + +type SearchShopPlayersReq 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 + ShopId int64 `protobuf:"varint,3,opt,name=shopId,proto3" json:"shopId,omitempty"` //shopId + PlayerId int64 `protobuf:"varint,4,opt,name=playerId,proto3" json:"playerId,omitempty"` //playerId + IsPrimary bool `protobuf:"varint,5,opt,name=isPrimary,proto3" json:"isPrimary,omitempty"` //isPrimary + JoinedAt int64 `protobuf:"varint,6,opt,name=joinedAt,proto3" json:"joinedAt,omitempty"` //joinedAt + LeftAt int64 `protobuf:"varint,7,opt,name=leftAt,proto3" json:"leftAt,omitempty"` //leftAt + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SearchShopPlayersReq) Reset() { + *x = SearchShopPlayersReq{} + mi := &file_shop_proto_msgTypes[20] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SearchShopPlayersReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SearchShopPlayersReq) ProtoMessage() {} + +func (x *SearchShopPlayersReq) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[20] + 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 SearchShopPlayersReq.ProtoReflect.Descriptor instead. +func (*SearchShopPlayersReq) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{20} +} + +func (x *SearchShopPlayersReq) GetPage() int64 { + if x != nil { + return x.Page + } + return 0 +} + +func (x *SearchShopPlayersReq) GetLimit() int64 { + if x != nil { + return x.Limit + } + return 0 +} + +func (x *SearchShopPlayersReq) GetShopId() int64 { + if x != nil { + return x.ShopId + } + return 0 +} + +func (x *SearchShopPlayersReq) GetPlayerId() int64 { + if x != nil { + return x.PlayerId + } + return 0 +} + +func (x *SearchShopPlayersReq) GetIsPrimary() bool { + if x != nil { + return x.IsPrimary + } + return false +} + +func (x *SearchShopPlayersReq) GetJoinedAt() int64 { + if x != nil { + return x.JoinedAt + } + return 0 +} + +func (x *SearchShopPlayersReq) GetLeftAt() int64 { + if x != nil { + return x.LeftAt + } + return 0 +} + +type SearchShopPlayersResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + ShopPlayers []*ShopPlayers `protobuf:"bytes,1,rep,name=shopPlayers,proto3" json:"shopPlayers,omitempty"` //shopPlayers + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SearchShopPlayersResp) Reset() { + *x = SearchShopPlayersResp{} + mi := &file_shop_proto_msgTypes[21] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SearchShopPlayersResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SearchShopPlayersResp) ProtoMessage() {} + +func (x *SearchShopPlayersResp) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[21] + 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 SearchShopPlayersResp.ProtoReflect.Descriptor instead. +func (*SearchShopPlayersResp) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{21} +} + +func (x *SearchShopPlayersResp) GetShopPlayers() []*ShopPlayers { + if x != nil { + return x.ShopPlayers + } + return nil +} + +// --------------------------------shops-------------------------------- +type Shops struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id + OwnerId int64 `protobuf:"varint,2,opt,name=ownerId,proto3" json:"ownerId,omitempty"` //ownerId + Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` //name + Banner string `protobuf:"bytes,4,opt,name=banner,proto3" json:"banner,omitempty"` //banner + Description string `protobuf:"bytes,5,opt,name=description,proto3" json:"description,omitempty"` //description + Rating float64 `protobuf:"fixed64,6,opt,name=rating,proto3" json:"rating,omitempty"` //rating + TotalOrders int64 `protobuf:"varint,7,opt,name=totalOrders,proto3" json:"totalOrders,omitempty"` //totalOrders + PlayerCount int64 `protobuf:"varint,8,opt,name=playerCount,proto3" json:"playerCount,omitempty"` //playerCount + CommissionType string `protobuf:"bytes,9,opt,name=commissionType,proto3" json:"commissionType,omitempty"` //commissionType + CommissionValue float64 `protobuf:"fixed64,10,opt,name=commissionValue,proto3" json:"commissionValue,omitempty"` //commissionValue + AllowMultiShop bool `protobuf:"varint,11,opt,name=allowMultiShop,proto3" json:"allowMultiShop,omitempty"` //allowMultiShop + AllowIndependentOrders bool `protobuf:"varint,12,opt,name=allowIndependentOrders,proto3" json:"allowIndependentOrders,omitempty"` //allowIndependentOrders + DispatchMode string `protobuf:"bytes,13,opt,name=dispatchMode,proto3" json:"dispatchMode,omitempty"` //dispatchMode + Announcements []string `protobuf:"bytes,14,rep,name=announcements,proto3" json:"announcements,omitempty"` //announcements + TemplateConfig string `protobuf:"bytes,15,opt,name=templateConfig,proto3" json:"templateConfig,omitempty"` //templateConfig + CreatedAt int64 `protobuf:"varint,16,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt + UpdatedAt int64 `protobuf:"varint,17,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Shops) Reset() { + *x = Shops{} + mi := &file_shop_proto_msgTypes[22] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Shops) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Shops) ProtoMessage() {} + +func (x *Shops) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[22] + 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 Shops.ProtoReflect.Descriptor instead. +func (*Shops) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{22} +} + +func (x *Shops) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *Shops) GetOwnerId() int64 { + if x != nil { + return x.OwnerId + } + return 0 +} + +func (x *Shops) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Shops) GetBanner() string { + if x != nil { + return x.Banner + } + return "" +} + +func (x *Shops) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +func (x *Shops) GetRating() float64 { + if x != nil { + return x.Rating + } + return 0 +} + +func (x *Shops) GetTotalOrders() int64 { + if x != nil { + return x.TotalOrders + } + return 0 +} + +func (x *Shops) GetPlayerCount() int64 { + if x != nil { + return x.PlayerCount + } + return 0 +} + +func (x *Shops) GetCommissionType() string { + if x != nil { + return x.CommissionType + } + return "" +} + +func (x *Shops) GetCommissionValue() float64 { + if x != nil { + return x.CommissionValue + } + return 0 +} + +func (x *Shops) GetAllowMultiShop() bool { + if x != nil { + return x.AllowMultiShop + } + return false +} + +func (x *Shops) GetAllowIndependentOrders() bool { + if x != nil { + return x.AllowIndependentOrders + } + return false +} + +func (x *Shops) GetDispatchMode() string { + if x != nil { + return x.DispatchMode + } + return "" +} + +func (x *Shops) GetAnnouncements() []string { + if x != nil { + return x.Announcements + } + return nil +} + +func (x *Shops) GetTemplateConfig() string { + if x != nil { + return x.TemplateConfig + } + return "" +} + +func (x *Shops) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *Shops) GetUpdatedAt() int64 { + if x != nil { + return x.UpdatedAt + } + return 0 +} + +type AddShopsReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + OwnerId int64 `protobuf:"varint,1,opt,name=ownerId,proto3" json:"ownerId,omitempty"` //ownerId + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` //name + Banner string `protobuf:"bytes,3,opt,name=banner,proto3" json:"banner,omitempty"` //banner + Description string `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty"` //description + Rating float64 `protobuf:"fixed64,5,opt,name=rating,proto3" json:"rating,omitempty"` //rating + TotalOrders int64 `protobuf:"varint,6,opt,name=totalOrders,proto3" json:"totalOrders,omitempty"` //totalOrders + PlayerCount int64 `protobuf:"varint,7,opt,name=playerCount,proto3" json:"playerCount,omitempty"` //playerCount + CommissionType string `protobuf:"bytes,8,opt,name=commissionType,proto3" json:"commissionType,omitempty"` //commissionType + CommissionValue float64 `protobuf:"fixed64,9,opt,name=commissionValue,proto3" json:"commissionValue,omitempty"` //commissionValue + AllowMultiShop bool `protobuf:"varint,10,opt,name=allowMultiShop,proto3" json:"allowMultiShop,omitempty"` //allowMultiShop + AllowIndependentOrders bool `protobuf:"varint,11,opt,name=allowIndependentOrders,proto3" json:"allowIndependentOrders,omitempty"` //allowIndependentOrders + DispatchMode string `protobuf:"bytes,12,opt,name=dispatchMode,proto3" json:"dispatchMode,omitempty"` //dispatchMode + Announcements []string `protobuf:"bytes,13,rep,name=announcements,proto3" json:"announcements,omitempty"` //announcements + TemplateConfig string `protobuf:"bytes,14,opt,name=templateConfig,proto3" json:"templateConfig,omitempty"` //templateConfig + CreatedAt int64 `protobuf:"varint,15,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt + UpdatedAt int64 `protobuf:"varint,16,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AddShopsReq) Reset() { + *x = AddShopsReq{} + mi := &file_shop_proto_msgTypes[23] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AddShopsReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AddShopsReq) ProtoMessage() {} + +func (x *AddShopsReq) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[23] + 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 AddShopsReq.ProtoReflect.Descriptor instead. +func (*AddShopsReq) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{23} +} + +func (x *AddShopsReq) GetOwnerId() int64 { + if x != nil { + return x.OwnerId + } + return 0 +} + +func (x *AddShopsReq) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *AddShopsReq) GetBanner() string { + if x != nil { + return x.Banner + } + return "" +} + +func (x *AddShopsReq) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +func (x *AddShopsReq) GetRating() float64 { + if x != nil { + return x.Rating + } + return 0 +} + +func (x *AddShopsReq) GetTotalOrders() int64 { + if x != nil { + return x.TotalOrders + } + return 0 +} + +func (x *AddShopsReq) GetPlayerCount() int64 { + if x != nil { + return x.PlayerCount + } + return 0 +} + +func (x *AddShopsReq) GetCommissionType() string { + if x != nil { + return x.CommissionType + } + return "" +} + +func (x *AddShopsReq) GetCommissionValue() float64 { + if x != nil { + return x.CommissionValue + } + return 0 +} + +func (x *AddShopsReq) GetAllowMultiShop() bool { + if x != nil { + return x.AllowMultiShop + } + return false +} + +func (x *AddShopsReq) GetAllowIndependentOrders() bool { + if x != nil { + return x.AllowIndependentOrders + } + return false +} + +func (x *AddShopsReq) GetDispatchMode() string { + if x != nil { + return x.DispatchMode + } + return "" +} + +func (x *AddShopsReq) GetAnnouncements() []string { + if x != nil { + return x.Announcements + } + return nil +} + +func (x *AddShopsReq) GetTemplateConfig() string { + if x != nil { + return x.TemplateConfig + } + return "" +} + +func (x *AddShopsReq) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *AddShopsReq) GetUpdatedAt() int64 { + if x != nil { + return x.UpdatedAt + } + return 0 +} + +type AddShopsResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AddShopsResp) Reset() { + *x = AddShopsResp{} + mi := &file_shop_proto_msgTypes[24] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AddShopsResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AddShopsResp) ProtoMessage() {} + +func (x *AddShopsResp) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[24] + 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 AddShopsResp.ProtoReflect.Descriptor instead. +func (*AddShopsResp) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{24} +} + +type UpdateShopsReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id + OwnerId int64 `protobuf:"varint,2,opt,name=ownerId,proto3" json:"ownerId,omitempty"` //ownerId + Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` //name + Banner string `protobuf:"bytes,4,opt,name=banner,proto3" json:"banner,omitempty"` //banner + Description string `protobuf:"bytes,5,opt,name=description,proto3" json:"description,omitempty"` //description + Rating float64 `protobuf:"fixed64,6,opt,name=rating,proto3" json:"rating,omitempty"` //rating + TotalOrders int64 `protobuf:"varint,7,opt,name=totalOrders,proto3" json:"totalOrders,omitempty"` //totalOrders + PlayerCount int64 `protobuf:"varint,8,opt,name=playerCount,proto3" json:"playerCount,omitempty"` //playerCount + CommissionType string `protobuf:"bytes,9,opt,name=commissionType,proto3" json:"commissionType,omitempty"` //commissionType + CommissionValue float64 `protobuf:"fixed64,10,opt,name=commissionValue,proto3" json:"commissionValue,omitempty"` //commissionValue + AllowMultiShop bool `protobuf:"varint,11,opt,name=allowMultiShop,proto3" json:"allowMultiShop,omitempty"` //allowMultiShop + AllowIndependentOrders bool `protobuf:"varint,12,opt,name=allowIndependentOrders,proto3" json:"allowIndependentOrders,omitempty"` //allowIndependentOrders + DispatchMode string `protobuf:"bytes,13,opt,name=dispatchMode,proto3" json:"dispatchMode,omitempty"` //dispatchMode + Announcements []string `protobuf:"bytes,14,rep,name=announcements,proto3" json:"announcements,omitempty"` //announcements + TemplateConfig string `protobuf:"bytes,15,opt,name=templateConfig,proto3" json:"templateConfig,omitempty"` //templateConfig + CreatedAt int64 `protobuf:"varint,16,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt + UpdatedAt int64 `protobuf:"varint,17,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *UpdateShopsReq) Reset() { + *x = UpdateShopsReq{} + mi := &file_shop_proto_msgTypes[25] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UpdateShopsReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateShopsReq) ProtoMessage() {} + +func (x *UpdateShopsReq) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[25] + 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 UpdateShopsReq.ProtoReflect.Descriptor instead. +func (*UpdateShopsReq) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{25} +} + +func (x *UpdateShopsReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *UpdateShopsReq) GetOwnerId() int64 { + if x != nil { + return x.OwnerId + } + return 0 +} + +func (x *UpdateShopsReq) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *UpdateShopsReq) GetBanner() string { + if x != nil { + return x.Banner + } + return "" +} + +func (x *UpdateShopsReq) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +func (x *UpdateShopsReq) GetRating() float64 { + if x != nil { + return x.Rating + } + return 0 +} + +func (x *UpdateShopsReq) GetTotalOrders() int64 { + if x != nil { + return x.TotalOrders + } + return 0 +} + +func (x *UpdateShopsReq) GetPlayerCount() int64 { + if x != nil { + return x.PlayerCount + } + return 0 +} + +func (x *UpdateShopsReq) GetCommissionType() string { + if x != nil { + return x.CommissionType + } + return "" +} + +func (x *UpdateShopsReq) GetCommissionValue() float64 { + if x != nil { + return x.CommissionValue + } + return 0 +} + +func (x *UpdateShopsReq) GetAllowMultiShop() bool { + if x != nil { + return x.AllowMultiShop + } + return false +} + +func (x *UpdateShopsReq) GetAllowIndependentOrders() bool { + if x != nil { + return x.AllowIndependentOrders + } + return false +} + +func (x *UpdateShopsReq) GetDispatchMode() string { + if x != nil { + return x.DispatchMode + } + return "" +} + +func (x *UpdateShopsReq) GetAnnouncements() []string { + if x != nil { + return x.Announcements + } + return nil +} + +func (x *UpdateShopsReq) GetTemplateConfig() string { + if x != nil { + return x.TemplateConfig + } + return "" +} + +func (x *UpdateShopsReq) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *UpdateShopsReq) GetUpdatedAt() int64 { + if x != nil { + return x.UpdatedAt + } + return 0 +} + +type UpdateShopsResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *UpdateShopsResp) Reset() { + *x = UpdateShopsResp{} + mi := &file_shop_proto_msgTypes[26] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UpdateShopsResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateShopsResp) ProtoMessage() {} + +func (x *UpdateShopsResp) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[26] + 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 UpdateShopsResp.ProtoReflect.Descriptor instead. +func (*UpdateShopsResp) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{26} +} + +type DelShopsReq 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 *DelShopsReq) Reset() { + *x = DelShopsReq{} + mi := &file_shop_proto_msgTypes[27] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DelShopsReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DelShopsReq) ProtoMessage() {} + +func (x *DelShopsReq) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[27] + 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 DelShopsReq.ProtoReflect.Descriptor instead. +func (*DelShopsReq) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{27} +} + +func (x *DelShopsReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type DelShopsResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *DelShopsResp) Reset() { + *x = DelShopsResp{} + mi := &file_shop_proto_msgTypes[28] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DelShopsResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DelShopsResp) ProtoMessage() {} + +func (x *DelShopsResp) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[28] + 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 DelShopsResp.ProtoReflect.Descriptor instead. +func (*DelShopsResp) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{28} +} + +type GetShopsByIdReq 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 *GetShopsByIdReq) Reset() { + *x = GetShopsByIdReq{} + mi := &file_shop_proto_msgTypes[29] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetShopsByIdReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetShopsByIdReq) ProtoMessage() {} + +func (x *GetShopsByIdReq) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[29] + 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 GetShopsByIdReq.ProtoReflect.Descriptor instead. +func (*GetShopsByIdReq) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{29} +} + +func (x *GetShopsByIdReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type GetShopsByIdResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + Shops *Shops `protobuf:"bytes,1,opt,name=shops,proto3" json:"shops,omitempty"` //shops + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *GetShopsByIdResp) Reset() { + *x = GetShopsByIdResp{} + mi := &file_shop_proto_msgTypes[30] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetShopsByIdResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetShopsByIdResp) ProtoMessage() {} + +func (x *GetShopsByIdResp) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[30] + 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 GetShopsByIdResp.ProtoReflect.Descriptor instead. +func (*GetShopsByIdResp) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{30} +} + +func (x *GetShopsByIdResp) GetShops() *Shops { + if x != nil { + return x.Shops + } + return nil +} + +type SearchShopsReq 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 + OwnerId int64 `protobuf:"varint,4,opt,name=ownerId,proto3" json:"ownerId,omitempty"` //ownerId + Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name,omitempty"` //name + Banner string `protobuf:"bytes,6,opt,name=banner,proto3" json:"banner,omitempty"` //banner + Description string `protobuf:"bytes,7,opt,name=description,proto3" json:"description,omitempty"` //description + Rating float64 `protobuf:"fixed64,8,opt,name=rating,proto3" json:"rating,omitempty"` //rating + TotalOrders int64 `protobuf:"varint,9,opt,name=totalOrders,proto3" json:"totalOrders,omitempty"` //totalOrders + PlayerCount int64 `protobuf:"varint,10,opt,name=playerCount,proto3" json:"playerCount,omitempty"` //playerCount + CommissionType string `protobuf:"bytes,11,opt,name=commissionType,proto3" json:"commissionType,omitempty"` //commissionType + CommissionValue float64 `protobuf:"fixed64,12,opt,name=commissionValue,proto3" json:"commissionValue,omitempty"` //commissionValue + AllowMultiShop bool `protobuf:"varint,13,opt,name=allowMultiShop,proto3" json:"allowMultiShop,omitempty"` //allowMultiShop + AllowIndependentOrders bool `protobuf:"varint,14,opt,name=allowIndependentOrders,proto3" json:"allowIndependentOrders,omitempty"` //allowIndependentOrders + DispatchMode string `protobuf:"bytes,15,opt,name=dispatchMode,proto3" json:"dispatchMode,omitempty"` //dispatchMode + Announcements []string `protobuf:"bytes,16,rep,name=announcements,proto3" json:"announcements,omitempty"` //announcements + TemplateConfig string `protobuf:"bytes,17,opt,name=templateConfig,proto3" json:"templateConfig,omitempty"` //templateConfig + CreatedAt int64 `protobuf:"varint,18,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt + UpdatedAt int64 `protobuf:"varint,19,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"` //updatedAt + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SearchShopsReq) Reset() { + *x = SearchShopsReq{} + mi := &file_shop_proto_msgTypes[31] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SearchShopsReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SearchShopsReq) ProtoMessage() {} + +func (x *SearchShopsReq) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[31] + 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 SearchShopsReq.ProtoReflect.Descriptor instead. +func (*SearchShopsReq) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{31} +} + +func (x *SearchShopsReq) GetPage() int64 { + if x != nil { + return x.Page + } + return 0 +} + +func (x *SearchShopsReq) GetLimit() int64 { + if x != nil { + return x.Limit + } + return 0 +} + +func (x *SearchShopsReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *SearchShopsReq) GetOwnerId() int64 { + if x != nil { + return x.OwnerId + } + return 0 +} + +func (x *SearchShopsReq) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *SearchShopsReq) GetBanner() string { + if x != nil { + return x.Banner + } + return "" +} + +func (x *SearchShopsReq) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +func (x *SearchShopsReq) GetRating() float64 { + if x != nil { + return x.Rating + } + return 0 +} + +func (x *SearchShopsReq) GetTotalOrders() int64 { + if x != nil { + return x.TotalOrders + } + return 0 +} + +func (x *SearchShopsReq) GetPlayerCount() int64 { + if x != nil { + return x.PlayerCount + } + return 0 +} + +func (x *SearchShopsReq) GetCommissionType() string { + if x != nil { + return x.CommissionType + } + return "" +} + +func (x *SearchShopsReq) GetCommissionValue() float64 { + if x != nil { + return x.CommissionValue + } + return 0 +} + +func (x *SearchShopsReq) GetAllowMultiShop() bool { + if x != nil { + return x.AllowMultiShop + } + return false +} + +func (x *SearchShopsReq) GetAllowIndependentOrders() bool { + if x != nil { + return x.AllowIndependentOrders + } + return false +} + +func (x *SearchShopsReq) GetDispatchMode() string { + if x != nil { + return x.DispatchMode + } + return "" +} + +func (x *SearchShopsReq) GetAnnouncements() []string { + if x != nil { + return x.Announcements + } + return nil +} + +func (x *SearchShopsReq) GetTemplateConfig() string { + if x != nil { + return x.TemplateConfig + } + return "" +} + +func (x *SearchShopsReq) GetCreatedAt() int64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *SearchShopsReq) GetUpdatedAt() int64 { + if x != nil { + return x.UpdatedAt + } + return 0 +} + +type SearchShopsResp struct { + state protoimpl.MessageState `protogen:"open.v1"` + Shops []*Shops `protobuf:"bytes,1,rep,name=shops,proto3" json:"shops,omitempty"` //shops + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SearchShopsResp) Reset() { + *x = SearchShopsResp{} + mi := &file_shop_proto_msgTypes[32] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SearchShopsResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SearchShopsResp) ProtoMessage() {} + +func (x *SearchShopsResp) ProtoReflect() protoreflect.Message { + mi := &file_shop_proto_msgTypes[32] + 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 SearchShopsResp.ProtoReflect.Descriptor instead. +func (*SearchShopsResp) Descriptor() ([]byte, []int) { + return file_shop_proto_rawDescGZIP(), []int{32} +} + +func (x *SearchShopsResp) GetShops() []*Shops { + if x != nil { + return x.Shops + } + return nil +} + +var File_shop_proto protoreflect.FileDescriptor + +const file_shop_proto_rawDesc = "" + + "\n" + + "\n" + + "shop.proto\x12\x02pb\"\xcb\x01\n" + + "\x0fShopInvitations\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x16\n" + + "\x06shopId\x18\x02 \x01(\x03R\x06shopId\x12\x1a\n" + + "\bplayerId\x18\x03 \x01(\x03R\bplayerId\x12\x16\n" + + "\x06status\x18\x04 \x01(\tR\x06status\x12\x1c\n" + + "\tinvitedBy\x18\x05 \x01(\x03R\tinvitedBy\x12\x1c\n" + + "\tcreatedAt\x18\x06 \x01(\x03R\tcreatedAt\x12 \n" + + "\vrespondedAt\x18\a \x01(\x03R\vrespondedAt\"\xc1\x01\n" + + "\x15AddShopInvitationsReq\x12\x16\n" + + "\x06shopId\x18\x01 \x01(\x03R\x06shopId\x12\x1a\n" + + "\bplayerId\x18\x02 \x01(\x03R\bplayerId\x12\x16\n" + + "\x06status\x18\x03 \x01(\tR\x06status\x12\x1c\n" + + "\tinvitedBy\x18\x04 \x01(\x03R\tinvitedBy\x12\x1c\n" + + "\tcreatedAt\x18\x05 \x01(\x03R\tcreatedAt\x12 \n" + + "\vrespondedAt\x18\x06 \x01(\x03R\vrespondedAt\"\x18\n" + + "\x16AddShopInvitationsResp\"\xd4\x01\n" + + "\x18UpdateShopInvitationsReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x16\n" + + "\x06shopId\x18\x02 \x01(\x03R\x06shopId\x12\x1a\n" + + "\bplayerId\x18\x03 \x01(\x03R\bplayerId\x12\x16\n" + + "\x06status\x18\x04 \x01(\tR\x06status\x12\x1c\n" + + "\tinvitedBy\x18\x05 \x01(\x03R\tinvitedBy\x12\x1c\n" + + "\tcreatedAt\x18\x06 \x01(\x03R\tcreatedAt\x12 \n" + + "\vrespondedAt\x18\a \x01(\x03R\vrespondedAt\"\x1b\n" + + "\x19UpdateShopInvitationsResp\"'\n" + + "\x15DelShopInvitationsReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\"\x18\n" + + "\x16DelShopInvitationsResp\"+\n" + + "\x19GetShopInvitationsByIdReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\"[\n" + + "\x1aGetShopInvitationsByIdResp\x12=\n" + + "\x0fshopInvitations\x18\x01 \x01(\v2\x13.pb.ShopInvitationsR\x0fshopInvitations\"\xfe\x01\n" + + "\x18SearchShopInvitationsReq\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\x16\n" + + "\x06shopId\x18\x04 \x01(\x03R\x06shopId\x12\x1a\n" + + "\bplayerId\x18\x05 \x01(\x03R\bplayerId\x12\x16\n" + + "\x06status\x18\x06 \x01(\tR\x06status\x12\x1c\n" + + "\tinvitedBy\x18\a \x01(\x03R\tinvitedBy\x12\x1c\n" + + "\tcreatedAt\x18\b \x01(\x03R\tcreatedAt\x12 \n" + + "\vrespondedAt\x18\t \x01(\x03R\vrespondedAt\"Z\n" + + "\x19SearchShopInvitationsResp\x12=\n" + + "\x0fshopInvitations\x18\x01 \x03(\v2\x13.pb.ShopInvitationsR\x0fshopInvitations\"\x93\x01\n" + + "\vShopPlayers\x12\x16\n" + + "\x06shopId\x18\x01 \x01(\x03R\x06shopId\x12\x1a\n" + + "\bplayerId\x18\x02 \x01(\x03R\bplayerId\x12\x1c\n" + + "\tisPrimary\x18\x03 \x01(\bR\tisPrimary\x12\x1a\n" + + "\bjoinedAt\x18\x04 \x01(\x03R\bjoinedAt\x12\x16\n" + + "\x06leftAt\x18\x05 \x01(\x03R\x06leftAt\"\x99\x01\n" + + "\x11AddShopPlayersReq\x12\x16\n" + + "\x06shopId\x18\x01 \x01(\x03R\x06shopId\x12\x1a\n" + + "\bplayerId\x18\x02 \x01(\x03R\bplayerId\x12\x1c\n" + + "\tisPrimary\x18\x03 \x01(\bR\tisPrimary\x12\x1a\n" + + "\bjoinedAt\x18\x04 \x01(\x03R\bjoinedAt\x12\x16\n" + + "\x06leftAt\x18\x05 \x01(\x03R\x06leftAt\"\x14\n" + + "\x12AddShopPlayersResp\"\x9c\x01\n" + + "\x14UpdateShopPlayersReq\x12\x16\n" + + "\x06shopId\x18\x01 \x01(\x03R\x06shopId\x12\x1a\n" + + "\bplayerId\x18\x02 \x01(\x03R\bplayerId\x12\x1c\n" + + "\tisPrimary\x18\x03 \x01(\bR\tisPrimary\x12\x1a\n" + + "\bjoinedAt\x18\x04 \x01(\x03R\bjoinedAt\x12\x16\n" + + "\x06leftAt\x18\x05 \x01(\x03R\x06leftAt\"\x17\n" + + "\x15UpdateShopPlayersResp\"#\n" + + "\x11DelShopPlayersReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\"\x14\n" + + "\x12DelShopPlayersResp\"'\n" + + "\x15GetShopPlayersByIdReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\"K\n" + + "\x16GetShopPlayersByIdResp\x121\n" + + "\vshopPlayers\x18\x01 \x01(\v2\x0f.pb.ShopPlayersR\vshopPlayers\"\xc6\x01\n" + + "\x14SearchShopPlayersReq\x12\x12\n" + + "\x04page\x18\x01 \x01(\x03R\x04page\x12\x14\n" + + "\x05limit\x18\x02 \x01(\x03R\x05limit\x12\x16\n" + + "\x06shopId\x18\x03 \x01(\x03R\x06shopId\x12\x1a\n" + + "\bplayerId\x18\x04 \x01(\x03R\bplayerId\x12\x1c\n" + + "\tisPrimary\x18\x05 \x01(\bR\tisPrimary\x12\x1a\n" + + "\bjoinedAt\x18\x06 \x01(\x03R\bjoinedAt\x12\x16\n" + + "\x06leftAt\x18\a \x01(\x03R\x06leftAt\"J\n" + + "\x15SearchShopPlayersResp\x121\n" + + "\vshopPlayers\x18\x01 \x03(\v2\x0f.pb.ShopPlayersR\vshopPlayers\"\xbb\x04\n" + + "\x05Shops\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x18\n" + + "\aownerId\x18\x02 \x01(\x03R\aownerId\x12\x12\n" + + "\x04name\x18\x03 \x01(\tR\x04name\x12\x16\n" + + "\x06banner\x18\x04 \x01(\tR\x06banner\x12 \n" + + "\vdescription\x18\x05 \x01(\tR\vdescription\x12\x16\n" + + "\x06rating\x18\x06 \x01(\x01R\x06rating\x12 \n" + + "\vtotalOrders\x18\a \x01(\x03R\vtotalOrders\x12 \n" + + "\vplayerCount\x18\b \x01(\x03R\vplayerCount\x12&\n" + + "\x0ecommissionType\x18\t \x01(\tR\x0ecommissionType\x12(\n" + + "\x0fcommissionValue\x18\n" + + " \x01(\x01R\x0fcommissionValue\x12&\n" + + "\x0eallowMultiShop\x18\v \x01(\bR\x0eallowMultiShop\x126\n" + + "\x16allowIndependentOrders\x18\f \x01(\bR\x16allowIndependentOrders\x12\"\n" + + "\fdispatchMode\x18\r \x01(\tR\fdispatchMode\x12$\n" + + "\rannouncements\x18\x0e \x03(\tR\rannouncements\x12&\n" + + "\x0etemplateConfig\x18\x0f \x01(\tR\x0etemplateConfig\x12\x1c\n" + + "\tcreatedAt\x18\x10 \x01(\x03R\tcreatedAt\x12\x1c\n" + + "\tupdatedAt\x18\x11 \x01(\x03R\tupdatedAt\"\xb1\x04\n" + + "\vAddShopsReq\x12\x18\n" + + "\aownerId\x18\x01 \x01(\x03R\aownerId\x12\x12\n" + + "\x04name\x18\x02 \x01(\tR\x04name\x12\x16\n" + + "\x06banner\x18\x03 \x01(\tR\x06banner\x12 \n" + + "\vdescription\x18\x04 \x01(\tR\vdescription\x12\x16\n" + + "\x06rating\x18\x05 \x01(\x01R\x06rating\x12 \n" + + "\vtotalOrders\x18\x06 \x01(\x03R\vtotalOrders\x12 \n" + + "\vplayerCount\x18\a \x01(\x03R\vplayerCount\x12&\n" + + "\x0ecommissionType\x18\b \x01(\tR\x0ecommissionType\x12(\n" + + "\x0fcommissionValue\x18\t \x01(\x01R\x0fcommissionValue\x12&\n" + + "\x0eallowMultiShop\x18\n" + + " \x01(\bR\x0eallowMultiShop\x126\n" + + "\x16allowIndependentOrders\x18\v \x01(\bR\x16allowIndependentOrders\x12\"\n" + + "\fdispatchMode\x18\f \x01(\tR\fdispatchMode\x12$\n" + + "\rannouncements\x18\r \x03(\tR\rannouncements\x12&\n" + + "\x0etemplateConfig\x18\x0e \x01(\tR\x0etemplateConfig\x12\x1c\n" + + "\tcreatedAt\x18\x0f \x01(\x03R\tcreatedAt\x12\x1c\n" + + "\tupdatedAt\x18\x10 \x01(\x03R\tupdatedAt\"\x0e\n" + + "\fAddShopsResp\"\xc4\x04\n" + + "\x0eUpdateShopsReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x18\n" + + "\aownerId\x18\x02 \x01(\x03R\aownerId\x12\x12\n" + + "\x04name\x18\x03 \x01(\tR\x04name\x12\x16\n" + + "\x06banner\x18\x04 \x01(\tR\x06banner\x12 \n" + + "\vdescription\x18\x05 \x01(\tR\vdescription\x12\x16\n" + + "\x06rating\x18\x06 \x01(\x01R\x06rating\x12 \n" + + "\vtotalOrders\x18\a \x01(\x03R\vtotalOrders\x12 \n" + + "\vplayerCount\x18\b \x01(\x03R\vplayerCount\x12&\n" + + "\x0ecommissionType\x18\t \x01(\tR\x0ecommissionType\x12(\n" + + "\x0fcommissionValue\x18\n" + + " \x01(\x01R\x0fcommissionValue\x12&\n" + + "\x0eallowMultiShop\x18\v \x01(\bR\x0eallowMultiShop\x126\n" + + "\x16allowIndependentOrders\x18\f \x01(\bR\x16allowIndependentOrders\x12\"\n" + + "\fdispatchMode\x18\r \x01(\tR\fdispatchMode\x12$\n" + + "\rannouncements\x18\x0e \x03(\tR\rannouncements\x12&\n" + + "\x0etemplateConfig\x18\x0f \x01(\tR\x0etemplateConfig\x12\x1c\n" + + "\tcreatedAt\x18\x10 \x01(\x03R\tcreatedAt\x12\x1c\n" + + "\tupdatedAt\x18\x11 \x01(\x03R\tupdatedAt\"\x11\n" + + "\x0fUpdateShopsResp\"\x1d\n" + + "\vDelShopsReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\"\x0e\n" + + "\fDelShopsResp\"!\n" + + "\x0fGetShopsByIdReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\"3\n" + + "\x10GetShopsByIdResp\x12\x1f\n" + + "\x05shops\x18\x01 \x01(\v2\t.pb.ShopsR\x05shops\"\xee\x04\n" + + "\x0eSearchShopsReq\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\x18\n" + + "\aownerId\x18\x04 \x01(\x03R\aownerId\x12\x12\n" + + "\x04name\x18\x05 \x01(\tR\x04name\x12\x16\n" + + "\x06banner\x18\x06 \x01(\tR\x06banner\x12 \n" + + "\vdescription\x18\a \x01(\tR\vdescription\x12\x16\n" + + "\x06rating\x18\b \x01(\x01R\x06rating\x12 \n" + + "\vtotalOrders\x18\t \x01(\x03R\vtotalOrders\x12 \n" + + "\vplayerCount\x18\n" + + " \x01(\x03R\vplayerCount\x12&\n" + + "\x0ecommissionType\x18\v \x01(\tR\x0ecommissionType\x12(\n" + + "\x0fcommissionValue\x18\f \x01(\x01R\x0fcommissionValue\x12&\n" + + "\x0eallowMultiShop\x18\r \x01(\bR\x0eallowMultiShop\x126\n" + + "\x16allowIndependentOrders\x18\x0e \x01(\bR\x16allowIndependentOrders\x12\"\n" + + "\fdispatchMode\x18\x0f \x01(\tR\fdispatchMode\x12$\n" + + "\rannouncements\x18\x10 \x03(\tR\rannouncements\x12&\n" + + "\x0etemplateConfig\x18\x11 \x01(\tR\x0etemplateConfig\x12\x1c\n" + + "\tcreatedAt\x18\x12 \x01(\x03R\tcreatedAt\x12\x1c\n" + + "\tupdatedAt\x18\x13 \x01(\x03R\tupdatedAt\"2\n" + + "\x0fSearchShopsResp\x12\x1f\n" + + "\x05shops\x18\x01 \x03(\v2\t.pb.ShopsR\x05shops2\x98\b\n" + + "\vshopService\x12K\n" + + "\x12AddShopInvitations\x12\x19.pb.AddShopInvitationsReq\x1a\x1a.pb.AddShopInvitationsResp\x12T\n" + + "\x15UpdateShopInvitations\x12\x1c.pb.UpdateShopInvitationsReq\x1a\x1d.pb.UpdateShopInvitationsResp\x12K\n" + + "\x12DelShopInvitations\x12\x19.pb.DelShopInvitationsReq\x1a\x1a.pb.DelShopInvitationsResp\x12W\n" + + "\x16GetShopInvitationsById\x12\x1d.pb.GetShopInvitationsByIdReq\x1a\x1e.pb.GetShopInvitationsByIdResp\x12T\n" + + "\x15SearchShopInvitations\x12\x1c.pb.SearchShopInvitationsReq\x1a\x1d.pb.SearchShopInvitationsResp\x12?\n" + + "\x0eAddShopPlayers\x12\x15.pb.AddShopPlayersReq\x1a\x16.pb.AddShopPlayersResp\x12H\n" + + "\x11UpdateShopPlayers\x12\x18.pb.UpdateShopPlayersReq\x1a\x19.pb.UpdateShopPlayersResp\x12?\n" + + "\x0eDelShopPlayers\x12\x15.pb.DelShopPlayersReq\x1a\x16.pb.DelShopPlayersResp\x12K\n" + + "\x12GetShopPlayersById\x12\x19.pb.GetShopPlayersByIdReq\x1a\x1a.pb.GetShopPlayersByIdResp\x12H\n" + + "\x11SearchShopPlayers\x12\x18.pb.SearchShopPlayersReq\x1a\x19.pb.SearchShopPlayersResp\x12-\n" + + "\bAddShops\x12\x0f.pb.AddShopsReq\x1a\x10.pb.AddShopsResp\x126\n" + + "\vUpdateShops\x12\x12.pb.UpdateShopsReq\x1a\x13.pb.UpdateShopsResp\x12-\n" + + "\bDelShops\x12\x0f.pb.DelShopsReq\x1a\x10.pb.DelShopsResp\x129\n" + + "\fGetShopsById\x12\x13.pb.GetShopsByIdReq\x1a\x14.pb.GetShopsByIdResp\x126\n" + + "\vSearchShops\x12\x12.pb.SearchShopsReq\x1a\x13.pb.SearchShopsRespB\x06Z\x04./pbb\x06proto3" + +var ( + file_shop_proto_rawDescOnce sync.Once + file_shop_proto_rawDescData []byte +) + +func file_shop_proto_rawDescGZIP() []byte { + file_shop_proto_rawDescOnce.Do(func() { + file_shop_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_shop_proto_rawDesc), len(file_shop_proto_rawDesc))) + }) + return file_shop_proto_rawDescData +} + +var file_shop_proto_msgTypes = make([]protoimpl.MessageInfo, 33) +var file_shop_proto_goTypes = []any{ + (*ShopInvitations)(nil), // 0: pb.ShopInvitations + (*AddShopInvitationsReq)(nil), // 1: pb.AddShopInvitationsReq + (*AddShopInvitationsResp)(nil), // 2: pb.AddShopInvitationsResp + (*UpdateShopInvitationsReq)(nil), // 3: pb.UpdateShopInvitationsReq + (*UpdateShopInvitationsResp)(nil), // 4: pb.UpdateShopInvitationsResp + (*DelShopInvitationsReq)(nil), // 5: pb.DelShopInvitationsReq + (*DelShopInvitationsResp)(nil), // 6: pb.DelShopInvitationsResp + (*GetShopInvitationsByIdReq)(nil), // 7: pb.GetShopInvitationsByIdReq + (*GetShopInvitationsByIdResp)(nil), // 8: pb.GetShopInvitationsByIdResp + (*SearchShopInvitationsReq)(nil), // 9: pb.SearchShopInvitationsReq + (*SearchShopInvitationsResp)(nil), // 10: pb.SearchShopInvitationsResp + (*ShopPlayers)(nil), // 11: pb.ShopPlayers + (*AddShopPlayersReq)(nil), // 12: pb.AddShopPlayersReq + (*AddShopPlayersResp)(nil), // 13: pb.AddShopPlayersResp + (*UpdateShopPlayersReq)(nil), // 14: pb.UpdateShopPlayersReq + (*UpdateShopPlayersResp)(nil), // 15: pb.UpdateShopPlayersResp + (*DelShopPlayersReq)(nil), // 16: pb.DelShopPlayersReq + (*DelShopPlayersResp)(nil), // 17: pb.DelShopPlayersResp + (*GetShopPlayersByIdReq)(nil), // 18: pb.GetShopPlayersByIdReq + (*GetShopPlayersByIdResp)(nil), // 19: pb.GetShopPlayersByIdResp + (*SearchShopPlayersReq)(nil), // 20: pb.SearchShopPlayersReq + (*SearchShopPlayersResp)(nil), // 21: pb.SearchShopPlayersResp + (*Shops)(nil), // 22: pb.Shops + (*AddShopsReq)(nil), // 23: pb.AddShopsReq + (*AddShopsResp)(nil), // 24: pb.AddShopsResp + (*UpdateShopsReq)(nil), // 25: pb.UpdateShopsReq + (*UpdateShopsResp)(nil), // 26: pb.UpdateShopsResp + (*DelShopsReq)(nil), // 27: pb.DelShopsReq + (*DelShopsResp)(nil), // 28: pb.DelShopsResp + (*GetShopsByIdReq)(nil), // 29: pb.GetShopsByIdReq + (*GetShopsByIdResp)(nil), // 30: pb.GetShopsByIdResp + (*SearchShopsReq)(nil), // 31: pb.SearchShopsReq + (*SearchShopsResp)(nil), // 32: pb.SearchShopsResp +} +var file_shop_proto_depIdxs = []int32{ + 0, // 0: pb.GetShopInvitationsByIdResp.shopInvitations:type_name -> pb.ShopInvitations + 0, // 1: pb.SearchShopInvitationsResp.shopInvitations:type_name -> pb.ShopInvitations + 11, // 2: pb.GetShopPlayersByIdResp.shopPlayers:type_name -> pb.ShopPlayers + 11, // 3: pb.SearchShopPlayersResp.shopPlayers:type_name -> pb.ShopPlayers + 22, // 4: pb.GetShopsByIdResp.shops:type_name -> pb.Shops + 22, // 5: pb.SearchShopsResp.shops:type_name -> pb.Shops + 1, // 6: pb.shopService.AddShopInvitations:input_type -> pb.AddShopInvitationsReq + 3, // 7: pb.shopService.UpdateShopInvitations:input_type -> pb.UpdateShopInvitationsReq + 5, // 8: pb.shopService.DelShopInvitations:input_type -> pb.DelShopInvitationsReq + 7, // 9: pb.shopService.GetShopInvitationsById:input_type -> pb.GetShopInvitationsByIdReq + 9, // 10: pb.shopService.SearchShopInvitations:input_type -> pb.SearchShopInvitationsReq + 12, // 11: pb.shopService.AddShopPlayers:input_type -> pb.AddShopPlayersReq + 14, // 12: pb.shopService.UpdateShopPlayers:input_type -> pb.UpdateShopPlayersReq + 16, // 13: pb.shopService.DelShopPlayers:input_type -> pb.DelShopPlayersReq + 18, // 14: pb.shopService.GetShopPlayersById:input_type -> pb.GetShopPlayersByIdReq + 20, // 15: pb.shopService.SearchShopPlayers:input_type -> pb.SearchShopPlayersReq + 23, // 16: pb.shopService.AddShops:input_type -> pb.AddShopsReq + 25, // 17: pb.shopService.UpdateShops:input_type -> pb.UpdateShopsReq + 27, // 18: pb.shopService.DelShops:input_type -> pb.DelShopsReq + 29, // 19: pb.shopService.GetShopsById:input_type -> pb.GetShopsByIdReq + 31, // 20: pb.shopService.SearchShops:input_type -> pb.SearchShopsReq + 2, // 21: pb.shopService.AddShopInvitations:output_type -> pb.AddShopInvitationsResp + 4, // 22: pb.shopService.UpdateShopInvitations:output_type -> pb.UpdateShopInvitationsResp + 6, // 23: pb.shopService.DelShopInvitations:output_type -> pb.DelShopInvitationsResp + 8, // 24: pb.shopService.GetShopInvitationsById:output_type -> pb.GetShopInvitationsByIdResp + 10, // 25: pb.shopService.SearchShopInvitations:output_type -> pb.SearchShopInvitationsResp + 13, // 26: pb.shopService.AddShopPlayers:output_type -> pb.AddShopPlayersResp + 15, // 27: pb.shopService.UpdateShopPlayers:output_type -> pb.UpdateShopPlayersResp + 17, // 28: pb.shopService.DelShopPlayers:output_type -> pb.DelShopPlayersResp + 19, // 29: pb.shopService.GetShopPlayersById:output_type -> pb.GetShopPlayersByIdResp + 21, // 30: pb.shopService.SearchShopPlayers:output_type -> pb.SearchShopPlayersResp + 24, // 31: pb.shopService.AddShops:output_type -> pb.AddShopsResp + 26, // 32: pb.shopService.UpdateShops:output_type -> pb.UpdateShopsResp + 28, // 33: pb.shopService.DelShops:output_type -> pb.DelShopsResp + 30, // 34: pb.shopService.GetShopsById:output_type -> pb.GetShopsByIdResp + 32, // 35: pb.shopService.SearchShops:output_type -> pb.SearchShopsResp + 21, // [21:36] is the sub-list for method output_type + 6, // [6:21] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name +} + +func init() { file_shop_proto_init() } +func file_shop_proto_init() { + if File_shop_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_shop_proto_rawDesc), len(file_shop_proto_rawDesc)), + NumEnums: 0, + NumMessages: 33, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_shop_proto_goTypes, + DependencyIndexes: file_shop_proto_depIdxs, + MessageInfos: file_shop_proto_msgTypes, + }.Build() + File_shop_proto = out.File + file_shop_proto_goTypes = nil + file_shop_proto_depIdxs = nil +} diff --git a/app/shop/rpc/pb/shop_grpc.pb.go b/app/shop/rpc/pb/shop_grpc.pb.go new file mode 100644 index 0000000..acb049d --- /dev/null +++ b/app/shop/rpc/pb/shop_grpc.pb.go @@ -0,0 +1,659 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.6.1 +// - protoc v5.29.6 +// source: shop.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 ( + ShopService_AddShopInvitations_FullMethodName = "/pb.shopService/AddShopInvitations" + ShopService_UpdateShopInvitations_FullMethodName = "/pb.shopService/UpdateShopInvitations" + ShopService_DelShopInvitations_FullMethodName = "/pb.shopService/DelShopInvitations" + ShopService_GetShopInvitationsById_FullMethodName = "/pb.shopService/GetShopInvitationsById" + ShopService_SearchShopInvitations_FullMethodName = "/pb.shopService/SearchShopInvitations" + ShopService_AddShopPlayers_FullMethodName = "/pb.shopService/AddShopPlayers" + ShopService_UpdateShopPlayers_FullMethodName = "/pb.shopService/UpdateShopPlayers" + ShopService_DelShopPlayers_FullMethodName = "/pb.shopService/DelShopPlayers" + ShopService_GetShopPlayersById_FullMethodName = "/pb.shopService/GetShopPlayersById" + ShopService_SearchShopPlayers_FullMethodName = "/pb.shopService/SearchShopPlayers" + ShopService_AddShops_FullMethodName = "/pb.shopService/AddShops" + ShopService_UpdateShops_FullMethodName = "/pb.shopService/UpdateShops" + ShopService_DelShops_FullMethodName = "/pb.shopService/DelShops" + ShopService_GetShopsById_FullMethodName = "/pb.shopService/GetShopsById" + ShopService_SearchShops_FullMethodName = "/pb.shopService/SearchShops" +) + +// ShopServiceClient is the client API for ShopService 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 ShopServiceClient interface { + // -----------------------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) +} + +type shopServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewShopServiceClient(cc grpc.ClientConnInterface) ShopServiceClient { + return &shopServiceClient{cc} +} + +func (c *shopServiceClient) AddShopInvitations(ctx context.Context, in *AddShopInvitationsReq, opts ...grpc.CallOption) (*AddShopInvitationsResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AddShopInvitationsResp) + err := c.cc.Invoke(ctx, ShopService_AddShopInvitations_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shopServiceClient) UpdateShopInvitations(ctx context.Context, in *UpdateShopInvitationsReq, opts ...grpc.CallOption) (*UpdateShopInvitationsResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(UpdateShopInvitationsResp) + err := c.cc.Invoke(ctx, ShopService_UpdateShopInvitations_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shopServiceClient) DelShopInvitations(ctx context.Context, in *DelShopInvitationsReq, opts ...grpc.CallOption) (*DelShopInvitationsResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(DelShopInvitationsResp) + err := c.cc.Invoke(ctx, ShopService_DelShopInvitations_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shopServiceClient) GetShopInvitationsById(ctx context.Context, in *GetShopInvitationsByIdReq, opts ...grpc.CallOption) (*GetShopInvitationsByIdResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetShopInvitationsByIdResp) + err := c.cc.Invoke(ctx, ShopService_GetShopInvitationsById_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shopServiceClient) SearchShopInvitations(ctx context.Context, in *SearchShopInvitationsReq, opts ...grpc.CallOption) (*SearchShopInvitationsResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SearchShopInvitationsResp) + err := c.cc.Invoke(ctx, ShopService_SearchShopInvitations_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shopServiceClient) AddShopPlayers(ctx context.Context, in *AddShopPlayersReq, opts ...grpc.CallOption) (*AddShopPlayersResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AddShopPlayersResp) + err := c.cc.Invoke(ctx, ShopService_AddShopPlayers_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shopServiceClient) UpdateShopPlayers(ctx context.Context, in *UpdateShopPlayersReq, opts ...grpc.CallOption) (*UpdateShopPlayersResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(UpdateShopPlayersResp) + err := c.cc.Invoke(ctx, ShopService_UpdateShopPlayers_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shopServiceClient) DelShopPlayers(ctx context.Context, in *DelShopPlayersReq, opts ...grpc.CallOption) (*DelShopPlayersResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(DelShopPlayersResp) + err := c.cc.Invoke(ctx, ShopService_DelShopPlayers_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shopServiceClient) GetShopPlayersById(ctx context.Context, in *GetShopPlayersByIdReq, opts ...grpc.CallOption) (*GetShopPlayersByIdResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetShopPlayersByIdResp) + err := c.cc.Invoke(ctx, ShopService_GetShopPlayersById_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shopServiceClient) SearchShopPlayers(ctx context.Context, in *SearchShopPlayersReq, opts ...grpc.CallOption) (*SearchShopPlayersResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SearchShopPlayersResp) + err := c.cc.Invoke(ctx, ShopService_SearchShopPlayers_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shopServiceClient) AddShops(ctx context.Context, in *AddShopsReq, opts ...grpc.CallOption) (*AddShopsResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AddShopsResp) + err := c.cc.Invoke(ctx, ShopService_AddShops_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shopServiceClient) UpdateShops(ctx context.Context, in *UpdateShopsReq, opts ...grpc.CallOption) (*UpdateShopsResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(UpdateShopsResp) + err := c.cc.Invoke(ctx, ShopService_UpdateShops_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shopServiceClient) DelShops(ctx context.Context, in *DelShopsReq, opts ...grpc.CallOption) (*DelShopsResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(DelShopsResp) + err := c.cc.Invoke(ctx, ShopService_DelShops_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shopServiceClient) GetShopsById(ctx context.Context, in *GetShopsByIdReq, opts ...grpc.CallOption) (*GetShopsByIdResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetShopsByIdResp) + err := c.cc.Invoke(ctx, ShopService_GetShopsById_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shopServiceClient) SearchShops(ctx context.Context, in *SearchShopsReq, opts ...grpc.CallOption) (*SearchShopsResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SearchShopsResp) + err := c.cc.Invoke(ctx, ShopService_SearchShops_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ShopServiceServer is the server API for ShopService service. +// All implementations must embed UnimplementedShopServiceServer +// for forward compatibility. +type ShopServiceServer interface { + // -----------------------shopInvitations----------------------- + AddShopInvitations(context.Context, *AddShopInvitationsReq) (*AddShopInvitationsResp, error) + UpdateShopInvitations(context.Context, *UpdateShopInvitationsReq) (*UpdateShopInvitationsResp, error) + DelShopInvitations(context.Context, *DelShopInvitationsReq) (*DelShopInvitationsResp, error) + GetShopInvitationsById(context.Context, *GetShopInvitationsByIdReq) (*GetShopInvitationsByIdResp, error) + SearchShopInvitations(context.Context, *SearchShopInvitationsReq) (*SearchShopInvitationsResp, error) + // -----------------------shopPlayers----------------------- + AddShopPlayers(context.Context, *AddShopPlayersReq) (*AddShopPlayersResp, error) + UpdateShopPlayers(context.Context, *UpdateShopPlayersReq) (*UpdateShopPlayersResp, error) + DelShopPlayers(context.Context, *DelShopPlayersReq) (*DelShopPlayersResp, error) + GetShopPlayersById(context.Context, *GetShopPlayersByIdReq) (*GetShopPlayersByIdResp, error) + SearchShopPlayers(context.Context, *SearchShopPlayersReq) (*SearchShopPlayersResp, error) + // -----------------------shops----------------------- + AddShops(context.Context, *AddShopsReq) (*AddShopsResp, error) + UpdateShops(context.Context, *UpdateShopsReq) (*UpdateShopsResp, error) + DelShops(context.Context, *DelShopsReq) (*DelShopsResp, error) + GetShopsById(context.Context, *GetShopsByIdReq) (*GetShopsByIdResp, error) + SearchShops(context.Context, *SearchShopsReq) (*SearchShopsResp, error) + mustEmbedUnimplementedShopServiceServer() +} + +// UnimplementedShopServiceServer 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 UnimplementedShopServiceServer struct{} + +func (UnimplementedShopServiceServer) AddShopInvitations(context.Context, *AddShopInvitationsReq) (*AddShopInvitationsResp, error) { + return nil, status.Error(codes.Unimplemented, "method AddShopInvitations not implemented") +} +func (UnimplementedShopServiceServer) UpdateShopInvitations(context.Context, *UpdateShopInvitationsReq) (*UpdateShopInvitationsResp, error) { + return nil, status.Error(codes.Unimplemented, "method UpdateShopInvitations not implemented") +} +func (UnimplementedShopServiceServer) DelShopInvitations(context.Context, *DelShopInvitationsReq) (*DelShopInvitationsResp, error) { + return nil, status.Error(codes.Unimplemented, "method DelShopInvitations not implemented") +} +func (UnimplementedShopServiceServer) GetShopInvitationsById(context.Context, *GetShopInvitationsByIdReq) (*GetShopInvitationsByIdResp, error) { + return nil, status.Error(codes.Unimplemented, "method GetShopInvitationsById not implemented") +} +func (UnimplementedShopServiceServer) SearchShopInvitations(context.Context, *SearchShopInvitationsReq) (*SearchShopInvitationsResp, error) { + return nil, status.Error(codes.Unimplemented, "method SearchShopInvitations not implemented") +} +func (UnimplementedShopServiceServer) AddShopPlayers(context.Context, *AddShopPlayersReq) (*AddShopPlayersResp, error) { + return nil, status.Error(codes.Unimplemented, "method AddShopPlayers not implemented") +} +func (UnimplementedShopServiceServer) UpdateShopPlayers(context.Context, *UpdateShopPlayersReq) (*UpdateShopPlayersResp, error) { + return nil, status.Error(codes.Unimplemented, "method UpdateShopPlayers not implemented") +} +func (UnimplementedShopServiceServer) DelShopPlayers(context.Context, *DelShopPlayersReq) (*DelShopPlayersResp, error) { + return nil, status.Error(codes.Unimplemented, "method DelShopPlayers not implemented") +} +func (UnimplementedShopServiceServer) GetShopPlayersById(context.Context, *GetShopPlayersByIdReq) (*GetShopPlayersByIdResp, error) { + return nil, status.Error(codes.Unimplemented, "method GetShopPlayersById not implemented") +} +func (UnimplementedShopServiceServer) SearchShopPlayers(context.Context, *SearchShopPlayersReq) (*SearchShopPlayersResp, error) { + return nil, status.Error(codes.Unimplemented, "method SearchShopPlayers not implemented") +} +func (UnimplementedShopServiceServer) AddShops(context.Context, *AddShopsReq) (*AddShopsResp, error) { + return nil, status.Error(codes.Unimplemented, "method AddShops not implemented") +} +func (UnimplementedShopServiceServer) UpdateShops(context.Context, *UpdateShopsReq) (*UpdateShopsResp, error) { + return nil, status.Error(codes.Unimplemented, "method UpdateShops not implemented") +} +func (UnimplementedShopServiceServer) DelShops(context.Context, *DelShopsReq) (*DelShopsResp, error) { + return nil, status.Error(codes.Unimplemented, "method DelShops not implemented") +} +func (UnimplementedShopServiceServer) GetShopsById(context.Context, *GetShopsByIdReq) (*GetShopsByIdResp, error) { + return nil, status.Error(codes.Unimplemented, "method GetShopsById not implemented") +} +func (UnimplementedShopServiceServer) SearchShops(context.Context, *SearchShopsReq) (*SearchShopsResp, error) { + return nil, status.Error(codes.Unimplemented, "method SearchShops not implemented") +} +func (UnimplementedShopServiceServer) mustEmbedUnimplementedShopServiceServer() {} +func (UnimplementedShopServiceServer) testEmbeddedByValue() {} + +// UnsafeShopServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ShopServiceServer will +// result in compilation errors. +type UnsafeShopServiceServer interface { + mustEmbedUnimplementedShopServiceServer() +} + +func RegisterShopServiceServer(s grpc.ServiceRegistrar, srv ShopServiceServer) { + // If the following call panics, it indicates UnimplementedShopServiceServer 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(&ShopService_ServiceDesc, srv) +} + +func _ShopService_AddShopInvitations_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AddShopInvitationsReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShopServiceServer).AddShopInvitations(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShopService_AddShopInvitations_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShopServiceServer).AddShopInvitations(ctx, req.(*AddShopInvitationsReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShopService_UpdateShopInvitations_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateShopInvitationsReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShopServiceServer).UpdateShopInvitations(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShopService_UpdateShopInvitations_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShopServiceServer).UpdateShopInvitations(ctx, req.(*UpdateShopInvitationsReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShopService_DelShopInvitations_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DelShopInvitationsReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShopServiceServer).DelShopInvitations(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShopService_DelShopInvitations_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShopServiceServer).DelShopInvitations(ctx, req.(*DelShopInvitationsReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShopService_GetShopInvitationsById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetShopInvitationsByIdReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShopServiceServer).GetShopInvitationsById(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShopService_GetShopInvitationsById_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShopServiceServer).GetShopInvitationsById(ctx, req.(*GetShopInvitationsByIdReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShopService_SearchShopInvitations_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SearchShopInvitationsReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShopServiceServer).SearchShopInvitations(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShopService_SearchShopInvitations_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShopServiceServer).SearchShopInvitations(ctx, req.(*SearchShopInvitationsReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShopService_AddShopPlayers_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AddShopPlayersReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShopServiceServer).AddShopPlayers(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShopService_AddShopPlayers_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShopServiceServer).AddShopPlayers(ctx, req.(*AddShopPlayersReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShopService_UpdateShopPlayers_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateShopPlayersReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShopServiceServer).UpdateShopPlayers(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShopService_UpdateShopPlayers_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShopServiceServer).UpdateShopPlayers(ctx, req.(*UpdateShopPlayersReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShopService_DelShopPlayers_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DelShopPlayersReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShopServiceServer).DelShopPlayers(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShopService_DelShopPlayers_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShopServiceServer).DelShopPlayers(ctx, req.(*DelShopPlayersReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShopService_GetShopPlayersById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetShopPlayersByIdReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShopServiceServer).GetShopPlayersById(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShopService_GetShopPlayersById_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShopServiceServer).GetShopPlayersById(ctx, req.(*GetShopPlayersByIdReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShopService_SearchShopPlayers_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SearchShopPlayersReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShopServiceServer).SearchShopPlayers(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShopService_SearchShopPlayers_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShopServiceServer).SearchShopPlayers(ctx, req.(*SearchShopPlayersReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShopService_AddShops_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AddShopsReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShopServiceServer).AddShops(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShopService_AddShops_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShopServiceServer).AddShops(ctx, req.(*AddShopsReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShopService_UpdateShops_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateShopsReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShopServiceServer).UpdateShops(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShopService_UpdateShops_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShopServiceServer).UpdateShops(ctx, req.(*UpdateShopsReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShopService_DelShops_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DelShopsReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShopServiceServer).DelShops(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShopService_DelShops_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShopServiceServer).DelShops(ctx, req.(*DelShopsReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShopService_GetShopsById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetShopsByIdReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShopServiceServer).GetShopsById(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShopService_GetShopsById_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShopServiceServer).GetShopsById(ctx, req.(*GetShopsByIdReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShopService_SearchShops_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SearchShopsReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShopServiceServer).SearchShops(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShopService_SearchShops_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShopServiceServer).SearchShops(ctx, req.(*SearchShopsReq)) + } + return interceptor(ctx, in, info, handler) +} + +// ShopService_ServiceDesc is the grpc.ServiceDesc for ShopService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ShopService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "pb.shopService", + HandlerType: (*ShopServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "AddShopInvitations", + Handler: _ShopService_AddShopInvitations_Handler, + }, + { + MethodName: "UpdateShopInvitations", + Handler: _ShopService_UpdateShopInvitations_Handler, + }, + { + MethodName: "DelShopInvitations", + Handler: _ShopService_DelShopInvitations_Handler, + }, + { + MethodName: "GetShopInvitationsById", + Handler: _ShopService_GetShopInvitationsById_Handler, + }, + { + MethodName: "SearchShopInvitations", + Handler: _ShopService_SearchShopInvitations_Handler, + }, + { + MethodName: "AddShopPlayers", + Handler: _ShopService_AddShopPlayers_Handler, + }, + { + MethodName: "UpdateShopPlayers", + Handler: _ShopService_UpdateShopPlayers_Handler, + }, + { + MethodName: "DelShopPlayers", + Handler: _ShopService_DelShopPlayers_Handler, + }, + { + MethodName: "GetShopPlayersById", + Handler: _ShopService_GetShopPlayersById_Handler, + }, + { + MethodName: "SearchShopPlayers", + Handler: _ShopService_SearchShopPlayers_Handler, + }, + { + MethodName: "AddShops", + Handler: _ShopService_AddShops_Handler, + }, + { + MethodName: "UpdateShops", + Handler: _ShopService_UpdateShops_Handler, + }, + { + MethodName: "DelShops", + Handler: _ShopService_DelShops_Handler, + }, + { + MethodName: "GetShopsById", + Handler: _ShopService_GetShopsById_Handler, + }, + { + MethodName: "SearchShops", + Handler: _ShopService_SearchShops_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "shop.proto", +} diff --git a/app/shop/rpc/shopservice/shopService.go b/app/shop/rpc/shopservice/shopService.go new file mode 100644 index 0000000..440439f --- /dev/null +++ b/app/shop/rpc/shopservice/shopService.go @@ -0,0 +1,159 @@ +// Code generated by goctl. DO NOT EDIT. +// goctl 1.9.2 +// Source: shop.proto + +package shopservice + +import ( + "context" + + "juwan-backend/app/shop/rpc/pb" + + "github.com/zeromicro/go-zero/zrpc" + "google.golang.org/grpc" +) + +type ( + AddShopInvitationsReq = pb.AddShopInvitationsReq + AddShopInvitationsResp = pb.AddShopInvitationsResp + AddShopPlayersReq = pb.AddShopPlayersReq + AddShopPlayersResp = pb.AddShopPlayersResp + AddShopsReq = pb.AddShopsReq + AddShopsResp = pb.AddShopsResp + DelShopInvitationsReq = pb.DelShopInvitationsReq + DelShopInvitationsResp = pb.DelShopInvitationsResp + DelShopPlayersReq = pb.DelShopPlayersReq + DelShopPlayersResp = pb.DelShopPlayersResp + DelShopsReq = pb.DelShopsReq + DelShopsResp = pb.DelShopsResp + GetShopInvitationsByIdReq = pb.GetShopInvitationsByIdReq + GetShopInvitationsByIdResp = pb.GetShopInvitationsByIdResp + GetShopPlayersByIdReq = pb.GetShopPlayersByIdReq + GetShopPlayersByIdResp = pb.GetShopPlayersByIdResp + GetShopsByIdReq = pb.GetShopsByIdReq + GetShopsByIdResp = pb.GetShopsByIdResp + 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 + UpdateShopInvitationsReq = pb.UpdateShopInvitationsReq + UpdateShopInvitationsResp = pb.UpdateShopInvitationsResp + UpdateShopPlayersReq = pb.UpdateShopPlayersReq + UpdateShopPlayersResp = pb.UpdateShopPlayersResp + UpdateShopsReq = pb.UpdateShopsReq + UpdateShopsResp = pb.UpdateShopsResp + + ShopService interface { + // -----------------------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) + } + + defaultShopService struct { + cli zrpc.Client + } +) + +func NewShopService(cli zrpc.Client) ShopService { + return &defaultShopService{ + cli: cli, + } +} + +// -----------------------shopInvitations----------------------- +func (m *defaultShopService) AddShopInvitations(ctx context.Context, in *AddShopInvitationsReq, opts ...grpc.CallOption) (*AddShopInvitationsResp, error) { + client := pb.NewShopServiceClient(m.cli.Conn()) + return client.AddShopInvitations(ctx, in, opts...) +} + +func (m *defaultShopService) UpdateShopInvitations(ctx context.Context, in *UpdateShopInvitationsReq, opts ...grpc.CallOption) (*UpdateShopInvitationsResp, error) { + client := pb.NewShopServiceClient(m.cli.Conn()) + return client.UpdateShopInvitations(ctx, in, opts...) +} + +func (m *defaultShopService) DelShopInvitations(ctx context.Context, in *DelShopInvitationsReq, opts ...grpc.CallOption) (*DelShopInvitationsResp, error) { + client := pb.NewShopServiceClient(m.cli.Conn()) + return client.DelShopInvitations(ctx, in, opts...) +} + +func (m *defaultShopService) GetShopInvitationsById(ctx context.Context, in *GetShopInvitationsByIdReq, opts ...grpc.CallOption) (*GetShopInvitationsByIdResp, error) { + client := pb.NewShopServiceClient(m.cli.Conn()) + return client.GetShopInvitationsById(ctx, in, opts...) +} + +func (m *defaultShopService) SearchShopInvitations(ctx context.Context, in *SearchShopInvitationsReq, opts ...grpc.CallOption) (*SearchShopInvitationsResp, error) { + client := pb.NewShopServiceClient(m.cli.Conn()) + return client.SearchShopInvitations(ctx, in, opts...) +} + +// -----------------------shopPlayers----------------------- +func (m *defaultShopService) AddShopPlayers(ctx context.Context, in *AddShopPlayersReq, opts ...grpc.CallOption) (*AddShopPlayersResp, error) { + client := pb.NewShopServiceClient(m.cli.Conn()) + return client.AddShopPlayers(ctx, in, opts...) +} + +func (m *defaultShopService) UpdateShopPlayers(ctx context.Context, in *UpdateShopPlayersReq, opts ...grpc.CallOption) (*UpdateShopPlayersResp, error) { + client := pb.NewShopServiceClient(m.cli.Conn()) + return client.UpdateShopPlayers(ctx, in, opts...) +} + +func (m *defaultShopService) DelShopPlayers(ctx context.Context, in *DelShopPlayersReq, opts ...grpc.CallOption) (*DelShopPlayersResp, error) { + client := pb.NewShopServiceClient(m.cli.Conn()) + return client.DelShopPlayers(ctx, in, opts...) +} + +func (m *defaultShopService) GetShopPlayersById(ctx context.Context, in *GetShopPlayersByIdReq, opts ...grpc.CallOption) (*GetShopPlayersByIdResp, error) { + client := pb.NewShopServiceClient(m.cli.Conn()) + return client.GetShopPlayersById(ctx, in, opts...) +} + +func (m *defaultShopService) SearchShopPlayers(ctx context.Context, in *SearchShopPlayersReq, opts ...grpc.CallOption) (*SearchShopPlayersResp, error) { + client := pb.NewShopServiceClient(m.cli.Conn()) + return client.SearchShopPlayers(ctx, in, opts...) +} + +// -----------------------shops----------------------- +func (m *defaultShopService) AddShops(ctx context.Context, in *AddShopsReq, opts ...grpc.CallOption) (*AddShopsResp, error) { + client := pb.NewShopServiceClient(m.cli.Conn()) + return client.AddShops(ctx, in, opts...) +} + +func (m *defaultShopService) UpdateShops(ctx context.Context, in *UpdateShopsReq, opts ...grpc.CallOption) (*UpdateShopsResp, error) { + client := pb.NewShopServiceClient(m.cli.Conn()) + return client.UpdateShops(ctx, in, opts...) +} + +func (m *defaultShopService) DelShops(ctx context.Context, in *DelShopsReq, opts ...grpc.CallOption) (*DelShopsResp, error) { + client := pb.NewShopServiceClient(m.cli.Conn()) + return client.DelShops(ctx, in, opts...) +} + +func (m *defaultShopService) GetShopsById(ctx context.Context, in *GetShopsByIdReq, opts ...grpc.CallOption) (*GetShopsByIdResp, error) { + client := pb.NewShopServiceClient(m.cli.Conn()) + return client.GetShopsById(ctx, in, opts...) +} + +func (m *defaultShopService) SearchShops(ctx context.Context, in *SearchShopsReq, opts ...grpc.CallOption) (*SearchShopsResp, error) { + client := pb.NewShopServiceClient(m.cli.Conn()) + return client.SearchShops(ctx, in, opts...) +} diff --git a/backup/envoy - 副本.yaml b/backup/envoy - 副本.yaml new file mode 100644 index 0000000..86aa780 --- /dev/null +++ b/backup/envoy - 副本.yaml @@ -0,0 +1,402 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: envoy-config + namespace: juwan +data: + envoy.yaml: | + static_resources: + listeners: + - name: ingress_http + address: + socket_address: + address: 0.0.0.0 + port_value: 8080 + filter_chains: + - filters: + - name: envoy.filters.network.http_connection_manager + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager + stat_prefix: ingress_http + codec_type: AUTO + generate_request_id: true + use_remote_address: true + internal_address_config: + cidr_ranges: + - address_prefix: 10.0.0.0 + prefix_len: 8 + - address_prefix: 172.16.0.0 + prefix_len: 12 + - address_prefix: 192.168.0.0 + prefix_len: 16 + - address_prefix: 127.0.0.0 + prefix_len: 8 + route_config: + name: local_route + virtual_hosts: + - name: juwan_services + domains: ["*"] + routes: + - match: + path: /healthz + direct_response: + status: 200 + body: + inline_string: ok + typed_per_filter_config: + envoy.filters.http.ext_authz: + "@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthzPerRoute + disabled: true + + - match: + path: /api/v1/auth/login + route: + cluster: user_api_cluster + timeout: 30s + typed_per_filter_config: + envoy.filters.http.ext_authz: + "@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthzPerRoute + disabled: true + + - match: + path: /api/v1/auth/register + route: + cluster: user_api_cluster + timeout: 30s + typed_per_filter_config: + envoy.filters.http.ext_authz: + "@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthzPerRoute + disabled: true + + - match: + prefix: /api/users + route: + cluster: user_api_cluster + timeout: 30s + typed_per_filter_config: + envoy.filters.http.ext_authz: + "@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthzPerRoute + disabled: true + + - match: + path: /api/v1/email/verification-code/send + route: + cluster: email_api_cluster + timeout: 30s + typed_per_filter_config: + envoy.filters.http.ext_authz: + "@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthzPerRoute + disabled: true + + - match: + prefix: /api/email + route: + cluster: email_api_cluster + timeout: 30s + + - match: + prefix: / + direct_response: + status: 404 + body: + inline_string: "gateway route not found" + + http_filters: + - name: envoy.filters.http.lua + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua + inline_code: | + local TOKEN_HEADER = "xsrf-token" + local TOKEN_COOKIE = "__Host-XSRF-TOKEN" + local GUARD_COOKIE = "__Host-XSRF-GUARD" + + local seeded = false + + local function seed_random() + if seeded then + return + end + seeded = true + math.randomseed(os.time()) + end + + local function split_cookie(header) + local out = {} + if not header then + return out + end + for pair in string.gmatch(header, "([^;]+)") do + local key, value = string.match(pair, "^%s*([^=]+)=?(.*)$") + if key ~= nil and value ~= nil then + out[string.lower(key)] = value + end + end + return out + end + + local function is_safe_method(method) + return method == "GET" or method == "HEAD" or method == "OPTIONS" + end + + local function build_token(request_id) + seed_random() + local rnd = tostring(math.random(100000, 999999)) + local rid = request_id or "rid" + return tostring(os.time()) .. "-" .. rid .. "-" .. rnd + end + + function envoy_on_request(request_handle) + local headers = request_handle:headers() + local method = headers:get(":method") + + local cookie_header = headers:get("cookie") + local cookies = split_cookie(cookie_header) + local token_cookie = cookies[string.lower(TOKEN_COOKIE)] + local guard_cookie = cookies[string.lower(GUARD_COOKIE)] + + request_handle:streamInfo():dynamicMetadata():set("csrf", "need_set_token_cookie", token_cookie == nil or token_cookie == "") + request_handle:streamInfo():dynamicMetadata():set("csrf", "need_set_guard_cookie", guard_cookie == nil or guard_cookie == "") + + if token_cookie == nil or token_cookie == "" then + token_cookie = build_token(headers:get("x-request-id")) + request_handle:streamInfo():dynamicMetadata():set("csrf", "token_value", token_cookie) + else + request_handle:streamInfo():dynamicMetadata():set("csrf", "token_value", token_cookie) + end + + if guard_cookie == nil or guard_cookie == "" then + guard_cookie = build_token(headers:get("x-request-id")) + request_handle:streamInfo():dynamicMetadata():set("csrf", "guard_value", guard_cookie) + else + request_handle:streamInfo():dynamicMetadata():set("csrf", "guard_value", guard_cookie) + end + + if is_safe_method(method) then + return + end + + local token_header = headers:get(TOKEN_HEADER) + + if token_header == nil or token_header == "" then + request_handle:respond( + {[":status"] = "403", ["content-type"] = "application/json"}, + '{"code":403,"message":"missing XSRF-TOKEN header"}' + ) + return + end + + if token_cookie == nil or token_cookie == "" or guard_cookie == nil or guard_cookie == "" then + request_handle:respond( + {[":status"] = "403", ["content-type"] = "application/json"}, + '{"code":403,"message":"missing csrf cookies"}' + ) + return + end + + if token_header ~= token_cookie then + request_handle:respond( + {[":status"] = "403", ["content-type"] = "application/json"}, + '{"code":403,"message":"xsrf token mismatch"}' + ) + return + end + end + + function envoy_on_response(response_handle) + local metadata = response_handle:streamInfo():dynamicMetadata():get("csrf") + if metadata == nil then + return + end + + local token_value = metadata["token_value"] + local guard_value = metadata["guard_value"] + + if metadata["need_set_token_cookie"] == true and token_value ~= nil and token_value ~= "" then + response_handle:headers():add( + "set-cookie", + TOKEN_COOKIE .. "=" .. token_value .. "; Path=/; Max-Age=7200; SameSite=Strict; Secure" + ) + end + + if metadata["need_set_guard_cookie"] == true and guard_value ~= nil and guard_value ~= "" then + response_handle:headers():add( + "set-cookie", + GUARD_COOKIE .. "=" .. guard_value .. "; Path=/; Max-Age=7200; SameSite=Strict; Secure; HttpOnly" + ) + end + end + + - name: envoy.filters.http.jwt_authn + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.http.jwt_authn.v3.JwtAuthentication + providers: + juwan_user_jwt: + issuer: "juwan-user-rpc" + from_cookies: + - "JToken" + local_jwks: + inline_string: '{"keys":[{"kty":"oct","k":"MGUyMWE3ZDhjMTQ5ZDg1MWViOWU0MGM3OTE2NWVkYTBlOTE5ZWRkZDU1YjYzOGJjOWRiNzM0NTc4NDIyMjlkZQ","alg":"HS256","use":"sig","kid":"juwan-hs256-1"}]}' + forward: false + claim_to_headers: + - header_name: "x-auth-user-id" + claim_name: "UserId" + - header_name: "x-auth-is-admin" + claim_name: "IsAdmin" + rules: + - match: + path: "/healthz" + - match: + path: "/api/v1/auth/login" + - match: + path: "/api/v1/auth/register" + - match: + path: "/api/v1/email/verification-code/send" + - match: + prefix: "/api/users" + requires: + provider_name: juwan_user_jwt + - match: + prefix: "/api/email" + requires: + provider_name: juwan_user_jwt + + - name: envoy.filters.http.ext_authz + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthz + transport_api_version: V3 + failure_mode_allow: false + with_request_body: + max_request_bytes: 8192 + allow_partial_message: true + grpc_service: + envoy_grpc: + cluster_name: authz_adapter_cluster + timeout: 0.5s + + - name: envoy.filters.http.router + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router + + clusters: + - name: user_api_cluster + connect_timeout: 2s + type: STRICT_DNS + lb_policy: ROUND_ROBIN + load_assignment: + cluster_name: user_api_cluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: user-api-svc.juwan.svc.cluster.local + port_value: 8888 + + - name: email_api_cluster + connect_timeout: 2s + type: STRICT_DNS + lb_policy: ROUND_ROBIN + load_assignment: + cluster_name: email_api_cluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: email-api-svc.juwan.svc.cluster.local + port_value: 8888 + + - name: authz_adapter_cluster + connect_timeout: 0.5s + type: STRICT_DNS + lb_policy: ROUND_ROBIN + http2_protocol_options: {} + load_assignment: + cluster_name: authz_adapter_cluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: authz-adapter-svc.juwan.svc.cluster.local + port_value: 9002 + + admin: + access_log_path: /tmp/admin_access.log + address: + socket_address: + address: 0.0.0.0 + port_value: 9901 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: envoy-gateway + namespace: juwan + labels: + app: envoy-gateway +spec: + replicas: 2 + revisionHistoryLimit: 5 + selector: + matchLabels: + app: envoy-gateway + template: + metadata: + labels: + app: envoy-gateway + spec: + serviceAccountName: envoy-gateway + containers: + - name: envoy + image: envoyproxy/envoy:v1.31-latest + imagePullPolicy: IfNotPresent + command: ["/usr/local/bin/envoy"] + args: + - "-c" + - "/etc/envoy/envoy.yaml" + - "--log-level" + - "info" + ports: + - containerPort: 8080 + name: http + - containerPort: 9901 + name: admin + livenessProbe: + httpGet: + path: /healthz + port: 8080 + initialDelaySeconds: 10 + periodSeconds: 15 + readinessProbe: + httpGet: + path: /healthz + port: 8080 + initialDelaySeconds: 5 + periodSeconds: 10 + volumeMounts: + - name: envoy-config + mountPath: /etc/envoy + volumes: + - name: envoy-config + configMap: + name: envoy-config + +--- +apiVersion: v1 +kind: Service +metadata: + name: envoy-gateway + namespace: juwan +spec: + selector: + app: envoy-gateway + ports: + - name: http + port: 80 + targetPort: 8080 + - name: admin + port: 9901 + targetPort: 9901 + type: ClusterIP diff --git a/backup/envoy copy.yaml b/backup/envoy copy.yaml deleted file mode 100644 index e54923e..0000000 --- a/backup/envoy copy.yaml +++ /dev/null @@ -1,388 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: envoy-config - namespace: juwan -data: - envoy.yaml: | - static_resources: - listeners: - - name: ingress_http - address: - socket_address: - address: 0.0.0.0 - port_value: 8080 - filter_chains: - - filters: - - name: envoy.filters.network.http_connection_manager - typed_config: - "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager - stat_prefix: ingress_http - codec_type: AUTO - generate_request_id: true - use_remote_address: true - internal_address_config: - cidr_ranges: - - address_prefix: 10.0.0.0 - prefix_len: 8 - - address_prefix: 172.16.0.0 - prefix_len: 12 - - address_prefix: 192.168.0.0 - prefix_len: 16 - - address_prefix: 127.0.0.0 - prefix_len: 8 - route_config: - name: local_route - virtual_hosts: - - name: juwan_services - domains: ["*"] - routes: - - match: - path: /healthz - direct_response: - status: 200 - body: - inline_string: ok - typed_per_filter_config: &public_route_ext_authz_disabled - envoy.filters.http.ext_authz: - "@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthzPerRoute - disabled: true - - - match: - path: /api/users/login - route: - cluster: user_api_cluster - timeout: &default_route_timeout 30s - typed_per_filter_config: *public_route_ext_authz_disabled - - - match: - path: /api/users/register - route: - cluster: user_api_cluster - timeout: *default_route_timeout - typed_per_filter_config: *public_route_ext_authz_disabled - - - match: - prefix: /api/users - route: - cluster: user_api_cluster - timeout: *default_route_timeout - - - match: - path: /api/email/verification-code/send - route: - cluster: email_api_cluster - timeout: *default_route_timeout - typed_per_filter_config: *public_route_ext_authz_disabled - - - match: - prefix: /api/email - route: - cluster: email_api_cluster - timeout: *default_route_timeout - - - match: - prefix: / - direct_response: - status: 404 - body: - inline_string: "gateway route not found" - - http_filters: - - name: envoy.filters.http.lua - typed_config: - "@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua - inline_code: | - local TOKEN_HEADER = "xsrf-token" - local TOKEN_COOKIE = "__Host-XSRF-TOKEN" - local GUARD_COOKIE = "__Host-XSRF-GUARD" - - local seeded = false - - local function seed_random() - if seeded then - return - end - seeded = true - math.randomseed(os.time()) - end - - local function split_cookie(header) - local out = {} - if not header then - return out - end - for pair in string.gmatch(header, "([^;]+)") do - local key, value = string.match(pair, "^%s*([^=]+)=?(.*)$") - if key ~= nil and value ~= nil then - out[string.lower(key)] = value - end - end - return out - end - - local function is_safe_method(method) - return method == "GET" or method == "HEAD" or method == "OPTIONS" - end - - local function build_token(request_id) - seed_random() - local rnd = tostring(math.random(100000, 999999)) - local rid = request_id or "rid" - return tostring(os.time()) .. "-" .. rid .. "-" .. rnd - end - - function envoy_on_request(request_handle) - local headers = request_handle:headers() - local method = headers:get(":method") - - local cookie_header = headers:get("cookie") - local cookies = split_cookie(cookie_header) - local token_cookie = cookies[string.lower(TOKEN_COOKIE)] - local guard_cookie = cookies[string.lower(GUARD_COOKIE)] - - request_handle:streamInfo():dynamicMetadata():set("csrf", "need_set_token_cookie", token_cookie == nil or token_cookie == "") - request_handle:streamInfo():dynamicMetadata():set("csrf", "need_set_guard_cookie", guard_cookie == nil or guard_cookie == "") - - if token_cookie == nil or token_cookie == "" then - token_cookie = build_token(headers:get("x-request-id")) - request_handle:streamInfo():dynamicMetadata():set("csrf", "token_value", token_cookie) - else - request_handle:streamInfo():dynamicMetadata():set("csrf", "token_value", token_cookie) - end - - if guard_cookie == nil or guard_cookie == "" then - guard_cookie = build_token(headers:get("x-request-id")) - request_handle:streamInfo():dynamicMetadata():set("csrf", "guard_value", guard_cookie) - else - request_handle:streamInfo():dynamicMetadata():set("csrf", "guard_value", guard_cookie) - end - - if is_safe_method(method) then - return - end - - local token_header = headers:get(TOKEN_HEADER) - - if token_header == nil or token_header == "" then - request_handle:respond( - {[":status"] = "403", ["content-type"] = "application/json"}, - '{"code":403,"message":"missing XSRF-TOKEN header"}' - ) - return - end - - if token_cookie == nil or token_cookie == "" or guard_cookie == nil or guard_cookie == "" then - request_handle:respond( - {[":status"] = "403", ["content-type"] = "application/json"}, - '{"code":403,"message":"missing csrf cookies"}' - ) - return - end - - if token_header ~= token_cookie then - request_handle:respond( - {[":status"] = "403", ["content-type"] = "application/json"}, - '{"code":403,"message":"xsrf token mismatch"}' - ) - return - end - end - - function envoy_on_response(response_handle) - local metadata = response_handle:streamInfo():dynamicMetadata():get("csrf") - if metadata == nil then - return - end - - local token_value = metadata["token_value"] - local guard_value = metadata["guard_value"] - - if metadata["need_set_token_cookie"] == true and token_value ~= nil and token_value ~= "" then - response_handle:headers():add( - "set-cookie", - TOKEN_COOKIE .. "=" .. token_value .. "; Path=/; Max-Age=7200; SameSite=Strict; Secure" - ) - end - - if metadata["need_set_guard_cookie"] == true and guard_value ~= nil and guard_value ~= "" then - response_handle:headers():add( - "set-cookie", - GUARD_COOKIE .. "=" .. guard_value .. "; Path=/; Max-Age=7200; SameSite=Strict; Secure; HttpOnly" - ) - end - end - - - name: envoy.filters.http.jwt_authn - typed_config: - "@type": type.googleapis.com/envoy.extensions.filters.http.jwt_authn.v3.JwtAuthentication - providers: - juwan_user_jwt: - issuer: "juwan-user-rpc" - from_cookies: - - "JToken" - local_jwks: - inline_string: '{"keys":[{"kty":"oct","k":"MGUyMWE3ZDhjMTQ5ZDg1MWViOWU0MGM3OTE2NWVkYTBlOTE5ZWRkZDU1YjYzOGJjOWRiNzM0NTc4NDIyMjlkZQ","alg":"HS256","use":"sig","kid":"juwan-hs256-1"}]}' - forward: false - claim_to_headers: - - header_name: "x-auth-user-id" - claim_name: "UserId" - - header_name: "x-auth-is-admin" - claim_name: "IsAdmin" - rules: - - match: - path: "/healthz" - - match: - path: "/api/users/login" - - match: - path: "/api/users/register" - - match: - path: "/api/email/verification-code/send" - - match: - prefix: "/api/users" - requires: &jwt_required - provider_name: juwan_user_jwt - - match: - prefix: "/api/email" - requires: *jwt_required - - - name: envoy.filters.http.ext_authz - typed_config: - "@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthz - transport_api_version: V3 - failure_mode_allow: false - with_request_body: - max_request_bytes: 8192 - allow_partial_message: true - grpc_service: - envoy_grpc: - cluster_name: authz_adapter_cluster - timeout: 0.5s - - - name: envoy.filters.http.router - typed_config: - "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router - - clusters: - - name: user_api_cluster - connect_timeout: 2s - type: STRICT_DNS - lb_policy: ROUND_ROBIN - load_assignment: - cluster_name: user_api_cluster - endpoints: - - lb_endpoints: - - endpoint: - address: - socket_address: - address: user-api-svc.juwan.svc.cluster.local - port_value: 8888 - - - name: email_api_cluster - connect_timeout: 2s - type: STRICT_DNS - lb_policy: ROUND_ROBIN - load_assignment: - cluster_name: email_api_cluster - endpoints: - - lb_endpoints: - - endpoint: - address: - socket_address: - address: email-api-svc.juwan.svc.cluster.local - port_value: 8888 - - - name: authz_adapter_cluster - connect_timeout: 0.5s - type: STRICT_DNS - lb_policy: ROUND_ROBIN - http2_protocol_options: {} - load_assignment: - cluster_name: authz_adapter_cluster - endpoints: - - lb_endpoints: - - endpoint: - address: - socket_address: - address: authz-adapter-svc.juwan.svc.cluster.local - port_value: 9002 - - admin: - access_log_path: /tmp/admin_access.log - address: - socket_address: - address: 0.0.0.0 - port_value: 9901 - ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: envoy-gateway - namespace: juwan - labels: - app: envoy-gateway -spec: - replicas: 2 - revisionHistoryLimit: 5 - selector: - matchLabels: - app: envoy-gateway - template: - metadata: - labels: - app: envoy-gateway - spec: - serviceAccountName: envoy-gateway - containers: - - name: envoy - image: envoyproxy/envoy:v1.31-latest - imagePullPolicy: IfNotPresent - command: ["/usr/local/bin/envoy"] - args: - - "-c" - - "/etc/envoy/envoy.yaml" - - "--log-level" - - "info" - ports: - - containerPort: 8080 - name: http - - containerPort: 9901 - name: admin - livenessProbe: - httpGet: - path: /healthz - port: 8080 - initialDelaySeconds: 10 - periodSeconds: 15 - readinessProbe: - httpGet: - path: /healthz - port: 8080 - initialDelaySeconds: 5 - periodSeconds: 10 - volumeMounts: - - name: envoy-config - mountPath: /etc/envoy - volumes: - - name: envoy-config - configMap: - name: envoy-config - ---- -apiVersion: v1 -kind: Service -metadata: - name: envoy-gateway - namespace: juwan -spec: - selector: - app: envoy-gateway - ports: - - name: http - port: 80 - targetPort: 8080 - - name: admin - port: 9901 - targetPort: 9901 - type: ClusterIP diff --git a/deploy/k8s/envoy/envoy.yaml b/deploy/k8s/envoy/envoy.yaml index 86aa780..113708a 100644 --- a/deploy/k8s/envoy/envoy.yaml +++ b/deploy/k8s/envoy/envoy.yaml @@ -67,6 +67,36 @@ data: envoy.filters.http.ext_authz: "@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthzPerRoute disabled: true + + - match: + path: /api/v1/auth/forgot-password + route: + cluster: user_api_cluster + timeout: 30s + typed_per_filter_config: + envoy.filters.http.ext_authz: + "@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthzPerRoute + disabled: true + + - match: + path: /api/v1/auth/reset-password + route: + cluster: user_api_cluster + timeout: 30s + typed_per_filter_config: + envoy.filters.http.ext_authz: + "@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthzPerRoute + disabled: true + + - match: + path: /api/v1/auth/forgot-password/send + route: + cluster: email_api_cluster + timeout: 30s + typed_per_filter_config: + envoy.filters.http.ext_authz: + "@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthzPerRoute + disabled: true - match: prefix: /api/users @@ -87,7 +117,123 @@ data: envoy.filters.http.ext_authz: "@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthzPerRoute disabled: true - + + - match: + prefix: /api/v1/email + route: + cluster: email_api_cluster + timeout: 30s + + - match: + prefix: /api/v1/auth + route: + cluster: user_api_cluster + timeout: 30s + + # ===== 未来按服务拆分路由(服务未落地前先注释) ===== + # - match: + # prefix: /api/v1/games + # route: + # cluster: game_api_cluster + # timeout: 30s + # - match: + # prefix: /api/v1/orders + # route: + # cluster: order_api_cluster + # timeout: 30s + # - match: + # prefix: /api/v1/players + # route: + # cluster: player_api_cluster + # timeout: 30s + # - match: + # prefix: /api/v1/services + # route: + # cluster: player_api_cluster + # timeout: 30s + # - match: + # prefix: /api/v1/shops + # route: + # cluster: shop_api_cluster + # timeout: 30s + # - match: + # prefix: /api/v1/wallet + # route: + # cluster: wallet_api_cluster + # timeout: 30s + # - match: + # prefix: /api/v1/disputes + # route: + # cluster: dispute_api_cluster + # timeout: 30s + # - match: + # safe_regex: + # google_re2: {} + # regex: "^/api/v1/orders/[^/]+/dispute$" + # route: + # cluster: dispute_api_cluster + # timeout: 30s + # - match: + # prefix: /api/v1/reviews + # route: + # cluster: review_api_cluster + # timeout: 30s + # - match: + # safe_regex: + # google_re2: {} + # regex: "^/api/v1/orders/[^/]+/review(s)?$" + # route: + # cluster: review_api_cluster + # timeout: 30s + # - match: + # prefix: /api/v1/posts + # route: + # cluster: community_api_cluster + # timeout: 30s + # - match: + # safe_regex: + # google_re2: {} + # regex: "^/api/v1/comments/[^/]+/like$" + # route: + # cluster: community_api_cluster + # timeout: 30s + # - match: + # path: /api/v1/search + # route: + # cluster: search_api_cluster + # timeout: 30s + # - match: + # path: /api/v1/recommendations/home + # route: + # cluster: search_api_cluster + # timeout: 30s + # - match: + # prefix: /api/v1/notifications + # route: + # cluster: notification_api_cluster + # timeout: 30s + # - match: + # prefix: /api/v1/chat + # route: + # cluster: chat_api_cluster + # timeout: 30s + # - match: + # prefix: /api/v1/upload + # route: + # cluster: objectstory_api_cluster + # timeout: 30s + # - match: + # prefix: /api/v1/files + # route: + # cluster: objectstory_api_cluster + # timeout: 30s + + - match: + prefix: /api/v1 + route: + cluster: user_api_cluster + timeout: 30s + - match: prefix: /api/email route: @@ -245,12 +391,112 @@ data: rules: - match: path: "/healthz" + - match: + prefix: "/api/v1" + headers: + - name: ":method" + exact_match: "OPTIONS" - match: path: "/api/v1/auth/login" - match: path: "/api/v1/auth/register" + - match: + path: "/api/v1/auth/forgot-password" + - match: + path: "/api/v1/auth/reset-password" + - match: + path: "/api/v1/auth/forgot-password/send" - match: path: "/api/v1/email/verification-code/send" + + - match: + prefix: "/api/v1/games" + headers: + - name: ":method" + exact_match: "GET" + - match: + prefix: "/api/v1/players" + headers: + - name: ":method" + exact_match: "GET" + - match: + prefix: "/api/v1/services" + headers: + - name: ":method" + exact_match: "GET" + - match: + path: "/api/v1/search" + headers: + - name: ":method" + exact_match: "GET" + - match: + path: "/api/v1/recommendations/home" + headers: + - name: ":method" + exact_match: "GET" + - match: + prefix: "/api/v1/posts" + headers: + - name: ":method" + exact_match: "GET" + - match: + prefix: "/api/v1/reviews" + headers: + - name: ":method" + exact_match: "GET" + - match: + path: "/api/v1/shops" + headers: + - name: ":method" + exact_match: "GET" + - match: + safe_regex: + google_re2: {} + regex: "^/api/v1/shops/[^/]+$" + headers: + - name: ":method" + exact_match: "GET" + - match: + safe_regex: + google_re2: {} + regex: "^/api/v1/shops/[^/]+/players$" + headers: + - name: ":method" + exact_match: "GET" + - match: + safe_regex: + google_re2: {} + regex: "^/api/v1/users/[^/]+$" + headers: + - name: ":method" + exact_match: "GET" + - match: + safe_regex: + google_re2: {} + regex: "^/api/v1/users/[^/]+/posts$" + headers: + - name: ":method" + exact_match: "GET" + - match: + safe_regex: + google_re2: {} + regex: "^/api/v1/users/[^/]+/reviews$" + headers: + - name: ":method" + exact_match: "GET" + - match: + safe_regex: + google_re2: {} + regex: "^/api/v1/users/[^/]+/shop$" + headers: + - name: ":method" + exact_match: "GET" + + - match: + prefix: "/api/v1" + requires: + provider_name: juwan_user_jwt + - match: prefix: "/api/users" requires: @@ -305,6 +551,175 @@ data: socket_address: address: email-api-svc.juwan.svc.cluster.local port_value: 8888 + + # ===== 未来服务集群预留(当前未实现,先注释) ===== + # - name: game_api_cluster + # connect_timeout: 2s + # type: STRICT_DNS + # lb_policy: ROUND_ROBIN + # load_assignment: + # cluster_name: game_api_cluster + # endpoints: + # - lb_endpoints: + # - endpoint: + # address: + # socket_address: + # address: game-api-svc.juwan.svc.cluster.local + # port_value: 8888 + # + # - name: objectstory_api_cluster + # connect_timeout: 2s + # type: STRICT_DNS + # lb_policy: ROUND_ROBIN + # load_assignment: + # cluster_name: objectstory_api_cluster + # endpoints: + # - lb_endpoints: + # - endpoint: + # address: + # socket_address: + # address: objectstory-api-svc.juwan.svc.cluster.local + # port_value: 8888 + # + # - name: order_api_cluster + # connect_timeout: 2s + # type: STRICT_DNS + # lb_policy: ROUND_ROBIN + # load_assignment: + # cluster_name: order_api_cluster + # endpoints: + # - lb_endpoints: + # - endpoint: + # address: + # socket_address: + # address: order-api-svc.juwan.svc.cluster.local + # port_value: 8888 + # + # - name: player_api_cluster + # connect_timeout: 2s + # type: STRICT_DNS + # lb_policy: ROUND_ROBIN + # load_assignment: + # cluster_name: player_api_cluster + # endpoints: + # - lb_endpoints: + # - endpoint: + # address: + # socket_address: + # address: player-api-svc.juwan.svc.cluster.local + # port_value: 8888 + # + # - name: shop_api_cluster + # connect_timeout: 2s + # type: STRICT_DNS + # lb_policy: ROUND_ROBIN + # load_assignment: + # cluster_name: shop_api_cluster + # endpoints: + # - lb_endpoints: + # - endpoint: + # address: + # socket_address: + # address: shop-api-svc.juwan.svc.cluster.local + # port_value: 8888 + # + # - name: wallet_api_cluster + # connect_timeout: 2s + # type: STRICT_DNS + # lb_policy: ROUND_ROBIN + # load_assignment: + # cluster_name: wallet_api_cluster + # endpoints: + # - lb_endpoints: + # - endpoint: + # address: + # socket_address: + # address: wallet-api-svc.juwan.svc.cluster.local + # port_value: 8888 + # + # - name: dispute_api_cluster + # connect_timeout: 2s + # type: STRICT_DNS + # lb_policy: ROUND_ROBIN + # load_assignment: + # cluster_name: dispute_api_cluster + # endpoints: + # - lb_endpoints: + # - endpoint: + # address: + # socket_address: + # address: dispute-api-svc.juwan.svc.cluster.local + # port_value: 8888 + # + # - name: review_api_cluster + # connect_timeout: 2s + # type: STRICT_DNS + # lb_policy: ROUND_ROBIN + # load_assignment: + # cluster_name: review_api_cluster + # endpoints: + # - lb_endpoints: + # - endpoint: + # address: + # socket_address: + # address: review-api-svc.juwan.svc.cluster.local + # port_value: 8888 + # + # - name: search_api_cluster + # connect_timeout: 2s + # type: STRICT_DNS + # lb_policy: ROUND_ROBIN + # load_assignment: + # cluster_name: search_api_cluster + # endpoints: + # - lb_endpoints: + # - endpoint: + # address: + # socket_address: + # address: search-api-svc.juwan.svc.cluster.local + # port_value: 8888 + # + # - name: community_api_cluster + # connect_timeout: 2s + # type: STRICT_DNS + # lb_policy: ROUND_ROBIN + # load_assignment: + # cluster_name: community_api_cluster + # endpoints: + # - lb_endpoints: + # - endpoint: + # address: + # socket_address: + # address: community-api-svc.juwan.svc.cluster.local + # port_value: 8888 + # + # - name: notification_api_cluster + # connect_timeout: 2s + # type: STRICT_DNS + # lb_policy: ROUND_ROBIN + # load_assignment: + # cluster_name: notification_api_cluster + # endpoints: + # - lb_endpoints: + # - endpoint: + # address: + # socket_address: + # address: notification-api-svc.juwan.svc.cluster.local + # port_value: 8888 + # + # - name: chat_api_cluster + # connect_timeout: 2s + # type: STRICT_DNS + # lb_policy: ROUND_ROBIN + # load_assignment: + # cluster_name: chat_api_cluster + # endpoints: + # - lb_endpoints: + # - endpoint: + # address: + # socket_address: + # address: chat-api-svc.juwan.svc.cluster.local + # port_value: 8888 - name: authz_adapter_cluster connect_timeout: 0.5s diff --git a/deploy/k8s/secrets/email-smtp-secret.yaml b/deploy/k8s/secrets/email-smtp-secret.yaml new file mode 100644 index 0000000..fb2a7a8 --- /dev/null +++ b/deploy/k8s/secrets/email-smtp-secret.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Secret +metadata: + name: email-smtp-secret + namespace: juwan +type: Opaque +data: + EMAIL_SMTP_HOST: c210cC4xNjMuY29t + EMAIL_SMTP_PORT: NDY1 + EMAIL_SMTP_USERNAME: Y2h1cm9uZzI2NDZAMTYzLmNvbQ== + EMAIL_SMTP_PASSWORD: R1R2NkM2cU5idjV1ckFpRA== + EMAIL_FROM_ADDRESS: Y2h1cm9uZzI2NDZAMTYzLmNvbQ== + EMAIL_FROM_NAME: 6IGa546p + EMAIL_REPLY_TO: Y2h1cm9uZzI2NDZAMTYzLmNvbQ== \ No newline at end of file diff --git a/deploy/k8s/service/email/email-api.yaml b/deploy/k8s/service/email/email-api.yaml index 42eeae1..38e4196 100644 --- a/deploy/k8s/service/email/email-api.yaml +++ b/deploy/k8s/service/email/email-api.yaml @@ -21,6 +21,7 @@ spec: - name: email-api # image: 103.236.53.208:4418/library/email-api@sha256:fe5c66f5bcb1a39652620df42351de3e48227920a34be3110a45eb13db327020 image: email-api:latest + imagePullPolicy: Always ports: - containerPort: 8888 - containerPort: 4001 diff --git a/deploy/k8s/service/email/email-mq.yaml b/deploy/k8s/service/email/email-mq.yaml index ee2d14a..e4718e5 100644 --- a/deploy/k8s/service/email/email-mq.yaml +++ b/deploy/k8s/service/email/email-mq.yaml @@ -26,6 +26,43 @@ spec: - name: email-consumer # image: 103.236.53.208:4418/library/email-mq@sha256:a9f76e8f4a17d1c00cefc429962037550e17feebb5cf38b28d360c91c8ba3e68 image: email-mq:latest + imagePullPolicy: Always + env: + - name: EMAIL_SMTP_HOST + valueFrom: + secretKeyRef: + name: email-smtp-secret + key: EMAIL_SMTP_HOST + - name: EMAIL_SMTP_PORT + valueFrom: + secretKeyRef: + name: email-smtp-secret + key: EMAIL_SMTP_PORT + - name: EMAIL_SMTP_USERNAME + valueFrom: + secretKeyRef: + name: email-smtp-secret + key: EMAIL_SMTP_USERNAME + - name: EMAIL_SMTP_PASSWORD + valueFrom: + secretKeyRef: + name: email-smtp-secret + key: EMAIL_SMTP_PASSWORD + - name: EMAIL_FROM_ADDRESS + valueFrom: + secretKeyRef: + name: email-smtp-secret + key: EMAIL_FROM_ADDRESS + - name: EMAIL_FROM_NAME + valueFrom: + secretKeyRef: + name: email-smtp-secret + key: EMAIL_FROM_NAME + - name: EMAIL_REPLY_TO + valueFrom: + secretKeyRef: + name: email-smtp-secret + key: EMAIL_REPLY_TO ports: - containerPort: 4001 resources: diff --git a/deploy/k8s/service/user/user-rpc.yaml b/deploy/k8s/service/user/user-rpc.yaml index eda1d4f..8f333c4 100644 --- a/deploy/k8s/service/user/user-rpc.yaml +++ b/deploy/k8s/service/user/user-rpc.yaml @@ -10,7 +10,7 @@ spec: revisionHistoryLimit: 5 selector: matchLabels: - app: user-rpc + app: user-rpc # .Name template: metadata: labels: diff --git a/desc/api/chat.api b/desc/api/chat.api index 1989878..7896132 100644 --- a/desc/api/chat.api +++ b/desc/api/chat.api @@ -2,8 +2,12 @@ syntax = "v1" import "common.api" type ( + SessionIdReq { + Id int64 `path:"id"` + } + ChatSession { - Id string `json:"id"` + Id int64 `json:"id"` Type string `json:"type"` // order, consultation OrderId string `json:"orderId,optional"` Participants []SimpleUser `json:"participants"` @@ -17,7 +21,7 @@ type ( } ChatMessage { - Id string `json:"id"` + Id int64 `json:"id"` SessionId string `json:"sessionId"` SenderId string `json:"senderId"` Type string `json:"type"` // text, image, system @@ -31,15 +35,20 @@ type ( } SendMessageReq { + SessionIdReq Type string `json:"type"` Content string `json:"content"` } + + ListMessageReq { + SessionIdReq + PageReq + } ) @server( prefix: api/v1/chat group: chat - jwt: Auth ) service juwan-api { @doc "获取会话列表" @@ -48,11 +57,11 @@ service juwan-api { @doc "获取会话详情" @handler GetSession - get /sessions/:id (EmptyResp) returns (ChatSession) + get /sessions/:id (SessionIdReq) returns (ChatSession) @doc "获取消息历史" @handler ListMessages - get /sessions/:id/messages (PageReq) returns (ChatMessageListResp) + get /sessions/:id/messages (ListMessageReq) returns (ChatMessageListResp) @doc "发送消息" @handler SendMessage diff --git a/desc/api/community.api b/desc/api/community.api index 97a93cf..e99e803 100644 --- a/desc/api/community.api +++ b/desc/api/community.api @@ -2,8 +2,11 @@ syntax = "v1" import "common.api" type ( + PathId { + Id int64 `path:"id"` + } Post { - Id string `json:"id"` + Id int64 `json:"id"` Title string `json:"title"` Content string `json:"content"` Images []string `json:"images"` @@ -35,7 +38,7 @@ type ( } Comment { - Id string `json:"id"` + Id int64 `json:"id"` Content string `json:"content"` Author UserProfile `json:"author"` LikeCount int64 `json:"likeCount"` @@ -51,6 +54,10 @@ type ( CreateCommentReq { Content string `json:"content"` } + ListCommentsReq { + PathId + PageReq + } ) @server( @@ -64,21 +71,20 @@ service juwan-api { @doc "获取帖子详情" @handler GetPost - get /posts/:id (EmptyResp) returns (Post) + get /posts/:id (PathId) returns (Post) @doc "获取帖子评论" @handler ListComments - get /posts/:id/comments (PageReq) returns (CommentListResp) + get /posts/:id/comments (ListCommentsReq ) returns (CommentListResp) @doc "获取用户帖子" @handler ListUserPosts - get /users/:id/posts (PageReq) returns (PostListResp) + get /users/:id/posts (ListCommentsReq ) returns (PostListResp) } @server( prefix: api/v1 group: community - jwt: Auth ) service juwan-api { @doc "发布帖子" @@ -87,19 +93,19 @@ service juwan-api { @doc "点赞帖子" @handler LikePost - post /posts/:id/like (EmptyResp) returns (EmptyResp) + post /posts/:id/like (PathId) returns (EmptyResp) @doc "取消点赞帖子" @handler UnlikePost - delete /posts/:id/like (EmptyResp) returns (EmptyResp) + delete /posts/:id/like (PathId) returns (EmptyResp) @doc "置顶帖子" @handler PinPost - post /posts/:id/pin (EmptyResp) returns (EmptyResp) + post /posts/:id/pin (PathId) returns (EmptyResp) @doc "取消置顶" @handler UnpinPost - delete /posts/:id/pin (EmptyResp) returns (EmptyResp) + delete /posts/:id/pin (PathId) returns (EmptyResp) @doc "发表评论" @handler CreateComment @@ -107,9 +113,9 @@ service juwan-api { @doc "点赞评论" @handler LikeComment - post /comments/:id/like (EmptyResp) returns (EmptyResp) + post /comments/:id/like (PathId) returns (EmptyResp) @doc "取消点赞评论" @handler UnlikeComment - delete /comments/:id/like (EmptyResp) returns (EmptyResp) + delete /comments/:id/like (PathId) returns (EmptyResp) } \ No newline at end of file diff --git a/desc/api/dispute.api b/desc/api/dispute.api index 7798e32..e7e94af 100644 --- a/desc/api/dispute.api +++ b/desc/api/dispute.api @@ -2,32 +2,38 @@ syntax = "v1" import "common.api" type ( + PathId { + Id int64 `path:"id"` + } Dispute { - Id string `json:"id"` - OrderId string `json:"orderId"` - Reason string `json:"reason"` - Status string `json:"status"` - Evidence []string `json:"evidence"` - Result string `json:"result,optional"` - CreatedAt string `json:"createdAt"` + Id int64 `json:"id"` + OrderId int64 `json:"orderId"` + Reason string `json:"reason"` + Status string `json:"status"` + Evidence []string `json:"evidence"` + Result string `json:"result,optional"` + CreatedAt string `json:"createdAt"` } DisputeListResp { Items []Dispute `json:"items"` - Meta PageMeta `json:"meta"` + Meta PageMeta `json:"meta"` } CreateDisputeReq { - Reason string `json:"reason"` + PathId + Reason string `json:"reason"` Evidence []string `json:"evidence"` } DisputeResponseReq { - Reason string `json:"reason"` + PathId + Reason string `json:"reason"` Evidence []string `json:"evidence"` } AppealReq { + PathId Reason string `json:"reason"` } ) @@ -35,7 +41,6 @@ type ( @server( prefix: api/v1 group: dispute - jwt: Auth ) service juwan-api { @doc "获取争议列表" @@ -44,7 +49,7 @@ service juwan-api { @doc "获取订单争议" @handler GetOrderDispute - get /orders/:id/dispute (EmptyResp) returns (Dispute) + get /orders/:id/dispute (PathId) returns (Dispute) @doc "发起争议" @handler CreateDispute diff --git a/desc/api/game.api b/desc/api/game.api index 5254893..15aa996 100644 --- a/desc/api/game.api +++ b/desc/api/game.api @@ -1,30 +1,34 @@ syntax = "v1" + import "common.api" type ( - Game { - Id string `json:"id"` - Name string `json:"name"` - Icon string `json:"icon"` - Category string `json:"category"` - } - - GameListResp { - Items []Game `json:"items"` - Meta PageMeta `json:"meta"` - } + Game { + Id int64 `json:"id"` + Name string `json:"name"` + Icon string `json:"icon"` + Category string `json:"category"` + } + GameListResp { + Items []Game `json:"items"` + Meta PageMeta `json:"meta"` + } + GetGameReq { + Id int64 `path:"id"` + } ) -@server( - prefix: api/v1/games - group: game +@server ( + prefix: api/v1/games + group: game ) -service juwan-api { - @doc "获取游戏列表" - @handler ListGames - get / (PageReq) returns (GameListResp) +service game-api { + @doc "获取游戏列表" + @handler ListGames + get / (PageReq) returns (GameListResp) + + @doc "获取游戏详情" + @handler GetGame + get /:id (GetGameReq) returns (Game) +} - @doc "获取游戏详情" - @handler GetGame - get /:id (EmptyResp) returns (Game) -} \ No newline at end of file diff --git a/desc/api/notification.api b/desc/api/notification.api index 253af69..089d20d 100644 --- a/desc/api/notification.api +++ b/desc/api/notification.api @@ -2,8 +2,11 @@ syntax = "v1" import "common.api" type ( + PathId { + Id int64 `path:"id"` + } Notification { - Id string `json:"id"` + Id int64 `json:"id"` Type string `json:"type"` Title string `json:"title"` Content string `json:"content"` @@ -21,7 +24,6 @@ type ( @server( prefix: api/v1 group: notification - jwt: Auth ) service juwan-api { @doc "获取通知列表" @@ -30,7 +32,7 @@ service juwan-api { @doc "标记已读" @handler ReadNotification - put /notifications/:id/read (EmptyResp) returns (EmptyResp) + put /notifications/:id/read (PathId) returns (EmptyResp) @doc "全部已读" @handler ReadAllNotifications diff --git a/desc/api/objectstory.api b/desc/api/objectstory.api index 5bcd95d..7992a43 100644 --- a/desc/api/objectstory.api +++ b/desc/api/objectstory.api @@ -25,7 +25,6 @@ type ( @server ( prefix: /api/v1 group: file - jwt: Logger middleware: FileSizeLimit // 建议添加中间件限制文件大小 ) service file-api { diff --git a/desc/api/order.api b/desc/api/order.api index cf03c16..0262c87 100644 --- a/desc/api/order.api +++ b/desc/api/order.api @@ -3,13 +3,16 @@ import "common.api" import "player.api" // 为了使用 PlayerService 定义 type ( + PathId { + Id int64 `path:"id"` + } Order { - Id string `json:"id"` - ConsumerId string `json:"consumerId"` + Id int64 `json:"id"` + ConsumerId int64 `json:"consumerId"` ConsumerName string `json:"consumerName"` PlayerId string `json:"playerId"` PlayerName string `json:"playerName"` - ShopId string `json:"shopId,optional"` + ShopId int64 `json:"shopId,optional"` ShopName string `json:"shopName,optional"` Service PlayerService `json:"service"` Status string `json:"status"` @@ -32,9 +35,9 @@ type ( } CreateOrderReq { - PlayerId string `json:"playerId"` - ShopId string `json:"shopId,optional"` - ServiceId string `json:"serviceId"` + PlayerId int64 `json:"playerId"` + ShopId int64 `json:"shopId,optional"` + ServiceId int64 `json:"serviceId"` Quantity int `json:"quantity"` Note string `json:"note,optional"` } @@ -48,7 +51,6 @@ type ( @server( prefix: api/v1/orders group: order - jwt: Auth ) service juwan-api { @doc "获取订单列表" @@ -57,7 +59,7 @@ service juwan-api { @doc "获取订单详情" @handler GetOrder - get /:id (EmptyResp) returns (Order) + get /:id (PathId) returns (Order) @doc "创建订单" @handler CreateOrder @@ -69,25 +71,25 @@ service juwan-api { @doc "支付订单" @handler PayOrder - post /:id/pay (EmptyResp) returns (EmptyResp) + post /:id/pay (PathId) returns (EmptyResp) @doc "接单" @handler AcceptOrder - post /:id/accept (EmptyResp) returns (EmptyResp) + post /:id/accept (PathId) returns (EmptyResp) @doc "申请结算" @handler RequestCloseOrder - post /:id/request-close (EmptyResp) returns (EmptyResp) + post /:id/request-close (PathId) returns (EmptyResp) @doc "确认结算" @handler ConfirmCloseOrder - post /:id/confirm-close (EmptyResp) returns (EmptyResp) + post /:id/confirm-close (PathId) returns (EmptyResp) @doc "取消订单" @handler CancelOrder - post /:id/cancel (EmptyResp) returns (EmptyResp) + post /:id/cancel (PathId) returns (EmptyResp) @doc "再来一单" @handler Reorder - post /:id/reorder (EmptyResp) returns (CreateOrderResp) + post /:id/reorder (PathId) returns (CreateOrderResp) } \ No newline at end of file diff --git a/desc/api/player.api b/desc/api/player.api index a03f1b0..915055c 100644 --- a/desc/api/player.api +++ b/desc/api/player.api @@ -1,110 +1,135 @@ syntax = "v1" + import "common.api" type ( - PlayerService { - Id string `json:"id"` - PlayerId string `json:"playerId"` - GameId string `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"` - } - - PlayerServiceListResp { - Items []PlayerService `json:"items"` - Meta PageMeta `json:"meta"` - } - - CreateServiceReq { - GameId string `json:"gameId"` - Title string `json:"title"` - Description string `json:"description,optional"` - Price float64 `json:"price"` - Unit string `json:"unit"` - RankRange string `json:"rankRange,optional"` - Availability []string `json:"availability,optional"` - } - - PlayerProfile { - Id string `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"` - } - - PlayerListReq { - PageReq - GameId string `form:"gameId,optional"` - Gender int `form:"gender,optional"` - } - - PlayerListResp { - Items []PlayerProfile `json:"items"` - Meta PageMeta `json:"meta"` - } - - UpdatePlayerStatusReq { - Status string `json:"status"` - } + PlayerService { + 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"` + } + PlayerServiceListResp { + Items []PlayerService `json:"items"` + Meta PageMeta `json:"meta"` + } + CreateServiceReq { + 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"` + } + UpdateServiceReq { + 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"` + } + PlayerProfile { + 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"` + } + PlayerListReq { + PageReq + GameId int64 `form:"gameId,optional"` + Gender int `form:"gender,optional"` + } + PlayerListResp { + Items []PlayerProfile `json:"items"` + Meta PageMeta `json:"meta"` + } + UpdatePlayerStatusReq { + Status string `json:"status"` + } ) -@server( - prefix: api/v1 - group: player +type ( + GetServiceReq { + Id int64 `path:"id"` + } + GetPlayerReq { + Id int64 `path:"id"` + } + ListPlayerServicesReq { + PageReq + Id int64 `path:"id"` + } +) + +@server ( + prefix: api/v1 + group: player ) service juwan-api { - @doc "获取打手列表" - @handler ListPlayers - get /players (PlayerListReq) returns (PlayerListResp) + @doc "获取打手列表" + @handler ListPlayers + get /players (PlayerListReq) returns (PlayerListResp) - @doc "获取打手详情" - @handler GetPlayer - get /players/:id (EmptyResp) returns (PlayerProfile) + @doc "获取打手详情" + @handler GetPlayer + get /players/:id (GetPlayerReq) returns (PlayerProfile) - @doc "获取所有服务列表" - @handler ListServices - get /services (PageReq) returns (PlayerServiceListResp) + @doc "获取所有服务列表" + @handler ListServices + get /services (PageReq) returns (PlayerServiceListResp) - @doc "获取服务详情" - @handler GetService - get /services/:id (EmptyResp) returns (PlayerService) + @doc "获取服务详情" + @handler GetService + get /services/:id (GetServiceReq) returns (PlayerService) - @doc "获取指定打手的服务列表" - @handler ListPlayerServices - get /players/:id/services (PageReq) returns (PlayerServiceListResp) + @doc "获取指定打手的服务列表" + @handler ListPlayerServices + get /players/:id/services (ListPlayerServicesReq) returns (PlayerServiceListResp) } -@server( - prefix: api/v1 - group: player - jwt: Auth +type ( + DeleteServiceReq { + Id int64 `path:"id"` + } +) + +@server ( + prefix: api/v1 + group: player ) service juwan-api { - @doc "更新接单状态" - @handler UpdatePlayerStatus - put /players/me/status (UpdatePlayerStatusReq) returns (EmptyResp) + @doc "更新接单状态" + @handler UpdatePlayerStatus + put /players/me/status (UpdatePlayerStatusReq) returns (EmptyResp) - @doc "创建服务" - @handler CreateService - post /services (CreateServiceReq) returns (PlayerService) + @doc "创建服务" + @handler CreateService + post /services (CreateServiceReq) returns (PlayerService) - @doc "更新服务" - @handler UpdateService - put /services/:id (CreateServiceReq) returns (PlayerService) + @doc "更新服务" + @handler UpdateService + put /services/:id (UpdateServiceReq) returns (PlayerService) + + @doc "删除服务" + @handler DeleteService + delete /services/:id (DeleteServiceReq) returns (EmptyResp) +} - @doc "删除服务" - @handler DeleteService - delete /services/:id (EmptyResp) returns (EmptyResp) -} \ No newline at end of file diff --git a/desc/api/review.api b/desc/api/review.api index 6f0d8e1..ad842de 100644 --- a/desc/api/review.api +++ b/desc/api/review.api @@ -3,9 +3,9 @@ import "common.api" type ( Review { - Id string `json:"id"` - OrderId string `json:"orderId"` - FromUserId string `json:"fromUserId"` + Id int64 `json:"id"` + OrderId int64 `json:"orderId"` + FromUserId int64 `json:"fromUserId"` FromUserName string `json:"fromUserName"` Rating int `json:"rating"` Content string `json:"content"` @@ -27,7 +27,6 @@ type ( @server( prefix: api/v1 group: review - jwt: Auth ) service juwan-api { @doc "提交评价" diff --git a/desc/api/search.api b/desc/api/search.api index 41c9142..dbe1908 100644 --- a/desc/api/search.api +++ b/desc/api/search.api @@ -2,6 +2,9 @@ syntax = "v1" import "common.api" type ( + PathIDReq { + Id int64 `path:"id"` + } SearchReq { PageReq Q string `form:"q"` @@ -18,12 +21,13 @@ type ( FavoriteReq { TargetType string `json:"targetType"` // player, shop - TargetId string `json:"targetId"` + TargetId int64 `json:"targetId"` } FavoriteCheckReq { + PathIDReq TargetType string `form:"targetType"` - TargetId string `form:"targetId"` + TargetId int64 `form:"targetId"` } FavoriteCheckResp { @@ -48,7 +52,6 @@ service juwan-api { @server( prefix: api/v1 group: favorites - jwt: Auth ) service juwan-api { @doc "获取收藏列表" @@ -61,7 +64,7 @@ service juwan-api { @doc "取消收藏" @handler RemoveFavorite - delete /favorites/:id (EmptyResp) returns (EmptyResp) + delete /favorites/:id (PathIDReq) returns (EmptyResp) @doc "检查收藏状态" @handler CheckFavorite diff --git a/desc/api/shop.api b/desc/api/shop.api index c86767d..66c51d1 100644 --- a/desc/api/shop.api +++ b/desc/api/shop.api @@ -1,130 +1,147 @@ syntax = "v1" + import "common.api" type ( - ShopProfile { - Id string `json:"id"` - Owner UserProfile `json:"owner"` - Name string `json:"name"` - Banner string `json:"banner,optional"` - Description string `json:"description"` - Rating float64 `json:"rating"` - TotalOrders int64 `json:"totalOrders"` - PlayerCount int64 `json:"playerCount"` - CommissionType string `json:"commissionType"` - CommissionValue float64 `json:"commissionValue"` - Announcements []string `json:"announcements"` - TemplateConfig interface{} `json:"templateConfig"` - } - - ShopListResp { - Items []ShopProfile `json:"items"` - Meta PageMeta `json:"meta"` - } - - CreateShopReq { - Name string `json:"name"` - Description string `json:"description"` - CommissionType string `json:"commissionType"` - CommissionValue float64 `json:"commissionValue"` - } - - UpdateShopReq { - Name string `json:"name,optional"` - Description string `json:"description,optional"` - CommissionType string `json:"commissionType,optional"` - CommissionValue float64 `json:"commissionValue,optional"` - AllowMultiShop bool `json:"allowMultiShop,optional"` - AllowIndependentOrders bool `json:"allowIndependentOrders,optional"` - DispatchMode string `json:"dispatchMode,optional"` - } - - UpdateTemplateReq { - Sections interface{} `json:"sections"` - } - - AnnouncementReq { - Content string `json:"content"` - } - - IncomeStatsResp { - MonthlyIncome float64 `json:"monthlyIncome"` - PendingSettlement float64 `json:"pendingSettlement"` - TotalWithdrawn float64 `json:"totalWithdrawn"` - TotalOrders int64 `json:"totalOrders"` - CompletedOrders int64 `json:"completedOrders"` - } - - InvitationReq { - PlayerId string `json:"playerId"` - } + ShopProfile { + Id string `json:"id"` + Owner UserProfile `json:"owner"` + Name string `json:"name"` + Banner string `json:"banner,optional"` + Description string `json:"description"` + Rating float64 `json:"rating"` + TotalOrders int64 `json:"totalOrders"` + PlayerCount int64 `json:"playerCount"` + CommissionType string `json:"commissionType"` + CommissionValue float64 `json:"commissionValue"` + Announcements []string `json:"announcements"` + TemplateConfig interface{} `json:"templateConfig"` + } + ShopListResp { + Items []ShopProfile `json:"items"` + Meta PageMeta `json:"meta"` + } + CreateShopReq { + Name string `json:"name"` + Description string `json:"description"` + CommissionType string `json:"commissionType"` + CommissionValue float64 `json:"commissionValue"` + } + UpdateShopReq { + Id int64 `path:"id"` + Name string `json:"name,optional"` + Description string `json:"description,optional"` + CommissionType string `json:"commissionType,optional"` + CommissionValue float64 `json:"commissionValue,optional"` + AllowMultiShop bool `json:"allowMultiShop,optional"` + AllowIndependentOrders bool `json:"allowIndependentOrders,optional"` + DispatchMode string `json:"dispatchMode,optional"` + } + UpdateTemplateReq { + Id int64 `path:"id"` + Sections interface{} `json:"sections"` + } + AnnouncementReq { + Id int64 `path:"id"` + Content string `json:"content"` + } + IncomeStatsResp { + MonthlyIncome float64 `json:"monthlyIncome"` + PendingSettlement float64 `json:"pendingSettlement"` + TotalWithdrawn float64 `json:"totalWithdrawn"` + TotalOrders int64 `json:"totalOrders"` + CompletedOrders int64 `json:"completedOrders"` + } + InvitationReq { + Id int64 `path:"id"` + PlayerId int64 `json:"playerId"` + } ) -@server( - prefix: api/v1 - group: shop +type ( + ShopIdReq { + Id int64 `path:"id"` + } + UserIdReq { + Id int64 `path:"id"` + } +) + +@server ( + prefix: api/v1 + group: shop ) service juwan-api { - @doc "获取店铺列表" - @handler ListShops - get /shops (PageReq) returns (ShopListResp) + @doc "获取店铺列表" + @handler ListShops + get /shops (PageReq) returns (ShopListResp) - @doc "获取店铺详情" - @handler GetShop - get /shops/:id (EmptyResp) returns (ShopProfile) + @doc "获取店铺详情" + @handler GetShop + get /shops/:id (ShopIdReq) returns (ShopProfile) - @doc "获取店长的店铺" - @handler GetUserShop - get /users/:id/shop (EmptyResp) returns (ShopProfile) + @doc "获取店长的店铺" + @handler GetUserShop + get /users/:id/shop (UserIdReq) returns (ShopProfile) } -@server( - prefix: api/v1 - group: shop - jwt: Auth +type ( + DeleteAnnouncementReq { + Id int64 `path:"id"` + index int64 `path:"index"` + } + AcceptInvitationReq { + Id int64 `path:"id"` + } +) + +@server ( + prefix: api/v1 + group: shop ) service juwan-api { - @doc "创建店铺" - @handler CreateShop - post /shops (CreateShopReq) returns (ShopProfile) + @doc "创建店铺" + @handler CreateShop + post /shops (CreateShopReq) returns (ShopProfile) - @doc "获取当前用户的店铺" - @handler GetMyShop - get /shops/mine (EmptyResp) returns (ShopProfile) + @doc "获取当前用户的店铺" + @handler GetMyShop + get /shops/mine (EmptyResp) returns (ShopProfile) - @doc "更新店铺信息" - @handler UpdateShop - put /shops/:id (UpdateShopReq) returns (ShopProfile) + @doc "更新店铺信息" + @handler UpdateShop + put /shops/:id (ShopIdReq) returns (ShopProfile) - @doc "更新店铺模板" - @handler UpdateShopTemplate - put /shops/:id/template (UpdateTemplateReq) returns (EmptyResp) + @doc "更新店铺模板" + @handler UpdateShopTemplate + put /shops/:id/template (UpdateTemplateReq) returns (EmptyResp) - @doc "新增店铺公告" - @handler AddAnnouncement - post /shops/:id/announcements (AnnouncementReq) returns (EmptyResp) + @doc "新增店铺公告" + @handler AddAnnouncement + post /shops/:id/announcements (AnnouncementReq) returns (EmptyResp) - @doc "删除店铺公告" - @handler DeleteAnnouncement - delete /shops/:id/announcements/:index (EmptyResp) returns (EmptyResp) + @doc "删除店铺公告" + @handler DeleteAnnouncement + delete /shops/:id/announcements/:index (DeleteAnnouncementReq) returns (EmptyResp) - @doc "邀请打手" - @handler InvitePlayer - post /shops/:id/invitations (InvitationReq) returns (EmptyResp) + @doc "邀请打手" + @handler InvitePlayer + post /shops/:id/invitations (InvitationReq) returns (EmptyResp) - @doc "接受邀请" - @handler AcceptInvitation - post /shops/invitations/:id/accept (EmptyResp) returns (EmptyResp) + @doc "接受邀请" + @handler AcceptInvitation + post /shops/invitations/:id/accept (AcceptInvitationReq) returns (EmptyResp) - @doc "拒绝邀请" - @handler RejectInvitation - delete /shops/invitations/:id (EmptyResp) returns (EmptyResp) + @doc "拒绝邀请" + @handler RejectInvitation + delete /shops/invitations/:id (AcceptInvitationReq) returns (EmptyResp) - @doc "移除打手" - @handler RemovePlayer - delete /shops/:id/players/:playerId (EmptyResp) returns (EmptyResp) + @doc "移除打手" + @handler RemovePlayer + delete /shops/:id/players/:playerId (InvitationReq) returns (EmptyResp) + + @doc "获取收入统计" + @handler GetShopIncomeStats + get /shops/:id/income-stats (AcceptInvitationReq) returns (IncomeStatsResp) +} - @doc "获取收入统计" - @handler GetShopIncomeStats - get /shops/:id/income-stats (EmptyResp) returns (IncomeStatsResp) -} \ No newline at end of file diff --git a/desc/api/user_verifications.api b/desc/api/user_verifications.api index 685a5a6..d991f7d 100644 --- a/desc/api/user_verifications.api +++ b/desc/api/user_verifications.api @@ -18,7 +18,6 @@ info ( @server ( group: verification_user prefix: /api/v1/users - jwt: Auth // 必须登录 ) service verification-api { @doc "提交或修改角色认证申请 (支持幂等更新)" @@ -37,7 +36,6 @@ service verification-api { @server ( group: verification_admin prefix: /api/v1/admin - jwt: Auth // 需要登录,且 Logic 层需校验 IsAdmin ) service verification-api { @doc "管理员获取认证申请列表 (分页)" diff --git a/desc/api/wallet.api b/desc/api/wallet.api index 61aae1b..bb4031c 100644 --- a/desc/api/wallet.api +++ b/desc/api/wallet.api @@ -8,7 +8,7 @@ type ( } Transaction { - Id string `json:"id"` + Id int64 `json:"id"` Type string `json:"type"` Amount float64 `json:"amount"` Description string `json:"description"` @@ -30,7 +30,6 @@ type ( @server( prefix: api/v1/wallet group: wallet - jwt: Auth ) service juwan-api { @doc "获取余额" diff --git a/desc/rpc/game.proto b/desc/rpc/game.proto new file mode 100644 index 0000000..6d9751a --- /dev/null +++ b/desc/rpc/game.proto @@ -0,0 +1,97 @@ +syntax = "proto3"; + +option go_package ="./pb"; + +package pb; + +// ------------------------------------ +// Messages +// ------------------------------------ + +//--------------------------------games-------------------------------- +message Games { + int64 id = 1; //id + string name = 2; //name + string icon = 3; //icon + string category = 4; //category + int64 sortOrder = 5; //sortOrder + bool isActive = 6; //isActive + int64 createdAt = 7; //createdAt + int64 updatedAt = 8; //updatedAt +} + +message AddGamesReq { + string name = 1; //name + string icon = 2; //icon + string category = 3; //category + int64 sortOrder = 4; //sortOrder + bool isActive = 5; //isActive + int64 createdAt = 6; //createdAt + int64 updatedAt = 7; //updatedAt +} + +message AddGamesResp { +} + +message UpdateGamesReq { + int64 id = 1; //id + string name = 2; //name + string icon = 3; //icon + string category = 4; //category + int64 sortOrder = 5; //sortOrder + bool isActive = 6; //isActive + int64 createdAt = 7; //createdAt + int64 updatedAt = 8; //updatedAt +} + +message UpdateGamesResp { +} + +message DelGamesReq { + int64 id = 1; //id +} + +message DelGamesResp { +} + +message GetGamesByIdReq { + int64 id = 1; //id +} + +message GetGamesByIdResp { + Games games = 1; //games +} + +message SearchGamesReq { + int64 page = 1; //page + int64 limit = 2; //limit + int64 id = 3; //id + string name = 4; //name + string icon = 5; //icon + string category = 6; //category + int64 sortOrder = 7; //sortOrder + bool isActive = 8; //isActive + int64 createdAt = 9; //createdAt + int64 updatedAt = 10; //updatedAt +} + +message SearchGamesResp { + repeated Games games = 1; //games +} + + + +// ------------------------------------ +// Rpc Func +// ------------------------------------ + +service public{ + + //-----------------------games----------------------- + rpc AddGames(AddGamesReq) returns (AddGamesResp); + rpc UpdateGames(UpdateGamesReq) returns (UpdateGamesResp); + rpc DelGames(DelGamesReq) returns (DelGamesResp); + rpc GetGamesById(GetGamesByIdReq) returns (GetGamesByIdResp); + rpc SearchGames(SearchGamesReq) returns (SearchGamesResp); + +} diff --git a/desc/rpc/player.proto b/desc/rpc/player.proto new file mode 100644 index 0000000..c8a4ee9 --- /dev/null +++ b/desc/rpc/player.proto @@ -0,0 +1,208 @@ +syntax = "proto3"; + +option go_package ="./pb"; + +package pb; + +// ------------------------------------ +// Messages +// ------------------------------------ + +//--------------------------------playerServices-------------------------------- +message PlayerServices { + int64 id = 1; //id + int64 playerId = 2; //playerId + int64 gameId = 3; //gameId + string title = 4; //title + string description = 5; //description + double price = 6; //price + string unit = 7; //unit + string rankRange = 8; //rankRange + repeated string availability = 9; //availability + double rating = 10; //rating + bool isActive = 11; //isActive + int64 createdAt = 12; //createdAt + int64 updatedAt = 13; //updatedAt +} + +message AddPlayerServicesReq { + int64 playerId = 1; //playerId + int64 gameId = 2; //gameId + string title = 3; //title + string description = 4; //description + double price = 5; //price + string unit = 6; //unit + string rankRange = 7; //rankRange + repeated string availability = 8; //availability + double rating = 9; //rating + bool isActive = 10; //isActive + int64 createdAt = 11; //createdAt + int64 updatedAt = 12; //updatedAt +} + +message AddPlayerServicesResp { +} + +message UpdatePlayerServicesReq { + int64 id = 1; //id + optional int64 playerId = 2; //playerId + optional int64 gameId = 3; //gameId + optional string title = 4; //title + optional string description = 5; //description + optional double price = 6; //price + optional string unit = 7; //unit + optional string rankRange = 8; //rankRange + repeated string availability = 9; //availability + optional double rating = 10; //rating + optional bool isActive = 11; //isActive + optional int64 createdAt = 12; //createdAt + optional int64 updatedAt = 13; //updatedAt +} + +message UpdatePlayerServicesResp { +} + +message DelPlayerServicesReq { + int64 id = 1; //id +} + +message DelPlayerServicesResp { +} + +message GetPlayerServicesByIdReq { + int64 id = 1; //id +} + +message GetPlayerServicesByIdResp { + PlayerServices playerServices = 1; //playerServices +} + +message SearchPlayerServicesReq { + int64 page = 1; //page + int64 limit = 2; //limit + int64 id = 3; //id + int64 playerId = 4; //playerId + int64 gameId = 5; //gameId + string title = 6; //title + string description = 7; //description + double price = 8; //price + string unit = 9; //unit + string rankRange = 10; //rankRange + repeated string availability = 11; //availability + double rating = 12; //rating + bool isActive = 13; //isActive + int64 createdAt = 14; //createdAt + int64 updatedAt = 15; //updatedAt +} + +message SearchPlayerServicesResp { + repeated PlayerServices playerServices = 1; //playerServices +} + +//--------------------------------players-------------------------------- +message Players { + int64 id = 1; //id + int64 userId = 2; //userId + string status = 3; //status + double rating = 4; //rating + int64 totalOrders = 5; //totalOrders + int64 completedOrders = 6; //completedOrders + int64 shopId = 7; //shopId + repeated string tags = 8; //tags + repeated int64 games = 9; //games + int64 createdAt = 10; //createdAt + int64 updatedAt = 11; //updatedAt + int64 gender = 12; //gender +} + +message AddPlayersReq { + int64 userId = 1; //userId + string status = 2; //status + double rating = 3; //rating + int64 totalOrders = 4; //totalOrders + int64 completedOrders = 5; //completedOrders + int64 shopId = 6; //shopId + repeated string tags = 7; //tags + repeated int64 games = 8; //games + int64 createdAt = 9; //createdAt + int64 updatedAt = 10; //updatedAt + int64 gender = 11; //gender +} + +message AddPlayersResp { +} + +message UpdatePlayersReq { + int64 id = 1; //id + optional int64 userId = 2; //userId + optional string status = 3; //status + optional double rating = 4; //rating + optional int64 totalOrders = 5; //totalOrders + optional int64 completedOrders = 6; //completedOrders + optional int64 shopId = 7; //shopId + repeated string tags = 8; //tags + repeated int64 games = 9; //games + optional int64 createdAt = 10; //createdAt + optional int64 updatedAt = 11; //updatedAt + optional int64 gender = 12; //gender +} + +message UpdatePlayersResp { +} + +message DelPlayersReq { + int64 id = 1; //id +} + +message DelPlayersResp { +} + +message GetPlayersByIdReq { + int64 id = 1; //id +} + +message GetPlayersByIdResp { + Players players = 1; //players +} + +message SearchPlayersReq { + int64 page = 1; //page + int64 limit = 2; //limit + int64 id = 3; //id + int64 userId = 4; //userId + string status = 5; //status + double rating = 6; //rating + int64 totalOrders = 7; //totalOrders + int64 completedOrders = 8; //completedOrders + int64 shopId = 9; //shopId + repeated string tags = 10; //tags + repeated int64 games = 11; //games + int64 createdAt = 12; //createdAt + int64 updatedAt = 13; //updatedAt + int64 gender = 14; //gender +} + +message SearchPlayersResp { + repeated Players players = 1; //players +} + + +// ------------------------------------ +// Rpc Func +// ------------------------------------ + +service playerService{ + + //-----------------------playerServices----------------------- + rpc AddPlayerServices(AddPlayerServicesReq) returns (AddPlayerServicesResp); + rpc UpdatePlayerServices(UpdatePlayerServicesReq) returns (UpdatePlayerServicesResp); + rpc DelPlayerServices(DelPlayerServicesReq) returns (DelPlayerServicesResp); + rpc GetPlayerServicesById(GetPlayerServicesByIdReq) returns (GetPlayerServicesByIdResp); + rpc SearchPlayerServices(SearchPlayerServicesReq) returns (SearchPlayerServicesResp); + //-----------------------players----------------------- + rpc AddPlayers(AddPlayersReq) returns (AddPlayersResp); + rpc UpdatePlayers(UpdatePlayersReq) returns (UpdatePlayersResp); + rpc DelPlayers(DelPlayersReq) returns (DelPlayersResp); + rpc GetPlayersById(GetPlayersByIdReq) returns (GetPlayersByIdResp); + rpc SearchPlayers(SearchPlayersReq) returns (SearchPlayersResp); +} diff --git a/desc/rpc/shop.proto b/desc/rpc/shop.proto new file mode 100644 index 0000000..d7959da --- /dev/null +++ b/desc/rpc/shop.proto @@ -0,0 +1,272 @@ +syntax = "proto3"; + +option go_package ="./pb"; + +package pb; + +// ------------------------------------ +// Messages +// ------------------------------------ + +//--------------------------------shopInvitations-------------------------------- +message ShopInvitations { + int64 id = 1; //id + int64 shopId = 2; //shopId + int64 playerId = 3; //playerId + string status = 4; //status + int64 invitedBy = 5; //invitedBy + int64 createdAt = 6; //createdAt + int64 respondedAt = 7; //respondedAt +} + +message AddShopInvitationsReq { + int64 shopId = 1; //shopId + int64 playerId = 2; //playerId + string status = 3; //status + int64 invitedBy = 4; //invitedBy + int64 createdAt = 5; //createdAt + int64 respondedAt = 6; //respondedAt +} + +message AddShopInvitationsResp { +} + +message UpdateShopInvitationsReq { + int64 id = 1; //id + int64 shopId = 2; //shopId + int64 playerId = 3; //playerId + string status = 4; //status + int64 invitedBy = 5; //invitedBy + int64 createdAt = 6; //createdAt + int64 respondedAt = 7; //respondedAt +} + +message UpdateShopInvitationsResp { +} + +message DelShopInvitationsReq { + int64 id = 1; //id +} + +message DelShopInvitationsResp { +} + +message GetShopInvitationsByIdReq { + int64 id = 1; //id +} + +message GetShopInvitationsByIdResp { + ShopInvitations shopInvitations = 1; //shopInvitations +} + +message SearchShopInvitationsReq { + int64 page = 1; //page + int64 limit = 2; //limit + int64 id = 3; //id + int64 shopId = 4; //shopId + int64 playerId = 5; //playerId + string status = 6; //status + int64 invitedBy = 7; //invitedBy + int64 createdAt = 8; //createdAt + int64 respondedAt = 9; //respondedAt +} + +message SearchShopInvitationsResp { + repeated ShopInvitations shopInvitations = 1; //shopInvitations +} + +//--------------------------------shopPlayers-------------------------------- +message ShopPlayers { + int64 shopId = 1; //shopId + int64 playerId = 2; //playerId + bool isPrimary = 3; //isPrimary + int64 joinedAt = 4; //joinedAt + int64 leftAt = 5; //leftAt +} + +message AddShopPlayersReq { + int64 shopId = 1; //shopId + int64 playerId = 2; //playerId + bool isPrimary = 3; //isPrimary + int64 joinedAt = 4; //joinedAt + int64 leftAt = 5; //leftAt +} + +message AddShopPlayersResp { +} + +message UpdateShopPlayersReq { + int64 shopId = 1; //shopId + int64 playerId = 2; //playerId + bool isPrimary = 3; //isPrimary + int64 joinedAt = 4; //joinedAt + int64 leftAt = 5; //leftAt +} + +message UpdateShopPlayersResp { +} + +message DelShopPlayersReq { + int64 id = 1; //id +} + +message DelShopPlayersResp { +} + +message GetShopPlayersByIdReq { + int64 id = 1; //id +} + +message GetShopPlayersByIdResp { + ShopPlayers shopPlayers = 1; //shopPlayers +} + +message SearchShopPlayersReq { + int64 page = 1; //page + int64 limit = 2; //limit + int64 shopId = 3; //shopId + int64 playerId = 4; //playerId + bool isPrimary = 5; //isPrimary + int64 joinedAt = 6; //joinedAt + int64 leftAt = 7; //leftAt +} + +message SearchShopPlayersResp { + repeated ShopPlayers shopPlayers = 1; //shopPlayers +} + +//--------------------------------shops-------------------------------- +message Shops { + int64 id = 1; //id + int64 ownerId = 2; //ownerId + string name = 3; //name + string banner = 4; //banner + string description = 5; //description + double rating = 6; //rating + int64 totalOrders = 7; //totalOrders + int64 playerCount = 8; //playerCount + string commissionType = 9; //commissionType + double commissionValue = 10; //commissionValue + bool allowMultiShop = 11; //allowMultiShop + bool allowIndependentOrders = 12; //allowIndependentOrders + string dispatchMode = 13; //dispatchMode + repeated string announcements = 14; //announcements + string templateConfig = 15; //templateConfig + int64 createdAt = 16; //createdAt + int64 updatedAt = 17; //updatedAt +} + +message AddShopsReq { + int64 ownerId = 1; //ownerId + string name = 2; //name + string banner = 3; //banner + string description = 4; //description + double rating = 5; //rating + int64 totalOrders = 6; //totalOrders + int64 playerCount = 7; //playerCount + string commissionType = 8; //commissionType + double commissionValue = 9; //commissionValue + bool allowMultiShop = 10; //allowMultiShop + bool allowIndependentOrders = 11; //allowIndependentOrders + string dispatchMode = 12; //dispatchMode + repeated string announcements = 13; //announcements + string templateConfig = 14; //templateConfig + int64 createdAt = 15; //createdAt + int64 updatedAt = 16; //updatedAt +} + +message AddShopsResp { +} + +message UpdateShopsReq { + int64 id = 1; //id + int64 ownerId = 2; //ownerId + string name = 3; //name + string banner = 4; //banner + string description = 5; //description + double rating = 6; //rating + int64 totalOrders = 7; //totalOrders + int64 playerCount = 8; //playerCount + string commissionType = 9; //commissionType + double commissionValue = 10; //commissionValue + bool allowMultiShop = 11; //allowMultiShop + bool allowIndependentOrders = 12; //allowIndependentOrders + string dispatchMode = 13; //dispatchMode + repeated string announcements = 14; //announcements + string templateConfig = 15; //templateConfig + int64 createdAt = 16; //createdAt + int64 updatedAt = 17; //updatedAt +} + +message UpdateShopsResp { +} + +message DelShopsReq { + int64 id = 1; //id +} + +message DelShopsResp { +} + +message GetShopsByIdReq { + int64 id = 1; //id +} + +message GetShopsByIdResp { + Shops shops = 1; //shops +} + +message SearchShopsReq { + int64 page = 1; //page + int64 limit = 2; //limit + int64 id = 3; //id + int64 ownerId = 4; //ownerId + string name = 5; //name + string banner = 6; //banner + string description = 7; //description + double rating = 8; //rating + int64 totalOrders = 9; //totalOrders + int64 playerCount = 10; //playerCount + string commissionType = 11; //commissionType + double commissionValue = 12; //commissionValue + bool allowMultiShop = 13; //allowMultiShop + bool allowIndependentOrders = 14; //allowIndependentOrders + string dispatchMode = 15; //dispatchMode + repeated string announcements = 16; //announcements + string templateConfig = 17; //templateConfig + int64 createdAt = 18; //createdAt + int64 updatedAt = 19; //updatedAt +} + +message SearchShopsResp { + repeated Shops shops = 1; //shops +} + + + +// ------------------------------------ +// Rpc Func +// ------------------------------------ + +service shopService{ + + //-----------------------shopInvitations----------------------- + rpc AddShopInvitations(AddShopInvitationsReq) returns (AddShopInvitationsResp); + rpc UpdateShopInvitations(UpdateShopInvitationsReq) returns (UpdateShopInvitationsResp); + rpc DelShopInvitations(DelShopInvitationsReq) returns (DelShopInvitationsResp); + rpc GetShopInvitationsById(GetShopInvitationsByIdReq) returns (GetShopInvitationsByIdResp); + rpc SearchShopInvitations(SearchShopInvitationsReq) returns (SearchShopInvitationsResp); + //-----------------------shopPlayers----------------------- + rpc AddShopPlayers(AddShopPlayersReq) returns (AddShopPlayersResp); + rpc UpdateShopPlayers(UpdateShopPlayersReq) returns (UpdateShopPlayersResp); + rpc DelShopPlayers(DelShopPlayersReq) returns (DelShopPlayersResp); + rpc GetShopPlayersById(GetShopPlayersByIdReq) returns (GetShopPlayersByIdResp); + rpc SearchShopPlayers(SearchShopPlayersReq) returns (SearchShopPlayersResp); + //-----------------------shops----------------------- + rpc AddShops(AddShopsReq) returns (AddShopsResp); + rpc UpdateShops(UpdateShopsReq) returns (UpdateShopsResp); + rpc DelShops(DelShopsReq) returns (DelShopsResp); + rpc GetShopsById(GetShopsByIdReq) returns (GetShopsByIdResp); + rpc SearchShops(SearchShopsReq) returns (SearchShopsResp); + +} diff --git a/desc/sql/common/update_updated_at_column.sql b/desc/sql/common/update_updated_at_column.sql new file mode 100644 index 0000000..33e7745 --- /dev/null +++ b/desc/sql/common/update_updated_at_column.sql @@ -0,0 +1,12 @@ +CREATE EXTENSION IF NOT EXISTS pg_trgm; +CREATE EXTENSION IF NOT EXISTS btree_gin; +CREATE EXTENSION IF NOT EXISTS btree_gist; +CREATE EXTENSION IF NOT EXISTS pgcrypto; + +CREATE OR REPLACE FUNCTION update_updated_at_column() +RETURNS TRIGGER AS $$ +BEGIN + NEW.updated_at = CURRENT_TIMESTAMP; +RETURN NEW; +END; +$$ language 'plpgsql'; \ No newline at end of file diff --git a/desc/sql/game/player_services.sql b/desc/sql/game/player_services.sql deleted file mode 100644 index a12012a..0000000 --- a/desc/sql/game/player_services.sql +++ /dev/null @@ -1,49 +0,0 @@ -CREATE TABLE player_services ( - id BIGINT PRIMARY KEY, - player_id BIGINT NOT NULL REFERENCES players(id), - game_id BIGINT NOT NULL, - title VARCHAR(200) NOT NULL, - description TEXT, - price DECIMAL(10,2) NOT NULL, - unit VARCHAR(20) NOT NULL, - rank_range VARCHAR(100), - availability TEXT[] DEFAULT ARRAY[]::TEXT[], - rating DECIMAL(3,2) DEFAULT 5.00, - is_active BOOLEAN DEFAULT TRUE, - created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), - updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), - - CONSTRAINT chk_price_positive CHECK (price > 0), - CONSTRAINT chk_service_rating CHECK (rating >= 0 AND rating <= 5) -); - --- 基础索引 -CREATE INDEX idx_services_player ON player_services(player_id) WHERE is_active = TRUE; -CREATE INDEX idx_services_game ON player_services(game_id) WHERE is_active = TRUE; -CREATE INDEX idx_services_price ON player_services(price); - --- 三元组索引用于服务标题模糊搜索 -CREATE INDEX idx_services_title_trgm ON player_services USING gin(title gin_trgm_ops) - WHERE is_active = TRUE; - --- 全文搜索索引 -CREATE INDEX idx_services_fulltext ON player_services USING gin( - to_tsvector('simple', title || ' ' || coalesce(description, '')) - ) WHERE is_active = TRUE; - --- 复合索引优化价格区间查询 -CREATE INDEX idx_services_game_price ON player_services(game_id, price, rating DESC) - WHERE is_active = TRUE; - --- 打手+游戏复合索引 -CREATE INDEX idx_services_player_game ON player_services(player_id, game_id) - WHERE is_active = TRUE; - --- GIN 索引优化时间段查询 -CREATE INDEX idx_services_availability ON player_services USING gin(availability) - WHERE is_active = TRUE; - -CREATE TRIGGER trigger_services_updated_at - BEFORE UPDATE ON player_services - FOR EACH ROW - EXECUTE FUNCTION update_updated_at_column(); \ No newline at end of file diff --git a/desc/sql/game/shop_invitations.sql b/desc/sql/game/shop_invitations.sql deleted file mode 100644 index 56d5463..0000000 --- a/desc/sql/game/shop_invitations.sql +++ /dev/null @@ -1,17 +0,0 @@ -CREATE TABLE shop_invitations ( - id BIGINT PRIMARY KEY, - shop_id BIGINT NOT NULL REFERENCES shops(id), - player_id BIGINT NOT NULL, - status VARCHAR(20) NOT NULL DEFAULT 'pending', - invited_by BIGINT NOT NULL, - created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), - responded_at TIMESTAMPTZ, - - CONSTRAINT chk_invitation_status CHECK (status IN ('pending', 'accepted', 'rejected', 'cancelled')), - UNIQUE(shop_id, player_id, status) WHERE status = 'pending' -); - -CREATE INDEX idx_invitations_shop ON shop_invitations(shop_id); -CREATE INDEX idx_invitations_player ON shop_invitations(player_id) WHERE status = 'pending'; -CREATE INDEX idx_invitations_player_status ON shop_invitations(player_id, status, created_at DESC); -CREATE INDEX idx_invitations_shop_status ON shop_invitations(shop_id, status, created_at DESC); \ No newline at end of file diff --git a/desc/sql/player/player_services.sql b/desc/sql/player/player_services.sql new file mode 100644 index 0000000..3d1bd6a --- /dev/null +++ b/desc/sql/player/player_services.sql @@ -0,0 +1,51 @@ +CREATE TABLE player_services +( + id BIGINT PRIMARY KEY, + player_id BIGINT NOT NULL REFERENCES players (id), + game_id BIGINT NOT NULL, + title VARCHAR(200) NOT NULL, + description TEXT, + price DECIMAL(10, 2) NOT NULL, + unit VARCHAR(20) NOT NULL, + rank_range VARCHAR(100), + availability TEXT[] DEFAULT ARRAY []::TEXT[], + rating DECIMAL(3, 2) DEFAULT 5.00, + is_active BOOLEAN DEFAULT TRUE, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + + CONSTRAINT chk_price_positive CHECK (price > 0), + CONSTRAINT chk_service_rating CHECK (rating >= 0 AND rating <= 5) +); + +-- 基础索引 +CREATE INDEX idx_services_player ON player_services (player_id) WHERE is_active = TRUE; +CREATE INDEX idx_services_game ON player_services (game_id) WHERE is_active = TRUE; +CREATE INDEX idx_services_price ON player_services (price); + +-- 三元组索引用于服务标题模糊搜索 +CREATE INDEX idx_services_title_trgm ON player_services USING gin (title gin_trgm_ops) + WHERE is_active = TRUE; + +-- 全文搜索索引 +CREATE INDEX idx_services_fulltext ON player_services USING gin ( + to_tsvector('simple', title || ' ' || coalesce(description, '')) + ) WHERE is_active = TRUE; + +-- 复合索引优化价格区间查询 +CREATE INDEX idx_services_game_price ON player_services (game_id, price, rating DESC) + WHERE is_active = TRUE; + +-- 打手+游戏复合索引 +CREATE INDEX idx_services_player_game ON player_services (player_id, game_id) + WHERE is_active = TRUE; + +-- GIN 索引优化时间段查询 +CREATE INDEX idx_services_availability ON player_services USING gin (availability) + WHERE is_active = TRUE; + +CREATE TRIGGER trigger_services_updated_at + BEFORE UPDATE + ON player_services + FOR EACH ROW +EXECUTE FUNCTION update_updated_at_column(); \ No newline at end of file diff --git a/desc/sql/game/players.sql b/desc/sql/player/players.sql similarity index 85% rename from desc/sql/game/players.sql rename to desc/sql/player/players.sql index b9e0603..308ddfa 100644 --- a/desc/sql/game/players.sql +++ b/desc/sql/player/players.sql @@ -1,7 +1,5 @@ CREATE TABLE players ( - id BIGINT PRIMARY KEY, - CREATE TABLE players ( id BIGINT PRIMARY KEY, user_id BIGINT NOT NULL UNIQUE, status VARCHAR(20) NOT NULL DEFAULT 'offline', @@ -11,12 +9,13 @@ CREATE TABLE players -- [注意] 此字段为冗余缓存,通过消息队列与 shop_players 表保持一致 shop_id BIGINT, - + gender bool default 1 not null , tags TEXT[] DEFAULT ARRAY[]::TEXT[], games BIGINT[] DEFAULT ARRAY[]::BIGINT[], created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); + -- 基础索引 CREATE INDEX idx_players_user ON players (user_id); CREATE INDEX idx_players_shop ON players (shop_id) WHERE shop_id IS NOT NULL; @@ -33,8 +32,8 @@ CREATE INDEX idx_players_tags_gin ON players USING gin(tags); -- 店铺+状态复合索引 CREATE INDEX idx_players_shop_status ON players (shop_id, status, rating DESC) WHERE shop_id IS NOT NULL; --- CREATE TRIGGER trigger_players_updated_at --- BEFORE UPDATE --- ON players --- FOR EACH ROW --- EXECUTE FUNCTION update_updated_at_column(); +CREATE TRIGGER trigger_players_updated_at + BEFORE UPDATE + ON players + FOR EACH ROW + EXECUTE FUNCTION update_updated_at_column(); diff --git a/desc/sql/game/shop.sql b/desc/sql/shop/shop.sql similarity index 100% rename from desc/sql/game/shop.sql rename to desc/sql/shop/shop.sql diff --git a/desc/sql/shop/shop_invitations.sql b/desc/sql/shop/shop_invitations.sql new file mode 100644 index 0000000..638b491 --- /dev/null +++ b/desc/sql/shop/shop_invitations.sql @@ -0,0 +1,20 @@ +CREATE TABLE shop_invitations +( + id BIGINT PRIMARY KEY, + shop_id BIGINT NOT NULL REFERENCES shops (id), + player_id BIGINT NOT NULL, + status VARCHAR(20) NOT NULL DEFAULT 'pending', + invited_by BIGINT NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + responded_at TIMESTAMPTZ, + + CONSTRAINT chk_invitation_status CHECK (status IN ('pending', 'accepted', 'rejected', 'cancelled')) +); + +CREATE UNIQUE INDEX idx_unique_pending_invitation + ON shop_invitations (shop_id, player_id) + WHERE status = 'pending'; +CREATE INDEX idx_invitations_shop ON shop_invitations (shop_id); +CREATE INDEX idx_invitations_player ON shop_invitations (player_id) WHERE status = 'pending'; +CREATE INDEX idx_invitations_player_status ON shop_invitations (player_id, status, created_at DESC); +CREATE INDEX idx_invitations_shop_status ON shop_invitations (shop_id, status, created_at DESC); \ No newline at end of file diff --git a/desc/sql/game/shop_players.sql b/desc/sql/shop/shop_players.sql similarity index 88% rename from desc/sql/game/shop_players.sql rename to desc/sql/shop/shop_players.sql index 78ccc3a..23c7988 100644 --- a/desc/sql/game/shop_players.sql +++ b/desc/sql/shop/shop_players.sql @@ -3,9 +3,8 @@ CREATE TABLE shop_players shop_id BIGINT NOT NULL REFERENCES shops (id), player_id BIGINT NOT NULL, - -- [新增] 标记是否为主店铺。用于个人主页展示和 players.shop_id 缓存源 + -- 标记是否为主店铺。用于个人主页展示和 players.shop_id 缓存源 is_primary BOOLEAN DEFAULT FALSE, - joined_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), left_at TIMESTAMPTZ, -- 软删除,表示已离职 diff --git a/docs/ENT_EDGES_GUIDE.md b/docs/ENT_EDGES_GUIDE.md new file mode 100644 index 0000000..e4373ec --- /dev/null +++ b/docs/ENT_EDGES_GUIDE.md @@ -0,0 +1,97 @@ +# Ent Edges 使用说明(game 模块) + +本文说明 `app/game/rpc/internal/models/schema` 下 Edges 的定义方式、生成方式,以及在业务代码中如何使用。 + +## 1. 当前 game 模块关系设计 + +基于 `desc/sql/game` 的表结构,当前主要关系: + +- `players` 1:N `player_services` + - `player_services.player_id -> players.id` +- `shops` 1:N `shop_players` + - `shop_players.shop_id -> shops.id` +- `players` 1:N `shop_players`(逻辑关联) + - `shop_players.player_id -> players.id` +- `shops` 1:N `shop_invitations` + - `shop_invitations.shop_id -> shops.id` +- `players` 1:N `shop_invitations`(收到邀请) + - `shop_invitations.player_id -> players.id` +- `players` 1:N `shop_invitations`(发起邀请) + - `shop_invitations.invited_by -> players.id` + +## 2. Edge 定义规则 + +### 2.1 在子表(持有外键字段)上定义 `edge.From(...).Field(...)` + +示例(`player_services`): + +- `edge.From("player", Players.Type).Ref("services").Field("player_id").Required().Unique()` + +含义: + +- 当前实体(`player_services`)通过 `player_id` 指向一个 `players` +- `Unique()` 表示每条 `player_services` 记录只对应一个 player(典型 N:1 子侧定义) + +### 2.2 在父表定义反向 `edge.To(...)` + +示例(`players`): + +- `edge.To("services", PlayerServices.Type)` + +含义: + +- 一个 player 可以有多条 service(1:N) + +## 3. 代码生成 + +在项目根目录执行: + +```bash +go run entgo.io/ent/cmd/ent generate ./app/game/rpc/internal/models/schema +``` + +如果你后续为 schema 增加了注解或字段,重复执行同一命令即可刷新生成代码。 + +## 4. 业务查询示例 + +> 以下为典型写法,具体包路径以你项目实际生成结果为准。 + +### 4.1 查询某个玩家及其所有服务 + +```go +player, err := client.Players. + Query(). + Where(players.ID(playerID)). + WithServices(). + Only(ctx) +``` + +### 4.2 查询某个店铺及其成员关系记录 + +```go +shop, err := client.Shops. + Query(). + Where(shops.ID(shopID)). + WithMemberships(). + Only(ctx) +``` + +### 4.3 查询某玩家收到的邀请 + +```go +invitations, err := client.Players. + QueryReceivedInvitations(player). + All(ctx) +``` + +## 5. 常见坑 + +- `edge.From(...).Field(...)` 的字段名必须是当前 schema 里真实存在的字段。 +- `Ref("...")` 名称要和对端 `edge.To("...")` 保持一致。 +- 同一实体指向同一目标实体的多条边(例如邀请的 `player` 和 `inviter`)必须使用不同 edge 名称,避免代码生成冲突。 +- 如果 SQL 没有声明外键但你定义了带 `Field(...)` 的 edge,迁移时可能会生成外键约束;若不想生成,请保持和 SQL 一致或在迁移层显式控制。 + +## 6. 当前文件位置 + +- Schema 目录:`app/game/rpc/internal/models/schema` +- SQL 来源:`desc/sql/game` diff --git a/go.mod b/go.mod index 0c418f8..88e5826 100644 --- a/go.mod +++ b/go.mod @@ -23,6 +23,25 @@ require ( filippo.io/edwards25519 v1.1.1 // indirect github.com/agext/levenshtein v1.2.3 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect + github.com/aws/aws-sdk-go-v2 v1.41.2 // indirect + github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.5 // indirect + github.com/aws/aws-sdk-go-v2/config v1.32.10 // indirect + github.com/aws/aws-sdk-go-v2/credentials v1.19.10 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.18 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.18 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.18 // indirect + github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect + github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.18 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.5 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.10 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.18 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.18 // indirect + github.com/aws/aws-sdk-go-v2/service/s3 v1.96.2 // indirect + github.com/aws/aws-sdk-go-v2/service/signin v1.0.6 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.30.11 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.15 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.41.7 // indirect + github.com/aws/smithy-go v1.24.1 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bmatcuk/doublestar v1.3.4 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect @@ -74,6 +93,7 @@ require ( github.com/prometheus/common v0.66.1 // indirect github.com/prometheus/procfs v0.16.1 // indirect github.com/segmentio/kafka-go v0.4.47 // indirect + github.com/shopspring/decimal v1.4.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/zclconf/go-cty v1.14.4 // indirect github.com/zclconf/go-cty-yaml v1.1.0 // indirect diff --git a/go.sum b/go.sum index 7a39949..4404b19 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,44 @@ github.com/alicebob/miniredis/v2 v2.36.1 h1:Dvc5oAnNOr7BIfPn7tF269U8DvRW1dBG2D5n github.com/alicebob/miniredis/v2 v2.36.1/go.mod h1:TcL7YfarKPGDAthEtl5NBeHZfeUQj6OXMm/+iu5cLMM= github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= +github.com/aws/aws-sdk-go-v2 v1.41.2 h1:LuT2rzqNQsauaGkPK/7813XxcZ3o3yePY0Iy891T2ls= +github.com/aws/aws-sdk-go-v2 v1.41.2/go.mod h1:IvvlAZQXvTXznUPfRVfryiG1fbzE2NGK6m9u39YQ+S4= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.5 h1:zWFmPmgw4sveAYi1mRqG+E/g0461cJ5M4bJ8/nc6d3Q= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.5/go.mod h1:nVUlMLVV8ycXSb7mSkcNu9e3v/1TJq2RTlrPwhYWr5c= +github.com/aws/aws-sdk-go-v2/config v1.32.10 h1:9DMthfO6XWZYLfzZglAgW5Fyou2nRI5CuV44sTedKBI= +github.com/aws/aws-sdk-go-v2/config v1.32.10/go.mod h1:2rUIOnA2JaiqYmSKYmRJlcMWy6qTj1vuRFscppSBMcw= +github.com/aws/aws-sdk-go-v2/credentials v1.19.10 h1:EEhmEUFCE1Yhl7vDhNOI5OCL/iKMdkkYFTRpZXNw7m8= +github.com/aws/aws-sdk-go-v2/credentials v1.19.10/go.mod h1:RnnlFCAlxQCkN2Q379B67USkBMu1PipEEiibzYN5UTE= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.18 h1:Ii4s+Sq3yDfaMLpjrJsqD6SmG/Wq/P5L/hw2qa78UAY= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.18/go.mod h1:6x81qnY++ovptLE6nWQeWrpXxbnlIex+4H4eYYGcqfc= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.18 h1:F43zk1vemYIqPAwhjTjYIz0irU2EY7sOb/F5eJ3HuyM= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.18/go.mod h1:w1jdlZXrGKaJcNoL+Nnrj+k5wlpGXqnNrKoP22HvAug= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.18 h1:xCeWVjj0ki0l3nruoyP2slHsGArMxeiiaoPN5QZH6YQ= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.18/go.mod h1:r/eLGuGCBw6l36ZRWiw6PaZwPXb6YOj+i/7MizNl5/k= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 h1:WKuaxf++XKWlHWu9ECbMlha8WOEGm0OUEZqm4K/Gcfk= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4/go.mod h1:ZWy7j6v1vWGmPReu0iSGvRiise4YI5SkR3OHKTZ6Wuc= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.18 h1:eZioDaZGJ0tMM4gzmkNIO2aAoQd+je7Ug7TkvAzlmkU= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.18/go.mod h1:CCXwUKAJdoWr6/NcxZ+zsiPr6oH/Q5aTooRGYieAyj4= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.5 h1:CeY9LUdur+Dxoeldqoun6y4WtJ3RQtzk0JMP2gfUay0= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.5/go.mod h1:AZLZf2fMaahW5s/wMRciu1sYbdsikT/UHwbUjOdEVTc= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.10 h1:fJvQ5mIBVfKtiyx0AHY6HeWcRX5LGANLpq8SVR+Uazs= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.10/go.mod h1:Kzm5e6OmNH8VMkgK9t+ry5jEih4Y8whqs+1hrkxim1I= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.18 h1:LTRCYFlnnKFlKsyIQxKhJuDuA3ZkrDQMRYm6rXiHlLY= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.18/go.mod h1:XhwkgGG6bHSd00nO/mexWTcTjgd6PjuvWQMqSn2UaEk= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.18 h1:/A/xDuZAVD2BpsS2fftFRo/NoEKQJ8YTnJDEHBy2Gtg= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.18/go.mod h1:hWe9b4f+djUQGmyiGEeOnZv69dtMSgpDRIvNMvuvzvY= +github.com/aws/aws-sdk-go-v2/service/s3 v1.96.2 h1:M1A9AjcFwlxTLuf0Faj88L8Iqw0n/AJHjpZTQzMMsSc= +github.com/aws/aws-sdk-go-v2/service/s3 v1.96.2/go.mod h1:KsdTV6Q9WKUZm2mNJnUFmIoXfZux91M3sr/a4REX8e0= +github.com/aws/aws-sdk-go-v2/service/signin v1.0.6 h1:MzORe+J94I+hYu2a6XmV5yC9huoTv8NRcCrUNedDypQ= +github.com/aws/aws-sdk-go-v2/service/signin v1.0.6/go.mod h1:hXzcHLARD7GeWnifd8j9RWqtfIgxj4/cAtIVIK7hg8g= +github.com/aws/aws-sdk-go-v2/service/sso v1.30.11 h1:7oGD8KPfBOJGXiCoRKrrrQkbvCp8N++u36hrLMPey6o= +github.com/aws/aws-sdk-go-v2/service/sso v1.30.11/go.mod h1:0DO9B5EUJQlIDif+XJRWCljZRKsAFKh3gpFz7UnDtOo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.15 h1:edCcNp9eGIUDUCrzoCu1jWAXLGFIizeqkdkKgRlJwWc= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.15/go.mod h1:lyRQKED9xWfgkYC/wmmYfv7iVIM68Z5OQ88ZdcV1QbU= +github.com/aws/aws-sdk-go-v2/service/sts v1.41.7 h1:NITQpgo9A5NrDZ57uOWj+abvXSb83BbyggcUBVksN7c= +github.com/aws/aws-sdk-go-v2/service/sts v1.41.7/go.mod h1:sks5UWBhEuWYDPdwlnRFn1w7xWdH29Jcpe+/PJQefEs= +github.com/aws/smithy-go v1.24.1 h1:VbyeNfmYkWoxMVpGUAbQumkODcYmfMRfZ8yQiH30SK0= +github.com/aws/smithy-go v1.24.1/go.mod h1:LEj2LM3rBRQJxPZTB4KuzZkaZYnZPnvgIhb4pu07mx0= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -214,6 +252,8 @@ github.com/segmentio/kafka-go v0.4.47 h1:IqziR4pA3vrZq7YdRxaT3w1/5fvIH5qpCwstUan github.com/segmentio/kafka-go v0.4.47/go.mod h1:HjF6XbOKh0Pjlkr5GVZxt6CsjjwnmhVOfURM5KMd8qg= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= +github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k= +github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=