Add pagination and add Hendle permision CORS
parent
148603f4f3
commit
931153b0da
|
@ -3,6 +3,7 @@ package bd
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"git.ukamnya.ru/stulyaganov/RestApi/internal/bd/model"
|
"git.ukamnya.ru/stulyaganov/RestApi/internal/bd/model"
|
||||||
)
|
)
|
||||||
|
@ -131,9 +132,12 @@ func (f *Filmsrepo) SortByGanres(name string) (*[]model.Films, error) {
|
||||||
return &films, nil
|
return &films, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Filmsrepo) Pagination(offcet string) (*[]model.Films, error) {
|
func (f *Filmsrepo) Pagination(page string) (*[]model.Films, error) {
|
||||||
var buffs []model.Films
|
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 ORDER BY year desc LIMIT 32 OFFSET "+offcet)
|
pages, _ := strconv.Atoi(page)
|
||||||
|
limit := 32
|
||||||
|
offcet := limit * (pages - 1)
|
||||||
|
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, created DESC LIMIT 32 OFFSET $1", offcet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,6 +103,8 @@ func (r *RestServer) HendleFindID() http.HandlerFunc {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.logger.Errorln(err)
|
r.logger.Errorln(err)
|
||||||
}
|
}
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||||
io.WriteString(w, string(jsonData))
|
io.WriteString(w, string(jsonData))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,6 +120,8 @@ func (r *RestServer) HendlePagination() http.HandlerFunc {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.logger.Errorln(err)
|
r.logger.Errorln(err)
|
||||||
}
|
}
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||||
io.WriteString(w, string(jsondata))
|
io.WriteString(w, string(jsondata))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue