Add get details button for movies

This commit is contained in:
Grégoire Delattre 2016-11-23 19:14:52 +01:00
parent 64d731a9c6
commit 0a4d09d7c5
2 changed files with 15 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"github.com/gorilla/mux"
"github.com/odwrtw/papi" "github.com/odwrtw/papi"
polochon "github.com/odwrtw/polochon/lib" polochon "github.com/odwrtw/polochon/lib"
"github.com/odwrtw/polochon/modules/pam" "github.com/odwrtw/polochon/modules/pam"
@ -134,3 +135,16 @@ func ExplorePopular(env *web.Env, w http.ResponseWriter, r *http.Request) error
return env.RenderJSON(w, movies) return env.RenderJSON(w, movies)
} }
// GetDetailsHandler retrieves details for a movie
func GetDetailsHandler(env *web.Env, w http.ResponseWriter, r *http.Request) error {
vars := mux.Vars(r)
id := vars["id"]
m := New(id)
if err := m.GetDetails(env, true); err != nil {
return err
}
return env.RenderJSON(w, m)
}

View File

@ -75,6 +75,7 @@ func main() {
env.Handle("/movies/polochon", movies.FromPolochon).WithRole(users.UserRole) env.Handle("/movies/polochon", movies.FromPolochon).WithRole(users.UserRole)
env.Handle("/movies/explore/popular", movies.ExplorePopular).WithRole(users.UserRole) env.Handle("/movies/explore/popular", movies.ExplorePopular).WithRole(users.UserRole)
env.Handle("/movies/{id:tt[0-9]+}/get_details", movies.GetDetailsHandler).WithRole(users.UserRole)
n := negroni.Classic() n := negroni.Classic()
n.Use(authMiddleware) n.Use(authMiddleware)