Refactor order and tenant ledger models to use consts for Currency and Type fields; add new UserStatus values; implement comprehensive test cases for content, creator, order, super, and wallet services.

This commit is contained in:
2025-12-29 14:21:20 +08:00
parent d648a1e45b
commit 8fa3d18a9c
30 changed files with 2251 additions and 85 deletions

View File

@@ -35,6 +35,11 @@ func newComment(db *gorm.DB, opts ...gen.DOOption) commentQuery {
_commentQuery.CreatedAt = field.NewTime(tableName, "created_at")
_commentQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
_commentQuery.DeletedAt = field.NewField(tableName, "deleted_at")
_commentQuery.User = commentQueryBelongsToUser{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("User", "User"),
}
_commentQuery.fillFieldMap()
@@ -55,6 +60,7 @@ type commentQuery struct {
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
User commentQueryBelongsToUser
fieldMap map[string]field.Expr
}
@@ -113,7 +119,7 @@ func (c *commentQuery) GetFieldByName(fieldName string) (field.OrderExpr, bool)
}
func (c *commentQuery) fillFieldMap() {
c.fieldMap = make(map[string]field.Expr, 10)
c.fieldMap = make(map[string]field.Expr, 11)
c.fieldMap["id"] = c.ID
c.fieldMap["tenant_id"] = c.TenantID
c.fieldMap["user_id"] = c.UserID
@@ -124,18 +130,103 @@ func (c *commentQuery) fillFieldMap() {
c.fieldMap["created_at"] = c.CreatedAt
c.fieldMap["updated_at"] = c.UpdatedAt
c.fieldMap["deleted_at"] = c.DeletedAt
}
func (c commentQuery) clone(db *gorm.DB) commentQuery {
c.commentQueryDo.ReplaceConnPool(db.Statement.ConnPool)
c.User.db = db.Session(&gorm.Session{Initialized: true})
c.User.db.Statement.ConnPool = db.Statement.ConnPool
return c
}
func (c commentQuery) replaceDB(db *gorm.DB) commentQuery {
c.commentQueryDo.ReplaceDB(db)
c.User.db = db.Session(&gorm.Session{})
return c
}
type commentQueryBelongsToUser struct {
db *gorm.DB
field.RelationField
}
func (a commentQueryBelongsToUser) Where(conds ...field.Expr) *commentQueryBelongsToUser {
if len(conds) == 0 {
return &a
}
exprs := make([]clause.Expression, 0, len(conds))
for _, cond := range conds {
exprs = append(exprs, cond.BeCond().(clause.Expression))
}
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
return &a
}
func (a commentQueryBelongsToUser) WithContext(ctx context.Context) *commentQueryBelongsToUser {
a.db = a.db.WithContext(ctx)
return &a
}
func (a commentQueryBelongsToUser) Session(session *gorm.Session) *commentQueryBelongsToUser {
a.db = a.db.Session(session)
return &a
}
func (a commentQueryBelongsToUser) Model(m *Comment) *commentQueryBelongsToUserTx {
return &commentQueryBelongsToUserTx{a.db.Model(m).Association(a.Name())}
}
func (a commentQueryBelongsToUser) Unscoped() *commentQueryBelongsToUser {
a.db = a.db.Unscoped()
return &a
}
type commentQueryBelongsToUserTx struct{ tx *gorm.Association }
func (a commentQueryBelongsToUserTx) Find() (result *User, err error) {
return result, a.tx.Find(&result)
}
func (a commentQueryBelongsToUserTx) Append(values ...*User) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Append(targetValues...)
}
func (a commentQueryBelongsToUserTx) Replace(values ...*User) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Replace(targetValues...)
}
func (a commentQueryBelongsToUserTx) Delete(values ...*User) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Delete(targetValues...)
}
func (a commentQueryBelongsToUserTx) Clear() error {
return a.tx.Clear()
}
func (a commentQueryBelongsToUserTx) Count() int64 {
return a.tx.Count()
}
func (a commentQueryBelongsToUserTx) Unscoped() *commentQueryBelongsToUserTx {
a.tx = a.tx.Unscoped()
return &a
}
type commentQueryDo struct{ gen.DO }
func (c commentQueryDo) Debug() *commentQueryDo {