From d33c02a5ac1b6e93e76af7da65ef6e691b133a1c Mon Sep 17 00:00:00 2001 From: Teajey <21069848+Teajey@users.noreply.github.com> Date: Tue, 19 Aug 2025 16:43:28 +0900 Subject: [PATCH] Rename internal rsvp package To prevent conflicts when github.com/Teajey/rsvp moves in --- http/{rsvp => response}/handler.go | 4 +-- http/{rsvp => response}/request.go | 2 +- http/{rsvp => response}/response.go | 4 +-- http/{rsvp => response}/session.go | 2 +- http/router/router.go | 10 +++--- http/routing/context.go | 14 ++++---- http/routing/foreign_wishlist.go | 24 +++++++------- http/routing/groups.go | 50 ++++++++++++++--------------- http/routing/home.go | 14 ++++---- http/routing/login.go | 19 +++++------ http/routing/logout.go | 6 ++-- http/routing/not_found.go | 6 ++-- http/routing/register.go | 14 ++++---- http/routing/todo.go | 12 +++---- http/routing/users.go | 28 ++++++++-------- http/routing/wishlist.go | 30 ++++++++--------- 16 files changed, 121 insertions(+), 118 deletions(-) rename http/{rsvp => response}/handler.go (93%) rename http/{rsvp => response}/request.go (97%) rename http/{rsvp => response}/response.go (96%) rename http/{rsvp => response}/session.go (97%) diff --git a/http/rsvp/handler.go b/http/response/handler.go similarity index 93% rename from http/rsvp/handler.go rename to http/response/handler.go index c172834..43c3fa7 100644 --- a/http/rsvp/handler.go +++ b/http/response/handler.go @@ -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) } }) diff --git a/http/rsvp/request.go b/http/response/request.go similarity index 97% rename from http/rsvp/request.go rename to http/response/request.go index 7e387cd..9ed5b97 100644 --- a/http/rsvp/request.go +++ b/http/response/request.go @@ -1,4 +1,4 @@ -package rsvp +package response import ( "log" diff --git a/http/rsvp/response.go b/http/response/response.go similarity index 96% rename from http/rsvp/response.go rename to http/response/response.go index 2c380b5..94f7ddd 100644 --- a/http/rsvp/response.go +++ b/http/response/response.go @@ -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 } diff --git a/http/rsvp/session.go b/http/response/session.go similarity index 97% rename from http/rsvp/session.go rename to http/response/session.go index 4da6ed0..0399994 100644 --- a/http/rsvp/session.go +++ b/http/response/session.go @@ -1,4 +1,4 @@ -package rsvp +package response import ( "github.com/gorilla/sessions" diff --git a/http/router/router.go b/http/router/router.go index 8891f68..4a0c75d 100644 --- a/http/router/router.go +++ b/http/router/router.go @@ -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), } } diff --git a/http/routing/context.go b/http/routing/context.go index a45b9f1..f02f041 100644 --- a/http/routing/context.go +++ b/http/routing/context.go @@ -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) diff --git a/http/routing/foreign_wishlist.go b/http/routing/foreign_wishlist.go index 9a91c88..5b1d2d9 100644 --- a/http/routing/foreign_wishlist.go +++ b/http/routing/foreign_wishlist.go @@ -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) } diff --git a/http/routing/groups.go b/http/routing/groups.go index eefdac3..c2756f1 100644 --- a/http/routing/groups.go +++ b/http/routing/groups.go @@ -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) } diff --git a/http/routing/home.go b/http/routing/home.go index 4e4229c..c7f268c 100644 --- a/http/routing/home.go +++ b/http/routing/home.go @@ -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": diff --git a/http/routing/login.go b/http/routing/login.go index bb5cf65..c2434c1 100644 --- a/http/routing/login.go +++ b/http/routing/login.go @@ -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) } diff --git a/http/routing/logout.go b/http/routing/logout.go index dc1bb66..d25638b 100644 --- a/http/routing/logout.go +++ b/http/routing/logout.go @@ -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) } diff --git a/http/routing/not_found.go b/http/routing/not_found.go index 43a0efd..bc68387 100644 --- a/http/routing/not_found.go +++ b/http/routing/not_found.go @@ -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") } diff --git a/http/routing/register.go b/http/routing/register.go index b7a8d4c..d9e15ec 100644 --- a/http/routing/register.go +++ b/http/routing/register.go @@ -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) } diff --git a/http/routing/todo.go b/http/routing/todo.go index 4f6764a..a56e500 100644 --- a/http/routing/todo.go +++ b/http/routing/todo.go @@ -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("/") } diff --git a/http/routing/users.go b/http/routing/users.go index becb2e3..bdada5b 100644 --- a/http/routing/users.go +++ b/http/routing/users.go @@ -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) } diff --git a/http/routing/wishlist.go b/http/routing/wishlist.go index dec0cf3..d0363cf 100644 --- a/http/routing/wishlist.go +++ b/http/routing/wishlist.go @@ -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) }