Browse Source

Update label repository and service

pull/1680/head
Hironsan 2 years ago
parent
commit
ed42153d58
3 changed files with 13 additions and 0 deletions
  1. 2
      frontend/domain/models/label/labelRepository.ts
  2. 6
      frontend/repositories/label/apiLabelRepository.ts
  3. 5
      frontend/services/application/label/labelApplicationService.ts

2
frontend/domain/models/label/labelRepository.ts

@ -3,6 +3,8 @@ import { LabelItem } from '~/domain/models/label/label'
export interface LabelRepository {
list(projectId: string): Promise<LabelItem[]>
findById(projectId: string, labelId: number): Promise<LabelItem>
create(projectId: string, item: LabelItem): Promise<LabelItem>
update(projectId: string, item: LabelItem): Promise<LabelItem>

6
frontend/repositories/label/apiLabelRepository.ts

@ -24,6 +24,12 @@ export class APILabelRepository implements LabelRepository {
return response.data.map((item: any) => plainToInstance(LabelItem, item))
}
async findById(projectId: string, labelId: number): Promise<LabelItem> {
const url = `/projects/${projectId}/${this.baseUrl}s/${labelId}`
const response = await this.request.get(url)
return plainToInstance(LabelItem, response.data)
}
async create(projectId: string, item: LabelItem): Promise<LabelItem> {
const url = `/projects/${projectId}/${this.baseUrl}s`
const response = await this.request.post(url, item.toObject())

5
frontend/services/application/label/labelApplicationService.ts

@ -14,6 +14,11 @@ export class LabelApplicationService {
return items.map(item => new LabelDTO(item))
}
public async findById(projectId: string, labelId: number): Promise<LabelDTO> {
const item = await this.repository.findById(projectId, labelId)
return new LabelDTO(item)
}
public async create(projectId: string, item: CreateLabelCommand): Promise<LabelDTO> {
// Todo: use auto mapping.
const label = new LabelItem()

Loading…
Cancel
Save