lishwist/context/home.go

24 lines
455 B
Go

package context
import (
"net/http"
"lishwist/db"
"lishwist/templates"
)
type HomeProps struct {
Gifts []db.Gift
}
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
}
p := HomeProps{Gifts: gifts}
templates.Execute(w, "home.gotmpl", p)
}