fix: some api bug

This commit is contained in:
wwweww
2026-03-31 22:12:06 +08:00
parent c5ff4f0216
commit e7970ac25f
219 changed files with 16195 additions and 2126 deletions
@@ -94,7 +94,7 @@ var (
{Name: "allow_multi_shop", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "allow_independent_orders", Type: field.TypeBool, Nullable: true, Default: true},
{Name: "dispatch_mode", Type: field.TypeString, Size: 20, Default: "manual"},
{Name: "announcements", Type: field.TypeJSON, Nullable: true},
{Name: "announcements", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "text[]"}},
{Name: "template_config", Type: field.TypeJSON, Nullable: true},
{Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime},
+7 -23
View File
@@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"juwan-backend/app/shop/rpc/internal/models/predicate"
"juwan-backend/app/shop/rpc/internal/models/schema"
"juwan-backend/app/shop/rpc/internal/models/shopinvitations"
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
"juwan-backend/app/shop/rpc/internal/models/shops"
@@ -1437,8 +1438,7 @@ type ShopsMutation struct {
allow_multi_shop *bool
allow_independent_orders *bool
dispatch_mode *string
announcements *[]string
appendannouncements []string
announcements *schema.TextArray
template_config *map[string]interface{}
created_at *time.Time
updated_at *time.Time
@@ -2138,13 +2138,12 @@ func (m *ShopsMutation) ResetDispatchMode() {
}
// SetAnnouncements sets the "announcements" field.
func (m *ShopsMutation) SetAnnouncements(s []string) {
m.announcements = &s
m.appendannouncements = nil
func (m *ShopsMutation) SetAnnouncements(sa schema.TextArray) {
m.announcements = &sa
}
// Announcements returns the value of the "announcements" field in the mutation.
func (m *ShopsMutation) Announcements() (r []string, exists bool) {
func (m *ShopsMutation) Announcements() (r schema.TextArray, exists bool) {
v := m.announcements
if v == nil {
return
@@ -2155,7 +2154,7 @@ func (m *ShopsMutation) Announcements() (r []string, exists bool) {
// OldAnnouncements returns the old "announcements" field's value of the Shops entity.
// If the Shops object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ShopsMutation) OldAnnouncements(ctx context.Context) (v []string, err error) {
func (m *ShopsMutation) OldAnnouncements(ctx context.Context) (v schema.TextArray, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldAnnouncements is only allowed on UpdateOne operations")
}
@@ -2169,23 +2168,9 @@ func (m *ShopsMutation) OldAnnouncements(ctx context.Context) (v []string, err e
return oldValue.Announcements, nil
}
// AppendAnnouncements adds s to the "announcements" field.
func (m *ShopsMutation) AppendAnnouncements(s []string) {
m.appendannouncements = append(m.appendannouncements, s...)
}
// AppendedAnnouncements returns the list of values that were appended to the "announcements" field in this mutation.
func (m *ShopsMutation) AppendedAnnouncements() ([]string, bool) {
if len(m.appendannouncements) == 0 {
return nil, false
}
return m.appendannouncements, true
}
// ClearAnnouncements clears the value of the "announcements" field.
func (m *ShopsMutation) ClearAnnouncements() {
m.announcements = nil
m.appendannouncements = nil
m.clearedFields[shops.FieldAnnouncements] = struct{}{}
}
@@ -2198,7 +2183,6 @@ func (m *ShopsMutation) AnnouncementsCleared() bool {
// ResetAnnouncements resets all changes to the "announcements" field.
func (m *ShopsMutation) ResetAnnouncements() {
m.announcements = nil
m.appendannouncements = nil
delete(m.clearedFields, shops.FieldAnnouncements)
}
@@ -2581,7 +2565,7 @@ func (m *ShopsMutation) SetField(name string, value ent.Value) error {
m.SetDispatchMode(v)
return nil
case shops.FieldAnnouncements:
v, ok := value.([]string)
v, ok := value.(schema.TextArray)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
-4
View File
@@ -76,10 +76,6 @@ func init() {
shops.DefaultDispatchMode = shopsDescDispatchMode.Default.(string)
// shops.DispatchModeValidator is a validator for the "dispatch_mode" field. It is called by the builders before save.
shops.DispatchModeValidator = shopsDescDispatchMode.Validators[0].(func(string) error)
// shopsDescAnnouncements is the schema descriptor for announcements field.
shopsDescAnnouncements := shopsFields[13].Descriptor()
// shops.DefaultAnnouncements holds the default value on creation for the announcements field.
shops.DefaultAnnouncements = shopsDescAnnouncements.Default.([]string)
// shopsDescCreatedAt is the schema descriptor for created_at field.
shopsDescCreatedAt := shopsFields[15].Descriptor()
// shops.DefaultCreatedAt holds the default value on creation for the created_at field.
+48 -1
View File
@@ -1,6 +1,9 @@
package schema
import (
"database/sql/driver"
"errors"
"strings"
"time"
"entgo.io/ent"
@@ -8,11 +11,53 @@ import (
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"github.com/jackc/pgx/v5/pgtype"
"github.com/shopspring/decimal"
)
var shopDefaultRating = decimal.RequireFromString("5.00")
type TextArray pgtype.Array[string]
func (s *TextArray) Scan(src any) error {
if src == nil {
s.Elements = []string{}
s.Dims = nil
s.Valid = true
return nil
}
var strSrc string
switch v := src.(type) {
case string:
strSrc = v
case []byte:
strSrc = string(v)
default:
return errors.New("failed to scan text array")
}
trimmed := strings.Trim(strSrc, "{}")
if len(trimmed) == 0 {
s.Elements = []string{}
s.Dims = nil
s.Valid = true
return nil
}
s.Elements = strings.Split(trimmed, ",")
s.Dims = nil
s.Valid = true
return nil
}
func (s TextArray) Value() (driver.Value, error) {
if s.Elements == nil {
return []string{}, nil
}
return s.Elements, nil
}
// Shops holds the schema definition for the Shops entity.
type Shops struct {
ent.Schema
@@ -56,7 +101,9 @@ func (Shops) Fields() []ent.Field {
field.Bool("allow_multi_shop").Optional().Default(false),
field.Bool("allow_independent_orders").Optional().Default(true),
field.String("dispatch_mode").MaxLen(20).Default("manual"),
field.Strings("announcements").Optional().Default([]string{}),
field.Other("announcements", TextArray{}).
SchemaType(map[string]string{dialect.Postgres: "text[]"}).
Optional(),
field.JSON("template_config", map[string]any{}).Optional(),
field.Time("created_at").Default(time.Now).Immutable(),
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
+8 -7
View File
@@ -5,6 +5,7 @@ package models
import (
"encoding/json"
"fmt"
"juwan-backend/app/shop/rpc/internal/models/schema"
"juwan-backend/app/shop/rpc/internal/models/shops"
"strings"
"time"
@@ -44,7 +45,7 @@ type Shops struct {
// DispatchMode holds the value of the "dispatch_mode" field.
DispatchMode string `json:"dispatch_mode,omitempty"`
// Announcements holds the value of the "announcements" field.
Announcements []string `json:"announcements,omitempty"`
Announcements schema.TextArray `json:"announcements,omitempty"`
// TemplateConfig holds the value of the "template_config" field.
TemplateConfig map[string]interface{} `json:"template_config,omitempty"`
// CreatedAt holds the value of the "created_at" field.
@@ -59,10 +60,12 @@ func (*Shops) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case shops.FieldAnnouncements, shops.FieldTemplateConfig:
case shops.FieldTemplateConfig:
values[i] = new([]byte)
case shops.FieldRating, shops.FieldCommissionValue:
values[i] = new(decimal.Decimal)
case shops.FieldAnnouncements:
values[i] = new(schema.TextArray)
case shops.FieldAllowMultiShop, shops.FieldAllowIndependentOrders:
values[i] = new(sql.NullBool)
case shops.FieldID, shops.FieldOwnerID, shops.FieldTotalOrders, shops.FieldPlayerCount:
@@ -167,12 +170,10 @@ func (_m *Shops) assignValues(columns []string, values []any) error {
_m.DispatchMode = value.String
}
case shops.FieldAnnouncements:
if value, ok := values[i].(*[]byte); !ok {
if value, ok := values[i].(*schema.TextArray); !ok {
return fmt.Errorf("unexpected type %T for field announcements", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &_m.Announcements); err != nil {
return fmt.Errorf("unmarshal field announcements: %w", err)
}
} else if value != nil {
_m.Announcements = *value
}
case shops.FieldTemplateConfig:
if value, ok := values[i].(*[]byte); !ok {
+5 -2
View File
@@ -102,8 +102,6 @@ var (
DefaultDispatchMode string
// DispatchModeValidator is a validator for the "dispatch_mode" field. It is called by the builders before save.
DispatchModeValidator func(string) error
// DefaultAnnouncements holds the default value on creation for the "announcements" field.
DefaultAnnouncements []string
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
@@ -180,6 +178,11 @@ func ByDispatchMode(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDispatchMode, opts...).ToFunc()
}
// ByAnnouncements orders the results by the announcements field.
func ByAnnouncements(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldAnnouncements, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
@@ -4,6 +4,7 @@ package shops
import (
"juwan-backend/app/shop/rpc/internal/models/predicate"
"juwan-backend/app/shop/rpc/internal/models/schema"
"time"
"entgo.io/ent/dialect/sql"
@@ -115,6 +116,11 @@ func DispatchMode(v string) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldDispatchMode, v))
}
// Announcements applies equality check predicate on the "announcements" field. It's identical to AnnouncementsEQ.
func Announcements(v schema.TextArray) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldAnnouncements, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldCreatedAt, v))
@@ -740,6 +746,46 @@ func DispatchModeContainsFold(v string) predicate.Shops {
return predicate.Shops(sql.FieldContainsFold(FieldDispatchMode, v))
}
// AnnouncementsEQ applies the EQ predicate on the "announcements" field.
func AnnouncementsEQ(v schema.TextArray) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldAnnouncements, v))
}
// AnnouncementsNEQ applies the NEQ predicate on the "announcements" field.
func AnnouncementsNEQ(v schema.TextArray) predicate.Shops {
return predicate.Shops(sql.FieldNEQ(FieldAnnouncements, v))
}
// AnnouncementsIn applies the In predicate on the "announcements" field.
func AnnouncementsIn(vs ...schema.TextArray) predicate.Shops {
return predicate.Shops(sql.FieldIn(FieldAnnouncements, vs...))
}
// AnnouncementsNotIn applies the NotIn predicate on the "announcements" field.
func AnnouncementsNotIn(vs ...schema.TextArray) predicate.Shops {
return predicate.Shops(sql.FieldNotIn(FieldAnnouncements, vs...))
}
// AnnouncementsGT applies the GT predicate on the "announcements" field.
func AnnouncementsGT(v schema.TextArray) predicate.Shops {
return predicate.Shops(sql.FieldGT(FieldAnnouncements, v))
}
// AnnouncementsGTE applies the GTE predicate on the "announcements" field.
func AnnouncementsGTE(v schema.TextArray) predicate.Shops {
return predicate.Shops(sql.FieldGTE(FieldAnnouncements, v))
}
// AnnouncementsLT applies the LT predicate on the "announcements" field.
func AnnouncementsLT(v schema.TextArray) predicate.Shops {
return predicate.Shops(sql.FieldLT(FieldAnnouncements, v))
}
// AnnouncementsLTE applies the LTE predicate on the "announcements" field.
func AnnouncementsLTE(v schema.TextArray) predicate.Shops {
return predicate.Shops(sql.FieldLTE(FieldAnnouncements, v))
}
// AnnouncementsIsNil applies the IsNil predicate on the "announcements" field.
func AnnouncementsIsNil() predicate.Shops {
return predicate.Shops(sql.FieldIsNull(FieldAnnouncements))
+11 -6
View File
@@ -6,6 +6,7 @@ import (
"context"
"errors"
"fmt"
"juwan-backend/app/shop/rpc/internal/models/schema"
"juwan-backend/app/shop/rpc/internal/models/shops"
"time"
@@ -166,11 +167,19 @@ func (_c *ShopsCreate) SetNillableDispatchMode(v *string) *ShopsCreate {
}
// SetAnnouncements sets the "announcements" field.
func (_c *ShopsCreate) SetAnnouncements(v []string) *ShopsCreate {
func (_c *ShopsCreate) SetAnnouncements(v schema.TextArray) *ShopsCreate {
_c.mutation.SetAnnouncements(v)
return _c
}
// SetNillableAnnouncements sets the "announcements" field if the given value is not nil.
func (_c *ShopsCreate) SetNillableAnnouncements(v *schema.TextArray) *ShopsCreate {
if v != nil {
_c.SetAnnouncements(*v)
}
return _c
}
// SetTemplateConfig sets the "template_config" field.
func (_c *ShopsCreate) SetTemplateConfig(v map[string]interface{}) *ShopsCreate {
_c.mutation.SetTemplateConfig(v)
@@ -274,10 +283,6 @@ func (_c *ShopsCreate) defaults() {
v := shops.DefaultDispatchMode
_c.mutation.SetDispatchMode(v)
}
if _, ok := _c.mutation.Announcements(); !ok {
v := shops.DefaultAnnouncements
_c.mutation.SetAnnouncements(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := shops.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
@@ -407,7 +412,7 @@ func (_c *ShopsCreate) createSpec() (*Shops, *sqlgraph.CreateSpec) {
_node.DispatchMode = value
}
if value, ok := _c.mutation.Announcements(); ok {
_spec.SetField(shops.FieldAnnouncements, field.TypeJSON, value)
_spec.SetField(shops.FieldAnnouncements, field.TypeOther, value)
_node.Announcements = value
}
if value, ok := _c.mutation.TemplateConfig(); ok {
+17 -23
View File
@@ -7,12 +7,12 @@ import (
"errors"
"fmt"
"juwan-backend/app/shop/rpc/internal/models/predicate"
"juwan-backend/app/shop/rpc/internal/models/schema"
"juwan-backend/app/shop/rpc/internal/models/shops"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/dialect/sql/sqljson"
"entgo.io/ent/schema/field"
"github.com/shopspring/decimal"
)
@@ -262,14 +262,16 @@ func (_u *ShopsUpdate) SetNillableDispatchMode(v *string) *ShopsUpdate {
}
// SetAnnouncements sets the "announcements" field.
func (_u *ShopsUpdate) SetAnnouncements(v []string) *ShopsUpdate {
func (_u *ShopsUpdate) SetAnnouncements(v schema.TextArray) *ShopsUpdate {
_u.mutation.SetAnnouncements(v)
return _u
}
// AppendAnnouncements appends value to the "announcements" field.
func (_u *ShopsUpdate) AppendAnnouncements(v []string) *ShopsUpdate {
_u.mutation.AppendAnnouncements(v)
// SetNillableAnnouncements sets the "announcements" field if the given value is not nil.
func (_u *ShopsUpdate) SetNillableAnnouncements(v *schema.TextArray) *ShopsUpdate {
if v != nil {
_u.SetAnnouncements(*v)
}
return _u
}
@@ -437,15 +439,10 @@ func (_u *ShopsUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec.SetField(shops.FieldDispatchMode, field.TypeString, value)
}
if value, ok := _u.mutation.Announcements(); ok {
_spec.SetField(shops.FieldAnnouncements, field.TypeJSON, value)
}
if value, ok := _u.mutation.AppendedAnnouncements(); ok {
_spec.AddModifier(func(u *sql.UpdateBuilder) {
sqljson.Append(u, shops.FieldAnnouncements, value)
})
_spec.SetField(shops.FieldAnnouncements, field.TypeOther, value)
}
if _u.mutation.AnnouncementsCleared() {
_spec.ClearField(shops.FieldAnnouncements, field.TypeJSON)
_spec.ClearField(shops.FieldAnnouncements, field.TypeOther)
}
if value, ok := _u.mutation.TemplateConfig(); ok {
_spec.SetField(shops.FieldTemplateConfig, field.TypeJSON, value)
@@ -708,14 +705,16 @@ func (_u *ShopsUpdateOne) SetNillableDispatchMode(v *string) *ShopsUpdateOne {
}
// SetAnnouncements sets the "announcements" field.
func (_u *ShopsUpdateOne) SetAnnouncements(v []string) *ShopsUpdateOne {
func (_u *ShopsUpdateOne) SetAnnouncements(v schema.TextArray) *ShopsUpdateOne {
_u.mutation.SetAnnouncements(v)
return _u
}
// AppendAnnouncements appends value to the "announcements" field.
func (_u *ShopsUpdateOne) AppendAnnouncements(v []string) *ShopsUpdateOne {
_u.mutation.AppendAnnouncements(v)
// SetNillableAnnouncements sets the "announcements" field if the given value is not nil.
func (_u *ShopsUpdateOne) SetNillableAnnouncements(v *schema.TextArray) *ShopsUpdateOne {
if v != nil {
_u.SetAnnouncements(*v)
}
return _u
}
@@ -913,15 +912,10 @@ func (_u *ShopsUpdateOne) sqlSave(ctx context.Context) (_node *Shops, err error)
_spec.SetField(shops.FieldDispatchMode, field.TypeString, value)
}
if value, ok := _u.mutation.Announcements(); ok {
_spec.SetField(shops.FieldAnnouncements, field.TypeJSON, value)
}
if value, ok := _u.mutation.AppendedAnnouncements(); ok {
_spec.AddModifier(func(u *sql.UpdateBuilder) {
sqljson.Append(u, shops.FieldAnnouncements, value)
})
_spec.SetField(shops.FieldAnnouncements, field.TypeOther, value)
}
if _u.mutation.AnnouncementsCleared() {
_spec.ClearField(shops.FieldAnnouncements, field.TypeJSON)
_spec.ClearField(shops.FieldAnnouncements, field.TypeOther)
}
if value, ok := _u.mutation.TemplateConfig(); ok {
_spec.SetField(shops.FieldTemplateConfig, field.TypeJSON, value)