diff --git a/frontend/components/member/FormCreate.vue b/frontend/components/member/FormCreate.vue index 218173e5..4e4b0986 100644 --- a/frontend/components/member/FormCreate.vue +++ b/frontend/components/member/FormCreate.vue @@ -56,9 +56,9 @@ import { mdiAccount, mdiCreditCardOutline } from '@mdi/js' import type { PropType } from 'vue' import Vue from 'vue' import BaseCard from '@/components/utils/BaseCard.vue' +import { MemberItem } from '~/domain/models/member/member' import { RoleItem } from '~/domain/models/role/role' import { UserItem } from '~/domain/models/user/user' -import { MemberDTO } from '~/services/application/member/memberData' export default Vue.extend({ components: { @@ -67,7 +67,7 @@ export default Vue.extend({ props: { value: { - type: Object as PropType, + type: Object as PropType, required: true }, errorMessage: { @@ -108,7 +108,7 @@ export default Vue.extend({ isSuperuser: false } }, - set(val: MemberDTO) { + set(val: MemberItem) { if (val === undefined) return const user = { user: val.id, username: val.username } this.$emit('input', { ...this.value, ...user }) diff --git a/frontend/domain/models/member/memberRepository.ts b/frontend/domain/models/member/memberRepository.ts deleted file mode 100644 index 30813116..00000000 --- a/frontend/domain/models/member/memberRepository.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { MemberItem } from '~/domain/models/member/member' - -export interface MemberRepository { - list(projectId: string): Promise - - create(projectId: string, item: MemberItem): Promise - - update(projectId: string, item: MemberItem): Promise - - bulkDelete(projectId: string, memberIds: number[]): Promise - - fetchMyRole(projectId: string): Promise -} diff --git a/frontend/layouts/project.vue b/frontend/layouts/project.vue index 79709d19..84e95fd1 100644 --- a/frontend/layouts/project.vue +++ b/frontend/layouts/project.vue @@ -46,7 +46,8 @@ export default { }, async created() { - this.isProjectAdmin = await this.$services.member.isProjectAdmin(this.$route.params.id) + const member = await this.$repositories.member.fetchMyRole(this.$route.params.id) + this.isProjectAdmin = member.isProjectAdmin } } diff --git a/frontend/layouts/workspace.vue b/frontend/layouts/workspace.vue index 5c96c34d..dae6c610 100644 --- a/frontend/layouts/workspace.vue +++ b/frontend/layouts/workspace.vue @@ -46,7 +46,8 @@ export default { }, async created() { - this.isProjectAdmin = await this.$services.member.isProjectAdmin(this.$route.params.id) + const member = await this.$repositories.member.fetchMyRole(this.$route.params.id) + this.isProjectAdmin = member.isProjectAdmin } } diff --git a/frontend/middleware/check-admin.js b/frontend/middleware/check-admin.js index 29b647e5..b8d521bb 100644 --- a/frontend/middleware/check-admin.js +++ b/frontend/middleware/check-admin.js @@ -6,11 +6,11 @@ export default _.debounce(async function ({ app, store, route, redirect }) { } catch (e) { redirect('/projects') } - const isProjectAdmin = await app.$services.member.isProjectAdmin(route.params.id) + const member = await app.$repositories.member.fetchMyRole(route.params.id) const projectRoot = app.localePath('/projects/' + route.params.id) const path = route.fullPath.replace(/\/$/g, '') - if (isProjectAdmin || path === projectRoot || path.startsWith(projectRoot + '/dataset')) { + if (member.isProjectAdmin || path === projectRoot || path.startsWith(projectRoot + '/dataset')) { return } diff --git a/frontend/pages/projects/_id/dataset/index.vue b/frontend/pages/projects/_id/dataset/index.vue index 476050ff..e04a76a3 100644 --- a/frontend/pages/projects/_id/dataset/index.vue +++ b/frontend/pages/projects/_id/dataset/index.vue @@ -144,7 +144,8 @@ export default Vue.extend({ async created() { this.project = await this.$services.project.findById(this.projectId) - this.isProjectAdmin = await this.$services.member.isProjectAdmin(this.projectId) + const member = await this.$repositories.member.fetchMyRole(this.projectId) + this.isProjectAdmin = member.isProjectAdmin }, methods: { diff --git a/frontend/pages/projects/_id/members/index.vue b/frontend/pages/projects/_id/members/index.vue index f34b1da4..97b59723 100644 --- a/frontend/pages/projects/_id/members/index.vue +++ b/frontend/pages/projects/_id/members/index.vue @@ -33,7 +33,7 @@ import Vue from 'vue' import FormDelete from '@/components/member/FormDelete.vue' import MemberList from '@/components/member/MemberList.vue' import FormCreate from '~/components/member/FormCreate.vue' -import { MemberDTO } from '~/services/application/member/memberData' +import { MemberItem } from '~/domain/models/member/member' export default Vue.extend({ components: { @@ -57,15 +57,15 @@ export default Vue.extend({ role: -1, username: '', rolename: 'annotator' - } as MemberDTO, + } as MemberItem, defaultItem: { user: -1, role: -1, username: '', rolename: 'annotator' - } as MemberDTO, - items: [] as MemberDTO[], - selected: [] as MemberDTO[], + } as MemberItem, + items: [] as MemberItem[], + selected: [] as MemberItem[], isLoading: false, errorMessage: '' } @@ -74,7 +74,7 @@ export default Vue.extend({ async fetch() { this.isLoading = true try { - this.items = await this.$services.member.list(this.projectId) + this.items = await this.$repositories.member.list(this.projectId) } catch (e) { this.$router.push(`/projects/${this.projectId}`) } finally { @@ -94,21 +94,21 @@ export default Vue.extend({ methods: { async create() { try { - await this.$services.member.create(this.projectId, this.editedItem) + await this.$repositories.member.create(this.projectId, this.editedItem) this.close() this.$fetch() } catch (e: any) { - this.errorMessage = e.message + this.errorMessage = e.response.data.detail } }, async update() { try { - await this.$services.member.update(this.projectId, this.editedItem) + await this.$repositories.member.update(this.projectId, this.editedItem) this.close() this.$fetch() } catch (e: any) { - this.errorMessage = e.message + this.errorMessage = e.response.data.detail } }, @@ -130,13 +130,13 @@ export default Vue.extend({ }, async remove() { - await this.$services.member.bulkDelete(this.projectId, this.selected) + await this.$repositories.member.bulkDelete(this.projectId, this.selected) this.$fetch() this.dialogDelete = false this.selected = [] }, - editItem(item: MemberDTO) { + editItem(item: MemberItem) { this.editedIndex = this.items.indexOf(item) this.editedItem = Object.assign({}, item) this.dialogCreate = true diff --git a/frontend/plugins/services.ts b/frontend/plugins/services.ts index 9dd67a99..76b51fda 100644 --- a/frontend/plugins/services.ts +++ b/frontend/plugins/services.ts @@ -3,7 +3,6 @@ import { repositories } from './repositories' import { ConfigApplicationService } from '@/services/application/autoLabeling/configApplicationService' import { ExampleApplicationService } from '@/services/application/example/exampleApplicationService' import { LabelApplicationService } from '@/services/application/label/labelApplicationService' -import { MemberApplicationService } from '@/services/application/member/memberApplicationService' import { OptionApplicationService } from '@/services/application/option/optionApplicationService' import { ProjectApplicationService } from '@/services/application/project/projectApplicationService' import { TagApplicationService } from '@/services/application/tag/tagApplicationService' @@ -17,7 +16,6 @@ export interface Services { categoryType: LabelApplicationService spanType: LabelApplicationService relationType: LabelApplicationService - member: MemberApplicationService project: ProjectApplicationService example: ExampleApplicationService textClassification: TextClassificationService @@ -41,7 +39,6 @@ const plugin: Plugin = (_, inject) => { categoryType: new LabelApplicationService(repositories.categoryType), spanType: new LabelApplicationService(repositories.spanType), relationType: new LabelApplicationService(repositories.relationType), - member: new MemberApplicationService(repositories.member), project: new ProjectApplicationService(repositories.project), example: new ExampleApplicationService(repositories.example), textClassification: new TextClassificationService(repositories.category), diff --git a/frontend/repositories/member/apiMemberRepository.ts b/frontend/repositories/member/apiMemberRepository.ts index 7972511c..76c2f93a 100644 --- a/frontend/repositories/member/apiMemberRepository.ts +++ b/frontend/repositories/member/apiMemberRepository.ts @@ -1,6 +1,5 @@ -import ApiService from '@/services/api.service' -import { MemberRepository } from '@/domain/models/member/memberRepository' import { MemberItem } from '@/domain/models/member/member' +import ApiService from '@/services/api.service' function toModel(item: { [key: string]: any }): MemberItem { return new MemberItem(item.id, item.user, item.role, item.username, item.rolename) @@ -16,7 +15,7 @@ function toPayload(item: MemberItem): { [key: string]: any } { } } -export class APIMemberRepository implements MemberRepository { +export class APIMemberRepository { constructor(private readonly request = ApiService) {} async list(projectId: string): Promise { @@ -39,9 +38,10 @@ export class APIMemberRepository implements MemberRepository { return toModel(response.data) } - async bulkDelete(projectId: string, memberIds: number[]): Promise { + async bulkDelete(projectId: string, members: MemberItem[]): Promise { const url = `/projects/${projectId}/members` - await this.request.delete(url, { ids: memberIds }) + const ids = members.map((member) => member.id) + await this.request.delete(url, { ids }) } async fetchMyRole(projectId: string): Promise { diff --git a/frontend/services/application/member/memberApplicationService.ts b/frontend/services/application/member/memberApplicationService.ts deleted file mode 100644 index 3ff225d9..00000000 --- a/frontend/services/application/member/memberApplicationService.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { plainToInstance } from 'class-transformer' -import { MemberDTO } from './memberData' -import { MemberRepository } from '~/domain/models/member/memberRepository' -import { MemberItem } from '~/domain/models/member/member' - -export class MemberApplicationService { - constructor(private readonly repository: MemberRepository) {} - - public async list(id: string): Promise { - try { - const items = await this.repository.list(id) - return items.map((item) => new MemberDTO(item)) - } catch (e: any) { - throw new Error(e.response.data.detail) - } - } - - public async create(projectId: string, item: MemberDTO): Promise { - try { - const member = plainToInstance(MemberItem, item) - await this.repository.create(projectId, member) - } catch (e: any) { - throw new Error(e.response.data.detail) - } - } - - public async update(projectId: string, item: MemberDTO): Promise { - try { - const member = plainToInstance(MemberItem, item) - await this.repository.update(projectId, member) - } catch (e: any) { - throw new Error(e.response.data.detail) - } - } - - public bulkDelete(projectId: string, items: MemberDTO[]): Promise { - const ids = items.map((item) => item.id) - return this.repository.bulkDelete(projectId, ids) - } - - public async isProjectAdmin(projectId: string): Promise { - const item = await this.repository.fetchMyRole(projectId) - return item.isProjectAdmin - } -} diff --git a/frontend/services/application/member/memberData.ts b/frontend/services/application/member/memberData.ts deleted file mode 100644 index 70dbb826..00000000 --- a/frontend/services/application/member/memberData.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { MemberItem } from '~/domain/models/member/member' -import { RoleName } from '~/domain/models/role/role' -export class MemberDTO { - id: number - user: number - role: number - username: string - rolename: RoleName - - constructor(item: MemberItem) { - this.id = item.id - this.user = item.user - this.role = item.role - this.username = item.username - this.rolename = item.rolename - } -}