Got cool stuff working
This commit is contained in:
49
views.go
Normal file
49
views.go
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user