diff --git a/.env b/.env
index c58a6e2b..89dca287 100644
--- a/.env
+++ b/.env
@@ -45,4 +45,6 @@ NEXT_PUBLIC_IFRAME_AI_ASSISTANT_URL=https://alma.slm-lab.net
ROCKET_CHAT_TOKEN=w91TYgkH-Z67Oz72usYdkW5TZLLRwnre7qyAhp7aHJB
ROCKET_CHAT_USER_ID=Tpuww59PJKsrGNQJB
LEANTIME_TOKEN=lt_lsdShQdoYHaPUWuL07XZR1Rf3GeySsIs_UDlll3VJPk5EwAuILpMC4BwzJ9MZFRrb
-LEANTIME_API_URL=https://agilite.slm-lab.net
\ No newline at end of file
+LEANTIME_API_URL=https://agilite.slm-lab.net
+
+NEWSDB_URL=postgresql://alma:Sict33711###@cube.governance-labs.com/rivacube
\ No newline at end of file
diff --git a/app/api/news/route.ts b/app/api/news/route.ts
new file mode 100644
index 00000000..f4f4ef5c
--- /dev/null
+++ b/app/api/news/route.ts
@@ -0,0 +1,30 @@
+import { NextResponse } from 'next/server';
+import { prisma } from '@/lib/prisma';
+
+export async function GET() {
+ try {
+ const news = await prisma.news.findMany({
+ orderBy: {
+ date: 'desc'
+ },
+ take: 5,
+ select: {
+ id: true,
+ title: true,
+ date: true,
+ source: true,
+ description: true,
+ category: true,
+ url: true
+ }
+ });
+
+ return NextResponse.json(news);
+ } catch (error) {
+ console.error('Error fetching news:', error);
+ return NextResponse.json(
+ { error: 'Failed to fetch news' },
+ { status: 500 }
+ );
+ }
+}
\ No newline at end of file
diff --git a/components/news.tsx b/components/news.tsx
index e51ef7b5..cbb7d8ea 100644
--- a/components/news.tsx
+++ b/components/news.tsx
@@ -5,12 +5,17 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { RefreshCw } from "lucide-react";
import { useSession } from "next-auth/react";
+import { formatDistance } from 'date-fns';
+import { fr } from 'date-fns/locale';
interface NewsItem {
- id: string;
+ id: number;
title: string;
date: string;
- category: string;
+ source: string;
+ description: string | null;
+ category: string | null;
+ url: string;
}
export function News() {
@@ -22,19 +27,16 @@ export function News() {
const fetchNews = async (isRefresh = false) => {
if (isRefresh) setRefreshing(true);
- setLoading(true);
-
- // Placeholder data - replace with actual API call
- const mockNews = [
- { id: '1', title: 'New Project Management Features Released', date: '2024-03-20', category: 'Product Update' },
- { id: '2', title: 'Team Meeting Schedule Changes', date: '2024-03-19', category: 'Announcement' },
- { id: '3', title: 'Upcoming Training Sessions', date: '2024-03-18', category: 'Training' },
- ];
+ if (!isRefresh) setLoading(true);
try {
- // Simulate API call
- await new Promise(resolve => setTimeout(resolve, 1000));
- setNews(mockNews);
+ const response = await fetch('/api/news');
+ if (!response.ok) {
+ throw new Error('Failed to fetch news');
+ }
+
+ const data = await response.json();
+ setNews(data);
setError(null);
} catch (err) {
setError('Failed to fetch news');
@@ -51,6 +53,19 @@ export function News() {
}
}, [status]);
+ const formatDate = (dateString: string) => {
+ try {
+ const date = new Date(dateString);
+ return formatDistance(date, new Date(), {
+ addSuffix: true,
+ locale: fr
+ });
+ } catch (err) {
+ console.error('Error formatting date:', err);
+ return dateString;
+ }
+ };
+
if (status === 'loading' || loading) {
return (
Loading...
+ {item.description} +
+ )}