|
@ -13,44 +13,45 @@ export interface LabelItemResponse { |
|
|
|
|
|
|
|
|
export class APILabelRepository implements LabelRepository { |
|
|
export class APILabelRepository implements LabelRepository { |
|
|
constructor( |
|
|
constructor( |
|
|
|
|
|
private readonly baseUrl = 'label', |
|
|
private readonly request = ApiService |
|
|
private readonly request = ApiService |
|
|
) {} |
|
|
) {} |
|
|
|
|
|
|
|
|
async list(projectId: string): Promise<LabelItem[]> { |
|
|
async list(projectId: string): Promise<LabelItem[]> { |
|
|
const url = `/projects/${projectId}/labels` |
|
|
|
|
|
|
|
|
const url = `/projects/${projectId}/${this.baseUrl}s` |
|
|
const response = await this.request.get(url) |
|
|
const response = await this.request.get(url) |
|
|
const responseItems: LabelItemResponse[] = response.data |
|
|
const responseItems: LabelItemResponse[] = response.data |
|
|
return responseItems.map(item => LabelItem.valueOf(item)) |
|
|
return responseItems.map(item => LabelItem.valueOf(item)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async create(projectId: string, item: LabelItem): Promise<LabelItem> { |
|
|
async create(projectId: string, item: LabelItem): Promise<LabelItem> { |
|
|
const url = `/projects/${projectId}/labels` |
|
|
|
|
|
|
|
|
const url = `/projects/${projectId}/${this.baseUrl}s` |
|
|
const response = await this.request.post(url, item.toObject()) |
|
|
const response = await this.request.post(url, item.toObject()) |
|
|
const responseItem: LabelItemResponse = response.data |
|
|
const responseItem: LabelItemResponse = response.data |
|
|
return LabelItem.valueOf(responseItem) |
|
|
return LabelItem.valueOf(responseItem) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async update(projectId: string, item: LabelItem): Promise<LabelItem> { |
|
|
async update(projectId: string, item: LabelItem): Promise<LabelItem> { |
|
|
const url = `/projects/${projectId}/labels/${item.id}` |
|
|
|
|
|
|
|
|
const url = `/projects/${projectId}/${this.baseUrl}s/${item.id}` |
|
|
const response = await this.request.patch(url, item.toObject()) |
|
|
const response = await this.request.patch(url, item.toObject()) |
|
|
const responseItem: LabelItemResponse = response.data |
|
|
const responseItem: LabelItemResponse = response.data |
|
|
return LabelItem.valueOf(responseItem) |
|
|
return LabelItem.valueOf(responseItem) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async bulkDelete(projectId: string, labelIds: number[]): Promise<void> { |
|
|
async bulkDelete(projectId: string, labelIds: number[]): Promise<void> { |
|
|
const url = `/projects/${projectId}/labels` |
|
|
|
|
|
|
|
|
const url = `/projects/${projectId}/${this.baseUrl}s` |
|
|
await this.request.delete(url, { ids: labelIds }) |
|
|
await this.request.delete(url, { ids: labelIds }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async uploadFile(projectId: string, payload: FormData): Promise<void> { |
|
|
async uploadFile(projectId: string, payload: FormData): Promise<void> { |
|
|
const url = `/projects/${projectId}/label-upload` |
|
|
|
|
|
|
|
|
const url = `/projects/${projectId}/${this.baseUrl}-upload` |
|
|
const config = { |
|
|
const config = { |
|
|
headers: { |
|
|
headers: { |
|
|
'Content-Type': 'multipart/form-data' |
|
|
'Content-Type': 'multipart/form-data' |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
try { |
|
|
try { |
|
|
await this.request.post(`/projects/${projectId}/label-upload`, payload, config) |
|
|
|
|
|
|
|
|
await this.request.post(url, payload, config) |
|
|
} catch(e) { |
|
|
} catch(e) { |
|
|
const data = e.response.data |
|
|
const data = e.response.data |
|
|
if ('detail' in data) { |
|
|
if ('detail' in data) { |
|
|