From 24fb818cfac064693cb9b7a4ab2700c603865a57 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Thu, 4 Mar 2021 10:31:26 +0900 Subject: [PATCH] Use comment DTO --- .../services/application/comment.service.ts | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/frontend/services/application/comment.service.ts b/frontend/services/application/comment.service.ts index 2b2037d7..e0e007c0 100644 --- a/frontend/services/application/comment.service.ts +++ b/frontend/services/application/comment.service.ts @@ -1,13 +1,30 @@ import { CommentItem, CommentItemList } from '@/models/comment' import { CommentItemListRepository } from '@/repositories/comment/interface' +export class CommentReadDTO { + id: number + username: string + documentText: string + text: string + createdAt: string + + constructor(item: CommentItem) { + this.id = item.id + this.username = item.username + this.documentText = item.documentText + this.text = item.text + this.createdAt = item.createdAt + } +} + export class CommentApplicationService { constructor( private readonly repository: CommentItemListRepository ) {} - public listProjectComment(projectId: string, q: string = ''): Promise { - return this.repository.listAll(projectId, q) + public async listProjectComment(projectId: string, q: string = ''): Promise { + const items = await this.repository.listAll(projectId, q) + return items.map(item => new CommentReadDTO(item)) } public list(projectId: string, docId: string): Promise { @@ -26,7 +43,8 @@ export class CommentApplicationService { return this.repository.delete(projectId, docId, item) } - public deleteBulk(projectId: string, items: CommentItemList): Promise { - return this.repository.deleteBulk(projectId, items) + public deleteBulk(projectId: string, items: CommentReadDTO[]): Promise { + const ids = items.map(item => item.id) + return this.repository.deleteBulk(projectId, ids) } }