You've already forked gun-manager-backend
initial commit
This commit is contained in:
27
Handlers/Guns/Edit.go
Normal file
27
Handlers/Guns/Edit.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package Guns
|
||||
|
||||
import (
|
||||
"git.siteworxpro.com/gun-manager/sql"
|
||||
"github.com/gorilla/mux"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func Edit(w http.ResponseWriter, r *http.Request) {
|
||||
db := sql.GetDb()
|
||||
id, _ := strconv.ParseInt(mux.Vars(r)["id"], 10, 32)
|
||||
|
||||
gun, err := db.GunById(uint(id))
|
||||
if err != nil {
|
||||
w.WriteHeader(404)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
t, err := template.ParseFiles("templates/Index.gohtml")
|
||||
err = t.Execute(w, gun)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
37
Handlers/Guns/Index.go
Normal file
37
Handlers/Guns/Index.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package Guns
|
||||
|
||||
import (
|
||||
"git.siteworxpro.com/gun-manager/sql"
|
||||
"html/template"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Get(w http.ResponseWriter, r *http.Request) {
|
||||
db := sql.GetDb()
|
||||
|
||||
guns := db.AllGuns()
|
||||
|
||||
t, err := template.ParseFiles("templates/Index.gohtml")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var total uint = 0
|
||||
for _, gun := range guns {
|
||||
total += gun.ValueAmount
|
||||
}
|
||||
|
||||
data := struct {
|
||||
Guns []sql.Gun
|
||||
Total uint
|
||||
}{
|
||||
Guns: guns,
|
||||
Total: total,
|
||||
}
|
||||
|
||||
err = t.Execute(w, data)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user