Skip to content

Commit

Permalink
✨ Task에 participantCount 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ashlovesliitea committed Feb 19, 2023
1 parent 84c1f97 commit f8e2459
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,6 +18,7 @@
import java.time.LocalDate;
import java.util.List;

@Slf4j
@RestController
@CrossOrigin(origins = "*")
@RequiredArgsConstructor
Expand All @@ -33,9 +35,8 @@ public CustomResponse<TaskResponse.TaskInfo> findTaskById(

Task task = taskService.findTaskById(taskId);
Participant participant = participantService.findParticipantById(task.getParticipant().getId());
int participantCount = participantService.findParticipantCountByProject(participant.getProject()) - 1; //자기 자신 제외
List<TaskContent> 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);
}

Expand All @@ -48,6 +49,7 @@ public CustomResponse<String> createTask(@PathVariable Long projectId,
.dueDate(taskCreateRequest.getDueDate())
.startDate(taskCreateRequest.getStartDate())
.memo(taskCreateRequest.getMemo())
.feedbackRequiredPersonnel(participantService.findParticipantCountByProjectId(projectId)-1)
.status(taskCreateRequest.getTaskStatus()))
.participant(participant)
.build();
Expand Down Expand Up @@ -106,13 +108,12 @@ public CustomResponse<List<TaskResponse.TaskInfo>> findTasksByProject(
@RequestParam(name = "participant-id") Long participantId
) {
Project project = projectService.findProjectById(projectId);
int participantCount = projectService.findParticipantCountByProject(project);
Participant representative = participantService.findParticipantById(participantId);

List<Task> tasks = taskService.findTaskByParticipant(representative);
List<TaskResponse.TaskInfo> 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<TaskContentInfo> taskContents;

public static TaskInfo of(Task task, Participant participant, int participantCount, List<TaskContent> taskContents) {
public static TaskInfo of(Task task, Participant participant, List<TaskContent> taskContents) {
TaskInfo taskInfo = new TaskInfo();
MemberInfo representative = MemberInfo.of(participant);

Expand All @@ -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<TaskContentInfo> taskContentInfos = taskContents.stream().map(TaskContentInfo::of).toList();
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/yapp/allround3/task/domain/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -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 +
'}';
}
}

0 comments on commit f8e2459

Please sign in to comment.