You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.tad17.ru/itman/stem/stemdb"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
)
|
|
|
|
|
|
|
|
// The function `initRouter` initializes the router for a Fiber app, sets up static file serving, and
|
|
|
|
// defines routes for a test page and a list of books.
|
|
|
|
func initRouter(app *fiber.App) {
|
|
|
|
db := stemdb.Connect()
|
|
|
|
|
|
|
|
app.Static("/", "app/dist")
|
|
|
|
app.Static("/assets", "app/dist/assets", fiber.Static{
|
|
|
|
Compress: true,
|
|
|
|
})
|
|
|
|
app.Static("/fonts", "app/dist/fonts", fiber.Static{
|
|
|
|
Compress: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
app.Get("/test", testPage)
|
|
|
|
app.Get("/books", list_books(db))
|
|
|
|
}
|
|
|
|
|
|
|
|
func testPage(c *fiber.Ctx) error {
|
|
|
|
return c.SendString("простая проверка")
|
|
|
|
}
|
|
|
|
|
|
|
|
// The function `list_books` returns a Fiber handler that lists all books based on the provided query
|
|
|
|
// parameters.
|
|
|
|
func list_books(db *sqlx.DB) fiber.Handler {
|
|
|
|
return func(c *fiber.Ctx) error {
|
|
|
|
deleted := c.Query("deleted")
|
|
|
|
selected := c.Query("selected")
|
|
|
|
books, err := stemdb.ListAllBooks(deleted, selected)
|
|
|
|
return c.JSON(&fiber.Map{
|
|
|
|
"success": err == nil,
|
|
|
|
"books": books,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|