Skip to content

Commit

Permalink
Merge pull request #30 from TEAM-DAWM/feat/28
Browse files Browse the repository at this point in the history
[feat] Task �상세조회 GET API 구현
  • Loading branch information
choyeongju authored Jul 8, 2024
2 parents 5636a4f + 0203772 commit b13bd55
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/main/java/nutshell/server/controller/TaskController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -31,4 +32,12 @@ public ResponseEntity<Void> deleteTask(
taskService.removeTask(userId, taskId);
return ResponseEntity.noContent().build();
}

@GetMapping("/tasks/{taskId}")
public ResponseEntity<TaskDto> getTask(
@UserId final Long userId,
@PathVariable Long taskId
){
return ResponseEntity.ok(taskService.getTaskDetails(userId, taskId));
}
}
11 changes: 11 additions & 0 deletions src/main/java/nutshell/server/dto/task/TaskDto.java
Original file line number Diff line number Diff line change
@@ -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
) {
}
24 changes: 19 additions & 5 deletions src/main/java/nutshell/server/service/task/TaskService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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();
}
}

0 comments on commit b13bd55

Please sign in to comment.