-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReviewService.java
More file actions
27 lines (22 loc) · 919 Bytes
/
ReviewService.java
File metadata and controls
27 lines (22 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package devsathi.movies;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;
@Service
public class ReviewService {
@Autowired
private ReviewRepository reviewRepository;
@Autowired
private MongoTemplate mongoTemplate;
public Review createReview(String reviewBody, String imdbId) {
Review review = reviewRepository.insert(new Review(reviewBody));
//updation be performed in movie class
mongoTemplate.update(Movie.class)
.matching(Criteria.where("imdbId").is(imdbId))
.apply(new Update().push("reviewIds").value(review))
.first();
return review;
}
}