48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package routing
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"lishwist/db"
|
|
"lishwist/env"
|
|
"lishwist/rsvp"
|
|
)
|
|
|
|
type HomeProps struct {
|
|
Username string
|
|
Gifts []db.Gift
|
|
Todo []db.Gift
|
|
Reference string
|
|
HostUrl string
|
|
Groups []db.Group
|
|
}
|
|
|
|
func Home(currentUser *db.User, h http.Header, r *rsvp.Request) rsvp.Response {
|
|
gifts, err := currentUser.GetGifts()
|
|
if err != nil {
|
|
return rsvp.Error(http.StatusInternalServerError, "An error occurred while fetching your wishlist :(").Log("Failed to get gifts: %s", err)
|
|
}
|
|
todo, err := currentUser.GetTodo()
|
|
if err != nil {
|
|
return rsvp.Error(http.StatusInternalServerError, "An error occurred while fetching your wishlist :(").Log("Failed to get todo: %s", err)
|
|
}
|
|
groups, err := currentUser.GetGroups()
|
|
if err != nil {
|
|
return rsvp.Error(http.StatusInternalServerError, "An error occurred while fetching your wishlist :(").Log("Failed to get groups: %s", err)
|
|
}
|
|
p := HomeProps{Username: currentUser.Name, Gifts: gifts, Todo: todo, Reference: currentUser.Reference, HostUrl: env.HostUrl.String(), Groups: groups}
|
|
return rsvp.Data("home.gotmpl", p)
|
|
}
|
|
|
|
func HomePost(currentUser *db.User, h http.Header, r *rsvp.Request) rsvp.Response {
|
|
form := r.ParseForm()
|
|
switch form.Get("intent") {
|
|
case "add_idea":
|
|
return WishlistAdd(currentUser, h, r)
|
|
case "delete_idea":
|
|
return WishlistDelete(currentUser, h, r)
|
|
default:
|
|
return TodoUpdate(currentUser, h, r)
|
|
}
|
|
}
|