'기술', 'items' => array_map(fn($s) => $s['name'] ?? '', $profile['skills']) ] ]; $profile['skills'] = $migrated; } return $profile; } // ===================================================== // GET: 프로필 조회 (인증 불필요) // ===================================================== if ($method === 'GET') { $profile = read_json_safe(PROFILE_FILE); if ($profile === null) { json_response(['error' => '프로필을 읽을 수 없습니다'], 500); } $profile = migrate_skills($profile); json_response($profile); } // 이하 수정은 인증 필요 require_auth(); // ===================================================== // PUT: 프로필 전체 업데이트 // ===================================================== if ($method === 'PUT') { $input = get_json_input(); if (!is_array($input)) { json_response(['error' => '잘못된 데이터 형식'], 400); } $current = read_json_safe(PROFILE_FILE) ?? []; $updated = array_merge($current, [ 'name' => trim($input['name'] ?? $current['name'] ?? ''), 'title' => trim($input['title'] ?? $current['title'] ?? ''), 'tagline' => trim($input['tagline'] ?? $current['tagline'] ?? ''), 'avatar' => trim($input['avatar'] ?? $current['avatar'] ?? ''), 'bio' => trim($input['bio'] ?? $current['bio'] ?? ''), 'location' => trim($input['location'] ?? $current['location'] ?? ''), 'email' => trim($input['email'] ?? $current['email'] ?? ''), ]); // 카테고리화된 스킬 처리 if (isset($input['skills']) && is_array($input['skills'])) { $cleanSkills = []; foreach ($input['skills'] as $cat) { if (!isset($cat['category']) || !isset($cat['items'])) continue; $catName = trim($cat['category']); if ($catName === '') continue; $items = is_array($cat['items']) ? array_values(array_filter(array_map('trim', $cat['items']), fn($v) => $v !== '')) : []; if (count($items) > 0) { $cleanSkills[] = [ 'category' => $catName, 'items' => $items ]; } } $updated['skills'] = $cleanSkills; } if (isset($input['timeline']) && is_array($input['timeline'])) { $updated['timeline'] = array_values(array_filter($input['timeline'], function($t) { return !empty($t['title']); })); } if (isset($input['social']) && is_array($input['social'])) { $updated['social'] = array_merge($current['social'] ?? [], $input['social']); } if (write_json_safe(PROFILE_FILE, $updated)) { json_response(['success' => true, 'profile' => $updated]); } else { json_response(['error' => '저장에 실패했습니다'], 500); } } json_response(['error' => 'Method not allowed'], 405);