Ignore:
Timestamp:
02/08/22 20:13:23 (3 years ago)
Author:
Petar Partaloski <ppartaloski@…>
Branches:
main
Children:
0226942, 3fe36de
Parents:
3c0f9a9
Message:

Added new core functionalities, fixed bugs and improved visual clarity

File:
1 edited

Legend:

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

    r3c0f9a9 rc02189f  
    55import com.wediscussmovies.project.model.Reply;
    66import com.wediscussmovies.project.model.User;
     7import com.wediscussmovies.project.model.relation.DiscussionLikes;
    78import com.wediscussmovies.project.service.DiscussionService;
    89import com.wediscussmovies.project.service.MovieService;
     
    1718import org.springframework.web.bind.annotation.*;
    1819
     20import java.util.ArrayList;
    1921import java.util.List;
    2022
     
    4648        model.addAttribute("contentTemplate", "discussionsList");
    4749        model.addAttribute("user",LoggedUser.getLoggedUser());
     50        this.addModelPropertiesForUser(model);
     51        this.addModelPropertiesLikes(model,null, discussions);
    4852        return "template";
    4953    }
     
    6266            model.addAttribute("user",LoggedUser.getLoggedUser());
    6367            model.addAttribute("replies",this.replyService.findAllByDiscussion(disc));
     68            addModelPropertiesLikes(model, disc, null);
     69            addModelPropertiesForUser(model);
    6470
    6571            return "template";
     
    171177
    172178    }
     179    private void addModelPropertiesForUser(Model model){
     180        User user = LoggedUser.getLoggedUser();
     181        model.addAttribute("likedDiscussions",this.discussionService.findLikedDiscussionsByUser(user));
     182        model.addAttribute("user",user);
     183    }
     184    private void addModelPropertiesLikes(Model model, Discussion discussion, List<Discussion> discussions){
     185        if(discussion==null){
     186            List<com.wediscussmovies.project.querymodels.DiscussionLikes> discussionLikes = new ArrayList<>();
     187            for(Discussion d: discussions){
     188                discussionLikes.add(discussionService.findLikesForDiscussionWithId(d.getDiscussionId()));
     189            }
     190            model.addAttribute("likes", discussionLikes);
     191        }
     192        else{
     193            model.addAttribute("likes",discussionService.findLikesForDiscussionWithId(discussion.getDiscussionId()).getLikes());
     194        }
     195    }
    173196
    174197
Note: See TracChangeset for help on using the changeset viewer.