diff --git a/internal/bd/filmsrepo.go b/internal/bd/filmsrepo.go index 219b13a..3d35a0f 100644 --- a/internal/bd/filmsrepo.go +++ b/internal/bd/filmsrepo.go @@ -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 } diff --git a/internal/restserver/filmhandle.go b/internal/restserver/filmhandle.go index 30d24d5..e8e2db3 100644 --- a/internal/restserver/filmhandle.go +++ b/internal/restserver/filmhandle.go @@ -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)) }