feat(DailyCheckbox): associate checkboxes with users and enhance daily view functionality
- Added userId field to DailyCheckbox model for user association. - Updated DailyService methods to handle user-specific checkbox retrieval and management. - Integrated user authentication checks in API routes and actions for secure access to daily data. - Enhanced DailyPage to display user-specific daily views, ensuring proper session handling. - Updated client and service interfaces to reflect changes in data structure.
This commit is contained in:
@@ -6,12 +6,19 @@ import {
|
||||
isValidAPIDate,
|
||||
createDateFromParts,
|
||||
} from '@/lib/date-utils';
|
||||
import { getServerSession } from 'next-auth/next';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
/**
|
||||
* API route pour récupérer la vue daily (hier + aujourd'hui)
|
||||
*/
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: 'Non authentifié' }, { status: 401 });
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
|
||||
const action = searchParams.get('action');
|
||||
@@ -20,7 +27,10 @@ export async function GET(request: Request) {
|
||||
if (action === 'history') {
|
||||
// Récupérer l'historique
|
||||
const limit = parseInt(searchParams.get('limit') || '30');
|
||||
const history = await dailyService.getCheckboxHistory(limit);
|
||||
const history = await dailyService.getCheckboxHistory(
|
||||
session.user.id,
|
||||
limit
|
||||
);
|
||||
return NextResponse.json(history);
|
||||
}
|
||||
|
||||
@@ -55,7 +65,10 @@ export async function GET(request: Request) {
|
||||
targetDate = getToday();
|
||||
}
|
||||
|
||||
const dailyView = await dailyService.getDailyView(targetDate);
|
||||
const dailyView = await dailyService.getDailyView(
|
||||
targetDate,
|
||||
session.user.id
|
||||
);
|
||||
return NextResponse.json(dailyView);
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de la récupération du daily:', error);
|
||||
@@ -71,6 +84,10 @@ export async function GET(request: Request) {
|
||||
*/
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: 'Non authentifié' }, { status: 401 });
|
||||
}
|
||||
const body = await request.json();
|
||||
|
||||
// Validation des données
|
||||
@@ -100,6 +117,7 @@ export async function POST(request: Request) {
|
||||
|
||||
const checkbox = await dailyService.addCheckbox({
|
||||
date,
|
||||
userId: session.user.id,
|
||||
text: body.text,
|
||||
type: body.type,
|
||||
taskId: body.taskId,
|
||||
|
||||
Reference in New Issue
Block a user