-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReviewService.java
More file actions
28 lines (21 loc) · 880 Bytes
/
ReviewService.java
File metadata and controls
28 lines (21 loc) · 880 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
28
package com.example.moviesweb;
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));
mongoTemplate.update(Review.class)
.matching(Criteria.where("imdbId").is(imdbId))
.apply(new Update().push("reviewIds").value(review))
.first();
return review;
}
}