A website for my game dev stuff that supports chat, etc.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
zedshaw-games/admin/handlers.go

86 lines
2.0 KiB

package admin
import (
"maps"
"strconv"
"github.com/gofiber/fiber/v2"
"zedshaw.games/webapp/data"
"zedshaw.games/webapp/api"
)
func GetApiTableIndex(c *fiber.Ctx) error {
var tables []string
for k := range maps.Keys(data.Models()) {
tables = append(tables, k)
}
return c.JSON(tables)
}
func GetApiSelectAll(c *fiber.Ctx) error {
table := c.Params("table")
if table == "" { return c.Redirect("/admin/") }
type_is := data.Models()[table]
result, err := SelectTable(table, type_is, 20, 0);
if err != nil { return api.IfErrNil(err, c) }
return c.JSON(result)
}
func GetPageSelectAll(c *fiber.Ctx) error {
return c.Render("admin/table/contents", fiber.Map{"Table": c.Params("table")})
}
func GetApiSelectOne(c *fiber.Ctx) error {
table := c.Params("table")
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
if err != nil { return api.IfErrNil(err, c) }
type_is := data.Models()[table]
result, err := Get(table, type_is, id)
if err != nil { return api.IfErrNil(err, c) }
return c.JSON(result.Interface())
}
func GetPageSelectOne(c *fiber.Ctx) error {
table := c.Params("table")
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
if err != nil { return api.IfErrNil(err, c) }
return c.Render("admin/table/view", fiber.Map{
"Table": table,
"Id": id,
})
}
func PostApiUpdate(c *fiber.Ctx) error {
return c.JSON(fiber.Map{})
}
func PutApiInsert(c *fiber.Ctx) error {
return c.JSON(fiber.Map{})
}
func DeleteApi(c *fiber.Ctx) error {
return c.JSON(fiber.Map{})
}
func Setup(app *fiber.App) {
app.Get("/api/admin/table/", GetApiTableIndex)
app.Get("/api/admin/table/:table/", GetApiSelectAll)
app.Get("/admin/table/:table/", GetPageSelectAll)
app.Get("/api/admin/table/:table/:id/", GetApiSelectOne)
app.Get("/admin/table/:table/:id/", GetPageSelectOne)
app.Post("/api/admin/table/:table/:id/", PostApiUpdate)
app.Put("/api/admin/table/:table/:id/", PutApiInsert)
app.Delete("/api/admin/table/:table/:id/", DeleteApi)
}