Browse Source

Add task status repository and service

pull/1310/head
Hironsan 3 years ago
parent
commit
d36c4f436b
7 changed files with 69 additions and 0 deletions
  1. 14
      frontend/domain/models/celery/status.ts
  2. 6
      frontend/domain/models/celery/taskStatusRepository.ts
  3. 6
      frontend/plugins/services.ts
  4. 16
      frontend/repositories/celery/apiTaskStatusRepository.ts
  5. 13
      frontend/services/application/celery/statusData.ts
  6. 13
      frontend/services/application/celery/taskStatusApplicationService.ts
  7. 1
      frontend/services/application/upload/parseApplicationService.ts

14
frontend/domain/models/celery/status.ts

@ -0,0 +1,14 @@
export class Status {
constructor(
public ready: boolean,
public result: object,
public error: any
) {}
static valueOf(
{ ready, result, error }:
{ ready: boolean, result: object, error: any }
) {
return new Status(ready, result, error)
}
}

6
frontend/domain/models/celery/taskStatusRepository.ts

@ -0,0 +1,6 @@
import { Status } from './status'
export interface TaskStatusRepository {
get(taskId: string): Promise<Status>
}

6
frontend/plugins/services.ts

@ -1,4 +1,6 @@
import { Plugin } from '@nuxt/types'
import { APITaskStatusRepository } from '@/repositories/celery/apiTaskStatusRepository'
import { TaskStatusApplicationService } from '@/services/application/celery/taskStatusApplicationService'
import { APICatalogRepository } from '../repositories/upload/apiCatalogRepository'
import { CatalogApplicationService } from '../services/application/upload/catalogApplicationService'
import { APIParseRepository } from '../repositories/upload/apiParseRepository'
@ -52,6 +54,7 @@ export interface Services {
auth: AuthApplicationService,
catalog: CatalogApplicationService,
parse: ParseApplicationService,
taskStatus: TaskStatusApplicationService,
}
declare module 'vue/types/vue' {
@ -78,6 +81,7 @@ const plugin: Plugin = (context, inject) => {
const authRepository = new APIAuthRepository()
const catalogRepository = new APICatalogRepository()
const parseRepository = new APIParseRepository()
const taskStatusRepository = new APITaskStatusRepository()
const label = new LabelApplicationService(labelRepository)
const member = new MemberApplicationService(memberRepository)
@ -96,6 +100,7 @@ const plugin: Plugin = (context, inject) => {
const auth = new AuthApplicationService(authRepository)
const catalog = new CatalogApplicationService(catalogRepository)
const parse = new ParseApplicationService(parseRepository)
const taskStatus = new TaskStatusApplicationService(taskStatusRepository)
const services: Services = {
label,
@ -115,6 +120,7 @@ const plugin: Plugin = (context, inject) => {
auth,
catalog,
parse,
taskStatus,
}
inject('services', services)
}

16
frontend/repositories/celery/apiTaskStatusRepository.ts

@ -0,0 +1,16 @@
import ApiService from '@/services/api.service'
import { TaskStatusRepository } from '@/domain/models/celery/taskStatusRepository'
import { Status } from '@/domain/models/celery/status'
export class APITaskStatusRepository implements TaskStatusRepository {
constructor(
private readonly request = ApiService
) {}
async get(taskId: string): Promise<Status> {
const url = `/tasks/status/${taskId}`
const response = await this.request.get(url)
return Status.valueOf(response.data)
}
}

13
frontend/services/application/celery/statusData.ts

@ -0,0 +1,13 @@
import { Status } from '@/domain/models/celery/status'
export class StatusDTO {
ready: boolean
result: object
error: any
constructor(item: Status) {
this.ready = item.ready
this.result = item.result
this.error = item.error
}
}

13
frontend/services/application/celery/taskStatusApplicationService.ts

@ -0,0 +1,13 @@
import { TaskStatusRepository } from '@/domain/models/celery/taskStatusRepository'
import { StatusDTO } from './statusData'
export class TaskStatusApplicationService {
constructor(
private readonly repository: TaskStatusRepository
) {}
public async get(taskId: string): Promise<StatusDTO> {
const item = await this.repository.get(taskId)
return new StatusDTO(item)
}
}

1
frontend/services/application/upload/parseApplicationService.ts

@ -8,5 +8,6 @@ export class ParseApplicationService {
public async analyze(projectId: string, format: string, uploadIds: number[]): Promise<string> {
const item = await this.repository.analyze(projectId, format, uploadIds)
return item
}
}
Loading…
Cancel
Save