Browse Source

Remove unused code

pull/1926/head
Hironsan 2 years ago
parent
commit
433697c4a3
8 changed files with 40 additions and 88 deletions
  1. 12
      frontend/domain/models/label/label.ts
  2. 10
      frontend/domain/models/member/member.ts
  3. 36
      frontend/domain/models/option/option.ts
  4. 8
      frontend/domain/models/tag/tag.ts
  5. 13
      frontend/repositories/label/apiLabelRepository.ts
  6. 3
      frontend/repositories/member/apiMemberRepository.ts
  7. 23
      frontend/repositories/option/apiOptionRepository.ts
  8. 23
      frontend/services/application/label/labelApplicationService.ts

12
frontend/domain/models/label/label.ts

@ -7,7 +7,13 @@ export class LabelItem {
readonly backgroundColor: string,
readonly textColor: string = '#ffffff'
) {}
}
export class DocTypeItem extends LabelItem {}
export class SpanTypeItem extends LabelItem {}
static create(
text: string,
prefixKey: string | null,
suffixKey: string | null,
backgroundColor: string
): LabelItem {
return new LabelItem(0, text, prefixKey, suffixKey, backgroundColor)
}
}

10
frontend/domain/models/member/member.ts

@ -12,14 +12,4 @@ export class MemberItem {
get isProjectAdmin(): boolean {
return this.rolename === 'project_admin'
}
toObject(): Object {
return {
id: this.id,
user: this.user,
role: this.role,
username: this.username,
rolename: this.rolename
}
}
}

36
frontend/domain/models/option/option.ts

@ -1,37 +1,3 @@
export class PageNumber {
num: number
constructor(public page: number) {
if (typeof page === 'string' && /^\d+$/.test(page)) {
this.num = parseInt(page, 10)
}
if (typeof page === 'number' && page > 0) {
this.num = page
}
this.num = 1
}
}
export class OptionItem {
constructor(public page: number, public q?: string, public isChecked?: string) {}
static valueOf({
page,
q = '',
isChecked = ''
}: {
page: number
q?: string
isChecked?: string
}): OptionItem {
return new OptionItem(page, q, isChecked)
}
toObject(): Object {
return {
page: this.page,
q: this.q,
isChecked: this.isChecked
}
}
constructor(public page: number, public q = '', public isChecked = '') {}
}

8
frontend/domain/models/tag/tag.ts

@ -1,11 +1,3 @@
export class TagItem {
constructor(readonly id: number, readonly text: string, readonly project: string) {}
toObject(): Object {
return {
id: this.id,
text: this.text,
project: this.project
}
}
}

13
frontend/repositories/label/apiLabelRepository.ts

@ -2,16 +2,7 @@ import ApiService from '@/services/api.service'
import { LabelRepository } from '@/domain/models/label/labelRepository'
import { LabelItem } from '@/domain/models/label/label'
export interface LabelItemResponse {
id: number
text: string
prefix_key: string
suffix_key: string
background_color: string
text_color: string
}
function toModel(item: LabelItemResponse): LabelItem {
function toModel(item: { [key: string]: any }): LabelItem {
return new LabelItem(
item.id,
item.text,
@ -39,7 +30,7 @@ export class APILabelRepository implements LabelRepository {
async list(projectId: string): Promise<LabelItem[]> {
const url = `/projects/${projectId}/${this.baseUrl}s`
const response = await this.request.get(url)
return response.data.map((item: LabelItemResponse) => toModel(item))
return response.data.map((item: { [key: string]: any }) => toModel(item))
}
async findById(projectId: string, labelId: number): Promise<LabelItem> {

3
frontend/repositories/member/apiMemberRepository.ts

@ -27,7 +27,8 @@ export class APIMemberRepository implements MemberRepository {
async create(projectId: string, item: MemberItem): Promise<MemberItem> {
const url = `/projects/${projectId}/members`
const response = await this.request.post(url, item.toObject())
const payload = toPayload(item)
const response = await this.request.post(url, payload)
return toModel(response.data)
}

23
frontend/repositories/option/apiOptionRepository.ts

@ -1,19 +1,32 @@
import { OptionRepository } from '../../domain/models/option/optionRepository'
import { OptionItem } from '~/domain/models/option/option'
import { OptionRepository } from '@/domain/models/option/optionRepository'
import { OptionItem } from '@/domain/models/option/option'
function toPayload(item: OptionItem): { [key: string]: any } {
return {
page: item.page,
q: item.q,
isChecked: item.isChecked
}
}
export class LocalStorageOptionRepository implements OptionRepository {
findById(projectId: string): OptionItem {
const checkpoint = this.loadCheckpoint()
return OptionItem.valueOf(checkpoint[projectId] ? checkpoint[projectId] : { page: 1 })
if (checkpoint[projectId]) {
const option = checkpoint[projectId]
return new OptionItem(option.page, option.q, option.isChecked)
} else {
return new OptionItem(1)
}
}
save(projectId: string, option: OptionItem): void {
const checkpoint = this.loadCheckpoint()
checkpoint[projectId] = option.toObject()
checkpoint[projectId] = toPayload(option)
localStorage.setItem('checkpoint', JSON.stringify(checkpoint))
}
loadCheckpoint() {
loadCheckpoint(): { [key: string]: any } {
const item = localStorage.getItem('checkpoint') || '{}'
return JSON.parse(item)
}

23
frontend/services/application/label/labelApplicationService.ts

@ -17,26 +17,19 @@ export class LabelApplicationService {
}
public async create(projectId: string, item: CreateLabelCommand): Promise<LabelDTO> {
// Todo: use auto mapping.
const label = new LabelItem()
label.text = item.text
label.prefixKey = item.prefixKey
label.suffixKey = item.suffixKey
label.backgroundColor = item.backgroundColor
label.textColor = item.textColor
const label = LabelItem.create(item.text, item.prefixKey, item.suffixKey, item.backgroundColor)
const created = await this.repository.create(projectId, label)
return new LabelDTO(created)
}
public async update(projectId: string, item: LabelDTO): Promise<LabelDTO> {
// Todo: use auto mapping.
const label = new LabelItem()
label.id = item.id
label.text = item.text
label.prefixKey = item.prefixKey
label.suffixKey = item.suffixKey
label.backgroundColor = item.backgroundColor
label.textColor = item.textColor
const label = new LabelItem(
item.id,
item.text,
item.prefixKey,
item.suffixKey,
item.backgroundColor
)
const updated = await this.repository.update(projectId, label)
return new LabelDTO(updated)
}

Loading…
Cancel
Save