Skip to content

Commit a05debb

Browse files
authored
Merge pull request #175 from it-at-m/feature/my-checklists-backend
Feature/my checklists backend
2 parents 0aea66b + 81c2309 commit a05debb

File tree

18 files changed

+546
-499
lines changed

18 files changed

+546
-499
lines changed

personalization-service/src/main/java/de/muenchen/dbs/personalization/checklist/ChecklistController.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.swagger.v3.oas.annotations.Operation;
99
import io.swagger.v3.oas.annotations.tags.Tag;
1010
import jakarta.validation.Valid;
11+
import java.time.ZonedDateTime;
1112
import java.util.List;
1213
import java.util.UUID;
1314
import lombok.RequiredArgsConstructor;
@@ -22,6 +23,11 @@
2223
@Tag(name = "Checklists", description = "Creating, reading and deleting Checklists.")
2324
public class ChecklistController {
2425

26+
public static final String CHECKLIST_ID = "checklistID";
27+
public static final String SERVICE_ID = "serviceID";
28+
public static final String PATH_VAR_CHECKLIST_ID = "/{" + CHECKLIST_ID + "}";
29+
public static final String PATH_VAR_SERVICE_ID = "/{" + SERVICE_ID + "}";
30+
2531
private final ChecklistService checklistService;
2632
private final ChecklistMapper checklistMapper;
2733

@@ -33,10 +39,10 @@ public List<ChecklistReadDTO> getChecklists() {
3339
return checklists.stream().map(checklistMapper::toReadDTO).toList();
3440
}
3541

36-
@GetMapping(path = "/{checklistID}")
42+
@GetMapping(path = PATH_VAR_CHECKLIST_ID)
3743
@Operation(summary = "Get specific checklist by checklist-id.", description = "Returns a checklist by checklistId")
3844
@ResponseStatus(HttpStatus.OK)
39-
public ChecklistReadDTO getChecklist(@PathVariable("checklistID") final UUID checklistID) {
45+
public ChecklistReadDTO getChecklist(@PathVariable(CHECKLIST_ID) final UUID checklistID) {
4046
return checklistMapper.toReadDTO(checklistService.getChecklist(checklistID));
4147
}
4248

@@ -48,18 +54,34 @@ public ChecklistReadDTO createChecklist(@Valid @RequestBody final ChecklistCreat
4854
.toReadDTO(checklistService.createChecklist(checklistMapper.toCreateChecklist(checklistCreateDTO)));
4955
}
5056

51-
@PutMapping("/{checklistID}")
57+
@PutMapping(PATH_VAR_CHECKLIST_ID)
5258
@Operation(summary = "Update a checklist", description = "Updates a checklist using the provided checklist details.")
5359
@ResponseStatus(HttpStatus.OK)
5460
public ChecklistReadDTO updateChecklist(@Valid @RequestBody final ChecklistUpdateDTO checklistUpdateDTO,
55-
@PathVariable("checklistID") final UUID checklistID) {
61+
@PathVariable(CHECKLIST_ID) final UUID checklistID) {
5662
return checklistMapper.toReadDTO(checklistService.updateChecklist(checklistMapper.toUpdateChecklist(checklistUpdateDTO), checklistID));
5763
}
5864

59-
@DeleteMapping("/{checklistID}")
65+
@DeleteMapping(PATH_VAR_CHECKLIST_ID)
6066
@Operation(summary = "Delete a checklist", description = "Deletes a checklist by checklistId.")
6167
@ResponseStatus(HttpStatus.OK)
62-
public void deleteChecklist(@PathVariable("checklistID") final UUID checklistID) {
68+
public void deleteChecklist(@PathVariable(CHECKLIST_ID) final UUID checklistID) {
6369
checklistService.deleteChecklist(checklistID);
6470
}
71+
72+
@PostMapping(PATH_VAR_CHECKLIST_ID + PATH_VAR_SERVICE_ID + "/check")
73+
@Operation(summary = "Check a Checklist-Entry", description = "Checks a checklist-entry.")
74+
@ResponseStatus(HttpStatus.OK)
75+
public ChecklistReadDTO checkChecklistEntry(@PathVariable(CHECKLIST_ID) final UUID checklistID,
76+
@PathVariable(SERVICE_ID) final String serviceID) {
77+
return checklistMapper.toReadDTO(checklistService.changeChecklistEntry(checklistID, serviceID, ZonedDateTime.now()));
78+
}
79+
80+
@PostMapping(PATH_VAR_CHECKLIST_ID + PATH_VAR_SERVICE_ID + "/uncheck")
81+
@Operation(summary = "Uncheck a Checklist-Entry", description = "Unchecks a checklist-entry.")
82+
@ResponseStatus(HttpStatus.OK)
83+
public ChecklistReadDTO uncheckChecklistEntry(@PathVariable(CHECKLIST_ID) final UUID checklistID,
84+
@PathVariable(SERVICE_ID) final String serviceID) {
85+
return checklistMapper.toReadDTO(checklistService.changeChecklistEntry(checklistID, serviceID, null));
86+
}
6587
}

personalization-service/src/main/java/de/muenchen/dbs/personalization/checklist/ChecklistService.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import lombok.RequiredArgsConstructor;
1111
import lombok.extern.slf4j.Slf4j;
1212
import org.apache.commons.lang3.StringUtils;
13+
import org.apache.commons.text.StringEscapeUtils;
1314
import org.springframework.http.HttpStatus;
1415
import org.springframework.security.core.Authentication;
1516
import org.springframework.security.core.context.SecurityContextHolder;
@@ -70,6 +71,26 @@ public void deleteChecklist(final UUID checklistId) {
7071
checklistRepository.deleteById(checklistId);
7172
}
7273

74+
public Checklist changeChecklistEntry(final UUID checklistId, final String serviceId, final ZonedDateTime newCheckedValue) {
75+
final String lhmExtId = getLhmExtIdFromAuthenticationOrThrow();
76+
final String sanitizedServiceId = StringEscapeUtils.escapeHtml4(serviceId);
77+
log.debug("Update checklist with checklist-ID {} and service-ID {} for {}", checklistId, sanitizedServiceId, lhmExtId);
78+
final Checklist foundChecklist = getChecklistOrThrowException(checklistId);
79+
80+
isChecklistOwnerOrThrow(foundChecklist, lhmExtId);
81+
82+
foundChecklist.getChecklistItems().forEach(checklistItem -> {
83+
if (checklistItem.getServiceID().equals(sanitizedServiceId)) {
84+
checklistItem.setChecked(newCheckedValue);
85+
}
86+
});
87+
foundChecklist.setLastUpdate(ZonedDateTime.now());
88+
89+
log.debug("Update Checklist {}", foundChecklist);
90+
91+
return checklistRepository.save(foundChecklist);
92+
}
93+
7394
private Checklist getChecklistOrThrowException(final UUID checklistId) {
7495
return checklistRepository
7596
.findById(checklistId)

0 commit comments

Comments
 (0)