2 Révisions

Auteur SHA1 Message Date
  rjsmall90 e10909cfbc ratings added updated i think il y a 6 ans
  rjsmall90 da62c8fba2 new new il y a 6 ans

+ 1
- 1
src/main/java/com/passionproject/project_spitball20/JWT/JWTAuthenticationFilter.java Voir le fichier

39
 
39
 
40
             return authenticationManager.authenticate(
40
             return authenticationManager.authenticate(
41
                     new UsernamePasswordAuthenticationToken(
41
                     new UsernamePasswordAuthenticationToken(
42
-                            creds.getDisplayName(),
42
+                            creds.getUsername(),
43
                             creds.getPassword(),
43
                             creds.getPassword(),
44
                             new ArrayList<>())
44
                             new ArrayList<>())
45
             );
45
             );

+ 4
- 1
src/main/java/com/passionproject/project_spitball20/JWT/WebSecurity.java Voir le fichier

45
     @Bean
45
     @Bean
46
     CorsConfigurationSource corsConfigurationSource() {
46
     CorsConfigurationSource corsConfigurationSource() {
47
         final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
47
         final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
48
-        source.registerCorsConfiguration("/**", new CorsConfiguration().applyPermitDefaultValues());
48
+        CorsConfiguration cors = new CorsConfiguration().applyPermitDefaultValues();
49
+        cors.addAllowedHeader("Authorization");
50
+
51
+        source.registerCorsConfiguration("/**", cors);
49
         return source;
52
         return source;
50
     }
53
     }
51
 }
54
 }

+ 51
- 0
src/main/java/com/passionproject/project_spitball20/controller/SchoolController.java Voir le fichier

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

+ 0
- 13
src/main/java/com/passionproject/project_spitball20/controller/SearchController.java Voir le fichier

1
-package com.passionproject.project_spitball20.controller;
2
-
3
-import org.springframework.web.bind.annotation.CrossOrigin;
4
-import org.springframework.web.bind.annotation.RequestMapping;
5
-import org.springframework.web.bind.annotation.RestController;
6
-
7
-@RestController
8
-@RequestMapping("search")
9
-@CrossOrigin(origins = "http://localhost:8100")
10
-public class SearchController {
11
-
12
-
13
-}

+ 1
- 1
src/main/java/com/passionproject/project_spitball20/controller/TeacherController.java Voir le fichier

15
 
15
 
16
 
16
 
17
 @RestController
17
 @RestController
18
-@RequestMapping("teacher_service")
18
+@RequestMapping("teachers")
19
 @CrossOrigin(origins = "http://localhost:8100")
19
 @CrossOrigin(origins = "http://localhost:8100")
20
 public class TeacherController {
20
 public class TeacherController {
21
 
21
 

+ 2
- 11
src/main/java/com/passionproject/project_spitball20/model/School.java Voir le fichier

1
 package com.passionproject.project_spitball20.model;
1
 package com.passionproject.project_spitball20.model;
2
 
2
 
3
-import com.passionproject.project_spitball20.model.ratings.SchoolRating;
4
 
3
 
5
 import javax.persistence.*;
4
 import javax.persistence.*;
6
 import java.util.List;
5
 import java.util.List;
14
 
13
 
15
     private String name;
14
     private String name;
16
 
15
 
17
-    @OneToMany(cascade = CascadeType.ALL)
18
-    @JoinColumn
19
-    private List<SchoolRating> ratings;
16
+    @OneToMany(cascade = CascadeType.ALL, mappedBy = "schoolId")
17
+    private List<Teacher> teachers;
20
 
18
 
21
     public Long getId() {
19
     public Long getId() {
22
         return id;
20
         return id;
34
         this.name = name;
32
         this.name = name;
35
     }
33
     }
36
 
34
 
37
-    public List<SchoolRating> getRatings() {
38
-        return ratings;
39
-    }
40
-
41
-    public void setRatings(List<SchoolRating> ratings) {
42
-        this.ratings = ratings;
43
-    }
44
 }
35
 }

+ 17
- 0
src/main/java/com/passionproject/project_spitball20/model/Teacher.java Voir le fichier

26
     @OneToMany
26
     @OneToMany
27
     private List<Comment> comments;
27
     private List<Comment> comments;
28
 
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
+    }
29
 
46
 
30
     public Long getId() {
47
     public Long getId() {
31
         return id;
48
         return id;

+ 7
- 7
src/main/java/com/passionproject/project_spitball20/model/User.java Voir le fichier

17
 
17
 
18
     String lastName;
18
     String lastName;
19
 
19
 
20
-    String displayName;
20
+    String username;
21
 
21
 
22
     String email;
22
     String email;
23
 
23
 
29
     public User() {
29
     public User() {
30
     }
30
     }
31
 
31
 
32
-    public User(String displayName, String password, List<User> user) {
33
-        this.displayName = displayName; this.password = password;
32
+    public User(String username, String password, List<User> user) {
33
+        this.username = username; this.password = password;
34
     }
34
     }
35
 
35
 
36
     public Long getId() {
36
     public Long getId() {
57
         this.lastName = lastName;
57
         this.lastName = lastName;
58
     }
58
     }
59
 
59
 
60
-    public String getDisplayName() {
61
-        return displayName;
60
+    public String getUsername() {
61
+        return username;
62
     }
62
     }
63
 
63
 
64
-    public void setDisplayName(String displayName) {
65
-        this.displayName = displayName;
64
+    public void setUsername(String username) {
65
+        this.username = username;
66
     }
66
     }
67
 
67
 
68
     public String getEmail() {
68
     public String getEmail() {

+ 2
- 2
src/main/java/com/passionproject/project_spitball20/model/UserDetailsServiceImpl.java Voir le fichier

19
 
19
 
20
     @Override
20
     @Override
21
     public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
21
     public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
22
-        com.passionproject.project_spitball20.model.User user = userRepository.findByDisplayName(username);
22
+        com.passionproject.project_spitball20.model.User user = userRepository.findByUsername(username);
23
         if (user == null) {
23
         if (user == null) {
24
             throw new UsernameNotFoundException(username);
24
             throw new UsernameNotFoundException(username);
25
         }
25
         }
26
-        return new org.springframework.security.core.userdetails.User(user.getDisplayName(), user.getPassword(), emptyList());
26
+        return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), emptyList());
27
     }
27
     }
28
 }
28
 }

+ 9
- 0
src/main/java/com/passionproject/project_spitball20/repositories/SchoolRepository.java Voir le fichier

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

+ 1
- 1
src/main/java/com/passionproject/project_spitball20/repositories/UserRepository.java Voir le fichier

7
 @Repository
7
 @Repository
8
 public interface UserRepository extends JpaRepository<User, Long> {
8
 public interface UserRepository extends JpaRepository<User, Long> {
9
 
9
 
10
-   User findByDisplayName(String displayname);
10
+   User findByUsername(String username);
11
 
11
 
12
    User findByEmail(String email);
12
    User findByEmail(String email);
13
 
13
 

+ 7
- 0
src/main/java/com/passionproject/project_spitball20/service/UserService.java Voir le fichier

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
32
         return userRepository.findById(id).get();
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
 }