From 1498cfa11ed8d9c5afb7114e730854a7c7fbfe6e Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Sun, 14 Apr 2024 12:34:04 +0200 Subject: [PATCH] added comments and fixed logic issue --- .../ScientificPublications/ResearchDTO.java | 7 +++++ .../ScientificPublications/ResearcherDTO.java | 7 +++++ .../ResearchController.java | 31 +++++++++++++++++++ .../ResearcherController.java | 15 +++++++-- .../ResearchesService.java | 2 ++ 5 files changed, 59 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/DTO/ScientificPublications/ResearchDTO.java b/backend/src/main/java/ovh/herisson/Clyde/DTO/ScientificPublications/ResearchDTO.java index 2c35a82..92605be 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/DTO/ScientificPublications/ResearchDTO.java +++ b/backend/src/main/java/ovh/herisson/Clyde/DTO/ScientificPublications/ResearchDTO.java @@ -1,5 +1,12 @@ package ovh.herisson.Clyde.DTO.ScientificPublications; +/****************************************************** + * @file ResearchDTO.java + * @author Bartha Maxime + * @scope Publications Scientifiques + * + * Research format to return to front (without author's password) + ******************************************************/ import lombok.Data; import ovh.herisson.Clyde.Tables.ScientificPublications.Access; diff --git a/backend/src/main/java/ovh/herisson/Clyde/DTO/ScientificPublications/ResearcherDTO.java b/backend/src/main/java/ovh/herisson/Clyde/DTO/ScientificPublications/ResearcherDTO.java index c9eebd4..4dffff0 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/DTO/ScientificPublications/ResearcherDTO.java +++ b/backend/src/main/java/ovh/herisson/Clyde/DTO/ScientificPublications/ResearcherDTO.java @@ -1,5 +1,12 @@ package ovh.herisson.Clyde.DTO.ScientificPublications; +/****************************************************** + * @file ResearcherDTO.java + * @author Bartha Maxime + * @scope Publications Scientifiques + * + * Researcher Format to return to front (without user password) + ******************************************************/ import lombok.Data; import ovh.herisson.Clyde.Services.ProtectionService; import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher; diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScientificPublications/ResearchController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScientificPublications/ResearchController.java index 692b4cc..c9b6270 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScientificPublications/ResearchController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScientificPublications/ResearchController.java @@ -1,5 +1,13 @@ package ovh.herisson.Clyde.EndPoints.ScientificPublications; +/****************************************************** + * @file ResearchController.java + * @author Bartha Maxime + * @scope Publications Scientifiques + * + * API class for the researches + ******************************************************/ + import lombok.AllArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -46,6 +54,10 @@ public class ResearchController { return new ResponseEntity<>(ResearchDTO.construct(research), HttpStatus.OK); } + /** + * @param token used to know if the user can download or not the research pdf + * @return every research + */ @GetMapping("/researches") public ResponseEntity> getResearches(@RequestHeader(value = "Authorization",required = false) String token){ Iterable researches = researchesServ.getAllResearches(); @@ -61,6 +73,10 @@ public class ResearchController { return new ResponseEntity<>(toReturnResearches,HttpStatus.OK); } + /** post a new research + * + * @return the research saved + */ @PostMapping("/research") public ResponseEntity postResearch(@RequestHeader("Authorization") String token, @RequestBody Research research){ @@ -72,6 +88,9 @@ public class ResearchController { return new ResponseEntity<>(researchesServ.saveResearch(research), HttpStatus.OK); } + /** post updates to the research + * + */ @PatchMapping("/research/{id}") public ResponseEntity patchResearch(@RequestHeader("Authorization") String token, @RequestBody Map updates, @@ -118,6 +137,11 @@ public class ResearchController { ///////////// // Co-authors Part + /** get all the co-authors in a research + * + * @param id the research id + * @return all the co-authors associated with the research + */ @GetMapping("/research/{id}/co-authors") public ResponseEntity> getCoAuthors(@PathVariable long id){ Research research = researchesServ.getResearchById(id); @@ -133,6 +157,13 @@ public class ResearchController { return new ResponseEntity<>(toReturn,HttpStatus.OK); } + /** post co-authors to the research + * + * @param token the Authorization header + * @param researchersId the co-authors ids + * @param id the research id + * @return the added researchers + */ @PostMapping("/research/{id}/co-authors") public ResponseEntity> postCoAuthor(@RequestHeader("Authorization") String token, @RequestBody Iterable researchersId, diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScientificPublications/ResearcherController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScientificPublications/ResearcherController.java index 9108691..d052686 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScientificPublications/ResearcherController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScientificPublications/ResearcherController.java @@ -1,5 +1,12 @@ package ovh.herisson.Clyde.EndPoints.ScientificPublications; +/****************************************************** + * @file ResearcherController.java + * @author Bartha Maxime + * @scope Publications Scientifiques + * + * API class for the researchers + ******************************************************/ import lombok.AllArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -51,7 +58,9 @@ public class ResearcherController { Researcher posted = researchesServ.saveResearcher(researcher); - return new ResponseEntity<>(ResearcherDTO.construct(posted), HttpStatus.OK); + if (posted == null) return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); + + return new ResponseEntity<>(ResearcherDTO.construct(posted), HttpStatus.CREATED); } @PatchMapping("/researcher/{id}") @@ -59,9 +68,9 @@ public class ResearcherController { @PathVariable long id, @RequestBody Map updates){ - Researcher researcher = researchesServ.getResearcherById(id); //todo check authorization j'ai pu patch sans le bon token + Researcher researcher = researchesServ.getResearcherById(id); if (authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin}, token) - && researcher == researchesServ.getResearcherByUser(authServ.getUserFromToken(token))) + || researcher == researchesServ.getResearcherByUser(authServ.getUserFromToken(token))) return new UnauthorizedResponse<>(null); if (researcher == null) return new ResponseEntity<>(HttpStatus.BAD_REQUEST); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/ScientificPublications/ResearchesService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/ScientificPublications/ResearchesService.java index a48fb1c..51f7708 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/ScientificPublications/ResearchesService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/ScientificPublications/ResearchesService.java @@ -110,6 +110,8 @@ public class ResearchesService { } public Researcher saveResearcher(Researcher researcher) { + + if (researcherRepo.findByUser(researcher.getUser()) != null) return null; return researcherRepo.save(researcher); }