This commit is contained in:
lbenedar
2026-03-18 17:47:26 +03:00
parent c4df79dffa
commit a309576cfb
2 changed files with 25 additions and 3 deletions

View File

@@ -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()