71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package model_classes
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
|
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
|
|
)
|
|
|
|
func HandleList(handle *Handle) {
|
|
handle.Get("/models/data/list", func(c *Context) *Error {
|
|
if !c.CheckAuthLevel(1) {
|
|
return nil
|
|
}
|
|
|
|
id, err := GetIdFromUrl(c, "id")
|
|
if err != nil {
|
|
return c.JsonBadRequest("Model Class not found!")
|
|
}
|
|
|
|
page := 0
|
|
if c.R.URL.Query().Has("page") {
|
|
page_url := c.R.URL.Query().Get("page")
|
|
page_url_number, err := strconv.Atoi(page_url)
|
|
if err != nil {
|
|
return c.JsonBadRequest("Page is not a number")
|
|
}
|
|
page = page_url_number
|
|
}
|
|
|
|
var class_row struct {
|
|
Name string
|
|
Model_id string
|
|
}
|
|
|
|
err = utils.GetDBOnce(c, &class_row, "model_classes where id=$1", id)
|
|
if err == NotFoundError {
|
|
return c.JsonBadRequest("Model Class not found!")
|
|
} else if err != nil {
|
|
return c.Error500(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 := utils.GetDbMultitple[baserow](c, "model_data_point where class_id=$1 limit 11 offset $2", id, page*10)
|
|
if err != nil {
|
|
return c.Error500(err)
|
|
}
|
|
|
|
type ReturnType struct {
|
|
ImageList []*baserow `json:"image_list"`
|
|
Page int `json:"page"`
|
|
ShowNext bool `json:"showNext"`
|
|
}
|
|
|
|
max_len := min(11, len(rows))
|
|
|
|
c.ShowMessage = false;
|
|
return c.SendJSON(ReturnType{
|
|
ImageList: rows[0:max_len],
|
|
Page: page,
|
|
ShowNext: len(rows) == 11,
|
|
})
|
|
})
|
|
}
|