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

Commit

Permalink
fix: update session do exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
HoXuanHieu committed Apr 23, 2024
1 parent 2aa02e5 commit a7edb6c
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/main/java/com/example/codeE/service/exercise/ExerciseImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,38 +179,38 @@ else if (exercise.getKey().equals(key) && isReTemp(exercise.getExerciseId(), stu
return exercise;
} else {
var session = sessionExercises.get(0);
if (session.getLoginId().equals(loginId) && session.getStudentId().equals(studentId)) {
Date timeStart = new Date();
try {
var timeString = session.getTimeStart();
SimpleDateFormat sdf = new SimpleDateFormat(Constant.DATE_TIME_ISO_FORMAT);
timeStart = sdf.parse(timeString);
} catch (ParseException e) {
e.printStackTrace();
}
Date now = new Date();
if ((long) exercise.getDurationTime() * 1000 * 60 + timeStart.getTime() < now.getTime()) {
this.sessionExerciseService.removeSession(response, request);
LocalDateTime dateNow = LocalDateTime.now();
//user Urgent ?
session = new SessionExercise(loginId, studentId, exerciseId, DateTimeUtil.formatToIso(dateNow), "");
sessionExerciseRepository.save(session);
}
Date timeStart = new Date();
try {
var timeString = session.getTimeStart();
SimpleDateFormat sdf = new SimpleDateFormat(Constant.DATE_TIME_ISO_FORMAT);
timeStart = sdf.parse(timeString);
} catch (ParseException e) {
e.printStackTrace();
}
Date now = new Date();
if ((long) exercise.getDurationTime() * 1000 * 60 + timeStart.getTime() < now.getTime()) {
this.sessionExerciseRepository.deleteById(session.getSessionId());
LocalDateTime dateNow = LocalDateTime.now();
//user Urgent ?
session = new SessionExercise(loginId, studentId, exerciseId, DateTimeUtil.formatToIso(dateNow), "");
sessionExerciseRepository.save(session);
}
if (session.getLoginId().equals(loginId)) {
if (session.getExerciseId().equals(exerciseId)) {
return exercise;
//after return, system need to calculate a time left
} else {
//student has joined another exercise
throw new IllegalArgumentException("Student need to complete another current exercise before participating in a new one.");
}
} else {
throw new IllegalArgumentException("Student is using another browser to take an exercise.");
}
}
}

} else
throw new IllegalArgumentException("Failed to retrieve exercise information.");
}


private boolean isReTemp(String exerciseId, String userId, String type, int reTemp) {
switch (type) {
case "quiz" -> {
Expand Down

0 comments on commit a7edb6c

Please sign in to comment.