Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { axiosInstance } from "@/utils/axiosInstance";

export type ๋กœ๊ทธ์•„์›ƒResponse = void;

export type ๋กœ๊ทธ์•„์›ƒRequest = Record<string, never>;

export interface ์• ํ”Œ ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Response {
isRegistered: boolean;
nickname: null;
email: string;
profileImageUrl: null;
signUpToken: string;
}

export type ์• ํ”Œ ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Request = Record<string, never>;

export interface ์—‘์„ธ์Šค ํ† ํฐ ์žฌ๋ฐœ๊ธ‰Response {
accessToken: string;
}

export type ์—‘์„ธ์Šค ํ† ํฐ ์žฌ๋ฐœ๊ธ‰Request = Record<string, never>;

export interface ์ด๋ฉ”์ผ ๋กœ๊ทธ์ธResponse {
accessToken: string;
refreshToken: string;
}

export type ์ด๋ฉ”์ผ ๋กœ๊ทธ์ธRequest = Record<string, never>;

export interface ์ด๋ฉ”์ผ ์ธ์ฆ (๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Response {
signUpToken: string;
}

export type ์ด๋ฉ”์ผ ์ธ์ฆ (๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Request = Record<string, never>;

export interface ์นด์นด์˜ค ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Response {
isRegistered: boolean;
nickname: string;
email: string;
profileImageUrl: string;
signUpToken: string;
}

export type ์นด์นด์˜ค ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Request = Record<string, never>;

export type ํšŒ์› ํƒˆํ‡ดResponse = void;

export interface ํšŒ์›๊ฐ€์ž…Response {
accessToken: string;
refreshToken: string;
}

export type ํšŒ์›๊ฐ€์ž…Request = Record<string, never>;

export const 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi = {
post๋กœ๊ทธ์•„์›ƒ: async (params: { data?: ๋กœ๊ทธ์•„์›ƒRequest }): Promise<๋กœ๊ทธ์•„์›ƒResponse> => {
const res = await axiosInstance.post<๋กœ๊ทธ์•„์›ƒResponse>(
`/auth/sign-out`, params?.data
);
return res.data;
},

post์• ํ”Œ ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰): async (params: { data?: ์• ํ”Œ ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Request }): Promise<์• ํ”Œ ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Response> => {
const res = await axiosInstance.post<์• ํ”Œ ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Response>(
`/auth/apple`, params?.data
);
return res.data;
},

post์—‘์„ธ์Šค ํ† ํฐ ์žฌ๋ฐœ๊ธ‰: async (params: { data?: ์—‘์„ธ์Šค ํ† ํฐ ์žฌ๋ฐœ๊ธ‰Request }): Promise<์—‘์„ธ์Šค ํ† ํฐ ์žฌ๋ฐœ๊ธ‰Response> => {
const res = await axiosInstance.post<์—‘์„ธ์Šค ํ† ํฐ ์žฌ๋ฐœ๊ธ‰Response>(
`/auth/reissue`, params?.data
);
return res.data;
},

post์ด๋ฉ”์ผ ๋กœ๊ทธ์ธ: async (params: { data?: ์ด๋ฉ”์ผ ๋กœ๊ทธ์ธRequest }): Promise<์ด๋ฉ”์ผ ๋กœ๊ทธ์ธResponse> => {
const res = await axiosInstance.post<์ด๋ฉ”์ผ ๋กœ๊ทธ์ธResponse>(
`/auth/email/sign-in`, params?.data
);
return res.data;
},

post์ด๋ฉ”์ผ ์ธ์ฆ (๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰): async (params: { data?: ์ด๋ฉ”์ผ ์ธ์ฆ (๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Request }): Promise<์ด๋ฉ”์ผ ์ธ์ฆ (๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Response> => {
const res = await axiosInstance.post<์ด๋ฉ”์ผ ์ธ์ฆ (๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Response>(
`/auth/email/sign-up`, params?.data
);
return res.data;
},

post์นด์นด์˜ค ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰): async (params: { data?: ์นด์นด์˜ค ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Request }): Promise<์นด์นด์˜ค ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Response> => {
const res = await axiosInstance.post<์นด์นด์˜ค ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Response>(
`/auth/kakao`, params?.data
);
return res.data;
},

deleteํšŒ์› ํƒˆํ‡ด: async (): Promise<ํšŒ์› ํƒˆํ‡ดResponse> => {
const res = await axiosInstance.delete<ํšŒ์› ํƒˆํ‡ดResponse>(
`/auth/quit`
);
return res.data;
},

postํšŒ์›๊ฐ€์ž…: async (params: { data?: ํšŒ์›๊ฐ€์ž…Request }): Promise<ํšŒ์›๊ฐ€์ž…Response> => {
const res = await axiosInstance.post<ํšŒ์›๊ฐ€์ž…Response>(
`/auth/sign-up`, params?.data
);
return res.data;
},

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AxiosError } from "axios";
import { useMutation } from "@tanstack/react-query";
import { 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi, ํšŒ์› ํƒˆํ‡ดResponse, ํšŒ์› ํƒˆํ‡ดRequest } from "./api";

const useDeleteํšŒ์› ํƒˆํ‡ด = () => {
return useMutation<ํšŒ์› ํƒˆํ‡ดResponse, AxiosError, ํšŒ์› ํƒˆํ‡ดRequest>({
mutationFn: (data) => 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi.deleteํšŒ์› ํƒˆํ‡ด({ data }),
});
};

export default useDeleteํšŒ์› ํƒˆํ‡ด;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export { 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi } from './api';
export { default as deleteํšŒ์› ํƒˆํ‡ด } from './deleteํšŒ์› ํƒˆํ‡ด';
export { default as post๋กœ๊ทธ์•„์›ƒ } from './post๋กœ๊ทธ์•„์›ƒ';
export { default as post์• ํ”Œ ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰) } from './post์• ํ”Œ ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)';
export { default as post์—‘์„ธ์Šค ํ† ํฐ ์žฌ๋ฐœ๊ธ‰ } from './post์—‘์„ธ์Šค ํ† ํฐ ์žฌ๋ฐœ๊ธ‰';
export { default as post์ด๋ฉ”์ผ ๋กœ๊ทธ์ธ } from './post์ด๋ฉ”์ผ ๋กœ๊ทธ์ธ';
export { default as post์ด๋ฉ”์ผ ์ธ์ฆ (๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰) } from './post์ด๋ฉ”์ผ ์ธ์ฆ (๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)';
export { default as post์นด์นด์˜ค ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰) } from './post์นด์นด์˜ค ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)';
export { default as postํšŒ์›๊ฐ€์ž… } from './postํšŒ์›๊ฐ€์ž…';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AxiosError } from "axios";
import { useMutation } from "@tanstack/react-query";
import { 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi, ๋กœ๊ทธ์•„์›ƒResponse, ๋กœ๊ทธ์•„์›ƒRequest } from "./api";

const usePost๋กœ๊ทธ์•„์›ƒ = () => {
return useMutation<๋กœ๊ทธ์•„์›ƒResponse, AxiosError, ๋กœ๊ทธ์•„์›ƒRequest>({
mutationFn: (data) => 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi.post๋กœ๊ทธ์•„์›ƒ({ data }),
});
};

export default usePost๋กœ๊ทธ์•„์›ƒ;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AxiosError } from "axios";
import { useMutation } from "@tanstack/react-query";
import { 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi, ์• ํ”Œ ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Response, ์• ํ”Œ ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Request } from "./api";

const usePost์• ํ”Œ ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰) = () => {
return useMutation<์• ํ”Œ ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Response, AxiosError, ์• ํ”Œ ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Request>({
mutationFn: (data) => 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi.post์• ํ”Œ ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)({ data }),
});
};

export default usePost์• ํ”Œ ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AxiosError } from "axios";
import { useMutation } from "@tanstack/react-query";
import { 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi, ์—‘์„ธ์Šค ํ† ํฐ ์žฌ๋ฐœ๊ธ‰Response, ์—‘์„ธ์Šค ํ† ํฐ ์žฌ๋ฐœ๊ธ‰Request } from "./api";

const usePost์—‘์„ธ์Šค ํ† ํฐ ์žฌ๋ฐœ๊ธ‰ = () => {
return useMutation<์—‘์„ธ์Šค ํ† ํฐ ์žฌ๋ฐœ๊ธ‰Response, AxiosError, ์—‘์„ธ์Šค ํ† ํฐ ์žฌ๋ฐœ๊ธ‰Request>({
mutationFn: (data) => 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi.post์—‘์„ธ์Šค ํ† ํฐ ์žฌ๋ฐœ๊ธ‰({ data }),
});
};

export default usePost์—‘์„ธ์Šค ํ† ํฐ ์žฌ๋ฐœ๊ธ‰;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AxiosError } from "axios";
import { useMutation } from "@tanstack/react-query";
import { 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi, ์ด๋ฉ”์ผ ๋กœ๊ทธ์ธResponse, ์ด๋ฉ”์ผ ๋กœ๊ทธ์ธRequest } from "./api";

const usePost์ด๋ฉ”์ผ ๋กœ๊ทธ์ธ = () => {
return useMutation<์ด๋ฉ”์ผ ๋กœ๊ทธ์ธResponse, AxiosError, ์ด๋ฉ”์ผ ๋กœ๊ทธ์ธRequest>({
mutationFn: (data) => 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi.post์ด๋ฉ”์ผ ๋กœ๊ทธ์ธ({ data }),
});
};

export default usePost์ด๋ฉ”์ผ ๋กœ๊ทธ์ธ;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AxiosError } from "axios";
import { useMutation } from "@tanstack/react-query";
import { 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi, ์ด๋ฉ”์ผ ์ธ์ฆ (๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Response, ์ด๋ฉ”์ผ ์ธ์ฆ (๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Request } from "./api";

const usePost์ด๋ฉ”์ผ ์ธ์ฆ (๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰) = () => {
return useMutation<์ด๋ฉ”์ผ ์ธ์ฆ (๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Response, AxiosError, ์ด๋ฉ”์ผ ์ธ์ฆ (๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Request>({
mutationFn: (data) => 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi.post์ด๋ฉ”์ผ ์ธ์ฆ (๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)({ data }),
});
};

export default usePost์ด๋ฉ”์ผ ์ธ์ฆ (๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AxiosError } from "axios";
import { useMutation } from "@tanstack/react-query";
import { 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi, ์นด์นด์˜ค ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Response, ์นด์นด์˜ค ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Request } from "./api";

const usePost์นด์นด์˜ค ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰) = () => {
return useMutation<์นด์นด์˜ค ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Response, AxiosError, ์นด์นด์˜ค ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)Request>({
mutationFn: (data) => 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi.post์นด์นด์˜ค ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰)({ data }),
});
};

export default usePost์นด์นด์˜ค ์ธ์ฆ (๋กœ๊ทธ์ธ or ๊ฐ€์ž… ์ฝ”๋“œ ๋ฐœ๊ธ‰);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AxiosError } from "axios";
import { useMutation } from "@tanstack/react-query";
import { 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi, ํšŒ์›๊ฐ€์ž…Response, ํšŒ์›๊ฐ€์ž…Request } from "./api";

const usePostํšŒ์›๊ฐ€์ž… = () => {
return useMutation<ํšŒ์›๊ฐ€์ž…Response, AxiosError, ํšŒ์›๊ฐ€์ž…Request>({
mutationFn: (data) => 1) ํšŒ์›๊ฐ€์ž…๋กœ๊ทธ์ธApi.postํšŒ์›๊ฐ€์ž…({ data }),
});
};

export default usePostํšŒ์›๊ฐ€์ž…;
64 changes: 64 additions & 0 deletions src/apis/10) ์†Œ์‹์ง€/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { axiosInstance } from "@/utils/axiosInstance";

export type ์†Œ์‹์ง€ ๋ชฉ๋ก ์กฐํšŒResponse = void;

export type ์†Œ์‹์ง€ ์‚ญ์ œResponse = void;

export type ์†Œ์‹์ง€ ์ˆ˜์ •Response = void;

export type ์†Œ์‹์ง€ ์ˆ˜์ •Request = Record<string, never>;

export type ์†Œ์‹์ง€ ์ข‹์•„์š” ์‚ญ์ œResponse = void;

export type ์†Œ์‹์ง€ ์ข‹์•„์š” ์ถ”๊ฐ€Response = void;

export type ์†Œ์‹์ง€ ์ข‹์•„์š” ์ถ”๊ฐ€Request = Record<string, never>;

export type ์†Œ์‹์ง€ ์ถ”๊ฐ€Response = void;

export type ์†Œ์‹์ง€ ์ถ”๊ฐ€Request = Record<string, never>;

export const 10) ์†Œ์‹์ง€Api = {
get์†Œ์‹์ง€ ๋ชฉ๋ก ์กฐํšŒ: async (params: { params?: Record<string, any> }): Promise<์†Œ์‹์ง€ ๋ชฉ๋ก ์กฐํšŒResponse> => {
const res = await axiosInstance.get<์†Œ์‹์ง€ ๋ชฉ๋ก ์กฐํšŒResponse>(
`/news?author-id=6`, { params: params?.params }
);
return res.data;
},

delete์†Œ์‹์ง€ ์‚ญ์ œ: async (params: { newsId: string | number }): Promise<์†Œ์‹์ง€ ์‚ญ์ œResponse> => {
const res = await axiosInstance.delete<์†Œ์‹์ง€ ์‚ญ์ œResponse>(
`/news/${params.newsId}`
);
return res.data;
},

put์†Œ์‹์ง€ ์ˆ˜์ •: async (params: { newsId: string | number, data?: ์†Œ์‹์ง€ ์ˆ˜์ •Request }): Promise<์†Œ์‹์ง€ ์ˆ˜์ •Response> => {
const res = await axiosInstance.put<์†Œ์‹์ง€ ์ˆ˜์ •Response>(
`/news/${params.newsId}`, params?.data
);
return res.data;
},

delete์†Œ์‹์ง€ ์ข‹์•„์š” ์‚ญ์ œ: async (params: { newsId: string | number }): Promise<์†Œ์‹์ง€ ์ข‹์•„์š” ์‚ญ์ œResponse> => {
const res = await axiosInstance.delete<์†Œ์‹์ง€ ์ข‹์•„์š” ์‚ญ์ œResponse>(
`/news/${params.newsId}/like`
);
return res.data;
},

post์†Œ์‹์ง€ ์ข‹์•„์š” ์ถ”๊ฐ€: async (params: { newsId: string | number, data?: ์†Œ์‹์ง€ ์ข‹์•„์š” ์ถ”๊ฐ€Request }): Promise<์†Œ์‹์ง€ ์ข‹์•„์š” ์ถ”๊ฐ€Response> => {
const res = await axiosInstance.post<์†Œ์‹์ง€ ์ข‹์•„์š” ์ถ”๊ฐ€Response>(
`/news/${params.newsId}/like`, params?.data
);
return res.data;
},

post์†Œ์‹์ง€ ์ถ”๊ฐ€: async (params: { data?: ์†Œ์‹์ง€ ์ถ”๊ฐ€Request }): Promise<์†Œ์‹์ง€ ์ถ”๊ฐ€Response> => {
const res = await axiosInstance.post<์†Œ์‹์ง€ ์ถ”๊ฐ€Response>(
`/news`, params?.data
);
return res.data;
},

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AxiosError } from "axios";
import { useMutation } from "@tanstack/react-query";
import { 10) ์†Œ์‹์ง€Api, ์†Œ์‹์ง€ ์‚ญ์ œResponse, ์†Œ์‹์ง€ ์‚ญ์ œRequest } from "./api";

const useDelete์†Œ์‹์ง€ ์‚ญ์ œ = () => {
return useMutation<์†Œ์‹์ง€ ์‚ญ์ œResponse, AxiosError, { newsId: string | number; data: ์†Œ์‹์ง€ ์‚ญ์ œRequest }>({
mutationFn: (variables) => 10) ์†Œ์‹์ง€Api.delete์†Œ์‹์ง€ ์‚ญ์ œ(variables),
});
};

export default useDelete์†Œ์‹์ง€ ์‚ญ์ œ;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AxiosError } from "axios";
import { useMutation } from "@tanstack/react-query";
import { 10) ์†Œ์‹์ง€Api, ์†Œ์‹์ง€ ์ข‹์•„์š” ์‚ญ์ œResponse, ์†Œ์‹์ง€ ์ข‹์•„์š” ์‚ญ์ œRequest } from "./api";

const useDelete์†Œ์‹์ง€ ์ข‹์•„์š” ์‚ญ์ œ = () => {
return useMutation<์†Œ์‹์ง€ ์ข‹์•„์š” ์‚ญ์ œResponse, AxiosError, { newsId: string | number; data: ์†Œ์‹์ง€ ์ข‹์•„์š” ์‚ญ์ œRequest }>({
mutationFn: (variables) => 10) ์†Œ์‹์ง€Api.delete์†Œ์‹์ง€ ์ข‹์•„์š” ์‚ญ์ œ(variables),
});
};

export default useDelete์†Œ์‹์ง€ ์ข‹์•„์š” ์‚ญ์ œ;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { AxiosError } from "axios";
import { useQuery } from "@tanstack/react-query";
import { 10) ์†Œ์‹์ง€Api, ์†Œ์‹์ง€ ๋ชฉ๋ก ์กฐํšŒResponse } from "./api";
import { QueryKeys } from "../queryKeys";

const useGet์†Œ์‹์ง€ ๋ชฉ๋ก ์กฐํšŒ = (params?: Record<string, any>) => {
return useQuery<์†Œ์‹์ง€ ๋ชฉ๋ก ์กฐํšŒResponse, AxiosError>({
queryKey: [QueryKeys.10) ์†Œ์‹์ง€.์†Œ์‹์ง€ ๋ชฉ๋ก ์กฐํšŒ, params],
queryFn: () => 10) ์†Œ์‹์ง€Api.get์†Œ์‹์ง€ ๋ชฉ๋ก ์กฐํšŒ(params ? { params } : {}),
});
};

export default useGet์†Œ์‹์ง€ ๋ชฉ๋ก ์กฐํšŒ;
7 changes: 7 additions & 0 deletions src/apis/10) ์†Œ์‹์ง€/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export { 10) ์†Œ์‹์ง€Api } from './api';
export { default as delete์†Œ์‹์ง€ ์‚ญ์ œ } from './delete์†Œ์‹์ง€ ์‚ญ์ œ';
export { default as delete์†Œ์‹์ง€ ์ข‹์•„์š” ์‚ญ์ œ } from './delete์†Œ์‹์ง€ ์ข‹์•„์š” ์‚ญ์ œ';
export { default as get์†Œ์‹์ง€ ๋ชฉ๋ก ์กฐํšŒ } from './get์†Œ์‹์ง€ ๋ชฉ๋ก ์กฐํšŒ';
export { default as post์†Œ์‹์ง€ ์ข‹์•„์š” ์ถ”๊ฐ€ } from './post์†Œ์‹์ง€ ์ข‹์•„์š” ์ถ”๊ฐ€';
export { default as post์†Œ์‹์ง€ ์ถ”๊ฐ€ } from './post์†Œ์‹์ง€ ์ถ”๊ฐ€';
export { default as put์†Œ์‹์ง€ ์ˆ˜์ • } from './put์†Œ์‹์ง€ ์ˆ˜์ •';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AxiosError } from "axios";
import { useMutation } from "@tanstack/react-query";
import { 10) ์†Œ์‹์ง€Api, ์†Œ์‹์ง€ ์ข‹์•„์š” ์ถ”๊ฐ€Response, ์†Œ์‹์ง€ ์ข‹์•„์š” ์ถ”๊ฐ€Request } from "./api";

const usePost์†Œ์‹์ง€ ์ข‹์•„์š” ์ถ”๊ฐ€ = () => {
return useMutation<์†Œ์‹์ง€ ์ข‹์•„์š” ์ถ”๊ฐ€Response, AxiosError, { newsId: string | number; data: ์†Œ์‹์ง€ ์ข‹์•„์š” ์ถ”๊ฐ€Request }>({
mutationFn: (variables) => 10) ์†Œ์‹์ง€Api.post์†Œ์‹์ง€ ์ข‹์•„์š” ์ถ”๊ฐ€(variables),
});
};

export default usePost์†Œ์‹์ง€ ์ข‹์•„์š” ์ถ”๊ฐ€;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AxiosError } from "axios";
import { useMutation } from "@tanstack/react-query";
import { 10) ์†Œ์‹์ง€Api, ์†Œ์‹์ง€ ์ถ”๊ฐ€Response, ์†Œ์‹์ง€ ์ถ”๊ฐ€Request } from "./api";

const usePost์†Œ์‹์ง€ ์ถ”๊ฐ€ = () => {
return useMutation<์†Œ์‹์ง€ ์ถ”๊ฐ€Response, AxiosError, ์†Œ์‹์ง€ ์ถ”๊ฐ€Request>({
mutationFn: (data) => 10) ์†Œ์‹์ง€Api.post์†Œ์‹์ง€ ์ถ”๊ฐ€({ data }),
});
};

export default usePost์†Œ์‹์ง€ ์ถ”๊ฐ€;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AxiosError } from "axios";
import { useMutation } from "@tanstack/react-query";
import { 10) ์†Œ์‹์ง€Api, ์†Œ์‹์ง€ ์ˆ˜์ •Response, ์†Œ์‹์ง€ ์ˆ˜์ •Request } from "./api";

const usePut์†Œ์‹์ง€ ์ˆ˜์ • = () => {
return useMutation<์†Œ์‹์ง€ ์ˆ˜์ •Response, AxiosError, { newsId: string | number; data: ์†Œ์‹์ง€ ์ˆ˜์ •Request }>({
mutationFn: (variables) => 10) ์†Œ์‹์ง€Api.put์†Œ์‹์ง€ ์ˆ˜์ •(variables),
});
};

export default usePut์†Œ์‹์ง€ ์ˆ˜์ •;
15 changes: 15 additions & 0 deletions src/apis/11) ์‹ ๊ณ /api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { axiosInstance } from "@/utils/axiosInstance";

export type ์‹ ๊ณ ํ•˜๊ธฐResponse = void;

export type ์‹ ๊ณ ํ•˜๊ธฐRequest = Record<string, never>;

export const 11) ์‹ ๊ณ Api = {
post์‹ ๊ณ ํ•˜๊ธฐ: async (params: { data?: ์‹ ๊ณ ํ•˜๊ธฐRequest }): Promise<์‹ ๊ณ ํ•˜๊ธฐResponse> => {
const res = await axiosInstance.post<์‹ ๊ณ ํ•˜๊ธฐResponse>(
`/reports`, params?.data
);
return res.data;
},

};
Loading
Loading