Skip to content

Commit

Permalink
feat: 태스크 상세 정보 조회 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jjeonghak committed Nov 24, 2024
1 parent 110fae3 commit 1de1c90
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
9 changes: 9 additions & 0 deletions apps/server/src/task/controller/task.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,13 @@ export class TaskController {
await this.taskService.updateAssignees(user.id, id, body.assignees)
);
}

@Get(':id/detail')
async getTaskDetail(@AuthUser() user: Account, @Param('id') id: number) {
return new BaseResponse(
200,
'태스크 상세 정보 조회 완료했습니다.',
await this.taskService.getTaskDetail(user.id, id)
);
}
}
49 changes: 49 additions & 0 deletions apps/server/src/task/dto/task-details-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Task } from '@/task/domain/task.entity';
import { SprintDetailsResponse } from '@/project/dto/sprint-details-response.dto';
import { AssigneeDetailsResponse } from '@/task/dto/assignee-details-response.dto';
import { LabelDetailsResponse } from '@/project/dto/label-details-response.dto';
import { CreateSubTaskResponse } from '@/task/dto/create-subTask-response.dto';

export class TaskDetailsResponse {
id: number;

title: string;

description: string;

priority: number;

estimate: number;

sprint: SprintDetailsResponse;

assignees: AssigneeDetailsResponse[];

labels: LabelDetailsResponse[];

subtasks: CreateSubTaskResponse[];

constructor(task: Task) {
this.id = task.id;
this.title = task.title;
this.description = task.description;
this.priority = task.priority;
this.estimate = task.estimate;
}

setSprint(sprintDetails: SprintDetailsResponse) {
this.sprint = sprintDetails;
}

setAssignees(assigneeDetails: AssigneeDetailsResponse[]) {
this.assignees = assigneeDetails;
}

setLabels(labelDetails: LabelDetailsResponse[]) {
this.labels = labelDetails;
}

setSubtasks(subtaskDetails: CreateSubTaskResponse[]) {
this.subtasks = subtaskDetails;
}
}
44 changes: 43 additions & 1 deletion apps/server/src/task/service/task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import { Label } from '@/project/entity/label.entity';
import { TaskLabel } from '@/task/domain/task-label.entity';
import { LabelDetailsResponse } from '@/project/dto/label-details-response.dto';
import { TaskAssignee } from '@/task/domain/task-assignee.entity';
import { AssigneeDetailsResponse } from '../dto/assignee-details-response.dto';
import { AssigneeDetailsResponse } from '@/task/dto/assignee-details-response.dto';
import { TaskDetailsResponse } from '@/task/dto/task-details-response.dto';
import { SprintDetailsResponse } from '@/project/dto/sprint-details-response.dto';
import { SubTask } from '@/task/domain/subTask.entity';
import { CreateSubTaskResponse } from '@/task/dto/create-subTask-response.dto';

const { defaultType: json0 } = ShareDB.types;

Expand All @@ -49,6 +53,12 @@ export class TaskService {
private sprintRepository: Repository<Sprint>,
@InjectRepository(Label)
private labelRepository: Repository<Label>,
@InjectRepository(TaskLabel)
private taskLabelRepository: Repository<TaskLabel>,
@InjectRepository(TaskAssignee)
private taskAssigneeRepository: Repository<TaskAssignee>,
@InjectRepository(SubTask)
private subTaskRepository: Repository<SubTask>,
private dataSource: DataSource,
private broadcastService: BroadcastService,
private eventEmitter: EventEmitter2
Expand Down Expand Up @@ -289,6 +299,38 @@ export class TaskService {
};
}

async getTaskDetail(userId: number, taskId: number) {
const task = await this.findTaskOrThrow(taskId);
await this.validateUserRole(userId, task.section.project.id);

const result = new TaskDetailsResponse(task);
const sprint = await this.sprintRepository.findOneBy({ id: task.sprintId });
result.setSprint(sprint ? new SprintDetailsResponse(sprint) : null);

const taskAssigneeRecords = await this.taskAssigneeRepository
.createQueryBuilder('ta')
.leftJoin('account', 'a', 'ta.accountId = a.id')
.where('ta.taskId = :taskId', { taskId })
.addSelect(['a.username'])
.getRawMany();
result.setAssignees(
taskAssigneeRecords.map(
(record) => new AssigneeDetailsResponse(record.ta_accountId, record.a_username, '')
)
);

const labels = await this.labelRepository
.createQueryBuilder('l')
.leftJoin('task_label', 'tl', 'l.id = tl.labelId')
.where('tl.taskId = :taskId', { taskId })
.getMany();
result.setLabels(labels.map((label) => new LabelDetailsResponse(label)));

const subTasks = await this.subTaskRepository.findBy({ taskId });
result.setSubtasks(subTasks.map((subTask) => new CreateSubTaskResponse(subTask)));
return result;
}

private async validateUserRole(userId: number, projectId: number) {
const contributor = await this.contributorRepository.findOneBy({ projectId, userId });
if (!contributor || contributor.status !== ContributorStatus.ACCEPTED) {
Expand Down

0 comments on commit 1de1c90

Please sign in to comment.