diff --git a/frontend/domain/models/page.ts b/frontend/domain/models/page.ts new file mode 100644 index 00000000..85527b04 --- /dev/null +++ b/frontend/domain/models/page.ts @@ -0,0 +1,8 @@ +export class Page { + constructor( + readonly count: number, + readonly next: string | null, + readonly prev: string | null, + readonly items: T[] + ) {} +} diff --git a/frontend/domain/models/project/project.ts b/frontend/domain/models/project/project.ts index dfb214a8..300640c4 100644 --- a/frontend/domain/models/project/project.ts +++ b/frontend/domain/models/project/project.ts @@ -74,15 +74,6 @@ export class ProjectReadItem { } } -export class ProjectItemList { - constructor( - readonly count: number, - readonly next: string | null, - readonly prev: string | null, - readonly items: ProjectReadItem[] - ) {} -} - export class ProjectWriteItem { constructor( public id: number, diff --git a/frontend/domain/models/project/projectRepository.ts b/frontend/domain/models/project/projectRepository.ts index 4a46cb4a..301ad357 100644 --- a/frontend/domain/models/project/projectRepository.ts +++ b/frontend/domain/models/project/projectRepository.ts @@ -1,4 +1,5 @@ -import { ProjectReadItem, ProjectWriteItem, ProjectItemList } from '~/domain/models/project/project' +import { Page } from '~/domain/models/page' +import { ProjectReadItem, ProjectWriteItem } from '~/domain/models/project/project' const sortableFieldList = ['name', 'projectType', 'createdAt', 'author'] as const type SortableFields = typeof sortableFieldList[number] @@ -22,7 +23,7 @@ export class SearchQuery { } export interface ProjectRepository { - list(query: SearchQuery): Promise + list(query: SearchQuery): Promise> findById(id: string): Promise diff --git a/frontend/repositories/project/apiProjectRepository.ts b/frontend/repositories/project/apiProjectRepository.ts index 17495db9..ab069933 100644 --- a/frontend/repositories/project/apiProjectRepository.ts +++ b/frontend/repositories/project/apiProjectRepository.ts @@ -1,4 +1,5 @@ -import { ProjectItemList, ProjectReadItem, ProjectWriteItem } from '@/domain/models/project/project' +import { Page } from '@/domain/models/page' +import { ProjectReadItem, ProjectWriteItem } from '@/domain/models/project/project' import { ProjectRepository, SearchQuery } from '@/domain/models/project/projectRepository' import ApiService from '@/services/api.service' @@ -46,7 +47,7 @@ function toPayload(item: ProjectWriteItem): { [key: string]: any } { export class APIProjectRepository implements ProjectRepository { constructor(private readonly request = ApiService) {} - async list(query: SearchQuery): Promise { + async list(query: SearchQuery): Promise> { const fieldMapper = { name: 'name', createdAt: 'created_at', @@ -57,7 +58,7 @@ export class APIProjectRepository implements ProjectRepository { const ordering = query.sortDesc ? `-${sortBy}` : `${sortBy}` const url = `/projects?limit=${query.limit}&offset=${query.offset}&q=${query.q}&ordering=${ordering}` const response = await this.request.get(url) - return new ProjectItemList( + return new Page( response.data.count, response.data.next, response.data.previous, diff --git a/frontend/services/application/project/projectData.ts b/frontend/services/application/project/projectData.ts index f8936540..c01b625f 100644 --- a/frontend/services/application/project/projectData.ts +++ b/frontend/services/application/project/projectData.ts @@ -1,4 +1,5 @@ -import { ProjectItemList, ProjectReadItem, ProjectType } from '~/domain/models/project/project' +import { Page } from '~/domain/models/page' +import { ProjectReadItem, ProjectType } from '~/domain/models/project/project' export class ProjectDTO { id: number @@ -71,7 +72,7 @@ export class ProjectListDTO { prev: string | null items: ProjectDTO[] - constructor(item: ProjectItemList) { + constructor(item: Page) { this.count = item.count this.next = item.next this.prev = item.prev