Skip to content

Commit

Permalink
faet: 태스크 수정 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchef1 authored Nov 11, 2024
1 parent bbc349b commit 8fa6560
Show file tree
Hide file tree
Showing 6 changed files with 4,663 additions and 1,617 deletions.
8 changes: 7 additions & 1 deletion apps/server/src/task/controller/task.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Body, Controller, Post } from '@nestjs/common';
import { Body, Controller, Param, Patch, Post } from '@nestjs/common';
import { TaskService } from '../service/task.service';
import { CreateTaskRequest } from '../dto/create-task-request.dto';
import { UpdateTaskRequest } from '../dto/update-task-request.dto';

@Controller('task')
export class TaskController {
Expand All @@ -10,4 +11,9 @@ export class TaskController {
create(@Body() createTaskRequest: CreateTaskRequest) {
return this.taskService.create(createTaskRequest);
}

@Patch(':id')
update(@Param('id') id: number, @Body() updateTaskRequest: UpdateTaskRequest) {
return this.taskService.update(id, updateTaskRequest);
}
}
7 changes: 7 additions & 0 deletions apps/server/src/task/dto/update-task-request.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class UpdateTaskRequest {
title: string;

description: string;

sectionId: number;
}
21 changes: 21 additions & 0 deletions apps/server/src/task/dto/update-task-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Task } from '../domain/task.entity';

export class UpdateTaskResponse {
constructor(task: Task) {
this.id = task.id;
this.title = task.title;
this.description = task.description;
this.sectionId = task.section.id;
this.position = task.position;
}

id: number;

title: string;

description: string;

sectionId: number;

position: number;
}
Empty file.
21 changes: 21 additions & 0 deletions apps/server/src/task/service/task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Task } from '../domain/task.entity';
import { CreateTaskRequest } from '../dto/create-task-request.dto';
import { CreateTaskResponse } from '../dto/create-task-response.dto';
import { Section } from '../domain/section.entity';
import { UpdateTaskRequest } from '../dto/update-task-request.dto';
import { UpdateTaskResponse } from '../dto/update-task-response.dto';

@Injectable()
export class TaskService {
Expand All @@ -27,4 +29,23 @@ export class TaskService {
});
return new CreateTaskResponse(task);
}

async update(id: number, updateTaskRequest: UpdateTaskRequest) {
const task = await this.taskRepository.findOneBy({ id });
if (!task) {
throw new NotFoundException('Task not found');
}

task.title = updateTaskRequest.title ?? task.title;
task.description = updateTaskRequest.description ?? task.description;

const section = await this.sectionRepository.findOneBy({ id: updateTaskRequest.sectionId });
if (!section) {
throw new NotFoundException('Section not found');
}
task.section = section;

await this.taskRepository.save(task);
return new UpdateTaskResponse(task);
}
}
Loading

0 comments on commit 8fa6560

Please sign in to comment.