Structs from db doesn't need to be exposed

This commit is contained in:
Lucas BEE 2017-03-22 10:02:59 +00:00
parent f68c2e7100
commit 7f7da8d097
7 changed files with 66 additions and 66 deletions

View File

@ -25,8 +25,8 @@ const (
FROM episode_torrents WHERE imdb_id=$1 AND season=$2 AND episode=$3;`
)
// EpisodeTorrentDB represents the EpisodeTorrent in the DB
type EpisodeTorrentDB struct {
// episodeTorrentDB represents the EpisodeTorrent in the DB
type episodeTorrentDB struct {
ID string `db:"id"`
ImdbID string `db:"imdb_id"`
URL string `db:"url"`
@ -43,7 +43,7 @@ type EpisodeTorrentDB struct {
// NewTorrentFromEpisodeTorrentDB returns a polochon.Torrent from an
// episodeTorrentDB
func NewTorrentFromEpisodeTorrentDB(eDB *EpisodeTorrentDB) *polochon.Torrent {
func NewTorrentFromEpisodeTorrentDB(eDB *episodeTorrentDB) *polochon.Torrent {
q, _ := polochon.StringToQuality(eDB.Quality)
return &polochon.Torrent{
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
func NewEpisodeTorrentDB(t *polochon.Torrent, imdbID string, season, episode int) *EpisodeTorrentDB {
return &EpisodeTorrentDB{
func NewEpisodeTorrentDB(t *polochon.Torrent, imdbID string, season, episode int) *episodeTorrentDB {
return &episodeTorrentDB{
ImdbID: imdbID,
Season: season,
Episode: episode,
@ -73,7 +73,7 @@ func NewEpisodeTorrentDB(t *polochon.Torrent, imdbID string, season, episode int
// GetEpisodeTorrents returns show episodes torrents from database
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)
if err != nil {
return nil, err

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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