8 Ревизии

Автор SHA1 Съобщение Дата
  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 години
  rjsmall90 75050438cf persistence persisting, will set new branch for JWT in the morning преди 6 години
  rjsmall90 d884370e7a ratings added, comment & review updated преди 6 години
  rjsmall90 104c3a593c teacher fully integrated преди 6 години
  rjsmall90 93834f7b2c added Teacher profile преди 6 години
променени са 34 файла, в които са добавени 1164 реда и са изтрити 22 реда
  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. 51
    0
      src/main/java/com/passionproject/project_spitball20/controller/SchoolController.java
  8. 69
    0
      src/main/java/com/passionproject/project_spitball20/controller/TeacherController.java
  9. 26
    10
      src/main/java/com/passionproject/project_spitball20/controller/UserController.java
  10. 12
    0
      src/main/java/com/passionproject/project_spitball20/controller/messages/CommentController.java
  11. 56
    0
      src/main/java/com/passionproject/project_spitball20/controller/messages/ReviewController.java
  12. 56
    0
      src/main/java/com/passionproject/project_spitball20/controller/ratings/SchoolRatingController.java
  13. 56
    0
      src/main/java/com/passionproject/project_spitball20/controller/ratings/TeacherRatingController.java
  14. 35
    0
      src/main/java/com/passionproject/project_spitball20/model/School.java
  15. 98
    0
      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. 15
    0
      src/main/java/com/passionproject/project_spitball20/model/messages/Comment.java
  19. 62
    0
      src/main/java/com/passionproject/project_spitball20/model/messages/Review.java
  20. 42
    0
      src/main/java/com/passionproject/project_spitball20/model/ratings/SchoolRating.java
  21. 46
    0
      src/main/java/com/passionproject/project_spitball20/model/ratings/TeacherRating.java
  22. 9
    0
      src/main/java/com/passionproject/project_spitball20/repositories/SchoolRepository.java
  23. 13
    0
      src/main/java/com/passionproject/project_spitball20/repositories/TeacherRepository.java
  24. 4
    1
      src/main/java/com/passionproject/project_spitball20/repositories/UserRepository.java
  25. 11
    0
      src/main/java/com/passionproject/project_spitball20/repositories/messages/CommentRepository.java
  26. 10
    0
      src/main/java/com/passionproject/project_spitball20/repositories/messages/ReviewRepository.java
  27. 11
    0
      src/main/java/com/passionproject/project_spitball20/repositories/ratings/SchoolRatingRepository.java
  28. 10
    0
      src/main/java/com/passionproject/project_spitball20/repositories/ratings/TeacherRatingRepository.java
  29. 39
    0
      src/main/java/com/passionproject/project_spitball20/service/TeacherService.java
  30. 11
    0
      src/main/java/com/passionproject/project_spitball20/service/UserService.java
  31. 38
    0
      src/main/java/com/passionproject/project_spitball20/service/messages/CommentService.java
  32. 39
    0
      src/main/java/com/passionproject/project_spitball20/service/messages/ReviewService.java
  33. 40
    0
      src/main/java/com/passionproject/project_spitball20/service/ratings/SchoolRatingService.java
  34. 33
    0
      src/main/java/com/passionproject/project_spitball20/service/ratings/TeacherRatingService.java

+ 22
- 1
pom.xml Целия файл

43
             <artifactId>mysql-connector-java</artifactId>
43
             <artifactId>mysql-connector-java</artifactId>
44
             <scope>runtime</scope>
44
             <scope>runtime</scope>
45
         </dependency>
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
             <!--<groupId>com.h2database</groupId>-->
69
             <!--<groupId>com.h2database</groupId>-->
49
             <!--<artifactId>h2</artifactId>-->
70
             <!--<artifactId>h2</artifactId>-->
50
         <!--</dependency>-->
71
         <!--</dependency>-->

+ 7
- 0
src/main/java/com/passionproject/project_spitball20/Application.java Целия файл

2
 
2
 
3
 import org.springframework.boot.SpringApplication;
3
 import org.springframework.boot.SpringApplication;
4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
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
 @SpringBootApplication
8
 @SpringBootApplication
7
 public class Application {
9
 public class Application {
9
 	public static void main(String[] args) {
11
 	public static void main(String[] args) {
10
 		SpringApplication.run(Application.class, args);
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 Целия файл

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 Целия файл

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 Целия файл

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 Целия файл

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

+ 51
- 0
src/main/java/com/passionproject/project_spitball20/controller/SchoolController.java Целия файл

1
+package com.passionproject.project_spitball20.controller;
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() {
38
+        HttpStatus status = HttpStatus.OK;
39
+        return new ResponseEntity<>(teacherService.findAll(), 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
+}

+ 69
- 0
src/main/java/com/passionproject/project_spitball20/controller/TeacherController.java Целия файл

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

+ 26
- 10
src/main/java/com/passionproject/project_spitball20/controller/UserController.java Целия файл

9
 import org.springframework.http.HttpStatus;
9
 import org.springframework.http.HttpStatus;
10
 import org.springframework.http.ResponseEntity;
10
 import org.springframework.http.ResponseEntity;
11
 import org.springframework.web.bind.annotation.*;
11
 import org.springframework.web.bind.annotation.*;
12
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
13
+
14
+
12
 
15
 
13
-@CrossOrigin
14
 @RestController
16
 @RestController
15
-@RequestMapping("profile")
17
+@RequestMapping("user_profile")
18
+@CrossOrigin(origins = "http://localhost:8100")
16
 public class UserController {
19
 public class UserController {
17
 
20
 
18
     @Autowired
21
     @Autowired
19
     UserService userService;
22
     UserService userService;
20
 
23
 
21
-    public static final Logger logger = LoggerFactory.getLogger(UserController.class);
24
+    @Autowired
25
+    private BCryptPasswordEncoder bCryptPasswordEncoder;
26
+
27
+   //public static final Logger logger = LoggerFactory.getLogger(UserController.class);
22
 
28
 
23
 
29
 
24
-    @RequestMapping(value = "/register", method = RequestMethod.POST)
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)
25
     public ResponseEntity<User> registerUser(@RequestBody User newUser) {
37
     public ResponseEntity<User> registerUser(@RequestBody User newUser) {
26
-        User user = new User();
27
         HttpStatus status = HttpStatus.CONFLICT;
38
         HttpStatus status = HttpStatus.CONFLICT;
28
-        if(userService.findEmail(newUser.getEmail()).equals(null)) {
29
-            user = userService.save(newUser);
30
-            status  = HttpStatus.CREATED;
39
+        if (userService.findEmail(newUser.getEmail()) == null) {
40
+            newUser.setPassword(bCryptPasswordEncoder.encode(newUser.getPassword()));
41
+            newUser = userService.save(newUser);
42
+            status = HttpStatus.CREATED;
31
         }
43
         }
44
+        return new ResponseEntity<>(newUser, new HttpHeaders(), status);
45
+    }
32
 
46
 
33
-        return new ResponseEntity<>(user, new HttpHeaders(), status);
34
-
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);
35
     }
51
     }
36
 }
52
 }

+ 12
- 0
src/main/java/com/passionproject/project_spitball20/controller/messages/CommentController.java Целия файл

1
+package com.passionproject.project_spitball20.controller.messages;
2
+
3
+
4
+import org.springframework.web.bind.annotation.CrossOrigin;
5
+import org.springframework.web.bind.annotation.RequestMapping;
6
+import org.springframework.web.bind.annotation.RestController;
7
+
8
+@CrossOrigin
9
+@RestController
10
+@RequestMapping("comments")
11
+public class CommentController {
12
+}

+ 56
- 0
src/main/java/com/passionproject/project_spitball20/controller/messages/ReviewController.java Целия файл

1
+package com.passionproject.project_spitball20.controller.messages;
2
+
3
+
4
+import com.fasterxml.jackson.core.JsonProcessingException;
5
+import com.fasterxml.jackson.databind.ObjectMapper;
6
+import com.passionproject.project_spitball20.model.messages.Review;
7
+import com.passionproject.project_spitball20.service.messages.ReviewService;
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
+@CrossOrigin
16
+@RestController
17
+@RequestMapping("reviews")
18
+public class ReviewController {
19
+
20
+    @Autowired
21
+    ReviewService reviewService;
22
+
23
+    @RequestMapping(value = "/post", method = RequestMethod.POST)
24
+    public ResponseEntity<Review> postReview(@RequestBody Review newReview) {
25
+        HttpStatus httpStatus = HttpStatus.CREATED;
26
+        Review content = this.reviewService.save(newReview);
27
+
28
+        return new ResponseEntity<>(content, new HttpHeaders(), httpStatus);
29
+    }
30
+
31
+    @RequestMapping(value = "/update", method = RequestMethod.PUT)
32
+    public ResponseEntity<Review> updateReview(@RequestBody Review review) {
33
+        HttpStatus httpStatus = HttpStatus.CREATED;
34
+        review = this.reviewService.update(review);
35
+
36
+        return new ResponseEntity<>(review, new HttpHeaders(), httpStatus);
37
+    }
38
+
39
+    @RequestMapping(value = "/get_reviews", method = RequestMethod.GET)
40
+    public ResponseEntity<?> getAllReviews() throws JsonProcessingException {
41
+        ObjectMapper objectMapper = new ObjectMapper();
42
+        HttpStatus httpStatus = HttpStatus.CREATED;
43
+        HttpHeaders header = new HttpHeaders();
44
+
45
+        String messageJSON = objectMapper.writeValueAsString(this.reviewService.getAllReviews());
46
+        header.setContentType(MediaType.APPLICATION_JSON);
47
+
48
+        return new ResponseEntity<>(messageJSON, header, httpStatus);
49
+    }
50
+
51
+    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
52
+    public ResponseEntity<Review> deleteReview(@RequestBody Review review) {
53
+        reviewService.delete(review);
54
+        return new ResponseEntity<>(HttpStatus.OK);
55
+    }
56
+}

+ 56
- 0
src/main/java/com/passionproject/project_spitball20/controller/ratings/SchoolRatingController.java Целия файл

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
+//}

+ 56
- 0
src/main/java/com/passionproject/project_spitball20/controller/ratings/TeacherRatingController.java Целия файл

1
+package com.passionproject.project_spitball20.controller.ratings;
2
+
3
+
4
+import com.fasterxml.jackson.core.JsonProcessingException;
5
+import com.fasterxml.jackson.databind.ObjectMapper;
6
+import com.passionproject.project_spitball20.model.ratings.TeacherRating;
7
+import com.passionproject.project_spitball20.service.ratings.TeacherRatingService;
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 TeacherRatingController {
19
+
20
+    @Autowired
21
+    TeacherRatingService ratingService;
22
+
23
+    @RequestMapping(value = "/rate", method = RequestMethod.POST)
24
+    public ResponseEntity<TeacherRating> newRating(@RequestBody TeacherRating newRating) {
25
+        HttpStatus httpStatus = HttpStatus.CREATED;
26
+        TeacherRating 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<TeacherRating> deleteRating(@RequestBody TeacherRating rating) {
32
+        ratingService.delete(rating);
33
+        return new ResponseEntity<>(HttpStatus.OK);
34
+    }
35
+
36
+    @RequestMapping(value = "/update", method = RequestMethod.PUT)
37
+    public ResponseEntity<TeacherRating> updateRating(@RequestBody TeacherRating 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
+}

+ 35
- 0
src/main/java/com/passionproject/project_spitball20/model/School.java Целия файл

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

+ 98
- 0
src/main/java/com/passionproject/project_spitball20/model/Teacher.java Целия файл

1
+package com.passionproject.project_spitball20.model;
2
+
3
+import com.passionproject.project_spitball20.model.messages.Comment;
4
+import com.passionproject.project_spitball20.model.ratings.TeacherRating;
5
+
6
+import javax.persistence.*;
7
+import java.util.List;
8
+
9
+@Entity
10
+@Table
11
+public class Teacher {
12
+
13
+    @Id
14
+    @GeneratedValue(strategy = GenerationType.AUTO)
15
+    private Long id;
16
+
17
+    String firstName;
18
+    String lastName;
19
+    String email;
20
+    String password;
21
+
22
+    @OneToMany(cascade = CascadeType.ALL)
23
+    @JoinColumn
24
+    private List<TeacherRating> ratings;
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
+    }
46
+
47
+    public Long getId() {
48
+        return id;
49
+    }
50
+
51
+    public void setId(Long id) {
52
+        this.id = id;
53
+    }
54
+
55
+    public String getFirstName() {
56
+        return firstName;
57
+    }
58
+
59
+    public void setFirstName(String firstName) {
60
+        this.firstName = firstName;
61
+    }
62
+
63
+    public String getLastName() {
64
+        return lastName;
65
+    }
66
+
67
+    public void setLastName(String lastName) {
68
+        this.lastName = lastName;
69
+    }
70
+
71
+    public String getEmail() {
72
+        return email;
73
+    }
74
+
75
+    public void setEmail(String email) {
76
+        this.email = email;
77
+    }
78
+
79
+    public String getPassword() {
80
+        return password;
81
+    }
82
+
83
+    public void setPassword(String password) {
84
+        this.password = password;
85
+    }
86
+
87
+    public String getFullName() {
88
+        return firstName + " " + lastName;
89
+    }
90
+
91
+    public List<TeacherRating> getRatings() {
92
+        return ratings;
93
+    }
94
+
95
+    public void setRatings(List<TeacherRating> ratings) {
96
+        this.ratings = ratings;
97
+    }
98
+}

+ 25
- 10
src/main/java/com/passionproject/project_spitball20/model/User.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
+
3
 import javax.persistence.*;
5
 import javax.persistence.*;
6
+import java.util.List;
4
 
7
 
5
 @Entity
8
 @Entity
6
 @Table
9
 @Table
8
 
11
 
9
     @Id
12
     @Id
10
     @GeneratedValue(strategy = GenerationType.AUTO)
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
     public Long getId() {
36
     public Long getId() {
24
         return id;
37
         return id;
44
         this.lastName = lastName;
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
     public String getEmail() {
68
     public String getEmail() {
67
     public void setPassword(String password) {
80
     public void setPassword(String password) {
68
         this.password = password;
81
         this.password = password;
69
     }
82
     }
83
+
84
+
70
 }
85
 }

+ 28
- 0
src/main/java/com/passionproject/project_spitball20/model/UserDetailsServiceImpl.java Целия файл

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

+ 15
- 0
src/main/java/com/passionproject/project_spitball20/model/messages/Comment.java Целия файл

1
+package com.passionproject.project_spitball20.model.messages;
2
+
3
+
4
+import javax.persistence.*;
5
+
6
+
7
+@Entity
8
+@Table
9
+public class Comment extends Review {
10
+
11
+
12
+
13
+
14
+
15
+}

+ 62
- 0
src/main/java/com/passionproject/project_spitball20/model/messages/Review.java Целия файл

1
+package com.passionproject.project_spitball20.model.messages;
2
+
3
+import javax.persistence.*;
4
+import java.util.Date;
5
+
6
+@Entity
7
+@Table
8
+public class Review {
9
+
10
+    @Id
11
+    @GeneratedValue(strategy = GenerationType.AUTO)
12
+    private Long id;
13
+
14
+    private Long userId;
15
+
16
+    private Date created;
17
+
18
+    private Date updated;
19
+
20
+    String review;
21
+
22
+    public Long getId() {
23
+        return id;
24
+    }
25
+
26
+    public void setId(Long id) {
27
+        this.id = id;
28
+    }
29
+
30
+    public Long getUserId() {
31
+        return userId;
32
+    }
33
+
34
+    public void setUserId(Long userId) {
35
+        this.userId = userId;
36
+    }
37
+
38
+    public Date getCreated() {
39
+        return created;
40
+    }
41
+
42
+    public void setCreated(Date created) {
43
+        this.created = created;
44
+    }
45
+
46
+    public Date getUpdated() {
47
+        return updated;
48
+    }
49
+
50
+    public void setUpdated(Date updated) {
51
+        this.updated = updated;
52
+    }
53
+
54
+    public String getReview() {
55
+        return review;
56
+    }
57
+
58
+    public void setReview(String review) {
59
+        this.review = review;
60
+    }
61
+}
62
+

+ 42
- 0
src/main/java/com/passionproject/project_spitball20/model/ratings/SchoolRating.java Целия файл

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

+ 46
- 0
src/main/java/com/passionproject/project_spitball20/model/ratings/TeacherRating.java Целия файл

1
+package com.passionproject.project_spitball20.model.ratings;
2
+
3
+import com.passionproject.project_spitball20.model.messages.Review;
4
+import org.springframework.beans.factory.annotation.Autowired;
5
+
6
+import javax.persistence.*;
7
+
8
+
9
+@Entity
10
+public class TeacherRating {
11
+
12
+    @Id
13
+    @GeneratedValue(strategy = GenerationType.AUTO)
14
+    private Long id;
15
+
16
+    @JoinColumn
17
+    Long teacherId;
18
+
19
+    Integer rating;
20
+
21
+
22
+    public Long getId() {
23
+        return id;
24
+    }
25
+
26
+    public void setId(Long id) {
27
+        this.id = id;
28
+    }
29
+
30
+    public Long getTeacherId() {
31
+        return teacherId;
32
+    }
33
+
34
+    public void setTeacherId(Long teacherId) {
35
+        this.teacherId = teacherId;
36
+    }
37
+
38
+    public Integer getRating() {
39
+        return rating;
40
+    }
41
+
42
+    public void setRating(Integer rating) {
43
+        this.rating = rating;
44
+    }
45
+
46
+}

+ 9
- 0
src/main/java/com/passionproject/project_spitball20/repositories/SchoolRepository.java Целия файл

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

+ 13
- 0
src/main/java/com/passionproject/project_spitball20/repositories/TeacherRepository.java Целия файл

1
+package com.passionproject.project_spitball20.repositories;
2
+
3
+import com.passionproject.project_spitball20.model.Teacher;
4
+import org.springframework.data.jpa.repository.JpaRepository;
5
+import org.springframework.stereotype.Repository;
6
+
7
+@Repository
8
+public interface TeacherRepository extends JpaRepository<Teacher, Long> {
9
+
10
+    Teacher findByEmail(String email);
11
+
12
+    //Teacher findByName(String fullName);
13
+}

+ 4
- 1
src/main/java/com/passionproject/project_spitball20/repositories/UserRepository.java Целия файл

7
 @Repository
7
 @Repository
8
 public interface UserRepository extends JpaRepository<User, Long> {
8
 public interface UserRepository extends JpaRepository<User, Long> {
9
 
9
 
10
-   public User findByEmail(String email);
10
+   User findByUsername(String username);
11
 
11
 
12
+   User findByEmail(String email);
13
+
14
+   //User findByName(String fullName);
12
 
15
 
13
 }
16
 }

+ 11
- 0
src/main/java/com/passionproject/project_spitball20/repositories/messages/CommentRepository.java Целия файл

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

+ 10
- 0
src/main/java/com/passionproject/project_spitball20/repositories/messages/ReviewRepository.java Целия файл

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

+ 11
- 0
src/main/java/com/passionproject/project_spitball20/repositories/ratings/SchoolRatingRepository.java Целия файл

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 Целия файл

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

+ 39
- 0
src/main/java/com/passionproject/project_spitball20/service/TeacherService.java Целия файл

1
+package com.passionproject.project_spitball20.service;
2
+
3
+import com.passionproject.project_spitball20.model.Teacher;
4
+import com.passionproject.project_spitball20.repositories.TeacherRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.stereotype.Service;
7
+
8
+import java.util.List;
9
+
10
+@Service
11
+public class TeacherService {
12
+
13
+    @Autowired
14
+    TeacherRepository teacherRepository;
15
+
16
+    public Teacher save(Teacher teacher) {
17
+        return teacherRepository.saveAndFlush(teacher);
18
+    }
19
+
20
+    public Teacher update(Teacher teacher) {
21
+        return teacherRepository.save(teacher);
22
+    }
23
+
24
+    public Teacher find(Long id) {
25
+        return teacherRepository.findById(id).get();
26
+    }
27
+
28
+    public void delete(Teacher teacher) {
29
+        teacherRepository.delete(teacher);
30
+    }
31
+
32
+    public Teacher findEmail(String email) {
33
+        return teacherRepository.findByEmail(email);
34
+    }
35
+
36
+
37
+    public List<Teacher> findAll() { return teacherRepository.findAll();
38
+    }
39
+}

+ 11
- 0
src/main/java/com/passionproject/project_spitball20/service/UserService.java Целия файл

4
 import com.passionproject.project_spitball20.model.User;
4
 import com.passionproject.project_spitball20.model.User;
5
 import com.passionproject.project_spitball20.repositories.UserRepository;
5
 import com.passionproject.project_spitball20.repositories.UserRepository;
6
 import org.springframework.beans.factory.annotation.Autowired;
6
 import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.security.core.Authentication;
8
+import org.springframework.security.core.context.SecurityContextHolder;
7
 import org.springframework.stereotype.Service;
9
 import org.springframework.stereotype.Service;
8
 
10
 
9
 @Service
11
 @Service
20
         return userRepository.save(user);
22
         return userRepository.save(user);
21
     }
23
     }
22
 
24
 
25
+    public void delete(User user) {
26
+        userRepository.delete(user);
27
+    }
28
+
23
     public User findEmail(String email) {
29
     public User findEmail(String email) {
24
         return userRepository.findByEmail(email);
30
         return userRepository.findByEmail(email);
25
     }
31
     }
28
         return userRepository.findById(id).get();
34
         return userRepository.findById(id).get();
29
     }
35
     }
30
 
36
 
37
+    public User getLoggedInUser(){
38
+        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
39
+        return auth != null ? userRepository.findByEmail(auth.getName()) : null;
40
+    }
41
+
31
 
42
 
32
 }
43
 }

+ 38
- 0
src/main/java/com/passionproject/project_spitball20/service/messages/CommentService.java Целия файл

1
+package com.passionproject.project_spitball20.service.messages;
2
+
3
+
4
+import com.passionproject.project_spitball20.model.messages.Comment;
5
+import com.passionproject.project_spitball20.repositories.messages.CommentRepository;
6
+import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.stereotype.Service;
8
+
9
+import java.util.Date;
10
+
11
+@Service
12
+public class CommentService {
13
+
14
+    @Autowired
15
+    CommentRepository commentRepository;
16
+
17
+
18
+    public Comment save(Comment comment) {
19
+        comment.setCreated(new Date());
20
+        return commentRepository.save(comment);
21
+    }
22
+
23
+    public Comment update(Comment comment) {
24
+        Comment update = commentRepository.findById(comment.getId()).get();
25
+        update.setUpdated(new Date());
26
+        update.setReview(comment.getReview());
27
+        return commentRepository.save(update);
28
+
29
+    }
30
+
31
+    public Iterable<Comment> getAllComments() {
32
+        return commentRepository.findAll();
33
+    }
34
+
35
+    public void delete(Comment comment) {
36
+        commentRepository.delete(comment);
37
+    }
38
+}

+ 39
- 0
src/main/java/com/passionproject/project_spitball20/service/messages/ReviewService.java Целия файл

1
+package com.passionproject.project_spitball20.service.messages;
2
+
3
+
4
+import com.passionproject.project_spitball20.model.messages.Review;
5
+import com.passionproject.project_spitball20.repositories.messages.ReviewRepository;
6
+import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.stereotype.Service;
8
+
9
+import java.util.Date;
10
+
11
+@Service
12
+public class ReviewService {
13
+
14
+
15
+    @Autowired
16
+    ReviewRepository reviewRepository;
17
+
18
+
19
+    public Review save(Review review) {
20
+        review.setCreated(new Date());
21
+        return reviewRepository.save(review);
22
+    }
23
+
24
+    public Review update(Review review) {
25
+        Review update = reviewRepository.findById(review.getId()).get();
26
+        update.setUpdated(new Date());
27
+        update.setReview(review.getReview());
28
+        return reviewRepository.save(update);
29
+
30
+    }
31
+
32
+    public Iterable<Review> getAllReviews() {
33
+        return reviewRepository.findAll();
34
+    }
35
+
36
+    public void delete(Review review) {
37
+        reviewRepository.delete(review);
38
+    }
39
+}

+ 40
- 0
src/main/java/com/passionproject/project_spitball20/service/ratings/SchoolRatingService.java Целия файл

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 Целия файл

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