package context import ( "lishwist/db" "lishwist/templates" "log" "net/http" ) type ForeignWishlistProps struct { Username string Gifts []db.Gift } func (ctx *Context) ViewForeignWishlist(w http.ResponseWriter, r *http.Request) { otherUsername := r.PathValue("username") user := ctx.Auth.ExpectUser(r) if user.Name == otherUsername { http.Error(w, "You can't view your own list, silly ;)", http.StatusForbidden) return } otherUser, err := db.GetUser(otherUsername) 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 { http.Error(w, "An error occurred while fetching this user's wishlist :(", http.StatusInternalServerError) return } p := ForeignWishlistProps{Username: otherUsername, Gifts: gifts} templates.Execute(w, "foreign_wishlist.gotmpl", p) }