Merge branch 'explorers' into 'master'

Explorers

See merge request !49
This commit is contained in:
Grégoire Delattre 2017-03-22 11:46:20 +00:00
commit 80ed83aeba
11 changed files with 140 additions and 67 deletions

View File

@ -25,8 +25,8 @@ const (
FROM episode_torrents WHERE imdb_id=$1 AND season=$2 AND episode=$3;` FROM episode_torrents WHERE imdb_id=$1 AND season=$2 AND episode=$3;`
) )
// EpisodeTorrentDB represents the EpisodeTorrent in the DB // episodeTorrentDB represents the EpisodeTorrent in the DB
type EpisodeTorrentDB struct { type episodeTorrentDB struct {
ID string `db:"id"` ID string `db:"id"`
ImdbID string `db:"imdb_id"` ImdbID string `db:"imdb_id"`
URL string `db:"url"` URL string `db:"url"`
@ -43,7 +43,7 @@ type EpisodeTorrentDB struct {
// NewTorrentFromEpisodeTorrentDB returns a polochon.Torrent from an // NewTorrentFromEpisodeTorrentDB returns a polochon.Torrent from an
// episodeTorrentDB // episodeTorrentDB
func NewTorrentFromEpisodeTorrentDB(eDB *EpisodeTorrentDB) *polochon.Torrent { func NewTorrentFromEpisodeTorrentDB(eDB *episodeTorrentDB) *polochon.Torrent {
q, _ := polochon.StringToQuality(eDB.Quality) q, _ := polochon.StringToQuality(eDB.Quality)
return &polochon.Torrent{ return &polochon.Torrent{
Quality: *q, Quality: *q,
@ -55,10 +55,10 @@ func NewTorrentFromEpisodeTorrentDB(eDB *EpisodeTorrentDB) *polochon.Torrent {
} }
} }
// NewEpisodeTorrentDB returns an EpisodeTorrentDB ready to be put in DB from a // NewEpisodeTorrentDB returns an episodeTorrentDB ready to be put in DB from a
// polochon.Torrent // polochon.Torrent
func NewEpisodeTorrentDB(t *polochon.Torrent, imdbID string, season, episode int) *EpisodeTorrentDB { func NewEpisodeTorrentDB(t *polochon.Torrent, imdbID string, season, episode int) *episodeTorrentDB {
return &EpisodeTorrentDB{ return &episodeTorrentDB{
ImdbID: imdbID, ImdbID: imdbID,
Season: season, Season: season,
Episode: episode, Episode: episode,
@ -73,7 +73,7 @@ func NewEpisodeTorrentDB(t *polochon.Torrent, imdbID string, season, episode int
// GetEpisodeTorrents returns show episodes torrents from database // GetEpisodeTorrents returns show episodes torrents from database
func GetEpisodeTorrents(db *sqlx.DB, imdbID string, season, episode int) ([]polochon.Torrent, error) { func GetEpisodeTorrents(db *sqlx.DB, imdbID string, season, episode int) ([]polochon.Torrent, error) {
var torrentsDB = []*EpisodeTorrentDB{} var torrentsDB = []*episodeTorrentDB{}
err := db.Select(&torrentsDB, getEpisodeTorrentQuery, imdbID, season, episode) err := db.Select(&torrentsDB, getEpisodeTorrentQuery, imdbID, season, episode)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -28,8 +28,8 @@ const (
FROM episodes WHERE show_imdb_id=$1 AND season=$2 AND episode=$3;` FROM episodes WHERE show_imdb_id=$1 AND season=$2 AND episode=$3;`
) )
// EpisodeDB represents the Episode in the DB // episodeDB represents the Episode in the DB
type EpisodeDB struct { type episodeDB struct {
ID string `db:"id"` ID string `db:"id"`
TvdbID int `db:"tvdb_id"` TvdbID int `db:"tvdb_id"`
ImdbID string `db:"imdb_id"` ImdbID string `db:"imdb_id"`
@ -48,9 +48,9 @@ type EpisodeDB struct {
Updated time.Time `db:"updated_at"` Updated time.Time `db:"updated_at"`
} }
// NewEpisodeFromPolochon returns an EpisodeDB from a polochon ShowEpisode // NewEpisodeFromPolochon returns an episodeDB from a polochon ShowEpisode
func NewEpisodeFromPolochon(e *polochon.ShowEpisode) *EpisodeDB { func NewEpisodeFromPolochon(e *polochon.ShowEpisode) *episodeDB {
return &EpisodeDB{ return &episodeDB{
TvdbID: e.TvdbID, TvdbID: e.TvdbID,
ImdbID: e.EpisodeImdbID, ImdbID: e.EpisodeImdbID,
ShowImdbID: e.ShowImdbID, ShowImdbID: e.ShowImdbID,
@ -67,15 +67,15 @@ func NewEpisodeFromPolochon(e *polochon.ShowEpisode) *EpisodeDB {
} }
} }
// NewEpisodeFromDB returns a new polochon ShowEpisode from an EpisodeDB // NewEpisodeFromDB returns a new polochon ShowEpisode from an episodeDB
func NewEpisodeFromDB(eDB *EpisodeDB) *polochon.ShowEpisode { func NewEpisodeFromDB(eDB *episodeDB) *polochon.ShowEpisode {
pEpisode := polochon.ShowEpisode{} pEpisode := polochon.ShowEpisode{}
FillEpisodeFromDB(eDB, &pEpisode) FillEpisodeFromDB(eDB, &pEpisode)
return &pEpisode return &pEpisode
} }
// FillEpisodeFromDB fills a ShowEpisode from an EpisodeDB // FillEpisodeFromDB fills a ShowEpisode from an episodeDB
func FillEpisodeFromDB(eDB *EpisodeDB, pEpisode *polochon.ShowEpisode) { func FillEpisodeFromDB(eDB *episodeDB, pEpisode *polochon.ShowEpisode) {
pEpisode.TvdbID = eDB.TvdbID pEpisode.TvdbID = eDB.TvdbID
pEpisode.EpisodeImdbID = eDB.ImdbID pEpisode.EpisodeImdbID = eDB.ImdbID
pEpisode.ShowImdbID = eDB.ShowImdbID pEpisode.ShowImdbID = eDB.ShowImdbID
@ -92,7 +92,7 @@ func FillEpisodeFromDB(eDB *EpisodeDB, pEpisode *polochon.ShowEpisode) {
// GetEpisode gets an episode and fills the polochon episode // GetEpisode gets an episode and fills the polochon episode
func GetEpisode(db *sqlx.DB, pEpisode *polochon.ShowEpisode) error { func GetEpisode(db *sqlx.DB, pEpisode *polochon.ShowEpisode) error {
var episodeDB EpisodeDB var episodeDB episodeDB
err := db.QueryRowx(getEpisodeQuery, pEpisode.ShowImdbID, pEpisode.Season, pEpisode.Episode).StructScan(&episodeDB) err := db.QueryRowx(getEpisodeQuery, pEpisode.ShowImdbID, pEpisode.Season, pEpisode.Episode).StructScan(&episodeDB)
if err != nil { if err != nil {
return err return err
@ -106,7 +106,7 @@ func GetEpisode(db *sqlx.DB, pEpisode *polochon.ShowEpisode) error {
// GetEpisodes gets show's episodes and fills the polochon show // GetEpisodes gets show's episodes and fills the polochon show
func GetEpisodes(db *sqlx.DB, pShow *polochon.Show, log *logrus.Entry) error { func GetEpisodes(db *sqlx.DB, pShow *polochon.Show, log *logrus.Entry) error {
// Get the episodes // Get the episodes
var episodesDB = []*EpisodeDB{} var episodesDB = []*episodeDB{}
err := db.Select(&episodesDB, getEpisodesQuery, pShow.ImdbID) err := db.Select(&episodesDB, getEpisodesQuery, pShow.ImdbID)
if err != nil { if err != nil {
return err return err

View File

@ -15,7 +15,12 @@ const (
DO UPDATE SET type=:type, source=:source, category=:category, ids=:ids DO UPDATE SET type=:type, source=:source, category=:category, ids=:ids
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
}

View File

@ -24,8 +24,8 @@ const (
FROM movie_torrents WHERE imdb_id=$1;` FROM movie_torrents WHERE imdb_id=$1;`
) )
// MovieTorrentDB represents the MovieTorrent in the DB // movieTorrentDB represents the MovieTorrent in the DB
type MovieTorrentDB struct { type movieTorrentDB struct {
ID string `db:"id"` ID string `db:"id"`
ImdbID string `db:"imdb_id"` ImdbID string `db:"imdb_id"`
URL string `db:"url"` URL string `db:"url"`
@ -39,8 +39,8 @@ type MovieTorrentDB struct {
} }
// NewTorrentFromMovieTorrentDB creates a new polochon.Torrent from a // NewTorrentFromMovieTorrentDB creates a new polochon.Torrent from a
// MovieTorrentDB // movieTorrentDB
func NewTorrentFromMovieTorrentDB(mDB *MovieTorrentDB) *polochon.Torrent { func NewTorrentFromMovieTorrentDB(mDB *movieTorrentDB) *polochon.Torrent {
q, _ := polochon.StringToQuality(mDB.Quality) q, _ := polochon.StringToQuality(mDB.Quality)
return &polochon.Torrent{ return &polochon.Torrent{
Quality: *q, Quality: *q,
@ -54,8 +54,8 @@ func NewTorrentFromMovieTorrentDB(mDB *MovieTorrentDB) *polochon.Torrent {
// NewMovieTorrentDB returns a MovieTorrent ready to be put in DB from a // NewMovieTorrentDB returns a MovieTorrent ready to be put in DB from a
// Torrent // Torrent
func NewMovieTorrentDB(t *polochon.Torrent, imdbID string) MovieTorrentDB { func NewMovieTorrentDB(t *polochon.Torrent, imdbID string) movieTorrentDB {
return MovieTorrentDB{ return movieTorrentDB{
ImdbID: imdbID, ImdbID: imdbID,
URL: t.URL, URL: t.URL,
Source: t.Source, Source: t.Source,
@ -68,7 +68,7 @@ func NewMovieTorrentDB(t *polochon.Torrent, imdbID string) MovieTorrentDB {
// GetMovieTorrents returns polochon.Torrents from the database // GetMovieTorrents returns polochon.Torrents from the database
func GetMovieTorrents(db *sqlx.DB, imdbID string) ([]polochon.Torrent, error) { func GetMovieTorrents(db *sqlx.DB, imdbID string) ([]polochon.Torrent, error) {
var torrentsDB = []*MovieTorrentDB{} var torrentsDB = []*movieTorrentDB{}
// Get the torrents from the DB // Get the torrents from the DB
err := db.Select(&torrentsDB, getMovieTorrentQueryByImdbID, imdbID) err := db.Select(&torrentsDB, getMovieTorrentQueryByImdbID, imdbID)
if err != nil { if err != nil {
@ -79,7 +79,7 @@ func GetMovieTorrents(db *sqlx.DB, imdbID string) ([]polochon.Torrent, error) {
return nil, sql.ErrNoRows return nil, sql.ErrNoRows
} }
// Create polochon Torrents from the MovieTorrentDB // Create polochon Torrents from the movieTorrentDB
var torrents []polochon.Torrent var torrents []polochon.Torrent
for _, torrentDB := range torrentsDB { for _, torrentDB := range torrentsDB {
torrent := NewTorrentFromMovieTorrentDB(torrentDB) torrent := NewTorrentFromMovieTorrentDB(torrentDB)

View File

@ -33,25 +33,25 @@ const (
deleteMovieWishlistedQueryByID = `DELETE FROM movies_tracked WHERE imdb_id=$1 AND user_id=$2;` deleteMovieWishlistedQueryByID = `DELETE FROM movies_tracked WHERE imdb_id=$1 AND user_id=$2;`
) )
// MovieWishlist represents the list of movies wishlisted by a user // movieWishlist represents the list of movies wishlisted by a user
type MovieWishlist struct { type movieWishlist struct {
movies map[string]struct{} movies map[string]struct{}
} }
// NewMovieWishlist returns a new MovieWishlist // NewMovieWishlist returns a new movieWishlist
func NewMovieWishlist() *MovieWishlist { func NewMovieWishlist() *movieWishlist {
return &MovieWishlist{ return &movieWishlist{
movies: map[string]struct{}{}, movies: map[string]struct{}{},
} }
} }
// add adds movie to the MovieWishlist // add adds movie to the movieWishlist
func (w *MovieWishlist) add(imdbID string) { func (w *movieWishlist) add(imdbID string) {
w.movies[imdbID] = struct{}{} w.movies[imdbID] = struct{}{}
} }
// List return a slice of imdbID wishlisted // List return a slice of imdbID wishlisted
func (w *MovieWishlist) List() []string { func (w *movieWishlist) List() []string {
movies := make([]string, len(w.movies)) movies := make([]string, len(w.movies))
i := 0 i := 0
@ -63,15 +63,15 @@ func (w *MovieWishlist) List() []string {
return movies return movies
} }
// GetMovieWishlist returns a MovieWishlist obejct for a user // GetMovieWishlist returns a movieWishlist obejct for a user
func GetMovieWishlist(db *sqlx.DB, userID string) (*MovieWishlist, error) { func GetMovieWishlist(db *sqlx.DB, userID string) (*movieWishlist, error) {
var movies = []string{} var movies = []string{}
// Get the list of movies // Get the list of movies
err := db.Select(&movies, getMovieWishlistQueryByUserID, userID) err := db.Select(&movies, getMovieWishlistQueryByUserID, userID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// Create a new MovieWishlist // Create a new movieWishlist
wishlist := NewMovieWishlist() wishlist := NewMovieWishlist()
for _, imdbID := range movies { for _, imdbID := range movies {
// add the movie to the wishlist object // add the movie to the wishlist object
@ -82,7 +82,7 @@ func GetMovieWishlist(db *sqlx.DB, userID string) (*MovieWishlist, error) {
} }
// IsMovieInWishlist returns true if the movie is in the wishlist // IsMovieInWishlist returns true if the movie is in the wishlist
func (w *MovieWishlist) IsMovieInWishlist(imdbID string) bool { func (w *movieWishlist) IsMovieInWishlist(imdbID string) bool {
_, ok := w.movies[imdbID] _, ok := w.movies[imdbID]
return ok return ok
} }

View File

@ -29,8 +29,8 @@ const (
WHERE imdb_id=$1;` WHERE imdb_id=$1;`
) )
// MovieDB represents the Movie in the DB // movieDB represents the Movie in the DB
type MovieDB struct { type movieDB struct {
ID string `db:"id"` ID string `db:"id"`
ImdbID string `db:"imdb_id"` ImdbID string `db:"imdb_id"`
TmdbID int `db:"tmdb_id"` TmdbID int `db:"tmdb_id"`
@ -51,7 +51,7 @@ type MovieDB struct {
// GetMovie fills show details of a polochon.Movie // GetMovie fills show details of a polochon.Movie
func GetMovie(db *sqlx.DB, pMovie *polochon.Movie) error { func GetMovie(db *sqlx.DB, pMovie *polochon.Movie) error {
var mDB MovieDB var mDB movieDB
var err error var err error
if pMovie.ImdbID != "" { if pMovie.ImdbID != "" {
// Get the data from the DB // Get the data from the DB
@ -63,13 +63,13 @@ func GetMovie(db *sqlx.DB, pMovie *polochon.Movie) error {
return err return err
} }
// Fills the polochon.Movie from the MovieDB // Fills the polochon.Movie from the movieDB
FillFromDB(&mDB, pMovie) FillFromDB(&mDB, pMovie)
return nil return nil
} }
// FillFromDB fills a Movie from a MovieDB extracted from the DB // FillFromDB fills a Movie from a movieDB extracted from the DB
func FillFromDB(mDB *MovieDB, pMovie *polochon.Movie) { func FillFromDB(mDB *movieDB, pMovie *polochon.Movie) {
pMovie.ImdbID = mDB.ImdbID pMovie.ImdbID = mDB.ImdbID
pMovie.Title = mDB.Title pMovie.Title = mDB.Title
pMovie.Rating = mDB.Rating pMovie.Rating = mDB.Rating
@ -98,12 +98,12 @@ func UpsertMovie(db *sqlx.DB, pMovie *polochon.Movie) error {
// NewMovieDB returns a Movie ready to be put in DB from a // NewMovieDB returns a Movie ready to be put in DB from a
// polochon Movie // polochon Movie
func NewMovieDB(m *polochon.Movie) MovieDB { func NewMovieDB(m *polochon.Movie) movieDB {
genres := []string{} genres := []string{}
if m.Genres != nil { if m.Genres != nil {
genres = m.Genres genres = m.Genres
} }
return MovieDB{ return movieDB{
ImdbID: m.ImdbID, ImdbID: m.ImdbID,
Title: m.Title, Title: m.Title,
Rating: m.Rating, Rating: m.Rating,

View File

@ -33,8 +33,8 @@ const (
deleteShowWishlistedQueryByID = `DELETE FROM shows_tracked WHERE imdb_id=$1 AND user_id=$2;` deleteShowWishlistedQueryByID = `DELETE FROM shows_tracked WHERE imdb_id=$1 AND user_id=$2;`
) )
// ShowWishlist represents the show wishlist of a user // showWishlist represents the show wishlist of a user
type ShowWishlist struct { type showWishlist struct {
shows map[string]*WishedShow shows map[string]*WishedShow
} }
@ -45,15 +45,15 @@ type WishedShow struct {
Episode int Episode int
} }
// NewShowWishlist returns a new ShowWishlist // NewShowWishlist returns a new showWishlist
func NewShowWishlist() *ShowWishlist { func NewShowWishlist() *showWishlist {
return &ShowWishlist{ return &showWishlist{
shows: map[string]*WishedShow{}, shows: map[string]*WishedShow{},
} }
} }
// add adds a show to the ShowWishlist object // add adds a show to the showWishlist object
func (w *ShowWishlist) add(imdbID string, season, episode int) { func (w *showWishlist) add(imdbID string, season, episode int) {
w.shows[imdbID] = &WishedShow{ w.shows[imdbID] = &WishedShow{
ImdbID: imdbID, ImdbID: imdbID,
Season: season, Season: season,
@ -62,7 +62,7 @@ func (w *ShowWishlist) add(imdbID string, season, episode int) {
} }
// List return a slice of WishedShow // List return a slice of WishedShow
func (w *ShowWishlist) List() []*WishedShow { func (w *showWishlist) List() []*WishedShow {
shows := make([]*WishedShow, len(w.shows)) shows := make([]*WishedShow, len(w.shows))
i := 0 i := 0
@ -78,8 +78,8 @@ func (w *ShowWishlist) List() []*WishedShow {
return shows return shows
} }
// GetShowWishlist returns a ShowWishlist for a user // GetShowWishlist returns a showWishlist for a user
func GetShowWishlist(db *sqlx.DB, userID string) (*ShowWishlist, error) { func GetShowWishlist(db *sqlx.DB, userID string) (*showWishlist, error) {
var wishedShows = []*WishedShow{} var wishedShows = []*WishedShow{}
// Get the wishlisted shows // Get the wishlisted shows
err := db.Select(&wishedShows, getShowWishlistQueryByUserID, userID) err := db.Select(&wishedShows, getShowWishlistQueryByUserID, userID)
@ -98,7 +98,7 @@ func GetShowWishlist(db *sqlx.DB, userID string) (*ShowWishlist, error) {
// IsShowInWishlist returns true and the WishedShow if the show is in the // IsShowInWishlist returns true and the WishedShow if the show is in the
// wishlist // wishlist
func (w *ShowWishlist) IsShowInWishlist(imdbID string) (*WishedShow, bool) { func (w *showWishlist) IsShowInWishlist(imdbID string) (*WishedShow, bool) {
show, ok := w.shows[imdbID] show, ok := w.shows[imdbID]
return show, ok return show, ok
} }

View File

@ -23,8 +23,8 @@ const (
FROM shows WHERE imdb_id=$1;` FROM shows WHERE imdb_id=$1;`
) )
// ShowDB represents the Show in the DB // showDB represents the Show in the DB
type ShowDB struct { type showDB struct {
ID string `db:"id"` ID string `db:"id"`
ImdbID string `db:"imdb_id"` ImdbID string `db:"imdb_id"`
TvdbID int `db:"tvdb_id"` TvdbID int `db:"tvdb_id"`
@ -59,9 +59,9 @@ func UpsertShow(db *sqlx.DB, s *polochon.Show) error {
return nil return nil
} }
// NewShowFromPolochon returns an ShowDB from a polochon Show // NewShowFromPolochon returns an showDB from a polochon Show
func NewShowFromPolochon(s *polochon.Show) *ShowDB { func NewShowFromPolochon(s *polochon.Show) *showDB {
sDB := ShowDB{ sDB := showDB{
ImdbID: s.ImdbID, ImdbID: s.ImdbID,
TvdbID: s.TvdbID, TvdbID: s.TvdbID,
Title: s.Title, Title: s.Title,
@ -78,7 +78,7 @@ func NewShowFromPolochon(s *polochon.Show) *ShowDB {
// GetShow fills a show from the DB // GetShow fills a show from the DB
func GetShow(db *sqlx.DB, pShow *polochon.Show) error { func GetShow(db *sqlx.DB, pShow *polochon.Show) error {
var err error var err error
var sDB ShowDB var sDB showDB
if pShow.ImdbID != "" { if pShow.ImdbID != "" {
err = db.QueryRowx(getShowQueryByImdbID, pShow.ImdbID).StructScan(&sDB) err = db.QueryRowx(getShowQueryByImdbID, pShow.ImdbID).StructScan(&sDB)
} else { } else {
@ -88,13 +88,13 @@ func GetShow(db *sqlx.DB, pShow *polochon.Show) error {
return err return err
} }
// Fill the show from the ShowDB // Fill the show from the showDB
FillShowFromDB(&sDB, pShow) FillShowFromDB(&sDB, pShow)
return nil return nil
} }
// FillShowFromDB returns a Show from a ShowDB extracted from the DB // FillShowFromDB returns a Show from a showDB extracted from the DB
func FillShowFromDB(sDB *ShowDB, pShow *polochon.Show) { func FillShowFromDB(sDB *showDB, pShow *polochon.Show) {
pShow.ImdbID = sDB.ImdbID pShow.ImdbID = sDB.ImdbID
pShow.Title = sDB.Title pShow.Title = sDB.Title
pShow.Rating = sDB.Rating pShow.Rating = sDB.Rating

View File

@ -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
}

View File

@ -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)
}

View File

@ -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")