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 { ProjectReadItem, ProjectWriteItem } from '@/models/project'
  3. import { ProjectItemListRepository } from './interface'
  4. export class FromApiProjectItemListRepository implements ProjectItemListRepository {
  5. constructor(
  6. private readonly request = ApiService
  7. ) {}
  8. async list(): Promise<ProjectReadItem[]> {
  9. const url = `/projects`
  10. const response = await this.request.get(url)
  11. const responseItems: ProjectReadItem[] = response.data
  12. return responseItems.map(item => ProjectReadItem.valueOf(item))
  13. }
  14. async findById(id: string): Promise<ProjectReadItem> {
  15. const url = `/projects/${id}`
  16. const response = await this.request.get(url)
  17. const responseItem: ProjectReadItem = response.data
  18. return ProjectReadItem.valueOf(responseItem)
  19. }
  20. async create(item: ProjectWriteItem): Promise<ProjectReadItem> {
  21. const url = `/projects`
  22. const response = await this.request.post(url, item.toObject())
  23. const responseItem: ProjectReadItem = response.data
  24. return ProjectReadItem.valueOf(responseItem)
  25. }
  26. async update(item: ProjectWriteItem): Promise<void> {
  27. const url = `/projects/${item.id}`
  28. const response = await this.request.patch(url, item.toObject())
  29. }
  30. async bulkDelete(projectIds: number[]): Promise<void> {
  31. const url = `/projects`
  32. await this.request.delete(url, { ids: projectIds })
  33. }
  34. }