Refactor: Remove deprecated gRPC service files and implement new API structure
- Deleted old gRPC service definitions in `game_grpc.pb.go` and `public.go`. - Added new API server implementations for objectstory, player, and shop services. - Introduced configuration files for new APIs in `etc/*.yaml`. - Created main entry points for each service in `objectstory.go`, `player.go`, and `shop.go`. - Removed unused user update handler and user API files. - Added utility functions for context management and HTTP header parsing. - Introduced PostgreSQL backup configuration in `backup/postgreSql.yaml`.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
Name: pb.rpc
|
||||
ListenOn: 0.0.0.0:8080
|
||||
|
||||
|
||||
Prometheus:
|
||||
Host: 0.0.0.0
|
||||
Port: 4001
|
||||
Path: /metrics
|
||||
|
||||
# tcd:
|
||||
# Hosts:
|
||||
# - 127.0.0.1:2379
|
||||
# Key: pb.rpc
|
||||
|
||||
# Target: k8s://juwan/<service name>.<namespace>:8080
|
||||
|
||||
|
||||
SnowflakeRpcConf:
|
||||
Target: k8s://juwan/snowflake-svc:8080
|
||||
|
||||
|
||||
DB:
|
||||
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-ro.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
|
||||
|
||||
CacheConf:
|
||||
- Host: "${REDIS_M_HOST}"
|
||||
Type: node
|
||||
Pass: "${REDIS_PASSWORD}"
|
||||
User: "default"
|
||||
- Host: "${REDIS_S_HOST}"
|
||||
Type: node
|
||||
Pass: "${REDIS_PASSWORD}"
|
||||
User: "default"
|
||||
|
||||
Log:
|
||||
Level: info
|
||||
@@ -0,0 +1,17 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
zrpc.RpcServerConf
|
||||
|
||||
SnowflakeRpcConf zrpc.RpcClientConf
|
||||
DB struct {
|
||||
Master string
|
||||
Slaves string
|
||||
}
|
||||
CacheConf cache.CacheConf
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddOrderStateLogsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAddOrderStateLogsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddOrderStateLogsLogic {
|
||||
return &AddOrderStateLogsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------orderStateLogs-----------------------
|
||||
func (l *AddOrderStateLogsLogic) AddOrderStateLogs(in *pb.AddOrderStateLogsReq) (*pb.AddOrderStateLogsResp, error) {
|
||||
if in == nil {
|
||||
return nil, errors.New("order state log is required")
|
||||
}
|
||||
|
||||
builder := l.svcCtx.OrderModelsRW.OrderStateLogs.Create().
|
||||
SetID(in.Id).
|
||||
SetOrderID(in.OrderId).
|
||||
SetToStatus(in.ToStatus).
|
||||
SetAction(in.Action).
|
||||
SetActorID(in.ActorId).
|
||||
SetActorRole(in.ActorRole)
|
||||
|
||||
if in.FromStatus != nil {
|
||||
builder = builder.SetFromStatus(*in.FromStatus)
|
||||
}
|
||||
if in.Metadata != nil {
|
||||
metadata, err := parseJSONMap(*in.Metadata)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder = builder.SetMetadata(metadata)
|
||||
}
|
||||
if in.CreatedAt != nil {
|
||||
builder = builder.SetCreatedAt(time.Unix(*in.CreatedAt, 0))
|
||||
}
|
||||
|
||||
if _, err := builder.Save(l.ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.AddOrderStateLogsResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddOrdersLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAddOrdersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddOrdersLogic {
|
||||
return &AddOrdersLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------orders-----------------------
|
||||
func (l *AddOrdersLogic) AddOrders(in *pb.AddOrdersReq) (*pb.AddOrdersResp, error) {
|
||||
orderID := in.Id
|
||||
if orderID <= 0 {
|
||||
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
orderID = idResp.Id
|
||||
}
|
||||
|
||||
totalPrice, err := parseDecimal(in.GetTotalPrice())
|
||||
if err != nil || totalPrice.Cmp(decimal.Zero) <= 0 {
|
||||
return nil, errors.New("invalid total price")
|
||||
}
|
||||
|
||||
serviceSnapshot, err := parseJSONMap(in.GetServiceSnapshot())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
creator := l.svcCtx.OrderModelsRW.Orders.Create().
|
||||
SetID(orderID).
|
||||
SetConsumerID(in.ConsumerId).
|
||||
SetConsumerName(in.ConsumerName).
|
||||
SetPlayerID(in.PlayerId).
|
||||
SetPlayerName(in.PlayerName).
|
||||
SetServiceSnapshot(serviceSnapshot).
|
||||
SetTotalPrice(totalPrice)
|
||||
|
||||
if in.ShopId != nil {
|
||||
creator = creator.SetShopID(*in.ShopId)
|
||||
}
|
||||
if in.ShopName != nil {
|
||||
creator = creator.SetShopName(*in.ShopName)
|
||||
}
|
||||
if in.Status != nil && *in.Status != "" {
|
||||
creator = creator.SetStatus(*in.Status)
|
||||
}
|
||||
if in.Note != nil {
|
||||
creator = creator.SetNote(*in.Note)
|
||||
}
|
||||
if in.Version != nil {
|
||||
creator = creator.SetVersion(int(*in.Version))
|
||||
}
|
||||
if in.TimeoutJobId != nil {
|
||||
creator = creator.SetTimeoutJobID(*in.TimeoutJobId)
|
||||
}
|
||||
if in.SearchText != nil {
|
||||
creator = creator.SetSearchText(*in.SearchText)
|
||||
}
|
||||
if createdAt := unixPtr(in.CreatedAt); createdAt != nil {
|
||||
creator = creator.SetCreatedAt(*createdAt)
|
||||
}
|
||||
if acceptedAt := unixPtr(in.AcceptedAt); acceptedAt != nil {
|
||||
creator = creator.SetAcceptedAt(*acceptedAt)
|
||||
}
|
||||
if closedAt := unixPtr(in.ClosedAt); closedAt != nil {
|
||||
creator = creator.SetClosedAt(*closedAt)
|
||||
}
|
||||
if completedAt := unixPtr(in.CompletedAt); completedAt != nil {
|
||||
creator = creator.SetCompletedAt(*completedAt)
|
||||
}
|
||||
if cancelledAt := unixPtr(in.CancelledAt); cancelledAt != nil {
|
||||
creator = creator.SetCancelledAt(*cancelledAt)
|
||||
}
|
||||
if updatedAt := unixPtr(in.UpdatedAt); updatedAt != nil {
|
||||
creator = creator.SetUpdatedAt(*updatedAt)
|
||||
} else {
|
||||
creator = creator.SetUpdatedAt(time.Now())
|
||||
}
|
||||
|
||||
if _, err := creator.Save(l.ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.AddOrdersResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"juwan-backend/app/order/rpc/internal/models"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
)
|
||||
|
||||
func parseDecimal(v string) (decimal.Decimal, error) {
|
||||
if v == "" {
|
||||
return decimal.Zero, nil
|
||||
}
|
||||
d, err := decimal.NewFromString(v)
|
||||
if err != nil {
|
||||
return decimal.Zero, errors.New("invalid decimal value")
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func parseJSONMap(v string) (map[string]any, error) {
|
||||
if v == "" {
|
||||
return map[string]any{}, nil
|
||||
}
|
||||
var result map[string]any
|
||||
if err := json.Unmarshal([]byte(v), &result); err != nil {
|
||||
return nil, errors.New("invalid json value")
|
||||
}
|
||||
if result == nil {
|
||||
return map[string]any{}, nil
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func unixPtr(v *int64) *time.Time {
|
||||
if v == nil || *v <= 0 {
|
||||
return nil
|
||||
}
|
||||
t := time.Unix(*v, 0)
|
||||
return &t
|
||||
}
|
||||
|
||||
func toPBOrder(item *models.Orders) *pb.Orders {
|
||||
serviceSnapshot := "{}"
|
||||
if b, err := json.Marshal(item.ServiceSnapshot); err == nil {
|
||||
serviceSnapshot = string(b)
|
||||
}
|
||||
|
||||
result := &pb.Orders{
|
||||
Id: item.ID,
|
||||
ConsumerId: item.ConsumerID,
|
||||
ConsumerName: item.ConsumerName,
|
||||
PlayerId: item.PlayerID,
|
||||
PlayerName: item.PlayerName,
|
||||
ServiceSnapshot: serviceSnapshot,
|
||||
Status: item.Status,
|
||||
TotalPrice: item.TotalPrice.String(),
|
||||
Version: int64(item.Version),
|
||||
CreatedAt: item.CreatedAt.Unix(),
|
||||
UpdatedAt: item.UpdatedAt.Unix(),
|
||||
}
|
||||
|
||||
if item.ShopID != nil {
|
||||
result.ShopId = item.ShopID
|
||||
}
|
||||
if item.ShopName != nil {
|
||||
result.ShopName = item.ShopName
|
||||
}
|
||||
if item.Note != nil {
|
||||
result.Note = item.Note
|
||||
}
|
||||
if item.TimeoutJobID != nil {
|
||||
result.TimeoutJobId = item.TimeoutJobID
|
||||
}
|
||||
if item.SearchText != nil {
|
||||
result.SearchText = *item.SearchText
|
||||
}
|
||||
if item.AcceptedAt != nil {
|
||||
t := item.AcceptedAt.Unix()
|
||||
result.AcceptedAt = &t
|
||||
}
|
||||
if item.ClosedAt != nil {
|
||||
t := item.ClosedAt.Unix()
|
||||
result.ClosedAt = &t
|
||||
}
|
||||
if item.CompletedAt != nil {
|
||||
t := item.CompletedAt.Unix()
|
||||
result.CompletedAt = &t
|
||||
}
|
||||
if item.CancelledAt != nil {
|
||||
t := item.CancelledAt.Unix()
|
||||
result.CancelledAt = &t
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func toPBOrderStateLog(item *models.OrderStateLogs) *pb.OrderStateLogs {
|
||||
result := &pb.OrderStateLogs{
|
||||
Id: item.ID,
|
||||
OrderId: item.OrderID,
|
||||
ToStatus: item.ToStatus,
|
||||
Action: item.Action,
|
||||
ActorId: item.ActorID,
|
||||
ActorRole: item.ActorRole,
|
||||
CreatedAt: item.CreatedAt.Unix(),
|
||||
}
|
||||
|
||||
if item.FromStatus != nil {
|
||||
result.FromStatus = item.FromStatus
|
||||
}
|
||||
if item.Metadata != nil {
|
||||
if b, err := json.Marshal(item.Metadata); err == nil {
|
||||
metadata := string(b)
|
||||
result.Metadata = &metadata
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/models"
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DelOrderStateLogsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDelOrderStateLogsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelOrderStateLogsLogic {
|
||||
return &DelOrderStateLogsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DelOrderStateLogsLogic) DelOrderStateLogs(in *pb.DelOrderStateLogsReq) (*pb.DelOrderStateLogsResp, error) {
|
||||
if err := l.svcCtx.OrderModelsRW.OrderStateLogs.DeleteOneID(in.Id).Exec(l.ctx); err != nil {
|
||||
if models.IsNotFound(err) {
|
||||
return nil, errors.New("order state log not found")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.DelOrderStateLogsResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DelOrdersLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDelOrdersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelOrdersLogic {
|
||||
return &DelOrdersLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DelOrdersLogic) DelOrders(in *pb.DelOrdersReq) (*pb.DelOrdersResp, error) {
|
||||
if err := l.svcCtx.OrderModelsRW.Orders.DeleteOneID(in.Id).Exec(l.ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.DelOrdersResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/internal/models/orderstatelogs"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetOrderStateLogsByIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetOrderStateLogsByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderStateLogsByIdLogic {
|
||||
return &GetOrderStateLogsByIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetOrderStateLogsByIdLogic) GetOrderStateLogsById(in *pb.GetOrderStateLogsByIdReq) (*pb.GetOrderStateLogsByIdResp, error) {
|
||||
item, err := l.svcCtx.OrderModelsRO.OrderStateLogs.Query().
|
||||
Where(orderstatelogs.IDEQ(in.Id)).
|
||||
Only(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.GetOrderStateLogsByIdResp{OrderStateLogs: toPBOrderStateLog(item)}, nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/models/orders"
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetOrdersByIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetOrdersByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrdersByIdLogic {
|
||||
return &GetOrdersByIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetOrdersByIdLogic) GetOrdersById(in *pb.GetOrdersByIdReq) (*pb.GetOrdersByIdResp, error) {
|
||||
item, err := l.svcCtx.OrderModelsRO.Orders.Query().Where(orders.IDEQ(in.Id)).First(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.GetOrdersByIdResp{Orders: toPBOrder(item)}, nil
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/models/orderstatelogs"
|
||||
"juwan-backend/app/order/rpc/internal/models/predicate"
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SearchOrderStateLogsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSearchOrderStateLogsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchOrderStateLogsLogic {
|
||||
return &SearchOrderStateLogsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SearchOrderStateLogsLogic) SearchOrderStateLogs(in *pb.SearchOrderStateLogsReq) (*pb.SearchOrderStateLogsResp, error) {
|
||||
if in.Limit <= 0 {
|
||||
in.Limit = 20
|
||||
}
|
||||
if in.Limit > 1000 {
|
||||
return nil, errors.New("limit too large")
|
||||
}
|
||||
|
||||
preds := make([]predicate.OrderStateLogs, 0, 8)
|
||||
if in.Id != nil {
|
||||
preds = append(preds, orderstatelogs.IDEQ(*in.Id))
|
||||
}
|
||||
if in.OrderId != nil {
|
||||
preds = append(preds, orderstatelogs.OrderIDEQ(*in.OrderId))
|
||||
}
|
||||
if in.FromStatus != nil && *in.FromStatus != "" {
|
||||
preds = append(preds, orderstatelogs.FromStatusEQ(*in.FromStatus))
|
||||
}
|
||||
if in.ToStatus != nil && *in.ToStatus != "" {
|
||||
preds = append(preds, orderstatelogs.ToStatusEQ(*in.ToStatus))
|
||||
}
|
||||
if in.Action != nil && *in.Action != "" {
|
||||
preds = append(preds, orderstatelogs.ActionContainsFold(*in.Action))
|
||||
}
|
||||
if in.ActorId != nil {
|
||||
preds = append(preds, orderstatelogs.ActorIDEQ(*in.ActorId))
|
||||
}
|
||||
if in.ActorRole != nil && *in.ActorRole != "" {
|
||||
preds = append(preds, orderstatelogs.ActorRoleContainsFold(*in.ActorRole))
|
||||
}
|
||||
if in.CreatedAt != nil && *in.CreatedAt > 0 {
|
||||
preds = append(preds, orderstatelogs.CreatedAtGTE(time.Unix(*in.CreatedAt, 0)))
|
||||
}
|
||||
|
||||
query := l.svcCtx.OrderModelsRO.OrderStateLogs.Query()
|
||||
if len(preds) > 0 {
|
||||
query = query.Where(orderstatelogs.And(preds...))
|
||||
}
|
||||
|
||||
items, err := query.Offset(int(in.Page * in.Limit)).Limit(int(in.Limit)).All(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]*pb.OrderStateLogs, 0, len(items))
|
||||
for _, item := range items {
|
||||
result = append(result, toPBOrderStateLog(item))
|
||||
}
|
||||
|
||||
return &pb.SearchOrderStateLogsResp{OrderStateLogs: result}, nil
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/models/orders"
|
||||
"juwan-backend/app/order/rpc/internal/models/predicate"
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SearchOrdersLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSearchOrdersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchOrdersLogic {
|
||||
return &SearchOrdersLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SearchOrdersLogic) SearchOrders(in *pb.SearchOrdersReq) (*pb.SearchOrdersResp, error) {
|
||||
if in.Limit <= 0 {
|
||||
in.Limit = 20
|
||||
}
|
||||
if in.Limit > 1000 {
|
||||
return nil, errors.New("limit too large")
|
||||
}
|
||||
|
||||
preds := make([]predicate.Orders, 0, 20)
|
||||
if in.Id != nil {
|
||||
preds = append(preds, orders.IDEQ(*in.Id))
|
||||
}
|
||||
if in.ConsumerId != nil {
|
||||
preds = append(preds, orders.ConsumerIDEQ(*in.ConsumerId))
|
||||
}
|
||||
if in.ConsumerName != nil && *in.ConsumerName != "" {
|
||||
preds = append(preds, orders.ConsumerNameContainsFold(*in.ConsumerName))
|
||||
}
|
||||
if in.PlayerId != nil {
|
||||
preds = append(preds, orders.PlayerIDEQ(*in.PlayerId))
|
||||
}
|
||||
if in.PlayerName != nil && *in.PlayerName != "" {
|
||||
preds = append(preds, orders.PlayerNameContainsFold(*in.PlayerName))
|
||||
}
|
||||
if in.ShopId != nil {
|
||||
preds = append(preds, orders.ShopIDEQ(*in.ShopId))
|
||||
}
|
||||
if in.ShopName != nil && *in.ShopName != "" {
|
||||
preds = append(preds, orders.ShopNameContainsFold(*in.ShopName))
|
||||
}
|
||||
if in.Status != nil && *in.Status != "" {
|
||||
preds = append(preds, orders.StatusEQ(*in.Status))
|
||||
}
|
||||
if in.TotalPrice != nil && *in.TotalPrice != "" {
|
||||
price, err := parseDecimal(*in.TotalPrice)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
preds = append(preds, orders.TotalPriceEQ(price))
|
||||
}
|
||||
if in.Note != nil && *in.Note != "" {
|
||||
preds = append(preds, orders.NoteContainsFold(*in.Note))
|
||||
}
|
||||
if in.Version != nil {
|
||||
preds = append(preds, orders.VersionEQ(int(*in.Version)))
|
||||
}
|
||||
if in.TimeoutJobId != nil && *in.TimeoutJobId != "" {
|
||||
preds = append(preds, orders.TimeoutJobIDEQ(*in.TimeoutJobId))
|
||||
}
|
||||
if in.SearchText != nil && *in.SearchText != "" {
|
||||
preds = append(preds, orders.SearchTextContainsFold(*in.SearchText))
|
||||
}
|
||||
if in.CreatedAt != nil && *in.CreatedAt > 0 {
|
||||
preds = append(preds, orders.CreatedAtGTE(time.Unix(*in.CreatedAt, 0)))
|
||||
}
|
||||
if in.AcceptedAt != nil && *in.AcceptedAt > 0 {
|
||||
preds = append(preds, orders.AcceptedAtGTE(time.Unix(*in.AcceptedAt, 0)))
|
||||
}
|
||||
if in.ClosedAt != nil && *in.ClosedAt > 0 {
|
||||
preds = append(preds, orders.ClosedAtGTE(time.Unix(*in.ClosedAt, 0)))
|
||||
}
|
||||
if in.CompletedAt != nil && *in.CompletedAt > 0 {
|
||||
preds = append(preds, orders.CompletedAtGTE(time.Unix(*in.CompletedAt, 0)))
|
||||
}
|
||||
if in.CancelledAt != nil && *in.CancelledAt > 0 {
|
||||
preds = append(preds, orders.CancelledAtGTE(time.Unix(*in.CancelledAt, 0)))
|
||||
}
|
||||
if in.UpdatedAt != nil && *in.UpdatedAt > 0 {
|
||||
preds = append(preds, orders.UpdatedAtGTE(time.Unix(*in.UpdatedAt, 0)))
|
||||
}
|
||||
|
||||
query := l.svcCtx.OrderModelsRO.Orders.Query()
|
||||
if len(preds) > 0 {
|
||||
query = query.Where(orders.And(preds...))
|
||||
}
|
||||
|
||||
items, err := query.Offset(int(in.Page * in.Limit)).Limit(int(in.Limit)).All(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]*pb.Orders, 0, len(items))
|
||||
for _, item := range items {
|
||||
result = append(result, toPBOrder(item))
|
||||
}
|
||||
|
||||
return &pb.SearchOrdersResp{Orders: result}, nil
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/models"
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateOrderStateLogsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateOrderStateLogsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateOrderStateLogsLogic {
|
||||
return &UpdateOrderStateLogsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateOrderStateLogsLogic) UpdateOrderStateLogs(in *pb.UpdateOrderStateLogsReq) (*pb.UpdateOrderStateLogsResp, error) {
|
||||
if in == nil {
|
||||
return nil, errors.New("order state log is required")
|
||||
}
|
||||
|
||||
builder := l.svcCtx.OrderModelsRW.OrderStateLogs.UpdateOneID(in.Id)
|
||||
|
||||
if in.OrderId != nil {
|
||||
builder = builder.SetOrderID(*in.OrderId)
|
||||
}
|
||||
if in.FromStatus != nil {
|
||||
builder = builder.SetFromStatus(*in.FromStatus)
|
||||
}
|
||||
if in.ToStatus != nil {
|
||||
builder = builder.SetToStatus(*in.ToStatus)
|
||||
}
|
||||
if in.Action != nil {
|
||||
builder = builder.SetAction(*in.Action)
|
||||
}
|
||||
if in.ActorId != nil {
|
||||
builder = builder.SetActorID(*in.ActorId)
|
||||
}
|
||||
if in.ActorRole != nil {
|
||||
builder = builder.SetActorRole(*in.ActorRole)
|
||||
}
|
||||
if in.Metadata != nil {
|
||||
metadata, err := parseJSONMap(*in.Metadata)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder = builder.SetMetadata(metadata)
|
||||
}
|
||||
if _, err := builder.Save(l.ctx); err != nil {
|
||||
if models.IsNotFound(err) {
|
||||
return nil, errors.New("order state log not found")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.UpdateOrderStateLogsResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateOrdersLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateOrdersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateOrdersLogic {
|
||||
return &UpdateOrdersLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateOrdersLogic) UpdateOrders(in *pb.UpdateOrdersReq) (*pb.UpdateOrdersResp, error) {
|
||||
updater := l.svcCtx.OrderModelsRW.Orders.UpdateOneID(in.Id)
|
||||
|
||||
if in.ConsumerId != nil {
|
||||
updater = updater.SetConsumerID(*in.ConsumerId)
|
||||
}
|
||||
if in.ConsumerName != nil {
|
||||
updater = updater.SetConsumerName(*in.ConsumerName)
|
||||
}
|
||||
if in.PlayerId != nil {
|
||||
updater = updater.SetPlayerID(*in.PlayerId)
|
||||
}
|
||||
if in.PlayerName != nil {
|
||||
updater = updater.SetPlayerName(*in.PlayerName)
|
||||
}
|
||||
if in.ShopId != nil {
|
||||
updater = updater.SetShopID(*in.ShopId)
|
||||
}
|
||||
if in.ShopName != nil {
|
||||
updater = updater.SetShopName(*in.ShopName)
|
||||
}
|
||||
if in.ServiceSnapshot != nil {
|
||||
snapshot, err := parseJSONMap(*in.ServiceSnapshot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
updater = updater.SetServiceSnapshot(snapshot)
|
||||
}
|
||||
if in.Status != nil {
|
||||
updater = updater.SetStatus(*in.Status)
|
||||
}
|
||||
if in.TotalPrice != nil {
|
||||
price, err := parseDecimal(*in.TotalPrice)
|
||||
if err != nil || price.Cmp(decimal.Zero) <= 0 {
|
||||
return nil, errors.New("invalid total price")
|
||||
}
|
||||
updater = updater.SetTotalPrice(price)
|
||||
}
|
||||
if in.Note != nil {
|
||||
updater = updater.SetNote(*in.Note)
|
||||
}
|
||||
if in.Version != nil {
|
||||
updater = updater.SetVersion(int(*in.Version))
|
||||
}
|
||||
if in.TimeoutJobId != nil {
|
||||
updater = updater.SetTimeoutJobID(*in.TimeoutJobId)
|
||||
}
|
||||
if in.SearchText != nil {
|
||||
updater = updater.SetSearchText(*in.SearchText)
|
||||
}
|
||||
if acceptedAt := unixPtr(in.AcceptedAt); acceptedAt != nil {
|
||||
updater = updater.SetAcceptedAt(*acceptedAt)
|
||||
}
|
||||
if closedAt := unixPtr(in.ClosedAt); closedAt != nil {
|
||||
updater = updater.SetClosedAt(*closedAt)
|
||||
}
|
||||
if completedAt := unixPtr(in.CompletedAt); completedAt != nil {
|
||||
updater = updater.SetCompletedAt(*completedAt)
|
||||
}
|
||||
if cancelledAt := unixPtr(in.CancelledAt); cancelledAt != nil {
|
||||
updater = updater.SetCancelledAt(*cancelledAt)
|
||||
}
|
||||
if updatedAt := unixPtr(in.UpdatedAt); updatedAt != nil {
|
||||
updater = updater.SetUpdatedAt(*updatedAt)
|
||||
}
|
||||
|
||||
if _, err := updater.Save(l.ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.UpdateOrdersResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,484 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/models/migrate"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/models/orders"
|
||||
"juwan-backend/app/order/rpc/internal/models/orderstatelogs"
|
||||
|
||||
"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
|
||||
// OrderStateLogs is the client for interacting with the OrderStateLogs builders.
|
||||
OrderStateLogs *OrderStateLogsClient
|
||||
// Orders is the client for interacting with the Orders builders.
|
||||
Orders *OrdersClient
|
||||
}
|
||||
|
||||
// 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.OrderStateLogs = NewOrderStateLogsClient(c.config)
|
||||
c.Orders = NewOrdersClient(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,
|
||||
OrderStateLogs: NewOrderStateLogsClient(cfg),
|
||||
Orders: NewOrdersClient(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,
|
||||
OrderStateLogs: NewOrderStateLogsClient(cfg),
|
||||
Orders: NewOrdersClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||
//
|
||||
// client.Debug().
|
||||
// OrderStateLogs.
|
||||
// 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.OrderStateLogs.Use(hooks...)
|
||||
c.Orders.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.OrderStateLogs.Intercept(interceptors...)
|
||||
c.Orders.Intercept(interceptors...)
|
||||
}
|
||||
|
||||
// Mutate implements the ent.Mutator interface.
|
||||
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
switch m := m.(type) {
|
||||
case *OrderStateLogsMutation:
|
||||
return c.OrderStateLogs.mutate(ctx, m)
|
||||
case *OrdersMutation:
|
||||
return c.Orders.mutate(ctx, m)
|
||||
default:
|
||||
return nil, fmt.Errorf("models: unknown mutation type %T", m)
|
||||
}
|
||||
}
|
||||
|
||||
// OrderStateLogsClient is a client for the OrderStateLogs schema.
|
||||
type OrderStateLogsClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewOrderStateLogsClient returns a client for the OrderStateLogs from the given config.
|
||||
func NewOrderStateLogsClient(c config) *OrderStateLogsClient {
|
||||
return &OrderStateLogsClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `orderstatelogs.Hooks(f(g(h())))`.
|
||||
func (c *OrderStateLogsClient) Use(hooks ...Hook) {
|
||||
c.hooks.OrderStateLogs = append(c.hooks.OrderStateLogs, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `orderstatelogs.Intercept(f(g(h())))`.
|
||||
func (c *OrderStateLogsClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.OrderStateLogs = append(c.inters.OrderStateLogs, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a OrderStateLogs entity.
|
||||
func (c *OrderStateLogsClient) Create() *OrderStateLogsCreate {
|
||||
mutation := newOrderStateLogsMutation(c.config, OpCreate)
|
||||
return &OrderStateLogsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of OrderStateLogs entities.
|
||||
func (c *OrderStateLogsClient) CreateBulk(builders ...*OrderStateLogsCreate) *OrderStateLogsCreateBulk {
|
||||
return &OrderStateLogsCreateBulk{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 *OrderStateLogsClient) MapCreateBulk(slice any, setFunc func(*OrderStateLogsCreate, int)) *OrderStateLogsCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &OrderStateLogsCreateBulk{err: fmt.Errorf("calling to OrderStateLogsClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*OrderStateLogsCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &OrderStateLogsCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for OrderStateLogs.
|
||||
func (c *OrderStateLogsClient) Update() *OrderStateLogsUpdate {
|
||||
mutation := newOrderStateLogsMutation(c.config, OpUpdate)
|
||||
return &OrderStateLogsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *OrderStateLogsClient) UpdateOne(_m *OrderStateLogs) *OrderStateLogsUpdateOne {
|
||||
mutation := newOrderStateLogsMutation(c.config, OpUpdateOne, withOrderStateLogs(_m))
|
||||
return &OrderStateLogsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *OrderStateLogsClient) UpdateOneID(id int64) *OrderStateLogsUpdateOne {
|
||||
mutation := newOrderStateLogsMutation(c.config, OpUpdateOne, withOrderStateLogsID(id))
|
||||
return &OrderStateLogsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for OrderStateLogs.
|
||||
func (c *OrderStateLogsClient) Delete() *OrderStateLogsDelete {
|
||||
mutation := newOrderStateLogsMutation(c.config, OpDelete)
|
||||
return &OrderStateLogsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *OrderStateLogsClient) DeleteOne(_m *OrderStateLogs) *OrderStateLogsDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *OrderStateLogsClient) DeleteOneID(id int64) *OrderStateLogsDeleteOne {
|
||||
builder := c.Delete().Where(orderstatelogs.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &OrderStateLogsDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for OrderStateLogs.
|
||||
func (c *OrderStateLogsClient) Query() *OrderStateLogsQuery {
|
||||
return &OrderStateLogsQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeOrderStateLogs},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a OrderStateLogs entity by its id.
|
||||
func (c *OrderStateLogsClient) Get(ctx context.Context, id int64) (*OrderStateLogs, error) {
|
||||
return c.Query().Where(orderstatelogs.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *OrderStateLogsClient) GetX(ctx context.Context, id int64) *OrderStateLogs {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *OrderStateLogsClient) Hooks() []Hook {
|
||||
return c.hooks.OrderStateLogs
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *OrderStateLogsClient) Interceptors() []Interceptor {
|
||||
return c.inters.OrderStateLogs
|
||||
}
|
||||
|
||||
func (c *OrderStateLogsClient) mutate(ctx context.Context, m *OrderStateLogsMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&OrderStateLogsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&OrderStateLogsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&OrderStateLogsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&OrderStateLogsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("models: unknown OrderStateLogs mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// OrdersClient is a client for the Orders schema.
|
||||
type OrdersClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewOrdersClient returns a client for the Orders from the given config.
|
||||
func NewOrdersClient(c config) *OrdersClient {
|
||||
return &OrdersClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `orders.Hooks(f(g(h())))`.
|
||||
func (c *OrdersClient) Use(hooks ...Hook) {
|
||||
c.hooks.Orders = append(c.hooks.Orders, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `orders.Intercept(f(g(h())))`.
|
||||
func (c *OrdersClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Orders = append(c.inters.Orders, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a Orders entity.
|
||||
func (c *OrdersClient) Create() *OrdersCreate {
|
||||
mutation := newOrdersMutation(c.config, OpCreate)
|
||||
return &OrdersCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Orders entities.
|
||||
func (c *OrdersClient) CreateBulk(builders ...*OrdersCreate) *OrdersCreateBulk {
|
||||
return &OrdersCreateBulk{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 *OrdersClient) MapCreateBulk(slice any, setFunc func(*OrdersCreate, int)) *OrdersCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &OrdersCreateBulk{err: fmt.Errorf("calling to OrdersClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*OrdersCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &OrdersCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Orders.
|
||||
func (c *OrdersClient) Update() *OrdersUpdate {
|
||||
mutation := newOrdersMutation(c.config, OpUpdate)
|
||||
return &OrdersUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *OrdersClient) UpdateOne(_m *Orders) *OrdersUpdateOne {
|
||||
mutation := newOrdersMutation(c.config, OpUpdateOne, withOrders(_m))
|
||||
return &OrdersUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *OrdersClient) UpdateOneID(id int64) *OrdersUpdateOne {
|
||||
mutation := newOrdersMutation(c.config, OpUpdateOne, withOrdersID(id))
|
||||
return &OrdersUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Orders.
|
||||
func (c *OrdersClient) Delete() *OrdersDelete {
|
||||
mutation := newOrdersMutation(c.config, OpDelete)
|
||||
return &OrdersDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *OrdersClient) DeleteOne(_m *Orders) *OrdersDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *OrdersClient) DeleteOneID(id int64) *OrdersDeleteOne {
|
||||
builder := c.Delete().Where(orders.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &OrdersDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Orders.
|
||||
func (c *OrdersClient) Query() *OrdersQuery {
|
||||
return &OrdersQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeOrders},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Orders entity by its id.
|
||||
func (c *OrdersClient) Get(ctx context.Context, id int64) (*Orders, error) {
|
||||
return c.Query().Where(orders.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *OrdersClient) GetX(ctx context.Context, id int64) *Orders {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *OrdersClient) Hooks() []Hook {
|
||||
return c.hooks.Orders
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *OrdersClient) Interceptors() []Interceptor {
|
||||
return c.inters.Orders
|
||||
}
|
||||
|
||||
func (c *OrdersClient) mutate(ctx context.Context, m *OrdersMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&OrdersCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&OrdersUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&OrdersUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&OrdersDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("models: unknown Orders mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// hooks and interceptors per client, for fast access.
|
||||
type (
|
||||
hooks struct {
|
||||
OrderStateLogs, Orders []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
OrderStateLogs, Orders []ent.Interceptor
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,610 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"juwan-backend/app/order/rpc/internal/models/orders"
|
||||
"juwan-backend/app/order/rpc/internal/models/orderstatelogs"
|
||||
"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{
|
||||
orderstatelogs.Table: orderstatelogs.ValidColumn,
|
||||
orders.Table: orders.ValidColumn,
|
||||
})
|
||||
})
|
||||
return columnCheck(t, c)
|
||||
}
|
||||
|
||||
// Asc applies the given fields in ASC order.
|
||||
func Asc(fields ...string) func(*sql.Selector) {
|
||||
return func(s *sql.Selector) {
|
||||
for _, f := range fields {
|
||||
if err := checkColumn(s.TableName(), f); err != nil {
|
||||
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("models: %w", err)})
|
||||
}
|
||||
s.OrderBy(sql.Asc(s.C(f)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Desc applies the given fields in DESC order.
|
||||
func Desc(fields ...string) func(*sql.Selector) {
|
||||
return func(s *sql.Selector) {
|
||||
for _, f := range fields {
|
||||
if err := checkColumn(s.TableName(), f); err != nil {
|
||||
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("models: %w", err)})
|
||||
}
|
||||
s.OrderBy(sql.Desc(s.C(f)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
|
||||
type AggregateFunc func(*sql.Selector) string
|
||||
|
||||
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
|
||||
//
|
||||
// GroupBy(field1, field2).
|
||||
// Aggregate(models.As(models.Sum(field1), "sum_field1"), (models.As(models.Sum(field2), "sum_field2")).
|
||||
// Scan(ctx, &v)
|
||||
func As(fn AggregateFunc, end string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.As(fn(s), end)
|
||||
}
|
||||
}
|
||||
|
||||
// Count applies the "count" aggregation function on each group.
|
||||
func Count() AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.Count("*")
|
||||
}
|
||||
}
|
||||
|
||||
// Max applies the "max" aggregation function on the given field of each group.
|
||||
func Max(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
if err := checkColumn(s.TableName(), field); err != nil {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||
return ""
|
||||
}
|
||||
return sql.Max(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Mean applies the "mean" aggregation function on the given field of each group.
|
||||
func Mean(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
if err := checkColumn(s.TableName(), field); err != nil {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||
return ""
|
||||
}
|
||||
return sql.Avg(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Min applies the "min" aggregation function on the given field of each group.
|
||||
func Min(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
if err := checkColumn(s.TableName(), field); err != nil {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||
return ""
|
||||
}
|
||||
return sql.Min(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Sum applies the "sum" aggregation function on the given field of each group.
|
||||
func Sum(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
if err := checkColumn(s.TableName(), field); err != nil {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||
return ""
|
||||
}
|
||||
return sql.Sum(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// ValidationError returns when validating a field or edge fails.
|
||||
type ValidationError struct {
|
||||
Name string // Field or edge name.
|
||||
err error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *ValidationError) Error() string {
|
||||
return e.err.Error()
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ValidationError) Unwrap() error {
|
||||
return e.err
|
||||
}
|
||||
|
||||
// IsValidationError returns a boolean indicating whether the error is a validation error.
|
||||
func IsValidationError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ValidationError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
|
||||
type NotFoundError struct {
|
||||
label string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotFoundError) Error() string {
|
||||
return "models: " + e.label + " not found"
|
||||
}
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// MaskNotFound masks not found error.
|
||||
func MaskNotFound(err error) error {
|
||||
if IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
|
||||
type NotSingularError struct {
|
||||
label string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotSingularError) Error() string {
|
||||
return "models: " + e.label + " not singular"
|
||||
}
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// NotLoadedError returns when trying to get a node that was not loaded by the query.
|
||||
type NotLoadedError struct {
|
||||
edge string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotLoadedError) Error() string {
|
||||
return "models: " + e.edge + " edge was not loaded"
|
||||
}
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct {
|
||||
msg string
|
||||
wrap error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ConstraintError) Error() string {
|
||||
return "models: constraint failed: " + e.msg
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ConstraintError) Unwrap() error {
|
||||
return e.wrap
|
||||
}
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// selector embedded by the different Select/GroupBy builders.
|
||||
type selector struct {
|
||||
label string
|
||||
flds *[]string
|
||||
fns []AggregateFunc
|
||||
scan func(context.Context, any) error
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (s *selector) ScanX(ctx context.Context, v any) {
|
||||
if err := s.scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(*s.flds) > 1 {
|
||||
return nil, errors.New("models: Strings is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := s.scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (s *selector) StringsX(ctx context.Context) []string {
|
||||
v, err := s.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = s.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{s.label}
|
||||
default:
|
||||
err = fmt.Errorf("models: Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (s *selector) StringX(ctx context.Context) string {
|
||||
v, err := s.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(*s.flds) > 1 {
|
||||
return nil, errors.New("models: Ints is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := s.scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (s *selector) IntsX(ctx context.Context) []int {
|
||||
v, err := s.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = s.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{s.label}
|
||||
default:
|
||||
err = fmt.Errorf("models: Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (s *selector) IntX(ctx context.Context) int {
|
||||
v, err := s.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(*s.flds) > 1 {
|
||||
return nil, errors.New("models: Float64s is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := s.scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (s *selector) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := s.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = s.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{s.label}
|
||||
default:
|
||||
err = fmt.Errorf("models: Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (s *selector) Float64X(ctx context.Context) float64 {
|
||||
v, err := s.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(*s.flds) > 1 {
|
||||
return nil, errors.New("models: Bools is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := s.scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (s *selector) BoolsX(ctx context.Context) []bool {
|
||||
v, err := s.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = s.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{s.label}
|
||||
default:
|
||||
err = fmt.Errorf("models: Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (s *selector) BoolX(ctx context.Context) bool {
|
||||
v, err := s.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// withHooks invokes the builder operation with the given hooks, if any.
|
||||
func withHooks[V Value, M any, PM interface {
|
||||
*M
|
||||
Mutation
|
||||
}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) {
|
||||
if len(hooks) == 0 {
|
||||
return exec(ctx)
|
||||
}
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutationT, ok := any(m).(PM)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
// Set the mutation to the builder.
|
||||
*mutation = *mutationT
|
||||
return exec(ctx)
|
||||
})
|
||||
for i := len(hooks) - 1; i >= 0; i-- {
|
||||
if hooks[i] == nil {
|
||||
return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = hooks[i](mut)
|
||||
}
|
||||
v, err := mut.Mutate(ctx, mutation)
|
||||
if err != nil {
|
||||
return value, err
|
||||
}
|
||||
nv, ok := v.(V)
|
||||
if !ok {
|
||||
return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation)
|
||||
}
|
||||
return nv, nil
|
||||
}
|
||||
|
||||
// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist.
|
||||
func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context {
|
||||
if ent.QueryFromContext(ctx) == nil {
|
||||
qc.Op = op
|
||||
ctx = ent.NewQueryContext(ctx, qc)
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
func querierAll[V Value, Q interface {
|
||||
sqlAll(context.Context, ...queryHook) (V, error)
|
||||
}]() Querier {
|
||||
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
query, ok := q.(Q)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||
}
|
||||
return query.sqlAll(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
func querierCount[Q interface {
|
||||
sqlCount(context.Context) (int, error)
|
||||
}]() Querier {
|
||||
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
query, ok := q.(Q)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||
}
|
||||
return query.sqlCount(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) {
|
||||
for i := len(inters) - 1; i >= 0; i-- {
|
||||
qr = inters[i].Intercept(qr)
|
||||
}
|
||||
rv, err := qr.Query(ctx, q)
|
||||
if err != nil {
|
||||
return v, err
|
||||
}
|
||||
vt, ok := rv.(V)
|
||||
if !ok {
|
||||
return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v)
|
||||
}
|
||||
return vt, nil
|
||||
}
|
||||
|
||||
func scanWithInterceptors[Q1 ent.Query, Q2 interface {
|
||||
sqlScan(context.Context, Q1, any) error
|
||||
}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error {
|
||||
rv := reflect.ValueOf(v)
|
||||
var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
query, ok := q.(Q1)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||
}
|
||||
if err := selectOrGroup.sqlScan(ctx, query, v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() {
|
||||
return rv.Elem().Interface(), nil
|
||||
}
|
||||
return v, nil
|
||||
})
|
||||
for i := len(inters) - 1; i >= 0; i-- {
|
||||
qr = inters[i].Intercept(qr)
|
||||
}
|
||||
vv, err := qr.Query(ctx, rootQuery)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch rv2 := reflect.ValueOf(vv); {
|
||||
case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer:
|
||||
case rv.Type() == rv2.Type():
|
||||
rv.Elem().Set(rv2.Elem())
|
||||
case rv.Elem().Type() == rv2.Type():
|
||||
rv.Elem().Set(rv2)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// queryHook describes an internal hook for the different sqlAll methods.
|
||||
type queryHook func(context.Context, *sqlgraph.QuerySpec)
|
||||
@@ -0,0 +1,85 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package enttest
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/models"
|
||||
// required by schema hooks.
|
||||
_ "juwan-backend/app/order/rpc/internal/models/runtime"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/models/migrate"
|
||||
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
)
|
||||
|
||||
type (
|
||||
// TestingT is the interface that is shared between
|
||||
// testing.T and testing.B and used by enttest.
|
||||
TestingT interface {
|
||||
FailNow()
|
||||
Error(...any)
|
||||
}
|
||||
|
||||
// Option configures client creation.
|
||||
Option func(*options)
|
||||
|
||||
options struct {
|
||||
opts []models.Option
|
||||
migrateOpts []schema.MigrateOption
|
||||
}
|
||||
)
|
||||
|
||||
// WithOptions forwards options to client creation.
|
||||
func WithOptions(opts ...models.Option) Option {
|
||||
return func(o *options) {
|
||||
o.opts = append(o.opts, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// WithMigrateOptions forwards options to auto migration.
|
||||
func WithMigrateOptions(opts ...schema.MigrateOption) Option {
|
||||
return func(o *options) {
|
||||
o.migrateOpts = append(o.migrateOpts, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
func newOptions(opts []Option) *options {
|
||||
o := &options{}
|
||||
for _, opt := range opts {
|
||||
opt(o)
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
// Open calls models.Open and auto-run migration.
|
||||
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *models.Client {
|
||||
o := newOptions(opts)
|
||||
c, err := models.Open(driverName, dataSourceName, o.opts...)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
migrateSchema(t, c, o)
|
||||
return c
|
||||
}
|
||||
|
||||
// NewClient calls models.NewClient and auto-run migration.
|
||||
func NewClient(t TestingT, opts ...Option) *models.Client {
|
||||
o := newOptions(opts)
|
||||
c := models.NewClient(o.opts...)
|
||||
migrateSchema(t, c, o)
|
||||
return c
|
||||
}
|
||||
func migrateSchema(t TestingT, c *models.Client, o *options) {
|
||||
tables, err := schema.CopyTables(migrate.Tables)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package models
|
||||
|
||||
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate ./schema
|
||||
@@ -0,0 +1,210 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package hook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"juwan-backend/app/order/rpc/internal/models"
|
||||
)
|
||||
|
||||
// The OrderStateLogsFunc type is an adapter to allow the use of ordinary
|
||||
// function as OrderStateLogs mutator.
|
||||
type OrderStateLogsFunc func(context.Context, *models.OrderStateLogsMutation) (models.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f OrderStateLogsFunc) Mutate(ctx context.Context, m models.Mutation) (models.Value, error) {
|
||||
if mv, ok := m.(*models.OrderStateLogsMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *models.OrderStateLogsMutation", m)
|
||||
}
|
||||
|
||||
// The OrdersFunc type is an adapter to allow the use of ordinary
|
||||
// function as Orders mutator.
|
||||
type OrdersFunc func(context.Context, *models.OrdersMutation) (models.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f OrdersFunc) Mutate(ctx context.Context, m models.Mutation) (models.Value, error) {
|
||||
if mv, ok := m.(*models.OrdersMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *models.OrdersMutation", m)
|
||||
}
|
||||
|
||||
// Condition is a hook condition function.
|
||||
type Condition func(context.Context, models.Mutation) bool
|
||||
|
||||
// And groups conditions with the AND operator.
|
||||
func And(first, second Condition, rest ...Condition) Condition {
|
||||
return func(ctx context.Context, m models.Mutation) bool {
|
||||
if !first(ctx, m) || !second(ctx, m) {
|
||||
return false
|
||||
}
|
||||
for _, cond := range rest {
|
||||
if !cond(ctx, m) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// Or groups conditions with the OR operator.
|
||||
func Or(first, second Condition, rest ...Condition) Condition {
|
||||
return func(ctx context.Context, m models.Mutation) bool {
|
||||
if first(ctx, m) || second(ctx, m) {
|
||||
return true
|
||||
}
|
||||
for _, cond := range rest {
|
||||
if cond(ctx, m) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Not negates a given condition.
|
||||
func Not(cond Condition) Condition {
|
||||
return func(ctx context.Context, m models.Mutation) bool {
|
||||
return !cond(ctx, m)
|
||||
}
|
||||
}
|
||||
|
||||
// HasOp is a condition testing mutation operation.
|
||||
func HasOp(op models.Op) Condition {
|
||||
return func(_ context.Context, m models.Mutation) bool {
|
||||
return m.Op().Is(op)
|
||||
}
|
||||
}
|
||||
|
||||
// HasAddedFields is a condition validating `.AddedField` on fields.
|
||||
func HasAddedFields(field string, fields ...string) Condition {
|
||||
return func(_ context.Context, m models.Mutation) bool {
|
||||
if _, exists := m.AddedField(field); !exists {
|
||||
return false
|
||||
}
|
||||
for _, field := range fields {
|
||||
if _, exists := m.AddedField(field); !exists {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// HasClearedFields is a condition validating `.FieldCleared` on fields.
|
||||
func HasClearedFields(field string, fields ...string) Condition {
|
||||
return func(_ context.Context, m models.Mutation) bool {
|
||||
if exists := m.FieldCleared(field); !exists {
|
||||
return false
|
||||
}
|
||||
for _, field := range fields {
|
||||
if exists := m.FieldCleared(field); !exists {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// HasFields is a condition validating `.Field` on fields.
|
||||
func HasFields(field string, fields ...string) Condition {
|
||||
return func(_ context.Context, m models.Mutation) bool {
|
||||
if _, exists := m.Field(field); !exists {
|
||||
return false
|
||||
}
|
||||
for _, field := range fields {
|
||||
if _, exists := m.Field(field); !exists {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// If executes the given hook under condition.
|
||||
//
|
||||
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
|
||||
func If(hk models.Hook, cond Condition) models.Hook {
|
||||
return func(next models.Mutator) models.Mutator {
|
||||
return models.MutateFunc(func(ctx context.Context, m models.Mutation) (models.Value, error) {
|
||||
if cond(ctx, m) {
|
||||
return hk(next).Mutate(ctx, m)
|
||||
}
|
||||
return next.Mutate(ctx, m)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// On executes the given hook only for the given operation.
|
||||
//
|
||||
// hook.On(Log, models.Delete|models.Create)
|
||||
func On(hk models.Hook, op models.Op) models.Hook {
|
||||
return If(hk, HasOp(op))
|
||||
}
|
||||
|
||||
// Unless skips the given hook only for the given operation.
|
||||
//
|
||||
// hook.Unless(Log, models.Update|models.UpdateOne)
|
||||
func Unless(hk models.Hook, op models.Op) models.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) models.Hook {
|
||||
return func(models.Mutator) models.Mutator {
|
||||
return models.MutateFunc(func(context.Context, models.Mutation) (models.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []models.Hook {
|
||||
// return []models.Hook{
|
||||
// Reject(models.Delete|models.Update),
|
||||
// }
|
||||
// }
|
||||
func Reject(op models.Op) models.Hook {
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
// Chain acts as a list of hooks and is effectively immutable.
|
||||
// Once created, it will always hold the same set of hooks in the same order.
|
||||
type Chain struct {
|
||||
hooks []models.Hook
|
||||
}
|
||||
|
||||
// NewChain creates a new chain of hooks.
|
||||
func NewChain(hooks ...models.Hook) Chain {
|
||||
return Chain{append([]models.Hook(nil), hooks...)}
|
||||
}
|
||||
|
||||
// Hook chains the list of hooks and returns the final hook.
|
||||
func (c Chain) Hook() models.Hook {
|
||||
return func(mutator models.Mutator) models.Mutator {
|
||||
for i := len(c.hooks) - 1; i >= 0; i-- {
|
||||
mutator = c.hooks[i](mutator)
|
||||
}
|
||||
return mutator
|
||||
}
|
||||
}
|
||||
|
||||
// Append extends a chain, adding the specified hook
|
||||
// as the last ones in the mutation flow.
|
||||
func (c Chain) Append(hooks ...models.Hook) Chain {
|
||||
newHooks := make([]models.Hook, 0, len(c.hooks)+len(hooks))
|
||||
newHooks = append(newHooks, c.hooks...)
|
||||
newHooks = append(newHooks, hooks...)
|
||||
return Chain{newHooks}
|
||||
}
|
||||
|
||||
// Extend extends a chain, adding the specified chain
|
||||
// as the last ones in the mutation flow.
|
||||
func (c Chain) Extend(chain Chain) Chain {
|
||||
return c.Append(chain.hooks...)
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
)
|
||||
|
||||
var (
|
||||
// WithGlobalUniqueID sets the universal ids options to the migration.
|
||||
// If this option is enabled, ent migration will allocate a 1<<32 range
|
||||
// for the ids of each entity (table).
|
||||
// Note that this option cannot be applied on tables that already exist.
|
||||
WithGlobalUniqueID = schema.WithGlobalUniqueID
|
||||
// WithDropColumn sets the drop column option to the migration.
|
||||
// If this option is enabled, ent migration will drop old columns
|
||||
// that were used for both fields and edges. This defaults to false.
|
||||
WithDropColumn = schema.WithDropColumn
|
||||
// WithDropIndex sets the drop index option to the migration.
|
||||
// If this option is enabled, ent migration will drop old indexes
|
||||
// that were defined in the schema. This defaults to false.
|
||||
// Note that unique constraints are defined using `UNIQUE INDEX`,
|
||||
// and therefore, it's recommended to enable this option to get more
|
||||
// flexibility in the schema changes.
|
||||
WithDropIndex = schema.WithDropIndex
|
||||
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
|
||||
WithForeignKeys = schema.WithForeignKeys
|
||||
)
|
||||
|
||||
// Schema is the API for creating, migrating and dropping a schema.
|
||||
type Schema struct {
|
||||
drv dialect.Driver
|
||||
}
|
||||
|
||||
// NewSchema creates a new schema client.
|
||||
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
|
||||
|
||||
// Create creates all schema resources.
|
||||
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
|
||||
return Create(ctx, s, Tables, opts...)
|
||||
}
|
||||
|
||||
// Create creates all table resources using the given schema driver.
|
||||
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error {
|
||||
migrate, err := schema.NewMigrate(s.drv, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ent/migrate: %w", err)
|
||||
}
|
||||
return migrate.Create(ctx, tables...)
|
||||
}
|
||||
|
||||
// WriteTo writes the schema changes to w instead of running them against the database.
|
||||
//
|
||||
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
|
||||
return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...)
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
// 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 (
|
||||
// OrderStateLogsColumns holds the columns for the "order_state_logs" table.
|
||||
OrderStateLogsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "order_id", Type: field.TypeInt64},
|
||||
{Name: "from_status", Type: field.TypeString, Nullable: true, Size: 30},
|
||||
{Name: "to_status", Type: field.TypeString, Size: 30},
|
||||
{Name: "action", Type: field.TypeString, Size: 50},
|
||||
{Name: "actor_id", Type: field.TypeInt64},
|
||||
{Name: "actor_role", Type: field.TypeString, Size: 20},
|
||||
{Name: "metadata", Type: field.TypeJSON, Nullable: true, SchemaType: map[string]string{"postgres": "jsonb"}},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
}
|
||||
// OrderStateLogsTable holds the schema information for the "order_state_logs" table.
|
||||
OrderStateLogsTable = &schema.Table{
|
||||
Name: "order_state_logs",
|
||||
Columns: OrderStateLogsColumns,
|
||||
PrimaryKey: []*schema.Column{OrderStateLogsColumns[0]},
|
||||
}
|
||||
// OrdersColumns holds the columns for the "orders" table.
|
||||
OrdersColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "consumer_id", Type: field.TypeInt64},
|
||||
{Name: "consumer_name", Type: field.TypeString, Size: 100},
|
||||
{Name: "player_id", Type: field.TypeInt64},
|
||||
{Name: "player_name", Type: field.TypeString, Size: 100},
|
||||
{Name: "shop_id", Type: field.TypeInt64, Nullable: true},
|
||||
{Name: "shop_name", Type: field.TypeString, Nullable: true, Size: 200},
|
||||
{Name: "service_snapshot", Type: field.TypeJSON, SchemaType: map[string]string{"postgres": "jsonb"}},
|
||||
{Name: "status", Type: field.TypeString, Size: 30, Default: "pending_payment"},
|
||||
{Name: "total_price", Type: field.TypeOther, SchemaType: map[string]string{"postgres": "decimal(10,2)"}},
|
||||
{Name: "note", Type: field.TypeString, Nullable: true},
|
||||
{Name: "version", Type: field.TypeInt, Default: 1},
|
||||
{Name: "timeout_job_id", Type: field.TypeString, Nullable: true, Size: 100},
|
||||
{Name: "search_text", Type: field.TypeString, Nullable: true},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "accepted_at", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "closed_at", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "completed_at", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "cancelled_at", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
}
|
||||
// OrdersTable holds the schema information for the "orders" table.
|
||||
OrdersTable = &schema.Table{
|
||||
Name: "orders",
|
||||
Columns: OrdersColumns,
|
||||
PrimaryKey: []*schema.Column{OrdersColumns[0]},
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
OrderStateLogsTable,
|
||||
OrdersTable,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
OrderStateLogsTable.Annotation = &entsql.Annotation{
|
||||
Table: "order_state_logs",
|
||||
}
|
||||
OrdersTable.Annotation = &entsql.Annotation{
|
||||
Table: "orders",
|
||||
}
|
||||
OrdersTable.Annotation.Checks = map[string]string{
|
||||
"chk_order_status": "status IN ('pending_payment', 'pending_accept', 'in_progress', 'pending_close', 'pending_review', 'disputed', 'completed', 'cancelled')",
|
||||
"chk_price_positive": "total_price > 0",
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,339 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"juwan-backend/app/order/rpc/internal/models/orders"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// Orders is the model entity for the Orders schema.
|
||||
type Orders struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int64 `json:"id,omitempty"`
|
||||
// ConsumerID holds the value of the "consumer_id" field.
|
||||
ConsumerID int64 `json:"consumer_id,omitempty"`
|
||||
// ConsumerName holds the value of the "consumer_name" field.
|
||||
ConsumerName string `json:"consumer_name,omitempty"`
|
||||
// PlayerID holds the value of the "player_id" field.
|
||||
PlayerID int64 `json:"player_id,omitempty"`
|
||||
// PlayerName holds the value of the "player_name" field.
|
||||
PlayerName string `json:"player_name,omitempty"`
|
||||
// ShopID holds the value of the "shop_id" field.
|
||||
ShopID *int64 `json:"shop_id,omitempty"`
|
||||
// ShopName holds the value of the "shop_name" field.
|
||||
ShopName *string `json:"shop_name,omitempty"`
|
||||
// ServiceSnapshot holds the value of the "service_snapshot" field.
|
||||
ServiceSnapshot map[string]interface{} `json:"service_snapshot,omitempty"`
|
||||
// Status holds the value of the "status" field.
|
||||
Status string `json:"status,omitempty"`
|
||||
// TotalPrice holds the value of the "total_price" field.
|
||||
TotalPrice decimal.Decimal `json:"total_price,omitempty"`
|
||||
// Note holds the value of the "note" field.
|
||||
Note *string `json:"note,omitempty"`
|
||||
// Version holds the value of the "version" field.
|
||||
Version int `json:"version,omitempty"`
|
||||
// TimeoutJobID holds the value of the "timeout_job_id" field.
|
||||
TimeoutJobID *string `json:"timeout_job_id,omitempty"`
|
||||
// SearchText holds the value of the "search_text" field.
|
||||
SearchText *string `json:"search_text,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// AcceptedAt holds the value of the "accepted_at" field.
|
||||
AcceptedAt *time.Time `json:"accepted_at,omitempty"`
|
||||
// ClosedAt holds the value of the "closed_at" field.
|
||||
ClosedAt *time.Time `json:"closed_at,omitempty"`
|
||||
// CompletedAt holds the value of the "completed_at" field.
|
||||
CompletedAt *time.Time `json:"completed_at,omitempty"`
|
||||
// CancelledAt holds the value of the "cancelled_at" field.
|
||||
CancelledAt *time.Time `json:"cancelled_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 (*Orders) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case orders.FieldServiceSnapshot:
|
||||
values[i] = new([]byte)
|
||||
case orders.FieldTotalPrice:
|
||||
values[i] = new(decimal.Decimal)
|
||||
case orders.FieldID, orders.FieldConsumerID, orders.FieldPlayerID, orders.FieldShopID, orders.FieldVersion:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case orders.FieldConsumerName, orders.FieldPlayerName, orders.FieldShopName, orders.FieldStatus, orders.FieldNote, orders.FieldTimeoutJobID, orders.FieldSearchText:
|
||||
values[i] = new(sql.NullString)
|
||||
case orders.FieldCreatedAt, orders.FieldAcceptedAt, orders.FieldClosedAt, orders.FieldCompletedAt, orders.FieldCancelledAt, orders.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 Orders fields.
|
||||
func (_m *Orders) 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 orders.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 orders.FieldConsumerID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field consumer_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ConsumerID = value.Int64
|
||||
}
|
||||
case orders.FieldConsumerName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field consumer_name", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ConsumerName = value.String
|
||||
}
|
||||
case orders.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 orders.FieldPlayerName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field player_name", values[i])
|
||||
} else if value.Valid {
|
||||
_m.PlayerName = value.String
|
||||
}
|
||||
case orders.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 orders.FieldShopName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field shop_name", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ShopName = new(string)
|
||||
*_m.ShopName = value.String
|
||||
}
|
||||
case orders.FieldServiceSnapshot:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field service_snapshot", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &_m.ServiceSnapshot); err != nil {
|
||||
return fmt.Errorf("unmarshal field service_snapshot: %w", err)
|
||||
}
|
||||
}
|
||||
case orders.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 orders.FieldTotalPrice:
|
||||
if value, ok := values[i].(*decimal.Decimal); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field total_price", values[i])
|
||||
} else if value != nil {
|
||||
_m.TotalPrice = *value
|
||||
}
|
||||
case orders.FieldNote:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field note", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Note = new(string)
|
||||
*_m.Note = value.String
|
||||
}
|
||||
case orders.FieldVersion:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field version", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Version = int(value.Int64)
|
||||
}
|
||||
case orders.FieldTimeoutJobID:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field timeout_job_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.TimeoutJobID = new(string)
|
||||
*_m.TimeoutJobID = value.String
|
||||
}
|
||||
case orders.FieldSearchText:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field search_text", values[i])
|
||||
} else if value.Valid {
|
||||
_m.SearchText = new(string)
|
||||
*_m.SearchText = value.String
|
||||
}
|
||||
case orders.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 orders.FieldAcceptedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field accepted_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.AcceptedAt = new(time.Time)
|
||||
*_m.AcceptedAt = value.Time
|
||||
}
|
||||
case orders.FieldClosedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field closed_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ClosedAt = new(time.Time)
|
||||
*_m.ClosedAt = value.Time
|
||||
}
|
||||
case orders.FieldCompletedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field completed_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.CompletedAt = new(time.Time)
|
||||
*_m.CompletedAt = value.Time
|
||||
}
|
||||
case orders.FieldCancelledAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field cancelled_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.CancelledAt = new(time.Time)
|
||||
*_m.CancelledAt = value.Time
|
||||
}
|
||||
case orders.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 Orders.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Orders) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Orders.
|
||||
// Note that you need to call Orders.Unwrap() before calling this method if this Orders
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Orders) Update() *OrdersUpdateOne {
|
||||
return NewOrdersClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Orders 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 *Orders) Unwrap() *Orders {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("models: Orders is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Orders) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Orders(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("consumer_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.ConsumerID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("consumer_name=")
|
||||
builder.WriteString(_m.ConsumerName)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("player_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.PlayerID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("player_name=")
|
||||
builder.WriteString(_m.PlayerName)
|
||||
builder.WriteString(", ")
|
||||
if v := _m.ShopID; v != nil {
|
||||
builder.WriteString("shop_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", *v))
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
if v := _m.ShopName; v != nil {
|
||||
builder.WriteString("shop_name=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("service_snapshot=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.ServiceSnapshot))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("status=")
|
||||
builder.WriteString(_m.Status)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("total_price=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.TotalPrice))
|
||||
builder.WriteString(", ")
|
||||
if v := _m.Note; v != nil {
|
||||
builder.WriteString("note=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("version=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Version))
|
||||
builder.WriteString(", ")
|
||||
if v := _m.TimeoutJobID; v != nil {
|
||||
builder.WriteString("timeout_job_id=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
if v := _m.SearchText; v != nil {
|
||||
builder.WriteString("search_text=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
if v := _m.AcceptedAt; v != nil {
|
||||
builder.WriteString("accepted_at=")
|
||||
builder.WriteString(v.Format(time.ANSIC))
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
if v := _m.ClosedAt; v != nil {
|
||||
builder.WriteString("closed_at=")
|
||||
builder.WriteString(v.Format(time.ANSIC))
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
if v := _m.CompletedAt; v != nil {
|
||||
builder.WriteString("completed_at=")
|
||||
builder.WriteString(v.Format(time.ANSIC))
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
if v := _m.CancelledAt; v != nil {
|
||||
builder.WriteString("cancelled_at=")
|
||||
builder.WriteString(v.Format(time.ANSIC))
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("updated_at=")
|
||||
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// OrdersSlice is a parsable slice of Orders.
|
||||
type OrdersSlice []*Orders
|
||||
@@ -0,0 +1,211 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package orders
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the orders type in the database.
|
||||
Label = "orders"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldConsumerID holds the string denoting the consumer_id field in the database.
|
||||
FieldConsumerID = "consumer_id"
|
||||
// FieldConsumerName holds the string denoting the consumer_name field in the database.
|
||||
FieldConsumerName = "consumer_name"
|
||||
// FieldPlayerID holds the string denoting the player_id field in the database.
|
||||
FieldPlayerID = "player_id"
|
||||
// FieldPlayerName holds the string denoting the player_name field in the database.
|
||||
FieldPlayerName = "player_name"
|
||||
// FieldShopID holds the string denoting the shop_id field in the database.
|
||||
FieldShopID = "shop_id"
|
||||
// FieldShopName holds the string denoting the shop_name field in the database.
|
||||
FieldShopName = "shop_name"
|
||||
// FieldServiceSnapshot holds the string denoting the service_snapshot field in the database.
|
||||
FieldServiceSnapshot = "service_snapshot"
|
||||
// FieldStatus holds the string denoting the status field in the database.
|
||||
FieldStatus = "status"
|
||||
// FieldTotalPrice holds the string denoting the total_price field in the database.
|
||||
FieldTotalPrice = "total_price"
|
||||
// FieldNote holds the string denoting the note field in the database.
|
||||
FieldNote = "note"
|
||||
// FieldVersion holds the string denoting the version field in the database.
|
||||
FieldVersion = "version"
|
||||
// FieldTimeoutJobID holds the string denoting the timeout_job_id field in the database.
|
||||
FieldTimeoutJobID = "timeout_job_id"
|
||||
// FieldSearchText holds the string denoting the search_text field in the database.
|
||||
FieldSearchText = "search_text"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// FieldAcceptedAt holds the string denoting the accepted_at field in the database.
|
||||
FieldAcceptedAt = "accepted_at"
|
||||
// FieldClosedAt holds the string denoting the closed_at field in the database.
|
||||
FieldClosedAt = "closed_at"
|
||||
// FieldCompletedAt holds the string denoting the completed_at field in the database.
|
||||
FieldCompletedAt = "completed_at"
|
||||
// FieldCancelledAt holds the string denoting the cancelled_at field in the database.
|
||||
FieldCancelledAt = "cancelled_at"
|
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at"
|
||||
// Table holds the table name of the orders in the database.
|
||||
Table = "orders"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for orders fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldConsumerID,
|
||||
FieldConsumerName,
|
||||
FieldPlayerID,
|
||||
FieldPlayerName,
|
||||
FieldShopID,
|
||||
FieldShopName,
|
||||
FieldServiceSnapshot,
|
||||
FieldStatus,
|
||||
FieldTotalPrice,
|
||||
FieldNote,
|
||||
FieldVersion,
|
||||
FieldTimeoutJobID,
|
||||
FieldSearchText,
|
||||
FieldCreatedAt,
|
||||
FieldAcceptedAt,
|
||||
FieldClosedAt,
|
||||
FieldCompletedAt,
|
||||
FieldCancelledAt,
|
||||
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 (
|
||||
// ConsumerNameValidator is a validator for the "consumer_name" field. It is called by the builders before save.
|
||||
ConsumerNameValidator func(string) error
|
||||
// PlayerNameValidator is a validator for the "player_name" field. It is called by the builders before save.
|
||||
PlayerNameValidator func(string) error
|
||||
// ShopNameValidator is a validator for the "shop_name" field. It is called by the builders before save.
|
||||
ShopNameValidator func(string) error
|
||||
// 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
|
||||
// DefaultVersion holds the default value on creation for the "version" field.
|
||||
DefaultVersion int
|
||||
// TimeoutJobIDValidator is a validator for the "timeout_job_id" field. It is called by the builders before save.
|
||||
TimeoutJobIDValidator func(string) error
|
||||
// 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 Orders 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()
|
||||
}
|
||||
|
||||
// ByConsumerID orders the results by the consumer_id field.
|
||||
func ByConsumerID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldConsumerID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByConsumerName orders the results by the consumer_name field.
|
||||
func ByConsumerName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldConsumerName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByPlayerID orders the results by the player_id field.
|
||||
func ByPlayerID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldPlayerID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByPlayerName orders the results by the player_name field.
|
||||
func ByPlayerName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldPlayerName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByShopID orders the results by the shop_id field.
|
||||
func ByShopID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldShopID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByShopName orders the results by the shop_name field.
|
||||
func ByShopName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldShopName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByStatus orders the results by the status field.
|
||||
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTotalPrice orders the results by the total_price field.
|
||||
func ByTotalPrice(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTotalPrice, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByNote orders the results by the note field.
|
||||
func ByNote(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldNote, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByVersion orders the results by the version field.
|
||||
func ByVersion(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldVersion, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTimeoutJobID orders the results by the timeout_job_id field.
|
||||
func ByTimeoutJobID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTimeoutJobID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// BySearchText orders the results by the search_text field.
|
||||
func BySearchText(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldSearchText, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAcceptedAt orders the results by the accepted_at field.
|
||||
func ByAcceptedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldAcceptedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByClosedAt orders the results by the closed_at field.
|
||||
func ByClosedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldClosedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCompletedAt orders the results by the completed_at field.
|
||||
func ByCompletedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCompletedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCancelledAt orders the results by the cancelled_at field.
|
||||
func ByCancelledAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCancelledAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdatedAt orders the results by the updated_at field.
|
||||
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,555 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"juwan-backend/app/order/rpc/internal/models/orders"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// OrdersCreate is the builder for creating a Orders entity.
|
||||
type OrdersCreate struct {
|
||||
config
|
||||
mutation *OrdersMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetConsumerID sets the "consumer_id" field.
|
||||
func (_c *OrdersCreate) SetConsumerID(v int64) *OrdersCreate {
|
||||
_c.mutation.SetConsumerID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetConsumerName sets the "consumer_name" field.
|
||||
func (_c *OrdersCreate) SetConsumerName(v string) *OrdersCreate {
|
||||
_c.mutation.SetConsumerName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetPlayerID sets the "player_id" field.
|
||||
func (_c *OrdersCreate) SetPlayerID(v int64) *OrdersCreate {
|
||||
_c.mutation.SetPlayerID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetPlayerName sets the "player_name" field.
|
||||
func (_c *OrdersCreate) SetPlayerName(v string) *OrdersCreate {
|
||||
_c.mutation.SetPlayerName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetShopID sets the "shop_id" field.
|
||||
func (_c *OrdersCreate) SetShopID(v int64) *OrdersCreate {
|
||||
_c.mutation.SetShopID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableShopID sets the "shop_id" field if the given value is not nil.
|
||||
func (_c *OrdersCreate) SetNillableShopID(v *int64) *OrdersCreate {
|
||||
if v != nil {
|
||||
_c.SetShopID(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetShopName sets the "shop_name" field.
|
||||
func (_c *OrdersCreate) SetShopName(v string) *OrdersCreate {
|
||||
_c.mutation.SetShopName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableShopName sets the "shop_name" field if the given value is not nil.
|
||||
func (_c *OrdersCreate) SetNillableShopName(v *string) *OrdersCreate {
|
||||
if v != nil {
|
||||
_c.SetShopName(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetServiceSnapshot sets the "service_snapshot" field.
|
||||
func (_c *OrdersCreate) SetServiceSnapshot(v map[string]interface{}) *OrdersCreate {
|
||||
_c.mutation.SetServiceSnapshot(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_c *OrdersCreate) SetStatus(v string) *OrdersCreate {
|
||||
_c.mutation.SetStatus(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_c *OrdersCreate) SetNillableStatus(v *string) *OrdersCreate {
|
||||
if v != nil {
|
||||
_c.SetStatus(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetTotalPrice sets the "total_price" field.
|
||||
func (_c *OrdersCreate) SetTotalPrice(v decimal.Decimal) *OrdersCreate {
|
||||
_c.mutation.SetTotalPrice(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNote sets the "note" field.
|
||||
func (_c *OrdersCreate) SetNote(v string) *OrdersCreate {
|
||||
_c.mutation.SetNote(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableNote sets the "note" field if the given value is not nil.
|
||||
func (_c *OrdersCreate) SetNillableNote(v *string) *OrdersCreate {
|
||||
if v != nil {
|
||||
_c.SetNote(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetVersion sets the "version" field.
|
||||
func (_c *OrdersCreate) SetVersion(v int) *OrdersCreate {
|
||||
_c.mutation.SetVersion(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableVersion sets the "version" field if the given value is not nil.
|
||||
func (_c *OrdersCreate) SetNillableVersion(v *int) *OrdersCreate {
|
||||
if v != nil {
|
||||
_c.SetVersion(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetTimeoutJobID sets the "timeout_job_id" field.
|
||||
func (_c *OrdersCreate) SetTimeoutJobID(v string) *OrdersCreate {
|
||||
_c.mutation.SetTimeoutJobID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableTimeoutJobID sets the "timeout_job_id" field if the given value is not nil.
|
||||
func (_c *OrdersCreate) SetNillableTimeoutJobID(v *string) *OrdersCreate {
|
||||
if v != nil {
|
||||
_c.SetTimeoutJobID(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetSearchText sets the "search_text" field.
|
||||
func (_c *OrdersCreate) SetSearchText(v string) *OrdersCreate {
|
||||
_c.mutation.SetSearchText(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableSearchText sets the "search_text" field if the given value is not nil.
|
||||
func (_c *OrdersCreate) SetNillableSearchText(v *string) *OrdersCreate {
|
||||
if v != nil {
|
||||
_c.SetSearchText(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (_c *OrdersCreate) SetCreatedAt(v time.Time) *OrdersCreate {
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (_c *OrdersCreate) SetNillableCreatedAt(v *time.Time) *OrdersCreate {
|
||||
if v != nil {
|
||||
_c.SetCreatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetAcceptedAt sets the "accepted_at" field.
|
||||
func (_c *OrdersCreate) SetAcceptedAt(v time.Time) *OrdersCreate {
|
||||
_c.mutation.SetAcceptedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableAcceptedAt sets the "accepted_at" field if the given value is not nil.
|
||||
func (_c *OrdersCreate) SetNillableAcceptedAt(v *time.Time) *OrdersCreate {
|
||||
if v != nil {
|
||||
_c.SetAcceptedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetClosedAt sets the "closed_at" field.
|
||||
func (_c *OrdersCreate) SetClosedAt(v time.Time) *OrdersCreate {
|
||||
_c.mutation.SetClosedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableClosedAt sets the "closed_at" field if the given value is not nil.
|
||||
func (_c *OrdersCreate) SetNillableClosedAt(v *time.Time) *OrdersCreate {
|
||||
if v != nil {
|
||||
_c.SetClosedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCompletedAt sets the "completed_at" field.
|
||||
func (_c *OrdersCreate) SetCompletedAt(v time.Time) *OrdersCreate {
|
||||
_c.mutation.SetCompletedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCompletedAt sets the "completed_at" field if the given value is not nil.
|
||||
func (_c *OrdersCreate) SetNillableCompletedAt(v *time.Time) *OrdersCreate {
|
||||
if v != nil {
|
||||
_c.SetCompletedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCancelledAt sets the "cancelled_at" field.
|
||||
func (_c *OrdersCreate) SetCancelledAt(v time.Time) *OrdersCreate {
|
||||
_c.mutation.SetCancelledAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCancelledAt sets the "cancelled_at" field if the given value is not nil.
|
||||
func (_c *OrdersCreate) SetNillableCancelledAt(v *time.Time) *OrdersCreate {
|
||||
if v != nil {
|
||||
_c.SetCancelledAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_c *OrdersCreate) SetUpdatedAt(v time.Time) *OrdersCreate {
|
||||
_c.mutation.SetUpdatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (_c *OrdersCreate) SetNillableUpdatedAt(v *time.Time) *OrdersCreate {
|
||||
if v != nil {
|
||||
_c.SetUpdatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (_c *OrdersCreate) SetID(v int64) *OrdersCreate {
|
||||
_c.mutation.SetID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the OrdersMutation object of the builder.
|
||||
func (_c *OrdersCreate) Mutation() *OrdersMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Orders in the database.
|
||||
func (_c *OrdersCreate) Save(ctx context.Context) (*Orders, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *OrdersCreate) SaveX(ctx context.Context) *Orders {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *OrdersCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *OrdersCreate) 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 *OrdersCreate) defaults() {
|
||||
if _, ok := _c.mutation.Status(); !ok {
|
||||
v := orders.DefaultStatus
|
||||
_c.mutation.SetStatus(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Version(); !ok {
|
||||
v := orders.DefaultVersion
|
||||
_c.mutation.SetVersion(v)
|
||||
}
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
v := orders.DefaultCreatedAt()
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
}
|
||||
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||
v := orders.DefaultUpdatedAt()
|
||||
_c.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *OrdersCreate) check() error {
|
||||
if _, ok := _c.mutation.ConsumerID(); !ok {
|
||||
return &ValidationError{Name: "consumer_id", err: errors.New(`models: missing required field "Orders.consumer_id"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.ConsumerName(); !ok {
|
||||
return &ValidationError{Name: "consumer_name", err: errors.New(`models: missing required field "Orders.consumer_name"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.ConsumerName(); ok {
|
||||
if err := orders.ConsumerNameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "consumer_name", err: fmt.Errorf(`models: validator failed for field "Orders.consumer_name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.PlayerID(); !ok {
|
||||
return &ValidationError{Name: "player_id", err: errors.New(`models: missing required field "Orders.player_id"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.PlayerName(); !ok {
|
||||
return &ValidationError{Name: "player_name", err: errors.New(`models: missing required field "Orders.player_name"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.PlayerName(); ok {
|
||||
if err := orders.PlayerNameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "player_name", err: fmt.Errorf(`models: validator failed for field "Orders.player_name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _c.mutation.ShopName(); ok {
|
||||
if err := orders.ShopNameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "shop_name", err: fmt.Errorf(`models: validator failed for field "Orders.shop_name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.ServiceSnapshot(); !ok {
|
||||
return &ValidationError{Name: "service_snapshot", err: errors.New(`models: missing required field "Orders.service_snapshot"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Status(); !ok {
|
||||
return &ValidationError{Name: "status", err: errors.New(`models: missing required field "Orders.status"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Status(); ok {
|
||||
if err := orders.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`models: validator failed for field "Orders.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.TotalPrice(); !ok {
|
||||
return &ValidationError{Name: "total_price", err: errors.New(`models: missing required field "Orders.total_price"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Version(); !ok {
|
||||
return &ValidationError{Name: "version", err: errors.New(`models: missing required field "Orders.version"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.TimeoutJobID(); ok {
|
||||
if err := orders.TimeoutJobIDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "timeout_job_id", err: fmt.Errorf(`models: validator failed for field "Orders.timeout_job_id": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`models: missing required field "Orders.created_at"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||
return &ValidationError{Name: "updated_at", err: errors.New(`models: missing required field "Orders.updated_at"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *OrdersCreate) sqlSave(ctx context.Context) (*Orders, 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 *OrdersCreate) createSpec() (*Orders, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Orders{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(orders.Table, sqlgraph.NewFieldSpec(orders.FieldID, field.TypeInt64))
|
||||
)
|
||||
if id, ok := _c.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = id
|
||||
}
|
||||
if value, ok := _c.mutation.ConsumerID(); ok {
|
||||
_spec.SetField(orders.FieldConsumerID, field.TypeInt64, value)
|
||||
_node.ConsumerID = value
|
||||
}
|
||||
if value, ok := _c.mutation.ConsumerName(); ok {
|
||||
_spec.SetField(orders.FieldConsumerName, field.TypeString, value)
|
||||
_node.ConsumerName = value
|
||||
}
|
||||
if value, ok := _c.mutation.PlayerID(); ok {
|
||||
_spec.SetField(orders.FieldPlayerID, field.TypeInt64, value)
|
||||
_node.PlayerID = value
|
||||
}
|
||||
if value, ok := _c.mutation.PlayerName(); ok {
|
||||
_spec.SetField(orders.FieldPlayerName, field.TypeString, value)
|
||||
_node.PlayerName = value
|
||||
}
|
||||
if value, ok := _c.mutation.ShopID(); ok {
|
||||
_spec.SetField(orders.FieldShopID, field.TypeInt64, value)
|
||||
_node.ShopID = &value
|
||||
}
|
||||
if value, ok := _c.mutation.ShopName(); ok {
|
||||
_spec.SetField(orders.FieldShopName, field.TypeString, value)
|
||||
_node.ShopName = &value
|
||||
}
|
||||
if value, ok := _c.mutation.ServiceSnapshot(); ok {
|
||||
_spec.SetField(orders.FieldServiceSnapshot, field.TypeJSON, value)
|
||||
_node.ServiceSnapshot = value
|
||||
}
|
||||
if value, ok := _c.mutation.Status(); ok {
|
||||
_spec.SetField(orders.FieldStatus, field.TypeString, value)
|
||||
_node.Status = value
|
||||
}
|
||||
if value, ok := _c.mutation.TotalPrice(); ok {
|
||||
_spec.SetField(orders.FieldTotalPrice, field.TypeOther, value)
|
||||
_node.TotalPrice = value
|
||||
}
|
||||
if value, ok := _c.mutation.Note(); ok {
|
||||
_spec.SetField(orders.FieldNote, field.TypeString, value)
|
||||
_node.Note = &value
|
||||
}
|
||||
if value, ok := _c.mutation.Version(); ok {
|
||||
_spec.SetField(orders.FieldVersion, field.TypeInt, value)
|
||||
_node.Version = value
|
||||
}
|
||||
if value, ok := _c.mutation.TimeoutJobID(); ok {
|
||||
_spec.SetField(orders.FieldTimeoutJobID, field.TypeString, value)
|
||||
_node.TimeoutJobID = &value
|
||||
}
|
||||
if value, ok := _c.mutation.SearchText(); ok {
|
||||
_spec.SetField(orders.FieldSearchText, field.TypeString, value)
|
||||
_node.SearchText = &value
|
||||
}
|
||||
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(orders.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := _c.mutation.AcceptedAt(); ok {
|
||||
_spec.SetField(orders.FieldAcceptedAt, field.TypeTime, value)
|
||||
_node.AcceptedAt = &value
|
||||
}
|
||||
if value, ok := _c.mutation.ClosedAt(); ok {
|
||||
_spec.SetField(orders.FieldClosedAt, field.TypeTime, value)
|
||||
_node.ClosedAt = &value
|
||||
}
|
||||
if value, ok := _c.mutation.CompletedAt(); ok {
|
||||
_spec.SetField(orders.FieldCompletedAt, field.TypeTime, value)
|
||||
_node.CompletedAt = &value
|
||||
}
|
||||
if value, ok := _c.mutation.CancelledAt(); ok {
|
||||
_spec.SetField(orders.FieldCancelledAt, field.TypeTime, value)
|
||||
_node.CancelledAt = &value
|
||||
}
|
||||
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(orders.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// OrdersCreateBulk is the builder for creating many Orders entities in bulk.
|
||||
type OrdersCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*OrdersCreate
|
||||
}
|
||||
|
||||
// Save creates the Orders entities in the database.
|
||||
func (_c *OrdersCreateBulk) Save(ctx context.Context) ([]*Orders, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Orders, 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.(*OrdersMutation)
|
||||
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 *OrdersCreateBulk) SaveX(ctx context.Context) []*Orders {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *OrdersCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *OrdersCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"juwan-backend/app/order/rpc/internal/models/orders"
|
||||
"juwan-backend/app/order/rpc/internal/models/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// OrdersDelete is the builder for deleting a Orders entity.
|
||||
type OrdersDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *OrdersMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the OrdersDelete builder.
|
||||
func (_d *OrdersDelete) Where(ps ...predicate.Orders) *OrdersDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *OrdersDelete) 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 *OrdersDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *OrdersDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(orders.Table, sqlgraph.NewFieldSpec(orders.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
|
||||
}
|
||||
|
||||
// OrdersDeleteOne is the builder for deleting a single Orders entity.
|
||||
type OrdersDeleteOne struct {
|
||||
_d *OrdersDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the OrdersDelete builder.
|
||||
func (_d *OrdersDeleteOne) Where(ps ...predicate.Orders) *OrdersDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *OrdersDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{orders.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *OrdersDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,527 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"juwan-backend/app/order/rpc/internal/models/orders"
|
||||
"juwan-backend/app/order/rpc/internal/models/predicate"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// OrdersQuery is the builder for querying Orders entities.
|
||||
type OrdersQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []orders.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Orders
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the OrdersQuery builder.
|
||||
func (_q *OrdersQuery) Where(ps ...predicate.Orders) *OrdersQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *OrdersQuery) Limit(limit int) *OrdersQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *OrdersQuery) Offset(offset int) *OrdersQuery {
|
||||
_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 *OrdersQuery) Unique(unique bool) *OrdersQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *OrdersQuery) Order(o ...orders.OrderOption) *OrdersQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// First returns the first Orders entity from the query.
|
||||
// Returns a *NotFoundError when no Orders was found.
|
||||
func (_q *OrdersQuery) First(ctx context.Context) (*Orders, 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{orders.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *OrdersQuery) FirstX(ctx context.Context) *Orders {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Orders ID from the query.
|
||||
// Returns a *NotFoundError when no Orders ID was found.
|
||||
func (_q *OrdersQuery) 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{orders.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *OrdersQuery) FirstIDX(ctx context.Context) int64 {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Orders entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Orders entity is found.
|
||||
// Returns a *NotFoundError when no Orders entities are found.
|
||||
func (_q *OrdersQuery) Only(ctx context.Context) (*Orders, 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{orders.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{orders.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *OrdersQuery) OnlyX(ctx context.Context) *Orders {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Orders ID in the query.
|
||||
// Returns a *NotSingularError when more than one Orders ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *OrdersQuery) 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{orders.Label}
|
||||
default:
|
||||
err = &NotSingularError{orders.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *OrdersQuery) 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 OrdersSlice.
|
||||
func (_q *OrdersQuery) All(ctx context.Context) ([]*Orders, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Orders, *OrdersQuery]()
|
||||
return withInterceptors[[]*Orders](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *OrdersQuery) AllX(ctx context.Context) []*Orders {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Orders IDs.
|
||||
func (_q *OrdersQuery) 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(orders.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *OrdersQuery) 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 *OrdersQuery) 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[*OrdersQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *OrdersQuery) 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 *OrdersQuery) 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 *OrdersQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the OrdersQuery 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 *OrdersQuery) Clone() *OrdersQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &OrdersQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]orders.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Orders{}, _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 {
|
||||
// ConsumerID int64 `json:"consumer_id,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Orders.Query().
|
||||
// GroupBy(orders.FieldConsumerID).
|
||||
// Aggregate(models.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *OrdersQuery) GroupBy(field string, fields ...string) *OrdersGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &OrdersGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = orders.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 {
|
||||
// ConsumerID int64 `json:"consumer_id,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Orders.Query().
|
||||
// Select(orders.FieldConsumerID).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *OrdersQuery) Select(fields ...string) *OrdersSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &OrdersSelect{OrdersQuery: _q}
|
||||
sbuild.label = orders.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a OrdersSelect configured with the given aggregations.
|
||||
func (_q *OrdersQuery) Aggregate(fns ...AggregateFunc) *OrdersSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *OrdersQuery) 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 !orders.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 *OrdersQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Orders, error) {
|
||||
var (
|
||||
nodes = []*Orders{}
|
||||
_spec = _q.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Orders).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Orders{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 *OrdersQuery) 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 *OrdersQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(orders.Table, orders.Columns, sqlgraph.NewFieldSpec(orders.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, orders.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != orders.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 *OrdersQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(orders.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = orders.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
|
||||
}
|
||||
|
||||
// OrdersGroupBy is the group-by builder for Orders entities.
|
||||
type OrdersGroupBy struct {
|
||||
selector
|
||||
build *OrdersQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *OrdersGroupBy) Aggregate(fns ...AggregateFunc) *OrdersGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *OrdersGroupBy) 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[*OrdersQuery, *OrdersGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *OrdersGroupBy) sqlScan(ctx context.Context, root *OrdersQuery, 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)
|
||||
}
|
||||
|
||||
// OrdersSelect is the builder for selecting fields of Orders entities.
|
||||
type OrdersSelect struct {
|
||||
*OrdersQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *OrdersSelect) Aggregate(fns ...AggregateFunc) *OrdersSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *OrdersSelect) 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[*OrdersQuery, *OrdersSelect](ctx, _s.OrdersQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *OrdersSelect) sqlScan(ctx context.Context, root *OrdersQuery, 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)
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,191 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"juwan-backend/app/order/rpc/internal/models/orderstatelogs"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// OrderStateLogs is the model entity for the OrderStateLogs schema.
|
||||
type OrderStateLogs struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int64 `json:"id,omitempty"`
|
||||
// OrderID holds the value of the "order_id" field.
|
||||
OrderID int64 `json:"order_id,omitempty"`
|
||||
// FromStatus holds the value of the "from_status" field.
|
||||
FromStatus *string `json:"from_status,omitempty"`
|
||||
// ToStatus holds the value of the "to_status" field.
|
||||
ToStatus string `json:"to_status,omitempty"`
|
||||
// Action holds the value of the "action" field.
|
||||
Action string `json:"action,omitempty"`
|
||||
// ActorID holds the value of the "actor_id" field.
|
||||
ActorID int64 `json:"actor_id,omitempty"`
|
||||
// ActorRole holds the value of the "actor_role" field.
|
||||
ActorRole string `json:"actor_role,omitempty"`
|
||||
// Metadata holds the value of the "metadata" field.
|
||||
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*OrderStateLogs) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case orderstatelogs.FieldMetadata:
|
||||
values[i] = new([]byte)
|
||||
case orderstatelogs.FieldID, orderstatelogs.FieldOrderID, orderstatelogs.FieldActorID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case orderstatelogs.FieldFromStatus, orderstatelogs.FieldToStatus, orderstatelogs.FieldAction, orderstatelogs.FieldActorRole:
|
||||
values[i] = new(sql.NullString)
|
||||
case orderstatelogs.FieldCreatedAt:
|
||||
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 OrderStateLogs fields.
|
||||
func (_m *OrderStateLogs) 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 orderstatelogs.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 orderstatelogs.FieldOrderID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field order_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.OrderID = value.Int64
|
||||
}
|
||||
case orderstatelogs.FieldFromStatus:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field from_status", values[i])
|
||||
} else if value.Valid {
|
||||
_m.FromStatus = new(string)
|
||||
*_m.FromStatus = value.String
|
||||
}
|
||||
case orderstatelogs.FieldToStatus:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field to_status", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ToStatus = value.String
|
||||
}
|
||||
case orderstatelogs.FieldAction:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field action", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Action = value.String
|
||||
}
|
||||
case orderstatelogs.FieldActorID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field actor_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ActorID = value.Int64
|
||||
}
|
||||
case orderstatelogs.FieldActorRole:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field actor_role", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ActorRole = value.String
|
||||
}
|
||||
case orderstatelogs.FieldMetadata:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field metadata", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &_m.Metadata); err != nil {
|
||||
return fmt.Errorf("unmarshal field metadata: %w", err)
|
||||
}
|
||||
}
|
||||
case orderstatelogs.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
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the OrderStateLogs.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *OrderStateLogs) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this OrderStateLogs.
|
||||
// Note that you need to call OrderStateLogs.Unwrap() before calling this method if this OrderStateLogs
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *OrderStateLogs) Update() *OrderStateLogsUpdateOne {
|
||||
return NewOrderStateLogsClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the OrderStateLogs 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 *OrderStateLogs) Unwrap() *OrderStateLogs {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("models: OrderStateLogs is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *OrderStateLogs) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("OrderStateLogs(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("order_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.OrderID))
|
||||
builder.WriteString(", ")
|
||||
if v := _m.FromStatus; v != nil {
|
||||
builder.WriteString("from_status=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("to_status=")
|
||||
builder.WriteString(_m.ToStatus)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("action=")
|
||||
builder.WriteString(_m.Action)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("actor_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.ActorID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("actor_role=")
|
||||
builder.WriteString(_m.ActorRole)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("metadata=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Metadata))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// OrderStateLogsSlice is a parsable slice of OrderStateLogs.
|
||||
type OrderStateLogsSlice []*OrderStateLogs
|
||||
@@ -0,0 +1,113 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package orderstatelogs
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the orderstatelogs type in the database.
|
||||
Label = "order_state_logs"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldOrderID holds the string denoting the order_id field in the database.
|
||||
FieldOrderID = "order_id"
|
||||
// FieldFromStatus holds the string denoting the from_status field in the database.
|
||||
FieldFromStatus = "from_status"
|
||||
// FieldToStatus holds the string denoting the to_status field in the database.
|
||||
FieldToStatus = "to_status"
|
||||
// FieldAction holds the string denoting the action field in the database.
|
||||
FieldAction = "action"
|
||||
// FieldActorID holds the string denoting the actor_id field in the database.
|
||||
FieldActorID = "actor_id"
|
||||
// FieldActorRole holds the string denoting the actor_role field in the database.
|
||||
FieldActorRole = "actor_role"
|
||||
// FieldMetadata holds the string denoting the metadata field in the database.
|
||||
FieldMetadata = "metadata"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// Table holds the table name of the orderstatelogs in the database.
|
||||
Table = "order_state_logs"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for orderstatelogs fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldOrderID,
|
||||
FieldFromStatus,
|
||||
FieldToStatus,
|
||||
FieldAction,
|
||||
FieldActorID,
|
||||
FieldActorRole,
|
||||
FieldMetadata,
|
||||
FieldCreatedAt,
|
||||
}
|
||||
|
||||
// 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 (
|
||||
// FromStatusValidator is a validator for the "from_status" field. It is called by the builders before save.
|
||||
FromStatusValidator func(string) error
|
||||
// ToStatusValidator is a validator for the "to_status" field. It is called by the builders before save.
|
||||
ToStatusValidator func(string) error
|
||||
// ActionValidator is a validator for the "action" field. It is called by the builders before save.
|
||||
ActionValidator func(string) error
|
||||
// ActorRoleValidator is a validator for the "actor_role" field. It is called by the builders before save.
|
||||
ActorRoleValidator 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 OrderStateLogs 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()
|
||||
}
|
||||
|
||||
// ByOrderID orders the results by the order_id field.
|
||||
func ByOrderID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldOrderID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByFromStatus orders the results by the from_status field.
|
||||
func ByFromStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldFromStatus, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByToStatus orders the results by the to_status field.
|
||||
func ByToStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldToStatus, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAction orders the results by the action field.
|
||||
func ByAction(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldAction, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByActorID orders the results by the actor_id field.
|
||||
func ByActorID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldActorID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByActorRole orders the results by the actor_role field.
|
||||
func ByActorRole(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldActorRole, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
@@ -0,0 +1,505 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package orderstatelogs
|
||||
|
||||
import (
|
||||
"juwan-backend/app/order/rpc/internal/models/predicate"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// OrderID applies equality check predicate on the "order_id" field. It's identical to OrderIDEQ.
|
||||
func OrderID(v int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEQ(FieldOrderID, v))
|
||||
}
|
||||
|
||||
// FromStatus applies equality check predicate on the "from_status" field. It's identical to FromStatusEQ.
|
||||
func FromStatus(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEQ(FieldFromStatus, v))
|
||||
}
|
||||
|
||||
// ToStatus applies equality check predicate on the "to_status" field. It's identical to ToStatusEQ.
|
||||
func ToStatus(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEQ(FieldToStatus, v))
|
||||
}
|
||||
|
||||
// Action applies equality check predicate on the "action" field. It's identical to ActionEQ.
|
||||
func Action(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEQ(FieldAction, v))
|
||||
}
|
||||
|
||||
// ActorID applies equality check predicate on the "actor_id" field. It's identical to ActorIDEQ.
|
||||
func ActorID(v int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEQ(FieldActorID, v))
|
||||
}
|
||||
|
||||
// ActorRole applies equality check predicate on the "actor_role" field. It's identical to ActorRoleEQ.
|
||||
func ActorRole(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEQ(FieldActorRole, v))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// OrderIDEQ applies the EQ predicate on the "order_id" field.
|
||||
func OrderIDEQ(v int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEQ(FieldOrderID, v))
|
||||
}
|
||||
|
||||
// OrderIDNEQ applies the NEQ predicate on the "order_id" field.
|
||||
func OrderIDNEQ(v int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNEQ(FieldOrderID, v))
|
||||
}
|
||||
|
||||
// OrderIDIn applies the In predicate on the "order_id" field.
|
||||
func OrderIDIn(vs ...int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldIn(FieldOrderID, vs...))
|
||||
}
|
||||
|
||||
// OrderIDNotIn applies the NotIn predicate on the "order_id" field.
|
||||
func OrderIDNotIn(vs ...int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNotIn(FieldOrderID, vs...))
|
||||
}
|
||||
|
||||
// OrderIDGT applies the GT predicate on the "order_id" field.
|
||||
func OrderIDGT(v int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldGT(FieldOrderID, v))
|
||||
}
|
||||
|
||||
// OrderIDGTE applies the GTE predicate on the "order_id" field.
|
||||
func OrderIDGTE(v int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldGTE(FieldOrderID, v))
|
||||
}
|
||||
|
||||
// OrderIDLT applies the LT predicate on the "order_id" field.
|
||||
func OrderIDLT(v int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldLT(FieldOrderID, v))
|
||||
}
|
||||
|
||||
// OrderIDLTE applies the LTE predicate on the "order_id" field.
|
||||
func OrderIDLTE(v int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldLTE(FieldOrderID, v))
|
||||
}
|
||||
|
||||
// FromStatusEQ applies the EQ predicate on the "from_status" field.
|
||||
func FromStatusEQ(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEQ(FieldFromStatus, v))
|
||||
}
|
||||
|
||||
// FromStatusNEQ applies the NEQ predicate on the "from_status" field.
|
||||
func FromStatusNEQ(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNEQ(FieldFromStatus, v))
|
||||
}
|
||||
|
||||
// FromStatusIn applies the In predicate on the "from_status" field.
|
||||
func FromStatusIn(vs ...string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldIn(FieldFromStatus, vs...))
|
||||
}
|
||||
|
||||
// FromStatusNotIn applies the NotIn predicate on the "from_status" field.
|
||||
func FromStatusNotIn(vs ...string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNotIn(FieldFromStatus, vs...))
|
||||
}
|
||||
|
||||
// FromStatusGT applies the GT predicate on the "from_status" field.
|
||||
func FromStatusGT(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldGT(FieldFromStatus, v))
|
||||
}
|
||||
|
||||
// FromStatusGTE applies the GTE predicate on the "from_status" field.
|
||||
func FromStatusGTE(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldGTE(FieldFromStatus, v))
|
||||
}
|
||||
|
||||
// FromStatusLT applies the LT predicate on the "from_status" field.
|
||||
func FromStatusLT(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldLT(FieldFromStatus, v))
|
||||
}
|
||||
|
||||
// FromStatusLTE applies the LTE predicate on the "from_status" field.
|
||||
func FromStatusLTE(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldLTE(FieldFromStatus, v))
|
||||
}
|
||||
|
||||
// FromStatusContains applies the Contains predicate on the "from_status" field.
|
||||
func FromStatusContains(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldContains(FieldFromStatus, v))
|
||||
}
|
||||
|
||||
// FromStatusHasPrefix applies the HasPrefix predicate on the "from_status" field.
|
||||
func FromStatusHasPrefix(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldHasPrefix(FieldFromStatus, v))
|
||||
}
|
||||
|
||||
// FromStatusHasSuffix applies the HasSuffix predicate on the "from_status" field.
|
||||
func FromStatusHasSuffix(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldHasSuffix(FieldFromStatus, v))
|
||||
}
|
||||
|
||||
// FromStatusIsNil applies the IsNil predicate on the "from_status" field.
|
||||
func FromStatusIsNil() predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldIsNull(FieldFromStatus))
|
||||
}
|
||||
|
||||
// FromStatusNotNil applies the NotNil predicate on the "from_status" field.
|
||||
func FromStatusNotNil() predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNotNull(FieldFromStatus))
|
||||
}
|
||||
|
||||
// FromStatusEqualFold applies the EqualFold predicate on the "from_status" field.
|
||||
func FromStatusEqualFold(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEqualFold(FieldFromStatus, v))
|
||||
}
|
||||
|
||||
// FromStatusContainsFold applies the ContainsFold predicate on the "from_status" field.
|
||||
func FromStatusContainsFold(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldContainsFold(FieldFromStatus, v))
|
||||
}
|
||||
|
||||
// ToStatusEQ applies the EQ predicate on the "to_status" field.
|
||||
func ToStatusEQ(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEQ(FieldToStatus, v))
|
||||
}
|
||||
|
||||
// ToStatusNEQ applies the NEQ predicate on the "to_status" field.
|
||||
func ToStatusNEQ(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNEQ(FieldToStatus, v))
|
||||
}
|
||||
|
||||
// ToStatusIn applies the In predicate on the "to_status" field.
|
||||
func ToStatusIn(vs ...string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldIn(FieldToStatus, vs...))
|
||||
}
|
||||
|
||||
// ToStatusNotIn applies the NotIn predicate on the "to_status" field.
|
||||
func ToStatusNotIn(vs ...string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNotIn(FieldToStatus, vs...))
|
||||
}
|
||||
|
||||
// ToStatusGT applies the GT predicate on the "to_status" field.
|
||||
func ToStatusGT(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldGT(FieldToStatus, v))
|
||||
}
|
||||
|
||||
// ToStatusGTE applies the GTE predicate on the "to_status" field.
|
||||
func ToStatusGTE(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldGTE(FieldToStatus, v))
|
||||
}
|
||||
|
||||
// ToStatusLT applies the LT predicate on the "to_status" field.
|
||||
func ToStatusLT(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldLT(FieldToStatus, v))
|
||||
}
|
||||
|
||||
// ToStatusLTE applies the LTE predicate on the "to_status" field.
|
||||
func ToStatusLTE(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldLTE(FieldToStatus, v))
|
||||
}
|
||||
|
||||
// ToStatusContains applies the Contains predicate on the "to_status" field.
|
||||
func ToStatusContains(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldContains(FieldToStatus, v))
|
||||
}
|
||||
|
||||
// ToStatusHasPrefix applies the HasPrefix predicate on the "to_status" field.
|
||||
func ToStatusHasPrefix(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldHasPrefix(FieldToStatus, v))
|
||||
}
|
||||
|
||||
// ToStatusHasSuffix applies the HasSuffix predicate on the "to_status" field.
|
||||
func ToStatusHasSuffix(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldHasSuffix(FieldToStatus, v))
|
||||
}
|
||||
|
||||
// ToStatusEqualFold applies the EqualFold predicate on the "to_status" field.
|
||||
func ToStatusEqualFold(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEqualFold(FieldToStatus, v))
|
||||
}
|
||||
|
||||
// ToStatusContainsFold applies the ContainsFold predicate on the "to_status" field.
|
||||
func ToStatusContainsFold(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldContainsFold(FieldToStatus, v))
|
||||
}
|
||||
|
||||
// ActionEQ applies the EQ predicate on the "action" field.
|
||||
func ActionEQ(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEQ(FieldAction, v))
|
||||
}
|
||||
|
||||
// ActionNEQ applies the NEQ predicate on the "action" field.
|
||||
func ActionNEQ(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNEQ(FieldAction, v))
|
||||
}
|
||||
|
||||
// ActionIn applies the In predicate on the "action" field.
|
||||
func ActionIn(vs ...string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldIn(FieldAction, vs...))
|
||||
}
|
||||
|
||||
// ActionNotIn applies the NotIn predicate on the "action" field.
|
||||
func ActionNotIn(vs ...string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNotIn(FieldAction, vs...))
|
||||
}
|
||||
|
||||
// ActionGT applies the GT predicate on the "action" field.
|
||||
func ActionGT(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldGT(FieldAction, v))
|
||||
}
|
||||
|
||||
// ActionGTE applies the GTE predicate on the "action" field.
|
||||
func ActionGTE(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldGTE(FieldAction, v))
|
||||
}
|
||||
|
||||
// ActionLT applies the LT predicate on the "action" field.
|
||||
func ActionLT(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldLT(FieldAction, v))
|
||||
}
|
||||
|
||||
// ActionLTE applies the LTE predicate on the "action" field.
|
||||
func ActionLTE(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldLTE(FieldAction, v))
|
||||
}
|
||||
|
||||
// ActionContains applies the Contains predicate on the "action" field.
|
||||
func ActionContains(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldContains(FieldAction, v))
|
||||
}
|
||||
|
||||
// ActionHasPrefix applies the HasPrefix predicate on the "action" field.
|
||||
func ActionHasPrefix(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldHasPrefix(FieldAction, v))
|
||||
}
|
||||
|
||||
// ActionHasSuffix applies the HasSuffix predicate on the "action" field.
|
||||
func ActionHasSuffix(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldHasSuffix(FieldAction, v))
|
||||
}
|
||||
|
||||
// ActionEqualFold applies the EqualFold predicate on the "action" field.
|
||||
func ActionEqualFold(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEqualFold(FieldAction, v))
|
||||
}
|
||||
|
||||
// ActionContainsFold applies the ContainsFold predicate on the "action" field.
|
||||
func ActionContainsFold(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldContainsFold(FieldAction, v))
|
||||
}
|
||||
|
||||
// ActorIDEQ applies the EQ predicate on the "actor_id" field.
|
||||
func ActorIDEQ(v int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEQ(FieldActorID, v))
|
||||
}
|
||||
|
||||
// ActorIDNEQ applies the NEQ predicate on the "actor_id" field.
|
||||
func ActorIDNEQ(v int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNEQ(FieldActorID, v))
|
||||
}
|
||||
|
||||
// ActorIDIn applies the In predicate on the "actor_id" field.
|
||||
func ActorIDIn(vs ...int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldIn(FieldActorID, vs...))
|
||||
}
|
||||
|
||||
// ActorIDNotIn applies the NotIn predicate on the "actor_id" field.
|
||||
func ActorIDNotIn(vs ...int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNotIn(FieldActorID, vs...))
|
||||
}
|
||||
|
||||
// ActorIDGT applies the GT predicate on the "actor_id" field.
|
||||
func ActorIDGT(v int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldGT(FieldActorID, v))
|
||||
}
|
||||
|
||||
// ActorIDGTE applies the GTE predicate on the "actor_id" field.
|
||||
func ActorIDGTE(v int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldGTE(FieldActorID, v))
|
||||
}
|
||||
|
||||
// ActorIDLT applies the LT predicate on the "actor_id" field.
|
||||
func ActorIDLT(v int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldLT(FieldActorID, v))
|
||||
}
|
||||
|
||||
// ActorIDLTE applies the LTE predicate on the "actor_id" field.
|
||||
func ActorIDLTE(v int64) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldLTE(FieldActorID, v))
|
||||
}
|
||||
|
||||
// ActorRoleEQ applies the EQ predicate on the "actor_role" field.
|
||||
func ActorRoleEQ(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEQ(FieldActorRole, v))
|
||||
}
|
||||
|
||||
// ActorRoleNEQ applies the NEQ predicate on the "actor_role" field.
|
||||
func ActorRoleNEQ(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNEQ(FieldActorRole, v))
|
||||
}
|
||||
|
||||
// ActorRoleIn applies the In predicate on the "actor_role" field.
|
||||
func ActorRoleIn(vs ...string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldIn(FieldActorRole, vs...))
|
||||
}
|
||||
|
||||
// ActorRoleNotIn applies the NotIn predicate on the "actor_role" field.
|
||||
func ActorRoleNotIn(vs ...string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNotIn(FieldActorRole, vs...))
|
||||
}
|
||||
|
||||
// ActorRoleGT applies the GT predicate on the "actor_role" field.
|
||||
func ActorRoleGT(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldGT(FieldActorRole, v))
|
||||
}
|
||||
|
||||
// ActorRoleGTE applies the GTE predicate on the "actor_role" field.
|
||||
func ActorRoleGTE(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldGTE(FieldActorRole, v))
|
||||
}
|
||||
|
||||
// ActorRoleLT applies the LT predicate on the "actor_role" field.
|
||||
func ActorRoleLT(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldLT(FieldActorRole, v))
|
||||
}
|
||||
|
||||
// ActorRoleLTE applies the LTE predicate on the "actor_role" field.
|
||||
func ActorRoleLTE(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldLTE(FieldActorRole, v))
|
||||
}
|
||||
|
||||
// ActorRoleContains applies the Contains predicate on the "actor_role" field.
|
||||
func ActorRoleContains(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldContains(FieldActorRole, v))
|
||||
}
|
||||
|
||||
// ActorRoleHasPrefix applies the HasPrefix predicate on the "actor_role" field.
|
||||
func ActorRoleHasPrefix(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldHasPrefix(FieldActorRole, v))
|
||||
}
|
||||
|
||||
// ActorRoleHasSuffix applies the HasSuffix predicate on the "actor_role" field.
|
||||
func ActorRoleHasSuffix(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldHasSuffix(FieldActorRole, v))
|
||||
}
|
||||
|
||||
// ActorRoleEqualFold applies the EqualFold predicate on the "actor_role" field.
|
||||
func ActorRoleEqualFold(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEqualFold(FieldActorRole, v))
|
||||
}
|
||||
|
||||
// ActorRoleContainsFold applies the ContainsFold predicate on the "actor_role" field.
|
||||
func ActorRoleContainsFold(v string) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldContainsFold(FieldActorRole, v))
|
||||
}
|
||||
|
||||
// MetadataIsNil applies the IsNil predicate on the "metadata" field.
|
||||
func MetadataIsNil() predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldIsNull(FieldMetadata))
|
||||
}
|
||||
|
||||
// MetadataNotNil applies the NotNil predicate on the "metadata" field.
|
||||
func MetadataNotNil() predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNotNull(FieldMetadata))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.OrderStateLogs) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.OrderStateLogs) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.OrderStateLogs) predicate.OrderStateLogs {
|
||||
return predicate.OrderStateLogs(sql.NotPredicates(p))
|
||||
}
|
||||
@@ -0,0 +1,327 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"juwan-backend/app/order/rpc/internal/models/orderstatelogs"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// OrderStateLogsCreate is the builder for creating a OrderStateLogs entity.
|
||||
type OrderStateLogsCreate struct {
|
||||
config
|
||||
mutation *OrderStateLogsMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetOrderID sets the "order_id" field.
|
||||
func (_c *OrderStateLogsCreate) SetOrderID(v int64) *OrderStateLogsCreate {
|
||||
_c.mutation.SetOrderID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetFromStatus sets the "from_status" field.
|
||||
func (_c *OrderStateLogsCreate) SetFromStatus(v string) *OrderStateLogsCreate {
|
||||
_c.mutation.SetFromStatus(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableFromStatus sets the "from_status" field if the given value is not nil.
|
||||
func (_c *OrderStateLogsCreate) SetNillableFromStatus(v *string) *OrderStateLogsCreate {
|
||||
if v != nil {
|
||||
_c.SetFromStatus(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetToStatus sets the "to_status" field.
|
||||
func (_c *OrderStateLogsCreate) SetToStatus(v string) *OrderStateLogsCreate {
|
||||
_c.mutation.SetToStatus(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetAction sets the "action" field.
|
||||
func (_c *OrderStateLogsCreate) SetAction(v string) *OrderStateLogsCreate {
|
||||
_c.mutation.SetAction(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetActorID sets the "actor_id" field.
|
||||
func (_c *OrderStateLogsCreate) SetActorID(v int64) *OrderStateLogsCreate {
|
||||
_c.mutation.SetActorID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetActorRole sets the "actor_role" field.
|
||||
func (_c *OrderStateLogsCreate) SetActorRole(v string) *OrderStateLogsCreate {
|
||||
_c.mutation.SetActorRole(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetMetadata sets the "metadata" field.
|
||||
func (_c *OrderStateLogsCreate) SetMetadata(v map[string]interface{}) *OrderStateLogsCreate {
|
||||
_c.mutation.SetMetadata(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (_c *OrderStateLogsCreate) SetCreatedAt(v time.Time) *OrderStateLogsCreate {
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (_c *OrderStateLogsCreate) SetNillableCreatedAt(v *time.Time) *OrderStateLogsCreate {
|
||||
if v != nil {
|
||||
_c.SetCreatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (_c *OrderStateLogsCreate) SetID(v int64) *OrderStateLogsCreate {
|
||||
_c.mutation.SetID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the OrderStateLogsMutation object of the builder.
|
||||
func (_c *OrderStateLogsCreate) Mutation() *OrderStateLogsMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the OrderStateLogs in the database.
|
||||
func (_c *OrderStateLogsCreate) Save(ctx context.Context) (*OrderStateLogs, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *OrderStateLogsCreate) SaveX(ctx context.Context) *OrderStateLogs {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *OrderStateLogsCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *OrderStateLogsCreate) 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 *OrderStateLogsCreate) defaults() {
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
v := orderstatelogs.DefaultCreatedAt()
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *OrderStateLogsCreate) check() error {
|
||||
if _, ok := _c.mutation.OrderID(); !ok {
|
||||
return &ValidationError{Name: "order_id", err: errors.New(`models: missing required field "OrderStateLogs.order_id"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.FromStatus(); ok {
|
||||
if err := orderstatelogs.FromStatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "from_status", err: fmt.Errorf(`models: validator failed for field "OrderStateLogs.from_status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.ToStatus(); !ok {
|
||||
return &ValidationError{Name: "to_status", err: errors.New(`models: missing required field "OrderStateLogs.to_status"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.ToStatus(); ok {
|
||||
if err := orderstatelogs.ToStatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "to_status", err: fmt.Errorf(`models: validator failed for field "OrderStateLogs.to_status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.Action(); !ok {
|
||||
return &ValidationError{Name: "action", err: errors.New(`models: missing required field "OrderStateLogs.action"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Action(); ok {
|
||||
if err := orderstatelogs.ActionValidator(v); err != nil {
|
||||
return &ValidationError{Name: "action", err: fmt.Errorf(`models: validator failed for field "OrderStateLogs.action": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.ActorID(); !ok {
|
||||
return &ValidationError{Name: "actor_id", err: errors.New(`models: missing required field "OrderStateLogs.actor_id"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.ActorRole(); !ok {
|
||||
return &ValidationError{Name: "actor_role", err: errors.New(`models: missing required field "OrderStateLogs.actor_role"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.ActorRole(); ok {
|
||||
if err := orderstatelogs.ActorRoleValidator(v); err != nil {
|
||||
return &ValidationError{Name: "actor_role", err: fmt.Errorf(`models: validator failed for field "OrderStateLogs.actor_role": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`models: missing required field "OrderStateLogs.created_at"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *OrderStateLogsCreate) sqlSave(ctx context.Context) (*OrderStateLogs, 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 *OrderStateLogsCreate) createSpec() (*OrderStateLogs, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &OrderStateLogs{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(orderstatelogs.Table, sqlgraph.NewFieldSpec(orderstatelogs.FieldID, field.TypeInt64))
|
||||
)
|
||||
if id, ok := _c.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = id
|
||||
}
|
||||
if value, ok := _c.mutation.OrderID(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldOrderID, field.TypeInt64, value)
|
||||
_node.OrderID = value
|
||||
}
|
||||
if value, ok := _c.mutation.FromStatus(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldFromStatus, field.TypeString, value)
|
||||
_node.FromStatus = &value
|
||||
}
|
||||
if value, ok := _c.mutation.ToStatus(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldToStatus, field.TypeString, value)
|
||||
_node.ToStatus = value
|
||||
}
|
||||
if value, ok := _c.mutation.Action(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldAction, field.TypeString, value)
|
||||
_node.Action = value
|
||||
}
|
||||
if value, ok := _c.mutation.ActorID(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldActorID, field.TypeInt64, value)
|
||||
_node.ActorID = value
|
||||
}
|
||||
if value, ok := _c.mutation.ActorRole(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldActorRole, field.TypeString, value)
|
||||
_node.ActorRole = value
|
||||
}
|
||||
if value, ok := _c.mutation.Metadata(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldMetadata, field.TypeJSON, value)
|
||||
_node.Metadata = value
|
||||
}
|
||||
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// OrderStateLogsCreateBulk is the builder for creating many OrderStateLogs entities in bulk.
|
||||
type OrderStateLogsCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*OrderStateLogsCreate
|
||||
}
|
||||
|
||||
// Save creates the OrderStateLogs entities in the database.
|
||||
func (_c *OrderStateLogsCreateBulk) Save(ctx context.Context) ([]*OrderStateLogs, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*OrderStateLogs, 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.(*OrderStateLogsMutation)
|
||||
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 *OrderStateLogsCreateBulk) SaveX(ctx context.Context) []*OrderStateLogs {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *OrderStateLogsCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *OrderStateLogsCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"juwan-backend/app/order/rpc/internal/models/orderstatelogs"
|
||||
"juwan-backend/app/order/rpc/internal/models/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// OrderStateLogsDelete is the builder for deleting a OrderStateLogs entity.
|
||||
type OrderStateLogsDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *OrderStateLogsMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the OrderStateLogsDelete builder.
|
||||
func (_d *OrderStateLogsDelete) Where(ps ...predicate.OrderStateLogs) *OrderStateLogsDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *OrderStateLogsDelete) 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 *OrderStateLogsDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *OrderStateLogsDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(orderstatelogs.Table, sqlgraph.NewFieldSpec(orderstatelogs.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
|
||||
}
|
||||
|
||||
// OrderStateLogsDeleteOne is the builder for deleting a single OrderStateLogs entity.
|
||||
type OrderStateLogsDeleteOne struct {
|
||||
_d *OrderStateLogsDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the OrderStateLogsDelete builder.
|
||||
func (_d *OrderStateLogsDeleteOne) Where(ps ...predicate.OrderStateLogs) *OrderStateLogsDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *OrderStateLogsDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{orderstatelogs.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *OrderStateLogsDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,527 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"juwan-backend/app/order/rpc/internal/models/orderstatelogs"
|
||||
"juwan-backend/app/order/rpc/internal/models/predicate"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// OrderStateLogsQuery is the builder for querying OrderStateLogs entities.
|
||||
type OrderStateLogsQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []orderstatelogs.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.OrderStateLogs
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the OrderStateLogsQuery builder.
|
||||
func (_q *OrderStateLogsQuery) Where(ps ...predicate.OrderStateLogs) *OrderStateLogsQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *OrderStateLogsQuery) Limit(limit int) *OrderStateLogsQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *OrderStateLogsQuery) Offset(offset int) *OrderStateLogsQuery {
|
||||
_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 *OrderStateLogsQuery) Unique(unique bool) *OrderStateLogsQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *OrderStateLogsQuery) Order(o ...orderstatelogs.OrderOption) *OrderStateLogsQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// First returns the first OrderStateLogs entity from the query.
|
||||
// Returns a *NotFoundError when no OrderStateLogs was found.
|
||||
func (_q *OrderStateLogsQuery) First(ctx context.Context) (*OrderStateLogs, 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{orderstatelogs.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *OrderStateLogsQuery) FirstX(ctx context.Context) *OrderStateLogs {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first OrderStateLogs ID from the query.
|
||||
// Returns a *NotFoundError when no OrderStateLogs ID was found.
|
||||
func (_q *OrderStateLogsQuery) 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{orderstatelogs.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *OrderStateLogsQuery) FirstIDX(ctx context.Context) int64 {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single OrderStateLogs entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one OrderStateLogs entity is found.
|
||||
// Returns a *NotFoundError when no OrderStateLogs entities are found.
|
||||
func (_q *OrderStateLogsQuery) Only(ctx context.Context) (*OrderStateLogs, 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{orderstatelogs.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{orderstatelogs.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *OrderStateLogsQuery) OnlyX(ctx context.Context) *OrderStateLogs {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only OrderStateLogs ID in the query.
|
||||
// Returns a *NotSingularError when more than one OrderStateLogs ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *OrderStateLogsQuery) 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{orderstatelogs.Label}
|
||||
default:
|
||||
err = &NotSingularError{orderstatelogs.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *OrderStateLogsQuery) 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 OrderStateLogsSlice.
|
||||
func (_q *OrderStateLogsQuery) All(ctx context.Context) ([]*OrderStateLogs, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*OrderStateLogs, *OrderStateLogsQuery]()
|
||||
return withInterceptors[[]*OrderStateLogs](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *OrderStateLogsQuery) AllX(ctx context.Context) []*OrderStateLogs {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of OrderStateLogs IDs.
|
||||
func (_q *OrderStateLogsQuery) 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(orderstatelogs.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *OrderStateLogsQuery) 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 *OrderStateLogsQuery) 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[*OrderStateLogsQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *OrderStateLogsQuery) 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 *OrderStateLogsQuery) 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 *OrderStateLogsQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the OrderStateLogsQuery 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 *OrderStateLogsQuery) Clone() *OrderStateLogsQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &OrderStateLogsQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]orderstatelogs.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.OrderStateLogs{}, _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 {
|
||||
// OrderID int64 `json:"order_id,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.OrderStateLogs.Query().
|
||||
// GroupBy(orderstatelogs.FieldOrderID).
|
||||
// Aggregate(models.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *OrderStateLogsQuery) GroupBy(field string, fields ...string) *OrderStateLogsGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &OrderStateLogsGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = orderstatelogs.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 {
|
||||
// OrderID int64 `json:"order_id,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.OrderStateLogs.Query().
|
||||
// Select(orderstatelogs.FieldOrderID).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *OrderStateLogsQuery) Select(fields ...string) *OrderStateLogsSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &OrderStateLogsSelect{OrderStateLogsQuery: _q}
|
||||
sbuild.label = orderstatelogs.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a OrderStateLogsSelect configured with the given aggregations.
|
||||
func (_q *OrderStateLogsQuery) Aggregate(fns ...AggregateFunc) *OrderStateLogsSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *OrderStateLogsQuery) 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 !orderstatelogs.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 *OrderStateLogsQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*OrderStateLogs, error) {
|
||||
var (
|
||||
nodes = []*OrderStateLogs{}
|
||||
_spec = _q.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*OrderStateLogs).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &OrderStateLogs{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 *OrderStateLogsQuery) 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 *OrderStateLogsQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(orderstatelogs.Table, orderstatelogs.Columns, sqlgraph.NewFieldSpec(orderstatelogs.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, orderstatelogs.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != orderstatelogs.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 *OrderStateLogsQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(orderstatelogs.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = orderstatelogs.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
|
||||
}
|
||||
|
||||
// OrderStateLogsGroupBy is the group-by builder for OrderStateLogs entities.
|
||||
type OrderStateLogsGroupBy struct {
|
||||
selector
|
||||
build *OrderStateLogsQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *OrderStateLogsGroupBy) Aggregate(fns ...AggregateFunc) *OrderStateLogsGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *OrderStateLogsGroupBy) 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[*OrderStateLogsQuery, *OrderStateLogsGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *OrderStateLogsGroupBy) sqlScan(ctx context.Context, root *OrderStateLogsQuery, 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)
|
||||
}
|
||||
|
||||
// OrderStateLogsSelect is the builder for selecting fields of OrderStateLogs entities.
|
||||
type OrderStateLogsSelect struct {
|
||||
*OrderStateLogsQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *OrderStateLogsSelect) Aggregate(fns ...AggregateFunc) *OrderStateLogsSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *OrderStateLogsSelect) 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[*OrderStateLogsQuery, *OrderStateLogsSelect](ctx, _s.OrderStateLogsQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *OrderStateLogsSelect) sqlScan(ctx context.Context, root *OrderStateLogsQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*_s.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
@@ -0,0 +1,529 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"juwan-backend/app/order/rpc/internal/models/orderstatelogs"
|
||||
"juwan-backend/app/order/rpc/internal/models/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// OrderStateLogsUpdate is the builder for updating OrderStateLogs entities.
|
||||
type OrderStateLogsUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *OrderStateLogsMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the OrderStateLogsUpdate builder.
|
||||
func (_u *OrderStateLogsUpdate) Where(ps ...predicate.OrderStateLogs) *OrderStateLogsUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOrderID sets the "order_id" field.
|
||||
func (_u *OrderStateLogsUpdate) SetOrderID(v int64) *OrderStateLogsUpdate {
|
||||
_u.mutation.ResetOrderID()
|
||||
_u.mutation.SetOrderID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableOrderID sets the "order_id" field if the given value is not nil.
|
||||
func (_u *OrderStateLogsUpdate) SetNillableOrderID(v *int64) *OrderStateLogsUpdate {
|
||||
if v != nil {
|
||||
_u.SetOrderID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddOrderID adds value to the "order_id" field.
|
||||
func (_u *OrderStateLogsUpdate) AddOrderID(v int64) *OrderStateLogsUpdate {
|
||||
_u.mutation.AddOrderID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetFromStatus sets the "from_status" field.
|
||||
func (_u *OrderStateLogsUpdate) SetFromStatus(v string) *OrderStateLogsUpdate {
|
||||
_u.mutation.SetFromStatus(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableFromStatus sets the "from_status" field if the given value is not nil.
|
||||
func (_u *OrderStateLogsUpdate) SetNillableFromStatus(v *string) *OrderStateLogsUpdate {
|
||||
if v != nil {
|
||||
_u.SetFromStatus(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearFromStatus clears the value of the "from_status" field.
|
||||
func (_u *OrderStateLogsUpdate) ClearFromStatus() *OrderStateLogsUpdate {
|
||||
_u.mutation.ClearFromStatus()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetToStatus sets the "to_status" field.
|
||||
func (_u *OrderStateLogsUpdate) SetToStatus(v string) *OrderStateLogsUpdate {
|
||||
_u.mutation.SetToStatus(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableToStatus sets the "to_status" field if the given value is not nil.
|
||||
func (_u *OrderStateLogsUpdate) SetNillableToStatus(v *string) *OrderStateLogsUpdate {
|
||||
if v != nil {
|
||||
_u.SetToStatus(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetAction sets the "action" field.
|
||||
func (_u *OrderStateLogsUpdate) SetAction(v string) *OrderStateLogsUpdate {
|
||||
_u.mutation.SetAction(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAction sets the "action" field if the given value is not nil.
|
||||
func (_u *OrderStateLogsUpdate) SetNillableAction(v *string) *OrderStateLogsUpdate {
|
||||
if v != nil {
|
||||
_u.SetAction(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetActorID sets the "actor_id" field.
|
||||
func (_u *OrderStateLogsUpdate) SetActorID(v int64) *OrderStateLogsUpdate {
|
||||
_u.mutation.ResetActorID()
|
||||
_u.mutation.SetActorID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableActorID sets the "actor_id" field if the given value is not nil.
|
||||
func (_u *OrderStateLogsUpdate) SetNillableActorID(v *int64) *OrderStateLogsUpdate {
|
||||
if v != nil {
|
||||
_u.SetActorID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddActorID adds value to the "actor_id" field.
|
||||
func (_u *OrderStateLogsUpdate) AddActorID(v int64) *OrderStateLogsUpdate {
|
||||
_u.mutation.AddActorID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetActorRole sets the "actor_role" field.
|
||||
func (_u *OrderStateLogsUpdate) SetActorRole(v string) *OrderStateLogsUpdate {
|
||||
_u.mutation.SetActorRole(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableActorRole sets the "actor_role" field if the given value is not nil.
|
||||
func (_u *OrderStateLogsUpdate) SetNillableActorRole(v *string) *OrderStateLogsUpdate {
|
||||
if v != nil {
|
||||
_u.SetActorRole(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetMetadata sets the "metadata" field.
|
||||
func (_u *OrderStateLogsUpdate) SetMetadata(v map[string]interface{}) *OrderStateLogsUpdate {
|
||||
_u.mutation.SetMetadata(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearMetadata clears the value of the "metadata" field.
|
||||
func (_u *OrderStateLogsUpdate) ClearMetadata() *OrderStateLogsUpdate {
|
||||
_u.mutation.ClearMetadata()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the OrderStateLogsMutation object of the builder.
|
||||
func (_u *OrderStateLogsUpdate) Mutation() *OrderStateLogsMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *OrderStateLogsUpdate) 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 *OrderStateLogsUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *OrderStateLogsUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *OrderStateLogsUpdate) 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 *OrderStateLogsUpdate) check() error {
|
||||
if v, ok := _u.mutation.FromStatus(); ok {
|
||||
if err := orderstatelogs.FromStatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "from_status", err: fmt.Errorf(`models: validator failed for field "OrderStateLogs.from_status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.ToStatus(); ok {
|
||||
if err := orderstatelogs.ToStatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "to_status", err: fmt.Errorf(`models: validator failed for field "OrderStateLogs.to_status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Action(); ok {
|
||||
if err := orderstatelogs.ActionValidator(v); err != nil {
|
||||
return &ValidationError{Name: "action", err: fmt.Errorf(`models: validator failed for field "OrderStateLogs.action": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.ActorRole(); ok {
|
||||
if err := orderstatelogs.ActorRoleValidator(v); err != nil {
|
||||
return &ValidationError{Name: "actor_role", err: fmt.Errorf(`models: validator failed for field "OrderStateLogs.actor_role": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *OrderStateLogsUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(orderstatelogs.Table, orderstatelogs.Columns, sqlgraph.NewFieldSpec(orderstatelogs.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.OrderID(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldOrderID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedOrderID(); ok {
|
||||
_spec.AddField(orderstatelogs.FieldOrderID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.FromStatus(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldFromStatus, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.FromStatusCleared() {
|
||||
_spec.ClearField(orderstatelogs.FieldFromStatus, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.ToStatus(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldToStatus, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Action(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldAction, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ActorID(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldActorID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedActorID(); ok {
|
||||
_spec.AddField(orderstatelogs.FieldActorID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ActorRole(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldActorRole, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Metadata(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldMetadata, field.TypeJSON, value)
|
||||
}
|
||||
if _u.mutation.MetadataCleared() {
|
||||
_spec.ClearField(orderstatelogs.FieldMetadata, field.TypeJSON)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{orderstatelogs.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// OrderStateLogsUpdateOne is the builder for updating a single OrderStateLogs entity.
|
||||
type OrderStateLogsUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *OrderStateLogsMutation
|
||||
}
|
||||
|
||||
// SetOrderID sets the "order_id" field.
|
||||
func (_u *OrderStateLogsUpdateOne) SetOrderID(v int64) *OrderStateLogsUpdateOne {
|
||||
_u.mutation.ResetOrderID()
|
||||
_u.mutation.SetOrderID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableOrderID sets the "order_id" field if the given value is not nil.
|
||||
func (_u *OrderStateLogsUpdateOne) SetNillableOrderID(v *int64) *OrderStateLogsUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetOrderID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddOrderID adds value to the "order_id" field.
|
||||
func (_u *OrderStateLogsUpdateOne) AddOrderID(v int64) *OrderStateLogsUpdateOne {
|
||||
_u.mutation.AddOrderID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetFromStatus sets the "from_status" field.
|
||||
func (_u *OrderStateLogsUpdateOne) SetFromStatus(v string) *OrderStateLogsUpdateOne {
|
||||
_u.mutation.SetFromStatus(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableFromStatus sets the "from_status" field if the given value is not nil.
|
||||
func (_u *OrderStateLogsUpdateOne) SetNillableFromStatus(v *string) *OrderStateLogsUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetFromStatus(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearFromStatus clears the value of the "from_status" field.
|
||||
func (_u *OrderStateLogsUpdateOne) ClearFromStatus() *OrderStateLogsUpdateOne {
|
||||
_u.mutation.ClearFromStatus()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetToStatus sets the "to_status" field.
|
||||
func (_u *OrderStateLogsUpdateOne) SetToStatus(v string) *OrderStateLogsUpdateOne {
|
||||
_u.mutation.SetToStatus(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableToStatus sets the "to_status" field if the given value is not nil.
|
||||
func (_u *OrderStateLogsUpdateOne) SetNillableToStatus(v *string) *OrderStateLogsUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetToStatus(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetAction sets the "action" field.
|
||||
func (_u *OrderStateLogsUpdateOne) SetAction(v string) *OrderStateLogsUpdateOne {
|
||||
_u.mutation.SetAction(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAction sets the "action" field if the given value is not nil.
|
||||
func (_u *OrderStateLogsUpdateOne) SetNillableAction(v *string) *OrderStateLogsUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetAction(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetActorID sets the "actor_id" field.
|
||||
func (_u *OrderStateLogsUpdateOne) SetActorID(v int64) *OrderStateLogsUpdateOne {
|
||||
_u.mutation.ResetActorID()
|
||||
_u.mutation.SetActorID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableActorID sets the "actor_id" field if the given value is not nil.
|
||||
func (_u *OrderStateLogsUpdateOne) SetNillableActorID(v *int64) *OrderStateLogsUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetActorID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddActorID adds value to the "actor_id" field.
|
||||
func (_u *OrderStateLogsUpdateOne) AddActorID(v int64) *OrderStateLogsUpdateOne {
|
||||
_u.mutation.AddActorID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetActorRole sets the "actor_role" field.
|
||||
func (_u *OrderStateLogsUpdateOne) SetActorRole(v string) *OrderStateLogsUpdateOne {
|
||||
_u.mutation.SetActorRole(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableActorRole sets the "actor_role" field if the given value is not nil.
|
||||
func (_u *OrderStateLogsUpdateOne) SetNillableActorRole(v *string) *OrderStateLogsUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetActorRole(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetMetadata sets the "metadata" field.
|
||||
func (_u *OrderStateLogsUpdateOne) SetMetadata(v map[string]interface{}) *OrderStateLogsUpdateOne {
|
||||
_u.mutation.SetMetadata(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearMetadata clears the value of the "metadata" field.
|
||||
func (_u *OrderStateLogsUpdateOne) ClearMetadata() *OrderStateLogsUpdateOne {
|
||||
_u.mutation.ClearMetadata()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the OrderStateLogsMutation object of the builder.
|
||||
func (_u *OrderStateLogsUpdateOne) Mutation() *OrderStateLogsMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the OrderStateLogsUpdate builder.
|
||||
func (_u *OrderStateLogsUpdateOne) Where(ps ...predicate.OrderStateLogs) *OrderStateLogsUpdateOne {
|
||||
_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 *OrderStateLogsUpdateOne) Select(field string, fields ...string) *OrderStateLogsUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated OrderStateLogs entity.
|
||||
func (_u *OrderStateLogsUpdateOne) Save(ctx context.Context) (*OrderStateLogs, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *OrderStateLogsUpdateOne) SaveX(ctx context.Context) *OrderStateLogs {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *OrderStateLogsUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *OrderStateLogsUpdateOne) 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 *OrderStateLogsUpdateOne) check() error {
|
||||
if v, ok := _u.mutation.FromStatus(); ok {
|
||||
if err := orderstatelogs.FromStatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "from_status", err: fmt.Errorf(`models: validator failed for field "OrderStateLogs.from_status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.ToStatus(); ok {
|
||||
if err := orderstatelogs.ToStatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "to_status", err: fmt.Errorf(`models: validator failed for field "OrderStateLogs.to_status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Action(); ok {
|
||||
if err := orderstatelogs.ActionValidator(v); err != nil {
|
||||
return &ValidationError{Name: "action", err: fmt.Errorf(`models: validator failed for field "OrderStateLogs.action": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.ActorRole(); ok {
|
||||
if err := orderstatelogs.ActorRoleValidator(v); err != nil {
|
||||
return &ValidationError{Name: "actor_role", err: fmt.Errorf(`models: validator failed for field "OrderStateLogs.actor_role": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *OrderStateLogsUpdateOne) sqlSave(ctx context.Context) (_node *OrderStateLogs, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(orderstatelogs.Table, orderstatelogs.Columns, sqlgraph.NewFieldSpec(orderstatelogs.FieldID, field.TypeInt64))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "OrderStateLogs.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, orderstatelogs.FieldID)
|
||||
for _, f := range fields {
|
||||
if !orderstatelogs.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
|
||||
}
|
||||
if f != orderstatelogs.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.OrderID(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldOrderID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedOrderID(); ok {
|
||||
_spec.AddField(orderstatelogs.FieldOrderID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.FromStatus(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldFromStatus, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.FromStatusCleared() {
|
||||
_spec.ClearField(orderstatelogs.FieldFromStatus, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.ToStatus(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldToStatus, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Action(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldAction, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ActorID(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldActorID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedActorID(); ok {
|
||||
_spec.AddField(orderstatelogs.FieldActorID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ActorRole(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldActorRole, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Metadata(); ok {
|
||||
_spec.SetField(orderstatelogs.FieldMetadata, field.TypeJSON, value)
|
||||
}
|
||||
if _u.mutation.MetadataCleared() {
|
||||
_spec.ClearField(orderstatelogs.FieldMetadata, field.TypeJSON)
|
||||
}
|
||||
_node = &OrderStateLogs{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{orderstatelogs.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package predicate
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// OrderStateLogs is the predicate function for orderstatelogs builders.
|
||||
type OrderStateLogs func(*sql.Selector)
|
||||
|
||||
// Orders is the predicate function for orders builders.
|
||||
type Orders func(*sql.Selector)
|
||||
@@ -0,0 +1,76 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"juwan-backend/app/order/rpc/internal/models/orders"
|
||||
"juwan-backend/app/order/rpc/internal/models/orderstatelogs"
|
||||
"juwan-backend/app/order/rpc/internal/models/schema"
|
||||
"time"
|
||||
)
|
||||
|
||||
// The init function reads all schema descriptors with runtime code
|
||||
// (default values, validators, hooks and policies) and stitches it
|
||||
// to their package variables.
|
||||
func init() {
|
||||
orderstatelogsFields := schema.OrderStateLogs{}.Fields()
|
||||
_ = orderstatelogsFields
|
||||
// orderstatelogsDescFromStatus is the schema descriptor for from_status field.
|
||||
orderstatelogsDescFromStatus := orderstatelogsFields[2].Descriptor()
|
||||
// orderstatelogs.FromStatusValidator is a validator for the "from_status" field. It is called by the builders before save.
|
||||
orderstatelogs.FromStatusValidator = orderstatelogsDescFromStatus.Validators[0].(func(string) error)
|
||||
// orderstatelogsDescToStatus is the schema descriptor for to_status field.
|
||||
orderstatelogsDescToStatus := orderstatelogsFields[3].Descriptor()
|
||||
// orderstatelogs.ToStatusValidator is a validator for the "to_status" field. It is called by the builders before save.
|
||||
orderstatelogs.ToStatusValidator = orderstatelogsDescToStatus.Validators[0].(func(string) error)
|
||||
// orderstatelogsDescAction is the schema descriptor for action field.
|
||||
orderstatelogsDescAction := orderstatelogsFields[4].Descriptor()
|
||||
// orderstatelogs.ActionValidator is a validator for the "action" field. It is called by the builders before save.
|
||||
orderstatelogs.ActionValidator = orderstatelogsDescAction.Validators[0].(func(string) error)
|
||||
// orderstatelogsDescActorRole is the schema descriptor for actor_role field.
|
||||
orderstatelogsDescActorRole := orderstatelogsFields[6].Descriptor()
|
||||
// orderstatelogs.ActorRoleValidator is a validator for the "actor_role" field. It is called by the builders before save.
|
||||
orderstatelogs.ActorRoleValidator = orderstatelogsDescActorRole.Validators[0].(func(string) error)
|
||||
// orderstatelogsDescCreatedAt is the schema descriptor for created_at field.
|
||||
orderstatelogsDescCreatedAt := orderstatelogsFields[8].Descriptor()
|
||||
// orderstatelogs.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
orderstatelogs.DefaultCreatedAt = orderstatelogsDescCreatedAt.Default.(func() time.Time)
|
||||
ordersFields := schema.Orders{}.Fields()
|
||||
_ = ordersFields
|
||||
// ordersDescConsumerName is the schema descriptor for consumer_name field.
|
||||
ordersDescConsumerName := ordersFields[2].Descriptor()
|
||||
// orders.ConsumerNameValidator is a validator for the "consumer_name" field. It is called by the builders before save.
|
||||
orders.ConsumerNameValidator = ordersDescConsumerName.Validators[0].(func(string) error)
|
||||
// ordersDescPlayerName is the schema descriptor for player_name field.
|
||||
ordersDescPlayerName := ordersFields[4].Descriptor()
|
||||
// orders.PlayerNameValidator is a validator for the "player_name" field. It is called by the builders before save.
|
||||
orders.PlayerNameValidator = ordersDescPlayerName.Validators[0].(func(string) error)
|
||||
// ordersDescShopName is the schema descriptor for shop_name field.
|
||||
ordersDescShopName := ordersFields[6].Descriptor()
|
||||
// orders.ShopNameValidator is a validator for the "shop_name" field. It is called by the builders before save.
|
||||
orders.ShopNameValidator = ordersDescShopName.Validators[0].(func(string) error)
|
||||
// ordersDescStatus is the schema descriptor for status field.
|
||||
ordersDescStatus := ordersFields[8].Descriptor()
|
||||
// orders.DefaultStatus holds the default value on creation for the status field.
|
||||
orders.DefaultStatus = ordersDescStatus.Default.(string)
|
||||
// orders.StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
||||
orders.StatusValidator = ordersDescStatus.Validators[0].(func(string) error)
|
||||
// ordersDescVersion is the schema descriptor for version field.
|
||||
ordersDescVersion := ordersFields[11].Descriptor()
|
||||
// orders.DefaultVersion holds the default value on creation for the version field.
|
||||
orders.DefaultVersion = ordersDescVersion.Default.(int)
|
||||
// ordersDescTimeoutJobID is the schema descriptor for timeout_job_id field.
|
||||
ordersDescTimeoutJobID := ordersFields[12].Descriptor()
|
||||
// orders.TimeoutJobIDValidator is a validator for the "timeout_job_id" field. It is called by the builders before save.
|
||||
orders.TimeoutJobIDValidator = ordersDescTimeoutJobID.Validators[0].(func(string) error)
|
||||
// ordersDescCreatedAt is the schema descriptor for created_at field.
|
||||
ordersDescCreatedAt := ordersFields[14].Descriptor()
|
||||
// orders.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
orders.DefaultCreatedAt = ordersDescCreatedAt.Default.(func() time.Time)
|
||||
// ordersDescUpdatedAt is the schema descriptor for updated_at field.
|
||||
ordersDescUpdatedAt := ordersFields[19].Descriptor()
|
||||
// orders.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||
orders.DefaultUpdatedAt = ordersDescUpdatedAt.Default.(func() time.Time)
|
||||
// orders.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||
orders.UpdateDefaultUpdatedAt = ordersDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package runtime
|
||||
|
||||
// The schema-stitching logic is generated in juwan-backend/app/order/rpc/internal/models/runtime.go
|
||||
|
||||
const (
|
||||
Version = "v0.14.5" // Version of ent codegen.
|
||||
Sum = "h1:Rj2WOYJtCkWyFo6a+5wB3EfBRP0rnx1fMk6gGA0UUe4=" // Sum of ent codegen.
|
||||
)
|
||||
@@ -0,0 +1,63 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// Orders holds the schema definition for the Orders entity.
|
||||
type Orders struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Annotations of the Orders.
|
||||
func (Orders) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.Annotation{
|
||||
Table: "orders",
|
||||
Checks: map[string]string{
|
||||
"chk_order_status": "status IN ('pending_payment', 'pending_accept', 'in_progress', 'pending_close', 'pending_review', 'disputed', 'completed', 'cancelled')",
|
||||
"chk_price_positive": "total_price > 0",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the Orders.
|
||||
func (Orders) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int64("id").Immutable().Unique(),
|
||||
field.Int64("consumer_id"),
|
||||
field.String("consumer_name").MaxLen(100),
|
||||
field.Int64("player_id"),
|
||||
field.String("player_name").MaxLen(100),
|
||||
field.Int64("shop_id").Optional().Nillable(),
|
||||
field.String("shop_name").Optional().Nillable().MaxLen(200),
|
||||
field.JSON("service_snapshot", map[string]any{}).
|
||||
SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
|
||||
field.String("status").Default("pending_payment").MaxLen(30),
|
||||
field.Other("total_price", decimal.Decimal{}).
|
||||
SchemaType(map[string]string{dialect.Postgres: "decimal(10,2)"}),
|
||||
field.String("note").Optional().Nillable(),
|
||||
field.Int("version").Default(1),
|
||||
field.String("timeout_job_id").Optional().Nillable().MaxLen(100),
|
||||
field.String("search_text").Optional().Nillable(),
|
||||
field.Time("created_at").Default(time.Now).Immutable(),
|
||||
field.Time("accepted_at").Optional().Nillable(),
|
||||
field.Time("closed_at").Optional().Nillable(),
|
||||
field.Time("completed_at").Optional().Nillable(),
|
||||
field.Time("cancelled_at").Optional().Nillable(),
|
||||
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Orders.
|
||||
func (Orders) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// OrderStateLogs holds the schema definition for the OrderStateLogs entity.
|
||||
type OrderStateLogs struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Annotations of the OrderStateLogs.
|
||||
func (OrderStateLogs) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.Annotation{
|
||||
Table: "order_state_logs",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the OrderStateLogs.
|
||||
func (OrderStateLogs) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int64("id").Immutable().Unique(),
|
||||
field.Int64("order_id"),
|
||||
field.String("from_status").Optional().Nillable().MaxLen(30),
|
||||
field.String("to_status").MaxLen(30),
|
||||
field.String("action").MaxLen(50),
|
||||
field.Int64("actor_id"),
|
||||
field.String("actor_role").MaxLen(20),
|
||||
field.JSON("metadata", map[string]any{}).
|
||||
Optional().
|
||||
SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
|
||||
field.Time("created_at").Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the OrderStateLogs.
|
||||
func (OrderStateLogs) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
@@ -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
|
||||
// OrderStateLogs is the client for interacting with the OrderStateLogs builders.
|
||||
OrderStateLogs *OrderStateLogsClient
|
||||
// Orders is the client for interacting with the Orders builders.
|
||||
Orders *OrdersClient
|
||||
|
||||
// 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.OrderStateLogs = NewOrderStateLogsClient(tx.config)
|
||||
tx.Orders = NewOrdersClient(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: OrderStateLogs.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)
|
||||
@@ -0,0 +1,76 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.9.2
|
||||
// Source: order.proto
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/logic"
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
)
|
||||
|
||||
type OrderServiceServer struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
pb.UnimplementedOrderServiceServer
|
||||
}
|
||||
|
||||
func NewOrderServiceServer(svcCtx *svc.ServiceContext) *OrderServiceServer {
|
||||
return &OrderServiceServer{
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------orders-----------------------
|
||||
func (s *OrderServiceServer) AddOrders(ctx context.Context, in *pb.AddOrdersReq) (*pb.AddOrdersResp, error) {
|
||||
l := logic.NewAddOrdersLogic(ctx, s.svcCtx)
|
||||
return l.AddOrders(in)
|
||||
}
|
||||
|
||||
func (s *OrderServiceServer) UpdateOrders(ctx context.Context, in *pb.UpdateOrdersReq) (*pb.UpdateOrdersResp, error) {
|
||||
l := logic.NewUpdateOrdersLogic(ctx, s.svcCtx)
|
||||
return l.UpdateOrders(in)
|
||||
}
|
||||
|
||||
func (s *OrderServiceServer) DelOrders(ctx context.Context, in *pb.DelOrdersReq) (*pb.DelOrdersResp, error) {
|
||||
l := logic.NewDelOrdersLogic(ctx, s.svcCtx)
|
||||
return l.DelOrders(in)
|
||||
}
|
||||
|
||||
func (s *OrderServiceServer) GetOrdersById(ctx context.Context, in *pb.GetOrdersByIdReq) (*pb.GetOrdersByIdResp, error) {
|
||||
l := logic.NewGetOrdersByIdLogic(ctx, s.svcCtx)
|
||||
return l.GetOrdersById(in)
|
||||
}
|
||||
|
||||
func (s *OrderServiceServer) SearchOrders(ctx context.Context, in *pb.SearchOrdersReq) (*pb.SearchOrdersResp, error) {
|
||||
l := logic.NewSearchOrdersLogic(ctx, s.svcCtx)
|
||||
return l.SearchOrders(in)
|
||||
}
|
||||
|
||||
// -----------------------orderStateLogs-----------------------
|
||||
func (s *OrderServiceServer) AddOrderStateLogs(ctx context.Context, in *pb.AddOrderStateLogsReq) (*pb.AddOrderStateLogsResp, error) {
|
||||
l := logic.NewAddOrderStateLogsLogic(ctx, s.svcCtx)
|
||||
return l.AddOrderStateLogs(in)
|
||||
}
|
||||
|
||||
func (s *OrderServiceServer) UpdateOrderStateLogs(ctx context.Context, in *pb.UpdateOrderStateLogsReq) (*pb.UpdateOrderStateLogsResp, error) {
|
||||
l := logic.NewUpdateOrderStateLogsLogic(ctx, s.svcCtx)
|
||||
return l.UpdateOrderStateLogs(in)
|
||||
}
|
||||
|
||||
func (s *OrderServiceServer) DelOrderStateLogs(ctx context.Context, in *pb.DelOrderStateLogsReq) (*pb.DelOrderStateLogsResp, error) {
|
||||
l := logic.NewDelOrderStateLogsLogic(ctx, s.svcCtx)
|
||||
return l.DelOrderStateLogs(in)
|
||||
}
|
||||
|
||||
func (s *OrderServiceServer) GetOrderStateLogsById(ctx context.Context, in *pb.GetOrderStateLogsByIdReq) (*pb.GetOrderStateLogsByIdResp, error) {
|
||||
l := logic.NewGetOrderStateLogsByIdLogic(ctx, s.svcCtx)
|
||||
return l.GetOrderStateLogsById(in)
|
||||
}
|
||||
|
||||
func (s *OrderServiceServer) SearchOrderStateLogs(ctx context.Context, in *pb.SearchOrderStateLogsReq) (*pb.SearchOrderStateLogsResp, error) {
|
||||
l := logic.NewSearchOrderStateLogsLogic(ctx, s.svcCtx)
|
||||
return l.SearchOrderStateLogs(in)
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"ariga.io/entcache"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"juwan-backend/app/order/rpc/internal/config"
|
||||
"juwan-backend/app/order/rpc/internal/models"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
"juwan-backend/common/redisx"
|
||||
"juwan-backend/common/snowflakex"
|
||||
"juwan-backend/pkg/adapter"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
Snowflake snowflake.SnowflakeServiceClient
|
||||
OrderModelsRW *models.Client
|
||||
OrderModelsRO *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)))
|
||||
|
||||
entLogFn := func(v ...any) {
|
||||
logx.Infof("[ent][order] %s", fmt.Sprint(v...))
|
||||
}
|
||||
|
||||
rwOpts := []models.Option{models.Driver(RWDrv), models.Log(entLogFn)}
|
||||
roOpts := []models.Option{models.Driver(RODrv), models.Log(entLogFn)}
|
||||
if strings.EqualFold(c.Log.Level, "debug") {
|
||||
rwOpts = append(rwOpts, models.Debug())
|
||||
roOpts = append(roOpts, models.Debug())
|
||||
}
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
Snowflake: snowflakex.NewClient(c.SnowflakeRpcConf),
|
||||
OrderModelsRW: models.NewClient(rwOpts...),
|
||||
OrderModelsRO: models.NewClient(roOpts...),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.9.2
|
||||
// Source: order.proto
|
||||
|
||||
package orderservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type (
|
||||
AddOrderStateLogsReq = pb.AddOrderStateLogsReq
|
||||
AddOrderStateLogsResp = pb.AddOrderStateLogsResp
|
||||
AddOrdersReq = pb.AddOrdersReq
|
||||
AddOrdersResp = pb.AddOrdersResp
|
||||
DelOrderStateLogsReq = pb.DelOrderStateLogsReq
|
||||
DelOrderStateLogsResp = pb.DelOrderStateLogsResp
|
||||
DelOrdersReq = pb.DelOrdersReq
|
||||
DelOrdersResp = pb.DelOrdersResp
|
||||
GetOrderStateLogsByIdReq = pb.GetOrderStateLogsByIdReq
|
||||
GetOrderStateLogsByIdResp = pb.GetOrderStateLogsByIdResp
|
||||
GetOrdersByIdReq = pb.GetOrdersByIdReq
|
||||
GetOrdersByIdResp = pb.GetOrdersByIdResp
|
||||
OrderStateLogs = pb.OrderStateLogs
|
||||
Orders = pb.Orders
|
||||
SearchOrderStateLogsReq = pb.SearchOrderStateLogsReq
|
||||
SearchOrderStateLogsResp = pb.SearchOrderStateLogsResp
|
||||
SearchOrdersReq = pb.SearchOrdersReq
|
||||
SearchOrdersResp = pb.SearchOrdersResp
|
||||
UpdateOrderStateLogsReq = pb.UpdateOrderStateLogsReq
|
||||
UpdateOrderStateLogsResp = pb.UpdateOrderStateLogsResp
|
||||
UpdateOrdersReq = pb.UpdateOrdersReq
|
||||
UpdateOrdersResp = pb.UpdateOrdersResp
|
||||
|
||||
OrderService interface {
|
||||
// -----------------------orders-----------------------
|
||||
AddOrders(ctx context.Context, in *AddOrdersReq, opts ...grpc.CallOption) (*AddOrdersResp, error)
|
||||
UpdateOrders(ctx context.Context, in *UpdateOrdersReq, opts ...grpc.CallOption) (*UpdateOrdersResp, error)
|
||||
DelOrders(ctx context.Context, in *DelOrdersReq, opts ...grpc.CallOption) (*DelOrdersResp, error)
|
||||
GetOrdersById(ctx context.Context, in *GetOrdersByIdReq, opts ...grpc.CallOption) (*GetOrdersByIdResp, error)
|
||||
SearchOrders(ctx context.Context, in *SearchOrdersReq, opts ...grpc.CallOption) (*SearchOrdersResp, error)
|
||||
// -----------------------orderStateLogs-----------------------
|
||||
AddOrderStateLogs(ctx context.Context, in *AddOrderStateLogsReq, opts ...grpc.CallOption) (*AddOrderStateLogsResp, error)
|
||||
UpdateOrderStateLogs(ctx context.Context, in *UpdateOrderStateLogsReq, opts ...grpc.CallOption) (*UpdateOrderStateLogsResp, error)
|
||||
DelOrderStateLogs(ctx context.Context, in *DelOrderStateLogsReq, opts ...grpc.CallOption) (*DelOrderStateLogsResp, error)
|
||||
GetOrderStateLogsById(ctx context.Context, in *GetOrderStateLogsByIdReq, opts ...grpc.CallOption) (*GetOrderStateLogsByIdResp, error)
|
||||
SearchOrderStateLogs(ctx context.Context, in *SearchOrderStateLogsReq, opts ...grpc.CallOption) (*SearchOrderStateLogsResp, error)
|
||||
}
|
||||
|
||||
defaultOrderService struct {
|
||||
cli zrpc.Client
|
||||
}
|
||||
)
|
||||
|
||||
func NewOrderService(cli zrpc.Client) OrderService {
|
||||
return &defaultOrderService{
|
||||
cli: cli,
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------orders-----------------------
|
||||
func (m *defaultOrderService) AddOrders(ctx context.Context, in *AddOrdersReq, opts ...grpc.CallOption) (*AddOrdersResp, error) {
|
||||
client := pb.NewOrderServiceClient(m.cli.Conn())
|
||||
return client.AddOrders(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultOrderService) UpdateOrders(ctx context.Context, in *UpdateOrdersReq, opts ...grpc.CallOption) (*UpdateOrdersResp, error) {
|
||||
client := pb.NewOrderServiceClient(m.cli.Conn())
|
||||
return client.UpdateOrders(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultOrderService) DelOrders(ctx context.Context, in *DelOrdersReq, opts ...grpc.CallOption) (*DelOrdersResp, error) {
|
||||
client := pb.NewOrderServiceClient(m.cli.Conn())
|
||||
return client.DelOrders(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultOrderService) GetOrdersById(ctx context.Context, in *GetOrdersByIdReq, opts ...grpc.CallOption) (*GetOrdersByIdResp, error) {
|
||||
client := pb.NewOrderServiceClient(m.cli.Conn())
|
||||
return client.GetOrdersById(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultOrderService) SearchOrders(ctx context.Context, in *SearchOrdersReq, opts ...grpc.CallOption) (*SearchOrdersResp, error) {
|
||||
client := pb.NewOrderServiceClient(m.cli.Conn())
|
||||
return client.SearchOrders(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// -----------------------orderStateLogs-----------------------
|
||||
func (m *defaultOrderService) AddOrderStateLogs(ctx context.Context, in *AddOrderStateLogsReq, opts ...grpc.CallOption) (*AddOrderStateLogsResp, error) {
|
||||
client := pb.NewOrderServiceClient(m.cli.Conn())
|
||||
return client.AddOrderStateLogs(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultOrderService) UpdateOrderStateLogs(ctx context.Context, in *UpdateOrderStateLogsReq, opts ...grpc.CallOption) (*UpdateOrderStateLogsResp, error) {
|
||||
client := pb.NewOrderServiceClient(m.cli.Conn())
|
||||
return client.UpdateOrderStateLogs(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultOrderService) DelOrderStateLogs(ctx context.Context, in *DelOrderStateLogsReq, opts ...grpc.CallOption) (*DelOrderStateLogsResp, error) {
|
||||
client := pb.NewOrderServiceClient(m.cli.Conn())
|
||||
return client.DelOrderStateLogs(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultOrderService) GetOrderStateLogsById(ctx context.Context, in *GetOrderStateLogsByIdReq, opts ...grpc.CallOption) (*GetOrderStateLogsByIdResp, error) {
|
||||
client := pb.NewOrderServiceClient(m.cli.Conn())
|
||||
return client.GetOrderStateLogsById(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultOrderService) SearchOrderStateLogs(ctx context.Context, in *SearchOrderStateLogsReq, opts ...grpc.CallOption) (*SearchOrderStateLogsResp, error) {
|
||||
client := pb.NewOrderServiceClient(m.cli.Conn())
|
||||
return client.SearchOrderStateLogs(ctx, in, opts...)
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/config"
|
||||
"juwan-backend/app/order/rpc/internal/server"
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/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.RegisterOrderServiceServer(grpcServer, server.NewOrderServiceServer(ctx))
|
||||
|
||||
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
||||
reflection.Register(grpcServer)
|
||||
}
|
||||
})
|
||||
defer s.Stop()
|
||||
|
||||
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
|
||||
s.Start()
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,467 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.6.1
|
||||
// - protoc v5.29.6
|
||||
// source: order.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 (
|
||||
OrderService_AddOrders_FullMethodName = "/pb.orderService/AddOrders"
|
||||
OrderService_UpdateOrders_FullMethodName = "/pb.orderService/UpdateOrders"
|
||||
OrderService_DelOrders_FullMethodName = "/pb.orderService/DelOrders"
|
||||
OrderService_GetOrdersById_FullMethodName = "/pb.orderService/GetOrdersById"
|
||||
OrderService_SearchOrders_FullMethodName = "/pb.orderService/SearchOrders"
|
||||
OrderService_AddOrderStateLogs_FullMethodName = "/pb.orderService/AddOrderStateLogs"
|
||||
OrderService_UpdateOrderStateLogs_FullMethodName = "/pb.orderService/UpdateOrderStateLogs"
|
||||
OrderService_DelOrderStateLogs_FullMethodName = "/pb.orderService/DelOrderStateLogs"
|
||||
OrderService_GetOrderStateLogsById_FullMethodName = "/pb.orderService/GetOrderStateLogsById"
|
||||
OrderService_SearchOrderStateLogs_FullMethodName = "/pb.orderService/SearchOrderStateLogs"
|
||||
)
|
||||
|
||||
// OrderServiceClient is the client API for OrderService 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 OrderServiceClient interface {
|
||||
// -----------------------orders-----------------------
|
||||
AddOrders(ctx context.Context, in *AddOrdersReq, opts ...grpc.CallOption) (*AddOrdersResp, error)
|
||||
UpdateOrders(ctx context.Context, in *UpdateOrdersReq, opts ...grpc.CallOption) (*UpdateOrdersResp, error)
|
||||
DelOrders(ctx context.Context, in *DelOrdersReq, opts ...grpc.CallOption) (*DelOrdersResp, error)
|
||||
GetOrdersById(ctx context.Context, in *GetOrdersByIdReq, opts ...grpc.CallOption) (*GetOrdersByIdResp, error)
|
||||
SearchOrders(ctx context.Context, in *SearchOrdersReq, opts ...grpc.CallOption) (*SearchOrdersResp, error)
|
||||
// -----------------------orderStateLogs-----------------------
|
||||
AddOrderStateLogs(ctx context.Context, in *AddOrderStateLogsReq, opts ...grpc.CallOption) (*AddOrderStateLogsResp, error)
|
||||
UpdateOrderStateLogs(ctx context.Context, in *UpdateOrderStateLogsReq, opts ...grpc.CallOption) (*UpdateOrderStateLogsResp, error)
|
||||
DelOrderStateLogs(ctx context.Context, in *DelOrderStateLogsReq, opts ...grpc.CallOption) (*DelOrderStateLogsResp, error)
|
||||
GetOrderStateLogsById(ctx context.Context, in *GetOrderStateLogsByIdReq, opts ...grpc.CallOption) (*GetOrderStateLogsByIdResp, error)
|
||||
SearchOrderStateLogs(ctx context.Context, in *SearchOrderStateLogsReq, opts ...grpc.CallOption) (*SearchOrderStateLogsResp, error)
|
||||
}
|
||||
|
||||
type orderServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewOrderServiceClient(cc grpc.ClientConnInterface) OrderServiceClient {
|
||||
return &orderServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *orderServiceClient) AddOrders(ctx context.Context, in *AddOrdersReq, opts ...grpc.CallOption) (*AddOrdersResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(AddOrdersResp)
|
||||
err := c.cc.Invoke(ctx, OrderService_AddOrders_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *orderServiceClient) UpdateOrders(ctx context.Context, in *UpdateOrdersReq, opts ...grpc.CallOption) (*UpdateOrdersResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(UpdateOrdersResp)
|
||||
err := c.cc.Invoke(ctx, OrderService_UpdateOrders_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *orderServiceClient) DelOrders(ctx context.Context, in *DelOrdersReq, opts ...grpc.CallOption) (*DelOrdersResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(DelOrdersResp)
|
||||
err := c.cc.Invoke(ctx, OrderService_DelOrders_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *orderServiceClient) GetOrdersById(ctx context.Context, in *GetOrdersByIdReq, opts ...grpc.CallOption) (*GetOrdersByIdResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetOrdersByIdResp)
|
||||
err := c.cc.Invoke(ctx, OrderService_GetOrdersById_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *orderServiceClient) SearchOrders(ctx context.Context, in *SearchOrdersReq, opts ...grpc.CallOption) (*SearchOrdersResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(SearchOrdersResp)
|
||||
err := c.cc.Invoke(ctx, OrderService_SearchOrders_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *orderServiceClient) AddOrderStateLogs(ctx context.Context, in *AddOrderStateLogsReq, opts ...grpc.CallOption) (*AddOrderStateLogsResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(AddOrderStateLogsResp)
|
||||
err := c.cc.Invoke(ctx, OrderService_AddOrderStateLogs_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *orderServiceClient) UpdateOrderStateLogs(ctx context.Context, in *UpdateOrderStateLogsReq, opts ...grpc.CallOption) (*UpdateOrderStateLogsResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(UpdateOrderStateLogsResp)
|
||||
err := c.cc.Invoke(ctx, OrderService_UpdateOrderStateLogs_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *orderServiceClient) DelOrderStateLogs(ctx context.Context, in *DelOrderStateLogsReq, opts ...grpc.CallOption) (*DelOrderStateLogsResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(DelOrderStateLogsResp)
|
||||
err := c.cc.Invoke(ctx, OrderService_DelOrderStateLogs_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *orderServiceClient) GetOrderStateLogsById(ctx context.Context, in *GetOrderStateLogsByIdReq, opts ...grpc.CallOption) (*GetOrderStateLogsByIdResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetOrderStateLogsByIdResp)
|
||||
err := c.cc.Invoke(ctx, OrderService_GetOrderStateLogsById_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *orderServiceClient) SearchOrderStateLogs(ctx context.Context, in *SearchOrderStateLogsReq, opts ...grpc.CallOption) (*SearchOrderStateLogsResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(SearchOrderStateLogsResp)
|
||||
err := c.cc.Invoke(ctx, OrderService_SearchOrderStateLogs_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// OrderServiceServer is the server API for OrderService service.
|
||||
// All implementations must embed UnimplementedOrderServiceServer
|
||||
// for forward compatibility.
|
||||
type OrderServiceServer interface {
|
||||
// -----------------------orders-----------------------
|
||||
AddOrders(context.Context, *AddOrdersReq) (*AddOrdersResp, error)
|
||||
UpdateOrders(context.Context, *UpdateOrdersReq) (*UpdateOrdersResp, error)
|
||||
DelOrders(context.Context, *DelOrdersReq) (*DelOrdersResp, error)
|
||||
GetOrdersById(context.Context, *GetOrdersByIdReq) (*GetOrdersByIdResp, error)
|
||||
SearchOrders(context.Context, *SearchOrdersReq) (*SearchOrdersResp, error)
|
||||
// -----------------------orderStateLogs-----------------------
|
||||
AddOrderStateLogs(context.Context, *AddOrderStateLogsReq) (*AddOrderStateLogsResp, error)
|
||||
UpdateOrderStateLogs(context.Context, *UpdateOrderStateLogsReq) (*UpdateOrderStateLogsResp, error)
|
||||
DelOrderStateLogs(context.Context, *DelOrderStateLogsReq) (*DelOrderStateLogsResp, error)
|
||||
GetOrderStateLogsById(context.Context, *GetOrderStateLogsByIdReq) (*GetOrderStateLogsByIdResp, error)
|
||||
SearchOrderStateLogs(context.Context, *SearchOrderStateLogsReq) (*SearchOrderStateLogsResp, error)
|
||||
mustEmbedUnimplementedOrderServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedOrderServiceServer 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 UnimplementedOrderServiceServer struct{}
|
||||
|
||||
func (UnimplementedOrderServiceServer) AddOrders(context.Context, *AddOrdersReq) (*AddOrdersResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method AddOrders not implemented")
|
||||
}
|
||||
func (UnimplementedOrderServiceServer) UpdateOrders(context.Context, *UpdateOrdersReq) (*UpdateOrdersResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method UpdateOrders not implemented")
|
||||
}
|
||||
func (UnimplementedOrderServiceServer) DelOrders(context.Context, *DelOrdersReq) (*DelOrdersResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method DelOrders not implemented")
|
||||
}
|
||||
func (UnimplementedOrderServiceServer) GetOrdersById(context.Context, *GetOrdersByIdReq) (*GetOrdersByIdResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GetOrdersById not implemented")
|
||||
}
|
||||
func (UnimplementedOrderServiceServer) SearchOrders(context.Context, *SearchOrdersReq) (*SearchOrdersResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method SearchOrders not implemented")
|
||||
}
|
||||
func (UnimplementedOrderServiceServer) AddOrderStateLogs(context.Context, *AddOrderStateLogsReq) (*AddOrderStateLogsResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method AddOrderStateLogs not implemented")
|
||||
}
|
||||
func (UnimplementedOrderServiceServer) UpdateOrderStateLogs(context.Context, *UpdateOrderStateLogsReq) (*UpdateOrderStateLogsResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method UpdateOrderStateLogs not implemented")
|
||||
}
|
||||
func (UnimplementedOrderServiceServer) DelOrderStateLogs(context.Context, *DelOrderStateLogsReq) (*DelOrderStateLogsResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method DelOrderStateLogs not implemented")
|
||||
}
|
||||
func (UnimplementedOrderServiceServer) GetOrderStateLogsById(context.Context, *GetOrderStateLogsByIdReq) (*GetOrderStateLogsByIdResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GetOrderStateLogsById not implemented")
|
||||
}
|
||||
func (UnimplementedOrderServiceServer) SearchOrderStateLogs(context.Context, *SearchOrderStateLogsReq) (*SearchOrderStateLogsResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method SearchOrderStateLogs not implemented")
|
||||
}
|
||||
func (UnimplementedOrderServiceServer) mustEmbedUnimplementedOrderServiceServer() {}
|
||||
func (UnimplementedOrderServiceServer) testEmbeddedByValue() {}
|
||||
|
||||
// UnsafeOrderServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to OrderServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeOrderServiceServer interface {
|
||||
mustEmbedUnimplementedOrderServiceServer()
|
||||
}
|
||||
|
||||
func RegisterOrderServiceServer(s grpc.ServiceRegistrar, srv OrderServiceServer) {
|
||||
// If the following call panics, it indicates UnimplementedOrderServiceServer 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(&OrderService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _OrderService_AddOrders_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AddOrdersReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(OrderServiceServer).AddOrders(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: OrderService_AddOrders_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(OrderServiceServer).AddOrders(ctx, req.(*AddOrdersReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _OrderService_UpdateOrders_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UpdateOrdersReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(OrderServiceServer).UpdateOrders(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: OrderService_UpdateOrders_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(OrderServiceServer).UpdateOrders(ctx, req.(*UpdateOrdersReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _OrderService_DelOrders_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DelOrdersReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(OrderServiceServer).DelOrders(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: OrderService_DelOrders_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(OrderServiceServer).DelOrders(ctx, req.(*DelOrdersReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _OrderService_GetOrdersById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetOrdersByIdReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(OrderServiceServer).GetOrdersById(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: OrderService_GetOrdersById_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(OrderServiceServer).GetOrdersById(ctx, req.(*GetOrdersByIdReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _OrderService_SearchOrders_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(SearchOrdersReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(OrderServiceServer).SearchOrders(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: OrderService_SearchOrders_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(OrderServiceServer).SearchOrders(ctx, req.(*SearchOrdersReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _OrderService_AddOrderStateLogs_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AddOrderStateLogsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(OrderServiceServer).AddOrderStateLogs(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: OrderService_AddOrderStateLogs_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(OrderServiceServer).AddOrderStateLogs(ctx, req.(*AddOrderStateLogsReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _OrderService_UpdateOrderStateLogs_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UpdateOrderStateLogsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(OrderServiceServer).UpdateOrderStateLogs(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: OrderService_UpdateOrderStateLogs_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(OrderServiceServer).UpdateOrderStateLogs(ctx, req.(*UpdateOrderStateLogsReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _OrderService_DelOrderStateLogs_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DelOrderStateLogsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(OrderServiceServer).DelOrderStateLogs(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: OrderService_DelOrderStateLogs_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(OrderServiceServer).DelOrderStateLogs(ctx, req.(*DelOrderStateLogsReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _OrderService_GetOrderStateLogsById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetOrderStateLogsByIdReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(OrderServiceServer).GetOrderStateLogsById(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: OrderService_GetOrderStateLogsById_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(OrderServiceServer).GetOrderStateLogsById(ctx, req.(*GetOrderStateLogsByIdReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _OrderService_SearchOrderStateLogs_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(SearchOrderStateLogsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(OrderServiceServer).SearchOrderStateLogs(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: OrderService_SearchOrderStateLogs_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(OrderServiceServer).SearchOrderStateLogs(ctx, req.(*SearchOrderStateLogsReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// OrderService_ServiceDesc is the grpc.ServiceDesc for OrderService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var OrderService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "pb.orderService",
|
||||
HandlerType: (*OrderServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "AddOrders",
|
||||
Handler: _OrderService_AddOrders_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "UpdateOrders",
|
||||
Handler: _OrderService_UpdateOrders_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DelOrders",
|
||||
Handler: _OrderService_DelOrders_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetOrdersById",
|
||||
Handler: _OrderService_GetOrdersById_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "SearchOrders",
|
||||
Handler: _OrderService_SearchOrders_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "AddOrderStateLogs",
|
||||
Handler: _OrderService_AddOrderStateLogs_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "UpdateOrderStateLogs",
|
||||
Handler: _OrderService_UpdateOrderStateLogs_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DelOrderStateLogs",
|
||||
Handler: _OrderService_DelOrderStateLogs_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetOrderStateLogsById",
|
||||
Handler: _OrderService_GetOrderStateLogsById_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "SearchOrderStateLogs",
|
||||
Handler: _OrderService_SearchOrderStateLogs_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "order.proto",
|
||||
}
|
||||
Reference in New Issue
Block a user