Skip to content

Commit 775ca26

Browse files
authored
feat: 작품 둘러보기 api 연결 및 구현 완료 (#209)
1 parent 1e985bc commit 775ca26

20 files changed

+471
-265
lines changed

package-lock.json

Lines changed: 69 additions & 69 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
]
5555
},
5656
"devDependencies": {
57-
"@tailwindcss/postcss": "^4.1.4",
57+
"@tailwindcss/postcss": "^4.1.5",
5858
"@types/js-cookie": "^3.0.6",
5959
"@types/node": "^22.10.8",
6060
"@types/react": "^19.0.7",

src/api/user/postListApi.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import axios from "axios";
2+
import Cookies from "js-cookie";
3+
import { StringOptionsWithImporter } from "sass";
4+
5+
const apiUrl = import.meta.env.VITE_API_URL;
6+
7+
const api = axios.create({
8+
baseURL: apiUrl, // Use environment variables
9+
timeout: 10000,
10+
});
11+
12+
export interface ScriptItem {
13+
id: string;
14+
title: string;
15+
writer: string;
16+
imagePath: string;
17+
script: boolean;
18+
scriptPrice: number;
19+
performance: boolean;
20+
performancePrice: number;
21+
checked: string;
22+
date: string; // ISO 8601 string
23+
like: boolean;
24+
likeCount: number;
25+
viewCount: number;
26+
}
27+
28+
export interface ExploreScriptsResponse {
29+
longPlay: ScriptItem[];
30+
shortPlay: ScriptItem[];
31+
}
32+
33+
export const fetchExploreScripts = async (
34+
accessToken?: string
35+
): Promise<ExploreScriptsResponse> => {
36+
try {
37+
const headers: Record<string, string> = {};
38+
39+
if (accessToken) {
40+
headers["Authorization"] = `Bearer ${accessToken}`;
41+
}
42+
43+
const response = await api.get<ExploreScriptsResponse>("/scripts", {
44+
headers,
45+
withCredentials: true, // 쿠키 인증 시 필요
46+
});
47+
48+
console.log(response);
49+
return response.data;
50+
} catch (error) {
51+
console.error("Error fetchExploreScripts:", error);
52+
throw new Error(`작품 둘러보기 API 호출 실패: ${(error as Error).message}`);
53+
}
54+
};
55+
56+
export const toggleLikeScript = async (
57+
id: string,
58+
accessToken?: string
59+
): Promise<"like" | "cancel like"> => {
60+
try {
61+
const headers: Record<string, string> = {
62+
"Content-Type": "application/json",
63+
};
64+
65+
if (accessToken) {
66+
headers["Authorization"] = `Bearer ${accessToken}`;
67+
}
68+
69+
const response = await api.post<{ message: "like" | "cancel like" }>(
70+
`/scripts/like/${id}`,
71+
null,
72+
{ headers, withCredentials: true }
73+
);
74+
75+
return response.data.message;
76+
} catch (error) {
77+
console.error("Error toggleLikeScript:", error);
78+
throw new Error(`좋아요 토글 실패: ${(error as Error).message}`);
79+
}
80+
};
Lines changed: 9 additions & 0 deletions
Loading
1.76 MB
Loading

0 commit comments

Comments
 (0)