diff --git a/src/main/java/nutshell/server/controller/TaskController.java b/src/main/java/nutshell/server/controller/TaskController.java index ff05d6e..eb6453d 100644 --- a/src/main/java/nutshell/server/controller/TaskController.java +++ b/src/main/java/nutshell/server/controller/TaskController.java @@ -6,6 +6,7 @@ import nutshell.server.service.task.TaskService; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.net.URI; @RestController @RequiredArgsConstructor @@ -20,7 +21,6 @@ public ResponseEntity createTask( @UserId final Long userId, @RequestBody final TaskCreateDto taskCreateDto ){ - taskService.createTask(userId, taskCreateDto); - return ResponseEntity.ok().build(); + return ResponseEntity.created(URI.create(taskService.createTask(userId, taskCreateDto).getId().toString())).build(); } } diff --git a/src/main/java/nutshell/server/service/task/TaskSaver.java b/src/main/java/nutshell/server/service/task/TaskSaver.java index 248a28f..92eb763 100644 --- a/src/main/java/nutshell/server/service/task/TaskSaver.java +++ b/src/main/java/nutshell/server/service/task/TaskSaver.java @@ -10,7 +10,7 @@ public class TaskSaver { private final TaskRepository taskRepository; - public void save(final Task task) { - taskRepository.save(task); + public Task save(final Task task) { + return taskRepository.save(task); } } diff --git a/src/main/java/nutshell/server/service/task/TaskService.java b/src/main/java/nutshell/server/service/task/TaskService.java index 810eb5b..dde22f7 100644 --- a/src/main/java/nutshell/server/service/task/TaskService.java +++ b/src/main/java/nutshell/server/service/task/TaskService.java @@ -17,9 +17,11 @@ public class TaskService { private final UserRetriever userRetriever; private final TaskSaver taskSaver; + private final TaskRetriever taskRetriever; + private final TaskRemover taskRemover; @Transactional - public void createTask(final Long userId, final TaskCreateDto taskCreateDto){ + public Task createTask(final Long userId, final TaskCreateDto taskCreateDto){ User user = userRetriever.findByUserId(userId); LocalDateTime deadLine = taskCreateDto.deadLine() != null @@ -33,6 +35,6 @@ public void createTask(final Long userId, final TaskCreateDto taskCreateDto){ .name(taskCreateDto.name()) .deadLine(deadLine) .build(); - taskSaver.save(task); + return taskSaver.save(task); } }