diff --git a/script.js b/script.js index 7164e93..04e901d 100644 --- a/script.js +++ b/script.js @@ -433,11 +433,12 @@ class FileManager { // localStorage 폴백 메서드들 addFileLocally(fileData) { - // 로컬 저장시에도 올바른 컬럼명 사용 + // 로컬 저장용 데이터 생성 (ID와 타임스탬프 추가) const localFileData = { + id: this.generateId(), ...fileData, - created_at: fileData.created_at || new Date().toISOString(), - updated_at: fileData.updated_at || new Date().toISOString() + created_at: new Date().toISOString(), + updated_at: new Date().toISOString() }; this.files.push(localFileData); @@ -445,6 +446,7 @@ class FileManager { this.renderFiles(); this.updateEmptyState(); this.showNotification('새 자료가 성공적으로 추가되었습니다! (로컬 저장)', 'success'); + this.clearForm(); // 폼 초기화 } updateFileLocally(id, updates) { @@ -635,14 +637,11 @@ class FileManager { } const fileData = { - id: this.generateId(), title, description, category, tags, - files: [], - created_at: new Date().toISOString(), - updated_at: new Date().toISOString() + files: [] // 첨부파일 임시 저장용 (Supabase 전송시 제외됨) }; if (fileInput.files.length > 0) { diff --git a/supabase-config.js b/supabase-config.js index 5fb5000..a1058cf 100644 --- a/supabase-config.js +++ b/supabase-config.js @@ -122,12 +122,19 @@ const SupabaseHelper = { async addFile(fileData, userId) { if (!supabase) throw new Error('Supabase가 초기화되지 않았습니다.'); + // 데이터베이스 스키마에 맞는 필드만 추출 + const dbFileData = { + title: fileData.title, + description: fileData.description || '', + category: fileData.category, + tags: fileData.tags || [], + user_id: userId + // created_at, updated_at은 데이터베이스에서 자동 생성 + }; + const { data, error } = await supabase .from('files') - .insert([{ - ...fileData, - user_id: userId - }]) + .insert([dbFileData]) .select() .single(); @@ -139,12 +146,18 @@ const SupabaseHelper = { async updateFile(id, updates, userId) { if (!supabase) throw new Error('Supabase가 초기화되지 않았습니다.'); + // 데이터베이스 스키마에 맞는 필드만 추출 + const dbUpdates = { + title: updates.title, + description: updates.description, + category: updates.category, + tags: updates.tags || [] + // updated_at은 트리거에 의해 자동 업데이트됨 + }; + const { data, error } = await supabase .from('files') - .update({ - ...updates, - updated_at: new Date().toISOString() - }) + .update(dbUpdates) .eq('id', id) .eq('user_id', userId) .select()