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.

28 lines
675 B

  1. import { UserItem } from '@/models/user'
  2. import { UserItemListRepository } from '@/repositories/user/interface'
  3. export class UserDTO {
  4. id: number
  5. username: string
  6. constructor(item: UserItem) {
  7. this.id = item.id
  8. this.username = item.username
  9. }
  10. }
  11. export class UserApplicationService {
  12. constructor(
  13. private readonly repository: UserItemListRepository
  14. ) {}
  15. public async getMyProfile(): Promise<UserDTO> {
  16. const item = await this.repository.getMe()
  17. return new UserDTO(item)
  18. }
  19. public async list(query: string): Promise<UserDTO[]> {
  20. const items = await this.repository.list(query)
  21. return items.map(item => new UserDTO(item))
  22. }
  23. }