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

     1  package project
     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/modules/applet"
     8  	"github.com/machinefi/w3bstream/pkg/types"
     9  	"github.com/machinefi/w3bstream/pkg/types/wasm"
    10  )
    11  
    12  type CondArgs struct {
    13  	AccountID  types.SFID   `name:"-"`
    14  	ProjectIDs []types.SFID `in:"query" name:"projectID,omitempty"`
    15  	Names      []string     `in:"query" name:"name,omitempty"`
    16  	Versions   []string     `in:"query" name:"version,omitempty"`
    17  }
    18  
    19  func (r *CondArgs) Condition() builder.SqlCondition {
    20  	m := &models.Project{}
    21  	c := make([]builder.SqlCondition, 0)
    22  
    23  	if r.AccountID != 0 {
    24  		c = append(c, m.ColAccountID().Eq(r.AccountID))
    25  	}
    26  	if len(r.ProjectIDs) > 0 {
    27  		c = append(c, m.ColProjectID().In(r.ProjectIDs))
    28  	}
    29  	if len(r.Names) > 0 {
    30  		// TODO how to fix name's prefix?
    31  		c = append(c, m.ColName().In(r.Names))
    32  	}
    33  	if len(r.Versions) > 0 {
    34  		c = append(c, m.ColVersion().In(r.Versions))
    35  	}
    36  	c = append(c, m.ColDeletedAt().Eq(0))
    37  	return builder.And(c...)
    38  }
    39  
    40  type ListReq struct {
    41  	CondArgs
    42  	datatypes.Pager
    43  }
    44  
    45  type ListRsp struct {
    46  	Data  []models.Project `json:"data"`
    47  	Total int64            `json:"total"`
    48  }
    49  
    50  type Detail struct {
    51  	ProjectID   types.SFID       `json:"projectID"`
    52  	ProjectName string           `json:"projectName"`
    53  	Applets     []*applet.Detail `json:"applets,omitempty"`
    54  }
    55  
    56  type ListDetailRsp struct {
    57  	Data  []*Detail `json:"data"`
    58  	Total int64     `json:"total"`
    59  }
    60  
    61  type CreateReq struct {
    62  	models.ProjectName
    63  	models.ProjectBase
    64  	Env      *wasm.Env      `json:"envs,omitempty"`
    65  	Database *wasm.Database `json:"database,omitempty"`
    66  	Flow     *wasm.Flow     `json:"flow,omitempty"`
    67  }
    68  
    69  type CreateRsp struct {
    70  	*models.Project
    71  	Env          *wasm.Env      `json:"envs,omitempty"`
    72  	Database     *wasm.Database `json:"database,omitempty"`
    73  	Flow         *wasm.Flow     `json:"flow,omitempty"`
    74  	ChannelState datatypes.Bool `json:"channelState"`
    75  }