Skip to content

Commit

Permalink
Merge pull request #107 from kakao-tech-campus-2nd-step3/Week10
Browse files Browse the repository at this point in the history
Week10 1차
  • Loading branch information
ppochaco authored Nov 6, 2024
2 parents a3f6793 + 938ffad commit ab3965f
Show file tree
Hide file tree
Showing 62 changed files with 1,209 additions and 410 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ module.exports = {
'error',
{ variables: false, functions: false, classes: false },
],
'react/jsx-props-no-spreading': 'off',
},
}
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
- name: install npm dependencies
run: npm install
- name: react build
env:
VITE_BASE_URL: ${{ secrets.VITE_BASE_URL }}
VITE_LOGIN_URL: ${{ secretes.VITE_LOGIN_URL }}
run: npm run build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
Expand Down
37 changes: 37 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview"
},
Expand All @@ -14,16 +14,19 @@
"@emotion/css": "^11.13.0",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@hookform/resolvers": "^3.9.1",
"@tanstack/react-query": "^5.56.2",
"axios": "^1.7.7",
"date-fns": "^4.1.0",
"framer-motion": "^11.5.4",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-error-boundary": "^4.1.1",
"react-hook-form": "^7.53.1",
"react-icons": "^5.3.0",
"react-intersection-observer": "^9.13.1",
"react-router-dom": "^6.26.2",
"zod": "^3.23.8",
"zustand": "^4.5.5"
},
"devDependencies": {
Expand Down
15 changes: 0 additions & 15 deletions src/api/services/answer/common/index.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/api/services/answer/common/useAnswerQuestion.ts

This file was deleted.

39 changes: 39 additions & 0 deletions src/api/services/answer/hint.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { queryOptions } from '@tanstack/react-query'

import { authorizationInstance } from '@/api/instance'
import { Hint } from '@/types'

type HintRequestParams = {
answerId: number
}

type HintResponse = {
hints: Hint[]
}

const getHint = async ({ answerId }: HintRequestParams) => {
const response = await authorizationInstance.get<HintResponse>(
`/api/answer/hint/${answerId}`
)

return response.data.hints
}

type BuyHintRequestBody = {
answerId: number
}

export const buyHint = async ({ answerId }: BuyHintRequestBody) => {
await authorizationInstance.post('/api/answer/hint', {
answerId,
})
}

export const hintQuries = {
all: () => ['hints'],
hints: (answerId: number) =>
queryOptions({
queryKey: [...hintQuries.all(), answerId],
queryFn: () => getHint({ answerId }),
}),
}
30 changes: 30 additions & 0 deletions src/api/services/answer/question.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useMutation } from '@tanstack/react-query'

import { authorizationInstance } from '@/api/instance'

type AnswerQuestionParam = {
questionId: number
pickedId: number
}

type AnswerQuestionResponse = {
message: string
}

const answerRandomQuestion = async ({
questionId,
pickedId,
}: AnswerQuestionParam): Promise<AnswerQuestionResponse> => {
const response = await authorizationInstance.post('/api/answer/common', {
questionId,
pickedId,
})

return response.data
}

export const useAnswerRandomQuestion = () => {
return useMutation({
mutationFn: (params: AnswerQuestionParam) => answerRandomQuestion(params),
})
}
21 changes: 0 additions & 21 deletions src/api/services/answer/record-paging/index.ts

This file was deleted.

45 changes: 0 additions & 45 deletions src/api/services/answer/record-paging/useAnswerRecordPaging.ts

This file was deleted.

45 changes: 45 additions & 0 deletions src/api/services/answer/record.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useSuspenseInfiniteQuery } from '@tanstack/react-query'

import { authorizationInstance } from '@/api/instance'
import { appendParamsToUrl } from '@/api/utils/common/appendParamsToUrl'
import { AnswerRecord, PagingRequestParams, PagingResponse } from '@/types'

type AnswerRecordPagingResponse = PagingResponse<AnswerRecord[]>

type AnswerRecordRequsetParams = {
date?: string
} & PagingRequestParams

const getAnswerRecordPaging = async (params: AnswerRecordRequsetParams) => {
const response = await authorizationInstance.get<AnswerRecordPagingResponse>(
appendParamsToUrl('/api/answer/record', params)
)

const { data } = response

return {
records: data.content,
nextPageToken:
data.page !== data.totalPages ? (data.page + 1).toString() : undefined,
}
}

interface AnswerRecordPagingProps extends PagingRequestParams {
initPageToken?: string
date?: string
}

export const useAnswerRecordPaging = ({
size = 10,
sort,
initPageToken,
date,
}: AnswerRecordPagingProps) => {
return useSuspenseInfiniteQuery({
queryKey: ['answer', 'record', initPageToken],
queryFn: ({ pageParam = initPageToken }) =>
getAnswerRecordPaging({ page: pageParam, size, sort, date }),
initialPageParam: initPageToken,
getNextPageParam: (lastPage) => lastPage.nextPageToken,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,14 @@ export const getFriends = async () => {
return response.data
}

type FriendId = {
id: number
}

type AddFriendRequestBody = {
friends: FriendId[]
friends: { id: number }[]
}

export const addFriends = async (friends: AddFriendRequestBody) => {
if (!friends.friends.length) {
export const addFriends = async ({ friends }: AddFriendRequestBody) => {
if (!friends.length) {
throw new Error(DATA_ERROR_MESSAGES.FRIEND_CANNOT_BE_EMPTY)
}

await authorizationInstance.post('/api/friend', friends)
}

export const fetchKakaoFriends = async () => {
const response = await authorizationInstance.get('/api/friend')

return response.data.friends
await authorizationInstance.post('/api/friend', { friends })
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { queryOptions, useSuspenseQueries } from '@tanstack/react-query'

import { getFriends } from './index'
import { getFriends } from './friend.api'

export const friendsQueries = {
all: () => ['friends'],
Expand Down
10 changes: 0 additions & 10 deletions src/api/services/friend/useKakaoFriends.ts

This file was deleted.

Loading

0 comments on commit ab3965f

Please sign in to comment.