|
| 1 | +package de.muenchen.dbs.personalization.checklist; |
| 2 | + |
| 3 | +import de.muenchen.dbs.personalization.checklist.domain.Checklist; |
| 4 | +import de.muenchen.dbs.personalization.checklist.domain.ChecklistCreateDTO; |
| 5 | +import de.muenchen.dbs.personalization.checklist.domain.ChecklistMapper; |
| 6 | +import de.muenchen.dbs.personalization.checklist.domain.ChecklistReadDTO; |
| 7 | +import de.muenchen.dbs.personalization.checklist.domain.ChecklistUpdateDTO; |
| 8 | +import io.swagger.v3.oas.annotations.Operation; |
| 9 | +import io.swagger.v3.oas.annotations.tags.Tag; |
| 10 | +import jakarta.validation.Valid; |
| 11 | +import java.util.List; |
| 12 | +import java.util.UUID; |
| 13 | +import lombok.RequiredArgsConstructor; |
| 14 | +import lombok.extern.slf4j.Slf4j; |
| 15 | +import org.springframework.http.HttpStatus; |
| 16 | +import org.springframework.web.bind.annotation.*; |
| 17 | + |
| 18 | +@RestController |
| 19 | +@RequestMapping("/checklist") |
| 20 | +@Slf4j |
| 21 | +@RequiredArgsConstructor |
| 22 | +@Tag(name = "Checklists", description = "Creating, reading and deleting Checklists.") |
| 23 | +public class ChecklistController { |
| 24 | + |
| 25 | + private final ChecklistService checklistService; |
| 26 | + private final ChecklistMapper checklistMapper; |
| 27 | + |
| 28 | + @GetMapping |
| 29 | + @Operation(summary = "Get all checklists by user.", description = "Returns all checklists of an user by lhmExtId") |
| 30 | + @ResponseStatus(HttpStatus.OK) |
| 31 | + public List<ChecklistReadDTO> getChecklists(@RequestHeader("lhmExtID") final String lhmExtID) { |
| 32 | + final List<Checklist> checklists = checklistService.getChecklists(lhmExtID); |
| 33 | + return checklists.stream().map(checklistMapper::toReadDTO).toList(); |
| 34 | + } |
| 35 | + |
| 36 | + @GetMapping(path = "/{checklistID}") |
| 37 | + @Operation(summary = "Get specific checklist by checklist-id.", description = "Returns a checklist by checklistId") |
| 38 | + @ResponseStatus(HttpStatus.OK) |
| 39 | + public ChecklistReadDTO getChecklist(@PathVariable("checklistID") final UUID checklistID) { |
| 40 | + return checklistMapper.toReadDTO(checklistService.getChecklist(checklistID)); |
| 41 | + } |
| 42 | + |
| 43 | + @PostMapping |
| 44 | + @Operation(summary = "Create a new checklist", description = "Creates a new checklist using the provided checklist details.") |
| 45 | + @ResponseStatus(HttpStatus.CREATED) |
| 46 | + public ChecklistReadDTO createChecklist(@Valid @RequestBody final ChecklistCreateDTO checklistCreateDTO) { |
| 47 | + return checklistMapper |
| 48 | + .toReadDTO(checklistService.createChecklist(checklistMapper.toCreateChecklist(checklistCreateDTO))); |
| 49 | + } |
| 50 | + |
| 51 | + @PutMapping("/{checklistID}") |
| 52 | + @Operation(summary = "Update a checklist", description = "Updates a checklist using the provided checklist details.") |
| 53 | + @ResponseStatus(HttpStatus.OK) |
| 54 | + public ChecklistReadDTO updateChecklist(@Valid @RequestBody final ChecklistUpdateDTO checklistUpdateDTO, |
| 55 | + @PathVariable("checklistID") final UUID checklistID) { |
| 56 | + return checklistMapper.toReadDTO(checklistService.updateChecklist(checklistMapper.toUpdateChecklist(checklistUpdateDTO), checklistID)); |
| 57 | + } |
| 58 | + |
| 59 | + @DeleteMapping("/{checklistID}") |
| 60 | + @Operation(summary = "Delete a checklist", description = "Deletes a checklist by checklistId.") |
| 61 | + @ResponseStatus(HttpStatus.OK) |
| 62 | + public void deleteChecklist(@PathVariable("checklistID") final UUID checklistID) { |
| 63 | + checklistService.deleteChecklist(checklistID); |
| 64 | + } |
| 65 | +} |
0 commit comments