Add movie count to performer and studio card (#1760)

* Add movies and movie_count properties to Performer type

Extend the GraphQL API to allow getting the movies and movie count by
performer.

* Add movies count to performer card

* Add movies and movie_count properties to Studio type

Extend the GraphQL API to allow getting the movies and movie count by
studio.

* Add movies count to studio card
This commit is contained in:
gitgiggety
2021-09-27 03:31:49 +02:00
committed by GitHub
parent 62af723017
commit be94e52f21
15 changed files with 257 additions and 3 deletions

View File

@@ -308,3 +308,42 @@ func (qb *movieQueryBuilder) GetBackImage(movieID int) ([]byte, error) {
query := `SELECT back_image from movies_images WHERE movie_id = ?`
return getImage(qb.tx, query, movieID)
}
func (qb *movieQueryBuilder) FindByPerformerID(performerID int) ([]*models.Movie, error) {
query := `SELECT DISTINCT movies.*
FROM movies
INNER JOIN movies_scenes ON movies.id = movies_scenes.movie_id
INNER JOIN performers_scenes ON performers_scenes.scene_id = movies_scenes.scene_id
WHERE performers_scenes.performer_id = ?
`
args := []interface{}{performerID}
return qb.queryMovies(query, args)
}
func (qb *movieQueryBuilder) CountByPerformerID(performerID int) (int, error) {
query := `SELECT COUNT(DISTINCT movies_scenes.movie_id) AS count
FROM movies_scenes
INNER JOIN performers_scenes ON performers_scenes.scene_id = movies_scenes.scene_id
WHERE performers_scenes.performer_id = ?
`
args := []interface{}{performerID}
return qb.runCountQuery(query, args)
}
func (qb *movieQueryBuilder) FindByStudioID(studioID int) ([]*models.Movie, error) {
query := `SELECT movies.*
FROM movies
WHERE movies.studio_id = ?
`
args := []interface{}{studioID}
return qb.queryMovies(query, args)
}
func (qb *movieQueryBuilder) CountByStudioID(studioID int) (int, error) {
query := `SELECT COUNT(1) AS count
FROM movies
WHERE movies.studio_id = ?
`
args := []interface{}{studioID}
return qb.runCountQuery(query, args)
}