Add routes to show explorer's options
This commit is contained in:
parent
7f7da8d097
commit
f042987d10
@ -16,6 +16,11 @@ const (
|
|||||||
RETURNING id;`
|
RETURNING id;`
|
||||||
|
|
||||||
getExternalMediaQuery = `SELECT * FROM external_medias WHERE type=$1 AND source=$2 AND category=$3 LIMIT 1;`
|
getExternalMediaQuery = `SELECT * FROM external_medias WHERE type=$1 AND source=$2 AND category=$3 LIMIT 1;`
|
||||||
|
getExternalMediaOptions = `
|
||||||
|
SELECT
|
||||||
|
source, category
|
||||||
|
FROM external_medias
|
||||||
|
WHERE type=$1;`
|
||||||
)
|
)
|
||||||
|
|
||||||
// Media represents an external media
|
// Media represents an external media
|
||||||
@ -46,3 +51,21 @@ func (m *Media) Upsert(db *sqlx.DB) error {
|
|||||||
defer r.Close()
|
defer r.Close()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetMediaOptions(db *sqlx.DB, mtype string) (map[string][]string, error) {
|
||||||
|
type mediaAvailable struct {
|
||||||
|
Source string `db:"source"`
|
||||||
|
Category string `db:"category"`
|
||||||
|
}
|
||||||
|
m := []*mediaAvailable{}
|
||||||
|
if err := db.Select(&m, getExternalMediaOptions, mtype); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
availableMedia := map[string][]string{}
|
||||||
|
for _, p := range m {
|
||||||
|
availableMedia[p.Source] = append(availableMedia[p.Source], p.Category)
|
||||||
|
}
|
||||||
|
|
||||||
|
return availableMedia, nil
|
||||||
|
}
|
||||||
|
@ -185,3 +185,29 @@ func Refresh(env *web.Env) {
|
|||||||
RefreshMovies(env)
|
RefreshMovies(env)
|
||||||
env.Log.Debugf("done refreshing movies")
|
env.Log.Debugf("done refreshing movies")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetShowOptions will get show explorer options available
|
||||||
|
func GetShowOptions(env *web.Env) (map[string][]string, error) {
|
||||||
|
log := env.Log.WithFields(logrus.Fields{
|
||||||
|
"function": "extmedias.GetShowOptions",
|
||||||
|
})
|
||||||
|
log.Debugf("getting explorer show options")
|
||||||
|
e, err := backend.GetMediaOptions(env.Database, "show")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return e, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMovieOptions will get movie explorer options available
|
||||||
|
func GetMovieOptions(env *web.Env) (map[string][]string, error) {
|
||||||
|
log := env.Log.WithFields(logrus.Fields{
|
||||||
|
"function": "extmedias.GetMovieOptions",
|
||||||
|
})
|
||||||
|
log.Debugf("getting explorer movie options")
|
||||||
|
e, err := backend.GetMediaOptions(env.Database, "movie")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return e, nil
|
||||||
|
}
|
||||||
|
@ -227,3 +227,25 @@ func ExploreShows(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
|||||||
|
|
||||||
return env.RenderJSON(w, shows)
|
return env.RenderJSON(w, shows)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MovieExplorerOptions will return all the explore movie options available
|
||||||
|
func MovieExplorerOptions(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||||
|
// Get the list of movie explorer options available
|
||||||
|
movieOptions, err := GetMovieOptions(env)
|
||||||
|
if err != nil {
|
||||||
|
return env.RenderError(w, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return env.RenderJSON(w, movieOptions)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShowExplorerOptions will return all the explore show options available
|
||||||
|
func ShowExplorerOptions(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||||
|
// Get the list of show explorer options available
|
||||||
|
showOptions, err := GetShowOptions(env)
|
||||||
|
if err != nil {
|
||||||
|
return env.RenderError(w, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return env.RenderJSON(w, showOptions)
|
||||||
|
}
|
||||||
|
@ -19,6 +19,7 @@ func setupRoutes(env *web.Env) {
|
|||||||
// Movies routes
|
// Movies routes
|
||||||
env.Handle("/movies/polochon", movies.PolochonMoviesHandler).WithRole(users.UserRole).Methods("GET")
|
env.Handle("/movies/polochon", movies.PolochonMoviesHandler).WithRole(users.UserRole).Methods("GET")
|
||||||
env.Handle("/movies/explore", extmedias.ExploreMovies).WithRole(users.UserRole).Methods("GET")
|
env.Handle("/movies/explore", extmedias.ExploreMovies).WithRole(users.UserRole).Methods("GET")
|
||||||
|
env.Handle("/movies/explore/options", extmedias.MovieExplorerOptions).WithRole(users.UserRole).Methods("GET")
|
||||||
env.Handle("/movies/search", movies.SearchMovie).WithRole(users.UserRole).Methods("POST")
|
env.Handle("/movies/search", movies.SearchMovie).WithRole(users.UserRole).Methods("POST")
|
||||||
env.Handle("/movies/{id:tt[0-9]+}", movies.PolochonDeleteHandler).WithRole(users.AdminRole).Methods("DELETE")
|
env.Handle("/movies/{id:tt[0-9]+}", movies.PolochonDeleteHandler).WithRole(users.AdminRole).Methods("DELETE")
|
||||||
env.Handle("/movies/{id:tt[0-9]+}/refresh", movies.RefreshMovieHandler).WithRole(users.UserRole).Methods("POST")
|
env.Handle("/movies/{id:tt[0-9]+}/refresh", movies.RefreshMovieHandler).WithRole(users.UserRole).Methods("POST")
|
||||||
@ -27,6 +28,7 @@ func setupRoutes(env *web.Env) {
|
|||||||
// Shows routes
|
// Shows routes
|
||||||
env.Handle("/shows/polochon", shows.PolochonShowsHandler).WithRole(users.UserRole).Methods("GET")
|
env.Handle("/shows/polochon", shows.PolochonShowsHandler).WithRole(users.UserRole).Methods("GET")
|
||||||
env.Handle("/shows/explore", extmedias.ExploreShows).WithRole(users.UserRole).Methods("GET")
|
env.Handle("/shows/explore", extmedias.ExploreShows).WithRole(users.UserRole).Methods("GET")
|
||||||
|
env.Handle("/shows/explore/options", extmedias.ShowExplorerOptions).WithRole(users.UserRole).Methods("GET")
|
||||||
env.Handle("/shows/search", shows.SearchShow).WithRole(users.UserRole).Methods("POST")
|
env.Handle("/shows/search", shows.SearchShow).WithRole(users.UserRole).Methods("POST")
|
||||||
env.Handle("/shows/{id:tt[0-9]+}", shows.GetDetailsHandler).WithRole(users.UserRole).Methods("GET")
|
env.Handle("/shows/{id:tt[0-9]+}", shows.GetDetailsHandler).WithRole(users.UserRole).Methods("GET")
|
||||||
env.Handle("/shows/{id:tt[0-9]+}/refresh", shows.RefreshShowHandler).WithRole(users.UserRole).Methods("POST")
|
env.Handle("/shows/{id:tt[0-9]+}/refresh", shows.RefreshShowHandler).WithRole(users.UserRole).Methods("POST")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user