fix struct pointer

main
Shuhrat Tulyaganov 2023-03-15 22:44:31 +03:00
parent 06837e86b8
commit 148603f4f3
4 changed files with 38 additions and 25 deletions

View File

@ -14,7 +14,7 @@ func TestFilmRepo_Create(t *testing.T) {
defer teardown("films")
u, err := s.Films().Create(&model.Films{
Id: 11,
Ru_title: "fasfa",
Ru_title: nil,
})
assert.NoError(t, err)
assert.NotNil(t, u)

View File

@ -27,7 +27,7 @@ func FindDyId(id int) (*model.Films, error) {
func (f *Filmsrepo) FindByAll() (*[]model.Films, error) {
var buffs []model.Films
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")
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, Created FROM films")
if err != nil {
return nil, err
}
@ -39,7 +39,7 @@ func (f *Filmsrepo) FindByAll() (*[]model.Films, error) {
&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.RatingKinopoiskVoteCount, &buff.Created)
if err != nil {
return nil, err
}
@ -78,7 +78,7 @@ func (f *Filmsrepo) FindById(id string) (*model.Films, error) {
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)
&buff.RatingKinopoiskVoteCount, &buff.Created, &buff.Media)
}
@ -102,7 +102,7 @@ func (f *Filmsrepo) FindByName(name string) (*[]model.Films, error) {
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)
&film.RatingKinopoiskVoteCount, &film.Created, &film.Media)
if err != nil {
return nil, err
}
@ -133,7 +133,7 @@ func (f *Filmsrepo) SortByGanres(name string) (*[]model.Films, error) {
func (f *Filmsrepo) Pagination(offcet string) (*[]model.Films, error) {
var buffs []model.Films
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 ORDER BY year desc LIMIT 32 OFFSET "+offcet)
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, Created FROM films ORDER BY year desc LIMIT 32 OFFSET "+offcet)
if err != nil {
return nil, err
}
@ -145,7 +145,7 @@ func (f *Filmsrepo) Pagination(offcet string) (*[]model.Films, error) {
&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.RatingKinopoiskVoteCount, &buff.Created)
if err != nil {
return nil, err
}
@ -160,7 +160,7 @@ func (f *Filmsrepo) Pagination(offcet string) (*[]model.Films, error) {
func (f *Filmsrepo) LastItem() (*[]model.Films, error) {
var buffs []model.Films
rows, err := f.db.db.Query(context.Background(), "SELECT id, ru_title, orig_title, posterurl, posterurlpreview, countries, genres, year FROM films ORDER BY year desc LIMIT 8")
rows, err := f.db.db.Query(context.Background(), "SELECT id, ru_title, orig_title, posterurl, posterurlpreview, countries, genres, year, created FROM films ORDER BY year desc, created DESC LIMIT 8")
if err != nil {
return nil, err
}
@ -169,7 +169,7 @@ func (f *Filmsrepo) LastItem() (*[]model.Films, error) {
for rows.Next() {
var buff model.Films
err = rows.Scan(
&buff.Id, &buff.Ru_title, &buff.Orig_title, &buff.PosterUrl, &buff.PosterUrlPreview, &buff.Countries, &buff.Genres, &buff.Year)
&buff.Id, &buff.Ru_title, &buff.Orig_title, &buff.PosterUrl, &buff.PosterUrlPreview, &buff.Countries, &buff.Genres, &buff.Year, &buff.Created)
if err != nil {
return nil, err
}

View File

@ -2,20 +2,21 @@ package model
type Films struct {
Id int
Ru_title string
Orig_title string
Imdb_id string
Kinopoisk_id string
PosterUrl string
PosterUrlPreview string
Countries interface{}
Genres interface{}
Year int
Description string
RatingKinopoisk int
RatingImdb int
Iframe_src string
RatingImdbVoteCount int
RatingKinopoiskVoteCount int
Media interface{}
Ru_title *string
Orig_title *string
Imdb_id *string
Kinopoisk_id *int
PosterUrl *string
PosterUrlPreview *string
Countries *any
Genres *any
Year *int
Description *string
RatingKinopoisk *int
RatingImdb *int
Iframe_src *string
RatingImdbVoteCount *int
RatingKinopoiskVoteCount *int
Created *string
Media *any
}

View File

@ -16,6 +16,18 @@ CREATE TABLE films (
iframe_src VARCHAR(2000),
ratingImdbVoteCount INTEGER,
ratingKinopoiskVoteCount INTEGER,
created VARCHAR(1500),
media JSON,
PRIMARY KEY(id)
);
CREATE TABLE users (
id INTEGER NOT NULL,
login VARCHAR(25) not NULL,
email VARCHAR(255) NOT NULL,
password VARCHAR(2500) NOT NULL,
avatar_url VARCHAR(2500),
token VARCHAR(2500) NOT NULL,
permisionLVL INTEGER NOT NULL,
PRIMARY KEY(id)
);