From f7a12a949a3aa76c72693bb0eb154703901cfef2 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Sat, 10 Dec 2022 11:36:32 +0900 Subject: [PATCH] Simplify FormUpdate component --- frontend/components/project/FormUpdate.vue | 240 ++++-------------- frontend/components/project/TagList.vue | 3 +- frontend/domain/models/tag/tagRepository.ts | 6 +- frontend/pages/projects/create.vue | 2 +- frontend/repositories/tag/apiTagRepository.ts | 10 +- .../project/projectApplicationService.ts | 2 +- .../application/tag/tagApplicationService.ts | 9 + 7 files changed, 75 insertions(+), 197 deletions(-) diff --git a/frontend/components/project/FormUpdate.vue b/frontend/components/project/FormUpdate.vue index c144c77c..4a2475ad 100644 --- a/frontend/components/project/FormUpdate.vue +++ b/frontend/components/project/FormUpdate.vue @@ -1,222 +1,92 @@ - diff --git a/frontend/components/project/TagList.vue b/frontend/components/project/TagList.vue index 009460dc..6d8c098f 100644 --- a/frontend/components/project/TagList.vue +++ b/frontend/components/project/TagList.vue @@ -6,10 +6,9 @@ label="Tags" multiple chips - outlined - dense deletable-chips hide-selected + hide-details @change="$emit('input', $event)" /> diff --git a/frontend/domain/models/tag/tagRepository.ts b/frontend/domain/models/tag/tagRepository.ts index 24ad63ea..2c887084 100644 --- a/frontend/domain/models/tag/tagRepository.ts +++ b/frontend/domain/models/tag/tagRepository.ts @@ -1,9 +1,9 @@ import { TagItem } from '~/domain/models/tag/tag' export interface TagRepository { - list(projectId: string): Promise + list(projectId: string | number): Promise - create(projectId: string, item: string): Promise + create(projectId: string | number, item: string): Promise - delete(projectId: string, tagId: number): Promise + delete(projectId: string | number, tagId: number): Promise } diff --git a/frontend/pages/projects/create.vue b/frontend/pages/projects/create.vue index 90b42771..c05aa8cb 100644 --- a/frontend/pages/projects/create.vue +++ b/frontend/pages/projects/create.vue @@ -6,7 +6,7 @@ - + { + async list(projectId: string | number): Promise { const url = `/projects/${projectId}/tags` const response = await this.request.get(url) return response.data.map((item: { [key: string]: any }) => toModel(item)) } - async create(projectId: string, text: string): Promise { + async create(projectId: string | number, text: string): Promise { const url = `/projects/${projectId}/tags` const response = await this.request.post(url, { text }) return toModel(response.data) } - async delete(projectId: string, tagId: number): Promise { + async delete(projectId: string | number, tagId: number): Promise { const url = `/projects/${projectId}/tags/${tagId}` await this.request.delete(url) } diff --git a/frontend/services/application/project/projectApplicationService.ts b/frontend/services/application/project/projectApplicationService.ts index 4659d5da..97b13dcc 100644 --- a/frontend/services/application/project/projectApplicationService.ts +++ b/frontend/services/application/project/projectApplicationService.ts @@ -87,7 +87,7 @@ export class ProjectApplicationService { enableGraphemeMode, useRelation, guideline = '' - }: Options + }: Omit ): Promise { const project = Project.create( projectId, diff --git a/frontend/services/application/tag/tagApplicationService.ts b/frontend/services/application/tag/tagApplicationService.ts index 19ce6939..69a01bd5 100644 --- a/frontend/services/application/tag/tagApplicationService.ts +++ b/frontend/services/application/tag/tagApplicationService.ts @@ -16,4 +16,13 @@ export class TagApplicationService { public async delete(projectId: string, id: number): Promise { return await this.repository.delete(projectId, id) } + + public async bulkUpdate(projectId: string | number, tags: string[]): Promise { + const currentTags = await this.repository.list(projectId) + const currentTagNames = currentTags.map((tag) => tag.text) + const addedTagNames = tags.filter((tag) => !currentTagNames.includes(tag)) + const deletedTagIds = currentTags.filter((tag) => !tags.includes(tag.text)).map((tag) => tag.id) + await Promise.all(addedTagNames.map((tag) => this.repository.create(projectId, tag))) + await Promise.all(deletedTagIds.map((id) => this.repository.delete(projectId, id))) + } }