From 5acb7bb1d0e6ae6a6776f0a3f033321d93f9dd6c Mon Sep 17 00:00:00 2001 From: Zlendy Date: Fri, 18 Apr 2025 10:26:23 +0200 Subject: [PATCH 1/2] refactor: Use GET in `/statistics` API endpoints instead of POST --- backend/routes/stats.js | 12 ++++++------ src/pages/components/statistics/daily-play-count.jsx | 5 ++--- .../components/statistics/play-stats-by-day.jsx | 5 ++--- .../components/statistics/play-stats-by-hour.jsx | 5 ++--- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/backend/routes/stats.js b/backend/routes/stats.js index 2a78f66..779ced6 100644 --- a/backend/routes/stats.js +++ b/backend/routes/stats.js @@ -407,9 +407,9 @@ router.post("/getLibraryLastPlayed", async (req, res) => { } }); -router.post("/getViewsOverTime", async (req, res) => { +router.get("/getViewsOverTime", async (req, res) => { try { - const { days } = req.body; + const { days } = req.query; let _days = days; if (days === undefined) { _days = 30; @@ -446,9 +446,9 @@ router.post("/getViewsOverTime", async (req, res) => { } }); -router.post("/getViewsByDays", async (req, res) => { +router.get("/getViewsByDays", async (req, res) => { try { - const { days } = req.body; + const { days } = req.query; let _days = days; if (days === undefined) { _days = 30; @@ -481,9 +481,9 @@ router.post("/getViewsByDays", async (req, res) => { } }); -router.post("/getViewsByHour", async (req, res) => { +router.get("/getViewsByHour", async (req, res) => { try { - const { days } = req.body; + const { days } = req.query; let _days = days; if (days === undefined) { _days = 30; diff --git a/src/pages/components/statistics/daily-play-count.jsx b/src/pages/components/statistics/daily-play-count.jsx index 3e896fc..e7b9316 100644 --- a/src/pages/components/statistics/daily-play-count.jsx +++ b/src/pages/components/statistics/daily-play-count.jsx @@ -17,12 +17,11 @@ function DailyPlayStats(props) { useEffect(() => { const fetchLibraries = () => { - const url = `/stats/getViewsOverTime`; + const url = `/stats/getViewsOverTime?days=${props.days}`; axios - .post( + .get( url, - { days: props.days }, { headers: { Authorization: `Bearer ${token}`, diff --git a/src/pages/components/statistics/play-stats-by-day.jsx b/src/pages/components/statistics/play-stats-by-day.jsx index d04843c..c7f5c09 100644 --- a/src/pages/components/statistics/play-stats-by-day.jsx +++ b/src/pages/components/statistics/play-stats-by-day.jsx @@ -13,12 +13,11 @@ function PlayStatsByDay(props) { useEffect(() => { const fetchLibraries = () => { - const url = `/stats/getViewsByDays`; + const url = `/stats/getViewsByDays?days=${props.days}`; axios - .post( + .get( url, - { days: props.days }, { headers: { Authorization: `Bearer ${token}`, diff --git a/src/pages/components/statistics/play-stats-by-hour.jsx b/src/pages/components/statistics/play-stats-by-hour.jsx index 4403400..f1895d3 100644 --- a/src/pages/components/statistics/play-stats-by-hour.jsx +++ b/src/pages/components/statistics/play-stats-by-hour.jsx @@ -12,12 +12,11 @@ function PlayStatsByHour(props) { useEffect(() => { const fetchLibraries = () => { - const url = `/stats/getViewsByHour`; + const url = `/stats/getViewsByHour?days=${props.days}`; axios - .post( + .get( url, - { days: props.days }, { headers: { Authorization: `Bearer ${token}`, From 85336327f71f4a2ccadf6df7c67f44ec6d054e8b Mon Sep 17 00:00:00 2001 From: Zlendy Date: Fri, 18 Apr 2025 10:38:02 +0200 Subject: [PATCH 2/2] chore: Generate swagger schema --- backend/swagger.json | 45 ++++++++++++-------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/backend/swagger.json b/backend/swagger.json index 84ec7fe..4fc931e 100644 --- a/backend/swagger.json +++ b/backend/swagger.json @@ -3504,7 +3504,7 @@ } }, "/stats/getViewsOverTime": { - "post": { + "get": { "tags": [ "Stats" ], @@ -3526,16 +3526,9 @@ "type": "string" }, { - "name": "body", - "in": "body", - "schema": { - "type": "object", - "properties": { - "days": { - "example": "any" - } - } - } + "name": "days", + "in": "query", + "type": "string" } ], "responses": { @@ -3558,7 +3551,7 @@ } }, "/stats/getViewsByDays": { - "post": { + "get": { "tags": [ "Stats" ], @@ -3580,16 +3573,9 @@ "type": "string" }, { - "name": "body", - "in": "body", - "schema": { - "type": "object", - "properties": { - "days": { - "example": "any" - } - } - } + "name": "days", + "in": "query", + "type": "string" } ], "responses": { @@ -3612,7 +3598,7 @@ } }, "/stats/getViewsByHour": { - "post": { + "get": { "tags": [ "Stats" ], @@ -3634,16 +3620,9 @@ "type": "string" }, { - "name": "body", - "in": "body", - "schema": { - "type": "object", - "properties": { - "days": { - "example": "any" - } - } - } + "name": "days", + "in": "query", + "type": "string" } ], "responses": {