Skip to content

Commit

Permalink
[backend] add trigger now date
Browse files Browse the repository at this point in the history
  • Loading branch information
MarineLeM committed Sep 16, 2024
1 parent 8710f02 commit 74a5e91
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public class V3_34__Add_column_trigger_now extends BaseJavaMigration {
@Override
public void migrate(Context context) throws Exception {
Statement select = context.getConnection().createStatement();
select.execute("ALTER TABLE injects ADD inject_trigger_now bool default false;");
select.execute("ALTER TABLE injects ADD inject_trigger_now_date timestamp;");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public Inject updateInjectTrigger(
@PathVariable String exerciseId,
@PathVariable String injectId) {
Inject inject = injectRepository.findById(injectId).orElseThrow(ElementNotFoundException::new);
inject.setTriggerNow(true);
inject.setTriggerNowDate(now());
inject.setUpdatedAt(now());
return injectRepository.save(inject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public class Inject implements Base, Injection {
private boolean enabled = true;

@Getter
@Column(name = "inject_trigger_now")
@JsonProperty("inject_trigger_now")
private boolean triggerNow;
@Column(name = "inject_trigger_now_date")
@JsonProperty("inject_trigger_now_date")
private Instant triggerNowDate;

@Getter
@Column(name = "inject_content")
Expand Down Expand Up @@ -284,10 +284,12 @@ public Instant computeInjectDate(Instant source, int speed) {

@JsonProperty("inject_date")
public Optional<Instant> getDate() {
// If a trigger now was executed for this inject, we ignore pauses and we set inject inside of a range of execution
if (this.triggerNow) {
this.triggerNow = false;
return Optional.of(now().minusSeconds(30));
// If a trigger now was executed for this inject linked to an exercise, we ignore pauses and we set inject inside of a range of execution
if(getExercise() != null && triggerNowDate != null ) {
Optional<Instant> exerciseStartOpt = getExercise().getStart();
if (exerciseStartOpt.isPresent() && (exerciseStartOpt.get().equals(triggerNowDate) || exerciseStartOpt.get().isBefore(triggerNowDate))) {
return Optional.of(now().minusSeconds(60));
}
}
return InjectModelHelper.getDate(getExercise(), getScenario(), getDependsOn(), getDependsDuration());
}
Expand Down

0 comments on commit 74a5e91

Please sign in to comment.