Add sort by genres
This commit is contained in:
1 parent
ed42b78cda
commit
f236dea4fd
3 files changed
+47
-3
No files matched your search
@@ -31,6 +31,7 @@ func (f *Filmsrepo) FindByAll() (*[]model.Films, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var buff model.Films
|
||||
@@ -57,7 +58,7 @@ func (f *Filmsrepo) GetCountFilms() (*int, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
rows.Scan(&count)
|
||||
}
|
||||
@@ -72,6 +73,7 @@ func (f *Filmsrepo) FindById(id string) (*model.Films, error) {
|
||||
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
rows.Scan(&buff.Id, &buff.Ru_title, &buff.Orig_title, &buff.Imdb_id, &buff.Kinopoisk_id,
|
||||
&buff.PosterUrl, &buff.PosterUrlPreview, &buff.Countries, &buff.Genres, &buff.Year,
|
||||
@@ -89,21 +91,42 @@ func (f *Filmsrepo) FindById(id string) (*model.Films, error) {
|
||||
|
||||
func (f *Filmsrepo) FindByName(name string) (*[]model.Films, error) {
|
||||
var films []model.Films
|
||||
rows, err := f.db.db.Query(context.Background(), "SELECT * FROM films WHERE ru_title LIKE '%"+name+"%'")
|
||||
rows, err := f.db.db.Query(context.Background(), "SELECT * FROM films WHERE ru_title LIKE $1;", "%"+name+"%")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var film model.Films
|
||||
rows.Scan(&film.Id, &film.Ru_title, &film.Orig_title, &film.Imdb_id, &film.Kinopoisk_id,
|
||||
err = rows.Scan(&film.Id, &film.Ru_title, &film.Orig_title, &film.Imdb_id, &film.Kinopoisk_id,
|
||||
&film.PosterUrl, &film.PosterUrlPreview, &film.Countries, &film.Genres, &film.Year,
|
||||
&film.Description, &film.RatingKinopoisk, &film.RatingImdb, &film.Iframe_src, &film.RatingImdbVoteCount,
|
||||
&film.RatingKinopoiskVoteCount, &film.Media)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
films = append(films, film)
|
||||
}
|
||||
|
||||
return &films, nil
|
||||
}
|
||||
|
||||
func (f *Filmsrepo) SortByGanres(name string) (*[]model.Films, error) {
|
||||
var films []model.Films
|
||||
rows, err := f.db.db.Query(context.Background(), "SELECT id, ru_title, posterurl FROM films WHERE genres::TEXT LIKE '%"+name+"%'")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var film model.Films
|
||||
rows.Scan(&film.Id, &film.Ru_title, &film.PosterUrl)
|
||||
if rows.Err() != nil {
|
||||
return nil, rows.Err()
|
||||
}
|
||||
films = append(films, film)
|
||||
}
|
||||
|
||||
return &films, nil
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package scanertable
|
||||
|
||||
type Scanertable interface {
|
||||
Scan() any
|
||||
}
|
||||
Reference in new issue
Block a user