Browse Source

Remove member application service

pull/2147/head
Hironsan 1 year ago
parent
commit
7d92be16a0
11 changed files with 28 additions and 103 deletions
  1. 6
      frontend/components/member/FormCreate.vue
  2. 13
      frontend/domain/models/member/memberRepository.ts
  3. 3
      frontend/layouts/project.vue
  4. 3
      frontend/layouts/workspace.vue
  5. 4
      frontend/middleware/check-admin.js
  6. 3
      frontend/pages/projects/_id/dataset/index.vue
  7. 24
      frontend/pages/projects/_id/members/index.vue
  8. 3
      frontend/plugins/services.ts
  9. 10
      frontend/repositories/member/apiMemberRepository.ts
  10. 45
      frontend/services/application/member/memberApplicationService.ts
  11. 17
      frontend/services/application/member/memberData.ts

6
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<MemberDTO>,
type: Object as PropType<MemberItem>,
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 })

13
frontend/domain/models/member/memberRepository.ts

@ -1,13 +0,0 @@
import { MemberItem } from '~/domain/models/member/member'
export interface MemberRepository {
list(projectId: string): Promise<MemberItem[]>
create(projectId: string, item: MemberItem): Promise<MemberItem>
update(projectId: string, item: MemberItem): Promise<MemberItem>
bulkDelete(projectId: string, memberIds: number[]): Promise<void>
fetchMyRole(projectId: string): Promise<MemberItem>
}

3
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
}
}
</script>

3
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
}
}
</script>

4
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
}

3
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: {

24
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

3
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),

10
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<MemberItem[]> {
@ -39,9 +38,10 @@ export class APIMemberRepository implements MemberRepository {
return toModel(response.data)
}
async bulkDelete(projectId: string, memberIds: number[]): Promise<void> {
async bulkDelete(projectId: string, members: MemberItem[]): Promise<void> {
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<MemberItem> {

45
frontend/services/application/member/memberApplicationService.ts

@ -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<MemberDTO[]> {
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<void> {
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<void> {
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<void> {
const ids = items.map((item) => item.id)
return this.repository.bulkDelete(projectId, ids)
}
public async isProjectAdmin(projectId: string): Promise<boolean> {
const item = await this.repository.fetchMyRole(projectId)
return item.isProjectAdmin
}
}

17
frontend/services/application/member/memberData.ts

@ -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
}
}
Loading…
Cancel
Save