Ignore:
Timestamp:
02/07/22 19:57:58 (3 years ago)
Author:
Petar Partaloski <ppartaloski@…>
Branches:
main
Children:
ad4243e, c02189f
Parents:
7f36551
Message:

Added genre liking, fixed counter, improved paging, improved searches

Location:
src/main/java/com/wediscussmovies/project/web
Files:
2 added
3 edited

Legend:

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

    r7f36551 r3c0f9a9  
    11package com.wediscussmovies.project.web.controller;
    22
     3import com.wediscussmovies.project.LoggedUser;
     4import com.wediscussmovies.project.model.Genre;
     5import com.wediscussmovies.project.model.User;
     6import com.wediscussmovies.project.model.relation.UserGenres;
     7import com.wediscussmovies.project.querymodels.GenreLikes;
     8import com.wediscussmovies.project.repository.GenreLikesRepository;
    39import com.wediscussmovies.project.service.GenreService;
    410import org.springframework.stereotype.Controller;
     
    713import org.springframework.web.bind.annotation.RequestMapping;
    814
     15import java.util.ArrayList;
     16import java.util.List;
     17
    918@Controller
    1019@RequestMapping("/genres")
    1120public class GenreController {
    1221    private final GenreService genreService;
     22    private final GenreLikesRepository genreLikesRepository;
    1323
    14     public GenreController(GenreService genreService) {
     24    public GenreController(GenreService genreService, GenreLikesRepository genreLikesRepository) {
    1525        this.genreService = genreService;
     26        this.genreLikesRepository = genreLikesRepository;
    1627    }
    1728    @GetMapping
    1829    public String getGenres(Model model){
    1930        model.addAttribute("genres",genreService.findAllWithLikes());
     31        model.addAttribute("allGenres", genreService.findAll());
    2032        model.addAttribute("contentTemplate","genres");
     33        addModelPropertiesForUser(model);
    2134        return "template";
    2235    }
     36
     37    private void addModelPropertiesForUser(Model model){
     38        User user = LoggedUser.getLoggedUser();
     39        List<UserGenres> genreLikesList = this.genreLikesRepository.findAllByUser(user);
     40        List<Genre> genres = new ArrayList<>();
     41        for(UserGenres g: genreLikesList){
     42            genres.add(genreService.findById(g.getId().getGenreId()));
     43        }
     44        model.addAttribute("likedGenres",genres);
     45        model.addAttribute("user",user);
     46    }
    2347}
  • src/main/java/com/wediscussmovies/project/web/controller/MovieController.java

    r7f36551 r3c0f9a9  
    99import com.wediscussmovies.project.service.PersonService;
    1010import com.wediscussmovies.project.web.DesignFrontMovies;
     11import com.wediscussmovies.project.web.PageFrontMovies;
    1112import lombok.Data;
    1213import org.springframework.format.annotation.DateTimeFormat;
     
    3738    }
    3839
    39     @GetMapping
     40    @GetMapping("/old")
    4041    public String getMovies(@RequestParam(required = false) String titleQuery, Model model,
    4142                            @RequestParam(required = false) String error){
     
    5556        model.addAttribute("movie_rows", movie_rows);
    5657        model.addAttribute("contentTemplate", "moviesList");
     58        if (error != null && !error.equals(" "))
     59            model.addAttribute("error",error);
     60        return "template";
     61    }
     62
     63
     64    @GetMapping
     65    public String getMoviesAlternative(@RequestParam(required = false) String titleQuery, Model model,
     66                            @RequestParam(required = false) String error, @RequestParam(required = false) String page){
     67        if (page==null){
     68            return "redirect:/movies?page=1";
     69        }
     70        addModelPropertiesForUser(model);
     71        List<Movie> movies = PageFrontMovies.getPagedMovies(page, movieService, model);
     72        List<List<Movie>> movie_rows = new ArrayList<>();
     73        DesignFrontMovies.designMovieList(movies,movie_rows);
     74        model.addAttribute("movies", movies);
     75        model.addAttribute("movie_rows", movie_rows);
     76        model.addAttribute("contentTemplate", "moviesListPaged");
    5777        if (error != null && !error.equals(" "))
    5878            model.addAttribute("error",error);
     
    160180    }
    161181    private void addModelProperties(Model model){
    162 
    163         model.addAttribute("directors",  personService.findAllDirectors());
     182        model.addAttribute("directors", personService.findAllDirectors());
    164183        model.addAttribute("actors", personService.findAllActors());
    165184        model.addAttribute("genres", genreService.findAll());
     
    169188        model.addAttribute("likedMovies",this.movieService.findLikedMoviesByUser(user));
    170189        model.addAttribute("user",user);
    171         }
     190    }
    172191
    173192}
  • src/main/java/com/wediscussmovies/project/web/controller/PersonController.java

    r7f36551 r3c0f9a9  
    11package com.wediscussmovies.project.web.controller;
    22
     3import com.wediscussmovies.project.LoggedUser;
    34import com.wediscussmovies.project.model.Person;
     5import com.wediscussmovies.project.model.User;
    46import com.wediscussmovies.project.service.MovieService;
    57import com.wediscussmovies.project.service.PersonService;
     
    135137    }
    136138
     139    private void addModelPropertiesForUser(Model model){
     140        User user = LoggedUser.getLoggedUser();
     141        model.addAttribute("user",user);
     142    }
     143
    137144
    138145}
Note: See TracChangeset for help on using the changeset viewer.