소스 검색

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
 package com.passionproject.project_spitball20.controller;
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
 @RestController
16
 @RestController
17
+@RequestMapping("ratings")
18
+@CrossOrigin(origins = "http://localhost:8100")
9
 public class RatingController {
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
 import org.springframework.http.ResponseEntity;
13
 import org.springframework.http.ResponseEntity;
14
 import org.springframework.web.bind.annotation.*;
14
 import org.springframework.web.bind.annotation.*;
15
 
15
 
16
-@CrossOrigin
16
+
17
 @RestController
17
 @RestController
18
 @RequestMapping("teacher_profile")
18
 @RequestMapping("teacher_profile")
19
+@CrossOrigin(origins = "http://localhost:8100")
19
 public class TeacherController {
20
 public class TeacherController {
20
 
21
 
21
     @Autowired
22
     @Autowired
28
     public ResponseEntity<Teacher> registerUser(@RequestBody Teacher newTeacher) {
29
     public ResponseEntity<Teacher> registerUser(@RequestBody Teacher newTeacher) {
29
         Teacher teacher = new Teacher();
30
         Teacher teacher = new Teacher();
30
         HttpStatus status = HttpStatus.CONFLICT;
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
             teacher = teacherService.save(newTeacher);
33
             teacher = teacherService.save(newTeacher);
33
             status  = HttpStatus.CREATED;
34
             status  = HttpStatus.CREATED;
34
         }
35
         }
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
     ReviewService reviewService;
21
     ReviewService reviewService;
22
 
22
 
23
     @RequestMapping(value = "/post", method = RequestMethod.POST)
23
     @RequestMapping(value = "/post", method = RequestMethod.POST)
24
-    public ResponseEntity<Review> postMessage(@RequestBody Review newReview) {
24
+    public ResponseEntity<Review> postReview(@RequestBody Review newReview) {
25
         HttpStatus httpStatus = HttpStatus.CREATED;
25
         HttpStatus httpStatus = HttpStatus.CREATED;
26
         Review content = this.reviewService.save(newReview);
26
         Review content = this.reviewService.save(newReview);
27
 
27
 
29
     }
29
     }
30
 
30
 
31
     @RequestMapping(value = "/update", method = RequestMethod.PUT)
31
     @RequestMapping(value = "/update", method = RequestMethod.PUT)
32
-    public ResponseEntity<Review> updateMessage(@RequestBody Review review) {
32
+    public ResponseEntity<Review> updateReview(@RequestBody Review review) {
33
         HttpStatus httpStatus = HttpStatus.CREATED;
33
         HttpStatus httpStatus = HttpStatus.CREATED;
34
-        review = (Review) this.reviewService.update(review);
34
+        review = this.reviewService.update(review);
35
 
35
 
36
         return new ResponseEntity<>(review, new HttpHeaders(), httpStatus);
36
         return new ResponseEntity<>(review, new HttpHeaders(), httpStatus);
37
     }
37
     }
38
 
38
 
39
     @RequestMapping(value = "/get_reviews", method = RequestMethod.GET)
39
     @RequestMapping(value = "/get_reviews", method = RequestMethod.GET)
40
-    public ResponseEntity<?> getAllMessages() throws JsonProcessingException {
40
+    public ResponseEntity<?> getAllReviews() throws JsonProcessingException {
41
         ObjectMapper objectMapper = new ObjectMapper();
41
         ObjectMapper objectMapper = new ObjectMapper();
42
         HttpStatus httpStatus = HttpStatus.CREATED;
42
         HttpStatus httpStatus = HttpStatus.CREATED;
43
         HttpHeaders header = new HttpHeaders();
43
         HttpHeaders header = new HttpHeaders();
49
     }
49
     }
50
 
50
 
51
     @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
51
     @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
52
-    public ResponseEntity<Review> deleteMessage(@RequestBody Review review) {
52
+    public ResponseEntity<Review> deleteReview(@RequestBody Review review) {
53
         reviewService.delete(review);
53
         reviewService.delete(review);
54
         return new ResponseEntity<>(HttpStatus.OK);
54
         return new ResponseEntity<>(HttpStatus.OK);
55
     }
55
     }

+ 4
- 0
src/main/java/com/passionproject/project_spitball20/model/Rating.java 파일 보기

1
 package com.passionproject.project_spitball20.model;
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
 import javax.persistence.*;
6
 import javax.persistence.*;
4
 
7
 
5
 
8
 
14
 
17
 
15
     Integer rating;
18
     Integer rating;
16
 
19
 
20
+
17
     public Long getId() {
21
     public Long getId() {
18
         return id;
22
         return id;
19
     }
23
     }

+ 1
- 0
src/main/java/com/passionproject/project_spitball20/service/RatingService.java 파일 보기

28
         return ratingRepository.findById(id).get();
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
         return teacherRepository.findById(id).get();
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
     public Teacher findEmail(String email) {
30
     public Teacher findEmail(String email) {
31
         return teacherRepository.findByEmail(email);
31
         return teacherRepository.findByEmail(email);