github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/modules/strategy/strategy_models.go (about) 1 package strategy 2 3 import ( 4 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/builder" 5 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/datatypes" 6 "github.com/machinefi/w3bstream/pkg/models" 7 "github.com/machinefi/w3bstream/pkg/types" 8 ) 9 10 type CondArgs struct { 11 ProjectID types.SFID `name:"-"` 12 AppletIDs []types.SFID `in:"query" name:"appletID,omitempty"` 13 StrategyIDs []types.SFID `in:"query" name:"strategyID,omitempty"` 14 EventTypes []string `in:"query" name:"eventType,omitempty"` 15 Handlers []string `in:"query" name:"handler,omitempty"` 16 } 17 18 func (r *CondArgs) Condition() builder.SqlCondition { 19 var ( 20 m = &models.Strategy{} 21 cs []builder.SqlCondition 22 ) 23 24 if r.ProjectID != 0 { 25 cs = append(cs, m.ColProjectID().Eq(r.ProjectID)) 26 } 27 if len(r.AppletIDs) > 0 { 28 cs = append(cs, m.ColAppletID().In(r.AppletIDs)) 29 } 30 if len(r.StrategyIDs) > 0 { 31 cs = append(cs, m.ColStrategyID().In(r.StrategyIDs)) 32 } 33 if len(r.EventTypes) > 0 { 34 cs = append(cs, m.ColEventType().In(r.EventTypes)) 35 } 36 if len(r.Handlers) > 0 { 37 cs = append(cs, m.ColHandler().In(r.Handlers)) 38 } 39 cs = append(cs, m.ColDeletedAt().Eq(0)) 40 41 return builder.And(cs...) 42 } 43 44 type ListReq struct { 45 CondArgs 46 datatypes.Pager 47 } 48 49 func (r *ListReq) Additions() builder.Additions { 50 m := &models.Strategy{} 51 return builder.Additions{ 52 builder.OrderBy( 53 builder.DescOrder(m.ColUpdatedAt()), 54 builder.DescOrder(m.ColCreatedAt()), 55 ), 56 r.Pager.Addition(), 57 } 58 } 59 60 type ListRsp struct { 61 Data []models.Strategy `json:"data"` 62 Total int64 `json:"total"` 63 } 64 65 type ListDetailRsp struct { 66 Data []*Detail `json:"data"` // Data strategy data list 67 Total int64 `json:"total"` // Total strategy count under current projectID 68 } 69 70 type Detail struct { 71 types.StrategyResult 72 datatypes.OperationTimes 73 } 74 75 type CreateReq struct { 76 models.RelApplet 77 models.StrategyInfo 78 } 79 80 type BatchCreateReq struct { 81 Strategies []CreateReq `json:"strategies"` 82 } 83 84 type UpdateReq = CreateReq