package context import ( "lishwist/db" "lishwist/templates" "log" "net/http" ) type ForeignWishlistProps struct { CurrentUserId string Username string UserReference string Gifts []db.Gift } func (ctx *Context) ViewForeignWishlist(w http.ResponseWriter, r *http.Request) { userReference := r.PathValue("userReference") user := ctx.Auth.ExpectUser(r) if user.Reference == userReference { http.Error(w, "You can't view your own list, silly ;)", http.StatusForbidden) return } otherUser, err := db.GetUserByReference(userReference) if err != nil { log.Printf("An error occurred while fetching a user: %s\n", err) http.Error(w, "An error occurred while fetching this user :(", http.StatusInternalServerError) return } if otherUser == nil { http.Error(w, "User not found", http.StatusNotFound) return } gifts, err := otherUser.GetGifts() if err != nil { log.Printf("An error occurred while fetching %s's wishlist: %s\n", otherUser.Name, err) http.Error(w, "An error occurred while fetching this user's wishlist :(", http.StatusInternalServerError) return } p := ForeignWishlistProps{CurrentUserId: user.Id, Username: otherUser.Name, UserReference: userReference, Gifts: gifts} templates.Execute(w, "foreign_wishlist.gotmpl", p) }