From 7dfe981b534cdf938adf79d9ef93113891d04aba Mon Sep 17 00:00:00 2001 From: Shuhrat Tulyaganov Date: Fri, 31 Mar 2023 20:08:38 +0300 Subject: [PATCH] Fix project pakage and fix struct json --- build/postgres/docker-compose_test_db_init.sql | 4 ++-- cmd/rest/main.go | 2 +- configs/restServer/config.yaml | 2 +- docker-compose.yaml | 10 +++++----- go.mod | 2 +- internal/bd/config.go | 4 +++- internal/bd/filmrepo_test.go | 4 ++-- internal/bd/filmsrepo.go | 8 ++++---- internal/bd/model/films.go | 2 ++ internal/bd/model/siries.go | 2 ++ internal/bd/siriesrepo.go | 4 ++-- internal/bd/userrepo.go | 2 +- internal/restserver/config.go | 2 +- internal/restserver/filmhandle.go | 2 +- internal/restserver/restserver.go | 2 +- internal/restserver/resultStruct/films.go | 2 +- internal/restserver/resultStruct/siries.go | 2 +- internal/restserver/siriesheandle.go | 2 +- internal/restserver/userHendle.go | 2 +- 19 files changed, 33 insertions(+), 27 deletions(-) diff --git a/build/postgres/docker-compose_test_db_init.sql b/build/postgres/docker-compose_test_db_init.sql index 21dc110..f00ad6e 100644 --- a/build/postgres/docker-compose_test_db_init.sql +++ b/build/postgres/docker-compose_test_db_init.sql @@ -1,2 +1,2 @@ -CREATE USER test11 WITH PASSWORD 'test' CREATEDB; -CREATE DATABASE test11 with owner = test11 ENCODING = 'UTF8' LC_COLLATE = 'en_US.utf8' LC_CTYPE = 'en_US.utf8' TABLESPACE = pg_default CONNECTION LIMIT = -1; +CREATE USER test WITH PASSWORD 'test' CREATEDB; +CREATE DATABASE test with owner = test ENCODING = 'UTF8' LC_COLLATE = 'en_US.utf8' LC_CTYPE = 'en_US.utf8' TABLESPACE = pg_default CONNECTION LIMIT = -1; diff --git a/cmd/rest/main.go b/cmd/rest/main.go index db90a71..20e78d5 100644 --- a/cmd/rest/main.go +++ b/cmd/rest/main.go @@ -4,7 +4,7 @@ import ( "flag" "log" - "git.ukamnya.ru/stulyaganov/RestApi/internal/restserver" + "git.ukamnya.ru/stulyaganov/RestApiv2/internal/restserver" "github.com/joho/godotenv" ) diff --git a/configs/restServer/config.yaml b/configs/restServer/config.yaml index 3184bda..425f311 100644 --- a/configs/restServer/config.yaml +++ b/configs/restServer/config.yaml @@ -7,4 +7,4 @@ log_level: "debug" # db DB: - baseurlbd: "host=localhost user=admin password=root dbname=postgres sslmode=disable" \ No newline at end of file + baseurlbd: "host=localhost:7000 user=films password=5429593sS dbname=postgres sslmode=disable" \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index d82dc6d..e6d7f2d 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,11 +2,11 @@ version: '3.7' services: database: - container_name: postgres + container_name: databaseFilms ports: - - "5432:5432" + - "7000:5432" environment: - - POSTGRES_PASSWORD=root - - POSTGRES_USER=admin + - POSTGRES_PASSWORD=5429593sS + - POSTGRES_USER=films build: ./build/postgres/ - \ No newline at end of file + diff --git a/go.mod b/go.mod index 82afc59..1a73900 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module git.ukamnya.ru/stulyaganov/RestApi +module git.ukamnya.ru/stulyaganov/RestApiv2 go 1.19 diff --git a/internal/bd/config.go b/internal/bd/config.go index caa307a..651fcdc 100644 --- a/internal/bd/config.go +++ b/internal/bd/config.go @@ -1,11 +1,13 @@ package bd +import "os" + type ConfigBD struct { BaseUrlBd string `yaml:"baseurlbd"` } func NewConfig() *ConfigBD { return &ConfigBD{ - BaseUrlBd: "host=localhost user=admin password=root dbname=postgres sslmode=disable", + BaseUrlBd: os.Getenv("DATABASE_URL"), } } diff --git a/internal/bd/filmrepo_test.go b/internal/bd/filmrepo_test.go index 540e332..b181889 100644 --- a/internal/bd/filmrepo_test.go +++ b/internal/bd/filmrepo_test.go @@ -3,8 +3,8 @@ package bd_test import ( "testing" - "git.ukamnya.ru/stulyaganov/RestApi/internal/bd" - "git.ukamnya.ru/stulyaganov/RestApi/internal/bd/model" + "git.ukamnya.ru/stulyaganov/RestApiv2/internal/bd" + "git.ukamnya.ru/stulyaganov/RestApiv2/internal/bd/model" "github.com/stretchr/testify/assert" ) diff --git a/internal/bd/filmsrepo.go b/internal/bd/filmsrepo.go index b0541e5..5970d55 100644 --- a/internal/bd/filmsrepo.go +++ b/internal/bd/filmsrepo.go @@ -5,7 +5,7 @@ import ( "fmt" "strconv" - "git.ukamnya.ru/stulyaganov/RestApi/internal/bd/model" + "git.ukamnya.ru/stulyaganov/RestApiv2/internal/bd/model" ) type Filmsrepo struct { @@ -28,7 +28,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, Created 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, content_type, ratingagelimits FROM films") if err != nil { return nil, err } @@ -40,7 +40,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.Created) + &buff.RatingKinopoiskVoteCount, &buff.Created, &buff.Contenttype, &buff.Ratingagelimits) if err != nil { return nil, err } @@ -79,7 +79,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.Created, &buff.Media) + &buff.RatingKinopoiskVoteCount, &buff.Created, &buff.Contenttype, &buff.Ratingagelimits, &buff.Media) } diff --git a/internal/bd/model/films.go b/internal/bd/model/films.go index f7e023c..449d90c 100644 --- a/internal/bd/model/films.go +++ b/internal/bd/model/films.go @@ -18,5 +18,7 @@ type Films struct { RatingImdbVoteCount *int RatingKinopoiskVoteCount *int Created *string + Contenttype *string + Ratingagelimits *string Media *any } diff --git a/internal/bd/model/siries.go b/internal/bd/model/siries.go index 46fccaa..519b353 100644 --- a/internal/bd/model/siries.go +++ b/internal/bd/model/siries.go @@ -18,6 +18,8 @@ type Siries struct { RatingImdbVoteCount *int RatingKinopoiskVoteCount *int Created *string + Contenttype *string + Ratingagelimits *string Translations *any Episodes *any } diff --git a/internal/bd/siriesrepo.go b/internal/bd/siriesrepo.go index ec05456..4f40e6d 100644 --- a/internal/bd/siriesrepo.go +++ b/internal/bd/siriesrepo.go @@ -4,7 +4,7 @@ import ( "context" "strconv" - "git.ukamnya.ru/stulyaganov/RestApi/internal/bd/model" + "git.ukamnya.ru/stulyaganov/RestApiv2/internal/bd/model" ) type Siriesrepo struct { @@ -22,7 +22,7 @@ func (s *Siriesrepo) FindById(id string) (*model.Siries, error) { 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, - &buff.RatingKinopoiskVoteCount, &buff.Created, &buff.Translations, &buff.Episodes) + &buff.RatingKinopoiskVoteCount, &buff.Created, &buff.Contenttype, &buff.Ratingagelimits, &buff.Translations, &buff.Episodes) } return &buff, nil } diff --git a/internal/bd/userrepo.go b/internal/bd/userrepo.go index 3e3fd6b..b8ac9de 100644 --- a/internal/bd/userrepo.go +++ b/internal/bd/userrepo.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "git.ukamnya.ru/stulyaganov/RestApi/internal/bd/model" + "git.ukamnya.ru/stulyaganov/RestApiv2/internal/bd/model" ) type Userrepo struct { diff --git a/internal/restserver/config.go b/internal/restserver/config.go index cdc2a0e..74c1952 100644 --- a/internal/restserver/config.go +++ b/internal/restserver/config.go @@ -3,7 +3,7 @@ package restserver import ( "io/ioutil" - "git.ukamnya.ru/stulyaganov/RestApi/internal/bd" + "git.ukamnya.ru/stulyaganov/RestApiv2/internal/bd" "gopkg.in/yaml.v3" ) diff --git a/internal/restserver/filmhandle.go b/internal/restserver/filmhandle.go index 940b937..230f987 100644 --- a/internal/restserver/filmhandle.go +++ b/internal/restserver/filmhandle.go @@ -7,7 +7,7 @@ import ( "net/http" "strconv" - resultstruct "git.ukamnya.ru/stulyaganov/RestApi/internal/restserver/resultStruct" + resultstruct "git.ukamnya.ru/stulyaganov/RestApiv2/internal/restserver/resultStruct" "github.com/gorilla/mux" ) diff --git a/internal/restserver/restserver.go b/internal/restserver/restserver.go index 6416a71..f8676af 100644 --- a/internal/restserver/restserver.go +++ b/internal/restserver/restserver.go @@ -3,7 +3,7 @@ package restserver import ( "net/http" - "git.ukamnya.ru/stulyaganov/RestApi/internal/bd" + "git.ukamnya.ru/stulyaganov/RestApiv2/internal/bd" "github.com/gorilla/mux" "github.com/sirupsen/logrus" ) diff --git a/internal/restserver/resultStruct/films.go b/internal/restserver/resultStruct/films.go index f67a3a4..b71caee 100644 --- a/internal/restserver/resultStruct/films.go +++ b/internal/restserver/resultStruct/films.go @@ -1,6 +1,6 @@ package resultstruct -import "git.ukamnya.ru/stulyaganov/RestApi/internal/bd/model" +import "git.ukamnya.ru/stulyaganov/RestApiv2/internal/bd/model" type Films struct { Result bool diff --git a/internal/restserver/resultStruct/siries.go b/internal/restserver/resultStruct/siries.go index 5cc7fe3..7c81f29 100644 --- a/internal/restserver/resultStruct/siries.go +++ b/internal/restserver/resultStruct/siries.go @@ -1,6 +1,6 @@ package resultstruct -import "git.ukamnya.ru/stulyaganov/RestApi/internal/bd/model" +import "git.ukamnya.ru/stulyaganov/RestApiv2/internal/bd/model" type Siries struct { Result bool diff --git a/internal/restserver/siriesheandle.go b/internal/restserver/siriesheandle.go index 5925f9f..1a3d41e 100644 --- a/internal/restserver/siriesheandle.go +++ b/internal/restserver/siriesheandle.go @@ -7,7 +7,7 @@ import ( "net/http" "strconv" - resultstruct "git.ukamnya.ru/stulyaganov/RestApi/internal/restserver/resultStruct" + resultstruct "git.ukamnya.ru/stulyaganov/RestApiv2/internal/restserver/resultStruct" "github.com/gorilla/mux" ) diff --git a/internal/restserver/userHendle.go b/internal/restserver/userHendle.go index 45a16b1..76eeaf5 100644 --- a/internal/restserver/userHendle.go +++ b/internal/restserver/userHendle.go @@ -3,7 +3,7 @@ package restserver import ( "net/http" - "git.ukamnya.ru/stulyaganov/RestApi/internal/bd/model" + "git.ukamnya.ru/stulyaganov/RestApiv2/internal/bd/model" ) func (r *RestServer) configureRouterUser() {