|
|
|
@ -2,7 +2,6 @@ package admin |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"maps" |
|
|
|
|
"strconv" |
|
|
|
|
"reflect" |
|
|
|
|
"fmt" |
|
|
|
|
"github.com/gofiber/fiber/v2" |
|
|
|
@ -23,10 +22,13 @@ func GetApiTableIndex(c *fiber.Ctx) error { |
|
|
|
|
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); |
|
|
|
|
page := c.QueryInt("page", 0) |
|
|
|
|
fmt.Println("-------------------------", page) |
|
|
|
|
if page < 0 { page = 0 } |
|
|
|
|
|
|
|
|
|
result, err := SelectTable(table, type_is, 20, uint64(page)); |
|
|
|
|
if err != nil { return IfErrNil(err, c) } |
|
|
|
|
|
|
|
|
|
return c.JSON(result) |
|
|
|
@ -38,12 +40,12 @@ func GetPageSelectAll(c *fiber.Ctx) error { |
|
|
|
|
|
|
|
|
|
func GetApiSelectOne(c *fiber.Ctx) error { |
|
|
|
|
table := c.Params("table") |
|
|
|
|
id, err := strconv.ParseInt(c.Params("id"), 10, 64) |
|
|
|
|
if err != nil { return IfErrNil(err, c) } |
|
|
|
|
id, err := c.ParamsInt("id", -1) |
|
|
|
|
if err != nil || id < 0 { return IfErrNil(err, c) } |
|
|
|
|
|
|
|
|
|
type_is := data.Models()[table] |
|
|
|
|
|
|
|
|
|
result, err := Get(table, type_is, id) |
|
|
|
|
result, err := Get(table, type_is, int64(id)) |
|
|
|
|
if err != nil { return IfErrNil(err, c) } |
|
|
|
|
|
|
|
|
|
return c.JSON(result.Interface()) |
|
|
|
@ -51,8 +53,8 @@ func GetApiSelectOne(c *fiber.Ctx) error { |
|
|
|
|
|
|
|
|
|
func GetPageSelectOne(c *fiber.Ctx) error { |
|
|
|
|
table := c.Params("table") |
|
|
|
|
id, err := strconv.ParseInt(c.Params("id"), 10, 64) |
|
|
|
|
if err != nil { return IfErrNil(err, c) } |
|
|
|
|
id, err := c.ParamsInt("id", -1) |
|
|
|
|
if err != nil || id < 0 { return IfErrNil(err, c) } |
|
|
|
|
|
|
|
|
|
return c.Render("admin/table/view", fiber.Map{ |
|
|
|
|
"Table": table, |
|
|
|
@ -100,10 +102,10 @@ func PostApiInsert(c *fiber.Ctx) error { |
|
|
|
|
func DeleteApi(c *fiber.Ctx) error { |
|
|
|
|
table := c.Params("table") |
|
|
|
|
|
|
|
|
|
id, err := strconv.ParseInt(c.Params("id"), 10, 64) |
|
|
|
|
if err != nil { return IfErrNil(err, c) } |
|
|
|
|
id, err := c.ParamsInt("id", -1) |
|
|
|
|
if err != nil || id < 0 { return IfErrNil(err, c) } |
|
|
|
|
|
|
|
|
|
err = Delete(table, id) |
|
|
|
|
err = Delete(table, int64(id)) |
|
|
|
|
if err != nil { return IfErrNil(err, c) } |
|
|
|
|
|
|
|
|
|
return c.JSON(fiber.Map{}) |
|
|
|
|