Browse Source

Remove interface for project repository

pull/2093/head
Hironsan 2 years ago
parent
commit
8755aaf5b3
3 changed files with 24 additions and 39 deletions
  1. 35
      frontend/domain/models/project/projectRepository.ts
  2. 24
      frontend/repositories/project/apiProjectRepository.ts
  3. 4
      frontend/services/application/project/projectApplicationService.ts

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

@ -1,35 +0,0 @@
import { Page } from '~/domain/models/page'
import { Project } from '~/domain/models/project/project'
const sortableFieldList = ['name', 'projectType', 'createdAt', 'author'] as const
type SortableFields = typeof sortableFieldList[number]
export class SearchQuery {
readonly limit: number = 10
readonly offset: number = 0
readonly q: string = ''
readonly sortBy: SortableFields = 'createdAt'
readonly sortDesc: boolean = false
constructor(_limit: string, _offset: string, _q?: string, _sortBy?: string, _sortDesc?: string) {
this.limit = /^\d+$/.test(_limit) ? parseInt(_limit) : 10
this.offset = /^\d+$/.test(_offset) ? parseInt(_offset) : 0
this.q = _q || ''
this.sortBy = (
_sortBy && sortableFieldList.includes(_sortBy as SortableFields) ? _sortBy : 'createdAt'
) as SortableFields
this.sortDesc = _sortDesc === 'true'
}
}
export interface ProjectRepository {
list(query: SearchQuery): Promise<Page<Project>>
findById(id: string): Promise<Project>
create(item: Project): Promise<Project>
update(item: Project): Promise<void>
bulkDelete(projectIds: number[]): Promise<void>
}

24
frontend/repositories/project/apiProjectRepository.ts

@ -1,8 +1,28 @@
import { Page } from '@/domain/models/page'
import { Project } from '@/domain/models/project/project'
import { ProjectRepository, SearchQuery } from '@/domain/models/project/projectRepository'
import ApiService from '@/services/api.service'
const sortableFieldList = ['name', 'projectType', 'createdAt', 'author'] as const
type SortableFields = typeof sortableFieldList[number]
export class SearchQuery {
readonly limit: number = 10
readonly offset: number = 0
readonly q: string = ''
readonly sortBy: SortableFields = 'createdAt'
readonly sortDesc: boolean = false
constructor(_limit: string, _offset: string, _q?: string, _sortBy?: string, _sortDesc?: string) {
this.limit = /^\d+$/.test(_limit) ? parseInt(_limit) : 10
this.offset = /^\d+$/.test(_offset) ? parseInt(_offset) : 0
this.q = _q || ''
this.sortBy = (
_sortBy && sortableFieldList.includes(_sortBy as SortableFields) ? _sortBy : 'createdAt'
) as SortableFields
this.sortDesc = _sortDesc === 'true'
}
}
function toModel(item: { [key: string]: any }): Project {
return new Project(
item.id,
@ -43,7 +63,7 @@ function toPayload(item: Project): { [key: string]: any } {
}
}
export class APIProjectRepository implements ProjectRepository {
export class APIProjectRepository {
constructor(private readonly request = ApiService) {}
async list(query: SearchQuery): Promise<Page<Project>> {

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

@ -1,6 +1,6 @@
import { Page } from '~/domain/models/page'
import { Project } from '~/domain/models/project/project'
import { ProjectRepository, SearchQuery } from '~/domain/models/project/projectRepository'
import { APIProjectRepository, SearchQuery } from '~/repositories/project/apiProjectRepository'
type Options = {
name: string
@ -25,7 +25,7 @@ export interface SearchQueryData {
}
export class ProjectApplicationService {
constructor(private readonly repository: ProjectRepository) {}
constructor(private readonly repository: APIProjectRepository) {}
public async list(q: SearchQueryData): Promise<Page<Project>> {
try {

Loading…
Cancel
Save