From 02037728e2a23914245c3bda021a96b9c5b719b3 Mon Sep 17 00:00:00 2001 From: choyeongju Date: Mon, 8 Jul 2024 05:11:20 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20#=2028=20[feat]=20Task=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20GET=20API=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/TaskController.java | 9 +++++++ .../nutshell/server/dto/task/TaskDto.java | 11 +++++++++ .../server/service/task/TaskService.java | 24 +++++++++++++++---- 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 src/main/java/nutshell/server/dto/task/TaskDto.java diff --git a/src/main/java/nutshell/server/controller/TaskController.java b/src/main/java/nutshell/server/controller/TaskController.java index ae965ad..84af0db 100644 --- a/src/main/java/nutshell/server/controller/TaskController.java +++ b/src/main/java/nutshell/server/controller/TaskController.java @@ -3,6 +3,7 @@ import lombok.RequiredArgsConstructor; import nutshell.server.annotation.UserId; import nutshell.server.dto.task.TaskCreateDto; +import nutshell.server.dto.task.TaskDto; import nutshell.server.service.task.TaskService; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -31,4 +32,12 @@ public ResponseEntity deleteTask( taskService.removeTask(userId, taskId); return ResponseEntity.noContent().build(); } + + @GetMapping("/tasks/{taskId}") + public ResponseEntity getTask( + @UserId final Long userId, + @PathVariable Long taskId + ){ + return ResponseEntity.ok(taskService.getTaskDetails(userId, taskId)); + } } diff --git a/src/main/java/nutshell/server/dto/task/TaskDto.java b/src/main/java/nutshell/server/dto/task/TaskDto.java new file mode 100644 index 0000000..a46e96d --- /dev/null +++ b/src/main/java/nutshell/server/dto/task/TaskDto.java @@ -0,0 +1,11 @@ +package nutshell.server.dto.task; +import lombok.Builder; + +@Builder +public record TaskDto( + String name, + String description, + TaskCreateDto.DeadLine deadLine, + String status +) { +} \ No newline at end of file diff --git a/src/main/java/nutshell/server/service/task/TaskService.java b/src/main/java/nutshell/server/service/task/TaskService.java index a13f929..ce712ea 100644 --- a/src/main/java/nutshell/server/service/task/TaskService.java +++ b/src/main/java/nutshell/server/service/task/TaskService.java @@ -4,11 +4,11 @@ import nutshell.server.domain.Task; import nutshell.server.domain.User; import nutshell.server.dto.task.TaskCreateDto; -import nutshell.server.dto.task.TaskResponse; +import nutshell.server.dto.task.TaskDto; import nutshell.server.service.user.UserRetriever; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; - +import java.time.LocalDate; import java.time.LocalDateTime; @Service @@ -25,9 +25,10 @@ public Task createTask(final Long userId, final TaskCreateDto taskCreateDto){ User user = userRetriever.findByUserId(userId); LocalDateTime deadLine = taskCreateDto.deadLine() != null - ? taskCreateDto.deadLine().date() - .withHour(Integer.parseInt(taskCreateDto.deadLine().time().split(":")[0])) - .withMinute(Integer.parseInt(taskCreateDto.deadLine().time().split(":")[1])) + ? taskCreateDto.deadLine().date().atTime( + Integer.parseInt(taskCreateDto.deadLine().time().split(":")[0]), + Integer.parseInt(taskCreateDto.deadLine().time().split(":")[1]) + ) : null; //null 체크 안하면 에러남! Task task = Task.builder() @@ -40,8 +41,21 @@ public Task createTask(final Long userId, final TaskCreateDto taskCreateDto){ @Transactional public void removeTask(final Long userId, final Long taskId) { + User user = userRetriever.findByUserId(userId); Task task = taskRetriever.findTaskByTaskId(taskId); taskRemover.deleteTask(task); } + public TaskDto getTaskDetails(final Long userId, final Long taskId){ + User user = userRetriever.findByUserId(userId); + Task task = taskRetriever.findTaskByTaskId(taskId); + LocalDate date = task.getDeadLine() != null ? task.getDeadLine().toLocalDate() : null; + String time = task.getDeadLine() != null ? task.getDeadLine().getHour() + ":" + task.getDeadLine().getMinute() : null; + + return TaskDto.builder().name(task.getName()) + .description(task.getDescription()) + .deadLine(new TaskCreateDto.DeadLine(date, time)) + .status(task.getStatus().getContent()) + .build(); + } }