Changeset e0ef1b1 in Git for src/main/java/com/wediscussmovies/project/service/impl/ReplyServiceImpl.java
- Timestamp:
- 02/04/22 23:22:13 (3 years ago)
- Branches:
- main
- Children:
- 5b447b0
- Parents:
- 3ded84d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/wediscussmovies/project/service/impl/ReplyServiceImpl.java
r3ded84d re0ef1b1 1 1 package com.wediscussmovies.project.service.impl; 2 2 3 import com.wediscussmovies.project.model.*; 3 import com.wediscussmovies.project.model.Discussion; 4 import com.wediscussmovies.project.model.exception.DiscussionNotExistException; 5 import com.wediscussmovies.project.model.exception.ReplyNotExistException; 6 import com.wediscussmovies.project.model.primarykeys.ReplyPK; 7 import com.wediscussmovies.project.repository.DiscussionRepository; 4 8 import com.wediscussmovies.project.repository.ReplyRepository; 9 import com.wediscussmovies.project.model.Reply; 10 import com.wediscussmovies.project.model.User; 11 import com.wediscussmovies.project.repository.UserRepository; 5 12 import com.wediscussmovies.project.service.ReplyService; 6 13 import org.springframework.stereotype.Service; 7 14 8 import java.util.Optional; 15 import java.sql.Date; 16 import java.time.LocalDate; 17 import java.util.List; 9 18 10 19 @Service 11 20 public class ReplyServiceImpl implements ReplyService { 21 12 22 private final ReplyRepository replyRepository; 23 private final DiscussionRepository discussionRepository; 13 24 14 public ReplyServiceImpl(ReplyRepository replyRepository) { 25 public ReplyServiceImpl(ReplyRepository replyRepository, 26 DiscussionRepository discussionRepository) { 15 27 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 16 41 } 17 42 18 43 @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 21 46 } 22 47 23 48 @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 26 51 } 27 52 28 53 @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 31 77 } 32 78 }
Note:
See TracChangeset
for help on using the changeset viewer.