Use RSVP #15
|
|
@ -1,4 +1,4 @@
|
|||
package rsvp
|
||||
package response
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
|
@ -45,7 +45,7 @@ func (m *ServeMux) HandleFunc(pattern string, handler HandlerFunc) {
|
|||
}
|
||||
err = response.Write(w, stdReq)
|
||||
if err != nil {
|
||||
log.Printf("Failed to write rsvp.Response to bytes: %s\n", err)
|
||||
log.Printf("Failed to write response.Response to bytes: %s\n", err)
|
||||
http.Error(w, "Failed to write response", http.StatusInternalServerError)
|
||||
}
|
||||
})
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package rsvp
|
||||
package response
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package rsvp
|
||||
package response
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
|
@ -79,7 +79,7 @@ func (res *Response) Write(w http.ResponseWriter, r *http.Request) error {
|
|||
|
||||
_, err := w.Write(bodyBytes.Bytes())
|
||||
if err != nil {
|
||||
log.Printf("Failed to write rsvp.Response to HTTP: %s\n", err)
|
||||
log.Printf("Failed to write response.Response to HTTP: %s\n", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package rsvp
|
||||
package response
|
||||
|
||||
import (
|
||||
"github.com/gorilla/sessions"
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"lishwist/http/rsvp"
|
||||
"lishwist/http/response"
|
||||
"net/http"
|
||||
|
||||
"github.com/Teajey/sqlstore"
|
||||
|
|
@ -9,8 +9,8 @@ import (
|
|||
|
||||
type VisibilityRouter struct {
|
||||
Store *sqlstore.Store
|
||||
Public *rsvp.ServeMux
|
||||
Private *rsvp.ServeMux
|
||||
Public *response.ServeMux
|
||||
Private *response.ServeMux
|
||||
}
|
||||
|
||||
func (s *VisibilityRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -27,7 +27,7 @@ func (s *VisibilityRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
func New(store *sqlstore.Store) *VisibilityRouter {
|
||||
return &VisibilityRouter{
|
||||
Store: store,
|
||||
Public: rsvp.NewServeMux(store),
|
||||
Private: rsvp.NewServeMux(store),
|
||||
Public: response.NewServeMux(store),
|
||||
Private: response.NewServeMux(store),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,24 @@
|
|||
package routing
|
||||
|
||||
import (
|
||||
lishwist "lishwist/core"
|
||||
"lishwist/http/rsvp"
|
||||
"net/http"
|
||||
|
||||
lishwist "lishwist/core"
|
||||
|
||||
"lishwist/http/response"
|
||||
)
|
||||
|
||||
func ExpectAppSession(next func(*lishwist.Session, http.Header, *rsvp.Request) rsvp.Response) rsvp.HandlerFunc {
|
||||
return func(w http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func ExpectAppSession(next func(*lishwist.Session, http.Header, *response.Request) response.Response) response.HandlerFunc {
|
||||
return func(w http.Header, r *response.Request) response.Response {
|
||||
session := r.GetSession()
|
||||
username, ok := session.GetValue("username").(string)
|
||||
if !ok {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Something went wrong.").Log("Failed to get username from session")
|
||||
return response.Error(http.StatusInternalServerError, "Something went wrong.").Log("Failed to get username from session")
|
||||
}
|
||||
|
||||
appSession, err := lishwist.SessionFromUsername(username)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Something went wrong.").Log("Failed to get session by username %q: %s", username, err)
|
||||
return response.Error(http.StatusInternalServerError, "Something went wrong.").Log("Failed to get session by username %q: %s", username, err)
|
||||
}
|
||||
|
||||
return next(appSession, w, r)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package routing
|
|||
|
||||
import (
|
||||
lishwist "lishwist/core"
|
||||
"lishwist/http/rsvp"
|
||||
"lishwist/http/response"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
|
@ -13,24 +13,24 @@ type foreignWishlistProps struct {
|
|||
Gifts []lishwist.Wish
|
||||
}
|
||||
|
||||
func ForeignWishlist(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func ForeignWishlist(app *lishwist.Session, h http.Header, r *response.Request) response.Response {
|
||||
userReference := r.PathValue("userReference")
|
||||
if app.User.Reference == userReference {
|
||||
return rsvp.SeeOther("/")
|
||||
return response.SeeOther("/")
|
||||
}
|
||||
otherUser, err := lishwist.GetUserByReference(userReference)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "An error occurred while fetching this user :(").Log("Couldn't get user by reference %q: %s", userReference, err)
|
||||
return response.Error(http.StatusInternalServerError, "An error occurred while fetching this user :(").Log("Couldn't get user by reference %q: %s", userReference, err)
|
||||
}
|
||||
if otherUser == nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "User not found")
|
||||
return response.Error(http.StatusInternalServerError, "User not found")
|
||||
}
|
||||
wishes, err := app.GetOthersWishes(userReference)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "An error occurred while fetching this user :(").Log("%q couldn't get wishes of other user %q: %s", app.User.Name, otherUser.Name, err)
|
||||
return response.Error(http.StatusInternalServerError, "An error occurred while fetching this user :(").Log("%q couldn't get wishes of other user %q: %s", app.User.Name, otherUser.Name, err)
|
||||
}
|
||||
p := foreignWishlistProps{CurrentUserId: app.User.Id, CurrentUserName: app.User.Name, Username: otherUser.Name, Gifts: wishes}
|
||||
return rsvp.Data("foreign_wishlist.gotmpl", p)
|
||||
return response.Data("foreign_wishlist.gotmpl", p)
|
||||
}
|
||||
|
||||
type publicWishlistProps struct {
|
||||
|
|
@ -38,19 +38,19 @@ type publicWishlistProps struct {
|
|||
GiftCount int
|
||||
}
|
||||
|
||||
func PublicWishlist(h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func PublicWishlist(h http.Header, r *response.Request) response.Response {
|
||||
userReference := r.PathValue("userReference")
|
||||
otherUser, err := lishwist.GetUserByReference(userReference)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "An error occurred while fetching this user :(").Log("Couldn't get user by reference %q on public wishlist: %s", userReference, err)
|
||||
return response.Error(http.StatusInternalServerError, "An error occurred while fetching this user :(").Log("Couldn't get user by reference %q on public wishlist: %s", userReference, err)
|
||||
}
|
||||
if otherUser == nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "User not found")
|
||||
return response.Error(http.StatusInternalServerError, "User not found")
|
||||
}
|
||||
giftCount, err := otherUser.WishCount()
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "An error occurred while fetching this user :(").Log("Couldn't get wishes of user %q on public wishlist: %s", otherUser.Name, err)
|
||||
return response.Error(http.StatusInternalServerError, "An error occurred while fetching this user :(").Log("Couldn't get wishes of user %q on public wishlist: %s", otherUser.Name, err)
|
||||
}
|
||||
p := publicWishlistProps{Username: otherUser.Name, GiftCount: giftCount}
|
||||
return rsvp.Data("public_foreign_wishlist.gotmpl", p)
|
||||
return response.Data("public_foreign_wishlist.gotmpl", p)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"slices"
|
||||
|
||||
lishwist "lishwist/core"
|
||||
"lishwist/http/rsvp"
|
||||
"lishwist/http/response"
|
||||
)
|
||||
|
||||
type GroupProps struct {
|
||||
|
|
@ -13,14 +13,14 @@ type GroupProps struct {
|
|||
CurrentUsername string
|
||||
}
|
||||
|
||||
func AdminGroup(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func AdminGroup(app *lishwist.Session, h http.Header, r *response.Request) response.Response {
|
||||
reference := r.PathValue("groupReference")
|
||||
group, err := app.GetGroupByReference(reference)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Couldn't get group: %s", err)
|
||||
return response.Error(http.StatusInternalServerError, "Couldn't get group: %s", err)
|
||||
}
|
||||
if group == nil {
|
||||
return rsvp.Error(http.StatusNotFound, "Group not found")
|
||||
return response.Error(http.StatusNotFound, "Group not found")
|
||||
}
|
||||
if !app.User.IsAdmin {
|
||||
index := group.MemberIndex(app.User.Id)
|
||||
|
|
@ -30,20 +30,20 @@ func AdminGroup(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Resp
|
|||
Group: group,
|
||||
CurrentUsername: app.User.Name,
|
||||
}
|
||||
return rsvp.Data("group_page.gotmpl", p)
|
||||
return response.Data("group_page.gotmpl", p)
|
||||
}
|
||||
|
||||
func Group(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func Group(app *lishwist.Session, h http.Header, r *response.Request) response.Response {
|
||||
if app.User.IsAdmin {
|
||||
return AdminGroup(app, h, r)
|
||||
}
|
||||
groupReference := r.PathValue("groupReference")
|
||||
group, err := app.GetGroupByReference(groupReference)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "An error occurred while fetching this group :(").Log("Couldn't get group: %s", err)
|
||||
return response.Error(http.StatusInternalServerError, "An error occurred while fetching this group :(").Log("Couldn't get group: %s", err)
|
||||
}
|
||||
if group == nil {
|
||||
return rsvp.Error(http.StatusNotFound, "Group not found. (It might be because you're not a member)")
|
||||
return response.Error(http.StatusNotFound, "Group not found. (It might be because you're not a member)")
|
||||
}
|
||||
index := group.MemberIndex(app.User.Id)
|
||||
group.Members = slices.Delete(group.Members, index, index+1)
|
||||
|
|
@ -51,22 +51,22 @@ func Group(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response
|
|||
Group: group,
|
||||
CurrentUsername: app.User.Name,
|
||||
}
|
||||
return rsvp.Data("group_page.gotmpl", p)
|
||||
return response.Data("group_page.gotmpl", p)
|
||||
}
|
||||
|
||||
func PublicGroup(h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func PublicGroup(h http.Header, r *response.Request) response.Response {
|
||||
groupReference := r.PathValue("groupReference")
|
||||
group, err := lishwist.GetGroupByReference(groupReference)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "An error occurred while fetching this group :(").Log("Couldn't get group: %s", err)
|
||||
return response.Error(http.StatusInternalServerError, "An error occurred while fetching this group :(").Log("Couldn't get group: %s", err)
|
||||
}
|
||||
p := GroupProps{
|
||||
Group: group,
|
||||
}
|
||||
return rsvp.Data("public_group_page.gotmpl", p)
|
||||
return response.Data("public_group_page.gotmpl", p)
|
||||
}
|
||||
|
||||
func GroupPost(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func GroupPost(app *lishwist.Session, h http.Header, r *response.Request) response.Response {
|
||||
admin := app.Admin()
|
||||
if admin == nil {
|
||||
return NotFound(h, r)
|
||||
|
|
@ -83,27 +83,27 @@ func GroupPost(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Respo
|
|||
if name != "" {
|
||||
createdGroup, err := admin.CreateGroup(name, reference)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Failed to create group: %s", err)
|
||||
return response.Error(http.StatusInternalServerError, "Failed to create group: %s", err)
|
||||
}
|
||||
group = createdGroup
|
||||
} else {
|
||||
existingGroup, err := lishwist.GetGroupByReference(reference)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Failed to get group: %s", err)
|
||||
return response.Error(http.StatusInternalServerError, "Failed to get group: %s", err)
|
||||
}
|
||||
if existingGroup == nil {
|
||||
return rsvp.Error(http.StatusNotFound, "Group not found", err)
|
||||
return response.Error(http.StatusNotFound, "Group not found", err)
|
||||
}
|
||||
group = existingGroup
|
||||
|
||||
for _, userId := range removeUsers {
|
||||
index := group.MemberIndex(userId)
|
||||
if index == -1 {
|
||||
return rsvp.Error(http.StatusBadRequest, "Group %q does not contain a user with id %s", reference, userId)
|
||||
return response.Error(http.StatusBadRequest, "Group %q does not contain a user with id %s", reference, userId)
|
||||
}
|
||||
err = admin.RemoveUserFromGroup(userId, group.Id)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "On group %q failed to remove user with id %s: %s", reference, userId, err)
|
||||
return response.Error(http.StatusInternalServerError, "On group %q failed to remove user with id %s: %s", reference, userId, err)
|
||||
}
|
||||
group.Members = slices.Delete(group.Members, index, index+1)
|
||||
}
|
||||
|
|
@ -112,22 +112,22 @@ func GroupPost(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Respo
|
|||
for _, userId := range addUsers {
|
||||
user, err := admin.GetUser(userId)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Groups exists, but a user with id %s could not be fetched: %s", userId, err)
|
||||
return response.Error(http.StatusInternalServerError, "Groups exists, but a user with id %s could not be fetched: %s", userId, err)
|
||||
}
|
||||
if user == nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Groups exists, but a user with id %s does not exist", userId)
|
||||
return response.Error(http.StatusInternalServerError, "Groups exists, but a user with id %s does not exist", userId)
|
||||
}
|
||||
err = admin.AddUserToGroup(user.Id, group.Id)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Groups exists, but failed to add user with id %s: %s", userId, err)
|
||||
return response.Error(http.StatusInternalServerError, "Groups exists, but failed to add user with id %s: %s", userId, err)
|
||||
}
|
||||
group.Members = append(group.Members, *user)
|
||||
}
|
||||
|
||||
return rsvp.Data("", group)
|
||||
return response.Data("", group)
|
||||
}
|
||||
|
||||
func Groups(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func Groups(app *lishwist.Session, h http.Header, r *response.Request) response.Response {
|
||||
admin := app.Admin()
|
||||
if admin == nil {
|
||||
return NotFound(h, r)
|
||||
|
|
@ -135,8 +135,8 @@ func Groups(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response
|
|||
|
||||
groups, err := admin.ListGroups()
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Failed to get groups: %s", err)
|
||||
return response.Error(http.StatusInternalServerError, "Failed to get groups: %s", err)
|
||||
}
|
||||
|
||||
return rsvp.Data("", groups)
|
||||
return response.Data("", groups)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
|
||||
lishwist "lishwist/core"
|
||||
"lishwist/http/env"
|
||||
"lishwist/http/rsvp"
|
||||
"lishwist/http/response"
|
||||
)
|
||||
|
||||
type HomeProps struct {
|
||||
|
|
@ -17,24 +17,24 @@ type HomeProps struct {
|
|||
Groups []lishwist.Group
|
||||
}
|
||||
|
||||
func Home(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func Home(app *lishwist.Session, h http.Header, r *response.Request) response.Response {
|
||||
gifts, err := app.GetWishes()
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "An error occurred while fetching your wishlist :(").Log("Failed to get gifts: %s", err)
|
||||
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 rsvp.Error(http.StatusInternalServerError, "An error occurred while fetching your wishlist :(").Log("Failed to get todo: %s", err)
|
||||
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 rsvp.Error(http.StatusInternalServerError, "An error occurred while fetching your wishlist :(").Log("Failed to get groups: %s", err)
|
||||
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 rsvp.Data("home.gotmpl", p)
|
||||
return response.Data("home.gotmpl", p)
|
||||
}
|
||||
|
||||
func HomePost(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func HomePost(app *lishwist.Session, h http.Header, r *response.Request) response.Response {
|
||||
form := r.ParseForm()
|
||||
switch form.Get("intent") {
|
||||
case "add_idea":
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
package routing
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
lishwist "lishwist/core"
|
||||
"lishwist/http/api"
|
||||
"lishwist/http/rsvp"
|
||||
"net/http"
|
||||
"lishwist/http/response"
|
||||
)
|
||||
|
||||
func Login(h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func Login(h http.Header, r *response.Request) response.Response {
|
||||
session := r.GetSession()
|
||||
|
||||
props := api.NewLoginProps("", "")
|
||||
|
|
@ -28,10 +29,10 @@ func Login(h http.Header, r *rsvp.Request) rsvp.Response {
|
|||
props.SuccessfulRegistration = true
|
||||
}
|
||||
|
||||
return rsvp.Data("login.gotmpl", props).SaveSession(session)
|
||||
return response.Data("login.gotmpl", props).SaveSession(session)
|
||||
}
|
||||
|
||||
func LoginPost(h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func LoginPost(h http.Header, r *response.Request) response.Response {
|
||||
form := r.ParseForm()
|
||||
session := r.GetSession()
|
||||
|
||||
|
|
@ -44,7 +45,7 @@ func LoginPost(h http.Header, r *rsvp.Request) rsvp.Response {
|
|||
props.Password.Value = ""
|
||||
if !valid {
|
||||
session.FlashSet(&props)
|
||||
return rsvp.SeeOther("/").SaveSession(session).Log("Invalid props: %#v\n", props)
|
||||
return response.SeeOther("/").SaveSession(session).Log("Invalid props: %#v\n", props)
|
||||
}
|
||||
|
||||
app, err := lishwist.Login(username, password)
|
||||
|
|
@ -53,11 +54,11 @@ func LoginPost(h http.Header, r *rsvp.Request) rsvp.Response {
|
|||
case lishwist.ErrorInvalidCredentials:
|
||||
props.GeneralError = "Username or password invalid"
|
||||
session.FlashSet(&props)
|
||||
return rsvp.SeeOther("/").SaveSession(session).Log("Invalid credentials: %s: %#v\n", err, props)
|
||||
return response.SeeOther("/").SaveSession(session).Log("Invalid credentials: %s: %#v\n", err, props)
|
||||
default:
|
||||
props.GeneralError = "Something went wrong."
|
||||
session.FlashSet(&props)
|
||||
return rsvp.SeeOther("/").SaveSession(session).Log("Login error: %s\n", err)
|
||||
return response.SeeOther("/").SaveSession(session).Log("Login error: %s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -65,5 +66,5 @@ func LoginPost(h http.Header, r *rsvp.Request) rsvp.Response {
|
|||
session.SetValue("authorized", true)
|
||||
session.SetValue("username", app.User.Name)
|
||||
|
||||
return rsvp.SeeOther(r.URL().Path).SaveSession(session)
|
||||
return response.SeeOther(r.URL().Path).SaveSession(session)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
package routing
|
||||
|
||||
import (
|
||||
"lishwist/http/rsvp"
|
||||
"lishwist/http/response"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func LogoutPost(h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func LogoutPost(h http.Header, r *response.Request) response.Response {
|
||||
session := r.GetSession()
|
||||
|
||||
session.Options().MaxAge = 0
|
||||
session.ClearValues()
|
||||
|
||||
return rsvp.SeeOther("/").SaveSession(session)
|
||||
return response.SeeOther("/").SaveSession(session)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ package routing
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"lishwist/http/rsvp"
|
||||
"lishwist/http/response"
|
||||
)
|
||||
|
||||
func NotFound(h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
return rsvp.Error(http.StatusNotFound, "Page not found")
|
||||
func NotFound(h http.Header, r *response.Request) response.Response {
|
||||
return response.Error(http.StatusNotFound, "Page not found")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ import (
|
|||
"errors"
|
||||
lishwist "lishwist/core"
|
||||
"lishwist/http/api"
|
||||
"lishwist/http/rsvp"
|
||||
"lishwist/http/response"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Register(h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func Register(h http.Header, r *response.Request) response.Response {
|
||||
props := api.NewRegisterProps("", "", "")
|
||||
|
||||
session := r.GetSession()
|
||||
|
|
@ -23,10 +23,10 @@ func Register(h http.Header, r *rsvp.Request) rsvp.Response {
|
|||
props.ConfirmPassword.Error = flashProps.ConfirmPassword.Error
|
||||
}
|
||||
|
||||
return rsvp.Data("register.gotmpl", props).SaveSession(session)
|
||||
return response.Data("register.gotmpl", props).SaveSession(session)
|
||||
}
|
||||
|
||||
func RegisterPost(h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func RegisterPost(h http.Header, r *response.Request) response.Response {
|
||||
form := r.ParseForm()
|
||||
s := r.GetSession()
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ func RegisterPost(h http.Header, r *rsvp.Request) rsvp.Response {
|
|||
props.ConfirmPassword.Value = ""
|
||||
if !valid {
|
||||
s.FlashSet(&props)
|
||||
return rsvp.SeeOther("/").SaveSession(s).Log("Invalid props: %#v\n", props)
|
||||
return response.SeeOther("/").SaveSession(s).Log("Invalid props: %#v\n", props)
|
||||
}
|
||||
|
||||
_, err := lishwist.Register(username, newPassword)
|
||||
|
|
@ -52,9 +52,9 @@ func RegisterPost(h http.Header, r *rsvp.Request) rsvp.Response {
|
|||
props.GeneralError = "Something went wrong."
|
||||
}
|
||||
s.FlashSet(&props)
|
||||
return rsvp.SeeOther("/register").SaveSession(s).Log("Registration failed: %s\n", err)
|
||||
return response.SeeOther("/register").SaveSession(s).Log("Registration failed: %s\n", err)
|
||||
}
|
||||
|
||||
s.FlashSet(true)
|
||||
return rsvp.SeeOther("/").SaveSession(s)
|
||||
return response.SeeOther("/").SaveSession(s)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ package routing
|
|||
|
||||
import (
|
||||
lishwist "lishwist/core"
|
||||
"lishwist/http/rsvp"
|
||||
"lishwist/http/response"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func TodoUpdate(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func TodoUpdate(app *lishwist.Session, h http.Header, r *response.Request) response.Response {
|
||||
form := r.ParseForm()
|
||||
|
||||
switch form.Get("intent") {
|
||||
|
|
@ -14,16 +14,16 @@ func TodoUpdate(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Resp
|
|||
unclaims := form["gift"]
|
||||
err := app.ClaimWishes([]string{}, unclaims)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Failed to update claim...").LogError(err)
|
||||
return response.Error(http.StatusInternalServerError, "Failed to update claim...").LogError(err)
|
||||
}
|
||||
case "complete_todo":
|
||||
claims := form["gift"]
|
||||
err := app.CompleteWishes(claims)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Failed to complete gifts...").LogError(err)
|
||||
return response.Error(http.StatusInternalServerError, "Failed to complete gifts...").LogError(err)
|
||||
}
|
||||
default:
|
||||
return rsvp.Error(http.StatusBadRequest, "Invalid intent")
|
||||
return response.Error(http.StatusBadRequest, "Invalid intent")
|
||||
}
|
||||
return rsvp.SeeOther("/")
|
||||
return response.SeeOther("/")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ package routing
|
|||
|
||||
import (
|
||||
lishwist "lishwist/core"
|
||||
"lishwist/http/rsvp"
|
||||
"lishwist/http/response"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Users(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func Users(app *lishwist.Session, h http.Header, r *response.Request) response.Response {
|
||||
admin := app.Admin()
|
||||
if admin == nil {
|
||||
return NotFound(h, r)
|
||||
|
|
@ -14,13 +14,13 @@ func Users(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response
|
|||
|
||||
users, err := admin.ListUsers()
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Failed to get users: %s", err)
|
||||
return response.Error(http.StatusInternalServerError, "Failed to get users: %s", err)
|
||||
}
|
||||
|
||||
return rsvp.Data("", users)
|
||||
return response.Data("", users)
|
||||
}
|
||||
|
||||
func User(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func User(app *lishwist.Session, h http.Header, r *response.Request) response.Response {
|
||||
admin := app.Admin()
|
||||
if admin == nil {
|
||||
return NotFound(h, r)
|
||||
|
|
@ -30,16 +30,16 @@ func User(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response {
|
|||
|
||||
user, err := lishwist.GetUserByReference(reference)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Failed to get user: %s", err)
|
||||
return response.Error(http.StatusInternalServerError, "Failed to get user: %s", err)
|
||||
}
|
||||
if user == nil {
|
||||
return rsvp.Error(http.StatusNotFound, "User not found")
|
||||
return response.Error(http.StatusNotFound, "User not found")
|
||||
}
|
||||
|
||||
return rsvp.Data("", user)
|
||||
return response.Data("", user)
|
||||
}
|
||||
|
||||
func UserPost(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func UserPost(app *lishwist.Session, h http.Header, r *response.Request) response.Response {
|
||||
admin := app.Admin()
|
||||
if admin == nil {
|
||||
return NotFound(h, r)
|
||||
|
|
@ -49,15 +49,15 @@ func UserPost(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Respon
|
|||
|
||||
reference := r.PathValue("userReference")
|
||||
if reference == app.User.Reference {
|
||||
return rsvp.Error(http.StatusForbidden, "You cannot delete yourself.")
|
||||
return response.Error(http.StatusForbidden, "You cannot delete yourself.")
|
||||
}
|
||||
|
||||
user, err := lishwist.GetUserByReference(reference)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Failed to get user: %s", err)
|
||||
return response.Error(http.StatusInternalServerError, "Failed to get user: %s", err)
|
||||
}
|
||||
if user == nil {
|
||||
return rsvp.Error(http.StatusNotFound, "User not found")
|
||||
return response.Error(http.StatusNotFound, "User not found")
|
||||
}
|
||||
|
||||
intent := form.Get("intent")
|
||||
|
|
@ -65,9 +65,9 @@ func UserPost(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Respon
|
|||
if intent != "" {
|
||||
err = admin.UserSetLive(reference, intent != "delete")
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Failed to delete user: %s", err)
|
||||
return response.Error(http.StatusInternalServerError, "Failed to delete user: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
return rsvp.Data("", user)
|
||||
return response.Data("", user)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,31 +2,31 @@ package routing
|
|||
|
||||
import (
|
||||
lishwist "lishwist/core"
|
||||
"lishwist/http/rsvp"
|
||||
"lishwist/http/response"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func WishlistAdd(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func WishlistAdd(app *lishwist.Session, h http.Header, r *response.Request) response.Response {
|
||||
form := r.ParseForm()
|
||||
newGiftName := form.Get("gift_name")
|
||||
err := app.MakeWish(newGiftName)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Failed to add gift.").LogError(err)
|
||||
return response.Error(http.StatusInternalServerError, "Failed to add gift.").LogError(err)
|
||||
}
|
||||
return rsvp.SeeOther("/")
|
||||
return response.SeeOther("/")
|
||||
}
|
||||
|
||||
func WishlistDelete(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func WishlistDelete(app *lishwist.Session, h http.Header, r *response.Request) response.Response {
|
||||
form := r.ParseForm()
|
||||
targets := form["gift"]
|
||||
err := app.RevokeWishes(targets...)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Failed to remove gifts.").LogError(err)
|
||||
return response.Error(http.StatusInternalServerError, "Failed to remove gifts.").LogError(err)
|
||||
}
|
||||
return rsvp.SeeOther("/")
|
||||
return response.SeeOther("/")
|
||||
}
|
||||
|
||||
func ForeignWishlistPost(app *lishwist.Session, h http.Header, r *rsvp.Request) rsvp.Response {
|
||||
func ForeignWishlistPost(app *lishwist.Session, h http.Header, r *response.Request) response.Response {
|
||||
form := r.ParseForm()
|
||||
userReference := r.PathValue("userReference")
|
||||
intent := form.Get("intent")
|
||||
|
|
@ -36,22 +36,22 @@ func ForeignWishlistPost(app *lishwist.Session, h http.Header, r *rsvp.Request)
|
|||
unclaims := form["claimed"]
|
||||
err := app.ClaimWishes(claims, unclaims)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Failed to update claim...").LogError(err)
|
||||
return response.Error(http.StatusInternalServerError, "Failed to update claim...").LogError(err)
|
||||
}
|
||||
case "complete":
|
||||
claims := form["claimed"]
|
||||
err := app.CompleteWishes(claims)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Failed to complete gifts...").LogError(err)
|
||||
return response.Error(http.StatusInternalServerError, "Failed to complete gifts...").LogError(err)
|
||||
}
|
||||
case "add":
|
||||
wishName := form.Get("gift_name")
|
||||
if wishName == "" {
|
||||
return rsvp.Error(http.StatusBadRequest, "Gift name not provided")
|
||||
return response.Error(http.StatusBadRequest, "Gift name not provided")
|
||||
}
|
||||
err := app.SuggestWishForUser(userReference, wishName)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Failed to add gift idea to other user...").LogError(err)
|
||||
return response.Error(http.StatusInternalServerError, "Failed to add gift idea to other user...").LogError(err)
|
||||
}
|
||||
case "delete":
|
||||
claims := form["unclaimed"]
|
||||
|
|
@ -59,10 +59,10 @@ func ForeignWishlistPost(app *lishwist.Session, h http.Header, r *rsvp.Request)
|
|||
gifts := append(claims, unclaims...)
|
||||
err := app.RecindWishesForUser(gifts...)
|
||||
if err != nil {
|
||||
return rsvp.Error(http.StatusInternalServerError, "Failed to remove gift idea for other user...").LogError(err)
|
||||
return response.Error(http.StatusInternalServerError, "Failed to remove gift idea for other user...").LogError(err)
|
||||
}
|
||||
default:
|
||||
return rsvp.Error(http.StatusBadRequest, "Invalid intent %q", intent)
|
||||
return response.Error(http.StatusBadRequest, "Invalid intent %q", intent)
|
||||
}
|
||||
return rsvp.SeeOther("/list/" + userReference)
|
||||
return response.SeeOther("/list/" + userReference)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue