This commit is contained in:
81
data.go
81
data.go
@@ -1,25 +1,14 @@
|
||||
package main
|
||||
|
||||
import "gitea.seeseepuff.be/seeseemelk/mysqlite"
|
||||
import (
|
||||
"fmt"
|
||||
"gitea.seeseepuff.be/seeseemelk/mysqlite"
|
||||
)
|
||||
|
||||
func (a *App) GetAllBrands() ([]string, error) {
|
||||
var brands []string
|
||||
var err error
|
||||
for row := range a.db.Query("SELECT brand FROM assets GROUP BY brand ORDER BY brand ASC").Range(&err) {
|
||||
var name string
|
||||
err := row.Scan(&name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
brands = append(brands, name)
|
||||
}
|
||||
return brands, err
|
||||
}
|
||||
|
||||
func (a *App) GetAllRAMTypes() ([]string, error) {
|
||||
func (a *App) getAllTypes(column, table string) ([]string, error) {
|
||||
var types []string
|
||||
var err error
|
||||
for row := range a.db.Query("SELECT type FROM info_ram GROUP BY type ORDER BY type ASC").Range(&err) {
|
||||
for row := range a.db.Query(fmt.Sprintf("SELECT %s FROM %s GROUP BY %s ORDER BY %s ASC", column, table, column, column)).Range(&err) {
|
||||
var name string
|
||||
err := row.Scan(&name)
|
||||
if err != nil {
|
||||
@@ -30,6 +19,64 @@ func (a *App) GetAllRAMTypes() ([]string, error) {
|
||||
return types, err
|
||||
}
|
||||
|
||||
func (a *App) GetAllBrands() ([]string, error) {
|
||||
return a.getAllTypes("brand", "assets")
|
||||
}
|
||||
|
||||
func (a *App) GetAllRamTypes() ([]string, error) {
|
||||
return a.getAllTypes("type", "info_ram")
|
||||
}
|
||||
|
||||
func (a *App) GetAllHddTypes() ([]string, error) {
|
||||
return a.getAllTypes("type", "info_hdd")
|
||||
}
|
||||
|
||||
func (a *App) GetAllHddFormFactors() ([]string, error) {
|
||||
return a.getAllTypes("form_factor", "info_hdd")
|
||||
}
|
||||
|
||||
func (a *App) GetAllHddConnections() ([]string, error) {
|
||||
return a.getAllTypes("connection", "info_hdd")
|
||||
}
|
||||
|
||||
func (a *App) GetAllHddSpeeds() ([]string, error) {
|
||||
return a.getAllTypes("rpm", "info_hdd")
|
||||
}
|
||||
|
||||
func (a *App) GetAllGroups(vm *CreateDeviceVM) error {
|
||||
var err error
|
||||
vm.AssetBrands, err = a.GetAllBrands()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
vm.RamTypes, err = a.GetAllRamTypes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
vm.HddTypes, err = a.GetAllHddTypes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
vm.HddFormFactors, err = a.GetAllHddFormFactors()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
vm.HddFormFactors, err = a.GetAllHddConnections()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
vm.HddRpms, err = a.GetAllHddSpeeds()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) GetAllTypes() ([]string, error) {
|
||||
var types []string
|
||||
var err error
|
||||
|
||||
Reference in New Issue
Block a user