Browse Source

Add project repository

pull/1230/head
Hironsan 3 years ago
parent
commit
7e993eb3a8
2 changed files with 48 additions and 0 deletions
  1. 36
      frontend/repositories/project/api.ts
  2. 12
      frontend/repositories/project/interface.ts

36
frontend/repositories/project/api.ts

@ -0,0 +1,36 @@
import ApiService from '@/services/api.service'
import { ProjectItem } from '@/models/project'
import { ProjectItemListRepository } from './interface'
export class FromApiProjectItemListRepository implements ProjectItemListRepository {
constructor(
private readonly request = ApiService
) {}
async list(): Promise<ProjectItem[]> {
const url = `/projects`
const response = await this.request.get(url)
const responseItems: ProjectItem[] = response.data
return responseItems.map(item => ProjectItem.valueOf(item))
}
async create(item: ProjectItem): Promise<ProjectItem> {
const url = `/projects`
const response = await this.request.post(url, item.toObject())
const responseItem: ProjectItem = response.data
return ProjectItem.valueOf(responseItem)
}
async update(item: ProjectItem): Promise<ProjectItem> {
const url = `/projects/${item.id}`
const response = await this.request.patch(url, item.toObject())
const responseItem: ProjectItem = response.data
return ProjectItem.valueOf(responseItem)
}
async bulkDelete(projectIds: number[]): Promise<void> {
const url = `/projects`
await this.request.delete(url, { ids: projectIds })
}
}

12
frontend/repositories/project/interface.ts

@ -0,0 +1,12 @@
import { ProjectItem } from '@/models/project'
export interface ProjectItemListRepository {
list(): Promise<ProjectItem[]>
create(item: ProjectItem): Promise<ProjectItem>
update(item: ProjectItem): Promise<ProjectItem>
bulkDelete(projectIds: number[]): Promise<void>
}
Loading…
Cancel
Save