瀏覽代碼

persistence persisting, will set new branch for JWT in the morning

rjsmall90 6 年之前
父節點
當前提交
75050438cf

+ 50
- 3
src/main/java/com/passionproject/project_spitball20/controller/RatingController.java 查看文件

@@ -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
 }

+ 17
- 2
src/main/java/com/passionproject/project_spitball20/controller/TeacherController.java 查看文件

@@ -13,9 +13,10 @@ import org.springframework.http.HttpStatus;
13 13
 import org.springframework.http.ResponseEntity;
14 14
 import org.springframework.web.bind.annotation.*;
15 15
 
16
-@CrossOrigin
16
+
17 17
 @RestController
18 18
 @RequestMapping("teacher_profile")
19
+@CrossOrigin(origins = "http://localhost:8100")
19 20
 public class TeacherController {
20 21
 
21 22
     @Autowired
@@ -28,7 +29,7 @@ public class TeacherController {
28 29
     public ResponseEntity<Teacher> registerUser(@RequestBody Teacher newTeacher) {
29 30
         Teacher teacher = new Teacher();
30 31
         HttpStatus status = HttpStatus.CONFLICT;
31
-        if(teacherService.findEmail(newTeacher.getEmail()).equals(null)){ //&& teacherService.findName(newTeacher.getFullName()).equals(null)) {
32
+        if(teacherService.findEmail(newTeacher.getEmail()).equals(null)){
32 33
             teacher = teacherService.save(newTeacher);
33 34
             status  = HttpStatus.CREATED;
34 35
         }
@@ -37,4 +38,18 @@ public class TeacherController {
37 38
 
38 39
     }
39 40
 
41
+    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
42
+    public ResponseEntity<Teacher> deleteRating(@RequestBody Teacher teacher) {
43
+        teacherService.delete(teacher);
44
+        return new ResponseEntity<>(HttpStatus.OK);
45
+    }
46
+
47
+    @RequestMapping(value = "/update", method = RequestMethod.PUT)
48
+    public ResponseEntity<Teacher> updateRating(@RequestBody Teacher teacher) {
49
+        HttpStatus httpStatus = HttpStatus.CREATED;
50
+        teacher = this.teacherService.update(teacher);
51
+
52
+        return new ResponseEntity<>(teacher, new HttpHeaders(), httpStatus);
53
+    }
54
+
40 55
 }

+ 5
- 5
src/main/java/com/passionproject/project_spitball20/controller/messages/ReviewController.java 查看文件

@@ -21,7 +21,7 @@ public class ReviewController {
21 21
     ReviewService reviewService;
22 22
 
23 23
     @RequestMapping(value = "/post", method = RequestMethod.POST)
24
-    public ResponseEntity<Review> postMessage(@RequestBody Review newReview) {
24
+    public ResponseEntity<Review> postReview(@RequestBody Review newReview) {
25 25
         HttpStatus httpStatus = HttpStatus.CREATED;
26 26
         Review content = this.reviewService.save(newReview);
27 27
 
@@ -29,15 +29,15 @@ public class ReviewController {
29 29
     }
30 30
 
31 31
     @RequestMapping(value = "/update", method = RequestMethod.PUT)
32
-    public ResponseEntity<Review> updateMessage(@RequestBody Review review) {
32
+    public ResponseEntity<Review> updateReview(@RequestBody Review review) {
33 33
         HttpStatus httpStatus = HttpStatus.CREATED;
34
-        review = (Review) this.reviewService.update(review);
34
+        review = this.reviewService.update(review);
35 35
 
36 36
         return new ResponseEntity<>(review, new HttpHeaders(), httpStatus);
37 37
     }
38 38
 
39 39
     @RequestMapping(value = "/get_reviews", method = RequestMethod.GET)
40
-    public ResponseEntity<?> getAllMessages() throws JsonProcessingException {
40
+    public ResponseEntity<?> getAllReviews() throws JsonProcessingException {
41 41
         ObjectMapper objectMapper = new ObjectMapper();
42 42
         HttpStatus httpStatus = HttpStatus.CREATED;
43 43
         HttpHeaders header = new HttpHeaders();
@@ -49,7 +49,7 @@ public class ReviewController {
49 49
     }
50 50
 
51 51
     @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
52
-    public ResponseEntity<Review> deleteMessage(@RequestBody Review review) {
52
+    public ResponseEntity<Review> deleteReview(@RequestBody Review review) {
53 53
         reviewService.delete(review);
54 54
         return new ResponseEntity<>(HttpStatus.OK);
55 55
     }

+ 4
- 0
src/main/java/com/passionproject/project_spitball20/model/Rating.java 查看文件

@@ -1,5 +1,8 @@
1 1
 package com.passionproject.project_spitball20.model;
2 2
 
3
+import com.passionproject.project_spitball20.model.messages.Review;
4
+import org.springframework.beans.factory.annotation.Autowired;
5
+
3 6
 import javax.persistence.*;
4 7
 
5 8
 
@@ -14,6 +17,7 @@ public class Rating {
14 17
 
15 18
     Integer rating;
16 19
 
20
+
17 21
     public Long getId() {
18 22
         return id;
19 23
     }

+ 1
- 0
src/main/java/com/passionproject/project_spitball20/service/RatingService.java 查看文件

@@ -28,5 +28,6 @@ public class RatingService {
28 28
         return ratingRepository.findById(id).get();
29 29
     }
30 30
 
31
+    public Object getAllRatings() { return ratingRepository.findAll(); }
31 32
 
32 33
 }

+ 3
- 3
src/main/java/com/passionproject/project_spitball20/service/TeacherService.java 查看文件

@@ -23,9 +23,9 @@ public class TeacherService {
23 23
         return teacherRepository.findById(id).get();
24 24
     }
25 25
 
26
-//    public Teacher findName(String fullName) {
27
-//        return teacherRepository.findByName(fullName);
28
-//    }
26
+    public void delete(Teacher teacher) {
27
+        teacherRepository.delete(teacher);
28
+    }
29 29
 
30 30
     public Teacher findEmail(String email) {
31 31
         return teacherRepository.findByEmail(email);