2 Commits

Autor SHA1 Mensagem Data
  rjsmall90 e10909cfbc ratings added updated i think 6 anos atrás
  rjsmall90 da62c8fba2 new new 6 anos atrás

+ 1
- 1
src/main/java/com/passionproject/project_spitball20/JWT/JWTAuthenticationFilter.java Ver arquivo

@@ -39,7 +39,7 @@ public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilte
39 39
 
40 40
             return authenticationManager.authenticate(
41 41
                     new UsernamePasswordAuthenticationToken(
42
-                            creds.getDisplayName(),
42
+                            creds.getUsername(),
43 43
                             creds.getPassword(),
44 44
                             new ArrayList<>())
45 45
             );

+ 4
- 1
src/main/java/com/passionproject/project_spitball20/JWT/WebSecurity.java Ver arquivo

@@ -45,7 +45,10 @@ public class WebSecurity extends WebSecurityConfigurerAdapter {
45 45
     @Bean
46 46
     CorsConfigurationSource corsConfigurationSource() {
47 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 52
         return source;
50 53
     }
51 54
 }

+ 51
- 0
src/main/java/com/passionproject/project_spitball20/controller/SchoolController.java Ver arquivo

@@ -0,0 +1,51 @@
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 Ver arquivo

@@ -1,13 +0,0 @@
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 Ver arquivo

@@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.*;
15 15
 
16 16
 
17 17
 @RestController
18
-@RequestMapping("teacher_service")
18
+@RequestMapping("teachers")
19 19
 @CrossOrigin(origins = "http://localhost:8100")
20 20
 public class TeacherController {
21 21
 

+ 2
- 11
src/main/java/com/passionproject/project_spitball20/model/School.java Ver arquivo

@@ -1,6 +1,5 @@
1 1
 package com.passionproject.project_spitball20.model;
2 2
 
3
-import com.passionproject.project_spitball20.model.ratings.SchoolRating;
4 3
 
5 4
 import javax.persistence.*;
6 5
 import java.util.List;
@@ -14,9 +13,8 @@ public class School {
14 13
 
15 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 19
     public Long getId() {
22 20
         return id;
@@ -34,11 +32,4 @@ public class School {
34 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 Ver arquivo

@@ -26,6 +26,23 @@ public class Teacher {
26 26
     @OneToMany
27 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 47
     public Long getId() {
31 48
         return id;

+ 7
- 7
src/main/java/com/passionproject/project_spitball20/model/User.java Ver arquivo

@@ -17,7 +17,7 @@ public class User {
17 17
 
18 18
     String lastName;
19 19
 
20
-    String displayName;
20
+    String username;
21 21
 
22 22
     String email;
23 23
 
@@ -29,8 +29,8 @@ public class User {
29 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 36
     public Long getId() {
@@ -57,12 +57,12 @@ public class User {
57 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 68
     public String getEmail() {

+ 2
- 2
src/main/java/com/passionproject/project_spitball20/model/UserDetailsServiceImpl.java Ver arquivo

@@ -19,10 +19,10 @@ public class UserDetailsServiceImpl implements UserDetailsService {
19 19
 
20 20
     @Override
21 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 23
         if (user == null) {
24 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 Ver arquivo

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

+ 1
- 1
src/main/java/com/passionproject/project_spitball20/repositories/UserRepository.java Ver arquivo

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

+ 7
- 0
src/main/java/com/passionproject/project_spitball20/service/UserService.java Ver arquivo

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