main
Last change
on this file since 0226942 was c02189f, checked in by Petar Partaloski <ppartaloski@…>, 2 years ago |
Added new core functionalities, fixed bugs and improved visual clarity
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[3c0f9a9] | 1 | package com.wediscussmovies.project.web;
|
---|
| 2 |
|
---|
| 3 | import com.wediscussmovies.project.model.Movie;
|
---|
| 4 | import com.wediscussmovies.project.service.MovieService;
|
---|
| 5 | import org.springframework.ui.Model;
|
---|
| 6 |
|
---|
| 7 | import java.util.ArrayList;
|
---|
| 8 | import java.util.List;
|
---|
| 9 |
|
---|
| 10 | public class PageFrontMovies {
|
---|
| 11 | public static List<Movie> getPagedMovies(String page, MovieService movieService, Model model){
|
---|
| 12 | List<Integer> movieIds = movieService.listAllIds();
|
---|
| 13 | List<Movie> movies = new ArrayList<>();
|
---|
| 14 | if(page==null || Integer.parseInt(page) <= 0)
|
---|
| 15 | page="1";
|
---|
| 16 | int pageToLoad = Integer.parseInt(page);
|
---|
| 17 |
|
---|
| 18 | int from = (pageToLoad-1)*12;
|
---|
| 19 | int to = pageToLoad*12;
|
---|
| 20 |
|
---|
| 21 | if (from>movieIds.size()){
|
---|
| 22 | page = "1";
|
---|
| 23 | pageToLoad = Integer.parseInt(page);
|
---|
| 24 | from = (pageToLoad-1)*12;
|
---|
| 25 | to = pageToLoad*12;
|
---|
| 26 | }
|
---|
| 27 | else if(to>movieIds.size()){
|
---|
| 28 | to = movieIds.size();
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | movieIds = movieIds.subList(from, to);
|
---|
| 32 |
|
---|
| 33 | for(Integer id: movieIds){
|
---|
[c02189f] | 34 | //Trying to improve load times by not pulling all things from the database, excluding un-needed stuff
|
---|
| 35 | //
|
---|
| 36 | //movies.add(movieService.findById(id));
|
---|
| 37 | movies.add(movieService.findBasicById(id));
|
---|
[3c0f9a9] | 38 | }
|
---|
| 39 | model.addAttribute("page", page);
|
---|
| 40 | return movies;
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.