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.

41 lines
1.4 KiB

  1. import ApiService from '@/services/api.service'
  2. import { AnnotationModel } from './interface'
  3. export abstract class AnnotationRepository<T extends AnnotationModel> {
  4. constructor(
  5. private readonly model: any,
  6. readonly request = ApiService
  7. ) {}
  8. public async list(projectId: string, docId: number): Promise<T[]> {
  9. const url = this.baseUrl(projectId, docId)
  10. const response = await this.request.get(url)
  11. const items: T[] = response.data
  12. return items.map(item => this.model.valueOf(item))
  13. }
  14. public async create(projectId: string, docId: number, item: T): Promise<void> {
  15. const url = this.baseUrl(projectId, docId)
  16. await this.request.post(url, item.toObject())
  17. }
  18. public async delete(projectId: string, docId: number, annotationId: number): Promise<void> {
  19. const url = this.baseUrl(projectId, docId) + `/${annotationId}`
  20. await this.request.delete(url)
  21. }
  22. public async clear(projectId: string, docId: number): Promise<void> {
  23. const url = this.baseUrl(projectId, docId)
  24. await this.request.delete(url)
  25. }
  26. public async autoLabel(projectId: string, docId: number): Promise<void> {
  27. const url = `/projects/${projectId}/examples/${docId}/auto-labeling`
  28. await this.request.post(url, {})
  29. }
  30. protected baseUrl(projectId: string, docId: number): string {
  31. return `/projects/${projectId}/examples/${docId}/annotations`
  32. }
  33. }