2020-03-10 03:28:15 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/stashapp/stash/pkg/models"
|
|
|
|
)
|
|
|
|
|
2021-01-18 01:23:20 +00:00
|
|
|
func (r *queryResolver) FindMovie(ctx context.Context, id string) (ret *models.Movie, err error) {
|
|
|
|
idInt, err := strconv.Atoi(id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := r.withReadTxn(ctx, func(repo models.ReaderRepository) error {
|
|
|
|
ret, err = repo.Movie().Find(idInt)
|
|
|
|
return err
|
|
|
|
}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret, nil
|
2020-03-10 03:28:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 01:23:20 +00:00
|
|
|
func (r *queryResolver) FindMovies(ctx context.Context, movieFilter *models.MovieFilterType, filter *models.FindFilterType) (ret *models.FindMoviesResultType, err error) {
|
|
|
|
if err := r.withReadTxn(ctx, func(repo models.ReaderRepository) error {
|
|
|
|
movies, total, err := repo.Movie().Query(movieFilter, filter)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = &models.FindMoviesResultType{
|
|
|
|
Count: total,
|
|
|
|
Movies: movies,
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret, nil
|
2020-03-10 03:28:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 01:23:20 +00:00
|
|
|
func (r *queryResolver) AllMovies(ctx context.Context) (ret []*models.Movie, err error) {
|
|
|
|
if err := r.withReadTxn(ctx, func(repo models.ReaderRepository) error {
|
|
|
|
ret, err = repo.Movie().All()
|
|
|
|
return err
|
|
|
|
}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret, nil
|
2020-03-10 03:28:15 +00:00
|
|
|
}
|