Working on using new data model

This commit is contained in:
2025-06-04 05:33:51 +02:00
parent ff1d95edab
commit 6e72582d77
13 changed files with 734 additions and 390 deletions

50
view_index.go Normal file
View File

@@ -0,0 +1,50 @@
package main
import (
"github.com/gin-gonic/gin"
"net/http"
)
type IndexVM struct {
AssetCount int
BrandCount int
TotalRamCapacity int
Brands []string
Types []string
}
func (a *App) getIndex(c *gin.Context) {
vm := &IndexVM{}
var err error
vm.AssetCount, err = a.GetAssetCount()
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
vm.BrandCount, err = a.GetBrandCount()
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
vm.TotalRamCapacity, err = a.GetTotalRamCapacity()
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
vm.Brands, err = a.GetAllBrands()
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
vm.Types, err = a.GetAllTypes()
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
c.HTML(http.StatusOK, "index", vm)
}