Ignore:
Timestamp:
02/04/22 23:22:13 (3 years ago)
Author:
Test <matonikolov77@…>
Branches:
main
Children:
5b447b0
Parents:
3ded84d
Message:

Added CRUD for movies,persons,discussion,replies,genres
Added ajaxcalls

File:
1 edited

Legend:

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

    r3ded84d re0ef1b1  
    11package com.wediscussmovies.project.service.impl;
    22
    3 import com.wediscussmovies.project.model.*;
     3import com.wediscussmovies.project.model.Discussion;
     4import com.wediscussmovies.project.model.exception.DiscussionNotExistException;
     5import com.wediscussmovies.project.model.exception.ReplyNotExistException;
     6import com.wediscussmovies.project.model.primarykeys.ReplyPK;
     7import com.wediscussmovies.project.repository.DiscussionRepository;
    48import com.wediscussmovies.project.repository.ReplyRepository;
     9import com.wediscussmovies.project.model.Reply;
     10import com.wediscussmovies.project.model.User;
     11import com.wediscussmovies.project.repository.UserRepository;
    512import com.wediscussmovies.project.service.ReplyService;
    613import org.springframework.stereotype.Service;
    714
    8 import java.util.Optional;
     15import java.sql.Date;
     16import java.time.LocalDate;
     17import java.util.List;
    918
    1019@Service
    1120public class ReplyServiceImpl implements ReplyService {
     21
    1222    private final ReplyRepository replyRepository;
     23    private final DiscussionRepository discussionRepository;
    1324
    14     public ReplyServiceImpl(ReplyRepository replyRepository) {
     25    public ReplyServiceImpl(ReplyRepository replyRepository,
     26                            DiscussionRepository discussionRepository) {
    1527        this.replyRepository = replyRepository;
     28        this.discussionRepository = discussionRepository;
     29    }
     30
     31
     32
     33    @Override
     34    public void save(Integer discussionId, String text,User user) {
     35
     36        Discussion discussion = this.discussionRepository.findById(discussionId).orElseThrow(() -> new DiscussionNotExistException(discussionId));
     37
     38        Date date = Date.valueOf(LocalDate.now());
     39        this.replyRepository.insertInto(text,date,user.getUserId(),discussionId);
     40
    1641    }
    1742
    1843    @Override
    19     public Optional<Reply> findById(Long id) {
    20         return replyRepository.findById(1);
     44    public void likeReply(Integer replyId, Integer userId) {
     45        //da se implementira, promena vo baza
    2146    }
    2247
    2348    @Override
    24     public void delete(Reply r) {
    25         replyRepository.delete(r);
     49    public void unlikeReply(Integer replyId, Integer userId) {
     50        // da se implementira, promena vo baza
    2651    }
    2752
    2853    @Override
    29     public Reply save(Reply r) {
    30         return replyRepository.save(r);
     54    public List<Reply> findAllByDiscussion(Discussion discussion) {
     55        return this.replyRepository.findAllByDiscussion(discussion);
     56    }
     57
     58
     59    @Override
     60    public Reply edit(Integer replyId,Integer discussionId,String text) {
     61        ReplyPK replyPK = new ReplyPK(discussionId,replyId);
     62        Reply reply = this.replyRepository.findById(replyPK).orElseThrow();
     63        reply.setText(text);
     64        return  this.replyRepository.save(reply);
     65    }
     66
     67    @Override
     68    public void delete(Integer discussionId, Integer replyId) {
     69        this.replyRepository.deleteById(new ReplyPK(discussionId,replyId));
     70    }
     71
     72    @Override
     73    public Reply findById(Integer discussionId, Integer replyId) {
     74        ReplyPK replyPK  = new ReplyPK(discussionId,replyId);
     75        return this.replyRepository.findById(replyPK).orElseThrow(() -> new ReplyNotExistException(replyPK));
     76
    3177    }
    3278}
Note: See TracChangeset for help on using the changeset viewer.