fyp/logic/models/list.go

49 lines
830 B
Go
Raw Normal View History

package models
import (
"net/http"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
)
func handleList(handle *Handle) {
// TODO json
handle.GetHTML("/models", func(w http.ResponseWriter, r *http.Request, c *Context) *Error {
if c.Mode == JSON {
panic("TODO JSON")
}
if !CheckAuthLevel(1, w, r, c) {
return nil
}
rows, err := handle.Db.Query("select id, name from models where user_id=$1;", c.User.Id)
if err != nil {
return Error500(err)
}
defer rows.Close()
type row struct {
Name string
Id string
}
got := []row{}
for rows.Next() {
var r row
err = rows.Scan(&r.Id, &r.Name)
if err != nil {
return Error500(err)
}
got = append(got, r)
}
LoadBasedOnAnswer(c.Mode, w, "/models/list.html", c.AddMap(AnyMap{
"List": got,
}))
return nil
})
}