From 9aa425d1c3be9dfcd04bcf0d87173482c82999ef Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Thu, 14 Mar 2024 20:04:27 +0100 Subject: [PATCH 1/5] changed details --- .../Clyde/Services/InscriptionService.java | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java index 45495b7..4b2f6f4 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java @@ -4,31 +4,24 @@ import org.springframework.stereotype.Service; import ovh.herisson.Clyde.Repositories.InscriptionRepository; import ovh.herisson.Clyde.Tables.InscriptionRequest; -import java.util.HashMap; -import java.util.Map; - @Service public class InscriptionService { - InscriptionRepository incriptionRepo; - public void save(InscriptionRequest inscriptionRequest){ - incriptionRepo.save(inscriptionRequest); - } + InscriptionRepository inscriptionRepo; public InscriptionService(InscriptionRepository inscriptionRepo){ - this.incriptionRepo = inscriptionRepo; + this.inscriptionRepo = inscriptionRepo; + } + + public void save(InscriptionRequest inscriptionRequest){ + inscriptionRepo.save(inscriptionRequest); } public InscriptionRequest getById(long id){ - InscriptionRequest inscriptionRequest = incriptionRepo.findById(id); - - if (inscriptionRequest == null){ - return null; - } - return inscriptionRequest; + return inscriptionRepo.findById(id); } public Iterable getAll(){ - return incriptionRepo.findAll(); + return inscriptionRepo.findAll(); } } \ No newline at end of file From 12846ed83d4538284e06254d5d5da41d0a2baff0 Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Thu, 14 Mar 2024 21:53:43 +0100 Subject: [PATCH 2/5] added cursus/course interactions --- .../Clyde/EndPoints/CursusController.java | 71 +++++++++++++++++++ .../Clyde/EndPoints/LoginController.java | 7 +- .../Clyde/EndPoints/MockController.java | 56 +++++++++++++-- .../Clyde/EndPoints/UserController.java | 2 - .../Clyde/Repositories/CourseRepository.java | 8 +++ .../Repositories/CursusCourseRepository.java | 20 ++++++ .../Clyde/Repositories/CursusRepository.java | 8 +++ .../Clyde/Services/CourseService.java | 23 ++++++ .../Clyde/Services/CursusCourseService.java | 68 ++++++++++++++++++ .../Clyde/Services/CursusService.java | 36 ++++++++++ .../ovh/herisson/Clyde/Tables/Cursus.java | 7 -- .../herisson/Clyde/Tables/CursusCourse.java | 4 +- .../ovh/herisson/Clyde/Tables/CursusType.java | 8 --- .../Clyde/Tables/InscriptionRequest.java | 3 + .../Clyde/Tables/ReinscriptionRequest.java | 9 ++- 15 files changed, 295 insertions(+), 35 deletions(-) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/EndPoints/CursusController.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/CourseRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusCourseRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/CourseService.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/CursusCourseService.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/CursusService.java delete mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/CursusType.java diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CursusController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CursusController.java new file mode 100644 index 0000000..670865f --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CursusController.java @@ -0,0 +1,71 @@ +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 findById(@PathVariable long id){ + return new ResponseEntity<>(cursusServ.findById(id), HttpStatus.OK); + } + + @GetMapping("/curriculums") + public ResponseEntity>> findAllindDepth(){ + return new ResponseEntity<>(cursusCourseServ.getAllDepthCursus(),HttpStatus.OK); + } + + @GetMapping("/curriculum") + public ResponseEntity> findAll(){ + return new ResponseEntity<>(cursusCourseServ.findAll(),HttpStatus.OK); + } + + /**@PostMapping("/cursus") + public ResponseEntity 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; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java index 20542b5..bc6222e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java @@ -1,19 +1,14 @@ package ovh.herisson.Clyde.EndPoints; import com.fasterxml.jackson.annotation.JsonFormat; -import jakarta.persistence.Column; import org.springframework.http.HttpHeaders; 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.Tables.Cursus; -import ovh.herisson.Clyde.Tables.CursusType; import ovh.herisson.Clyde.Tables.InscriptionRequest; -import ovh.herisson.Clyde.Tables.User; import java.util.Date; -import java.util.HashMap; @RestController @CrossOrigin(originPatterns = "*", allowCredentials = "true") @@ -35,6 +30,7 @@ public class LoginController { public LoginController(AuthenticatorService authServ){ this.authServ = authServ; } + @PostMapping(value = "/login") public ResponseEntity login(@RequestBody RequestLogin requestLogin){ @@ -50,7 +46,6 @@ public class LoginController { @PostMapping("/register") public ResponseEntity register(@RequestBody InscriptionRequest inscriptionRequest){ - authServ.register(inscriptionRequest); return new ResponseEntity<>("Is OK", HttpStatus.OK); } diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java index b140057..5b1306c 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -7,10 +7,8 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; import ovh.herisson.Clyde.Repositories.TokenRepository; import ovh.herisson.Clyde.Repositories.UserRepository; -import ovh.herisson.Clyde.Services.TokenService; -import ovh.herisson.Clyde.Tables.Role; -import ovh.herisson.Clyde.Tables.Token; -import ovh.herisson.Clyde.Tables.User; +import ovh.herisson.Clyde.Services.*; +import ovh.herisson.Clyde.Tables.*; import java.util.ArrayList; import java.util.Arrays; @@ -26,13 +24,22 @@ public class MockController { public final UserRepository userRepo; public final TokenRepository tokenRepo; public final TokenService tokenService; + + public final CursusCourseService cursusCourseService; + + public final CursusService cursusService; + + public final CourseService courseService; ArrayList mockUsers; - public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService){ + public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CursusCourseService cursusCourseService, CursusService cursusService, CourseService courseService){ this.tokenRepo = tokenRepo; this.userRepo = userRepo; this.tokenService = tokenService; + this.cursusCourseService = cursusCourseService; + this.cursusService = cursusService; + this.courseService = courseService; } /** Saves an example of each user type by : @@ -44,6 +51,9 @@ public class MockController { @PostMapping("/mock") 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 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")); @@ -52,6 +62,42 @@ public class MockController { mockUsers = new ArrayList(Arrays.asList(herobrine,joe,meh,joke)); 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") diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java index 43bcd0c..996905a 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java @@ -41,7 +41,5 @@ public class UserController { public Iterable getAllUsers(){ return userService.getAll(); } - - } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/CourseRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CourseRepository.java new file mode 100644 index 0000000..671a995 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CourseRepository.java @@ -0,0 +1,8 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.Course; + +public interface CourseRepository extends CrudRepository { + Course findById(long id); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusCourseRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusCourseRepository.java new file mode 100644 index 0000000..b0cba44 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusCourseRepository.java @@ -0,0 +1,20 @@ +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 { + + + //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 findCoursesByCursus(Cursus cursus); + + + @Query("select distinct cc.cursus from CursusCourse cc") + Iterable findDistinctCursuses(); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusRepository.java new file mode 100644 index 0000000..0e84688 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusRepository.java @@ -0,0 +1,8 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.Cursus; + +public interface CursusRepository extends CrudRepository { + Cursus findById(long id); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/CourseService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/CourseService.java new file mode 100644 index 0000000..368dbb2 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/CourseService.java @@ -0,0 +1,23 @@ +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); + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/CursusCourseService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/CursusCourseService.java new file mode 100644 index 0000000..95b31de --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/CursusCourseService.java @@ -0,0 +1,68 @@ +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 findAll(){ + return cursusCourseRepo.findAll(); + } + + + public Map getDepthCursus(Cursus cursus){ + + HashMap toReturn = new HashMap<>(); + ArrayList 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> getAllDepthCursus(){ + + ArrayList> toReturn = new ArrayList<>(); + + for (Cursus cursus : cursusCourseRepo.findDistinctCursuses()){ + toReturn.add(getDepthCursus(cursus)); + } + return toReturn; + } + + + + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/CursusService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/CursusService.java new file mode 100644 index 0000000..0258ec8 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/CursusService.java @@ -0,0 +1,36 @@ +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 findAll(){ + return cursusRepo.findAll(); + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java index 172ec7d..d124179 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java @@ -12,13 +12,6 @@ public class Cursus { private int cursusId; private int year; 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){ this.year = year; this.option = option; diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java index ecdd857..111cb78 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java @@ -8,11 +8,11 @@ public class CursusCourse { @GeneratedValue(strategy = GenerationType.AUTO) private int id; - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "Cursus") private Cursus cursus; - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "Course") private Course course; diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusType.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusType.java deleted file mode 100644 index 5e9c50f..0000000 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusType.java +++ /dev/null @@ -1,8 +0,0 @@ -package ovh.herisson.Clyde.Tables; - -public enum CursusType { - - infoBab1, - chemistryBab1, - psychologyBab1; -} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java index 9b6ef95..aecebe2 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java @@ -4,7 +4,10 @@ import jakarta.persistence.*; import java.util.Date; + +@Entity public class InscriptionRequest { + @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; private String firstName; diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java index 8a56f88..9369c80 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java @@ -1,16 +1,15 @@ package ovh.herisson.Clyde.Tables; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; +import jakarta.persistence.*; +@Entity public class ReinscriptionRequest { + @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; @ManyToOne - @JoinColumn(name = "User") + @JoinColumn(name = "Users") private User user; @ManyToOne From 1bff48a4b99c769b6f6a38c974640f3d952b8608 Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Fri, 15 Mar 2024 17:09:18 +0100 Subject: [PATCH 3/5] changed the frontend API calls to better suit the backend and logic (register => list and register => single item) --- frontend/src/rest/ServiceInscription.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/rest/ServiceInscription.js b/frontend/src/rest/ServiceInscription.js index ee75c3b..aa90768 100644 --- a/frontend/src/rest/ServiceInscription.js +++ b/frontend/src/rest/ServiceInscription.js @@ -3,14 +3,14 @@ * * TODO: On time of writing, the backend doesn't support these endpoints so it could be modified in the future. */ -import { restGet } from './restConsumer.js' +import {restGet, restPatch} from './restConsumer.js' /** * 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) */ export async function createRegister(){ - return restPost("/requests/register"}); + return restPost("/request/register"}); } /** @@ -24,12 +24,12 @@ export async function getRegisters(){ * Get info on a particular registering request */ export async function getRegisters(id){ - return restGet("/requests/register/" + id); + return restGet("/request/register/" + id); } /** * Change the state of a requests. */ export async function validateRegister(id, state){ - return restPost("/requests/register/" + id, {state: state}); + return restPatch("/request/register/" + id, {state: state}); } From 017235cccfc5164f9d98a5754d97b0e3f5b9a7f3 Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Fri, 15 Mar 2024 17:29:45 +0100 Subject: [PATCH 4/5] fixed inscription in the backend --- .../EndPoints/InscriptionController.java | 25 ++++++++++++++----- .../Clyde/EndPoints/LoginController.java | 6 ++--- .../Clyde/Services/InscriptionService.java | 7 ++++++ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java index a997c54..7757242 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java @@ -7,6 +7,7 @@ import ovh.herisson.Clyde.Responses.UnauthorizedResponse; import ovh.herisson.Clyde.Services.AuthenticatorService; import ovh.herisson.Clyde.Services.InscriptionService; import ovh.herisson.Clyde.Tables.InscriptionRequest; +import ovh.herisson.Clyde.Tables.RequestState; import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.User; import java.util.ArrayList; @@ -28,7 +29,7 @@ public class InscriptionController { } - @GetMapping("/inscriptionRequests") + @GetMapping("/requests/register") public ResponseEntity>> getAllRequests(@RequestHeader("Authorization") String token){ if (!isSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);} @@ -44,17 +45,29 @@ public class InscriptionController { } - @GetMapping("/inscriptionRequest/{id}") + @GetMapping("/request/register/{id}") public ResponseEntity> getById(@PathVariable long id){ - - - InscriptionRequest inscriptionRequest = inscriptionServ.getById(id); if (inscriptionRequest == null) {return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);} return new ResponseEntity<>(requestWithoutPassword(inscriptionRequest), HttpStatus.OK); } + @GetMapping("request/user/{id}") + public ResponseEntity 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 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 requestWithoutPassword(InscriptionRequest inscriptionRequest) { Map toReturn = new HashMap<>(); @@ -81,4 +94,4 @@ public class InscriptionController { return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin; } -} +} \ No newline at end of file diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java index bc6222e..a47603b 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java @@ -44,11 +44,9 @@ public class LoginController { return ResponseEntity.ok().headers(responseHeaders).build(); } - @PostMapping("/register") + @PostMapping("/request/register") public ResponseEntity register(@RequestBody InscriptionRequest inscriptionRequest){ authServ.register(inscriptionRequest); return new ResponseEntity<>("Is OK", HttpStatus.OK); } -} - - +} \ No newline at end of file diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java index 4b2f6f4..f1bd092 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java @@ -3,6 +3,7 @@ package ovh.herisson.Clyde.Services; import org.springframework.stereotype.Service; import ovh.herisson.Clyde.Repositories.InscriptionRepository; import ovh.herisson.Clyde.Tables.InscriptionRequest; +import ovh.herisson.Clyde.Tables.RequestState; @Service public class InscriptionService { @@ -24,4 +25,10 @@ public class InscriptionService { public Iterable getAll(){ return inscriptionRepo.findAll(); } + + public void modifyState(long id, RequestState requestState) { + InscriptionRequest inscriptionRequest = getById(id); + inscriptionRequest.setState(requestState); + save(inscriptionRequest); + } } \ No newline at end of file From 2ea6ed16bb64b8be0d66ee1a932272739100c13e Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Fri, 15 Mar 2024 18:53:58 +0100 Subject: [PATCH 5/5] removed missclick --- frontend/src/rest/ServiceInscription.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/rest/ServiceInscription.js b/frontend/src/rest/ServiceInscription.js index 8cdd276..5068217 100644 --- a/frontend/src/rest/ServiceInscription.js +++ b/frontend/src/rest/ServiceInscription.js @@ -10,7 +10,7 @@ import {restGet, restPatch} from './restConsumer.js' * TODO: add info in the Object (I don't know what will be needed) */ export async function createRegister(){ - return restPost("/request/register"}); + return restPost("/request/register"); } /**