diff --git a/app/api/statistics/category/route.js b/app/api/statistics/category/route.js new file mode 100644 index 0000000..00765cc --- /dev/null +++ b/app/api/statistics/category/route.js @@ -0,0 +1,10 @@ +import { NextResponse } from "next/server"; + +export async function GET() { + const response = await fetch( + "http://34.64.250.183:8080/api/statistics/category" + ); + const data = await response.json(); + + return NextResponse.json(data); +} diff --git a/app/api/statistics/summary/route.js b/app/api/statistics/summary/route.js new file mode 100644 index 0000000..2ccc4e6 --- /dev/null +++ b/app/api/statistics/summary/route.js @@ -0,0 +1,10 @@ +import { NextResponse } from "next/server"; + +export async function GET() { + const response = await fetch( + "http://34.64.250.183:8080/api/statistics/summary" + ); + const data = await response.json(); + + return NextResponse.json(data); +} diff --git a/app/api/statistics/weekly/route.js b/app/api/statistics/weekly/route.js new file mode 100644 index 0000000..c5d0c23 --- /dev/null +++ b/app/api/statistics/weekly/route.js @@ -0,0 +1,10 @@ +import { NextResponse } from "next/server"; + +export async function GET() { + const response = await fetch( + "http://34.64.250.183:8080/api/statistics/weekly" + ); + const data = await response.json(); + + return NextResponse.json(data); +} diff --git a/app/statistics/page.js b/app/statistics/page.js index 652a6bb..51e8e09 100644 --- a/app/statistics/page.js +++ b/app/statistics/page.js @@ -1,6 +1,6 @@ "use client"; -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import { Container, Typography } from "@mui/material"; import { Responsive, WidthProvider } from "react-grid-layout"; import "@/styles/react-grid.css"; @@ -18,11 +18,6 @@ import { RadialLinearScale, } from "chart.js"; import ChartDataLabels from "chartjs-plugin-datalabels"; -import { - mockSummaryStatisticsData, - mockWeeklyStatisticsData, - mockCategoryStatisticsData, -} from "@/constants/mockStatisticsResponseData"; import TotalSolvedChart from "@/components/statistics/summary/total-solved"; import CorrectRateChart from "@/components/statistics/summary/correct-rate"; @@ -31,7 +26,7 @@ import CategorySolvedChart from "@/components/statistics/category/category-solve import CategoryAccuracyChart from "@/components/statistics/category/category-accuracy"; import WeeklyTrendChart from "@/components/statistics/weekly/weekly-trend"; import { statisticUtils } from "@/utils/statisticUtils"; -import {Bell, Settings} from "lucide-react"; +import { Bell, Settings } from "lucide-react"; const ResponsiveGridLayout = WidthProvider(Responsive); @@ -69,6 +64,48 @@ export default function StatisticsPage() { ], }); + const [summaryData, setSummaryData] = useState(null); + const [weeklyData, setWeeklyData] = useState(null); + const [categoryData, setCategoryData] = useState(null); + const [isLoading, setIsLoading] = useState(true); + + useEffect(() => { + const fetchData = async () => { + try { + // API 호출 + const [summaryRes, weeklyRes, categoryRes] = await Promise.all([ + fetch("/api/statistics/summary"), + fetch("/api/statistics/weekly"), + fetch("/api/statistics/category"), + ]); + + // JSON 파싱 + const summary = await summaryRes.json(); + const weekly = await weeklyRes.json(); + const category = await categoryRes.json(); + + // 상태 업데이트 + setSummaryData(summary); + setWeeklyData(weekly); + setCategoryData(category); + } catch (error) { + console.error("Error fetching data:", error); + } finally { + setIsLoading(false); + } + }; + + fetchData(); + }, []); + + if (isLoading) { + return ( +