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.

47 lines
2.0 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  1. import ApiService from '@/services/api.service'
  2. import { CommentRepository, CommentItemResponse } from '@/domain/models/comment/commentRepository'
  3. import { CommentItem } from '~/domain/models/comment/comment'
  4. export class APICommentRepository implements CommentRepository {
  5. constructor(
  6. private readonly request = ApiService
  7. ) {}
  8. async listAll(projectId: string, q: string): Promise<CommentItem[]> {
  9. const url = `/projects/${projectId}/comments?q=${q}`
  10. const response = await this.request.get(url)
  11. const items: CommentItemResponse[] = response.data
  12. return items.map(item => CommentItem.valueOf(item))
  13. }
  14. async list(projectId: string, exampleId: number): Promise<CommentItem[]> {
  15. const url = `/projects/${projectId}/examples/${exampleId}/comments`
  16. const response = await this.request.get(url)
  17. const items: CommentItemResponse[] = response.data
  18. return items.map(item => CommentItem.valueOf(item))
  19. }
  20. async create(projectId: string, exampleId: number, text: string): Promise<CommentItem> {
  21. const url = `/projects/${projectId}/examples/${exampleId}/comments`
  22. const response = await this.request.post(url, { projectId, exampleId, text })
  23. const responseItem: CommentItemResponse = response.data
  24. return CommentItem.valueOf(responseItem)
  25. }
  26. async update(projectId: string, exampleId: number, item: CommentItem): Promise<CommentItem> {
  27. const url = `/projects/${projectId}/examples/${exampleId}/comments/${item.id}`
  28. const response = await this.request.put(url, item.toObject())
  29. const responseItem: CommentItemResponse = response.data
  30. return CommentItem.valueOf(responseItem)
  31. }
  32. async delete(projectId: string, exampleId: number, commentId: number): Promise<void> {
  33. const url = `/projects/${projectId}/examples/${exampleId}/comments/${commentId}`
  34. const response = await this.request.delete(url)
  35. }
  36. async deleteBulk(projectId: string, items: number[]): Promise<void> {
  37. const url = `/projects/${projectId}/comments`
  38. await this.request.delete(url, { ids: items })
  39. }
  40. }