source: src/main/java/tech/techharbor/Service/Impl/ReviewServiceImpl.java

main
Last change on this file was f4b4afa, checked in by Nikola Todoroski <nikola.todoroski@…>, 6 months ago

Pushed whole project, original project location on github:https://github.com/hehxd/Tech-Harbor

  • Property mode set to 100644
File size: 1.7 KB
Line 
1package tech.techharbor.Service.Impl;
2
3import org.springframework.stereotype.Service;
4import tech.techharbor.Model.Exceptions.ReviewNotFoundException;
5import tech.techharbor.Model.ReviewModel;
6import tech.techharbor.Repository.ReviewRepository;
7import tech.techharbor.Service.ReviewService;
8
9import java.util.List;
10import java.util.Optional;
11
12@Service
13public class ReviewServiceImpl implements ReviewService {
14
15 private final ReviewRepository reviewRepository;
16
17 public ReviewServiceImpl(ReviewRepository reviewRepository) {
18 this.reviewRepository = reviewRepository;
19 }
20
21 @Override
22 public List<ReviewModel> listReviews() {
23 return this.reviewRepository.findAll();
24 }
25
26 @Override
27 public Optional<ReviewModel> findById(Integer id) {
28 return this.reviewRepository.findById(id);
29 }
30
31 @Override
32 public ReviewModel create(Integer rating, String description, Integer customerId, Integer productId) {
33 ReviewModel review = new ReviewModel(rating, description, customerId, productId);
34 return this.reviewRepository.save(review);
35 }
36
37 @Override
38 public ReviewModel update(Integer id, Integer rating, String description) {
39 ReviewModel review = this.reviewRepository.findById(id).orElseThrow(() -> new ReviewNotFoundException(id));
40 review.setReviewRating(rating);
41 review.setReviewDescription(description);
42 return this.reviewRepository.save(review);
43 }
44
45 @Override
46 public void delete(Integer id) {
47 this.reviewRepository.deleteById(id);
48 }
49
50 @Override
51 public List<ReviewModel> getReviewsByProductId(Integer productId) {
52 return this.reviewRepository.findByProductId(productId);
53 }
54}
Note: See TracBrowser for help on using the repository browser.