Huge commit
- Rework the inscription requests system so that it considers the equivalence systems and the impact of the teacher in the inscription procedure.
This commit is contained in:
		@ -41,4 +41,12 @@ public class ExternalCurriculumController {
 | 
			
		||||
        ArrayList<ExternalCurriculum> toReturn = ecr.getExternalCurriculumByInscriptionRequest(ir);
 | 
			
		||||
        return new ResponseEntity<>(toReturn, HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PatchMapping("/externalcurriculum/{extcurrid}/{newstate}")
 | 
			
		||||
    public ResponseEntity<Object> changeExternalCurrState(@PathVariable long extcurrid, @PathVariable RequestState newstate){
 | 
			
		||||
        ExternalCurriculum externalCurriculum = ecr.getExternalCurriculumById(extcurrid);
 | 
			
		||||
        externalCurriculum.setState(newstate);
 | 
			
		||||
        ecr.save(externalCurriculum);
 | 
			
		||||
        return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,6 @@
 | 
			
		||||
package ovh.herisson.Clyde.EndPoints;
 | 
			
		||||
 | 
			
		||||
import org.apache.tomcat.util.http.parser.Authorization;
 | 
			
		||||
import org.springframework.http.HttpStatus;
 | 
			
		||||
import org.springframework.http.ResponseEntity;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
@ -79,4 +80,22 @@ public class InscriptionController {
 | 
			
		||||
        return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    //Allow teacher or admin to accept or refuse the equivalence
 | 
			
		||||
    @PatchMapping("/request/registerequiv/{id}/{newstate}")
 | 
			
		||||
    public ResponseEntity<Object> editRegisterEquiv(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable RequestState newstate){
 | 
			
		||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher}, token))
 | 
			
		||||
            return new UnauthorizedResponse<>(null);
 | 
			
		||||
 | 
			
		||||
        InscriptionRequest toEdit = inscriptionServ.getById(id);
 | 
			
		||||
        toEdit.setEquivalenceState(newstate);
 | 
			
		||||
 | 
			
		||||
        inscriptionServ.save(toEdit);
 | 
			
		||||
 | 
			
		||||
        if (toEdit.getState() == RequestState.Accepted && (toEdit.getEquivalenceState() == RequestState.Accepted || toEdit.getEquivalenceState() == RequestState.Unrequired))
 | 
			
		||||
        {
 | 
			
		||||
            inscriptionServ.createUser(toEdit);
 | 
			
		||||
        }
 | 
			
		||||
        return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -5,10 +5,15 @@ 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.Repositories.CurriculumRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.InscriptionRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
 | 
			
		||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
 | 
			
		||||
import ovh.herisson.Clyde.Services.ProtectionService;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Curriculum;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.RequestState;
 | 
			
		||||
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
@ -16,7 +21,7 @@ import java.util.Map;
 | 
			
		||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
 | 
			
		||||
public class LoginController {
 | 
			
		||||
    private final AuthenticatorService authServ;
 | 
			
		||||
 | 
			
		||||
    private final CurriculumRepository curriculumRepository;
 | 
			
		||||
    static public class RequestLogin{
 | 
			
		||||
        private final String identifier;
 | 
			
		||||
        private final String password;
 | 
			
		||||
@ -29,8 +34,9 @@ public class LoginController {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public LoginController(AuthenticatorService authServ){
 | 
			
		||||
    public LoginController(AuthenticatorService authServ, CurriculumRepository curriculumRepository){
 | 
			
		||||
        this.authServ = authServ;
 | 
			
		||||
        this.curriculumRepository = curriculumRepository;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping(value = "/login")
 | 
			
		||||
@ -48,9 +54,18 @@ public class LoginController {
 | 
			
		||||
 | 
			
		||||
    @PostMapping("/register")
 | 
			
		||||
    public ResponseEntity<Map<String,Object>> register(@RequestBody InscriptionRequest inscriptionRequest){
 | 
			
		||||
        //We ensure here that if the targeted cursus year is more than first grade then we need the teacher equivalence approval
 | 
			
		||||
        Curriculum curr = curriculumRepository.findById(inscriptionRequest.getCurriculumId());
 | 
			
		||||
 | 
			
		||||
        if (curr.getYear() > 1){
 | 
			
		||||
            inscriptionRequest.setEquivalenceState(RequestState.Pending);
 | 
			
		||||
        }else{
 | 
			
		||||
            inscriptionRequest.setEquivalenceState(RequestState.Unrequired);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        InscriptionRequest returnedInscriptionRequest = authServ.register(inscriptionRequest);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        return new ResponseEntity<>(ProtectionService.requestWithoutPassword(returnedInscriptionRequest), HttpStatus.CREATED);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ public class MockController {
 | 
			
		||||
    public final CurriculumCourseService CurriculumCourseService;
 | 
			
		||||
    public final CurriculumService curriculumService;
 | 
			
		||||
    public final CourseService courseService;
 | 
			
		||||
 | 
			
		||||
    public final ExternalCurriculumRepository externalCurriculumRepository;
 | 
			
		||||
    public final InscriptionService inscriptionService;
 | 
			
		||||
    ArrayList<User> mockUsers;
 | 
			
		||||
 | 
			
		||||
@ -31,13 +31,14 @@ public class MockController {
 | 
			
		||||
 | 
			
		||||
    public final ScholarshipRequestRepository scholarshipRequestRepository;
 | 
			
		||||
 | 
			
		||||
    public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService, UserCurriculumRepository ucr, MinervalRepository minervalRepository, ScholarshipRequestRepository scholarshipRequestRepository){
 | 
			
		||||
    public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, ExternalCurriculumRepository externalCurriculumRepository, InscriptionService inscriptionService, UserCurriculumRepository ucr, MinervalRepository minervalRepository, ScholarshipRequestRepository scholarshipRequestRepository){
 | 
			
		||||
        this.tokenRepo = tokenRepo;
 | 
			
		||||
        this.userRepo = userRepo;
 | 
			
		||||
        this.tokenService = tokenService;
 | 
			
		||||
        this.CurriculumCourseService = CurriculumCourseService;
 | 
			
		||||
        this.curriculumService = curriculumService;
 | 
			
		||||
        this.courseService = courseService;
 | 
			
		||||
        this.externalCurriculumRepository = externalCurriculumRepository;
 | 
			
		||||
        this.inscriptionService = inscriptionService;
 | 
			
		||||
        this.ucr = ucr;
 | 
			
		||||
        this.minervalRepository = minervalRepository;
 | 
			
		||||
@ -114,9 +115,12 @@ public class MockController {
 | 
			
		||||
        CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,chemistry1));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        InscriptionRequest inscriptionRequest = new InscriptionRequest("helen","prenom","non","helen@gmail.com","america",new Date(),(long) 1,RequestState.Pending,"yes.png","password", null, new Date());
 | 
			
		||||
        InscriptionRequest inscriptionRequest = new InscriptionRequest("helen","prenom","non","helen@gmail.com","america",new Date(),(long) 4,RequestState.Pending,"yes.png","password", null, new Date(), RequestState.Pending);
 | 
			
		||||
 | 
			
		||||
        inscriptionService.save(inscriptionRequest);
 | 
			
		||||
 | 
			
		||||
        ExternalCurriculum externalCurriculum = new ExternalCurriculum(inscriptionRequest, "HEH", "Bachelier en informatique", "Completed", 2015, 2018, null, RequestState.Pending);
 | 
			
		||||
        externalCurriculumRepository.save(externalCurriculum);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -9,4 +9,6 @@ import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
public interface ExternalCurriculumRepository extends CrudRepository<ExternalCurriculum, Long> {
 | 
			
		||||
    ArrayList<ExternalCurriculum> getExternalCurriculumByInscriptionRequest(InscriptionRequest ir);
 | 
			
		||||
 | 
			
		||||
    ExternalCurriculum getExternalCurriculumById(long id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -47,48 +47,43 @@ public class InscriptionService {
 | 
			
		||||
        if (inscrRequest == null)
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        // if th state is the same we don't send an email
 | 
			
		||||
        if (requestState == inscrRequest.getState())
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        /** todo send an email to tell the poster of the inscrRequest (inscrRequest.getEmail())
 | 
			
		||||
         *  to notify them that the state of their request changed
 | 
			
		||||
         *  FooEmailFormat toSend = (String.format("Your request state changed from %s to %s"),
 | 
			
		||||
         *                                              inscrRequest.getState(), requestState)
 | 
			
		||||
         * FooEmailSender.send(toSend, inscrRequest.getEmail())
 | 
			
		||||
         */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        //saves the user from the request if accepted
 | 
			
		||||
        if (requestState == RequestState.Accepted)
 | 
			
		||||
        {
 | 
			
		||||
            if (curriculumRepo.findById(inscrRequest.getCurriculumId()) == null)
 | 
			
		||||
                return false;
 | 
			
		||||
 | 
			
		||||
            User userFromRequest = new User(
 | 
			
		||||
                    inscrRequest.getLastName(),
 | 
			
		||||
                    inscrRequest.getFirstName(),
 | 
			
		||||
                    inscrRequest.getEmail(),
 | 
			
		||||
                    inscrRequest.getAddress(),
 | 
			
		||||
                    inscrRequest.getCountry(),
 | 
			
		||||
                    inscrRequest.getBirthDate(),
 | 
			
		||||
                    inscrRequest.getProfilePicture(),
 | 
			
		||||
                    inscrRequest.getPassword()
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
            userRepo.save(userFromRequest);
 | 
			
		||||
            userCurriculumRepo.save(new UserCurriculum(userFromRequest, curriculumRepo.findById(inscrRequest.getCurriculumId()),0));
 | 
			
		||||
 | 
			
		||||
            //Create a minerval for the new student
 | 
			
		||||
            Minerval minerval = new Minerval(userFromRequest.getRegNo(), 0, 852, 2023);
 | 
			
		||||
            minervalRepository.save(minerval);
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        inscrRequest.setState(requestState);
 | 
			
		||||
        save(inscrRequest);
 | 
			
		||||
 | 
			
		||||
        //saves the user from the request if accepted from teacher and inscription services
 | 
			
		||||
        if (requestState == RequestState.Accepted && (inscrRequest.getEquivalenceState() == RequestState.Accepted || inscrRequest.getEquivalenceState() == RequestState.Unrequired))
 | 
			
		||||
        {
 | 
			
		||||
            return createUser(inscrRequest);
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean createUser(InscriptionRequest inscrRequest){
 | 
			
		||||
        //We must send an email here
 | 
			
		||||
 | 
			
		||||
        if (curriculumRepo.findById(inscrRequest.getCurriculumId()) == null)
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        User userFromRequest = new User(
 | 
			
		||||
                inscrRequest.getLastName(),
 | 
			
		||||
                inscrRequest.getFirstName(),
 | 
			
		||||
                inscrRequest.getEmail(),
 | 
			
		||||
                inscrRequest.getAddress(),
 | 
			
		||||
                inscrRequest.getCountry(),
 | 
			
		||||
                inscrRequest.getBirthDate(),
 | 
			
		||||
                inscrRequest.getProfilePicture(),
 | 
			
		||||
                inscrRequest.getPassword()
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        userRepo.save(userFromRequest);
 | 
			
		||||
        userCurriculumRepo.save(new UserCurriculum(userFromRequest, curriculumRepo.findById(inscrRequest.getCurriculumId()),0));
 | 
			
		||||
 | 
			
		||||
        //Create a minerval for the new student
 | 
			
		||||
        Minerval minerval = new Minerval(userFromRequest.getRegNo(), 0, 852, 2023);
 | 
			
		||||
        minervalRepository.save(minerval);
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
    public void delete(InscriptionRequest toDelete) {
 | 
			
		||||
        inscriptionRepo.delete(toDelete);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -89,6 +89,7 @@ public class ProtectionService {
 | 
			
		||||
        toReturn.put("profilePictureUrl", inscriptionRequest.getProfilePicture());
 | 
			
		||||
        toReturn.put("identityCard", inscriptionRequest.getIdentityCard());
 | 
			
		||||
        toReturn.put("submissionDate", inscriptionRequest.getSubmissionDate());
 | 
			
		||||
        toReturn.put("equivalenceState", inscriptionRequest.getEquivalenceState());
 | 
			
		||||
        return toReturn;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -21,9 +21,10 @@ public class InscriptionRequest {
 | 
			
		||||
    private String password;
 | 
			
		||||
    private String identityCard;
 | 
			
		||||
    private Date submissionDate;
 | 
			
		||||
    private RequestState equivalenceState;
 | 
			
		||||
    public InscriptionRequest(){}
 | 
			
		||||
 | 
			
		||||
    public InscriptionRequest(String lastName, String firstName, String address, String email, String country, Date birthDate,Long curriculumId, RequestState state, String profilePicture, String password, String identityCard, Date submissionDate){
 | 
			
		||||
    public InscriptionRequest(String lastName, String firstName, String address, String email, String country, Date birthDate,Long curriculumId, RequestState state, String profilePicture, String password, String identityCard, Date submissionDate, RequestState equivalenceState){
 | 
			
		||||
        this.lastName = lastName;
 | 
			
		||||
        this.firstName = firstName;
 | 
			
		||||
        this.address = address;
 | 
			
		||||
@ -36,6 +37,7 @@ public class InscriptionRequest {
 | 
			
		||||
        this.password = password;
 | 
			
		||||
        this.identityCard = identityCard;
 | 
			
		||||
        this.submissionDate = submissionDate;
 | 
			
		||||
        this.equivalenceState = equivalenceState;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getId() {
 | 
			
		||||
@ -137,4 +139,12 @@ public class InscriptionRequest {
 | 
			
		||||
    public void setSubmissionDate(Date submissionDate) {
 | 
			
		||||
        this.submissionDate = submissionDate;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public RequestState getEquivalenceState() {
 | 
			
		||||
        return equivalenceState;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setEquivalenceState(RequestState equivalenceState) {
 | 
			
		||||
        this.equivalenceState = equivalenceState;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -3,5 +3,6 @@ package ovh.herisson.Clyde.Tables;
 | 
			
		||||
public enum RequestState {
 | 
			
		||||
    Accepted,
 | 
			
		||||
    Refused,
 | 
			
		||||
    Pending
 | 
			
		||||
    Pending,
 | 
			
		||||
    Unrequired
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,27 +0,0 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class University {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    private int id;
 | 
			
		||||
 | 
			
		||||
    private String name;
 | 
			
		||||
 | 
			
		||||
    public University(){}
 | 
			
		||||
 | 
			
		||||
    public University(String name){
 | 
			
		||||
        this.name = name;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getName() {
 | 
			
		||||
        return name;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setName(String name) {
 | 
			
		||||
        this.name = name;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user