lockserver/httpserver/index.go
Finn 22cafb347b
Some checks failed
/ build-container (push) Has been cancelled
Remove no-longer-needed REST endpoints
2024-04-24 00:15:12 -07:00

37 lines
694 B
Go

package httpserver
import (
"database/sql"
"errors"
echo "github.com/labstack/echo/v4"
"git.janky.solutions/finn/lockserver/db"
"git.janky.solutions/finn/lockserver/frontend"
)
type baseTemplateData struct {
Username string
UserDisplayName string
}
type indexTemplateData struct {
baseTemplateData
Locks []db.Lock
}
func indexHandler(c echo.Context) error {
queries, dbc, err := db.Get()
if err != nil {
return err
}
defer dbc.Close()
locks, err := queries.GetLocks(c.Request().Context())
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return err
}
return frontend.Templates.ExecuteTemplate(c.Response(), "index.html", indexTemplateData{Locks: locks})
}