Got cool stuff working

This commit is contained in:
2025-03-20 08:11:41 +01:00
parent 896ac66ab0
commit 8490a8c029
12 changed files with 316 additions and 13 deletions

49
views.go Normal file
View File

@@ -0,0 +1,49 @@
package main
import (
"gitea.seeseepuff.be/seeseemelk/mysqlite"
"github.com/gin-gonic/gin"
"net/http"
"strconv"
)
type App struct {
db *mysqlite.Db
}
type IndexVM struct {
AssetCount int
}
func (a *App) getIndex(c *gin.Context) {
vm := &IndexVM{}
err := a.db.Query("SELECT COUNT(*) FROM assets").ScanSingle(&vm.AssetCount)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
c.HTML(http.StatusOK, "index", vm)
}
func (a *App) getDevice(c *gin.Context) {
qr, err := strconv.Atoi(c.Query("id"))
if err != nil {
c.AbortWithError(http.StatusBadRequest, err)
return
}
var count int
err = a.db.Query("SELECT COUNT(*) FROM assets WHERE qr = ?").
Bind(qr).
ScanSingle(&count)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
if count == 0 {
c.Redirect(http.StatusTemporaryRedirect, "/create")
return
}
}