star
This commit is contained in:
@@ -30,6 +30,7 @@ type Model struct {
|
||||
UserID int `json:"user_id"` // 模型的所有者
|
||||
DatasetID int `json:"dataset_id"` // 模型所使用的數據集ID
|
||||
ServerID string `json:"server_id"` // 模型所在服務器(訓練機或推理機)
|
||||
Stars StarList `json:"stars"` // 模型的收藏者
|
||||
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
||||
}
|
||||
|
@@ -27,3 +27,13 @@ func (list *TagList) Scan(value interface{}) error {
|
||||
func (list TagList) Value() (driver.Value, error) {
|
||||
return json.Marshal(list)
|
||||
}
|
||||
|
||||
type StarList []int
|
||||
|
||||
func (list *StarList) Scan(value interface{}) error {
|
||||
return json.Unmarshal(value.([]byte), list)
|
||||
}
|
||||
|
||||
func (list StarList) Value() (driver.Value, error) {
|
||||
return json.Marshal(list)
|
||||
}
|
||||
|
@@ -28,27 +28,32 @@ func ModelsGet(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// 按照 user_id 篩選
|
||||
if user_id := utils.ParamInt(r.URL.Query().Get("user_id"), 0); user_id > 0 {
|
||||
db.Where("user_id = ?", user_id)
|
||||
db = db.Where("user_id = ?", user_id)
|
||||
}
|
||||
|
||||
// 按照 star 篩選
|
||||
if star := utils.ParamInt(r.URL.Query().Get("star"), 0); star > 0 {
|
||||
db = db.Where("stars LIKE ?", "%"+strconv.Itoa(star)+"%")
|
||||
}
|
||||
|
||||
// 按照 name 模糊搜索
|
||||
if name := r.URL.Query().Get("name"); name != "" {
|
||||
db.Where("name LIKE ?", "%"+name+"%")
|
||||
db = db.Where("name LIKE ?", "%"+name+"%")
|
||||
}
|
||||
|
||||
// 按照 type 篩選
|
||||
if model_type := r.URL.Query().Get("type"); model_type != "" {
|
||||
db.Where("type = ?", model_type)
|
||||
db = db.Where("type = ?", model_type)
|
||||
}
|
||||
|
||||
// 按照 status 篩選
|
||||
if status := r.URL.Query().Get("status"); status != "" {
|
||||
db.Where("status = ?", status)
|
||||
db = db.Where("status = ?", status)
|
||||
}
|
||||
|
||||
// 按照 tag 篩選
|
||||
if tag := r.URL.Query().Get("tag"); tag != "" {
|
||||
db.Where("tags LIKE ?", "%"+tag+"%")
|
||||
db = db.Where("tags LIKE ?", "%"+tag+"%")
|
||||
}
|
||||
|
||||
db.Offset((listview.Page - 1) * listview.PageSize).Limit(listview.PageSize).Find(&model_list)
|
||||
|
Reference in New Issue
Block a user