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

     1  package trafficlimit
     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  	Threshold int                    `json:"threshold"`
    13  	Duration  types.Duration         `json:"duration"`
    14  	ApiType   enums.TrafficLimitType `json:"apiType"`
    15  }
    16  
    17  type UpdateReq struct {
    18  	Threshold int            `json:"threshold"`
    19  	Duration  types.Duration `json:"duration"`
    20  }
    21  
    22  type CondArgs struct {
    23  	ProjectID types.SFID             `name:"-"`
    24  	ApiType   enums.TrafficLimitType `in:"query" name:"apiType,omitempty"`
    25  }
    26  
    27  func (r *CondArgs) Condition() builder.SqlCondition {
    28  	var (
    29  		m = &models.TrafficLimit{}
    30  		c []builder.SqlCondition
    31  	)
    32  	if r.ProjectID != 0 {
    33  		c = append(c, m.ColProjectID().Eq(r.ProjectID))
    34  	}
    35  	if r.ApiType != 0 {
    36  		c = append(c, m.ColApiType().In(r.ApiType))
    37  	}
    38  	return builder.And(c...)
    39  }
    40  
    41  type ListReq struct {
    42  	CondArgs
    43  	datatypes.Pager
    44  }
    45  
    46  func (r *ListReq) Additions() builder.Additions {
    47  	m := &models.TrafficLimit{}
    48  	return builder.Additions{
    49  		builder.OrderBy(
    50  			builder.DescOrder(m.ColUpdatedAt()),
    51  			builder.DescOrder(m.ColCreatedAt()),
    52  		),
    53  		r.Pager.Addition(),
    54  	}
    55  }
    56  
    57  type ListRsp struct {
    58  	Data  []models.TrafficLimit `json:"data"`
    59  	Total int64                 `json:"total"`
    60  }
    61  
    62  type Detail struct {
    63  	ProjectName string `json:"projectName" db:"f_project_name"`
    64  	models.TrafficLimit
    65  	datatypes.OperationTimes
    66  }
    67  
    68  type ListDetailRsp struct {
    69  	Total int64     `json:"total"`
    70  	Data  []*Detail `json:"data"`
    71  }