From d36c4f436b0e471db0235f23a1db54b3a62ae073 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Thu, 8 Apr 2021 14:30:38 +0900 Subject: [PATCH] Add task status repository and service --- frontend/domain/models/celery/status.ts | 14 ++++++++++++++ .../domain/models/celery/taskStatusRepository.ts | 6 ++++++ frontend/plugins/services.ts | 6 ++++++ .../celery/apiTaskStatusRepository.ts | 16 ++++++++++++++++ .../services/application/celery/statusData.ts | 13 +++++++++++++ .../celery/taskStatusApplicationService.ts | 13 +++++++++++++ .../upload/parseApplicationService.ts | 1 + 7 files changed, 69 insertions(+) create mode 100644 frontend/domain/models/celery/status.ts create mode 100644 frontend/domain/models/celery/taskStatusRepository.ts create mode 100644 frontend/repositories/celery/apiTaskStatusRepository.ts create mode 100644 frontend/services/application/celery/statusData.ts create mode 100644 frontend/services/application/celery/taskStatusApplicationService.ts diff --git a/frontend/domain/models/celery/status.ts b/frontend/domain/models/celery/status.ts new file mode 100644 index 00000000..897f7dc7 --- /dev/null +++ b/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) + } +} diff --git a/frontend/domain/models/celery/taskStatusRepository.ts b/frontend/domain/models/celery/taskStatusRepository.ts new file mode 100644 index 00000000..413314e2 --- /dev/null +++ b/frontend/domain/models/celery/taskStatusRepository.ts @@ -0,0 +1,6 @@ +import { Status } from './status' + + +export interface TaskStatusRepository { + get(taskId: string): Promise +} diff --git a/frontend/plugins/services.ts b/frontend/plugins/services.ts index 1f041a8f..6a334da2 100644 --- a/frontend/plugins/services.ts +++ b/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) } diff --git a/frontend/repositories/celery/apiTaskStatusRepository.ts b/frontend/repositories/celery/apiTaskStatusRepository.ts new file mode 100644 index 00000000..89d25967 --- /dev/null +++ b/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 { + const url = `/tasks/status/${taskId}` + const response = await this.request.get(url) + return Status.valueOf(response.data) + } +} diff --git a/frontend/services/application/celery/statusData.ts b/frontend/services/application/celery/statusData.ts new file mode 100644 index 00000000..9a1c54ea --- /dev/null +++ b/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 + } +} diff --git a/frontend/services/application/celery/taskStatusApplicationService.ts b/frontend/services/application/celery/taskStatusApplicationService.ts new file mode 100644 index 00000000..f7155904 --- /dev/null +++ b/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 { + const item = await this.repository.get(taskId) + return new StatusDTO(item) + } +} diff --git a/frontend/services/application/upload/parseApplicationService.ts b/frontend/services/application/upload/parseApplicationService.ts index 8d68c2cd..19f6a9b0 100644 --- a/frontend/services/application/upload/parseApplicationService.ts +++ b/frontend/services/application/upload/parseApplicationService.ts @@ -8,5 +8,6 @@ export class ParseApplicationService { public async analyze(projectId: string, format: string, uploadIds: number[]): Promise { const item = await this.repository.analyze(projectId, format, uploadIds) return item + } }