|
@@ -1,10 +1,57 @@
|
1
|
1
|
package com.passionproject.project_spitball20.controller;
|
2
|
2
|
|
3
|
3
|
|
4
|
|
-import org.springframework.web.bind.annotation.CrossOrigin;
|
5
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
4
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
5
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
6
|
+import com.passionproject.project_spitball20.model.Rating;
|
|
7
|
+import com.passionproject.project_spitball20.model.messages.Review;
|
|
8
|
+import com.passionproject.project_spitball20.service.RatingService;
|
|
9
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
10
|
+import org.springframework.http.HttpHeaders;
|
|
11
|
+import org.springframework.http.HttpStatus;
|
|
12
|
+import org.springframework.http.MediaType;
|
|
13
|
+import org.springframework.http.ResponseEntity;
|
|
14
|
+import org.springframework.web.bind.annotation.*;
|
6
|
15
|
|
7
|
|
-@CrossOrigin(origins = "http://localhost:8100")
|
8
|
16
|
@RestController
|
|
17
|
+@RequestMapping("ratings")
|
|
18
|
+@CrossOrigin(origins = "http://localhost:8100")
|
9
|
19
|
public class RatingController {
|
|
20
|
+
|
|
21
|
+ @Autowired
|
|
22
|
+ RatingService ratingService;
|
|
23
|
+
|
|
24
|
+ @RequestMapping(value = "/rate", method = RequestMethod.POST)
|
|
25
|
+ public ResponseEntity<Rating> newRating(@RequestBody Rating newRating) {
|
|
26
|
+ HttpStatus httpStatus = HttpStatus.CREATED;
|
|
27
|
+ Rating rate = this.ratingService.save(newRating);
|
|
28
|
+
|
|
29
|
+ return new ResponseEntity<>(rate, new HttpHeaders(), httpStatus);
|
|
30
|
+ }
|
|
31
|
+ @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
|
|
32
|
+ public ResponseEntity<Rating> deleteRating(@RequestBody Rating rating) {
|
|
33
|
+ ratingService.delete(rating);
|
|
34
|
+ return new ResponseEntity<>(HttpStatus.OK);
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ @RequestMapping(value = "/update", method = RequestMethod.PUT)
|
|
38
|
+ public ResponseEntity<Rating> updateRating(@RequestBody Rating rating) {
|
|
39
|
+ HttpStatus httpStatus = HttpStatus.CREATED;
|
|
40
|
+ rating = this.ratingService.update(rating);
|
|
41
|
+
|
|
42
|
+ return new ResponseEntity<>(rating, new HttpHeaders(), httpStatus);
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ @RequestMapping(value = "/get_all_ratings", method = RequestMethod.GET)
|
|
46
|
+ public ResponseEntity<?> getAllRatings() throws JsonProcessingException {
|
|
47
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
48
|
+ HttpStatus httpStatus = HttpStatus.CREATED;
|
|
49
|
+ HttpHeaders header = new HttpHeaders();
|
|
50
|
+
|
|
51
|
+ String messageJSON = objectMapper.writeValueAsString(this.ratingService.getAllRatings());
|
|
52
|
+ header.setContentType(MediaType.APPLICATION_JSON);
|
|
53
|
+
|
|
54
|
+ return new ResponseEntity<>(messageJSON, header, httpStatus);
|
|
55
|
+ }
|
|
56
|
+
|
10
|
57
|
}
|