-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(my-recruit): 내 공고 뽀각 페이지 api 연결 #28
Merged
Merged
Changes from 4 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { http } from '@/apis/http'; | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { GET_PROGRESSING_RECRUITS_KEY } from '@/app/(sidebar)/my-recruit/api/useGetProgressingRecruits'; | ||
import { GET_ALL_RECRUITS_KEY } from '@/app/(sidebar)/my-recruit/api/useGetAllRecruits'; | ||
|
||
export const DELETE_RECRUIT_KEY = 'delete-recruit'; | ||
|
||
export const deleteRecruit = (recruitId: number) => | ||
http.delete({ | ||
url: `/recruits/${recruitId}`, | ||
}); | ||
|
||
export const useDeleteRecruit = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
const mutate = useMutation({ | ||
mutationFn: (recruitId: number) => deleteRecruit(recruitId), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: [GET_PROGRESSING_RECRUITS_KEY] }); | ||
queryClient.invalidateQueries({ queryKey: [GET_ALL_RECRUITS_KEY] }); | ||
}, | ||
}); | ||
|
||
return mutate; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { http } from '@/apis/http'; | ||
import { useSuspenseQuery } from '@tanstack/react-query'; | ||
import { RecruitCard } from '@/app/(sidebar)/my-recruit/type'; | ||
import { ALL_RECRUITMENT } from '@/app/(sidebar)/my-recruit/containers/components/SeasonDropdownContent'; | ||
|
||
type Request = { season: string }; | ||
|
||
type Response = { data: RecruitCard[] }; | ||
|
||
export const GET_ALL_RECRUITS_KEY = 'recruits-all'; | ||
|
||
function getAllRecruits() { | ||
return http.get({ url: '/recruits' }); | ||
} | ||
|
||
function getRecruitsBySeason({ season }: Request) { | ||
return http.get({ url: '/recruits/bySeason', params: { season } }); | ||
} | ||
|
||
export function useGetAllRecruits({ season }: Request) { | ||
const result = useSuspenseQuery({ | ||
queryKey: [GET_ALL_RECRUITS_KEY, season], | ||
queryFn: season === ALL_RECRUITMENT ? getAllRecruits : () => getRecruitsBySeason({ season }), | ||
}); | ||
|
||
return result.data as unknown as Response; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { http } from '@/apis/http'; | ||
import { useSuspenseQuery } from '@tanstack/react-query'; | ||
import { TagType } from '@/types/info'; | ||
|
||
interface Props { | ||
type: string; | ||
} | ||
|
||
interface Response { | ||
data: Array<{ | ||
id: number; | ||
title: string; | ||
updatedDate: string; | ||
tagList: Array<TagType>; | ||
}>; | ||
} | ||
|
||
export const GET_CARDS = 'cards'; | ||
|
||
function getCards({ type }: Props) { | ||
return http.get({ url: '/cards', params: { type } }); | ||
} | ||
|
||
export function useGetCards({ type }: Props) { | ||
const result = useSuspenseQuery({ queryKey: [GET_CARDS, type], queryFn: () => getCards({ type }) }); | ||
|
||
return result.data as unknown as Response; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/app/(sidebar)/my-recruit/api/useGetProgressingRecruits.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { http } from '@/apis/http'; | ||
import { useSuspenseQuery } from '@tanstack/react-query'; | ||
import { RecruitCard } from '@/app/(sidebar)/my-recruit/type'; | ||
|
||
type Response = { data: RecruitCard[] }; | ||
|
||
export const GET_PROGRESSING_RECRUITS_KEY = 'recruits-progressing'; | ||
|
||
function getProgressingRecruits() { | ||
return http.get({ url: '/recruits/progressing' }); | ||
} | ||
|
||
export function useGetProgressingRecruits() { | ||
const result = useSuspenseQuery({ | ||
queryKey: [GET_PROGRESSING_RECRUITS_KEY], | ||
queryFn: getProgressingRecruits, | ||
}); | ||
|
||
return result.data as unknown as Response; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useSuspenseQuery } from '@tanstack/react-query'; | ||
import { http } from '@/apis/http'; | ||
|
||
type Response = { | ||
data: Array<{ | ||
name: string; | ||
}>; | ||
}; | ||
|
||
export const GET_SEASONS_KEY = 'seasons'; | ||
|
||
function getSeasons() { | ||
return http.get({ url: '/seasons' }); | ||
} | ||
|
||
export function useGetSeasons() { | ||
const result = useSuspenseQuery({ queryKey: [GET_SEASONS_KEY], queryFn: getSeasons }); | ||
|
||
return result.data as unknown as Response; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { http } from '@/apis/http'; | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { GET_PROGRESSING_RECRUITS_KEY } from '@/app/(sidebar)/my-recruit/api/useGetProgressingRecruits'; | ||
import { GET_ALL_RECRUITS_KEY } from '@/app/(sidebar)/my-recruit/api/useGetAllRecruits'; | ||
|
||
interface Request { | ||
id: number; | ||
recruitStatus: string; | ||
} | ||
|
||
export const PATCH_RECRUIT_STATUS_KEY = 'put-recruit-status'; | ||
|
||
function patchRecruitStatus({ id, recruitStatus }: Request) { | ||
return http.patch({ url: `/recruits/${id}/status`, data: { recruitStatus } }); | ||
} | ||
|
||
export function usePatchRecruitStatus() { | ||
const queryClient = useQueryClient(); | ||
|
||
const mutate = useMutation({ | ||
mutationFn: (data: Request) => patchRecruitStatus(data), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: [GET_PROGRESSING_RECRUITS_KEY] }); | ||
queryClient.invalidateQueries({ queryKey: [GET_ALL_RECRUITS_KEY] }); | ||
}, | ||
}); | ||
|
||
return mutate; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { http } from '@/apis/http'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
interface Request { | ||
recruitId: number; | ||
cardId: number; | ||
} | ||
|
||
export const POST_CARD_TO_RECRUIT_KEY = 'post-card-to-recruit'; | ||
|
||
function postCardToRecruit({ recruitId, cardId }: Request) { | ||
return http.post({ url: `/recruits/${recruitId}/cards/${cardId}` }); | ||
} | ||
|
||
export function usePostCardToRecruit() { | ||
const mutate = useMutation({ | ||
mutationKey: [POST_CARD_TO_RECRUIT_KEY], | ||
mutationFn: (data: Request) => postCardToRecruit(data), | ||
}); | ||
|
||
return mutate; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { http } from '@/apis/http'; | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { GET_PROGRESSING_RECRUITS_KEY } from '@/app/(sidebar)/my-recruit/api/useGetProgressingRecruits'; | ||
import { GET_ALL_RECRUITS_KEY } from '@/app/(sidebar)/my-recruit/api/useGetAllRecruits'; | ||
|
||
export interface Request { | ||
title: string; | ||
season: string; | ||
siteUrl: string; | ||
recruitScheduleStage: string; | ||
deadline: string | null; | ||
} | ||
|
||
export const POST_RECRUIT_KEY = 'post-recruit'; | ||
|
||
function postRecruit(data: Request) { | ||
return http.post({ url: '/recruits', data }); | ||
} | ||
|
||
export function usePostRecruit() { | ||
const queryClient = useQueryClient(); | ||
|
||
const mutate = useMutation({ | ||
mutationFn: (data: Request) => postRecruit(data), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: [GET_PROGRESSING_RECRUITS_KEY] }); | ||
queryClient.invalidateQueries({ queryKey: [GET_ALL_RECRUITS_KEY] }); | ||
}, | ||
}); | ||
|
||
return mutate; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이렇게 사용하면 tanstack-query의 반환값 타입을 명시하지 않아도 가능해요