Ignore:
Timestamp:
02/10/22 13:28:00 (3 years ago)
Author:
Test <matonikolov77@…>
Branches:
main
Children:
980eeda
Parents:
6f91f99
Message:

Changed DiscussionRepository and DiscussionServiceImpl for fetching likes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/wediscussmovies/project/service/impl/DiscussionServiceImpl.java

    r6f91f99 r8f1b7e9  
    1616import org.springframework.stereotype.Service;
    1717
    18 import java.sql.Date;
    1918import java.time.LocalDate;
    2019import java.util.ArrayList;
    2120import java.util.List;
     21import java.util.concurrent.atomic.AtomicInteger;
    2222
    2323@Service
     
    4545    @Override
    4646    public List<Discussion> listAll() {
    47         return this.discussionRepository.findAll();
     47        List<Discussion> discussions = this.discussionRepository.findAll();
     48        List<DiscussionLikesQM> discussionLikes  = this.discussionRepository.findAllDiscussionsWithLikes();
     49        for (int i = 0; i < discussionLikes.size(); i++){
     50            discussions.get(i).setLikes(discussionLikes.get(i).getLikes());
     51        }
     52        return discussions;
    4853    }
    4954
    5055    @Override
    5156    public void save(Character type,Integer id,String title, String text,User user) {
    52         Date date = Date.valueOf(LocalDate.now());
     57        LocalDate date = LocalDate.now();
    5358        Discussion discussion;
    5459
     
    123128
    124129    @Override
    125     public void findLikesForAllDiscussions(List<Discussion> discussions) {
    126 //        this.discussionRepository.findAllDiscussionsWithLikes()
    127 //                .forEach(el ->{
    128 //                        if (discussions.)
    129 //                });
     130    public List<DiscussionLikesQM> findLikesForAllDiscussions() {
     131           // return this.discussionRepository.findAllDiscussionsWithLikes();
     132        return this.discussionRepository.findAllDiscussionsWithLikes();
    130133    }
    131134
     
    145148    @Override
    146149    public Discussion findById(Integer id) {
    147         return discussionRepository.findById(id).orElseThrow(() -> new DiscussionNotExistException(id));
     150        Discussion disc =  discussionRepository.findById(id).orElseThrow(() -> new DiscussionNotExistException(id));
     151        disc.setLikes(this.discussionRepository.findDiscussionWithLikes(id).getLikes());
     152        return disc;
    148153    }
    149154
Note: See TracChangeset for help on using the changeset viewer.