Skip to content

Commit

Permalink
feat(api): add fetchFollowData function
Browse files Browse the repository at this point in the history
  • Loading branch information
yun-cheng committed Mar 21, 2024
1 parent 8e4f7d1 commit b995f6a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_SERVER_URL=https://avl-frontend-exam.herokuapp.com
29 changes: 29 additions & 0 deletions src/api/fetchFollowData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { FollowUser } from 'types/follow'

const { VITE_SERVER_URL } = import.meta.env

type Props = {
type: 'followers' | 'following'
page: number
pageSize?: number
}

type ResponseData = {
total: number
totalPages: number
page: number
pageSize: number
data: FollowUser[]
}

export default async function fetchFollowData({
type,
page,
pageSize = 10
}: Props) {
const queryType = type === 'followers' ? 'all' : 'friends'
const response = await fetch(
`${VITE_SERVER_URL}/api/users/${queryType}?page=${page}&pageSize=${pageSize}`
)
return (await response.json()) as ResponseData
}

0 comments on commit b995f6a

Please sign in to comment.