You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.5 KiB

3 years ago
3 years ago
  1. import { CommentReadDTO, CommentListDTO } from './commentData'
  2. import { CommentRepository, SearchOption } from '~/domain/models/comment/commentRepository'
  3. import { CommentItem } from '~/domain/models/comment/comment'
  4. export class CommentApplicationService {
  5. constructor(
  6. private readonly repository: CommentRepository
  7. ) {}
  8. public async listProjectComment(projectId: string, options: SearchOption): Promise<CommentListDTO> {
  9. const item = await this.repository.listAll(projectId, options)
  10. return new CommentListDTO(item)
  11. }
  12. public async list(projectId: string, docId: number): Promise<CommentReadDTO[]> {
  13. const items = await this.repository.list(projectId, docId)
  14. return items.map(item => new CommentReadDTO(item))
  15. }
  16. public create(projectId: string, docId: number, text: string): Promise<CommentItem> {
  17. return this.repository.create(projectId, docId, text)
  18. }
  19. public update(projectId: string, docId: number, item: CommentReadDTO): Promise<CommentItem> {
  20. const comment = new CommentItem(
  21. item.id, item.user, item.username, docId, item.text, item.createdAt
  22. )
  23. return this.repository.update(projectId, docId, comment)
  24. }
  25. public delete(projectId: string, docId: number, item: CommentReadDTO): Promise<void> {
  26. return this.repository.delete(projectId, docId, item.id)
  27. }
  28. public deleteBulk(projectId: string, items: CommentReadDTO[]): Promise<void> {
  29. const ids = items.map(item => item.id)
  30. return this.repository.deleteBulk(projectId, ids)
  31. }
  32. }