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

     1  package resource
     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  	AccountID      types.SFID      `name:"-"`
    12  	ResourceIDs    []types.SFID    `in:"query" name:"resourceID,omitempty"`
    13  	UploadedBefore types.Timestamp `in:"query" name:"uploadedBefore,omitempty"`
    14  	UploadedAfter  types.Timestamp `in:"query" name:"uploadedAfter,omitempty"`
    15  	ExpireBefore   types.Timestamp `in:"query" name:"expireBefore,omitempty"`
    16  	ExpireAfter    types.Timestamp `in:"query" name:"expireAfter,omitempty"`
    17  	FilenameLike   string          `in:"query" name:"filenameLike,omitempty"`
    18  	Filenames      []string        `in:"query" name:"filename,omitempty"`
    19  	Md5            string          `in:"query" name:"md5,omitempty"`
    20  }
    21  
    22  func (r *CondArgs) Condition() builder.SqlCondition {
    23  	var (
    24  		own = &models.ResourceOwnership{}
    25  		res = &models.Resource{}
    26  		c   []builder.SqlCondition
    27  	)
    28  	if r.AccountID != 0 {
    29  		c = append(c, own.ColAccountID().Eq(r.AccountID))
    30  	}
    31  	if len(r.ResourceIDs) > 0 {
    32  		c = append(c, res.ColResourceID().In(r.ResourceIDs))
    33  	}
    34  	if !r.UploadedBefore.IsZero() {
    35  		c = append(c, own.ColUploadedAt().Lte(r.UploadedBefore))
    36  	}
    37  	if !r.UploadedAfter.IsZero() {
    38  		c = append(c, own.ColUploadedAt().Gte(r.UploadedAfter))
    39  	}
    40  	if !r.ExpireBefore.IsZero() {
    41  		c = append(c, own.ColExpireAt().Lte(r.ExpireBefore))
    42  	}
    43  	if !r.UploadedAfter.IsZero() {
    44  		c = append(c, own.ColExpireAt().Gte(r.ExpireAfter))
    45  	}
    46  	if len(r.Filenames) > 0 {
    47  		c = append(c, own.ColFilename().In(r.Filenames))
    48  	}
    49  	if len(r.FilenameLike) > 0 {
    50  		c = append(c, own.ColFilename().Like(r.FilenameLike))
    51  	}
    52  	if r.Md5 != "" {
    53  		c = append(c, res.ColMd5().Eq(r.Md5))
    54  	}
    55  	return builder.And(c...)
    56  }
    57  
    58  type ListReq struct {
    59  	CondArgs
    60  	datatypes.Pager
    61  }
    62  
    63  type ResourceInfo struct {
    64  	models.RelResource
    65  	models.ResourceInfo
    66  	models.ResourceOwnerInfo
    67  	datatypes.OperationTimes
    68  }
    69  
    70  type ListRsp struct {
    71  	Data  []*ResourceInfo `json:"data"`
    72  	Total int64           `json:"total"`
    73  }
    74  
    75  type DownLoadResourceRsp struct {
    76  	FileName string `json:"fileName"`
    77  	Url      string `json:"url"`
    78  }