Skip to content
Merged
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
16 changes: 16 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"framer-motion": "^12.6.2",
"highcharts": "^12.3.0",
"highcharts-react-official": "^3.2.2",
"lightweight-charts": "^5.0.8",
"lucide-react": "^0.483.0",
"react": "^19.0.0",
"react-chartjs-2": "^5.3.0",
Expand Down
4 changes: 2 additions & 2 deletions src/api/auth/loginApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const login = async (
): Promise<{ token: string; user?: User }> => {
try {
const response = await fetch(
`${import.meta.env.VITE_API_BASE_URL}/auth/login`,
`${import.meta.env.VITE_API_BASE_URL}/api/auth/login`,
{
method: "POST",
headers: {
Expand Down Expand Up @@ -92,7 +92,7 @@ export const verifyAuth = async (): Promise<{
}

const response = await fetch(
`${import.meta.env.VITE_API_BASE_URL}/auth/check`,
`${import.meta.env.VITE_API_BASE_URL}/api/auth/check`,
{
method: "GET",
headers: {
Expand Down
2 changes: 1 addition & 1 deletion src/api/auth/logoutApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const logout = async (): Promise<LogoutResponse> => {
}

const response = await fetch(
`${import.meta.env.VITE_API_BASE_URL}/auth/logout`,
`${import.meta.env.VITE_API_BASE_URL}/api/auth/logout`,
{
method: "POST",
headers: {
Expand Down
2 changes: 1 addition & 1 deletion src/api/auth/signUpApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const register = async (
): Promise<RegisterResponse> => {
try {
const response = await fetch(
`${import.meta.env.VITE_API_BASE_URL}/auth/register`,
`${import.meta.env.VITE_API_BASE_URL}/api/auth/register`,
{
method: "POST",
headers: {
Expand Down
2 changes: 1 addition & 1 deletion src/api/market/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ export interface InterestRateWithHistory {
}

export const getAllMarketInfo = async () => {
const { data } = await axiosInstance.get<MarketAllResponse>("/info/all");
const { data } = await axiosInstance.get<MarketAllResponse>("/api/info/all");
return data;
};
14 changes: 7 additions & 7 deletions src/api/news/byCompany.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import axios from "axios";

const API_URL = import.meta.env.VITE_API_BASE_URL || "http://localhost:3000";
import { axiosInstance } from "@/lib/axiosInstance";

export interface CompanyNewsItemDTO {
id: string;
Expand All @@ -15,9 +13,11 @@ export interface CompanyNewsResponse {
}

export async function getNewsByCompany(stockCode: string, limit = 10) {
const url = `${API_URL}/news/by-company/${stockCode}`;
const { data } = await axios.get<CompanyNewsResponse>(url, {
params: { limit },
});
const { data } = await axiosInstance.get<CompanyNewsResponse>(
`/api/news/by-company/${stockCode}`,
{
params: { limit },
}
);
return data.results;
}
9 changes: 4 additions & 5 deletions src/api/news/detail.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import axios from "axios";
import { axiosInstance } from "@/lib/axiosInstance";
import { NewsItem } from "./types";

const API_URL = import.meta.env.VITE_API_BASE_URL || "http://localhost:3000";
import { isAxiosError } from "axios";

export const getNewsDetail = async (newsId: string): Promise<NewsItem> => {
try {
const response = await axios.get<NewsItem>(`${API_URL}/news/${newsId}`);
const response = await axiosInstance.get<NewsItem>(`/api/news/${newsId}`);
return response.data;
} catch (error) {
if (axios.isAxiosError(error)) {
if (isAxiosError(error)) {
if (error.response?.status === 404) {
throw new Error("ํ•ด๋‹น ๋‰ด์Šค๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
Expand Down
56 changes: 10 additions & 46 deletions src/api/news/feed.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import axios from "axios";
import { axiosInstance } from "@/lib/axiosInstance";
import { NewsItem } from "./types";

const API_URL = import.meta.env.VITE_API_BASE_URL || "http://localhost:3000";
import { isAxiosError } from "axios";

export interface MyFeedParams {
limit?: number;
Expand All @@ -16,57 +15,22 @@ export const getMyFeed = async (
params: MyFeedParams = {}
): Promise<NewsItem[]> => {
try {
const requestUrl = `${API_URL}/news/my-feed`;
const requestParams = {
limit: params.limit || 20,
};

const tokenKey = "access_token";
let token = localStorage.getItem(tokenKey);
if (token && !token.startsWith("Bearer ")) {
token = `Bearer ${token}`;
}

console.log("API ์š”์ฒญ ์ •๋ณด:", {
url: requestUrl,
params: requestParams,
env: {
VITE_API_BASE_URL: import.meta.env.VITE_API_BASE_URL,
NODE_ENV: import.meta.env.NODE_ENV,
},
headers: {
Authorization: token,
},
});

const response = await axios.get<MyFeedResponse>(requestUrl, {
params: requestParams,
headers: {
Authorization: token,
},
});

console.log("API ์‘๋‹ต:", {
status: response.status,
data: response.data,
headers: response.headers,
});
const response = await axiosInstance.get<MyFeedResponse>(
"/api/news/my-feed",
{
params: requestParams,
}
);

return response.data.results;
} catch (error) {
console.error("API ์—๋Ÿฌ ์ƒ์„ธ:", {
error,
isAxiosError: axios.isAxiosError(error),
response: axios.isAxiosError(error)
? {
status: error.response?.status,
data: error.response?.data,
headers: error.response?.headers,
}
: null,
});
console.error("API ์—๋Ÿฌ ์ƒ์„ธ:", error);

if (axios.isAxiosError(error)) {
if (isAxiosError(error)) {
// 404 Not Found - ์ฆ๊ฒจ์ฐพ๊ธฐ ์ข…๋ชฉ์ด ์—†๋Š” ๊ฒฝ์šฐ
if (error.response?.status === 404) {
const detail = error.response.data?.detail;
Expand Down
6 changes: 2 additions & 4 deletions src/api/news/search.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import axios from "axios";
import { axiosInstance } from "@/lib/axiosInstance";
import { NewsSearchParams } from "./types";

const API_URL = import.meta.env.VITE_API_BASE_URL || "http://localhost:3000";

export const searchNews = async (params: NewsSearchParams): Promise<any> => {
try {
const response = await axios.get(`${API_URL}/news/search`, {
const response = await axiosInstance.get("/api/news/search", {
params: {
keyword: params.keyword,
impact: params.impact,
Expand Down
2 changes: 1 addition & 1 deletion src/api/stock/company.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export type CompanyInfoResponse = Record<string, any>;
export const getCompanyInfoByCode = async (
stockCode: string
): Promise<CompanyInfoResponse> => {
const { data } = await axiosInstance.get(`/info/company/${stockCode}`);
const { data } = await axiosInstance.get(`/api/info/company/${stockCode}`);
return data;
};
33 changes: 32 additions & 1 deletion src/api/stock/detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,37 @@ export type RawStockInfoResponse = Record<string, any>;
export const getStockInfoByCode = async (
stockCode: string
): Promise<RawStockInfoResponse> => {
const { data } = await axiosInstance.get(`/info/stock/${stockCode}`);
const { data } = await axiosInstance.get(`/api/info/stock/${stockCode}`);
return data;
};

// ์ฐจํŠธ ๋ฐ์ดํ„ฐ ํƒ€์ž… ๋ฐ API
export interface StockChartCandle {
date: string;
open: number;
high: number;
low: number;
close: number;
volume: number;
}

export type StockChartPeriod = "D" | "W" | "M";

export interface StockChartResponse {
stock_code: string;
period: StockChartPeriod;
count: number;
candles: StockChartCandle[];
}

export async function getStockChart(
stockCode: string,
period: StockChartPeriod,
count: number
): Promise<StockChartResponse> {
const { data } = await axiosInstance.get<StockChartResponse>(
`/api/stock/chart/${encodeURIComponent(stockCode)}`,
{ params: { period, count } }
);
return data;
}
2 changes: 1 addition & 1 deletion src/api/stock/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const getStockList = async (
): Promise<StockListResponse> => {
try {
// ์ƒˆ๋กœ์šด /info/companies API ์‚ฌ์šฉ
const response = await axiosInstance.get("/info/companies", {
const response = await axiosInstance.get("/api/info/companies", {
params: {
sort_by: sortBy,
},
Expand Down
2 changes: 1 addition & 1 deletion src/api/stock/relatedCompanies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function getRelatedCompanies(
sort_by = "market_cap_desc"
) {
const { data } = await axiosInstance.get<RelatedCompanyDTO[]>(
`/info/related-companies/${stockCode}`,
`/api/info/related-companies/${stockCode}`,
{ params: { sort_by } }
);
return data;
Expand Down
2 changes: 1 addition & 1 deletion src/api/stock/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const searchStockData = async (
params: StockSearchParams
): Promise<StockSearchResponse> => {
try {
const response = await axiosInstance.get("/stock/search", { params });
const response = await axiosInstance.get("/api/stock/search", { params });
return response.data;
} catch (error) {
console.error("์ฃผ์‹ ๊ฒ€์ƒ‰ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:", error);
Expand Down
6 changes: 3 additions & 3 deletions src/api/user/favoritesApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ชฉ๋ก ์กฐํšŒ
export const getFavorites = async (): Promise<string[]> => {
try {
const response = await fetch("/user/favorites", {
const response = await fetch("/api/user/favorites", {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand All @@ -22,7 +22,7 @@ export const getFavorites = async (): Promise<string[]> => {
// ์ฆ๊ฒจ์ฐพ๊ธฐ ์ถ”๊ฐ€
export const addFavorite = async (tickerOrCompany: string): Promise<string> => {
try {
const response = await fetch("/user/favorites", {
const response = await fetch("/api/user/favorites", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -48,7 +48,7 @@ export const removeFavorite = async (
tickerOrCompany: string
): Promise<string> => {
try {
const response = await fetch("/user/favorites", {
const response = await fetch("/api/user/favorites", {
method: "DELETE",
headers: {
"Content-Type": "application/json",
Expand Down
2 changes: 1 addition & 1 deletion src/components/home/PopularStocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface Stock {
// API ํ˜ธ์ถœ ํ•จ์ˆ˜
const getPopularCompanies = async (): Promise<CompanyInfo[]> => {
try {
const response = await fetch("/info/companies?sort_by=market_cap_desc");
const response = await fetch("/api/info/companies?sort_by=market_cap_desc");

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
Expand Down
2 changes: 1 addition & 1 deletion src/components/home/TrendingKeywords.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const getCompanies = async (
sortBy: SortBy = "market_cap_desc"
): Promise<CompanyInfo[]> => {
try {
const response = await fetch(`/info/companies?sort_by=${sortBy}`);
const response = await fetch(`/api/info/companies?sort_by=${sortBy}`);

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
Expand Down
Loading