|
1 | 1 | package demo.codeexample.task.infrastructure.adapters.in; |
| 2 | +import demo.codeexample.comment.CommentLookup; |
| 3 | +import demo.codeexample.task.TaskResponseDto; |
| 4 | +import demo.codeexample.task.application.ports.in.TaskUseCase; |
| 5 | +import demo.codeexample.task.domain.Task; |
| 6 | +import lombok.RequiredArgsConstructor; |
| 7 | +import org.modelmapper.ModelMapper; |
| 8 | +import org.springframework.http.HttpStatus; |
| 9 | +import org.springframework.stereotype.Controller; |
| 10 | +import org.springframework.ui.Model; |
| 11 | +import org.springframework.web.bind.annotation.GetMapping; |
| 12 | +import org.springframework.web.bind.annotation.PathVariable; |
| 13 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 14 | +import org.springframework.web.server.ResponseStatusException; |
2 | 15 |
|
| 16 | + |
| 17 | + |
| 18 | +@Controller |
| 19 | +@RequestMapping("/tasks") |
| 20 | +@RequiredArgsConstructor |
3 | 21 | public class TaskController { |
| 22 | + private final TaskUseCase taskUseCase; |
| 23 | + private final CommentLookup commentLookup; |
| 24 | + private final ModelMapper modelMapper; |
| 25 | + |
| 26 | + |
| 27 | + @GetMapping("/{taskId}/view") |
| 28 | + public String viewTask(@PathVariable Long taskId, Model model) { |
| 29 | + Task task = taskUseCase.findById(taskId) |
| 30 | + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND)); |
| 31 | + |
| 32 | + TaskResponseDto dto = modelMapper.map(task, TaskResponseDto.class); |
| 33 | + |
| 34 | + dto.setComments(commentLookup.getCommentsForTask(taskId)); |
| 35 | + |
| 36 | + model.addAttribute("task", dto); |
| 37 | + return "task-detail"; |
| 38 | + } |
4 | 39 | } |
0 commit comments