fyp/logic/models/classes/list.go

52 lines
1.3 KiB
Go
Raw Permalink Normal View History

package model_classes
import (
2024-04-14 14:51:16 +01:00
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
)
func HandleList(handle *Handle) {
2024-04-14 15:19:32 +01:00
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 {
2024-03-09 10:52:08 +00:00
var class_row struct {
Name string
Model_id string
}
2024-04-14 15:19:32 +01:00
err := GetDBOnce(c, &class_row, "model_classes where id=$1", dat.Id)
2024-03-09 10:52:08 +00:00
if err == NotFoundError {
return c.JsonBadRequest("Model Class not found!")
} else if err != nil {
2024-04-14 15:19:32 +01:00
return c.E500M("Failed to get classes", err)
}
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-04-14 15:19:32 +01:00
rows, err := GetDbMultitple[baserow](c, "model_data_point where class_id=$1 limit 11 offset $2", dat.Id, dat.Page*10)
if err != nil {
2024-04-14 15:19:32 +01:00
return c.E500M("Failed to get classes", err)
}
2024-03-09 10:52:08 +00:00
max_len := min(11, len(rows))
2024-04-14 14:51:16 +01:00
c.ShowMessage = false
2024-04-14 15:19:32 +01:00
return c.SendJSON(struct {
ImageList []*baserow `json:"image_list"`
Page int `json:"page"`
ShowNext bool `json:"showNext"`
}{
2024-03-09 10:52:08 +00:00
ImageList: rows[0:max_len],
2024-04-14 15:19:32 +01:00
Page: dat.Page,
2024-03-09 10:52:08 +00:00
ShowNext: len(rows) == 11,
})
})
}