github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/modules/deploy/deploy_models.go (about)

     1  package deploy
     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/enums"
     7  	"github.com/machinefi/w3bstream/pkg/models"
     8  	"github.com/machinefi/w3bstream/pkg/types"
     9  	"github.com/machinefi/w3bstream/pkg/types/wasm"
    10  )
    11  
    12  type CondArgs struct {
    13  	ProjectID   types.SFID            `name:"-"`
    14  	InstanceIDs []types.SFID          `in:"query" name:"instanceID,omitempty"`
    15  	AppletIDs   []types.SFID          `in:"query" name:"appletID,omitempty"`
    16  	States      []enums.InstanceState `in:"query" name:"state,omitempty"`
    17  }
    18  
    19  func (r *CondArgs) Condition() builder.SqlCondition {
    20  	var (
    21  		m = &models.Instance{}
    22  		c []builder.SqlCondition
    23  	)
    24  
    25  	if r.ProjectID != 0 {
    26  		c = append(c, (&models.Applet{}).ColProjectID().Eq(r.ProjectID))
    27  	}
    28  	if len(r.InstanceIDs) > 0 {
    29  		if len(r.InstanceIDs) == 1 {
    30  			c = append(c, m.ColInstanceID().Eq(r.InstanceIDs[0]))
    31  		} else {
    32  			c = append(c, m.ColInstanceID().In(r.InstanceIDs))
    33  		}
    34  	}
    35  	if len(r.AppletIDs) > 0 {
    36  		if len(r.AppletIDs) == 1 {
    37  			c = append(c, m.ColAppletID().Eq(r.AppletIDs[0]))
    38  		} else {
    39  			c = append(c, m.ColAppletID().In(r.AppletIDs))
    40  		}
    41  	}
    42  	if len(r.States) > 0 {
    43  		if len(r.States) == 1 {
    44  			c = append(c, m.ColState().Eq(r.States[0]))
    45  		} else {
    46  			c = append(c, m.ColState().In(r.States))
    47  		}
    48  	}
    49  	return builder.And(c...)
    50  }
    51  
    52  type ListReq struct {
    53  	CondArgs
    54  	datatypes.Pager
    55  }
    56  
    57  type ListRsp struct {
    58  	Data  []models.Instance `json:"data"`
    59  	Total int64             `json:"total"`
    60  }
    61  
    62  type CreateReq struct {
    63  	Cache *wasm.Cache `json:"cache,omitempty"`
    64  }