32 lines
735 B
Go
32 lines
735 B
Go
package context
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"lishwist/db"
|
|
"lishwist/templates"
|
|
)
|
|
|
|
type HomeProps struct {
|
|
Username string
|
|
Gifts []db.Gift
|
|
Todo []db.Gift
|
|
Reference string
|
|
}
|
|
|
|
func (ctx *Context) Home(w http.ResponseWriter, r *http.Request) {
|
|
user := ctx.Auth.ExpectUser(r)
|
|
gifts, err := user.GetGifts()
|
|
if err != nil {
|
|
http.Error(w, "An error occurred while fetching your wishlist :(", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
todo, err := user.GetTodo()
|
|
if err != nil {
|
|
http.Error(w, "An error occurred while fetching your wishlist :(", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
p := HomeProps{Username: user.Name, Gifts: gifts, Todo: todo, Reference: user.Reference}
|
|
templates.Execute(w, "home.gotmpl", p)
|
|
}
|