diff --git a/data.go b/data.go index 1ff9338..df94ecd 100644 --- a/data.go +++ b/data.go @@ -45,32 +45,32 @@ func (a *App) GetAllHddSpeeds() ([]string, error) { 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() + //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 } diff --git a/descriptors.go b/descriptors.go new file mode 100644 index 0000000..3ab2e1d --- /dev/null +++ b/descriptors.go @@ -0,0 +1,130 @@ +package main + +var DescriptorTree = createDescriptorTree(DescriptorRoot{ + AssetTypes: []AssetType{ + { + Id: "asset", + Table: "assets", + Name: "General Information", + Abstract: true, + Fields: []AssetField{ + { + Id: "qr", + Name: "QR Code", + Type: Number, + }, + { + Id: "type", + Name: "Type", + Type: Type, + }, + { + Id: "brand", + Name: "Brand", + Type: Selection, + }, + { + Id: "name", + Name: "Name", + Type: String, + }, + { + Id: "description", + Name: "Description", + Type: String, + }, + }, + }, + { + Id: "ram", + Name: "Random Access Memory", + Table: "info_ram", + Fields: []AssetField{ + { + Id: "type", + Name: "Type", + Type: String, + }, + { + Id: "capacity", + Name: "Capacity", + Type: Capacity, + }, + }, + }, + { + Id: "hdd", + Name: "Hard Disk Drive", + Table: "info_hdd", + Fields: []AssetField{ + { + Id: "type", + Name: "Type", + Type: Selection, + }, + { + Id: "capacity", + Name: "Capacity", + Type: Capacity, + }, + { + Id: "form_factor", + Name: "Form Factor", + Type: Selection, + }, + { + Id: "interface", + Name: "Interface", + Type: Selection, + }, + { + Id: "rpm", + Name: "RPM", + Type: Selection, + }, + }, + }, + }, +}) + +func createDescriptorTree(tree DescriptorRoot) *DescriptorRoot { + return &tree +} + +func getAssetTypeById(id string) *AssetType { + for _, assetType := range DescriptorTree.AssetTypes { + if assetType.Id == id { + return &assetType + } + } + return nil +} + +type DescriptorRoot struct { + AssetTypes []AssetType +} + +type AssetType struct { + Id string + Name string + Table string + Fields []AssetField + Abstract bool +} + +type AssetField struct { + Id string + Name string + Type FieldType +} + +type FieldType string + +const ( + Number FieldType = "number" + String = "string" + Type = "type" + Selection = "selection" + Bool = "bool" + Capacity = "capacity" +) diff --git a/go.mod b/go.mod index 54d933d..ae21222 100644 --- a/go.mod +++ b/go.mod @@ -5,20 +5,20 @@ go 1.24 toolchain go1.24.1 require ( - gitea.seeseepuff.be/seeseemelk/mysqlite v0.9.0 - github.com/gin-gonic/gin v1.10.0 + gitea.seeseepuff.be/seeseemelk/mysqlite v0.15.0 + github.com/gin-gonic/gin v1.10.1 ) require ( - github.com/bytedance/sonic v1.13.1 // indirect + github.com/bytedance/sonic v1.13.2 // indirect github.com/bytedance/sonic/loader v0.2.4 // indirect github.com/cloudwego/base64x v0.1.5 // indirect github.com/dustin/go-humanize v1.0.1 // indirect - github.com/gabriel-vasile/mimetype v1.4.8 // indirect - github.com/gin-contrib/sse v1.0.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.9 // indirect + github.com/gin-contrib/sse v1.1.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.25.0 // indirect + github.com/go-playground/validator/v10 v10.26.0 // indirect github.com/goccy/go-json v0.10.5 // indirect github.com/google/uuid v1.6.0 // indirect github.com/json-iterator/go v1.1.12 // indirect @@ -28,20 +28,21 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/ncruces/go-strftime v0.1.9 // indirect - github.com/pelletier/go-toml/v2 v2.2.3 // indirect + github.com/pelletier/go-toml/v2 v2.2.4 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.12 // indirect - golang.org/x/arch v0.15.0 // indirect - golang.org/x/crypto v0.36.0 // indirect - golang.org/x/net v0.37.0 // indirect - golang.org/x/sys v0.31.0 // indirect - golang.org/x/text v0.23.0 // indirect - google.golang.org/protobuf v1.36.5 // indirect + github.com/ugorji/go/codec v1.2.14 // indirect + golang.org/x/arch v0.17.0 // indirect + golang.org/x/crypto v0.38.0 // indirect + golang.org/x/exp v0.0.0-20250531010427-b6e5de432a8b // indirect + golang.org/x/net v0.40.0 // indirect + golang.org/x/sys v0.33.0 // indirect + golang.org/x/text v0.25.0 // indirect + google.golang.org/protobuf v1.36.6 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - modernc.org/libc v1.55.3 // indirect - modernc.org/mathutil v1.6.0 // indirect - modernc.org/memory v1.8.0 // indirect - modernc.org/sqlite v1.33.1 // indirect - zombiezen.com/go/sqlite v1.4.0 // indirect + modernc.org/libc v1.65.8 // indirect + modernc.org/mathutil v1.7.1 // indirect + modernc.org/memory v1.11.0 // indirect + modernc.org/sqlite v1.37.1 // indirect + zombiezen.com/go/sqlite v1.4.2 // indirect ) diff --git a/go.sum b/go.sum index 7c65f36..98e21e1 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,13 @@ gitea.seeseepuff.be/seeseemelk/mysqlite v0.9.0 h1:GaU2DSrgDfZEqST3HdnNgfKSI4sNXvMm8SSfeMvBxA4= gitea.seeseepuff.be/seeseemelk/mysqlite v0.9.0/go.mod h1:cgswydOxJjMlNwfcBIXnKjr47LwXnMT9BInkiHb0tXE= +gitea.seeseepuff.be/seeseemelk/mysqlite v0.14.0 h1:aRItVfUj48fBmuec7rm/jY9KCfvHW2VzJfItVk4t8sw= +gitea.seeseepuff.be/seeseemelk/mysqlite v0.14.0/go.mod h1:cgswydOxJjMlNwfcBIXnKjr47LwXnMT9BInkiHb0tXE= +gitea.seeseepuff.be/seeseemelk/mysqlite v0.15.0 h1:+k0iBYM/aZJxz7++EKi/G9e66E9u4bPS3DFLrBeDb9Y= +gitea.seeseepuff.be/seeseemelk/mysqlite v0.15.0/go.mod h1:cgswydOxJjMlNwfcBIXnKjr47LwXnMT9BInkiHb0tXE= github.com/bytedance/sonic v1.13.1 h1:Jyd5CIvdFnkOWuKXr+wm4Nyk2h0yAFsr8ucJgEasO3g= github.com/bytedance/sonic v1.13.1/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4= +github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ= +github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY= github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI= @@ -15,10 +21,16 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= +github.com/gabriel-vasile/mimetype v1.4.9 h1:5k+WDwEsD9eTLL8Tz3L0VnmVh9QxGjRmjBvAG7U/oYY= +github.com/gabriel-vasile/mimetype v1.4.9/go.mod h1:WnSQhFKJuBlRyLiKohA/2DtIlPFAbguNaG7QCHcyGok= github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E= github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0= +github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w= +github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM= github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= +github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ= +github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= @@ -27,6 +39,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0nmsZJxEAnFLNO8= github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus= +github.com/go-playground/validator/v10 v10.26.0 h1:SP05Nqhjcvz81uJaRfEV0YBSSSGMc/iMaVtFbr3Sw2k= +github.com/go-playground/validator/v10 v10.26.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo= github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= @@ -53,6 +67,8 @@ github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdh github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= +github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= +github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= @@ -73,25 +89,43 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/ugorji/go/codec v1.2.14 h1:yOQvXCBc3Ij46LRkRoh4Yd5qK6LVOgi0bYOXfb7ifjw= +github.com/ugorji/go/codec v1.2.14/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= golang.org/x/arch v0.15.0 h1:QtOrQd0bTUnhNVNndMpLHNWrDmYzZ2KDqSrEymqInZw= golang.org/x/arch v0.15.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE= +golang.org/x/arch v0.17.0 h1:4O3dfLzd+lQewptAHqjewQZQDyEdejz3VwgeYwkZneU= +golang.org/x/arch v0.17.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk= golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= +golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= +golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= +golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 h1:y5zboxd6LQAqYIhHnB48p0ByQ/GnQx2BE33L8BOHQkI= +golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6/go.mod h1:U6Lno4MTRCDY+Ba7aCcauB9T60gsv5s4ralQzP72ZoQ= +golang.org/x/exp v0.0.0-20250531010427-b6e5de432a8b h1:QoALfVG9rhQ/M7vYDScfPdWjGL9dlsVVM5VGh7aKoAA= +golang.org/x/exp v0.0.0-20250531010427-b6e5de432a8b/go.mod h1:U6Lno4MTRCDY+Ba7aCcauB9T60gsv5s4ralQzP72ZoQ= golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c= golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= +golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= +golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw= golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= +golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= +golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= +google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= @@ -107,16 +141,24 @@ modernc.org/gc/v2 v2.4.1 h1:9cNzOqPyMJBvrUipmynX0ZohMhcxPtMccYgGOJdOiBw= modernc.org/gc/v2 v2.4.1/go.mod h1:wzN5dK1AzVGoH6XOzc3YZ+ey/jPgYHLuVckd62P0GYU= modernc.org/libc v1.55.3 h1:AzcW1mhlPNrRtjS5sS+eW2ISCgSOLLNyFzRh/V3Qj/U= modernc.org/libc v1.55.3/go.mod h1:qFXepLhz+JjFThQ4kzwzOjA/y/artDeg+pcYnY+Q83w= +modernc.org/libc v1.65.8 h1:7PXRJai0TXZ8uNA3srsmYzmTyrLoHImV5QxHeni108Q= +modernc.org/libc v1.65.8/go.mod h1:011EQibzzio/VX3ygj1qGFt5kMjP0lHb0qCW5/D/pQU= modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4= modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo= +modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU= +modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg= modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E= modernc.org/memory v1.8.0/go.mod h1:XPZ936zp5OMKGWPqbD3JShgd/ZoQ7899TUuQqxY+peU= +modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI= +modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw= modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4= modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0= modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc= modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss= modernc.org/sqlite v1.33.1 h1:trb6Z3YYoeM9eDL1O8do81kP+0ejv+YzgyFo+Gwy0nM= modernc.org/sqlite v1.33.1/go.mod h1:pXV2xHxhzXZsgT/RtTFAPY6JJDEvOTcTdwADQCCWD4k= +modernc.org/sqlite v1.37.1 h1:EgHJK/FPoqC+q2YBXg7fUmES37pCHFc97sI7zSayBEs= +modernc.org/sqlite v1.37.1/go.mod h1:XwdRtsE1MpiBcL54+MbKcaDvcuej+IYSMfLN6gSKV8g= modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA= modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0= modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= @@ -124,3 +166,5 @@ modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM= nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= zombiezen.com/go/sqlite v1.4.0 h1:N1s3RIljwtp4541Y8rM880qgGIgq3fTD2yks1xftnKU= zombiezen.com/go/sqlite v1.4.0/go.mod h1:0w9F1DN9IZj9AcLS9YDKMboubCACkwYCGkzoy3eG5ik= +zombiezen.com/go/sqlite v1.4.2 h1:KZXLrBuJ7tKNEm+VJcApLMeQbhmAUOKA5VWS93DfFRo= +zombiezen.com/go/sqlite v1.4.2/go.mod h1:5Kd4taTAD4MkBzT25mQ9uaAlLjyR0rFhsR6iINO70jc= diff --git a/static/scripts.js b/static/scripts.js index 34e9308..82f2c03 100644 --- a/static/scripts.js +++ b/static/scripts.js @@ -14,3 +14,10 @@ function newOption(elementId, name) { el.prepend(child) el.value = newValue } + +window.onload = function() { + var elements = document.getElementsByClassName("to-delete") + while (elements.length > 0) { + elements[0].remove() + } +} diff --git a/template_funcs.go b/template_funcs.go index c7d4481..ac65f39 100644 --- a/template_funcs.go +++ b/template_funcs.go @@ -88,14 +88,12 @@ func isRamType(size int, unit string) bool { } func formatType(t string) string { - switch t { - case "ram": - return "Random Access Memory" - case "hdd": - return "Hard Disk Drive" - default: - return t + for _, assetType := range DescriptorTree.AssetTypes { + if assetType.Id == t { + return assetType.Name + } } + panic("unknown type") } type SelectMenu struct { diff --git a/templates/create_device_step1.gohtml b/templates/create_device_step1.gohtml index e4369e8..c4a20ba 100644 --- a/templates/create_device_step1.gohtml +++ b/templates/create_device_step1.gohtml @@ -1,18 +1,20 @@ -{{- /*gotype: main.CreateDeviceVM */}} +{{- /*gotype: pcinv.CreateDeviceVM*/ -}} {{define "create_device_step1"}} {{template "header" "Create Device - Choose Device Type"}} {{template "footer"}} {{end}} - -{{define "create_device_link"}} - {{if .Qr}} -
  • {{"ram" | formatType}}
  • -
  • {{"hdd" | formatType}}
  • - {{- else}} -
  • {{"ram" | formatType}}
  • -
  • {{"hdd" | formatType}}
  • - {{- end}} -{{end}} diff --git a/templates/create_device_step2.gohtml b/templates/create_device_step2.gohtml index 006210d..518a2f5 100644 --- a/templates/create_device_step2.gohtml +++ b/templates/create_device_step2.gohtml @@ -2,129 +2,187 @@ {{define "create_device_step2"}} {{template "header" "Create Device - Enter Device Data"}}
    -

    General Information

    - - - - {{if .Qr}} - - {{else}} - - {{end}} - - - - - - - - - - - - - - - - - -
    - -
    - {{if eq .Type "ram"}} -

    Memory Information

    - - - - + + {{end}} +
    - + {{range .Fields}} + + + - - - - - -
    + {{if eq .Type "type"}} + {{$.NiceType}} + + {{else if eq .Type "number"}} + + {{else if eq .Type "string"}} + + {{else if eq .Type "selection"}} + + + {{else if eq .Type "capacity"}} + + {{end}} - {{end}} - - -
    - - -
    +
    + {{end}} {{end}} - {{if eq .Type "hdd"}} -

    Hard Drive Information

    - - - - - - - - - - - - - - - - - - - - - -
    - - -
    {{template "create_device_select" createSelectMenu "hdd_type" "HDD Type" .HddType .HddTypes}}
    {{template "create_device_select" createSelectMenu "hdd_form_factor" "HDD Form Factor" .HddFormFactor .HddFormFactors}}
    {{template "create_device_select" createSelectMenu "hdd_connection" "HDD Connection" .HddConnection .HddConnections}}
    {{template "create_device_select" createSelectMenuDefault "hdd_rpm" "HDD RPM" .HddRpm .HddRpms "Not Applicable"}}
    - {{end}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* {{if .Qr}}*/}} +{{/* */}} +{{/* {{else}}*/}} +{{/* */}} +{{/* {{end}}*/}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/*
    */}} +{{/* */}} +{{/*
    */}} + +{{/* {{if eq .Type "ram"}}*/}} +{{/*

    Memory Information

    */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/*
    */}} +{{/* */}} +{{/*
    */}} +{{/* */}} +{{/* */}} +{{/*
    */}} +{{/* {{end}}*/}} + +{{/* {{if eq .Type "hdd"}}*/}} +{{/*

    Hard Drive Information

    */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/* */}} +{{/*
    */}} +{{/* */}} +{{/* */}} +{{/*
    {{template "create_device_select" createSelectMenu "hdd_type" "HDD Type" .HddType .HddTypes}}
    {{template "create_device_select" createSelectMenu "hdd_form_factor" "HDD Form Factor" .HddFormFactor .HddFormFactors}}
    {{template "create_device_select" createSelectMenu "hdd_connection" "HDD Connection" .HddConnection .HddConnections}}
    {{template "create_device_select" createSelectMenuDefault "hdd_rpm" "HDD RPM" .HddRpm .HddRpms "Not Applicable"}}
    */}} +{{/* {{end}}*/}} {{if .IsEdit}} - + {{else}} - + {{end}}
    {{template "footer"}} {{end}} -{{define "create_device_select"}} - -{{end}} +{{/*{{define "create_device_select"}}*/}} +{{/* */}} +{{/*{{end}}*/}} diff --git a/templates/header.gohtml b/templates/header.gohtml index ba9c862..be6b2af 100644 --- a/templates/header.gohtml +++ b/templates/header.gohtml @@ -4,12 +4,12 @@ PC Inventory{{if .}} - {{.}}{{end}} - +

    PC Inventory{{if .}} - {{.}}{{end}}

    - + Create Device

    diff --git a/view_createdevice.go b/view_createdevice.go new file mode 100644 index 0000000..14f7dfc --- /dev/null +++ b/view_createdevice.go @@ -0,0 +1,135 @@ +package main + +import ( + "fmt" + "github.com/gin-gonic/gin" + "net/http" + "strconv" + "strings" +) + +type CreateDeviceVM struct { + IsEdit bool + DescriptorTree *DescriptorRoot + + // Assets + Qr *int + Type string + + Values map[string]string +} + +func (vm *CreateDeviceVM) SetValue(assetType string, field string, value string) { + if vm.Values == nil { + vm.Values = make(map[string]string) + } + vm.Values[assetType+"-"+field] = value +} + +func (vm *CreateDeviceVM) GetValue(assetType string, field string) string { + if vm.Values == nil { + return "" + } + return vm.Values[assetType+"-"+field] +} + +func (vm *CreateDeviceVM) NiceType() string { + return getAssetTypeById(vm.Type).Name +} + +func (vm *CreateDeviceVM) IsPartOf(assertType string) bool { + if assertType == "asset" { + return true + } + return assertType == vm.Type +} + +func (a *App) getCreateDevice(c *gin.Context) { + var err error + vm := &CreateDeviceVM{} + vm.DescriptorTree = DescriptorTree + vm.Type = c.Query("type") + + qr := c.Query("id") + if qr != "" { + qrInt, err := strconv.Atoi(qr) + if err != nil { + c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("invalid qr: %v", err)) + return + } + vm.Qr = &qrInt + } + + err = a.GetAllGroups(vm) + if err != nil { + c.AbortWithError(http.StatusInternalServerError, err) + return + } + + if c.Query("edit") != "" && vm.Qr != nil { + vm.IsEdit = true + err := a.pullDataFromDb(*vm.Qr, "asset", vm) + if err != nil { + c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to load asset data: %v", err)) + return + } + //// Load the asset data from the database + //err = a.db.Query("SELECT * FROM assets WHERE qr = ?"). + // Bind(*vm.Qr). + // ScanColumns(&columns). + // ScanSingle(&vm.Qr, &vm.Type, &vm.Values) + //if err != nil { + // c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to load asset: %v", err)) + // return + // + //} + + //err = a.db.Query("SELECT name, type, brand, description FROM assets WHERE qr = ?"). + // Bind(*vm.Qr). + // ScanSingle(&vm.AssetName, &vm.Type, &vm.AssetBrand, &vm.AssetDescription) + //if err != nil { + // c.AbortWithError(http.StatusInternalServerError, err) + // return + //} + //if vm.Type == "ram" { + // err = a.db.Query("SELECT type, capacity FROM info_ram WHERE asset = ?"). + // Bind(*vm.Qr). + // ScanSingle(&vm.RamType, &vm.RamCapacity) + // if err != nil { + // c.AbortWithError(http.StatusInternalServerError, err) + // return + // } + //} else if vm.Type == "hdd" { + // err = a.db.Query("SELECT capacity, type, form_factor, connection, rpm FROM info_hdd WHERE asset = ?"). + // Bind(*vm.Qr). + // ScanSingle(&vm.HddCapacity, &vm.HddType, &vm.HddFormFactor, &vm.HddConnection, &vm.HddRpm) + // if err != nil { + // c.AbortWithError(http.StatusInternalServerError, err) + // return + // } + //} + } + + c.HTML(http.StatusOK, "create_device", vm) +} + +func (a *App) pullDataFromDb(qr int, assetType string, vm *CreateDeviceVM) error { + var fields []string + assetDescriptor := getAssetTypeById(assetType) + for _, field := range assetDescriptor.Fields { + fields = append(fields, field.Id) + } + values := make([]any, len(fields)) + + query := fmt.Sprintf("SELECT %s FROM %s WHERE qr = ?", strings.Join(fields, ", "), assetDescriptor.Table) + err := a.db.Query(query).Bind(qr).ScanSingle(values...) + if err != nil { + return fmt.Errorf("failed to load asset data: %v", err) + } + + for i, field := range fields { + vm.SetValue(assetType, field, fmt.Sprintf("%v", values[i])) + } + + return err +} diff --git a/view_device.go b/view_device.go new file mode 100644 index 0000000..9ac3d6c --- /dev/null +++ b/view_device.go @@ -0,0 +1,73 @@ +package main + +import ( + "github.com/gin-gonic/gin" + "net/http" + "strconv" +) + +type DeviceVM struct { + Qr int + Name string + Brand string + Type string + Description string + RamType string + RamCapacity int + HddCapacity int + HddType string + HddFormFactor string + HddConnection string + HddRpm int +} + +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?id="+strconv.Itoa(qr)) + return + } + + vm := &DeviceVM{Qr: qr} + err = a.db.Query("SELECT name, brand, type, description FROM assets WHERE qr = ?"). + Bind(qr). + ScanSingle(&vm.Name, &vm.Brand, &vm.Type, &vm.Description) + if err != nil { + c.AbortWithError(http.StatusInternalServerError, err) + return + } + + if vm.Type == "ram" { + err = a.db.Query("SELECT type, capacity FROM info_ram WHERE asset = ?"). + Bind(qr). + ScanSingle(&vm.RamType, &vm.RamCapacity) + if err != nil { + c.AbortWithError(http.StatusInternalServerError, err) + return + } + } else if vm.Type == "hdd" { + err = a.db.Query("SELECT capacity, type, form_factor, connection, rpm FROM info_hdd WHERE asset = ?"). + Bind(qr). + ScanSingle(&vm.HddCapacity, &vm.HddType, &vm.HddFormFactor, &vm.HddConnection, &vm.HddRpm) + if err != nil { + c.AbortWithError(http.StatusInternalServerError, err) + return + } + } + + c.HTML(http.StatusOK, "device", vm) +} diff --git a/view_index.go b/view_index.go new file mode 100644 index 0000000..da0fd32 --- /dev/null +++ b/view_index.go @@ -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) +} diff --git a/views.go b/views.go index 2f14ff3..978dde3 100644 --- a/views.go +++ b/views.go @@ -3,217 +3,22 @@ package main import ( "errors" "fmt" - "net/http" - "strconv" - "gitea.seeseepuff.be/seeseemelk/mysqlite" "github.com/gin-gonic/gin" + "net/http" + "strconv" + "strings" ) type App struct { db *mysqlite.Db } -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) -} - -type DeviceVM struct { - Qr int - Name string - Brand string - Type string - Description string - RamType string - RamCapacity int - HddCapacity int - HddType string - HddFormFactor string - HddConnection string - HddRpm int -} - -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?id="+strconv.Itoa(qr)) - return - } - - vm := &DeviceVM{Qr: qr} - err = a.db.Query("SELECT name, brand, type, description FROM assets WHERE qr = ?"). - Bind(qr). - ScanSingle(&vm.Name, &vm.Brand, &vm.Type, &vm.Description) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - - if vm.Type == "ram" { - err = a.db.Query("SELECT type, capacity FROM info_ram WHERE asset = ?"). - Bind(qr). - ScanSingle(&vm.RamType, &vm.RamCapacity) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - } else if vm.Type == "hdd" { - err = a.db.Query("SELECT capacity, type, form_factor, connection, rpm FROM info_hdd WHERE asset = ?"). - Bind(qr). - ScanSingle(&vm.HddCapacity, &vm.HddType, &vm.HddFormFactor, &vm.HddConnection, &vm.HddRpm) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - } - - c.HTML(http.StatusOK, "device", vm) -} - -type CreateDeviceVM struct { - IsEdit bool - - // Assets - Qr *int - Type string - - AssetBrand string - AssetBrands []string - - AssetName string - AssetDescription string - - // RAM - RamType string - RamTypes []string - - RamCapacity int - - // HDD - HddCapacity int - - HddType string - HddTypes []string - HddFormFactor string - HddFormFactors []string - HddConnection string - HddConnections []string - HddRpm string - HddRpms []string -} - -func (a *App) getCreateDevice(c *gin.Context) { - var err error - vm := &CreateDeviceVM{} - vm.Type = c.Query("type") - - qr := c.Query("id") - if qr != "" { - qrInt, err := strconv.Atoi(qr) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("invalid qr: %v", err)) - return - } - vm.Qr = &qrInt - } - - err = a.GetAllGroups(vm) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - - if c.Query("edit") != "" && vm.Qr != nil { - vm.IsEdit = true - err = a.db.Query("SELECT name, type, brand, description FROM assets WHERE qr = ?"). - Bind(*vm.Qr). - ScanSingle(&vm.AssetName, &vm.Type, &vm.AssetBrand, &vm.AssetDescription) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - if vm.Type == "ram" { - err = a.db.Query("SELECT type, capacity FROM info_ram WHERE asset = ?"). - Bind(*vm.Qr). - ScanSingle(&vm.RamType, &vm.RamCapacity) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - } else if vm.Type == "hdd" { - err = a.db.Query("SELECT capacity, type, form_factor, connection, rpm FROM info_hdd WHERE asset = ?"). - Bind(*vm.Qr). - ScanSingle(&vm.HddCapacity, &vm.HddType, &vm.HddFormFactor, &vm.HddConnection, &vm.HddRpm) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - } - } - - c.HTML(http.StatusOK, "create_device", vm) -} - func (a *App) postCreateDevice(c *gin.Context) { - qr, err := strconv.Atoi(c.PostForm("qr")) + qr, err := strconv.Atoi(c.PostForm("asset-qr")) if err != nil { c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("invalid qr: %v", err)) } - assetType := c.PostForm("asset_type") tx, err := a.db.Begin() defer tx.MustRollback() @@ -227,20 +32,18 @@ func (a *App) postCreateDevice(c *gin.Context) { c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("error removing assets: %v", err)) return } - err = tx.Query("INSERT INTO assets (qr, type, brand, name, description) VALUES (?, ?, ?, ?, ?)"). - Bind(qr, c.PostForm("asset_type"), c.PostForm("asset_brand"), c.PostForm("asset_name"), c.PostForm("asset_description")). - Exec() + + // Insert the asset into the database + var id int + err = a.createAsset("asset", tx, c, &id) if err != nil { - c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("error inserting assets: %v", err)) + c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("error inserting asset: %v", err)) return } - - if assetType == "ram" { - err = a.postCreateDeviceRam(c, qr, tx) - } else if assetType == "hdd" { - err = a.postCreateDeviceHdd(c, qr, tx) - } else { - c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("invalid type: %s", assetType)) + assetType := c.PostForm("asset-type") + err = a.createAsset(assetType, tx, c, &id) + if err != nil { + c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("error inserting asset type: %v", err)) return } @@ -257,6 +60,49 @@ func (a *App) postCreateDevice(c *gin.Context) { c.Redirect(http.StatusSeeOther, "/") } +func (a *App) createAsset(assetType string, tx *mysqlite.Tx, c *gin.Context, assetId *int) error { + for _, assetDescriptor := range DescriptorTree.AssetTypes { + if assetDescriptor.Id != assetType { + continue + } + + var fields []string + var questions []string + var values []string + + for _, field := range assetDescriptor.Fields { + fields = append(fields, field.Id) + questions = append(questions, "?") + values = append(values, c.PostForm(assetType+"-"+field.Id)) + } + + if *assetId != 0 { + fields = append(fields, "asset") + questions = append(questions, "?") + values = append(values, strconv.Itoa(*assetId)) + } + + fieldsStr := strings.Join(fields, ", ") + questionsStr := strings.Join(questions, ", ") + err := tx.Query(fmt.Sprintf("INSERT INTO %s (%s) values (%s)", assetDescriptor.Table, fieldsStr, questionsStr)). + Bind(values). + Exec() + if err != nil { + return err + } + + if *assetId == 0 { + err := tx.Query("SELECT LAST_INSERT_ROWID()").ScanSingle(assetId) + if err != nil { + return fmt.Errorf("error getting last insert id: %v", err) + } + } + + return nil + } + return errors.New("Create Asset not implemented for type: " + assetType) +} + func (a *App) postCreateDeviceRam(c *gin.Context, qr int, tx *mysqlite.Tx) error { var err error capacity := 0