You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
772 B

  1. import ApiService from '@/services/api.service'
  2. import { UserRepository, UserItemResponse } from '@/domain/models/user/userRepository'
  3. import { UserItem } from '~/domain/models/user/user'
  4. export class APIUserRepository implements UserRepository {
  5. constructor(
  6. private readonly request = ApiService
  7. ) {}
  8. async getMe(): Promise<UserItem> {
  9. const url = '/me'
  10. const response = await this.request.get(url)
  11. const item: UserItemResponse = response.data
  12. return UserItem.valueOf(item)
  13. }
  14. async list(query: string): Promise<UserItem[]> {
  15. const url = `/users?q=${query}`
  16. const response = await this.request.get(url)
  17. const responseItems: UserItemResponse[] = response.data
  18. return responseItems.map(item => UserItem.valueOf(item))
  19. }
  20. }