28 lines
652 B
Go
28 lines
652 B
Go
package context
|
|
|
|
import (
|
|
"lishwist/db"
|
|
"lishwist/templates"
|
|
"net/http"
|
|
)
|
|
|
|
type ForeignWishlistProps struct {
|
|
Username string
|
|
Items []string
|
|
}
|
|
|
|
func (ctx *Context) ViewForeignWishlist(w http.ResponseWriter, r *http.Request) {
|
|
otherUsername := r.PathValue("username")
|
|
user := ctx.Auth.ExpectUser(r)
|
|
if user.Username == otherUsername {
|
|
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
|
return
|
|
}
|
|
items := db.GetUserItems(otherUsername)
|
|
if items == nil {
|
|
http.Error(w, "User not found", http.StatusNotFound)
|
|
}
|
|
p := ForeignWishlistProps{Username: otherUsername, Items: items}
|
|
templates.Execute(w, "foreign_wishlist.gotmpl", p)
|
|
}
|