Browse Source

Remove user application service

pull/2136/head
Hironsan 1 year ago
parent
commit
e4c7cf27d7
10 changed files with 32 additions and 69 deletions
  1. 13
      frontend/components/member/FormCreate.vue
  2. 7
      frontend/components/tasks/toolbar/forms/FormComment.vue
  3. 7
      frontend/domain/models/user/userRepository.ts
  4. 1
      frontend/nuxt.config.js
  5. 32
      frontend/plugins/repositories.ts
  6. 3
      frontend/plugins/services.ts
  7. 7
      frontend/repositories/user/apiUserRepository.ts
  8. 16
      frontend/services/application/user/userApplicationService.ts
  9. 13
      frontend/services/application/user/userData.ts
  10. 2
      frontend/store/auth.js

13
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 { UserItem } from '~/domain/models/user/user'
import { MemberDTO } from '~/services/application/member/memberData'
import { RoleDTO } from '~/services/application/role/roleData'
import { UserDTO } from '~/services/application/user/userData'
export default Vue.extend({
components: {
@ -80,11 +80,11 @@ export default Vue.extend({
return {
isLoading: false,
valid: false,
users: [] as UserDTO[],
users: [] as UserItem[],
roles: [] as RoleDTO[],
username: '',
rules: {
userRequired: (v: UserDTO) => (!!v && !!v.username) || 'Required',
userRequired: (v: UserItem) => (!!v && !!v.username) || 'Required',
roleRequired: (v: RoleDTO) => (!!v && !!v.rolename) || 'Required'
},
mdiAccount,
@ -94,17 +94,18 @@ export default Vue.extend({
async fetch() {
this.isLoading = true
this.users = await this.$services.user.list(this.username)
this.users = await this.$repositories.user.list(this.username)
this.isLoading = false
},
computed: {
user: {
get(): UserDTO {
get(): UserItem {
return {
id: this.value.user,
username: this.value.username,
isStaff: false
isStaff: false,
isSuperuser: false
}
},
set(val: MemberDTO) {

7
frontend/components/tasks/toolbar/forms/FormComment.vue

@ -20,9 +20,10 @@
<script lang="ts">
import Vue from 'vue'
import BaseCard from '@/components/utils/BaseCard.vue'
import Comment from '@/components/comment/Comment.vue'
import FormCreate from '@/components/comment/FormCreate.vue'
import BaseCard from '@/components/utils/BaseCard.vue'
import { UserItem } from '~/domain/models/user/user'
import { CommentReadDTO } from '~/services/application/comment/commentData'
export default Vue.extend({
@ -41,7 +42,7 @@ export default Vue.extend({
data() {
return {
user: {},
user: {} as UserItem,
comments: [] as CommentReadDTO[]
}
},
@ -59,7 +60,7 @@ export default Vue.extend({
},
async created() {
this.user = await this.$services.user.getMyProfile()
this.user = await this.$repositories.user.getProfile()
},
methods: {

7
frontend/domain/models/user/userRepository.ts

@ -1,7 +0,0 @@
import { UserItem } from '~/domain/models/user/user'
export interface UserRepository {
getMe(): Promise<UserItem>
list(query: string): Promise<UserItem[]>
}

1
frontend/nuxt.config.js

@ -46,6 +46,7 @@ export default {
'~/plugins/vue-shortkey.js',
'~/plugins/vue-konva.js',
'~/plugins/services.ts',
'~/plugins/repositories.ts',
'~/plugins/color.ts',
'~/plugins/role.ts'
],

32
frontend/plugins/repositories.ts

@ -1,27 +1,27 @@
import { Plugin } from '@nuxt/types'
import { APITaskStatusRepository } from '@/repositories/celery/apiTaskStatusRepository'
import { APICatalogRepository } from '@/repositories/upload/apiCatalogRepository'
import { APIParseRepository } from '@/repositories/upload/apiParseRepository'
import { APISpanRepository } from '@/repositories/tasks/apiSpanRepository'
import { APITextLabelRepository } from '@/repositories/tasks/apiTextLabelRepository'
import { APIAuthRepository } from '@/repositories/auth/apiAuthRepository'
import { APIConfigRepository } from '@/repositories/autoLabeling/config/apiConfigRepository'
import { APITemplateRepository } from '@/repositories/autoLabeling/template/apiTemplateRepository'
import { APIUserRepository } from '@/repositories/user/apiUserRepository'
import { APIMetricsRepository } from '@/repositories/metrics/apiMetricsRepository'
import { APIRoleRepository } from '@/repositories/role/apiRoleRepository'
import { APIProjectRepository } from '@/repositories/project/apiProjectRepository'
import { LocalStorageOptionRepository } from '@/repositories/option/apiOptionRepository'
import { APIMemberRepository } from '@/repositories/member/apiMemberRepository'
import { APILabelRepository } from '@/repositories/label/apiLabelRepository'
import { APIExampleRepository } from '@/repositories/example/apiDocumentRepository'
import { APITaskStatusRepository } from '@/repositories/celery/apiTaskStatusRepository'
import { APICommentRepository } from '@/repositories/comment/apiCommentRepository'
import { APIAuthRepository } from '@/repositories/auth/apiAuthRepository'
import { APICategoryRepository } from '@/repositories/tasks/apiCategoryRepository'
import { APIDownloadFormatRepository } from '@/repositories/download/apiDownloadFormatRepository'
import { APIDownloadRepository } from '@/repositories/download/apiDownloadRepository'
import { APIExampleRepository } from '@/repositories/example/apiDocumentRepository'
import { APILabelRepository } from '@/repositories/label/apiLabelRepository'
import { APIMemberRepository } from '@/repositories/member/apiMemberRepository'
import { APIMetricsRepository } from '@/repositories/metrics/apiMetricsRepository'
import { LocalStorageOptionRepository } from '@/repositories/option/apiOptionRepository'
import { APIProjectRepository } from '@/repositories/project/apiProjectRepository'
import { APIRoleRepository } from '@/repositories/role/apiRoleRepository'
import { APITagRepository } from '@/repositories/tag/apiTagRepository'
import { APIRelationRepository } from '@/repositories/tasks/apiRelationRepository'
import { APIBoundingBoxRepository } from '@/repositories/tasks/apiBoundingBoxRepository'
import { APICategoryRepository } from '@/repositories/tasks/apiCategoryRepository'
import { APIRelationRepository } from '@/repositories/tasks/apiRelationRepository'
import { APISpanRepository } from '@/repositories/tasks/apiSpanRepository'
import { APITextLabelRepository } from '@/repositories/tasks/apiTextLabelRepository'
import { APICatalogRepository } from '@/repositories/upload/apiCatalogRepository'
import { APIParseRepository } from '@/repositories/upload/apiParseRepository'
import { APIUserRepository } from '@/repositories/user/apiUserRepository'
import { APISegmentationRepository } from '~/repositories/tasks/apiSegmentationRepository'
export interface Repositories {

3
frontend/plugins/services.ts

@ -22,14 +22,12 @@ import { SequenceLabelingApplicationService } from '@/services/application/tasks
import { TextClassificationService } from '@/services/application/tasks/textClassification/textClassificationApplicationService'
import { CatalogApplicationService } from '@/services/application/upload/catalogApplicationService'
import { ParseApplicationService } from '@/services/application/upload/parseApplicationService'
import { UserApplicationService } from '@/services/application/user/userApplicationService'
export interface Services {
categoryType: LabelApplicationService
spanType: LabelApplicationService
relationType: LabelApplicationService
member: MemberApplicationService
user: UserApplicationService
role: RoleApplicationService
project: ProjectApplicationService
comment: CommentApplicationService
@ -64,7 +62,6 @@ const plugin: Plugin = (_, inject) => {
spanType: new LabelApplicationService(repositories.spanType),
relationType: new LabelApplicationService(repositories.relationType),
member: new MemberApplicationService(repositories.member),
user: new UserApplicationService(repositories.user),
role: new RoleApplicationService(repositories.role),
project: new ProjectApplicationService(repositories.project),
comment: new CommentApplicationService(repositories.comment),

7
frontend/repositories/user/apiUserRepository.ts

@ -1,15 +1,14 @@
import ApiService from '@/services/api.service'
import { UserRepository } from '@/domain/models/user/userRepository'
import { UserItem } from '@/domain/models/user/user'
import ApiService from '@/services/api.service'
function toModel(item: { [key: string]: any }): UserItem {
return new UserItem(item.id, item.username, item.is_superuser, item.is_staff)
}
export class APIUserRepository implements UserRepository {
export class APIUserRepository {
constructor(private readonly request = ApiService) {}
async getMe(): Promise<UserItem> {
async getProfile(): Promise<UserItem> {
const url = '/me'
const response = await this.request.get(url)
return toModel(response.data)

16
frontend/services/application/user/userApplicationService.ts

@ -1,16 +0,0 @@
import { UserDTO } from './userData'
import { UserRepository } from '~/domain/models/user/userRepository'
export class UserApplicationService {
constructor(private readonly repository: UserRepository) {}
public async getMyProfile(): Promise<UserDTO> {
const item = await this.repository.getMe()
return new UserDTO(item)
}
public async list(query: string): Promise<UserDTO[]> {
const items = await this.repository.list(query)
return items.map((item) => new UserDTO(item))
}
}

13
frontend/services/application/user/userData.ts

@ -1,13 +0,0 @@
import { UserItem } from '~/domain/models/user/user'
export class UserDTO {
id: number
username: string
isStaff: boolean
constructor(item: UserItem) {
this.id = item.id
this.username = item.username
this.isStaff = item.isStaff
}
}

2
frontend/store/auth.js

@ -52,7 +52,7 @@ export const actions = {
},
async initAuth({ commit }) {
try {
const user = await this.$services.user.getMyProfile()
const user = await this.$repositories.user.getProfile()
commit('setAuthenticated', true)
commit('setUsername', user.username)
commit('setUserId', user.id)

Loading…
Cancel
Save