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
1.7 KiB

  1. import ApiService from '@/services/api.service'
  2. import {LinkRepository} from "~/domain/models/links/linkRepository";
  3. import {LinkItem} from "~/domain/models/links/link";
  4. import {LabelItem} from "~/domain/models/label/label";
  5. import {LabelItemResponse} from "~/repositories/label/apiLabelRepository";
  6. export interface LinkResponse {
  7. id: number
  8. annotation_id_1: number
  9. annotation_id_2: number
  10. type: number,
  11. user: number,
  12. timestamp: string
  13. }
  14. export class ApiLinkRepository implements LinkRepository {
  15. constructor(
  16. private readonly request = ApiService
  17. ) {
  18. }
  19. async list(projectId: string): Promise<LinkItem[]> {
  20. const url = `/projects/${projectId}/annotation_relations`
  21. const response = await this.request.get(url)
  22. const responseLinks: LinkResponse[] = response.data
  23. return responseLinks.map(link => LinkItem.valueOf(link))
  24. }
  25. async create(projectId: string, item: LinkItem): Promise<LinkItem> {
  26. const url = `/projects/${projectId}/annotation_relations`
  27. const response = await this.request.post(url, item.toObject())
  28. const responseItem: LinkResponse = response.data
  29. return LinkItem.valueOf(responseItem)
  30. }
  31. async update(projectId: string, linkId: number, linkType: number): Promise<LinkItem> {
  32. const url = `/projects/${projectId}/annotation_relations/${linkId}`
  33. const response = await this.request.patch(url, {type: linkType})
  34. const responseItem: LinkResponse = response.data
  35. return LinkItem.valueOf(responseItem)
  36. }
  37. async bulkDelete(projectId: string, linkIds: number[]): Promise<void> {
  38. const url = `/projects/${projectId}/annotation_relations`
  39. await this.request.delete(url, {ids: linkIds})
  40. }
  41. }