Ignore:
Timestamp:
02/07/22 21:26:03 (3 years ago)
Author:
GitHub <noreply@…>
Branches:
main
Children:
0226942
Parents:
7f36551 (diff), 3c0f9a9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Mato-77 <56981531+Mato-77@…> (02/07/22 21:26:03)
git-committer:
GitHub <noreply@…> (02/07/22 21:26:03)
Message:

Merge pull request #2 from partaloski/master

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

File:
1 edited

Legend:

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

    r7f36551 rad4243e  
    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}
Note: See TracChangeset for help on using the changeset viewer.