Skip to content

Commit

Permalink
Merge 2 set date services
Browse files Browse the repository at this point in the history
  • Loading branch information
alicela committed May 14, 2024
1 parent b63dfd7 commit 25fba4d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ResponseEntity<Object> getAllSchedules() {

List<StoredSurveySchedule> storedSurveySchedules = scheduleApiPort.getAllSchedules();

log.info("Returning " + storedSurveySchedules.size() + " schedule documents...");
log.info("Returning {} schedule documents...", storedSurveySchedules.size());
return ResponseEntity.ok(storedSurveySchedules);
}

Expand All @@ -55,29 +55,13 @@ public ResponseEntity<Object> addSchedule(
@Parameter(description = "Schedule end date and time", example = "2024-01-01T12:00:00") @RequestParam("scheduleEndDate") LocalDateTime scheduleEndDate
){
try {
log.info("New schedule request for survey " + surveyName);
log.info("New schedule request for survey {}", surveyName);
scheduleApiPort.addSchedule(surveyName, serviceToCall, frequency, scheduleBeginDate, scheduleEndDate);
}catch (InvalidCronExpressionException e){
log.warn("Returned error for wrong frequency : " + frequency);
log.warn("Returned error for wrong frequency : {}", frequency);
return ResponseEntity.badRequest().body("Wrong frequency syntax");
}
log.info("New schedule created for survey " + surveyName);
return ResponseEntity.ok().build();
}

@Operation(summary = "Update last execution date with now")
@PostMapping(path = "/updateLastExecutionDate")
public ResponseEntity<Object> updateSurveyLastExecution(
@Parameter(description = "Survey name to call Kraftwerk on") @RequestBody String surveyName
) {
try {
log.debug("Got update last execution on {}", surveyName);
scheduleApiPort.updateLastExecutionName(surveyName, LocalDateTime.now());
log.info("{} last execution updated !", surveyName);
}catch (NotFoundException e){
log.warn("Survey {} not found !", surveyName);
return ResponseEntity.notFound().build();
}
log.info("New schedule created for survey {}", surveyName);
return ResponseEntity.ok().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void addScheduleDedupTest() throws InvalidCronExpressionException {
@Test
void updateLastExecutionTest(){
//When
scheduleController.updateSurveyLastExecution("TESTSURVEY");
scheduleController.setSurveyLastExecution("TESTSURVEY", LocalDateTime.now());

//Then
List<StoredSurveySchedule> mongoStubFiltered = scheduleApiPortStub.mongoStub.stream().filter(scheduleDocument ->
Expand Down Expand Up @@ -187,7 +187,7 @@ void wrongFrequencyTest(){
@Test
void notFoundTest(){
//When+Then
ResponseEntity<Object> response = scheduleController.updateSurveyLastExecution("ERROR");
ResponseEntity<Object> response = scheduleController.setSurveyLastExecution("ERROR", LocalDateTime.now());
Assertions.assertThat(response.getStatusCode().is4xxClientError()).isTrue();
}
}

0 comments on commit 25fba4d

Please sign in to comment.