ch9.6
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"gitea.local.lab/Lbenedar/greenlight/internal/validator"
|
||||
@@ -135,12 +136,12 @@ func (m MovieModel) Delete(id int64) error {
|
||||
}
|
||||
|
||||
func (m MovieModel) GetAll(title string, genres []string, filter Filters) ([]*Movie, error) {
|
||||
query := `
|
||||
query := fmt.Sprintf(`
|
||||
SELECT id, created_at, title, year, runtime, genres, version
|
||||
FROM movies
|
||||
WHERE (to_tsvector('simple', title) @@ plainto_tsquery('simple', $1) OR $1 = '')
|
||||
AND (genres @> $2 OR $2 = '{}')
|
||||
ORDER BY id`
|
||||
ORDER BY %s %s, id ASC`, filter.sortColumn(), filter.sortDirection())
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
|
||||
Reference in New Issue
Block a user