From 478b206be9b7095f58d56d22cf4fa0a74f6fb9d4 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 21 Dec 2025 16:50:56 +0000 Subject: [PATCH] feat: highlight notes created via API with red background - Add created_via column to notes table (values: 'web' or 'api') - Mark notes created via POST /api/notes/full as 'api' - Display light red background for API-created notes in dashboard - Add "API" badge with lightning icon for visual identification --- config/database.js | 11 +++++++++++ routes/notes.routes.js | 9 +++++---- src/pages/Index.tsx | 8 +++++++- src/services/NotesService.ts | 1 + 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/config/database.js b/config/database.js index f5749d9..e1d55f6 100644 --- a/config/database.js +++ b/config/database.js @@ -123,11 +123,22 @@ async function initDatabase() { archived BOOLEAN DEFAULT FALSE, archived_at TIMESTAMP, priority INTEGER DEFAULT 0, + created_via VARCHAR(20) DEFAULT 'web', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) `); + // Migration: ajouter la colonne created_via si elle n'existe pas + await client.query(` + DO $$ + BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'notes' AND column_name = 'created_via') THEN + ALTER TABLE notes ADD COLUMN created_via VARCHAR(20) DEFAULT 'web'; + END IF; + END $$; + `); + // Table note_todos await client.query(` CREATE TABLE IF NOT EXISTS note_todos ( diff --git a/routes/notes.routes.js b/routes/notes.routes.js index f24a084..b5cfd33 100644 --- a/routes/notes.routes.js +++ b/routes/notes.routes.js @@ -74,7 +74,7 @@ router.get('/', async (req, res) => { const notes = await getAll(` SELECT n.id, n.title, n.content, n.image_filename, n.archived, n.priority, - n.created_at, n.updated_at, + n.created_via, n.created_at, n.updated_at, (SELECT COUNT(*) FROM note_todos WHERE note_id = n.id) as todos_count, (SELECT COUNT(*) FROM note_todos WHERE note_id = n.id AND completed = TRUE) as todos_completed FROM notes n @@ -242,10 +242,10 @@ router.post('/full', logger.info(`[CREATE NOTE FULL] Début création - user_id: ${req.user.id}, title: "${title}", todos: ${todos.length}, tags: ${tags.length}`); - // 1. Créer la note + // 1. Créer la note (marquée comme créée via API) const noteResult = await runQuery(` - INSERT INTO notes (user_id, title, content) - VALUES ($1, $2, $3) + INSERT INTO notes (user_id, title, content, created_via) + VALUES ($1, $2, $3, 'api') RETURNING * `, [req.user.id, title, content || '']); @@ -325,6 +325,7 @@ router.post('/full', image_filename: null, archived: false, priority: 0, + created_via: 'api', todos: createdTodos, tags: createdTags, images: [], diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx index 4152632..dd7c2d2 100644 --- a/src/pages/Index.tsx +++ b/src/pages/Index.tsx @@ -1397,7 +1397,7 @@ const Index = () => { paginatedNotes.map(note => ( handleOpenNote(note)} > @@ -1451,6 +1451,12 @@ const Index = () => { {note.content ? cleanHtmlContent(note.content) : "Note vide"}

+ {note.created_via === 'api' && ( + + + API + + )} {note.todos && note.todos.length > 0 && ( diff --git a/src/services/NotesService.ts b/src/services/NotesService.ts index df8830e..6f2c7f6 100644 --- a/src/services/NotesService.ts +++ b/src/services/NotesService.ts @@ -29,6 +29,7 @@ export interface Note { title: string; content: string; archived?: boolean; + created_via?: 'web' | 'api'; created_at?: string; updated_at?: string; todos: Todo[];