diff --git a/src/main/java/yapp/allround3/task/controller/TaskController.java b/src/main/java/yapp/allround3/task/controller/TaskController.java index 9e010d0..a5a6703 100644 --- a/src/main/java/yapp/allround3/task/controller/TaskController.java +++ b/src/main/java/yapp/allround3/task/controller/TaskController.java @@ -1,6 +1,7 @@ package yapp.allround3.task.controller; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import yapp.allround3.common.dto.CustomResponse; import yapp.allround3.common.interceptor.NoAuth; @@ -17,6 +18,7 @@ import java.time.LocalDate; import java.util.List; +@Slf4j @RestController @CrossOrigin(origins = "*") @RequiredArgsConstructor @@ -33,9 +35,8 @@ public CustomResponse findTaskById( Task task = taskService.findTaskById(taskId); Participant participant = participantService.findParticipantById(task.getParticipant().getId()); - int participantCount = participantService.findParticipantCountByProject(participant.getProject()) - 1; //자기 자신 제외 List taskContents = taskService.findTaskContentsByTask(task); - TaskResponse.TaskInfo taskInfo = TaskResponse.TaskInfo.of(task, participant, participantCount, taskContents); + TaskResponse.TaskInfo taskInfo = TaskResponse.TaskInfo.of(task, participant, taskContents); return CustomResponse.success(taskInfo); } @@ -48,6 +49,7 @@ public CustomResponse createTask(@PathVariable Long projectId, .dueDate(taskCreateRequest.getDueDate()) .startDate(taskCreateRequest.getStartDate()) .memo(taskCreateRequest.getMemo()) + .feedbackRequiredPersonnel(participantService.findParticipantCountByProjectId(projectId)-1) .status(taskCreateRequest.getTaskStatus())) .participant(participant) .build(); @@ -106,13 +108,12 @@ public CustomResponse> findTasksByProject( @RequestParam(name = "participant-id") Long participantId ) { Project project = projectService.findProjectById(projectId); - int participantCount = projectService.findParticipantCountByProject(project); Participant representative = participantService.findParticipantById(participantId); List tasks = taskService.findTaskByParticipant(representative); List taskInfos = tasks.stream() .map(task -> - TaskResponse.TaskInfo.of(task, representative, participantCount, taskService.findTaskContentsByTask(task))) + TaskResponse.TaskInfo.of(task, representative, taskService.findTaskContentsByTask(task))) .toList(); return CustomResponse.success(taskInfos); } diff --git a/src/main/java/yapp/allround3/task/controller/dto/TaskResponse.java b/src/main/java/yapp/allround3/task/controller/dto/TaskResponse.java index bb2f93f..e346dd8 100644 --- a/src/main/java/yapp/allround3/task/controller/dto/TaskResponse.java +++ b/src/main/java/yapp/allround3/task/controller/dto/TaskResponse.java @@ -1,5 +1,6 @@ package yapp.allround3.task.controller.dto; +import jakarta.annotation.Nullable; import lombok.Data; import lombok.NoArgsConstructor; import yapp.allround3.participant.domain.Participant; @@ -23,11 +24,11 @@ public static class TaskInfo { private TaskStatus taskStatus; private LocalDate feedbackDueDate; private int confirmCount; - private int participantCount; + private int feedbackRequiredPersonnel; private List taskContents; - public static TaskInfo of(Task task, Participant participant, int participantCount, List taskContents) { + public static TaskInfo of(Task task, Participant participant, List taskContents) { TaskInfo taskInfo = new TaskInfo(); MemberInfo representative = MemberInfo.of(participant); @@ -39,7 +40,7 @@ public static TaskInfo of(Task task, Participant participant, int participantCou taskInfo.setDueDate(task.getDueDate()); taskInfo.setTaskStatus(task.getStatus()); taskInfo.setConfirmCount(task.getConfirmCount()); - taskInfo.setParticipantCount(participantCount); + taskInfo.setFeedbackRequiredPersonnel(task.getFeedbackRequiredPersonnel()); taskInfo.setFeedbackDueDate(task.getFeedbackRequestedDate()); List taskContentInfos = taskContents.stream().map(TaskContentInfo::of).toList(); diff --git a/src/main/java/yapp/allround3/task/domain/Task.java b/src/main/java/yapp/allround3/task/domain/Task.java index 1ccc01f..8ea6994 100644 --- a/src/main/java/yapp/allround3/task/domain/Task.java +++ b/src/main/java/yapp/allround3/task/domain/Task.java @@ -8,7 +8,6 @@ import org.hibernate.annotations.Formula; import yapp.allround3.common.entity.BaseTimeEntity; import yapp.allround3.participant.domain.Participant; -import yapp.allround3.project.domain.Project; import java.time.LocalDate; @@ -40,19 +39,21 @@ public class Task extends BaseTimeEntity { private LocalDate feedbackRequestedDate; + private int feedbackRequiredPersonnel; + @Formula("(SELECT count(*) FROM feedback f WHERE f.task_id= task_id)") private int confirmCount; - - @Builder - public Task(Participant participant, LocalDate startDate, LocalDate dueDate, String title, String memo, TaskStatus status) { + public Task(Participant participant, LocalDate startDate, LocalDate dueDate, String title, String memo, TaskStatus status, + int feedbackRequiredPersonnel) { this.participant = participant; this.startDate = startDate; this.dueDate = dueDate; this.title = title; this.memo = memo; this.status = status; + this.feedbackRequiredPersonnel = feedbackRequiredPersonnel; } public void updateTitle(String title) { @@ -78,4 +79,19 @@ public void updateTaskStatus(TaskStatus taskStatus) { public void updateFeedbackRequestedDate(LocalDate feedbackRequestedDate){ this.feedbackRequestedDate = feedbackRequestedDate; } + + @Override + public String toString() { + return "Task{" + + "id=" + id + + ", startDate=" + startDate + + ", dueDate=" + dueDate + + ", title='" + title + '\'' + + ", memo='" + memo + '\'' + + ", status=" + status + + ", feedbackRequestedDate=" + feedbackRequestedDate + + ", feedbackRequiredPersonnel=" + feedbackRequiredPersonnel + + ", confirmCount=" + confirmCount + + '}'; + } }