Compare commits
No commits in common. "9f02207eb065467d7cae77725b39c4d395b3f470" and "198ee8a4ce03e46ea878acc16ea972184b22ef0a" have entirely different histories.
9f02207eb0
...
198ee8a4ce
@ -1,71 +0,0 @@
|
|||||||
package ovh.herisson.Clyde.EndPoints;
|
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
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.CursusCourseService;
|
|
||||||
import ovh.herisson.Clyde.Services.CursusService;
|
|
||||||
import ovh.herisson.Clyde.Tables.Cursus;
|
|
||||||
import ovh.herisson.Clyde.Tables.CursusCourse;
|
|
||||||
import ovh.herisson.Clyde.Tables.Role;
|
|
||||||
import ovh.herisson.Clyde.Tables.User;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class CursusController {
|
|
||||||
|
|
||||||
|
|
||||||
private final CursusService cursusServ;
|
|
||||||
private final AuthenticatorService authServ;
|
|
||||||
|
|
||||||
private final CursusCourseService cursusCourseServ;
|
|
||||||
|
|
||||||
public CursusController(CursusService cursusServ, AuthenticatorService authServ, CursusCourseService cursusCourseServ){
|
|
||||||
this.cursusServ = cursusServ;
|
|
||||||
this.authServ = authServ;
|
|
||||||
this.cursusCourseServ = cursusCourseServ;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/cursus/{id}")
|
|
||||||
public ResponseEntity<Cursus> findById(@PathVariable long id){
|
|
||||||
return new ResponseEntity<>(cursusServ.findById(id), HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/curriculums")
|
|
||||||
public ResponseEntity<Iterable<Map<String, Object>>> findAllindDepth(){
|
|
||||||
return new ResponseEntity<>(cursusCourseServ.getAllDepthCursus(),HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/curriculum")
|
|
||||||
public ResponseEntity<Iterable<CursusCourse>> findAll(){
|
|
||||||
return new ResponseEntity<>(cursusCourseServ.findAll(),HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**@PostMapping("/cursus")
|
|
||||||
public ResponseEntity<String> postCursus(@RequestHeader("Authorization") String token,@RequestBody Cursus cursus){
|
|
||||||
|
|
||||||
if (!isSecretaryOrAdmin(token)){
|
|
||||||
return new UnauthorizedResponse<>("you're not allowed to post a cursus");
|
|
||||||
}
|
|
||||||
|
|
||||||
cursusServ.save(cursus);
|
|
||||||
|
|
||||||
return new ResponseEntity<>("created !",HttpStatus.CREATED);
|
|
||||||
}**/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private boolean isSecretaryOrAdmin(String authorization){
|
|
||||||
if (authorization ==null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
User poster = authServ.getUserFromToken(authorization);
|
|
||||||
if (poster == null) return false;
|
|
||||||
|
|
||||||
return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin;
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,7 +7,6 @@ import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
|||||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||||
import ovh.herisson.Clyde.Services.InscriptionService;
|
import ovh.herisson.Clyde.Services.InscriptionService;
|
||||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
||||||
import ovh.herisson.Clyde.Tables.RequestState;
|
|
||||||
import ovh.herisson.Clyde.Tables.Role;
|
import ovh.herisson.Clyde.Tables.Role;
|
||||||
import ovh.herisson.Clyde.Tables.User;
|
import ovh.herisson.Clyde.Tables.User;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -29,7 +28,7 @@ public class InscriptionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/requests/register")
|
@GetMapping("/inscriptionRequests")
|
||||||
public ResponseEntity<Iterable<Map<String,Object>>> getAllRequests(@RequestHeader("Authorization") String token){
|
public ResponseEntity<Iterable<Map<String,Object>>> getAllRequests(@RequestHeader("Authorization") String token){
|
||||||
|
|
||||||
if (!isSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);}
|
if (!isSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);}
|
||||||
@ -45,29 +44,17 @@ public class InscriptionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/request/register/{id}")
|
@GetMapping("/inscriptionRequest/{id}")
|
||||||
public ResponseEntity<Map<String,Object>> getById(@PathVariable long id){
|
public ResponseEntity<Map<String,Object>> getById(@PathVariable long id){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
InscriptionRequest inscriptionRequest = inscriptionServ.getById(id);
|
InscriptionRequest inscriptionRequest = inscriptionServ.getById(id);
|
||||||
if (inscriptionRequest == null) {return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);}
|
if (inscriptionRequest == null) {return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);}
|
||||||
|
|
||||||
return new ResponseEntity<>(requestWithoutPassword(inscriptionRequest), HttpStatus.OK);
|
return new ResponseEntity<>(requestWithoutPassword(inscriptionRequest), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("request/user/{id}")
|
|
||||||
public ResponseEntity<InscriptionRequest> getUserInscriptionRequest(@PathVariable long id, @RequestHeader("Authorize") String token){
|
|
||||||
//todo return l'inscriptionRequest ACTUELLE du user (check si le poster est bien le même que id target ou secretariat)
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PatchMapping("/request/register/{id}")
|
|
||||||
public ResponseEntity<InscriptionRequest> changeRequestState(@PathVariable long id,
|
|
||||||
@RequestHeader("Authorize") String token,
|
|
||||||
@RequestBody RequestState requestState)
|
|
||||||
{
|
|
||||||
if (!isSecretaryOrAdmin(token)) return new UnauthorizedResponse<>(null);
|
|
||||||
inscriptionServ.modifyState(id, requestState);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String,Object> requestWithoutPassword(InscriptionRequest inscriptionRequest) {
|
private Map<String,Object> requestWithoutPassword(InscriptionRequest inscriptionRequest) {
|
||||||
Map<String, Object> toReturn = new HashMap<>();
|
Map<String, Object> toReturn = new HashMap<>();
|
||||||
@ -94,4 +81,4 @@ public class InscriptionController {
|
|||||||
|
|
||||||
return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin;
|
return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
package ovh.herisson.Clyde.EndPoints;
|
package ovh.herisson.Clyde.EndPoints;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import jakarta.persistence.Column;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||||
|
import ovh.herisson.Clyde.Tables.Cursus;
|
||||||
|
import ovh.herisson.Clyde.Tables.CursusType;
|
||||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
||||||
|
import ovh.herisson.Clyde.Tables.User;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||||
@ -30,7 +35,6 @@ public class LoginController {
|
|||||||
public LoginController(AuthenticatorService authServ){
|
public LoginController(AuthenticatorService authServ){
|
||||||
this.authServ = authServ;
|
this.authServ = authServ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/login")
|
@PostMapping(value = "/login")
|
||||||
public ResponseEntity<String> login(@RequestBody RequestLogin requestLogin){
|
public ResponseEntity<String> login(@RequestBody RequestLogin requestLogin){
|
||||||
|
|
||||||
@ -44,9 +48,12 @@ public class LoginController {
|
|||||||
return ResponseEntity.ok().headers(responseHeaders).build();
|
return ResponseEntity.ok().headers(responseHeaders).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/request/register")
|
@PostMapping("/register")
|
||||||
public ResponseEntity<String> register(@RequestBody InscriptionRequest inscriptionRequest){
|
public ResponseEntity<String> register(@RequestBody InscriptionRequest inscriptionRequest){
|
||||||
|
|
||||||
authServ.register(inscriptionRequest);
|
authServ.register(inscriptionRequest);
|
||||||
return new ResponseEntity<>("Is OK", HttpStatus.OK);
|
return new ResponseEntity<>("Is OK", HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import ovh.herisson.Clyde.Repositories.TokenRepository;
|
import ovh.herisson.Clyde.Repositories.TokenRepository;
|
||||||
import ovh.herisson.Clyde.Repositories.UserRepository;
|
import ovh.herisson.Clyde.Repositories.UserRepository;
|
||||||
import ovh.herisson.Clyde.Services.*;
|
import ovh.herisson.Clyde.Services.TokenService;
|
||||||
import ovh.herisson.Clyde.Tables.*;
|
import ovh.herisson.Clyde.Tables.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -20,19 +20,14 @@ public class MockController {
|
|||||||
public final UserRepository userRepo;
|
public final UserRepository userRepo;
|
||||||
public final TokenRepository tokenRepo;
|
public final TokenRepository tokenRepo;
|
||||||
public final TokenService tokenService;
|
public final TokenService tokenService;
|
||||||
public final CursusCourseService cursusCourseService;
|
|
||||||
public final CursusService cursusService;
|
|
||||||
public final CourseService courseService;
|
|
||||||
ArrayList<User> mockUsers;
|
ArrayList<User> mockUsers;
|
||||||
|
|
||||||
|
|
||||||
public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CursusCourseService cursusCourseService, CursusService cursusService, CourseService courseService){
|
public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService){
|
||||||
this.tokenRepo = tokenRepo;
|
this.tokenRepo = tokenRepo;
|
||||||
this.userRepo = userRepo;
|
this.userRepo = userRepo;
|
||||||
this.tokenService = tokenService;
|
this.tokenService = tokenService;
|
||||||
this.cursusCourseService = cursusCourseService;
|
|
||||||
this.cursusService = cursusService;
|
|
||||||
this.courseService = courseService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Saves an example of each user type by :
|
/** Saves an example of each user type by :
|
||||||
@ -44,9 +39,6 @@ public class MockController {
|
|||||||
@PostMapping("/mock")
|
@PostMapping("/mock")
|
||||||
public void postMock(){
|
public void postMock(){
|
||||||
|
|
||||||
// user part
|
|
||||||
|
|
||||||
|
|
||||||
User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand",new Date(0), null,Role.Admin,passwordEncoder.encode("admin"));
|
User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand",new Date(0), null,Role.Admin,passwordEncoder.encode("admin"));
|
||||||
User joe = new User("Mama","Joe","student@student.com","roundabout","DaWarudo",new Date(0), null,Role.Student,passwordEncoder.encode("student"));
|
User joe = new User("Mama","Joe","student@student.com","roundabout","DaWarudo",new Date(0), null,Role.Student,passwordEncoder.encode("student"));
|
||||||
User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0), null,Role.Teacher,passwordEncoder.encode("secretary"));
|
User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0), null,Role.Teacher,passwordEncoder.encode("secretary"));
|
||||||
@ -54,42 +46,6 @@ public class MockController {
|
|||||||
mockUsers = new ArrayList<User>(Arrays.asList(herobrine,joe,meh,joke));
|
mockUsers = new ArrayList<User>(Arrays.asList(herobrine,joe,meh,joke));
|
||||||
|
|
||||||
userRepo.saveAll(mockUsers);
|
userRepo.saveAll(mockUsers);
|
||||||
|
|
||||||
|
|
||||||
// Course / Curriculum part
|
|
||||||
|
|
||||||
Cursus infoBab1 = new Cursus(1,"info");
|
|
||||||
Cursus chemistryBab1 = new Cursus(1,"chemistry");
|
|
||||||
Cursus psychologyBab1 = new Cursus(1,"psychology");
|
|
||||||
|
|
||||||
cursusService.save(infoBab1);
|
|
||||||
cursusService.save(chemistryBab1);
|
|
||||||
cursusService.save(psychologyBab1);
|
|
||||||
|
|
||||||
|
|
||||||
Course progra1 = new Course(5,"Programmation et algorithimque 1","TODO DELETE");
|
|
||||||
Course chemistry1 = new Course(12, "Thermochimie","TODO DELETE");
|
|
||||||
Course psycho1 = new Course(21, "rien faire t'as cru c'est psycho", "TODO DELETE");
|
|
||||||
Course commun = new Course(2, "cours commun","TODO DELETE");
|
|
||||||
|
|
||||||
courseService.save(progra1);
|
|
||||||
courseService.save(chemistry1);
|
|
||||||
courseService.save(psycho1);
|
|
||||||
courseService.save(commun);
|
|
||||||
|
|
||||||
|
|
||||||
cursusCourseService.save(new CursusCourse(infoBab1,progra1));
|
|
||||||
cursusCourseService.save(new CursusCourse(infoBab1,commun));
|
|
||||||
|
|
||||||
cursusCourseService.save(new CursusCourse(psychologyBab1,psycho1));
|
|
||||||
cursusCourseService.save(new CursusCourse(psychologyBab1,commun));
|
|
||||||
|
|
||||||
|
|
||||||
cursusCourseService.save(new CursusCourse(chemistryBab1,commun));
|
|
||||||
cursusCourseService.save(new CursusCourse(chemistryBab1,chemistry1));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/mock")
|
@DeleteMapping("/mock")
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package ovh.herisson.Clyde.EndPoints;
|
package ovh.herisson.Clyde.EndPoints;
|
||||||
|
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||||
@ -9,6 +12,8 @@ import ovh.herisson.Clyde.Services.AuthenticatorService;
|
|||||||
import ovh.herisson.Clyde.Services.UserService;
|
import ovh.herisson.Clyde.Services.UserService;
|
||||||
import ovh.herisson.Clyde.Tables.Role;
|
import ovh.herisson.Clyde.Tables.Role;
|
||||||
import ovh.herisson.Clyde.Tables.User;
|
import ovh.herisson.Clyde.Tables.User;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -72,6 +77,8 @@ public class UserController {
|
|||||||
|
|
||||||
return new ResponseEntity<>("data modified", HttpStatus.OK);
|
return new ResponseEntity<>("data modified", HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** return user's data except password
|
/** return user's data except password
|
||||||
* @param user the user to return
|
* @param user the user to return
|
||||||
* @return all the user data without the password
|
* @return all the user data without the password
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
package ovh.herisson.Clyde.Repositories;
|
|
||||||
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
|
||||||
import ovh.herisson.Clyde.Tables.Course;
|
|
||||||
|
|
||||||
public interface CourseRepository extends CrudRepository<Course,Long> {
|
|
||||||
Course findById(long id);
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
package ovh.herisson.Clyde.Repositories;
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.Query;
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
|
||||||
import ovh.herisson.Clyde.Tables.Course;
|
|
||||||
import ovh.herisson.Clyde.Tables.Cursus;
|
|
||||||
import ovh.herisson.Clyde.Tables.CursusCourse;
|
|
||||||
|
|
||||||
public interface CursusCourseRepository extends CrudRepository<CursusCourse,Long> {
|
|
||||||
|
|
||||||
|
|
||||||
//todo faire custom query pour trouver tous les cours d'un cursus par un cursusId
|
|
||||||
|
|
||||||
@Query("select distinct cc.course from CursusCourse cc where cc.cursus = ?1")
|
|
||||||
Iterable<Course> findCoursesByCursus(Cursus cursus);
|
|
||||||
|
|
||||||
|
|
||||||
@Query("select distinct cc.cursus from CursusCourse cc")
|
|
||||||
Iterable<Cursus> findDistinctCursuses();
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package ovh.herisson.Clyde.Repositories;
|
|
||||||
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
|
||||||
import ovh.herisson.Clyde.Tables.Cursus;
|
|
||||||
|
|
||||||
public interface CursusRepository extends CrudRepository<Cursus,Long> {
|
|
||||||
Cursus findById(long id);
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
package ovh.herisson.Clyde.Services;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
|
||||||
import ovh.herisson.Clyde.Tables.Course;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class CourseService {
|
|
||||||
|
|
||||||
private final CourseRepository courseRepo;
|
|
||||||
|
|
||||||
public CourseService(CourseRepository courseRepo) {
|
|
||||||
this.courseRepo = courseRepo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(Course course){
|
|
||||||
courseRepo.save(course);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Course findById(long id){
|
|
||||||
return courseRepo.findById(id);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
package ovh.herisson.Clyde.Services;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
|
||||||
import ovh.herisson.Clyde.Repositories.CursusCourseRepository;
|
|
||||||
import ovh.herisson.Clyde.Repositories.CursusRepository;
|
|
||||||
import ovh.herisson.Clyde.Tables.Course;
|
|
||||||
import ovh.herisson.Clyde.Tables.Cursus;
|
|
||||||
import ovh.herisson.Clyde.Tables.CursusCourse;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class CursusCourseService {
|
|
||||||
|
|
||||||
private final CursusCourseRepository cursusCourseRepo;
|
|
||||||
|
|
||||||
private final CourseRepository courseRepo;
|
|
||||||
|
|
||||||
private final CursusRepository cursusRepo;
|
|
||||||
|
|
||||||
public CursusCourseService(CursusCourseRepository cursusCourseRepo, CourseRepository courseRepo, CursusRepository cursusRepo) {
|
|
||||||
this.cursusCourseRepo = cursusCourseRepo;
|
|
||||||
this.courseRepo = courseRepo;
|
|
||||||
this.cursusRepo = cursusRepo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(CursusCourse cursusCourse){
|
|
||||||
cursusCourseRepo.save(cursusCourse);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterable<CursusCourse> findAll(){
|
|
||||||
return cursusCourseRepo.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Map<String, Object> getDepthCursus(Cursus cursus){
|
|
||||||
|
|
||||||
HashMap<String ,Object> toReturn = new HashMap<>();
|
|
||||||
ArrayList<Course> courses = new ArrayList<>();
|
|
||||||
for (Course c: cursusCourseRepo.findCoursesByCursus(cursus)){
|
|
||||||
courses.add(c);
|
|
||||||
}
|
|
||||||
toReturn.put("courses",courses);
|
|
||||||
toReturn.put("cursusId",cursus.getCursusId());
|
|
||||||
toReturn.put("year",cursus.getYear());
|
|
||||||
toReturn.put("option",cursus.getOption());
|
|
||||||
|
|
||||||
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterable<Map<String, Object>> getAllDepthCursus(){
|
|
||||||
|
|
||||||
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Cursus cursus : cursusCourseRepo.findDistinctCursuses()){
|
|
||||||
toReturn.add(getDepthCursus(cursus));
|
|
||||||
}
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
package ovh.herisson.Clyde.Services;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
|
||||||
import ovh.herisson.Clyde.Repositories.CursusRepository;
|
|
||||||
import ovh.herisson.Clyde.Tables.Cursus;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class CursusService {
|
|
||||||
|
|
||||||
|
|
||||||
private final CursusRepository cursusRepo;
|
|
||||||
|
|
||||||
private final CourseRepository courseRepo;
|
|
||||||
|
|
||||||
public CursusService(CursusRepository cursusRepo, CourseRepository courseRepo){
|
|
||||||
this.cursusRepo = cursusRepo;
|
|
||||||
this.courseRepo = courseRepo;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void save(Cursus cursus){
|
|
||||||
cursusRepo.save(cursus);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cursus findById(long id){
|
|
||||||
return cursusRepo.findById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterable<Cursus> findAll(){
|
|
||||||
return cursusRepo.findAll();
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,32 +3,32 @@ package ovh.herisson.Clyde.Services;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ovh.herisson.Clyde.Repositories.InscriptionRepository;
|
import ovh.herisson.Clyde.Repositories.InscriptionRepository;
|
||||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
||||||
import ovh.herisson.Clyde.Tables.RequestState;
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class InscriptionService {
|
public class InscriptionService {
|
||||||
|
|
||||||
InscriptionRepository inscriptionRepo;
|
InscriptionRepository incriptionRepo;
|
||||||
|
public void save(InscriptionRequest inscriptionRequest){
|
||||||
public InscriptionService(InscriptionRepository inscriptionRepo){
|
incriptionRepo.save(inscriptionRequest);
|
||||||
this.inscriptionRepo = inscriptionRepo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(InscriptionRequest inscriptionRequest){
|
public InscriptionService(InscriptionRepository inscriptionRepo){
|
||||||
inscriptionRepo.save(inscriptionRequest);
|
this.incriptionRepo = inscriptionRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InscriptionRequest getById(long id){
|
public InscriptionRequest getById(long id){
|
||||||
return inscriptionRepo.findById(id);
|
InscriptionRequest inscriptionRequest = incriptionRepo.findById(id);
|
||||||
|
|
||||||
|
if (inscriptionRequest == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return inscriptionRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterable<InscriptionRequest> getAll(){
|
public Iterable<InscriptionRequest> getAll(){
|
||||||
return inscriptionRepo.findAll();
|
return incriptionRepo.findAll();
|
||||||
}
|
|
||||||
|
|
||||||
public void modifyState(long id, RequestState requestState) {
|
|
||||||
InscriptionRequest inscriptionRequest = getById(id);
|
|
||||||
inscriptionRequest.setState(requestState);
|
|
||||||
save(inscriptionRequest);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,6 +12,13 @@ public class Cursus {
|
|||||||
private int cursusId;
|
private int cursusId;
|
||||||
private int year;
|
private int year;
|
||||||
private String option;
|
private String option;
|
||||||
|
|
||||||
|
public static Cursus infoBab1 = new Cursus(1,"info");
|
||||||
|
|
||||||
|
public static Cursus chemistryBab1 = new Cursus(1,"chemistry");
|
||||||
|
|
||||||
|
public static Cursus psychologyBab1 = new Cursus(1,"psychology");
|
||||||
|
|
||||||
public Cursus(int year, String option){
|
public Cursus(int year, String option){
|
||||||
this.year = year;
|
this.year = year;
|
||||||
this.option = option;
|
this.option = option;
|
||||||
|
@ -8,11 +8,11 @@ public class CursusCourse {
|
|||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.EAGER)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "Cursus")
|
@JoinColumn(name = "Cursus")
|
||||||
private Cursus cursus;
|
private Cursus cursus;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.EAGER)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "Course")
|
@JoinColumn(name = "Course")
|
||||||
private Course course;
|
private Course course;
|
||||||
|
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package ovh.herisson.Clyde.Tables;
|
||||||
|
|
||||||
|
public enum CursusType {
|
||||||
|
|
||||||
|
infoBab1,
|
||||||
|
chemistryBab1,
|
||||||
|
psychologyBab1;
|
||||||
|
}
|
@ -1,15 +1,16 @@
|
|||||||
package ovh.herisson.Clyde.Tables;
|
package ovh.herisson.Clyde.Tables;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class ReinscriptionRequest {
|
public class ReinscriptionRequest {
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "Users")
|
@JoinColumn(name = "User")
|
||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
|
@ -3,14 +3,14 @@
|
|||||||
*
|
*
|
||||||
* TODO: On time of writing, the backend doesn't support these endpoints so it could be modified in the future.
|
* TODO: On time of writing, the backend doesn't support these endpoints so it could be modified in the future.
|
||||||
*/
|
*/
|
||||||
import {restGet, restPatch} from './restConsumer.js'
|
import { restGet, restPost } from './restConsumer.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create a new register requests that can be recovered by the registering service
|
* create a new register requests that can be recovered by the registering service
|
||||||
* TODO: add info in the Object (I don't know what will be needed)
|
* TODO: add info in the Object (I don't know what will be needed)
|
||||||
*/
|
*/
|
||||||
export async function createRegister(){
|
export async function createRegister(){
|
||||||
return restPost("/request/register");
|
return restPost("/requests/register");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,13 +29,13 @@ export async function createRegister(){
|
|||||||
*/
|
*/
|
||||||
export async function getRegisters(id){
|
export async function getRegisters(id){
|
||||||
if(id != null)
|
if(id != null)
|
||||||
return restGet("/request/register/" + id);
|
return restGet("/requests/register/" + id);
|
||||||
return restGet("/request/register")
|
return restGet("/requests/register")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the state of a requests.
|
* Change the state of a requests.
|
||||||
*/
|
*/
|
||||||
export async function validateRegister(id, state){
|
export async function validateRegister(id, state){
|
||||||
return restPatch("/request/register/" + id, {state: state});
|
return restPost("/requests/register/" + id, {state: state});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user