Ignore:
Timestamp:
08/24/23 03:31:06 (15 months ago)
Author:
DenicaKj <dkorvezir@…>
Branches:
master
Children:
4158cac
Parents:
1e7126f
Message:

filter for genre

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/moviezone/web/HomeController.java

    r1e7126f rbcb4acc  
    236236    @GetMapping("/films")
    237237    @Transactional
    238     public String getFilmsPage1(Model model,@RequestParam(required = false) Integer id_cinema){
     238    public String getFilmsPage1(Model model,@RequestParam(required = false) Integer id_cinema, @RequestParam(required = false) Integer id_genre){
    239239        model.addAttribute("cinemas",cinemaService.findAllCinemas());
    240         model.addAttribute("genres", GenreEnum.values());
     240        List<GenreEnum> genres = List.of(GenreEnum.values());
     241        model.addAttribute("genres", genres);
     242        List<Film> films = filmService.findAllFilms();
    241243        if (id_cinema!=null) {
    242             model.addAttribute("films",filmService.getFilmsFromCinema(id_cinema));
    243         }else{
    244             List<FilmsReturnTable> pom=new LinkedList<>();
    245             model.addAttribute("films",filmService.findAllFilms());
    246         }
     244            films = filmService.getFilmsFromCinema(id_cinema);
     245        }
     246        if ( id_genre != null){
     247            List<Film> pom= new ArrayList<>();
     248            for (int i = 0; i < films.size(); i++) {
     249                if(films.get(i).getGenre().contains(genres.get(id_genre).name().toLowerCase())){
     250                   pom.add(films.get(i));
     251                }
     252            }
     253            films=pom;
     254        }
     255        model.addAttribute("films",films);
    247256        model.addAttribute("bodyContent","films");
    248257        return "master-template";
     
    270279            model.addAttribute("events",eventService.getEventsFromCinema(id_cinema));
    271280        }else{
    272             List<FilmsReturnTable> pom=new LinkedList<>();
    273281            model.addAttribute("events",eventService.getEventsNow());
    274282        }
Note: See TracChangeset for help on using the changeset viewer.