Browse Source

Rename ProjectReadItem to Project

pull/2093/head
Hironsan 2 years ago
parent
commit
973fb9091f
5 changed files with 21 additions and 21 deletions
  1. 4
      frontend/domain/models/project/project.ts
  2. 10
      frontend/domain/models/project/projectRepository.ts
  3. 16
      frontend/repositories/project/apiProjectRepository.ts
  4. 6
      frontend/services/application/project/projectApplicationService.ts
  5. 6
      frontend/services/application/project/projectData.ts

4
frontend/domain/models/project/project.ts

@ -19,7 +19,7 @@ export type ProjectType =
| typeof Segmentation
| typeof Speech2text
export class ProjectReadItem {
export class Project {
constructor(
readonly id: number,
readonly name: string,
@ -54,7 +54,7 @@ export class ProjectReadItem {
useRelation: boolean,
tags: Object[]
) {
return new ProjectReadItem(
return new Project(
id,
name,
description,

10
frontend/domain/models/project/projectRepository.ts

@ -1,5 +1,5 @@
import { Page } from '~/domain/models/page'
import { ProjectReadItem } from '~/domain/models/project/project'
import { Project } from '~/domain/models/project/project'
const sortableFieldList = ['name', 'projectType', 'createdAt', 'author'] as const
type SortableFields = typeof sortableFieldList[number]
@ -23,13 +23,13 @@ export class SearchQuery {
}
export interface ProjectRepository {
list(query: SearchQuery): Promise<Page<ProjectReadItem>>
list(query: SearchQuery): Promise<Page<Project>>
findById(id: string): Promise<ProjectReadItem>
findById(id: string): Promise<Project>
create(item: ProjectReadItem): Promise<ProjectReadItem>
create(item: Project): Promise<Project>
update(item: ProjectReadItem): Promise<void>
update(item: Project): Promise<void>
bulkDelete(projectIds: number[]): Promise<void>
}

16
frontend/repositories/project/apiProjectRepository.ts

@ -1,10 +1,10 @@
import { Page } from '@/domain/models/page'
import { ProjectReadItem } from '@/domain/models/project/project'
import { Project } from '@/domain/models/project/project'
import { ProjectRepository, SearchQuery } from '@/domain/models/project/projectRepository'
import ApiService from '@/services/api.service'
function toModel(item: { [key: string]: any }): ProjectReadItem {
return new ProjectReadItem(
function toModel(item: { [key: string]: any }): Project {
return new Project(
item.id,
item.name,
item.description,
@ -25,7 +25,7 @@ function toModel(item: { [key: string]: any }): ProjectReadItem {
)
}
function toPayload(item: ProjectReadItem): { [key: string]: any } {
function toPayload(item: Project): { [key: string]: any } {
return {
id: item.id,
name: item.name,
@ -46,7 +46,7 @@ function toPayload(item: ProjectReadItem): { [key: string]: any } {
export class APIProjectRepository implements ProjectRepository {
constructor(private readonly request = ApiService) {}
async list(query: SearchQuery): Promise<Page<ProjectReadItem>> {
async list(query: SearchQuery): Promise<Page<Project>> {
const fieldMapper = {
name: 'name',
createdAt: 'created_at',
@ -65,20 +65,20 @@ export class APIProjectRepository implements ProjectRepository {
)
}
async findById(id: string): Promise<ProjectReadItem> {
async findById(id: string): Promise<Project> {
const url = `/projects/${id}`
const response = await this.request.get(url)
return toModel(response.data)
}
async create(item: ProjectReadItem): Promise<ProjectReadItem> {
async create(item: Project): Promise<Project> {
const url = `/projects`
const payload = toPayload(item)
const response = await this.request.post(url, payload)
return toModel(response.data)
}
async update(item: ProjectReadItem): Promise<void> {
async update(item: Project): Promise<void> {
const url = `/projects/${item.id}`
const payload = toPayload(item)
await this.request.patch(url, payload)

6
frontend/services/application/project/projectApplicationService.ts

@ -1,4 +1,4 @@
import { ProjectReadItem } from '~/domain/models/project/project'
import { Project } from '~/domain/models/project/project'
import { ProjectRepository, SearchQuery } from '~/domain/models/project/projectRepository'
import {
ProjectDTO,
@ -50,8 +50,8 @@ export class ProjectApplicationService {
return this.repository.bulkDelete(ids)
}
private toModel(item: ProjectWriteDTO): ProjectReadItem {
return ProjectReadItem.create(
private toModel(item: ProjectWriteDTO): Project {
return Project.create(
item.id,
item.name,
item.description,

6
frontend/services/application/project/projectData.ts

@ -1,5 +1,5 @@
import { Page } from '~/domain/models/page'
import { ProjectReadItem, ProjectType } from '~/domain/models/project/project'
import { Project, ProjectType } from '~/domain/models/project/project'
export class ProjectDTO {
id: number
@ -25,7 +25,7 @@ export class ProjectDTO {
taskNames: string[]
useRelation: boolean
constructor(item: ProjectReadItem) {
constructor(item: Project) {
this.id = item.id
this.name = item.name
this.description = item.description
@ -72,7 +72,7 @@ export class ProjectListDTO {
prev: string | null
items: ProjectDTO[]
constructor(item: Page<ProjectReadItem>) {
constructor(item: Page<Project>) {
this.count = item.count
this.next = item.next
this.prev = item.prev

Loading…
Cancel
Save