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