Add pagination and add Hendle permision CORS

main
Shuhrat Tulyaganov 2023-03-30 19:04:46 +03:00
parent 148603f4f3
commit 931153b0da
2 changed files with 10 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package bd
import (
"context"
"fmt"
"strconv"
"git.ukamnya.ru/stulyaganov/RestApi/internal/bd/model"
)
@ -131,9 +132,12 @@ func (f *Filmsrepo) SortByGanres(name string) (*[]model.Films, error) {
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
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 {
return nil, err
}

View File

@ -103,6 +103,8 @@ func (r *RestServer) HendleFindID() http.HandlerFunc {
if err != nil {
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))
}
}
@ -118,6 +120,8 @@ func (r *RestServer) HendlePagination() http.HandlerFunc {
if err != nil {
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))
}