lockserver/httpserver/browser-endpoints.go
Finn 350fc3b339
All checks were successful
/ build-container (push) Successful in 1m3s
rip out all auth stuff, add a containerfile
2024-04-23 17:34:57 -07:00

44 lines
853 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 browserEndpoints struct{}
type baseTemplateData struct {
Username string
UserDisplayName string
}
func (b browserEndpoints) Register(e *echo.Echo) {
e.GET("/", b.Index)
e.StaticFS("/static", frontend.Static)
}
type indexTemplateData struct {
baseTemplateData
Locks []db.Lock
}
func (browserEndpoints) Index(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})
}