5 次代码提交

作者 SHA1 备注 提交日期
  rjsmall90 aa91985d1a updtd teacher & school controllers, added SchoolWall 6 年前
  rjsmall90 cd39c85f6e tokens updated 6 年前
  rjsmall90 e10909cfbc ratings added updated i think 6 年前
  rjsmall90 da62c8fba2 new new 6 年前
  rjsmall90 aa45ef7d6f teacher and school rating models updated 6 年前
共有 30 个文件被更改,包括 760 次插入124 次删除
  1. 22
    1
      pom.xml
  2. 7
    0
      src/main/java/com/passionproject/project_spitball20/Application.java
  3. 64
    0
      src/main/java/com/passionproject/project_spitball20/JWT/JWTAuthenticationFilter.java
  4. 60
    0
      src/main/java/com/passionproject/project_spitball20/JWT/JWTAuthorizationFilter.java
  5. 12
    0
      src/main/java/com/passionproject/project_spitball20/JWT/SecurityConstants.java
  6. 54
    0
      src/main/java/com/passionproject/project_spitball20/JWT/WebSecurity.java
  7. 0
    42
      src/main/java/com/passionproject/project_spitball20/controller/UserController.java
  8. 21
    10
      src/main/java/com/passionproject/project_spitball20/controller/profiles/TeacherProfileController.java
  9. 52
    0
      src/main/java/com/passionproject/project_spitball20/controller/profiles/UserProfileController.java
  10. 56
    0
      src/main/java/com/passionproject/project_spitball20/controller/ratings/SchoolRatingController.java
  11. 9
    10
      src/main/java/com/passionproject/project_spitball20/controller/ratings/TeacherRatingController.java
  12. 51
    0
      src/main/java/com/passionproject/project_spitball20/controller/school/SchoolController.java
  13. 58
    0
      src/main/java/com/passionproject/project_spitball20/controller/school/SchoolWallController.java
  14. 42
    0
      src/main/java/com/passionproject/project_spitball20/model/School.java
  15. 27
    6
      src/main/java/com/passionproject/project_spitball20/model/Teacher.java
  16. 25
    10
      src/main/java/com/passionproject/project_spitball20/model/User.java
  17. 28
    0
      src/main/java/com/passionproject/project_spitball20/model/UserDetailsServiceImpl.java
  18. 42
    0
      src/main/java/com/passionproject/project_spitball20/model/ratings/SchoolRating.java
  19. 3
    2
      src/main/java/com/passionproject/project_spitball20/model/ratings/TeacherRating.java
  20. 0
    10
      src/main/java/com/passionproject/project_spitball20/repositories/RatingRepository.java
  21. 9
    0
      src/main/java/com/passionproject/project_spitball20/repositories/SchoolRepository.java
  22. 4
    0
      src/main/java/com/passionproject/project_spitball20/repositories/TeacherRepository.java
  23. 2
    0
      src/main/java/com/passionproject/project_spitball20/repositories/UserRepository.java
  24. 11
    0
      src/main/java/com/passionproject/project_spitball20/repositories/ratings/SchoolRatingRepository.java
  25. 10
    0
      src/main/java/com/passionproject/project_spitball20/repositories/ratings/TeacherRatingRepository.java
  26. 0
    33
      src/main/java/com/passionproject/project_spitball20/service/RatingService.java
  27. 11
    0
      src/main/java/com/passionproject/project_spitball20/service/TeacherService.java
  28. 7
    0
      src/main/java/com/passionproject/project_spitball20/service/UserService.java
  29. 40
    0
      src/main/java/com/passionproject/project_spitball20/service/ratings/SchoolRatingService.java
  30. 33
    0
      src/main/java/com/passionproject/project_spitball20/service/ratings/TeacherRatingService.java

+ 22
- 1
pom.xml 查看文件

@@ -43,8 +43,29 @@
43 43
             <artifactId>mysql-connector-java</artifactId>
44 44
             <scope>runtime</scope>
45 45
         </dependency>
46
+        <dependency>
47
+            <groupId>org.springframework.security</groupId>
48
+            <artifactId>spring-security-core</artifactId>
49
+            <version>5.0.6.RELEASE</version>
50
+        </dependency>
51
+		<dependency>
52
+			<groupId>io.jsonwebtoken</groupId>
53
+			<artifactId>jjwt</artifactId>
54
+			<version>0.2</version>
55
+		</dependency>
56
+        <dependency>
57
+            <groupId>org.springframework.security</groupId>
58
+            <artifactId>spring-security-web</artifactId>
59
+            <version>5.0.6.RELEASE</version>
60
+        </dependency>
61
+		<dependency>
62
+			<groupId>org.springframework.security</groupId>
63
+			<artifactId>spring-security-config</artifactId>
64
+			<version>5.0.6.RELEASE</version>
65
+		</dependency>
66
+
46 67
 
47
-        <!--<dependency>-->
68
+		<!--<dependency>-->
48 69
             <!--<groupId>com.h2database</groupId>-->
49 70
             <!--<artifactId>h2</artifactId>-->
50 71
         <!--</dependency>-->

+ 7
- 0
src/main/java/com/passionproject/project_spitball20/Application.java 查看文件

@@ -2,6 +2,8 @@ package com.passionproject.project_spitball20;
2 2
 
3 3
 import org.springframework.boot.SpringApplication;
4 4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5
+import org.springframework.context.annotation.Bean;
6
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
5 7
 
6 8
 @SpringBootApplication
7 9
 public class Application {
@@ -9,4 +11,9 @@ public class Application {
9 11
 	public static void main(String[] args) {
10 12
 		SpringApplication.run(Application.class, args);
11 13
 	}
14
+
15
+	@Bean
16
+	public BCryptPasswordEncoder bCryptPasswordEncoder() {
17
+		return new BCryptPasswordEncoder();
18
+	}
12 19
 }

+ 64
- 0
src/main/java/com/passionproject/project_spitball20/JWT/JWTAuthenticationFilter.java 查看文件

@@ -0,0 +1,64 @@
1
+package com.passionproject.project_spitball20.JWT;
2
+
3
+import com.fasterxml.jackson.databind.ObjectMapper;
4
+import io.jsonwebtoken.Jwts;
5
+import io.jsonwebtoken.SignatureAlgorithm;
6
+import org.springframework.security.authentication.AuthenticationManager;
7
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
8
+import org.springframework.security.core.Authentication;
9
+import org.springframework.security.core.AuthenticationException;
10
+import org.springframework.security.core.userdetails.User;
11
+import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
12
+
13
+import javax.servlet.FilterChain;
14
+import javax.servlet.ServletException;
15
+import javax.servlet.http.HttpServletRequest;
16
+import javax.servlet.http.HttpServletResponse;
17
+import java.io.IOException;
18
+import java.util.ArrayList;
19
+import java.util.Date;
20
+
21
+import static com.passionproject.project_spitball20.JWT.SecurityConstants.EXPIRATION_TIME;
22
+import static com.passionproject.project_spitball20.JWT.SecurityConstants.HEADER_STRING;
23
+import static com.passionproject.project_spitball20.JWT.SecurityConstants.SECRET;
24
+import static com.passionproject.project_spitball20.JWT.SecurityConstants.TOKEN_PREFIX;
25
+
26
+public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
27
+    private AuthenticationManager authenticationManager;
28
+
29
+    public JWTAuthenticationFilter(AuthenticationManager authenticationManager) {
30
+        this.authenticationManager = authenticationManager;
31
+    }
32
+
33
+    @Override
34
+    public Authentication attemptAuthentication(HttpServletRequest req,
35
+                                                HttpServletResponse res) throws AuthenticationException {
36
+        try {
37
+            com.passionproject.project_spitball20.model.User creds = new ObjectMapper()
38
+                    .readValue(req.getInputStream(), com.passionproject.project_spitball20.model.User.class);
39
+
40
+            return authenticationManager.authenticate(
41
+                    new UsernamePasswordAuthenticationToken(
42
+                            creds.getUsername(),
43
+                            creds.getPassword(),
44
+                            new ArrayList<>())
45
+            );
46
+        } catch (IOException e) {
47
+            throw new RuntimeException(e);
48
+        }
49
+    }
50
+
51
+    @Override
52
+    protected void successfulAuthentication(HttpServletRequest req,
53
+                                            HttpServletResponse res,
54
+                                            FilterChain chain,
55
+                                            Authentication auth) throws IOException, ServletException {
56
+
57
+        String token = Jwts.builder()
58
+                .setSubject(((User) auth.getPrincipal()).getUsername())
59
+                .setExpiration(new Date(System.currentTimeMillis() + EXPIRATION_TIME))
60
+                .signWith(SignatureAlgorithm.HS512, SECRET.getBytes())
61
+                .compact();
62
+        res.addHeader(HEADER_STRING, TOKEN_PREFIX + token);
63
+    }
64
+}

+ 60
- 0
src/main/java/com/passionproject/project_spitball20/JWT/JWTAuthorizationFilter.java 查看文件

@@ -0,0 +1,60 @@
1
+package com.passionproject.project_spitball20.JWT;
2
+
3
+import io.jsonwebtoken.Jwts;
4
+import org.springframework.security.authentication.AuthenticationManager;
5
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
6
+import org.springframework.security.core.context.SecurityContextHolder;
7
+import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
8
+
9
+import javax.servlet.FilterChain;
10
+import javax.servlet.ServletException;
11
+import javax.servlet.http.HttpServletRequest;
12
+import javax.servlet.http.HttpServletResponse;
13
+import java.io.IOException;
14
+import java.util.ArrayList;
15
+
16
+import static  com.passionproject.project_spitball20.JWT.SecurityConstants.HEADER_STRING;
17
+import static  com.passionproject.project_spitball20.JWT.SecurityConstants.SECRET;
18
+import static  com.passionproject.project_spitball20.JWT.SecurityConstants.TOKEN_PREFIX;
19
+
20
+public class JWTAuthorizationFilter extends BasicAuthenticationFilter {
21
+
22
+    public JWTAuthorizationFilter(AuthenticationManager authManager) {
23
+        super(authManager);
24
+    }
25
+
26
+    @Override
27
+    protected void doFilterInternal(HttpServletRequest req,
28
+                                    HttpServletResponse res,
29
+                                    FilterChain chain) throws IOException, ServletException {
30
+        String header = req.getHeader(HEADER_STRING);
31
+
32
+        if (header == null || !header.startsWith(TOKEN_PREFIX)) {
33
+            chain.doFilter(req, res);
34
+            return;
35
+        }
36
+
37
+        UsernamePasswordAuthenticationToken authentication = getAuthentication(req);
38
+
39
+        SecurityContextHolder.getContext().setAuthentication(authentication);
40
+        chain.doFilter(req, res);
41
+    }
42
+
43
+    private UsernamePasswordAuthenticationToken getAuthentication(HttpServletRequest request) {
44
+        String token = request.getHeader(HEADER_STRING);
45
+        if (token != null) {
46
+            // parse the token.
47
+            String user = Jwts.parser()
48
+                    .setSigningKey(SECRET.getBytes())
49
+                    .parseClaimsJws(token.replace(TOKEN_PREFIX, ""))
50
+                    .getBody()
51
+                    .getSubject();
52
+
53
+            if (user != null) {
54
+                return new UsernamePasswordAuthenticationToken(user, null, new ArrayList<>());
55
+            }
56
+            return null;
57
+        }
58
+        return null;
59
+    }
60
+}

+ 12
- 0
src/main/java/com/passionproject/project_spitball20/JWT/SecurityConstants.java 查看文件

@@ -0,0 +1,12 @@
1
+package com.passionproject.project_spitball20.JWT;
2
+
3
+public class SecurityConstants {
4
+
5
+    public static final String SECRET = "SecretKeyToGenJWTs";
6
+    public static final long EXPIRATION_TIME = 864_000_000; // 10 days
7
+    public static final String TOKEN_PREFIX = "Bearer ";
8
+    public static final String HEADER_STRING = "Authorization";
9
+    public static final String SIGN_UP_URL = "/user_profile/register_user";
10
+
11
+
12
+}

+ 54
- 0
src/main/java/com/passionproject/project_spitball20/JWT/WebSecurity.java 查看文件

@@ -0,0 +1,54 @@
1
+package com.passionproject.project_spitball20.JWT;
2
+
3
+import org.springframework.http.HttpMethod;
4
+import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
5
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
7
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
8
+import org.springframework.security.config.http.SessionCreationPolicy;
9
+import org.springframework.security.core.userdetails.UserDetailsService;
10
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
11
+import org.springframework.web.cors.CorsConfiguration;
12
+import org.springframework.web.cors.CorsConfigurationSource;
13
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
14
+import org.springframework.context.annotation.Bean;
15
+
16
+import static  com.passionproject.project_spitball20.JWT.SecurityConstants.SIGN_UP_URL;
17
+
18
+@EnableWebSecurity
19
+public class WebSecurity extends WebSecurityConfigurerAdapter {
20
+    private UserDetailsService userDetailsService;
21
+    private BCryptPasswordEncoder bCryptPasswordEncoder;
22
+
23
+    public WebSecurity(UserDetailsService userDetailsService, BCryptPasswordEncoder bCryptPasswordEncoder) {
24
+        this.userDetailsService = userDetailsService;
25
+        this.bCryptPasswordEncoder = bCryptPasswordEncoder;
26
+    }
27
+
28
+    @Override
29
+    protected void configure(HttpSecurity http) throws Exception {
30
+        http.cors().and().csrf().disable().authorizeRequests()
31
+                .antMatchers(HttpMethod.POST, SIGN_UP_URL).permitAll()
32
+                .anyRequest().authenticated()
33
+                .and()
34
+                .addFilter(new JWTAuthenticationFilter(authenticationManager()))
35
+                .addFilter(new JWTAuthorizationFilter(authenticationManager()))
36
+                // this disables session creation on Spring Security
37
+                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
38
+    }
39
+
40
+    @Override
41
+    public void configure(AuthenticationManagerBuilder auth) throws Exception {
42
+        auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder);
43
+    }
44
+
45
+    @Bean
46
+    CorsConfigurationSource corsConfigurationSource() {
47
+        final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
48
+        CorsConfiguration cors = new CorsConfiguration().applyPermitDefaultValues();
49
+        cors.addExposedHeader("Authorization");
50
+
51
+        source.registerCorsConfiguration("/**", cors);
52
+        return source;
53
+    }
54
+}

+ 0
- 42
src/main/java/com/passionproject/project_spitball20/controller/UserController.java 查看文件

@@ -1,42 +0,0 @@
1
-package com.passionproject.project_spitball20.controller;
2
-
3
-import com.passionproject.project_spitball20.model.User;
4
-import com.passionproject.project_spitball20.service.UserService;
5
-import org.slf4j.Logger;
6
-import org.slf4j.LoggerFactory;
7
-import org.springframework.beans.factory.annotation.Autowired;
8
-import org.springframework.http.HttpHeaders;
9
-import org.springframework.http.HttpStatus;
10
-import org.springframework.http.ResponseEntity;
11
-import org.springframework.web.bind.annotation.*;
12
-
13
-@CrossOrigin(origins = "http://localhost:8100")
14
-@RestController
15
-//@RequestMapping("user_profile")
16
-public class UserController {
17
-
18
-    @Autowired
19
-    UserService userService;
20
-
21
-    public static final Logger logger = LoggerFactory.getLogger(UserController.class);
22
-
23
-
24
-    @RequestMapping(value = "/register_user", method = RequestMethod.POST)
25
-    public ResponseEntity<User> registerUser(@RequestBody User newUser) {
26
-        User user = new User();
27
-        HttpStatus status = HttpStatus.CONFLICT;
28
-        if(userService.findEmail(newUser.getEmail()) == null){ //&& userService.findName(newUser.getDisplayName()).equals(null)) {
29
-            user = userService.save(newUser);
30
-            status  = HttpStatus.CREATED;
31
-        }
32
-
33
-        return new ResponseEntity<>(user, new HttpHeaders(), status);
34
-
35
-    }
36
-
37
-    @RequestMapping(value = "/delete_profile", method = RequestMethod.DELETE)
38
-    public ResponseEntity<User> deleteMessage(@RequestBody User user) {
39
-        userService.delete(user);
40
-        return new ResponseEntity<>(HttpStatus.OK);
41
-    }
42
-}

src/main/java/com/passionproject/project_spitball20/controller/TeacherController.java → src/main/java/com/passionproject/project_spitball20/controller/profiles/TeacherProfileController.java 查看文件

@@ -1,10 +1,8 @@
1
-package com.passionproject.project_spitball20.controller;
1
+package com.passionproject.project_spitball20.controller.profiles;
2 2
 
3 3
 
4 4
 import com.passionproject.project_spitball20.model.Teacher;
5
-import com.passionproject.project_spitball20.model.User;
6 5
 import com.passionproject.project_spitball20.service.TeacherService;
7
-import com.passionproject.project_spitball20.service.UserService;
8 6
 import org.slf4j.Logger;
9 7
 import org.slf4j.LoggerFactory;
10 8
 import org.springframework.beans.factory.annotation.Autowired;
@@ -15,21 +13,21 @@ import org.springframework.web.bind.annotation.*;
15 13
 
16 14
 
17 15
 @RestController
18
-@RequestMapping("teacher_profile")
16
+@RequestMapping("teachers")
19 17
 @CrossOrigin(origins = "http://localhost:8100")
20
-public class TeacherController {
18
+public class TeacherProfileController {
21 19
 
22 20
     @Autowired
23 21
     TeacherService teacherService;
24 22
 
25
-    public static final Logger logger = LoggerFactory.getLogger(UserController.class);
23
+    public static final Logger logger = LoggerFactory.getLogger(TeacherProfileController.class);
26 24
 
27 25
 
28 26
     @RequestMapping(value = "/register", method = RequestMethod.POST)
29
-    public ResponseEntity<Teacher> registerUser(@RequestBody Teacher newTeacher) {
27
+    public ResponseEntity<Teacher> registerTeacher(@RequestBody Teacher newTeacher) {
30 28
         Teacher teacher = new Teacher();
31 29
         HttpStatus status = HttpStatus.CONFLICT;
32
-        if(teacherService.findEmail(newTeacher.getEmail()).equals(null)){
30
+        if(teacherService.findEmail(newTeacher.getEmail()) == (null)){
33 31
             teacher = teacherService.save(newTeacher);
34 32
             status  = HttpStatus.CREATED;
35 33
         }
@@ -38,14 +36,27 @@ public class TeacherController {
38 36
 
39 37
     }
40 38
 
39
+    @RequestMapping(value = "/find_all", method = RequestMethod.HEAD)
40
+    public ResponseEntity<?> getAllTeachers() {
41
+        HttpStatus status = HttpStatus.OK;
42
+        return new ResponseEntity<>(teacherService.findAll(), new HttpHeaders(), status);
43
+    }
44
+
45
+    @RequestMapping(value = "/find_teacher", method = RequestMethod.GET)
46
+    public ResponseEntity<Teacher> getTeacher(@RequestBody Teacher teacher) {
47
+        HttpStatus httpStatus = HttpStatus.OK;
48
+        teacher = teacherService.find(teacher.getId());
49
+        return new ResponseEntity<>(teacher, new HttpHeaders(), httpStatus);
50
+    }
51
+
41 52
     @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
42
-    public ResponseEntity<Teacher> deleteRating(@RequestBody Teacher teacher) {
53
+    public ResponseEntity<Teacher> deleteTeacherProfile(@RequestBody Teacher teacher) {
43 54
         teacherService.delete(teacher);
44 55
         return new ResponseEntity<>(HttpStatus.OK);
45 56
     }
46 57
 
47 58
     @RequestMapping(value = "/update", method = RequestMethod.PUT)
48
-    public ResponseEntity<Teacher> updateRating(@RequestBody Teacher teacher) {
59
+    public ResponseEntity<Teacher> updateTeacherProfile(@RequestBody Teacher teacher) {
49 60
         HttpStatus httpStatus = HttpStatus.CREATED;
50 61
         teacher = this.teacherService.update(teacher);
51 62
 

+ 52
- 0
src/main/java/com/passionproject/project_spitball20/controller/profiles/UserProfileController.java 查看文件

@@ -0,0 +1,52 @@
1
+package com.passionproject.project_spitball20.controller.profiles;
2
+
3
+import com.passionproject.project_spitball20.model.User;
4
+import com.passionproject.project_spitball20.service.UserService;
5
+import org.slf4j.Logger;
6
+import org.slf4j.LoggerFactory;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.http.HttpHeaders;
9
+import org.springframework.http.HttpStatus;
10
+import org.springframework.http.ResponseEntity;
11
+import org.springframework.web.bind.annotation.*;
12
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
13
+
14
+
15
+
16
+@RestController
17
+@RequestMapping("user_profile")
18
+@CrossOrigin(origins = "http://localhost:8100")
19
+public class UserProfileController {
20
+
21
+    @Autowired
22
+    UserService userService;
23
+
24
+    @Autowired
25
+    private BCryptPasswordEncoder bCryptPasswordEncoder;
26
+
27
+   //public static final Logger logger = LoggerFactory.getLogger(UserController.class);
28
+
29
+
30
+    @RequestMapping(value = "/find_user", method = RequestMethod.GET)
31
+    public ResponseEntity<User> getUser(@RequestParam (name = "user_id", required = true) Long userId) {
32
+        HttpStatus httpStatus = HttpStatus.OK;
33
+        return new ResponseEntity<>(userService.find(userId), new HttpHeaders(), httpStatus);
34
+    }
35
+
36
+    @RequestMapping(value = "/register_user", method = RequestMethod.POST)
37
+    public ResponseEntity<User> registerUser(@RequestBody User newUser) {
38
+        HttpStatus status = HttpStatus.CONFLICT;
39
+        if (userService.findEmail(newUser.getEmail()) == null) {
40
+            newUser.setPassword(bCryptPasswordEncoder.encode(newUser.getPassword()));
41
+            newUser = userService.save(newUser);
42
+            status = HttpStatus.CREATED;
43
+        }
44
+        return new ResponseEntity<>(newUser, new HttpHeaders(), status);
45
+    }
46
+
47
+    @RequestMapping(value = "/delete_profile", method = RequestMethod.DELETE)
48
+    public ResponseEntity<User> deleteMessage(@RequestBody User user) {
49
+        userService.delete(user);
50
+        return new ResponseEntity<>(HttpStatus.OK);
51
+    }
52
+}

+ 56
- 0
src/main/java/com/passionproject/project_spitball20/controller/ratings/SchoolRatingController.java 查看文件

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

src/main/java/com/passionproject/project_spitball20/controller/RatingController.java → src/main/java/com/passionproject/project_spitball20/controller/ratings/TeacherRatingController.java 查看文件

@@ -1,11 +1,10 @@
1
-package com.passionproject.project_spitball20.controller;
1
+package com.passionproject.project_spitball20.controller.ratings;
2 2
 
3 3
 
4 4
 import com.fasterxml.jackson.core.JsonProcessingException;
5 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;
6
+import com.passionproject.project_spitball20.model.ratings.TeacherRating;
7
+import com.passionproject.project_spitball20.service.ratings.TeacherRatingService;
9 8
 import org.springframework.beans.factory.annotation.Autowired;
10 9
 import org.springframework.http.HttpHeaders;
11 10
 import org.springframework.http.HttpStatus;
@@ -16,26 +15,26 @@ import org.springframework.web.bind.annotation.*;
16 15
 @RestController
17 16
 @RequestMapping("ratings")
18 17
 @CrossOrigin(origins = "http://localhost:8100")
19
-public class RatingController {
18
+public class TeacherRatingController {
20 19
 
21 20
     @Autowired
22
-    RatingService ratingService;
21
+    TeacherRatingService ratingService;
23 22
 
24 23
     @RequestMapping(value = "/rate", method = RequestMethod.POST)
25
-    public ResponseEntity<Rating> newRating(@RequestBody Rating newRating) {
24
+    public ResponseEntity<TeacherRating> newRating(@RequestBody TeacherRating newRating) {
26 25
         HttpStatus httpStatus = HttpStatus.CREATED;
27
-        Rating rate = this.ratingService.save(newRating);
26
+        TeacherRating rate = this.ratingService.save(newRating);
28 27
 
29 28
         return new ResponseEntity<>(rate, new HttpHeaders(), httpStatus);
30 29
     }
31 30
     @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
32
-    public ResponseEntity<Rating> deleteRating(@RequestBody Rating rating) {
31
+    public ResponseEntity<TeacherRating> deleteRating(@RequestBody TeacherRating rating) {
33 32
         ratingService.delete(rating);
34 33
         return new ResponseEntity<>(HttpStatus.OK);
35 34
     }
36 35
 
37 36
     @RequestMapping(value = "/update", method = RequestMethod.PUT)
38
-    public ResponseEntity<Rating> updateRating(@RequestBody Rating rating) {
37
+    public ResponseEntity<TeacherRating> updateRating(@RequestBody TeacherRating rating) {
39 38
         HttpStatus httpStatus = HttpStatus.CREATED;
40 39
         rating = this.ratingService.update(rating);
41 40
 

+ 51
- 0
src/main/java/com/passionproject/project_spitball20/controller/school/SchoolController.java 查看文件

@@ -0,0 +1,51 @@
1
+package com.passionproject.project_spitball20.controller.school;
2
+
3
+import com.passionproject.project_spitball20.model.School;
4
+import com.passionproject.project_spitball20.model.Teacher;
5
+import com.passionproject.project_spitball20.repositories.SchoolRepository;
6
+import com.passionproject.project_spitball20.service.TeacherService;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.http.HttpHeaders;
9
+import org.springframework.http.HttpStatus;
10
+import org.springframework.http.ResponseEntity;
11
+import org.springframework.web.bind.annotation.*;
12
+
13
+@RestController
14
+@RequestMapping("schools")
15
+@CrossOrigin(origins = "http://localhost:8100")
16
+public class SchoolController {
17
+
18
+    @Autowired
19
+    SchoolRepository schoolRepo;
20
+
21
+    @Autowired
22
+    private TeacherService teacherService;
23
+
24
+    @RequestMapping(value = "/post", method = RequestMethod.POST)
25
+    public ResponseEntity<School> postReview(@RequestBody School newSchool) {
26
+        School school = new School();
27
+        HttpStatus status = HttpStatus.CONFLICT;
28
+        if(schoolRepo.findByName(school.getName()) == null) {
29
+            school = schoolRepo.saveAndFlush(newSchool);
30
+            status  = HttpStatus.CREATED;
31
+        }
32
+
33
+        return new ResponseEntity<>(school, new HttpHeaders(), status);
34
+    }
35
+
36
+    @RequestMapping(value = "/getAll_Teacher", method = RequestMethod.HEAD)
37
+    public ResponseEntity<?> getAllTeachers(Long id) {
38
+        HttpStatus status = HttpStatus.OK;
39
+        return new ResponseEntity<>(teacherService.findAllBySchool(id), new HttpHeaders(), status);
40
+    }
41
+
42
+    @RequestMapping(value = "/select_teacher", method = RequestMethod.GET)
43
+    public ResponseEntity<?> findTeachersBySchoolId(Long id) {
44
+        Teacher teacher = new Teacher();
45
+        HttpStatus status = HttpStatus.OK;
46
+        if(id == teacher.getSchoolId()) { teacher = teacherService.find(teacher.getSchoolId()); }
47
+        return new ResponseEntity<>(teacher , new HttpHeaders(), status);
48
+    }
49
+
50
+
51
+}

+ 58
- 0
src/main/java/com/passionproject/project_spitball20/controller/school/SchoolWallController.java 查看文件

@@ -0,0 +1,58 @@
1
+package com.passionproject.project_spitball20.controller.school;
2
+
3
+import com.passionproject.project_spitball20.model.School;
4
+import com.passionproject.project_spitball20.model.messages.Comment;
5
+import com.passionproject.project_spitball20.model.messages.Review;
6
+import com.passionproject.project_spitball20.repositories.SchoolRepository;
7
+import com.passionproject.project_spitball20.repositories.messages.CommentRepository;
8
+import com.passionproject.project_spitball20.service.messages.CommentService;
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.ResponseEntity;
13
+import org.springframework.web.bind.annotation.*;
14
+
15
+@RestController
16
+@RequestMapping("bulletin_board")
17
+@CrossOrigin(origins = "http://localhost:8100")
18
+public class SchoolWallController {
19
+
20
+    @Autowired
21
+    SchoolRepository schoolRepo;
22
+
23
+    @Autowired
24
+    CommentService commentService;
25
+
26
+    @RequestMapping(value = "/post", method = RequestMethod.POST)
27
+    public ResponseEntity<?> postToBoard(@RequestBody School newSchool) {
28
+        School school = new School();
29
+        HttpStatus status = HttpStatus.CONFLICT;
30
+        if(schoolRepo.findByName(school.getName()) == null) {
31
+            school = schoolRepo.saveAndFlush(newSchool);
32
+            status  = HttpStatus.CREATED;
33
+        }
34
+
35
+        return new ResponseEntity<>(school, new HttpHeaders(), status);
36
+    }
37
+
38
+//    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
39
+//    public ResponseEntity<?> deletePost(@RequestBody Review review) {
40
+//        reviewService.delete(review);
41
+//        return new ResponseEntity<>(HttpStatus.OK);
42
+//    }
43
+
44
+    @RequestMapping(value = "/post_comment", method = RequestMethod.POST)
45
+    public ResponseEntity<?> postReview(@RequestBody Comment newComment) {
46
+        HttpStatus httpStatus = HttpStatus.CREATED;
47
+        Comment comment  = commentService.save(newComment);
48
+
49
+        return new ResponseEntity<>(comment, new HttpHeaders(), httpStatus);
50
+    }
51
+
52
+
53
+    @RequestMapping(value = "/delete_comment", method = RequestMethod.DELETE)
54
+    public ResponseEntity<?> deleteComment(@RequestBody Comment comment) {
55
+        commentService.delete(comment);
56
+        return new ResponseEntity<>(HttpStatus.OK);
57
+    }
58
+}

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

@@ -0,0 +1,42 @@
1
+package com.passionproject.project_spitball20.model;
2
+
3
+
4
+import javax.persistence.*;
5
+import java.util.List;
6
+
7
+@Entity
8
+public class School {
9
+
10
+    @Id
11
+    @GeneratedValue(strategy = GenerationType.AUTO)
12
+    private Long id;
13
+
14
+    private String name;
15
+
16
+    @OneToMany(cascade = CascadeType.ALL, mappedBy = "schoolId")
17
+    private List<Teacher> teachers;
18
+
19
+    public Long getId() {
20
+        return id;
21
+    }
22
+
23
+    public void setId(Long id) {
24
+        this.id = id;
25
+    }
26
+
27
+    public String getName() {
28
+        return name;
29
+    }
30
+
31
+    public void setName(String name) {
32
+        this.name = name;
33
+    }
34
+
35
+    public List<Teacher> getTeachers() {
36
+        return teachers;
37
+    }
38
+
39
+    public void setTeachers(List<Teacher> teachers) {
40
+        this.teachers = teachers;
41
+    }
42
+}

+ 27
- 6
src/main/java/com/passionproject/project_spitball20/model/Teacher.java 查看文件

@@ -1,6 +1,7 @@
1 1
 package com.passionproject.project_spitball20.model;
2 2
 
3
-import org.hibernate.engine.internal.Cascade;
3
+import com.passionproject.project_spitball20.model.messages.Comment;
4
+import com.passionproject.project_spitball20.model.ratings.TeacherRating;
4 5
 
5 6
 import javax.persistence.*;
6 7
 import java.util.List;
@@ -19,9 +20,29 @@ public class Teacher {
19 20
     String password;
20 21
 
21 22
     @OneToMany(cascade = CascadeType.ALL)
22
-    @JoinColumn(name = "teacherId")
23
-    private List<Rating> ratings;
23
+    @JoinColumn
24
+    private List<TeacherRating> ratings;
24 25
 
26
+    @OneToMany
27
+    private List<Comment> comments;
28
+
29
+    private Long schoolId;
30
+
31
+    public List<Comment> getComments() {
32
+        return comments;
33
+    }
34
+
35
+    public void setComments(List<Comment> comments) {
36
+        this.comments = comments;
37
+    }
38
+
39
+    public Long getSchoolId() {
40
+        return schoolId;
41
+    }
42
+
43
+    public void setSchoolId(Long schoolId) {
44
+        this.schoolId = schoolId;
45
+    }
25 46
 
26 47
     public Long getId() {
27 48
         return id;
@@ -64,14 +85,14 @@ public class Teacher {
64 85
     }
65 86
 
66 87
     public String getFullName() {
67
-        return firstName + lastName;
88
+        return firstName + " " + lastName;
68 89
     }
69 90
 
70
-    public List<Rating> getRatings() {
91
+    public List<TeacherRating> getRatings() {
71 92
         return ratings;
72 93
     }
73 94
 
74
-    public void setRatings(List<Rating> ratings) {
95
+    public void setRatings(List<TeacherRating> ratings) {
75 96
         this.ratings = ratings;
76 97
     }
77 98
 }

+ 25
- 10
src/main/java/com/passionproject/project_spitball20/model/User.java 查看文件

@@ -1,6 +1,9 @@
1 1
 package com.passionproject.project_spitball20.model;
2 2
 
3
+import com.passionproject.project_spitball20.model.messages.Review;
4
+
3 5
 import javax.persistence.*;
6
+import java.util.List;
4 7
 
5 8
 @Entity
6 9
 @Table
@@ -8,17 +11,27 @@ public class User {
8 11
 
9 12
     @Id
10 13
     @GeneratedValue(strategy = GenerationType.AUTO)
11
-     private Long id;
14
+    private Long id;
15
+
16
+    String firstName;
17
+
18
+    String lastName;
19
+
20
+    String username;
12 21
 
13
-     String firstName;
22
+    String email;
14 23
 
15
-     String lastName;
24
+    String password;
16 25
 
17
-     String displayName;
26
+    @OneToMany
27
+    List<Review> reviews;
18 28
 
19
-     String email;
29
+    public User() {
30
+    }
20 31
 
21
-     String password;
32
+    public User(String username, String password, List<User> user) {
33
+        this.username = username; this.password = password;
34
+    }
22 35
 
23 36
     public Long getId() {
24 37
         return id;
@@ -44,12 +57,12 @@ public class User {
44 57
         this.lastName = lastName;
45 58
     }
46 59
 
47
-    public String getDisplayName() {
48
-        return displayName;
60
+    public String getUsername() {
61
+        return username;
49 62
     }
50 63
 
51
-    public void setDisplayName(String displayName) {
52
-        this.displayName = displayName;
64
+    public void setUsername(String username) {
65
+        this.username = username;
53 66
     }
54 67
 
55 68
     public String getEmail() {
@@ -67,4 +80,6 @@ public class User {
67 80
     public void setPassword(String password) {
68 81
         this.password = password;
69 82
     }
83
+
84
+
70 85
 }

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

@@ -0,0 +1,28 @@
1
+package com.passionproject.project_spitball20.model;
2
+
3
+
4
+import com.passionproject.project_spitball20.repositories.UserRepository;
5
+import org.springframework.security.core.userdetails.UserDetails;
6
+import org.springframework.security.core.userdetails.UserDetailsService;
7
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
8
+import org.springframework.stereotype.Service;
9
+
10
+import static java.util.Collections.emptyList;
11
+
12
+@Service
13
+public class UserDetailsServiceImpl implements UserDetailsService {
14
+    private UserRepository userRepository;
15
+
16
+    public UserDetailsServiceImpl(UserRepository userRepository) {
17
+        this.userRepository = userRepository;
18
+    }
19
+
20
+    @Override
21
+    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
22
+        com.passionproject.project_spitball20.model.User user = userRepository.findByUsername(username);
23
+        if (user == null) {
24
+            throw new UsernameNotFoundException(username);
25
+        }
26
+        return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), emptyList());
27
+    }
28
+}

+ 42
- 0
src/main/java/com/passionproject/project_spitball20/model/ratings/SchoolRating.java 查看文件

@@ -0,0 +1,42 @@
1
+package com.passionproject.project_spitball20.model.ratings;
2
+
3
+
4
+import javax.persistence.*;
5
+
6
+@Entity
7
+public class SchoolRating {
8
+
9
+    @Id
10
+    @GeneratedValue(strategy = GenerationType.AUTO)
11
+    private Long id;
12
+
13
+    @JoinColumn
14
+    Long schoolId;
15
+
16
+    Integer rating;
17
+
18
+    public Long getId() {
19
+        return id;
20
+    }
21
+
22
+    public void setId(Long id) {
23
+        this.id = id;
24
+    }
25
+
26
+    public Long getSchoolId() {
27
+        return schoolId;
28
+    }
29
+
30
+    public void setSchoolId(Long schoolId) {
31
+        this.schoolId = schoolId;
32
+    }
33
+
34
+    public Integer getRating() {
35
+        return rating;
36
+    }
37
+
38
+    public void setRating(Integer rating) {
39
+        this.rating = rating;
40
+    }
41
+
42
+}

src/main/java/com/passionproject/project_spitball20/model/Rating.java → src/main/java/com/passionproject/project_spitball20/model/ratings/TeacherRating.java 查看文件

@@ -1,4 +1,4 @@
1
-package com.passionproject.project_spitball20.model;
1
+package com.passionproject.project_spitball20.model.ratings;
2 2
 
3 3
 import com.passionproject.project_spitball20.model.messages.Review;
4 4
 import org.springframework.beans.factory.annotation.Autowired;
@@ -7,12 +7,13 @@ import javax.persistence.*;
7 7
 
8 8
 
9 9
 @Entity
10
-public class Rating {
10
+public class TeacherRating {
11 11
 
12 12
     @Id
13 13
     @GeneratedValue(strategy = GenerationType.AUTO)
14 14
     private Long id;
15 15
 
16
+    @JoinColumn
16 17
     Long teacherId;
17 18
 
18 19
     Integer rating;

+ 0
- 10
src/main/java/com/passionproject/project_spitball20/repositories/RatingRepository.java 查看文件

@@ -1,10 +0,0 @@
1
-package com.passionproject.project_spitball20.repositories;
2
-
3
-import com.passionproject.project_spitball20.model.Rating;
4
-import org.springframework.data.jpa.repository.JpaRepository;
5
-import org.springframework.stereotype.Repository;
6
-
7
-
8
-@Repository
9
-public interface RatingRepository extends JpaRepository<Rating, Long> {
10
-}

+ 9
- 0
src/main/java/com/passionproject/project_spitball20/repositories/SchoolRepository.java 查看文件

@@ -0,0 +1,9 @@
1
+package com.passionproject.project_spitball20.repositories;
2
+
3
+        import com.passionproject.project_spitball20.model.School;
4
+        import org.springframework.data.jpa.repository.JpaRepository;
5
+
6
+public interface SchoolRepository extends JpaRepository<School, Long> {
7
+
8
+    School findByName(String name);
9
+}

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

@@ -4,10 +4,14 @@ import com.passionproject.project_spitball20.model.Teacher;
4 4
 import org.springframework.data.jpa.repository.JpaRepository;
5 5
 import org.springframework.stereotype.Repository;
6 6
 
7
+import java.util.List;
8
+
7 9
 @Repository
8 10
 public interface TeacherRepository extends JpaRepository<Teacher, Long> {
9 11
 
10 12
     Teacher findByEmail(String email);
11 13
 
14
+    List<Teacher> findAllBySchoolId(Long id);
15
+
12 16
     //Teacher findByName(String fullName);
13 17
 }

+ 2
- 0
src/main/java/com/passionproject/project_spitball20/repositories/UserRepository.java 查看文件

@@ -7,6 +7,8 @@ import org.springframework.stereotype.Repository;
7 7
 @Repository
8 8
 public interface UserRepository extends JpaRepository<User, Long> {
9 9
 
10
+   User findByUsername(String username);
11
+
10 12
    User findByEmail(String email);
11 13
 
12 14
    //User findByName(String fullName);

+ 11
- 0
src/main/java/com/passionproject/project_spitball20/repositories/ratings/SchoolRatingRepository.java 查看文件

@@ -0,0 +1,11 @@
1
+//package com.passionproject.project_spitball20.repositories;
2
+//
3
+//import com.passionproject.project_spitball20.model.Rating;
4
+//import com.passionproject.project_spitball20.model.ratings.SchoolRating;
5
+//import org.springframework.data.jpa.repository.JpaRepository;
6
+//import org.springframework.stereotype.Repository;
7
+//
8
+//
9
+//@Repository
10
+//public interface SchoolRatingRepository extends JpaRepository<SchoolRating, Long> {
11
+//}

+ 10
- 0
src/main/java/com/passionproject/project_spitball20/repositories/ratings/TeacherRatingRepository.java 查看文件

@@ -0,0 +1,10 @@
1
+package com.passionproject.project_spitball20.repositories.ratings;
2
+
3
+import com.passionproject.project_spitball20.model.ratings.TeacherRating;
4
+import org.springframework.data.jpa.repository.JpaRepository;
5
+import org.springframework.stereotype.Repository;
6
+
7
+
8
+@Repository
9
+public interface TeacherRatingRepository extends JpaRepository<TeacherRating, Long> {
10
+}

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

@@ -1,33 +0,0 @@
1
-package com.passionproject.project_spitball20.service;
2
-
3
-import com.passionproject.project_spitball20.model.Rating;
4
-import com.passionproject.project_spitball20.repositories.RatingRepository;
5
-import org.springframework.beans.factory.annotation.Autowired;
6
-import org.springframework.stereotype.Service;
7
-
8
-@Service
9
-public class RatingService {
10
-
11
-
12
-    @Autowired
13
-    RatingRepository ratingRepository;
14
-
15
-    public Rating save(Rating rating) {
16
-        return ratingRepository.saveAndFlush(rating);
17
-    }
18
-
19
-    public Rating update(Rating rating) {
20
-        return ratingRepository.save(rating);
21
-    }
22
-
23
-    public void delete(Rating rating) {
24
-        ratingRepository.delete(rating);
25
-    }
26
-
27
-    public Rating find(Long id) {
28
-        return ratingRepository.findById(id).get();
29
-    }
30
-
31
-    public Object getAllRatings() { return ratingRepository.findAll(); }
32
-
33
-}

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

@@ -5,12 +5,16 @@ import com.passionproject.project_spitball20.repositories.TeacherRepository;
5 5
 import org.springframework.beans.factory.annotation.Autowired;
6 6
 import org.springframework.stereotype.Service;
7 7
 
8
+import java.util.List;
9
+
8 10
 @Service
9 11
 public class TeacherService {
10 12
 
11 13
     @Autowired
12 14
     TeacherRepository teacherRepository;
13 15
 
16
+    Teacher teacher;
17
+
14 18
     public Teacher save(Teacher teacher) {
15 19
         return teacherRepository.saveAndFlush(teacher);
16 20
     }
@@ -31,5 +35,12 @@ public class TeacherService {
31 35
         return teacherRepository.findByEmail(email);
32 36
     }
33 37
 
38
+    public List<Teacher> findAllBySchool(Long id) {
39
+        id = teacher.getSchoolId();
40
+        return teacherRepository.findAllBySchoolId(id);
41
+    }
42
+
43
+    public List<Teacher> findAll() { return teacherRepository.findAll();
44
+    }
34 45
 
35 46
 }

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

@@ -4,6 +4,8 @@ package com.passionproject.project_spitball20.service;
4 4
 import com.passionproject.project_spitball20.model.User;
5 5
 import com.passionproject.project_spitball20.repositories.UserRepository;
6 6
 import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.security.core.Authentication;
8
+import org.springframework.security.core.context.SecurityContextHolder;
7 9
 import org.springframework.stereotype.Service;
8 10
 
9 11
 @Service
@@ -32,5 +34,10 @@ public class UserService {
32 34
         return userRepository.findById(id).get();
33 35
     }
34 36
 
37
+    public User getLoggedInUser(){
38
+        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
39
+        return auth != null ? userRepository.findByEmail(auth.getName()) : null;
40
+    }
41
+
35 42
 
36 43
 }

+ 40
- 0
src/main/java/com/passionproject/project_spitball20/service/ratings/SchoolRatingService.java 查看文件

@@ -0,0 +1,40 @@
1
+//package com.passionproject.project_spitball20.service;
2
+//
3
+//import com.passionproject.project_spitball20.model.Rating;
4
+//import com.passionproject.project_spitball20.model.ratings.SchoolRating;
5
+//import com.passionproject.project_spitball20.model.Teacher;
6
+//import com.passionproject.project_spitball20.repositories.RatingRepository;
7
+//import com.passionproject.project_spitball20.repositories.SchoolRatingRepository;
8
+//import org.springframework.beans.factory.annotation.Autowired;
9
+//import org.springframework.stereotype.Service;
10
+//
11
+//import java.util.List;
12
+//
13
+//@Service
14
+//public class SchoolRatingService {
15
+//
16
+//
17
+//    @Autowired
18
+//    SchoolRatingRepository schoolRatingRepository;
19
+//
20
+//    public SchoolRating save(SchoolRating rating) {
21
+//        return schoolRatingRepository.saveAndFlush(rating);
22
+//    }
23
+//
24
+//    public SchoolRating update(SchoolRating rating) {
25
+//        return schoolRatingRepository.save(rating);
26
+//    }
27
+//
28
+//    public void delete(SchoolRating rating) {
29
+//        schoolRatingRepository.delete(rating);
30
+//    }
31
+//
32
+//    public SchoolRating find(Long id) {
33
+//        return schoolRatingRepository.findById(id).get();
34
+//    }
35
+//
36
+//    public List<SchoolRating> getAllTeachers(SchoolRating teacherId) { return schoolRatingRepository.findAllById(teacherId.getTeacherId());s }
37
+//
38
+//    public Object getAllRatings() { return schoolRatingRepository.findAll(); }
39
+//
40
+//}

+ 33
- 0
src/main/java/com/passionproject/project_spitball20/service/ratings/TeacherRatingService.java 查看文件

@@ -0,0 +1,33 @@
1
+package com.passionproject.project_spitball20.service.ratings;
2
+
3
+import com.passionproject.project_spitball20.model.ratings.TeacherRating;
4
+import com.passionproject.project_spitball20.repositories.ratings.TeacherRatingRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.stereotype.Service;
7
+
8
+@Service
9
+public class TeacherRatingService {
10
+
11
+
12
+    @Autowired
13
+    TeacherRatingRepository ratingRepository;
14
+
15
+    public TeacherRating save(TeacherRating rating) {
16
+        return ratingRepository.saveAndFlush(rating);
17
+    }
18
+
19
+    public TeacherRating update(TeacherRating rating) {
20
+        return ratingRepository.save(rating);
21
+    }
22
+
23
+    public void delete(TeacherRating rating) {
24
+        ratingRepository.delete(rating);
25
+    }
26
+
27
+//    public TeacherRating find(Long id) {
28
+//        return ratingRepository.findById(id).get();
29
+//    }
30
+
31
+    public Object getAllRatings() { return ratingRepository.findAll(); }
32
+
33
+}