2023-09-23 11:44:36 +01:00
|
|
|
package model_classes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
2024-04-14 14:51:16 +01:00
|
|
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
|
2024-03-01 23:03:25 +00:00
|
|
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
|
2023-09-23 11:44:36 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func HandleList(handle *Handle) {
|
2024-03-09 10:52:08 +00:00
|
|
|
handle.Get("/models/data/list", func(c *Context) *Error {
|
|
|
|
if !c.CheckAuthLevel(1) {
|
2024-03-01 23:03:25 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-03-09 10:52:08 +00:00
|
|
|
id, err := GetIdFromUrl(c, "id")
|
2024-03-01 23:03:25 +00:00
|
|
|
if err != nil {
|
2024-03-09 10:52:08 +00:00
|
|
|
return c.JsonBadRequest("Model Class not found!")
|
2024-03-01 23:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
page := 0
|
2024-03-09 10:52:08 +00:00
|
|
|
if c.R.URL.Query().Has("page") {
|
|
|
|
page_url := c.R.URL.Query().Get("page")
|
2024-03-01 23:03:25 +00:00
|
|
|
page_url_number, err := strconv.Atoi(page_url)
|
|
|
|
if err != nil {
|
2024-03-09 10:52:08 +00:00
|
|
|
return c.JsonBadRequest("Page is not a number")
|
2024-03-01 23:03:25 +00:00
|
|
|
}
|
|
|
|
page = page_url_number
|
|
|
|
}
|
|
|
|
|
2024-03-09 10:52:08 +00:00
|
|
|
var class_row struct {
|
|
|
|
Name string
|
|
|
|
Model_id string
|
2024-03-01 23:03:25 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 14:51:16 +01:00
|
|
|
err = GetDBOnce(c, &class_row, "model_classes where id=$1", id)
|
2024-03-09 10:52:08 +00:00
|
|
|
if err == NotFoundError {
|
|
|
|
return c.JsonBadRequest("Model Class not found!")
|
|
|
|
} else if err != nil {
|
|
|
|
return c.Error500(err)
|
2024-03-01 23:03:25 +00:00
|
|
|
}
|
|
|
|
|
2024-03-09 10:52:08 +00:00
|
|
|
type baserow struct {
|
|
|
|
Id string `json:"id"`
|
|
|
|
File_Path string `json:"file_path"`
|
|
|
|
Model_Mode int `json:"model_mode"`
|
|
|
|
Status int `json:"status"`
|
2024-03-01 23:03:25 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 14:51:16 +01:00
|
|
|
rows, err := GetDbMultitple[baserow](c, "model_data_point where class_id=$1 limit 11 offset $2", id, page*10)
|
2024-03-01 23:03:25 +00:00
|
|
|
if err != nil {
|
2024-03-09 10:52:08 +00:00
|
|
|
return c.Error500(err)
|
2024-03-01 23:03:25 +00:00
|
|
|
}
|
|
|
|
|
2024-03-09 10:52:08 +00:00
|
|
|
type ReturnType struct {
|
|
|
|
ImageList []*baserow `json:"image_list"`
|
|
|
|
Page int `json:"page"`
|
|
|
|
ShowNext bool `json:"showNext"`
|
2024-03-01 23:03:25 +00:00
|
|
|
}
|
|
|
|
|
2024-03-09 10:52:08 +00:00
|
|
|
max_len := min(11, len(rows))
|
2024-03-01 23:03:25 +00:00
|
|
|
|
2024-04-14 14:51:16 +01:00
|
|
|
c.ShowMessage = false
|
2024-03-09 10:52:08 +00:00
|
|
|
return c.SendJSON(ReturnType{
|
|
|
|
ImageList: rows[0:max_len],
|
|
|
|
Page: page,
|
|
|
|
ShowNext: len(rows) == 11,
|
|
|
|
})
|
2024-03-01 23:03:25 +00:00
|
|
|
})
|
2023-09-23 11:44:36 +01:00
|
|
|
}
|