Compare commits
No commits in common. "a80fb2b2971c5ba675041fc0217e4b6d41073a56" and "7a23dcc96acbe4a2ef41bb22afd5a0fea8e2b7c7" have entirely different histories.
a80fb2b297
...
7a23dcc96a
@ -6,7 +6,6 @@ import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Services.InscriptionService;
|
||||
import ovh.herisson.Clyde.Services.ProtectionService;
|
||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
||||
import ovh.herisson.Clyde.Tables.RequestState;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
@ -35,8 +34,13 @@ public class InscriptionController {
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
Iterable<InscriptionRequest> inscriptionRequests = inscriptionServ.getAll();
|
||||
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.requestsWithoutPasswords(inscriptionRequests), HttpStatus.OK);
|
||||
for (InscriptionRequest i:inscriptionRequests){
|
||||
toReturn.add(requestWithoutPassword(i));
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(toReturn, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@ -51,21 +55,38 @@ public class InscriptionController {
|
||||
if (foundInscriptionRequest == null)
|
||||
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.requestWithoutPassword(foundInscriptionRequest), HttpStatus.OK);
|
||||
return new ResponseEntity<>(requestWithoutPassword(foundInscriptionRequest), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PatchMapping("/request/register/{id}")
|
||||
public ResponseEntity<InscriptionRequest> changeRequestState(@PathVariable long id,
|
||||
@RequestHeader("Authorization") String token,
|
||||
@RequestBody RequestState state)
|
||||
@RequestBody RequestState requestState)
|
||||
{
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.InscriptionService,Role.Admin},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
if (!inscriptionServ.modifyState(id, state))
|
||||
if (!inscriptionServ.modifyState(id, requestState))
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
private Map<String, Object> requestWithoutPassword(InscriptionRequest inscriptionRequest) {
|
||||
Map<String, Object> toReturn = new HashMap<>();
|
||||
|
||||
toReturn.put("id", inscriptionRequest.getId());
|
||||
toReturn.put("lastName", inscriptionRequest.getLastName());
|
||||
toReturn.put("firstName", inscriptionRequest.getFirstName());
|
||||
toReturn.put("address", inscriptionRequest.getAddress());
|
||||
toReturn.put("email",inscriptionRequest.getEmail());
|
||||
toReturn.put("birthDate", inscriptionRequest.getBirthDate());
|
||||
toReturn.put("country", inscriptionRequest.getCountry());
|
||||
toReturn.put("curriculum", inscriptionRequest.getCurriculumId());
|
||||
toReturn.put("state", inscriptionRequest.getState());
|
||||
toReturn.put("profilePictureUrl", inscriptionRequest.getProfilePicture());
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
@ -7,10 +7,8 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Services.ProtectionService;
|
||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
@ -47,10 +45,7 @@ public class LoginController {
|
||||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
public ResponseEntity<Map<String,Object>> register(@RequestBody InscriptionRequest inscriptionRequest){
|
||||
|
||||
InscriptionRequest returnedInscriptionRequest = authServ.register(inscriptionRequest);
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.requestWithoutPassword(returnedInscriptionRequest), HttpStatus.CREATED);
|
||||
public ResponseEntity<InscriptionRequest> register(@RequestBody InscriptionRequest inscriptionRequest){
|
||||
return new ResponseEntity<>(authServ.register(inscriptionRequest), HttpStatus.CREATED);
|
||||
}
|
||||
}
|
||||
|
@ -40,16 +40,6 @@ public class UserController {
|
||||
return new ResponseEntity<>(ProtectionService.userWithoutPassword(user), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/user/{id}")
|
||||
public ResponseEntity<HashMap<String ,Object>> getUserById(@RequestHeader("Authorization") String token, @PathVariable Long id){
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.userWithoutPassword(userService.getUserById(id)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/user")
|
||||
public ResponseEntity<Map<String ,Object>> postUser(@RequestBody User user,@RequestHeader("Authorization") String token){
|
||||
|
||||
@ -121,13 +111,4 @@ public class UserController {
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.usersWithoutPasswords(students), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@DeleteMapping("/user/{id}")
|
||||
public ResponseEntity<String> deleteStudent(@RequestHeader("Authorization") String token, @PathVariable Long id){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
userService.delete(userService.getUserById(id));
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -32,7 +32,6 @@ public class AuthenticatorService {
|
||||
}
|
||||
|
||||
public InscriptionRequest register(InscriptionRequest inscriptionRequest) {
|
||||
inscriptionRequest.setState(RequestState.Pending);
|
||||
return inscriptionService.save(inscriptionRequest);
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,10 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ProtectionService {
|
||||
|
||||
@ -63,32 +61,5 @@ public class ProtectionService {
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, Object> requestWithoutPassword(InscriptionRequest inscriptionRequest) {
|
||||
Map<String, Object> toReturn = new HashMap<>();
|
||||
|
||||
toReturn.put("id", inscriptionRequest.getId());
|
||||
toReturn.put("lastName", inscriptionRequest.getLastName());
|
||||
toReturn.put("firstName", inscriptionRequest.getFirstName());
|
||||
toReturn.put("address", inscriptionRequest.getAddress());
|
||||
toReturn.put("email",inscriptionRequest.getEmail());
|
||||
toReturn.put("birthDate", inscriptionRequest.getBirthDate());
|
||||
toReturn.put("country", inscriptionRequest.getCountry());
|
||||
toReturn.put("curriculum", inscriptionRequest.getCurriculumId());
|
||||
toReturn.put("state", inscriptionRequest.getState());
|
||||
toReturn.put("profilePictureUrl", inscriptionRequest.getProfilePicture());
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static Iterable<Map<String ,Object>> requestsWithoutPasswords(Iterable<InscriptionRequest> inscriptionRequests){
|
||||
|
||||
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
||||
|
||||
for (InscriptionRequest i:inscriptionRequests){
|
||||
toReturn.add(requestWithoutPassword(i));
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -122,12 +122,4 @@ public class UserService {
|
||||
public Iterable<User> getAllTeachers (){return userRepo.findAllTeachers();}
|
||||
|
||||
public Iterable<User> getAllStudents(){return userRepo.findAllStudents();}
|
||||
|
||||
public User getUserById(long id) {
|
||||
return userRepo.findById(id);
|
||||
}
|
||||
|
||||
public void delete(User user) {
|
||||
userRepo.delete(user);
|
||||
}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
package ovh.herisson.Clyde.Tables;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
|
||||
@Entity
|
||||
public class CurriculumCourse {
|
||||
@ -12,11 +10,9 @@ public class CurriculumCourse {
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "Curriculum")
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
private Curriculum curriculum;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
@JoinColumn(name = "Course")
|
||||
private Course course;
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
package ovh.herisson.Clyde.Tables;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
|
||||
@Entity
|
||||
public class ReInscriptionRequest {
|
||||
@ -12,12 +10,10 @@ public class ReInscriptionRequest {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "Users")
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
private User user;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "Curriculum")
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
private Curriculum newCurriculum;
|
||||
private RequestState state;
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
package ovh.herisson.Clyde.Tables;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
|
||||
@Entity
|
||||
public class TeacherCourse {
|
||||
@ -11,13 +9,11 @@ public class TeacherCourse {
|
||||
private int id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
@JoinColumn(name = "Users")
|
||||
private User user;
|
||||
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
@JoinColumn(name = "Course")
|
||||
private Course course;
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
package ovh.herisson.Clyde.Tables;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ -13,7 +11,6 @@ public class Token {
|
||||
private int id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
@JoinColumn(name ="Users")
|
||||
private User user;
|
||||
private String token;
|
||||
|
@ -1,8 +1,6 @@
|
||||
package ovh.herisson.Clyde.Tables;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
|
||||
@Entity
|
||||
public class UserCurriculum {
|
||||
@ -12,11 +10,10 @@ public class UserCurriculum {
|
||||
|
||||
//Un étudiant peut avoir plusieurs curriculums
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
@JoinColumn(name = "Users")
|
||||
private User user;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@OneToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "Curriculum")
|
||||
private Curriculum curriculum;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user