github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/modules/operator/models.go (about) 1 package operator 2 3 import ( 4 "github.com/machinefi/w3bstream/pkg/depends/base/types" 5 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/builder" 6 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/datatypes" 7 "github.com/machinefi/w3bstream/pkg/enums" 8 "github.com/machinefi/w3bstream/pkg/models" 9 ) 10 11 type CreateReq struct { 12 Name string `json:"name"` 13 PrivateKey string `json:"privateKey"` 14 PaymasterKey string `json:"paymasterKey,omitempty"` 15 Type enums.OperatorKeyType `json:"type,omitempty,default='1'"` 16 } 17 18 type CondArgs struct { 19 AccountID types.SFID `name:"-"` 20 } 21 22 type Detail struct { 23 models.Operator 24 Address string `json:"address"` 25 } 26 27 func (r *CondArgs) Condition() builder.SqlCondition { 28 var ( 29 m = &models.Operator{} 30 cs []builder.SqlCondition 31 ) 32 33 if r.AccountID != 0 { 34 cs = append(cs, m.ColAccountID().Eq(r.AccountID)) 35 } 36 cs = append(cs, m.ColDeletedAt().Eq(0)) 37 return builder.And(cs...) 38 } 39 40 type ListReq struct { 41 CondArgs 42 datatypes.Pager 43 } 44 45 func (r *ListReq) Additions() builder.Additions { 46 m := &models.Operator{} 47 return builder.Additions{ 48 builder.OrderBy( 49 builder.DescOrder(m.ColUpdatedAt()), 50 builder.DescOrder(m.ColCreatedAt()), 51 ), 52 r.Pager.Addition(), 53 } 54 } 55 56 type ListRsp struct { 57 Data []models.Operator `json:"data"` 58 Total int64 `json:"total"` 59 } 60 61 type ListDetailRsp struct { 62 Data []Detail `json:"data"` 63 Total int64 `json:"total"` 64 }