Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #189 from sef-global/development
Browse files Browse the repository at this point in the history
ScholarX v1.3
  • Loading branch information
Gravewalker666 committed Aug 3, 2021
2 parents 19a38ca + 46ec654 commit 3531f66
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public interface MenteeRepository extends JpaRepository<Mentee, Long> {

List<Mentee> findAllByProgramIdAndProfileId(long programId, long profileId);

List<Mentee> findAllByProgramIdAndProfileIdAndState(long programId, long profileId, EnrolmentState state);

List<Mentee> findAllByProgramIdAndProfileIdAndStateIn(long programId, long profileId, List<EnrolmentState> states);

Optional<Mentee> findByProfileIdAndMentorId(long profileId, long mentorId);
Expand All @@ -29,6 +31,8 @@ public interface MenteeRepository extends JpaRepository<Mentee, Long> {

List<Mentee> findAllByProgramId(long id);

List<Mentee> findAllByProgramIdAndState(long programId, EnrolmentState state);

@Modifying
@Query(
value = "DELETE " +
Expand All @@ -52,4 +56,16 @@ public interface MenteeRepository extends JpaRepository<Mentee, Long> {
nativeQuery = true
)
void removeAllByProgramIdAndProfileIdAndMentorIdNot(long programId, long profileId, long mentorId);

@Modifying
@Query(
value = "UPDATE " +
"mentee " +
"SET state = 'REMOVED' " +
"WHERE profile_id = :profileId " +
"AND program_id = :programId ",
nativeQuery = true
)
void removeAllByProgramIdAndProfileId(long programId, long profileId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ public Program updateState(long id) throws ResourceNotFoundException {
}

ProgramState nextState = program.get().getState().next();
if (ProgramState.ONGOING.equals(nextState)) {
List<Mentee> approvedMenteeList = menteeRepository.findAllByProgramIdAndState(id, EnrolmentState.APPROVED);
for (Mentee mentee : approvedMenteeList) {
long profileId = mentee.getProfile().getId();
if (menteeRepository.findAllByProgramIdAndProfileIdAndState(id, profileId, EnrolmentState.APPROVED).size() != 1) {
menteeRepository.removeAllByProgramIdAndProfileId(id, profileId);
}
}
}
program.get().setState(nextState);
return programRepository.save(program.get());
}
Expand Down

0 comments on commit 3531f66

Please sign in to comment.