Add the unregistration of a specific cursus only
This commit is contained in:
		| @ -103,7 +103,15 @@ public class RequestsController { | |||||||
|     @PostMapping(value = "/unregister") |     @PostMapping(value = "/unregister") | ||||||
|     public ResponseEntity<String> postUnregReq(@RequestBody Map<String,Object> uninscr){ |     public ResponseEntity<String> postUnregReq(@RequestBody Map<String,Object> uninscr){ | ||||||
|         User u = userRepository.findById((int) uninscr.get("userId")); |         User u = userRepository.findById((int) uninscr.get("userId")); | ||||||
|         UnregisterRequest ur = new UnregisterRequest(RequestState.Pending, (String) uninscr.get("reason"), new Date(), u.getRegNo(), u.getFirstName(), u.getLastName(), u.getEmail()); |         Curriculum c; | ||||||
|  |  | ||||||
|  |         if (uninscr.get("curriculumId") == null){ | ||||||
|  |             c = null; | ||||||
|  |         }else{ | ||||||
|  |             c = curriculumRepository.findById((Integer) uninscr.get("curriculumId")); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         UnregisterRequest ur = new UnregisterRequest(RequestState.Pending, (String) uninscr.get("reason"), new Date(), u.getRegNo(), u.getFirstName(), u.getLastName(), u.getEmail(), c); | ||||||
|         unregisterRequestRepository.save(ur); |         unregisterRequestRepository.save(ur); | ||||||
|         return new ResponseEntity<>(HttpStatus.OK); |         return new ResponseEntity<>(HttpStatus.OK); | ||||||
|     } |     } | ||||||
| @ -149,11 +157,18 @@ public class RequestsController { | |||||||
|         unregisterRequest.setState(newstate); |         unregisterRequest.setState(newstate); | ||||||
|  |  | ||||||
|         if (newstate == RequestState.Accepted){ |         if (newstate == RequestState.Accepted){ | ||||||
|  |             if (unregisterRequest.getCurriculum() == null){ | ||||||
|                 ArrayList<UserCurriculum> userCurricula = userCurriculumRepository.findByUserOrderByCurriculum(u); |                 ArrayList<UserCurriculum> userCurricula = userCurriculumRepository.findByUserOrderByCurriculum(u); | ||||||
|                 for (int i = 0; i < userCurricula.size(); i++){ |                 for (int i = 0; i < userCurricula.size(); i++){ | ||||||
|                     userCurricula.get(i).setActual(false); |                     userCurricula.get(i).setActual(false); | ||||||
|                 } |                 } | ||||||
|                 userCurriculumRepository.saveAll(userCurricula); |                 userCurriculumRepository.saveAll(userCurricula); | ||||||
|  |             }else{ | ||||||
|  |                 //This usercurriculum will contain the usercurriculum to set false | ||||||
|  |                 UserCurriculum userCurriculum = userCurriculumRepository.findByUserAndCurriculumAndActual(u, unregisterRequest.getCurriculum(), true); | ||||||
|  |                 userCurriculum.setActual(false); | ||||||
|  |                 userCurriculumRepository.save(userCurriculum); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         unregisterRequestRepository.save(unregisterRequest); |         unregisterRequestRepository.save(unregisterRequest); | ||||||
|  | |||||||
| @ -128,7 +128,7 @@ public class MockController { | |||||||
|  |  | ||||||
|         inscriptionService.save(inscriptionRequest); |         inscriptionService.save(inscriptionRequest); | ||||||
|  |  | ||||||
|         UnregisterRequest unregisterRequest = new UnregisterRequest(RequestState.Pending, "je veux partir", new Date(), joe.getRegNo(), joe.getFirstName(), joe.getLastName(), joe.getEmail()); |         UnregisterRequest unregisterRequest = new UnregisterRequest(RequestState.Pending, "je veux partir", new Date(), joe.getRegNo(), joe.getFirstName(), joe.getLastName(), joe.getEmail(), null); | ||||||
|         uninscriptionRequestRepository.save(unregisterRequest); |         uninscriptionRequestRepository.save(unregisterRequest); | ||||||
|  |  | ||||||
|         ExternalCurriculum externalCurriculum = new ExternalCurriculum(inscriptionRequest, "HEH", "Bachelier en informatique", "Completed", 2015, 2018, null, null); |         ExternalCurriculum externalCurriculum = new ExternalCurriculum(inscriptionRequest, "HEH", "Bachelier en informatique", "Completed", 2015, 2018, null, null); | ||||||
|  | |||||||
| @ -14,4 +14,5 @@ public interface UserCurriculumRepository extends CrudRepository<UserCurriculum, | |||||||
|     Curriculum findByUser(User student); |     Curriculum findByUser(User student); | ||||||
|  |  | ||||||
|     ArrayList<UserCurriculum> findByUserOrderByCurriculum(User student); |     ArrayList<UserCurriculum> findByUserOrderByCurriculum(User student); | ||||||
|  |     UserCurriculum findByUserAndCurriculumAndActual(User user, Curriculum curriculum, boolean actual); | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,6 +1,7 @@ | |||||||
| package ovh.herisson.Clyde.Tables.Inscription; | package ovh.herisson.Clyde.Tables.Inscription; | ||||||
|  |  | ||||||
| import jakarta.persistence.*; | import jakarta.persistence.*; | ||||||
|  | import ovh.herisson.Clyde.Tables.Curriculum; | ||||||
| import ovh.herisson.Clyde.Tables.RequestState; | import ovh.herisson.Clyde.Tables.RequestState; | ||||||
| import ovh.herisson.Clyde.Tables.User; | import ovh.herisson.Clyde.Tables.User; | ||||||
|  |  | ||||||
| @ -24,7 +25,12 @@ public class UnregisterRequest { | |||||||
|  |  | ||||||
|     private String email; |     private String email; | ||||||
|  |  | ||||||
|     public UnregisterRequest(RequestState state, String reason, Date date, long regNo, String firstName, String lastName, String email){ |     //Null if the user unregister for the academic year, contains a curriculum if the user wants to unregister from a specific curriculum | ||||||
|  |     @ManyToOne | ||||||
|  |     @JoinColumn(name = "Curriculum") | ||||||
|  |     private Curriculum curriculum; | ||||||
|  |  | ||||||
|  |     public UnregisterRequest(RequestState state, String reason, Date date, long regNo, String firstName, String lastName, String email, Curriculum curriculum){ | ||||||
|         this.state = state; |         this.state = state; | ||||||
|         this.reason = reason; |         this.reason = reason; | ||||||
|         this.date = date; |         this.date = date; | ||||||
| @ -32,6 +38,7 @@ public class UnregisterRequest { | |||||||
|         this.firstName = firstName; |         this.firstName = firstName; | ||||||
|         this.lastName = lastName; |         this.lastName = lastName; | ||||||
|         this.email = email; |         this.email = email; | ||||||
|  |         this.curriculum = curriculum; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public UnregisterRequest(){} |     public UnregisterRequest(){} | ||||||
| @ -95,5 +102,14 @@ public class UnregisterRequest { | |||||||
|     public long getRegNo() { |     public long getRegNo() { | ||||||
|         return regNo; |         return regNo; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public void setCurriculum(Curriculum curriculum) { | ||||||
|  |         this.curriculum = curriculum; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public Curriculum getCurriculum() { | ||||||
|  |         return curriculum; | ||||||
|  |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | |||||||
| @ -28,6 +28,8 @@ | |||||||
|   //0 base, 1 modif, 2 curriculum, 3 register, 4 courselist, 5 minerval, 6 payment, 7 scholarship, 8 scholarshipinfos, 9 unregister, 10 sure, 11 aboutunregister |   //0 base, 1 modif, 2 curriculum, 3 register, 4 courselist, 5 minerval, 6 payment, 7 scholarship, 8 scholarshipinfos, 9 unregister, 10 sure, 11 aboutunregister | ||||||
|   const windowState = ref(0); |   const windowState = ref(0); | ||||||
|  |  | ||||||
|  |   const isChecked = ref(false); | ||||||
|  |  | ||||||
|   const pattern = { |   const pattern = { | ||||||
|     profilPictureUrl:null, |     profilPictureUrl:null, | ||||||
|     email:null, |     email:null, | ||||||
| @ -71,7 +73,8 @@ | |||||||
|   //Used to post a uninscription request |   //Used to post a uninscription request | ||||||
|   const uninscriptionData = reactive({ |   const uninscriptionData = reactive({ | ||||||
|     reason : null, |     reason : null, | ||||||
|     userId : user.value.regNo |     userId : user.value.regNo, | ||||||
|  |     curriculumId:null | ||||||
|   }) |   }) | ||||||
|   const paymentAmount = ref(0); |   const paymentAmount = ref(0); | ||||||
|   let toModify= Object.assign({}, pattern); |   let toModify= Object.assign({}, pattern); | ||||||
| @ -194,14 +197,24 @@ | |||||||
|           </div> |           </div> | ||||||
|         </div> |         </div> | ||||||
|         <div v-else-if="windowState === 9" class="infosContainer"> |         <div v-else-if="windowState === 9" class="infosContainer"> | ||||||
|             <div v-if="sure !== 2">Please enter the reason you leave the university</div> |             <div v-if="sure !== 2">Please enter the reason you leave</div> | ||||||
|             <textarea v-if="sure !== 2" v-model="uninscriptionData.reason"></textarea> |             <textarea v-if="sure !== 2" v-model="uninscriptionData.reason"></textarea> | ||||||
|  |             <div v-if="sure !== 2"> | ||||||
|  |             I only want to unregister from a specific cursus | ||||||
|  |             <input type="checkbox" v-model="isChecked"> | ||||||
|  |             </div> | ||||||
|  |             <div v-if="sure !== 2 && isChecked"> | ||||||
|  |               Please select that cursus | ||||||
|  |               <select v-model="uninscriptionData.curriculumId"> | ||||||
|  |                 <option v-for="item in getActualCurriculumList()" :value="item.curriculumId">Bac {{item.year}} {{item.option}}</option> | ||||||
|  |               </select> | ||||||
|  |             </div> | ||||||
|             <div v-if="sure !== 2"> |             <div v-if="sure !== 2"> | ||||||
|               <button @click="sure++">Submit</button> |               <button @click="sure++">Submit</button> | ||||||
|             </div> |             </div> | ||||||
|             <div v-if="sure==1"> |             <div v-if="sure==1"> | ||||||
|               Are you sure that you want to unregister ? |               Are you sure that you want to unregister ? | ||||||
|               <button @click="addUninscReq(uninscriptionData.userId, uninscriptionData.reason);sure++">Yes</button> |               <button @click="addUninscReq(uninscriptionData.userId, uninscriptionData.reason, uninscriptionData.curriculumId);sure++">Yes</button> | ||||||
|               <button @click="sure=0">No</button> |               <button @click="sure=0">No</button> | ||||||
|             </div> |             </div> | ||||||
|             <p v-if="sure==2">You request has been send !</p> |             <p v-if="sure==2">You request has been send !</p> | ||||||
|  | |||||||
| @ -20,8 +20,8 @@ export async function editEquivalenceState(id, newstate){ | |||||||
|     return restPatch("/request/registerequiv/"+id+"/"+newstate) |     return restPatch("/request/registerequiv/"+id+"/"+newstate) | ||||||
| } | } | ||||||
|  |  | ||||||
| export async function addUninscReq(userId, reason){ | export async function addUninscReq(userId, reason, curriculumId){ | ||||||
|     return restPost("/unregister", {"userId" : userId, "reason" : reason}) |     return restPost("/unregister", {"userId" : userId, "reason" : reason, "curriculumId":curriculumId}) | ||||||
| } | } | ||||||
|  |  | ||||||
| export async function editScholarshipReq(body){ | export async function editScholarshipReq(body){ | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user