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.

37 lines
1.3 KiB

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