Ignore:
Timestamp:
02/06/22 22:56:26 (3 years ago)
Author:
Test <matonikolov77@…>
Branches:
main
Children:
3c0f9a9, ad4243e
Parents:
42d565b
Message:

Resolved bux for fronted and repaired filtering through title and genres for movies

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/wediscussmovies/project/web/controller/MovieController.java

    r42d565b r7f36551  
    88import com.wediscussmovies.project.service.MovieService;
    99import com.wediscussmovies.project.service.PersonService;
     10import com.wediscussmovies.project.web.DesignFrontMovies;
    1011import lombok.Data;
    1112import org.springframework.format.annotation.DateTimeFormat;
     
    4748        }
    4849
    49         Authentication auth = SecurityContextHolder.getContext().getAuthentication();
     50        addModelPropertiesForUser(model);
    5051
    51         if (!(auth instanceof AnonymousAuthenticationToken)){
    52             UserDetails userDetails = (UserDetails) auth.getPrincipal();
    53             User user = (User) userDetails;
    54           model.addAttribute("likedMovies",this.movieService.findLikedMoviesByUser(user));
    55           model.addAttribute("user",user);
    56         }
    57         List<Movie> movieList = movies;
    5852        List<List<Movie>> movie_rows = new ArrayList<>();
    59         for(int i=0; i<movieList.size(); i+=4){
    60             int j = i+4;
    61             if(j>movieList.size())
    62                 j=movieList.size();
    63             movie_rows.add(movieList.subList(i, j));
    64         }
     53        DesignFrontMovies.designMovieList(movies,movie_rows);
    6554        model.addAttribute("movies", movies);
    6655        model.addAttribute("movie_rows", movie_rows);
     
    7463    public String getMovie(@PathVariable Integer id, Model model){
    7564        model.addAttribute("movie", movieService.findById(id));
    76 
    77         Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    78         if (!(auth instanceof AnonymousAuthenticationToken)){
    79             UserDetails userDetails = (UserDetails) auth.getPrincipal();
    80             User user = (User) userDetails;
    81             model.addAttribute("likedMovies",this.movieService.findLikedMoviesByUser(user));
    82             model.addAttribute("user",user);
    83         }
    84 
     65        addModelPropertiesForUser(model);
    8566        model.addAttribute("contentTemplate", "movieShow");
    8667        return "template";
     
    184165        model.addAttribute("genres", genreService.findAll());
    185166    }
     167    private void addModelPropertiesForUser(Model model){
     168        User user = LoggedUser.getLoggedUser();
     169        model.addAttribute("likedMovies",this.movieService.findLikedMoviesByUser(user));
     170        model.addAttribute("user",user);
     171        }
     172
    186173}
Note: See TracChangeset for help on using the changeset viewer.