Show logs when editing a code
All checks were successful
/ build-container (push) Successful in 8m14s

This commit is contained in:
Finn 2024-11-24 16:08:06 -08:00
parent 060b5705c8
commit a26b9cc63e
7 changed files with 113 additions and 5 deletions

View file

@ -1,6 +1,8 @@
package httpserver
import (
"database/sql"
"errors"
"fmt"
"net/http"
"strconv"
@ -8,6 +10,7 @@ import (
"git.janky.solutions/finn/lockserver/db"
"git.janky.solutions/finn/lockserver/zwavejs"
echo "github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
)
func lockHandler(c echo.Context) error {
@ -109,9 +112,19 @@ func lockCodeEditHandler(c echo.Context) error {
}
if c.Request().Method == http.MethodGet {
logrus.WithField("lock", lockID).WithField("code", code.ID).Debug("querying logs")
log, err := queries.GetLogForSlot(ctx, db.GetLogForSlotParams{
Lock: lockID,
Code: db.NullInt64(code.ID),
})
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return err
}
return c.Render(http.StatusFound, "lock-code-edit.html", map[string]interface{}{
"lock": lock,
"code": code,
"log": log,
})
}