add user's save item, and fix pagination count last page
This commit is contained in:
1 parent
05b8d55d0e
commit
5508d54891
13 files changed
+238
-12
No files matched your search
@@ -90,6 +90,29 @@ func (f *Filmsrepo) FindById(id string) (*model.Films, error) {
|
||||
return &buff, nil
|
||||
}
|
||||
|
||||
func (s *Filmsrepo) FindByIdArray(id []int) (*[]model.Siries, error) {
|
||||
var buffs []model.Siries
|
||||
var stringId []string
|
||||
for _, i := range id {
|
||||
stringId = append(stringId, strconv.Itoa(i))
|
||||
}
|
||||
query := fmt.Sprint("SELECT id, Ru_title, PosterUrlPreview, Countries, Genres, Year FROM films WHERE Id = ANY($1)")
|
||||
rows, err := s.db.db.Query(context.Background(), query, stringId)
|
||||
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.PosterUrlPreview, &buff.Countries, &buff.Genres, &buff.Year)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
buffs = append(buffs, buff)
|
||||
}
|
||||
return &buffs, nil
|
||||
}
|
||||
|
||||
func (f *Filmsrepo) FindByName(name string) (*[]model.Films, error) {
|
||||
var films []model.Films
|
||||
rows, err := f.db.db.Query(context.Background(), "SELECT id, Ru_title, year, posterurl, content_type FROM films WHERE ru_title LIKE $1;", "%"+name+"%")
|
||||
|
||||
@@ -16,3 +16,9 @@ type UserData struct {
|
||||
PermisionLVL int
|
||||
AccesToken string
|
||||
}
|
||||
|
||||
type SaveItemUpdate struct {
|
||||
Login string `json:"login"`
|
||||
SaveItemFilms int `json:"SaveItemFilms"`
|
||||
SaveItemSiries int `json:"SaveItemSiries"`
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package bd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"git.ukamnya.ru/stulyaganov/RestApiv2/internal/bd/model"
|
||||
@@ -27,6 +28,29 @@ func (s *Siriesrepo) FindById(id string) (*model.Siries, error) {
|
||||
return &buff, nil
|
||||
}
|
||||
|
||||
func (s *Siriesrepo) FindByIdArray(id []int) (*[]model.Siries, error) {
|
||||
var buffs []model.Siries
|
||||
var stringId []string
|
||||
for _, i := range id {
|
||||
stringId = append(stringId, strconv.Itoa(i))
|
||||
}
|
||||
query := fmt.Sprint("SELECT id, Ru_title, PosterUrlPreview, Countries, Genres, Year FROM siries WHERE Id = ANY($1)")
|
||||
rows, err := s.db.db.Query(context.Background(), query, stringId)
|
||||
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.PosterUrlPreview, &buff.Countries, &buff.Genres, &buff.Year)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
buffs = append(buffs, buff)
|
||||
}
|
||||
return &buffs, nil
|
||||
}
|
||||
|
||||
func (s *Siriesrepo) Pagination(page string) (*[]model.Siries, error) {
|
||||
var buffs []model.Siries
|
||||
pages, _ := strconv.Atoi(page)
|
||||
|
||||
@@ -20,6 +20,44 @@ func (u *Userrepo) Create(user *model.User) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *Userrepo) AddSaveFilmsItem(userLogin string, films int) error {
|
||||
sql := fmt.Sprint("UPDATE users SET SaveItemFilms = array_append(SaveItemFilms, $1) WHERE login = $2")
|
||||
_, err := u.db.db.Exec(context.Background(), sql, films, userLogin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *Userrepo) AddSaveSiriesItem(userLogin string, siries int) error {
|
||||
sql := fmt.Sprint("UPDATE users SET SaveItemSiries = array_append(SaveItemSiries, $1) WHERE login = $2")
|
||||
_, err := u.db.db.Exec(context.Background(), sql, siries, userLogin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *Userrepo) GetSaveFilmsItem(userLogin string) ([]int, error) {
|
||||
var films []int
|
||||
sql := fmt.Sprint("SELECT SaveItemFilms FROM users WHERE login = $1")
|
||||
err := u.db.db.QueryRow(context.Background(), sql, userLogin).Scan(&films)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return films, err
|
||||
}
|
||||
|
||||
func (u *Userrepo) GetSaveSiriesItem(userLogin string) ([]int, error) {
|
||||
var siries []int
|
||||
sql := fmt.Sprint("SELECT SaveItemSiries FROM users WHERE login = $1")
|
||||
err := u.db.db.QueryRow(context.Background(), sql, userLogin).Scan(&siries)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return siries, err
|
||||
}
|
||||
|
||||
func (u *Userrepo) FindById(id string) (*model.User, error) {
|
||||
var user model.User
|
||||
query := fmt.Sprintf("SELECT * FROM users WHERE Id = %s;", id)
|
||||
|
||||
Reference in new issue
Block a user