add register user
This commit is contained in:
1 parent
7dfe981b53
commit
3026f89f2e
16 files changed
+275
-67
No files matched your search
@@ -92,7 +92,7 @@ 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 %$1%;", name)
|
||||
rows, err := f.db.db.Query(context.Background(), "SELECT id, Ru_title, year, posterurl, content_type FROM films WHERE ru_title LIKE $1;", "%"+name+"%")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -100,10 +100,7 @@ func (f *Filmsrepo) FindByName(name string) (*[]model.Films, error) {
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var film model.Films
|
||||
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.Created, &film.Media)
|
||||
err = rows.Scan(&film.Id, &film.Ru_title, &film.Year, &film.PosterUrl, &film.Contenttype)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -2,10 +2,9 @@ package model
|
||||
|
||||
type User struct {
|
||||
Id int
|
||||
Login string
|
||||
Email string
|
||||
Password string
|
||||
Login string `json:"login"`
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
Avatar_Url string
|
||||
Token string
|
||||
PermisionLVL int
|
||||
}
|
||||
@@ -125,17 +125,14 @@ func (s *Siriesrepo) FindByAll() (*[]model.Siries, error) {
|
||||
|
||||
func (s *Siriesrepo) FindByName(name string) (*[]model.Siries, error) {
|
||||
var buffs []model.Siries
|
||||
rows, err := s.db.db.Query(context.Background(), "SELECT * FROM siries WHERE ru_title LIKE $1", "%"+name+"%")
|
||||
rows, err := s.db.db.Query(context.Background(), "SELECT id, Ru_title, year, posterurl, content_type FROM siries WHERE ru_title LIKE $1;", "%"+name+"%")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var buff model.Siries
|
||||
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)
|
||||
err = rows.Scan(&buff.Id, &buff.Ru_title, &buff.Year, &buff.PosterUrl, &buff.Contenttype)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+35
-7
@@ -11,27 +11,55 @@ type Userrepo struct {
|
||||
db Bd
|
||||
}
|
||||
|
||||
func (u *Userrepo) Create(user *model.User) (*model.User, error) {
|
||||
err := u.db.db.QueryRow(context.Background(),
|
||||
"INSERT INTO users (id, login, email, password, avatar_url, token, permisionlvl) VALUES($1, $2, $3, $4, $5, $6, $7) RETURNING id, permisionlvl", user.Id, user.Login, user.Email, user.Password, user.Avatar_Url, user.Token, user.PermisionLVL).
|
||||
Scan(&user.Id, &user.PermisionLVL)
|
||||
func (u *Userrepo) Create(user *model.User) error {
|
||||
_, err := u.db.db.Exec(context.Background(),
|
||||
"INSERT INTO users (login, email, password, permisionlvl) VALUES($1, $2, $3, $4)", user.Login, user.Email, user.Password, user.PermisionLVL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
return user, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *Userrepo) FindById(id string) (*model.User, error) {
|
||||
var user model.User
|
||||
query := fmt.Sprintf("SELECT * FROM users WHERE Id = %s;", id)
|
||||
err := u.db.db.QueryRow(context.Background(), query).
|
||||
Scan(user.Id, user.Login, user.Email, user.Password, user.Avatar_Url, user.Token, user.PermisionLVL)
|
||||
Scan(user.Id, user.Login, user.Email, user.Password, user.Avatar_Url, user.PermisionLVL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
func (u *Userrepo) FindByLogin(login string) (*model.User, error) {
|
||||
var user model.User
|
||||
rows, err := u.db.db.Query(context.Background(), "SELECT login FROM users WHERE login = $1", login)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
err = rows.Scan(&user.Login)
|
||||
}
|
||||
return &user, nil
|
||||
|
||||
}
|
||||
|
||||
func (u *Userrepo) FindByEmail(email string) (*model.User, error) {
|
||||
var user model.User
|
||||
rows, err := u.db.db.Query(context.Background(), "SELECT email FROM users WHERE email = $1", email)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
err = rows.Scan(&user.Email)
|
||||
}
|
||||
return &user, nil
|
||||
|
||||
}
|
||||
|
||||
func (u *Userrepo) FindByAll() (*model.User, error) {
|
||||
return nil, nil
|
||||
}
|
||||
Reference in new issue
Block a user