From 148603f4f399d1aee799fea4eb6b7165aff1d950 Mon Sep 17 00:00:00 2001 From: Shuhrat Tulyaganov Date: Wed, 15 Mar 2023 22:44:31 +0300 Subject: [PATCH] fix struct pointer --- internal/bd/filmrepo_test.go | 2 +- internal/bd/filmsrepo.go | 16 +++++++------- internal/bd/model/films.go | 33 ++++++++++++++-------------- migrates/20221213130458_films.up.sql | 12 ++++++++++ 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/internal/bd/filmrepo_test.go b/internal/bd/filmrepo_test.go index 6fe9493..540e332 100644 --- a/internal/bd/filmrepo_test.go +++ b/internal/bd/filmrepo_test.go @@ -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) diff --git a/internal/bd/filmsrepo.go b/internal/bd/filmsrepo.go index d0bafcd..219b13a 100644 --- a/internal/bd/filmsrepo.go +++ b/internal/bd/filmsrepo.go @@ -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 } diff --git a/internal/bd/model/films.go b/internal/bd/model/films.go index a2ccd99..f7e023c 100644 --- a/internal/bd/model/films.go +++ b/internal/bd/model/films.go @@ -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 } diff --git a/migrates/20221213130458_films.up.sql b/migrates/20221213130458_films.up.sql index fc950a4..a172a74 100644 --- a/migrates/20221213130458_films.up.sql +++ b/migrates/20221213130458_films.up.sql @@ -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) +);