Browse Source

Add page class and remove ProjectItemList class

pull/2093/head
Hironsan 2 years ago
parent
commit
ae6f8aa6e5
5 changed files with 18 additions and 16 deletions
  1. 8
      frontend/domain/models/page.ts
  2. 9
      frontend/domain/models/project/project.ts
  3. 5
      frontend/domain/models/project/projectRepository.ts
  4. 7
      frontend/repositories/project/apiProjectRepository.ts
  5. 5
      frontend/services/application/project/projectData.ts

8
frontend/domain/models/page.ts

@ -0,0 +1,8 @@
export class Page<T> {
constructor(
readonly count: number,
readonly next: string | null,
readonly prev: string | null,
readonly items: T[]
) {}
}

9
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,

5
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<ProjectItemList>
list(query: SearchQuery): Promise<Page<ProjectReadItem>>
findById(id: string): Promise<ProjectReadItem>

7
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<ProjectItemList> {
async list(query: SearchQuery): Promise<Page<ProjectReadItem>> {
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,

5
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<ProjectReadItem>) {
this.count = item.count
this.next = item.next
this.prev = item.prev

Loading…
Cancel
Save