Skip to content

Commit b34feaa

Browse files
committed
fix periodic filter range bug
1 parent fde0776 commit b34feaa

File tree

12 files changed

+45
-47
lines changed

12 files changed

+45
-47
lines changed

backend/app/api/routes.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_news(
3838
Query params:
3939
- page: Page number (default: 1)
4040
- limit: Items per page (default: 12, max: 500)
41-
- period: Time filter ("24h", "7d", "30d", "all")
41+
- period: Time filter ("48h", "7d", "30d", "all")
4242
- sentiment: Filter by sentiment ("positive", "neutral", "negative")
4343
- search: Search query (searches title and content)
4444
"""
@@ -67,8 +67,8 @@ def get_news(
6767
# Apply period filter
6868
if period:
6969
now = datetime.now(timezone.utc)
70-
if period == "24h":
71-
cutoff = now - timedelta(hours=24)
70+
if period == "48h":
71+
cutoff = now - timedelta(hours=48)
7272
query = query.filter(News.published_at >= cutoff)
7373
elif period == "7d":
7474
cutoff = now - timedelta(days=7)
@@ -80,7 +80,7 @@ def get_news(
8080
# No filter for "all"
8181
pass
8282
else:
83-
raise HTTPException(400, "Invalid period. Use: 24h, 7d, 30d, or all")
83+
raise HTTPException(400, "Invalid period. Use: 48h, 7d, 30d, or all")
8484

8585
# Sentiment filter (p/n/neutral)
8686
if sentiment:
@@ -104,8 +104,8 @@ def get_news(
104104

105105
total_query = db.query(News)
106106
if period and period != "all":
107-
if period == "24h":
108-
cutoff = now - timedelta(hours=24)
107+
if period == "48h":
108+
cutoff = now - timedelta(hours=48)
109109
elif period == "7d":
110110
cutoff = now - timedelta(days=7)
111111
elif period == "30d":
@@ -180,15 +180,15 @@ def refresh_news(db: Session = Depends(get_db), redis = Depends(get_redis)):
180180

181181
@router.get("/api/sentiment/aggregate")
182182
def get_market_sentiment(
183-
period: str = "24h", # "24h", "7d", "30d", "all"
183+
period: str = "48h", # "48h", "7d", "30d", "all"
184184
db: Session = Depends(get_db),
185185
redis = Depends(get_redis)
186186
):
187187
"""
188188
Get overall market sentiment for specified period.
189189
190190
Query params:
191-
- period: "24h" (default), "7d", "30d", "all"
191+
- period: "48h" (default), "7d", "30d", "all"
192192
193193
Returns:
194194
- Distribution: % positive/neutral/negative
@@ -211,16 +211,16 @@ def get_market_sentiment(
211211
# Calculate cutoff based on period
212212
now = datetime.now(timezone.utc)
213213

214-
if period == "24h":
215-
cutoff = now - timedelta(hours=24)
214+
if period == "48h":
215+
cutoff = now - timedelta(hours=48)
216216
elif period == "7d":
217217
cutoff = now - timedelta(days=7)
218218
elif period == "30d":
219219
cutoff = now - timedelta(days=30)
220220
elif period == "all":
221221
cutoff = None
222222
else:
223-
raise HTTPException(400, "Invalid period. Use: 24h, 7d, 30d, or all")
223+
raise HTTPException(400, "Invalid period. Use: 48h, 7d, 30d, or all")
224224

225225
# Query with optional date filter
226226
query = db.query(
@@ -294,12 +294,12 @@ def get_market_sentiment(
294294

295295

296296
@router.get('/api/coins/sentiment')
297-
def get_coins_sentiment(period:str = "24h",
297+
def get_coins_sentiment(period:str = "48h",
298298
db: Session = Depends(get_db),
299299
redis = Depends(get_redis),
300300
):
301301
'''API buat ngereturn top 5 bullish dan bearish coins
302-
Params: period (24h and 7d)
302+
Params: period (48h and 7d)
303303
304304
Response:
305305
- ticker
@@ -323,16 +323,16 @@ def get_coins_sentiment(period:str = "24h",
323323
# Calculate cutoff based on period
324324
now = datetime.now(timezone.utc)
325325

326-
if period == "24h":
327-
cutoff = now - timedelta(hours=24)
326+
if period == "48h":
327+
cutoff = now - timedelta(hours=48)
328328
elif period == "7d":
329329
cutoff = now - timedelta(days=7)
330330
elif period == "30d":
331331
cutoff = now - timedelta(days=30)
332332
elif period == "all":
333333
cutoff = None
334334
else:
335-
raise HTTPException(400, "Invalid period. Use: 24h, 7d, 30d, or all")
335+
raise HTTPException(400, "Invalid period. Use: 48h, 7d, 30d, or all")
336336

337337
query = db.query(
338338
Coin.symbol,
@@ -420,16 +420,16 @@ def get_coins_bubble(period: str = "all",
420420
# Calculate cutoff based on period
421421
now = datetime.now(timezone.utc)
422422

423-
if period == "24h":
424-
cutoff = now - timedelta(hours=24)
423+
if period == "48h":
424+
cutoff = now - timedelta(hours=48)
425425
elif period == "7d":
426426
cutoff = now - timedelta(days=7)
427427
elif period == "30d":
428428
cutoff = now - timedelta(days=30)
429429
elif period == "all":
430430
cutoff = None
431431
else:
432-
raise HTTPException(400, "Invalid period. Use: 24h, 7d, 30d, or all")
432+
raise HTTPException(400, "Invalid period. Use: 48h, 7d, 30d, or all")
433433

434434
query = db.query(
435435
Coin.symbol,

frontend/src/app/news/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default function NewsPage() {
4747
<PeriodFilter
4848
activePeriod={period}
4949
onPeriodChange={setPeriod}
50-
periods={["all", "30d", "7d", "24h"]}
50+
periods={["all", "30d", "7d", "48h"]}
5151
centered
5252
/>
5353
</div>
@@ -64,12 +64,12 @@ export default function NewsPage() {
6464
/>
6565
</div>
6666

67-
<div className="flex justify-center flex-wrap gap-2">
67+
<div className="flex justify-center sm:justify-start flex-wrap gap-2">
6868
{["all", "positive", "neutral", "negative"].map((s) => (
6969
<button
7070
key={s}
7171
onClick={() => setSentiment(s === "all" ? undefined : s)}
72-
className={`px-3 sm:px-4 py-2 rounded-lg text-xs sm:text-sm font-medium transition-all ${
72+
className={`px-2 sm:px-3 py-1.5 sm:py-2 rounded-lg text-xs sm:text-sm font-medium transition-all ${
7373
(s === "all" && !sentiment) || sentiment === s
7474
? "bg-[#02D5E9]/80 text-white"
7575
: "bg-white/5 text-gray-400 hover:text-white hover:bg-white/10"

frontend/src/components/charts/BubbleChart.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ export function BubbleChart() {
311311
return (
312312
<>
313313
<GlassCard>
314-
<div className="flex flex-col items-center gap-4 mb-4">
315-
<div className="text-center">
314+
<div className="flex flex-col items-center sm:flex-row sm:items-center sm:justify-between gap-4 mb-4">
315+
<div className="text-center sm:text-left">
316316
<h3 className="text-lg font-semibold text-white">
317317
News Sentiment Bubbles
318318
</h3>
@@ -326,8 +326,7 @@ export function BubbleChart() {
326326
<PeriodFilter
327327
activePeriod={period}
328328
onPeriodChange={setPeriod}
329-
periods={["all", "30d", "7d", "24h"]}
330-
centered
329+
periods={["all", "30d", "7d", "48h"]}
331330
/>
332331
</div>
333332

frontend/src/components/dashboard/Leaderboards.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ export function Leaderboards() {
135135
<GlassCard>
136136
<div
137137
id="leaderboard"
138-
className="flex flex-col items-center gap-4 mb-6"
138+
className="flex flex-col items-center sm:flex-row sm:items-center sm:justify-between gap-4 mb-6"
139139
>
140-
<div className="text-center">
140+
<div className="text-center sm:text-left">
141141
<h3 className="text-lg font-semibold text-[hsl(210,40%,98%)]">
142142
Leaderboards
143143
</h3>
@@ -151,7 +151,7 @@ export function Leaderboards() {
151151
<PeriodFilter
152152
activePeriod={period}
153153
onPeriodChange={setPeriod}
154-
periods={["all", "30d", "7d", "24h"]}
154+
periods={["all", "30d", "7d", "48h"]}
155155
/>
156156
</div>
157157

frontend/src/components/layout/PeriodFilter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface PeriodFilterProps {
1010
export function PeriodFilter({
1111
activePeriod,
1212
onPeriodChange,
13-
periods = ["24h", "7d", "30d", "all"],
13+
periods = ["48h", "7d", "30d", "all"],
1414
centered = false,
1515
}: PeriodFilterProps) {
1616
return (

frontend/src/components/news/NewsFeed.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ export function NewsFeed() {
3030
return (
3131
<GlassCard>
3232
<div className="space-y-4 mb-6">
33-
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
33+
<div className="flex flex-col items-center sm:flex-row sm:items-center sm:justify-between gap-4">
3434
<div className="text-center sm:text-left">
35-
<h3 className="text-lg font-semibold text-white">
35+
<h3 className="text-lg sm:text-base font-semibold text-white">
3636
Latest Crypto News
3737
</h3>
38-
<p className="text-sm text-gray-400">
38+
<p className="text-xs sm:text-sm text-gray-400">
3939
Aggregated from top sources with AI sentiment analysis
4040
</p>
4141
</div>
4242
<PeriodFilter
4343
activePeriod={period}
4444
onPeriodChange={setPeriod}
45-
periods={["all", "30d", "7d", "24h"]}
45+
periods={["all", "30d", "7d", "48h"]}
4646
/>
4747
</div>
4848

@@ -58,12 +58,12 @@ export function NewsFeed() {
5858
/>
5959
</div>
6060

61-
<div className="inline-flex flex-wrap justify-center gap-2">
61+
<div className="inline-flex flex-wrap justify-center sm:justify-start gap-2">
6262
{["all", "positive", "neutral", "negative"].map((s) => (
6363
<button
6464
key={s}
6565
onClick={() => setSentiment(s === "all" ? undefined : s)}
66-
className={`px-4 py-2 rounded-lg text-sm font-medium transition-all ${
66+
className={`px-2.5 sm:px-3 py-1.5 sm:py-2 rounded-lg text-xs sm:text-sm font-medium transition-all ${
6767
(s === "all" && !sentiment) || sentiment === s
6868
? "bg-[#02D5E9]/80 text-white"
6969
: "bg-white/5 text-gray-400 hover:text-white hover:bg-white/10"

frontend/src/components/sentiment/SentimentHistory.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ export function SentimentHistory() {
116116

117117
return (
118118
<GlassCard>
119-
<div className="flex flex-col items-center gap-4 mb-6">
120-
<div className="text-center">
119+
<div className="flex flex-col items-center sm:flex-row sm:items-center sm:justify-between gap-4 mb-6">
120+
<div className="text-center sm:text-left">
121121
<h3 className="text-lg font-semibold text-white">
122122
Sentiment History
123123
</h3>
@@ -128,7 +128,6 @@ export function SentimentHistory() {
128128
activePeriod={period}
129129
onPeriodChange={setPeriod}
130130
periods={["all", "30d", "7d", "24h"]}
131-
centered
132131
/>
133132
</div>
134133

frontend/src/hooks/useCoinBubble.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useQuery } from "@tanstack/react-query";
22
import { fetchCoinBubble } from "@/lib/api";
33

4-
export function useCoinBubble(period: string = "24h") {
4+
export function useCoinBubble(period: string = "48h") {
55
return useQuery({
66
queryKey: ["coinBubble", period],
77
queryFn: () => fetchCoinBubble(period),

frontend/src/hooks/useCoinSentiment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { fetchCoinSentiment } from "@/lib/api";
33

44
/**
55
* Custom hook to fetch coin sentiment data
6-
* @param period - Time period filter ("24h", "7d", "30d", "all")
6+
* @param period - Time period filter ("48h", "7d", "30d", "all")
77
* @returns { data, isLoading, error } - React Query result
88
*/
9-
export function useCoinSentiment(period: string = "24h") {
9+
export function useCoinSentiment(period: string = "48h") {
1010
return useQuery({
1111
queryKey: ["coinSentiment", period], // Cache key (unique per period)
1212
queryFn: () => fetchCoinSentiment(period),

frontend/src/hooks/useSentiment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useQuery } from "@tanstack/react-query";
22
import { fetchSentiment } from "@/lib/api";
33
import type { Period } from "@/types/sentiment";
44

5-
export function useSentiment(period: Period = "24h") {
5+
export function useSentiment(period: Period = "48h") {
66
return useQuery({
77
queryKey: ["sentiment", period],
88
queryFn: () => fetchSentiment(period),

0 commit comments

Comments
 (0)