Browse Source

Add user repository

pull/1224/head
Hironsan 3 years ago
parent
commit
c5ade8f8d9
2 changed files with 27 additions and 0 deletions
  1. 16
      frontend/repositories/user/api.ts
  2. 11
      frontend/repositories/user/interface.ts

16
frontend/repositories/user/api.ts

@ -0,0 +1,16 @@
import ApiService from '@/services/api.service'
import { UserItem } from '@/models/user'
import { UserItemListRepository, UserItemResponse } from './interface'
export class FromApiUserItemListRepository implements UserItemListRepository {
constructor(
private readonly request = ApiService
) {}
async list(query: string): Promise<UserItem[]> {
const url = `/users?q=${query}`
const response = await this.request.get(url)
const responseItems: UserItemResponse[] = response.data
return responseItems.map(item => UserItem.valueOf(item))
}
}

11
frontend/repositories/user/interface.ts

@ -0,0 +1,11 @@
import { UserItem } from '@/models/user'
export interface UserItemResponse {
id: number,
username: string,
is_superuser: boolean
}
export interface UserItemListRepository {
list(query: string): Promise<UserItem[]>
}
Loading…
Cancel
Save