2022-12-13 19:24:42 +03:00
|
|
|
package bd
|
|
|
|
|
|
|
|
import (
|
2022-12-31 01:43:30 +03:00
|
|
|
"context"
|
2023-01-07 14:19:53 +03:00
|
|
|
"fmt"
|
2022-12-31 01:43:30 +03:00
|
|
|
|
2022-12-13 19:24:42 +03:00
|
|
|
"git.ukamnya.ru/stulyaganov/RestApi/internal/bd/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Filmsrepo struct {
|
|
|
|
db Bd
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Filmsrepo) Create(m *model.Films) (*model.Films, error) {
|
2022-12-31 01:43:30 +03:00
|
|
|
if err := f.db.db.QueryRow(context.Background(),
|
2022-12-13 19:24:42 +03:00
|
|
|
"INSERT INTO films (id, ru_title, orig_title) VALUES($1, $2, $3) RETURNING id",
|
|
|
|
m.Id, m.Ru_title, m.Orig_title).Scan(&m.Id); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return m, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func FindDyId(id int) (*model.Films, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2023-01-05 17:21:03 +03:00
|
|
|
|
|
|
|
func (f *Filmsrepo) FindByAll() (*[]model.Films, error) {
|
|
|
|
var buffs []model.Films
|
2023-01-07 14:19:53 +03:00
|
|
|
rows, err := f.db.db.Query(context.Background(), "SELECT Id, Ru_title, Orig_title, Imdb_id, Kinopoisk_id, PosterUrl, PosterUrlPreview, Countries, Genres, Year, Description, RatingKinopoisk, RatingImdb, Iframe_src, RatingImdbVoteCount, RatingKinopoiskVoteCount FROM films")
|
2023-01-05 17:21:03 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
var buff model.Films
|
|
|
|
err = 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,
|
|
|
|
&buff.Description, &buff.RatingKinopoisk, &buff.RatingImdb, &buff.Iframe_src, &buff.RatingImdbVoteCount,
|
2023-01-07 14:19:53 +03:00
|
|
|
&buff.RatingKinopoiskVoteCount)
|
2023-01-05 17:21:03 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
buffs = append(buffs, buff)
|
|
|
|
}
|
|
|
|
err = rows.Err()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &buffs, nil
|
|
|
|
}
|
2023-01-07 14:19:53 +03:00
|
|
|
|
|
|
|
func (f *Filmsrepo) FindById(id string) (*model.Films, error) {
|
|
|
|
query := fmt.Sprintf("SELECT * FROM films WHERE Id = %s;", id)
|
|
|
|
var buff model.Films
|
|
|
|
rows, err := f.db.db.Query(context.Background(), query)
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
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,
|
|
|
|
&buff.Description, &buff.RatingKinopoisk, &buff.RatingImdb, &buff.Iframe_src, &buff.RatingImdbVoteCount,
|
|
|
|
&buff.RatingKinopoiskVoteCount, &buff.Media)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if rows.Err() != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &buff, nil
|
|
|
|
}
|