fyp/logic/models/classes/list.go

52 lines
1.3 KiB
Go

package model_classes
import (
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
)
func HandleList(handle *Handle) {
type DataList struct {
Id string `json:"id" validate:"required"`
Page int `json:"page"`
}
PostAuthJson(handle, "/models/data/list", User_Normal, func(c *Context, dat *DataList) *Error {
var class_row struct {
Name string
Model_id string
}
err := GetDBOnce(c, &class_row, "model_classes where id=$1", dat.Id)
if err == NotFoundError {
return c.JsonBadRequest("Model Class not found!")
} else if err != nil {
return c.E500M("Failed to get classes", err)
}
type baserow struct {
Id string `json:"id"`
File_Path string `json:"file_path"`
Model_Mode int `json:"model_mode"`
Status int `json:"status"`
}
rows, err := GetDbMultitple[baserow](c, "model_data_point where class_id=$1 limit 11 offset $2", dat.Id, dat.Page*10)
if err != nil {
return c.E500M("Failed to get classes", err)
}
max_len := min(11, len(rows))
c.ShowMessage = false
return c.SendJSON(struct {
ImageList []*baserow `json:"image_list"`
Page int `json:"page"`
ShowNext bool `json:"showNext"`
}{
ImageList: rows[0:max_len],
Page: dat.Page,
ShowNext: len(rows) == 11,
})
})
}