shows

package
v0.0.0-...-a114734 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2017 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ShowStatusShowing = iota
	ShowStatusPaused
	ShowStatusFinished
	ShowStatusCanceled

	// ShowStatusEndOfList represent the total number of possible status
	ShowStatusEndOfList
)
View Source
const (
	EndpointAdd = iota
	EndpointSearch
	EndpointUpdate
	EndpointGetOne
	EndpointDelete
)

Contains the index of all Endpoints

View Source
const DefaultNbResultsPerPage = 20

DefaultNbResultsPerPage represents the default number of result per page

View Source
const ShowDateFormat = "January 02 2006"

Variables

View Source
var Endpoints = router.Endpoints{
	EndpointAdd: {
		Verb:    "POST",
		Path:    "/shows",
		Auth:    router.AdminAccess,
		Handler: Add,
		Params:  &AddParams{},
	},
	EndpointSearch: {
		Verb:    "GET",
		Path:    "/shows",
		Auth:    nil,
		Handler: Search,
		Params:  &SearchParams{},
	},
	EndpointUpdate: {
		Verb:    "PATCH",
		Path:    "/shows/{id}",
		Auth:    router.AdminAccess,
		Handler: Update,
		Params:  &UpdateParams{},
	},
	EndpointGetOne: {
		Verb:    "GET",
		Path:    "/shows/{id}",
		Auth:    nil,
		Handler: GetOne,
		Params:  &GetOneParams{},
	},
	EndpointDelete: {
		Verb:    "DELETE",
		Path:    "/shows/{id}",
		Auth:    router.AdminAccess,
		Handler: Delete,
		Params:  &DeleteParams{},
	},
}

Endpoints is a list of endpoints for this components

Functions

func Add

func Add(req *router.Request) error

Add is an API handler to

func Delete

func Delete(req *router.Request) error

Delete is an API handler to

func GetOne

func GetOne(req *router.Request) error

GetOne is an API handler to

func JoinShowSQL

func JoinShowSQL(prefix string) string

JoinShowSQL returns a string ready to be embed in a JOIN query

func Search(req *router.Request) error

Search is an API handler to search a show

func SetRoutes

func SetRoutes(r *mux.Router)

SetRoutes is used to set all the routes of the article

func ShowExists

func ShowExists(id string) (bool, error)

ShowExists checks if a show exists for a specific ID

func Update

func Update(req *router.Request) error

Update is an API handler to

Types

type AddParams

type AddParams struct {
	TMDbID int `from:"form" json:"tmdb_id" params:"required"`
}

AddParams represents the params needed by the AddShow handler

type DeleteParams

type DeleteParams struct {
	ID string `from:"url" json:"id" params:"uuid"`
}

DeleteParams represents the params needed by the GetOne handler

type GetOneParams

type GetOneParams struct {
	ID string `from:"url" json:"id" params:"uuid"`
}

GetOneParams represents the params needed by the GetOne handler

type Payload

type Payload struct {
	ID            string `json:"id"`
	Name          string `json:"name"`
	OriginalName  string `json:"original_name"`
	YearReleased  int    `json:"year_released"`
	Synopsis      string `json:"synopsis"`
	Poster        string `json:"poster"`
	Backdrop      string `json:"backdrop"`
	TMDbID        int    `json:"tmdb_id"`
	Status        int    `json:"status"`
	DayOfWeek     int    `json:"day_of_week"`
	ReturningDate string `json:"returning_date,omitempty"`
	Website       string `json:"website,omitempty"`
	Wikipedia     string `json:"wikipedia"`
	ExtraLink     string `json:"extra_link,omitempty"`
	IsOnNetflix   bool   `json:"is_on_netflix"`
}

Payload represents a TV Show returnable to the clients

func NewPayload

func NewPayload(m *Show) *Payload

NewPayload turn a Show model into a payload

type PayloadList

type PayloadList struct {
	Results []*Payload
}

PayloadList represents a list of TV Show that can be returned to the clients

func NewPayloadList

func NewPayloadList(list []*Show) *PayloadList

NewPayloadList turns a list of Shows into a payload

type SearchParams

type SearchParams struct {
	paginator.HandlerParams

	// FromProvider will query TMDb instead of the local database
	FromProvider bool `from:"query" json:"from_provider" default:"false"`

	// Name represents a string to use to look against the name field
	Name string `from:"query" json:"name" params:"trim"`

	// Status represents a list of status separated by "|"
	// ex ?status=0|1|3
	Status string `from:"query" json:"status" params:"trim"`

	// DayOfWeek filters the day of the week
	DayOfWeek *int `from:"query" json:"day_of_week"`

	// OrderBy represents a list of orders separated by "|"
	// ex ?order=-name|day_of_week will order by name desc and day of week asc
	// fields are: name, day_of_week, returning_date, created_at
	OrderBy string `from:"query" json:"order" params:"trim"`
}

SearchParams represents the params needed by the Search handler

type Show

type Show struct {
	ID            string       `db:"id"`
	CreatedAt     *db.Time     `db:"created_at"`
	UpdatedAt     *db.Time     `db:"updated_at"`
	DeletedAt     *db.Time     `db:"deleted_at"`
	Name          string       `db:"name"`
	OriginalName  string       `db:"original_name"`
	YearReleased  int          `db:"year_released"`
	Synopsis      string       `db:"synopsis"`
	PosterPath    string       `db:"poster_path"`
	BackdropPath  string       `db:"backdrop_path"`
	TMDbID        int          `db:"tmdb_id"`
	Status        int          `db:"status"`
	DayOfWeek     time.Weekday `db:"day_of_week"`
	ReturningDate string       `db:"returning_date"`
	Website       string       `db:"website"`
	Wikipedia     string       `db:"wikipedia"`
	ExtraLink     string       `db:"extra_link"`
	IsOnNetflix   bool         `db:"is_on_netflix"`
}

Show represents a TV show from the database

func GetShow

func GetShow(id string) (*Show, error)

GetShow finds and returns an active show by ID

func NewFromTMDb

func NewFromTMDb(show *tmdb.Show) (*Show, error)

NewFromTMDb turns a TMDb.Show into a Show

func NewListFromTMDb

func NewListFromTMDb(shows []*tmdb.Show) ([]*Show, error)

NewListFromTMDb turns a list of TMDb.Show into a list of Show

func (*Show) BackdropURL

func (m *Show) BackdropURL() string

BackdropURL returns a URL to the backdrop

func (*Show) Create

func (s *Show) Create() error

Create persists a show in the database

func (*Show) CreateQ

func (s *Show) CreateQ(q db.Queryable) error

Create persists a show in the database

func (*Show) Delete

func (s *Show) Delete() error

Delete soft delete a show.

func (*Show) DeleteQ

func (s *Show) DeleteQ(q db.Queryable) error

DeleteQ soft delete a show using a transaction

func (*Show) FullyDelete

func (s *Show) FullyDelete() error

FullyDelete removes a show from the database

func (*Show) FullyDeleteQ

func (s *Show) FullyDeleteQ(q db.Queryable) error

FullyDeleteQ removes a show from the database using a transaction

func (*Show) IsZero

func (s *Show) IsZero() bool

IsZero checks if the object is either nil or don't have an ID

func (*Show) PosterURL

func (m *Show) PosterURL() string

PosterURL returns a URL to the Poster

func (*Show) Save

func (s *Show) Save() error

Save creates or updates the show depending on the value of the id

func (*Show) SaveQ

func (s *Show) SaveQ(q db.Queryable) error

SaveQ creates or updates the article depending on the value of the id using a transaction

func (*Show) Update

func (s *Show) Update() error

Update updates most of the fields of a persisted show. Excluded fields are id, created_at, deleted_at, etc.

func (*Show) UpdateQ

func (s *Show) UpdateQ(q db.Queryable) error

Update updates most of the fields of a persisted show using a transaction Excluded fields are id, created_at, deleted_at, etc.

type UpdateParams

type UpdateParams struct {
	ID            string  `from:"url" json:"id" params:"uuid"`
	Name          string  `from:"form" json:"name" params:"trim"`
	OriginalName  string  `from:"form" json:"original_name" params:"trim"`
	Synopsis      string  `from:"form" json:"synopsis" params:"trim"`
	Status        *int    `from:"form" json:"status"`
	DayOfWeek     *int    `from:"form" json:"day_of_week"`
	ReturningDate *string `from:"form" json:"returning_date"`
	Website       *string `from:"form" json:"website" params:"trim"`
	Wikipedia     *string `from:"form" json:"wikipedia" params:"trim"`
	ExtraLink     *string `from:"form" json:"extra_link" params:"trim"`
	IsOnNetflix   *bool   `from:"form" json:"is_on_netflix" params:"trim"`
}

UpdateParams represents the params needed by the Update handler

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL