文档
简历管理 API
SmartCV 简历管理 API 文档,包含简历的创建、编辑、删除、导出等功能
更新时间: 2024/12/30
SmartCV 简历管理 API 提供完整的简历 CRUD 操作,支持简历创建、编辑、删除、导出、分享等功能。
📋 API 端点概览
端点 | 方法 | 描述 |
---|---|---|
/api/resumes | GET | 获取用户简历列表 |
/api/resumes | POST | 创建新简历 |
/api/resumes/[id] | GET | 获取指定简历详情 |
/api/resumes/[id] | PUT | 更新简历信息 |
/api/resumes/[id] | DELETE | 删除简历 |
/api/resumes/[id]/export | POST | 导出简历 |
/api/resumes/[id]/share | POST | 创建分享链接 |
/api/resumes/[id]/share | PUT | 更新分享设置 |
/api/resumes/[id]/projects | GET | 获取简历项目经历 |
/api/resumes/[id]/projects | POST | 添加项目经历 |
🔍 获取简历列表
端点: GET /api/resumes
描述: 获取当前用户的所有简历列表
认证: 需要登录
查询参数:
page
(可选): 页码,默认为 1limit
(可选): 每页数量,默认为 10status
(可选): 筛选状态 (DRAFT
,PUBLISHED
,ARCHIVED
)
响应:
{
"success": true,
"data": [
{
"id": "resume_123",
"title": "软件工程师简历",
"status": "DRAFT",
"templateId": "template_456",
"template": {
"id": "template_456",
"name": "现代简约",
"category": "MODERN"
},
"atsScore": 85,
"keywordMatchScore": 78,
"createdAt": "2024-12-30T10:00:00Z",
"updatedAt": "2024-12-30T15:00:00Z",
"shareInfo": {
"isEnabled": true,
"viewCount": 12,
"hasPassword": false,
"lastViewedAt": "2024-12-30T14:00:00Z"
}
}
],
"meta": {
"total": 5,
"page": 1,
"limit": 10,
"totalPages": 1
}
}
➕ 创建简历
端点: POST /api/resumes
描述: 创建新的简历
认证: 需要登录
请求体:
{
"title": "软件工程师简历",
"templateId": "template_456",
"contentJson": {
"personalInfo": {
"name": "张三",
"email": "[email protected]",
"phone": "13800138000",
"address": "北京市朝阳区",
"summary": "5年软件开发经验..."
},
"workExperience": [
{
"company": "ABC科技公司",
"position": "高级软件工程师",
"startDate": "2021-01",
"endDate": "2024-12",
"description": "负责核心产品开发..."
}
],
"education": [
{
"school": "北京大学",
"degree": "计算机科学与技术",
"startDate": "2017-09",
"endDate": "2021-06"
}
],
"skills": ["JavaScript", "React", "Node.js", "Python"],
"projects": [
{
"name": "电商平台",
"description": "使用React和Node.js开发的电商平台",
"technologies": ["React", "Node.js", "MongoDB"],
"url": "https://github.com/example/ecommerce"
}
]
}
}
响应:
{
"success": true,
"data": {
"id": "resume_123",
"title": "软件工程师简历",
"status": "DRAFT",
"templateId": "template_456",
"template": {
"id": "template_456",
"name": "现代简约",
"category": "MODERN"
},
"contentJson": {
/* 完整的简历内容 */
},
"createdAt": "2024-12-30T10:00:00Z",
"updatedAt": "2024-12-30T10:00:00Z"
}
}
📄 获取简历详情
端点: GET /api/resumes/[id]
描述: 获取指定简历的详细信息
认证: 需要登录
路径参数:
id
: 简历 ID
响应:
{
"success": true,
"data": {
"id": "resume_123",
"title": "软件工程师简历",
"status": "DRAFT",
"templateId": "template_456",
"template": {
"id": "template_456",
"name": "现代简约",
"category": "MODERN",
"htmlTemplate": "...",
"cssStyles": "..."
},
"contentJson": {
"personalInfo": {
/* 个人信息 */
},
"workExperience": [
/* 工作经历 */
],
"education": [
/* 教育背景 */
],
"skills": [
/* 技能列表 */
],
"projects": [
/* 项目经历 */
]
},
"sectionsVisibility": {
"personalInfo": true,
"workExperience": true,
"education": true,
"skills": true,
"projects": true
},
"atsScore": 85,
"keywordMatchScore": 78,
"targetJobDescription": "...",
"createdAt": "2024-12-30T10:00:00Z",
"updatedAt": "2024-12-30T15:00:00Z"
}
}
✏️ 更新简历
端点: PUT /api/resumes/[id]
描述: 更新简历信息
认证: 需要登录
路径参数:
id
: 简历 ID
请求体:
{
"title": "新的简历标题",
"templateId": "template_789",
"contentJson": {
/* 更新的简历内容 */
},
"sectionsVisibility": {
"personalInfo": true,
"workExperience": true,
"education": false,
"skills": true,
"projects": true
},
"status": "PUBLISHED"
}
响应:
{
"success": true,
"data": {
/* 更新后的简历信息 */
}
}
🗑️ 删除简历
端点: DELETE /api/resumes/[id]
描述: 删除指定简历(软删除)
认证: 需要登录
路径参数:
id
: 简历 ID
响应:
{
"success": true,
"message": "简历删除成功"
}
📤 导出简历
端点: POST /api/resumes/[id]/export
描述: 导出简历为指定格式
认证: 需要登录
路径参数:
id
: 简历 ID
请求体:
{
"format": "pdf",
"options": {
"pageSize": "A4",
"margin": "normal",
"includePhoto": true,
"colorScheme": "default"
}
}
响应:
{
"success": true,
"data": {
"downloadUrl": "https://storage.smartcv.cc/exports/resume_123.pdf",
"filename": "张三_软件工程师简历.pdf",
"format": "pdf",
"fileSize": 1024000,
"expiresAt": "2024-12-31T10:00:00Z"
}
}
支持的导出格式:
pdf
: PDF 文档docx
: Word 文档html
: HTML 网页txt
: 纯文本
🔗 创建分享链接
端点: POST /api/resumes/[id]/share
描述: 为简历创建分享链接
认证: 需要登录
路径参数:
id
: 简历 ID
请求体:
{
"isEnabled": true,
"password": "optional-password",
"expiresAt": "2025-01-30T10:00:00Z",
"allowDownload": true,
"allowComments": false
}
响应:
{
"success": true,
"data": {
"id": "share_123",
"token": "abc123def456",
"shareUrl": "https://smartcv.cc/share/abc123def456",
"isEnabled": true,
"hasPassword": true,
"allowDownload": true,
"allowComments": false,
"viewCount": 0,
"expiresAt": "2025-01-30T10:00:00Z",
"createdAt": "2024-12-30T10:00:00Z"
}
}
🔄 更新分享设置
端点: PUT /api/resumes/[id]/share
描述: 更新简历分享设置
认证: 需要登录
路径参数:
id
: 简历 ID
请求体:
{
"isEnabled": false,
"password": null,
"expiresAt": null,
"allowDownload": false,
"allowComments": true
}
响应:
{
"success": true,
"data": {
/* 更新后的分享设置 */
}
}
📊 获取项目经历
端点: GET /api/resumes/[id]/projects
描述: 获取简历的项目经历列表
认证: 需要登录
路径参数:
id
: 简历 ID
响应:
{
"success": true,
"data": [
{
"id": "project_123",
"name": "电商平台",
"description": "使用React和Node.js开发的电商平台",
"technologies": ["React", "Node.js", "MongoDB"],
"url": "https://github.com/example/ecommerce",
"startDate": "2023-01",
"endDate": "2023-12",
"highlights": ["实现了用户认证和授权系统", "设计了高效的数据库架构", "优化了前端性能,提升了50%的加载速度"]
}
]
}
➕ 添加项目经历
端点: POST /api/resumes/[id]/projects
描述: 为简历添加新的项目经历
认证: 需要登录
路径参数:
id
: 简历 ID
请求体:
{
"name": "新项目",
"description": "项目描述",
"technologies": ["技术栈"],
"url": "https://github.com/example/project",
"startDate": "2024-01",
"endDate": "2024-12",
"highlights": ["主要成就1", "主要成就2"]
}
响应:
{
"success": true,
"data": {
"id": "project_124"
/* 新创建的项目信息 */
}
}
📝 使用示例
JavaScript 示例
// 获取简历列表
async function getResumes() {
const response = await fetch('/api/resumes', {
credentials: 'include'
})
const data = await response.json()
return data.data
}
// 创建新简历
async function createResume(resumeData) {
const response = await fetch('/api/resumes', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
credentials: 'include',
body: JSON.stringify(resumeData)
})
const data = await response.json()
if (data.success) {
console.log('简历创建成功:', data.data)
} else {
console.error('创建失败:', data.error)
}
}
// 更新简历
async function updateResume(resumeId, updates) {
const response = await fetch(`/api/resumes/${resumeId}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
credentials: 'include',
body: JSON.stringify(updates)
})
return response.json()
}
// 导出简历
async function exportResume(resumeId, format = 'pdf') {
const response = await fetch(`/api/resumes/${resumeId}/export`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
credentials: 'include',
body: JSON.stringify({
format,
options: {
pageSize: 'A4',
margin: 'normal'
}
})
})
const data = await response.json()
if (data.success) {
// 下载文件
window.open(data.data.downloadUrl, '_blank')
}
}
// 创建分享链接
async function createShareLink(resumeId, settings) {
const response = await fetch(`/api/resumes/${resumeId}/share`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
credentials: 'include',
body: JSON.stringify(settings)
})
const data = await response.json()
if (data.success) {
return data.data.shareUrl
}
}
React Hook 示例
import { useState, useEffect } from 'react'
function useResumes() {
const [resumes, setResumes] = useState([])
const [loading, setLoading] = useState(true)
const [error, setError] = useState(null)
useEffect(() => {
fetchResumes()
}, [])
const fetchResumes = async () => {
try {
setLoading(true)
const response = await fetch('/api/resumes', {
credentials: 'include'
})
const data = await response.json()
if (data.success) {
setResumes(data.data)
} else {
setError(data.error)
}
} catch (err) {
setError('获取简历列表失败')
} finally {
setLoading(false)
}
}
const createResume = async (resumeData) => {
try {
const response = await fetch('/api/resumes', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
credentials: 'include',
body: JSON.stringify(resumeData)
})
const data = await response.json()
if (data.success) {
setResumes((prev) => [data.data, ...prev])
return data.data
} else {
throw new Error(data.error)
}
} catch (err) {
setError(err.message)
throw err
}
}
const deleteResume = async (resumeId) => {
try {
const response = await fetch(`/api/resumes/${resumeId}`, {
method: 'DELETE',
credentials: 'include'
})
const data = await response.json()
if (data.success) {
setResumes((prev) => prev.filter((r) => r.id !== resumeId))
} else {
throw new Error(data.error)
}
} catch (err) {
setError(err.message)
throw err
}
}
return {
resumes,
loading,
error,
createResume,
deleteResume,
refetch: fetchResumes
}
}
❌ 错误处理
常见错误码
错误码 | HTTP 状态 | 描述 |
---|---|---|
RESUME_NOT_FOUND | 404 | 简历不存在 |
RESUME_NOT_OWNED | 403 | 无权访问此简历 |
INVALID_TEMPLATE | 400 | 模板不存在或无效 |
CONTENT_TOO_LARGE | 413 | 简历内容过大 |
EXPORT_FAILED | 500 | 导出失败 |
SHARE_LIMIT_EXCEEDED | 429 | 分享次数超限 |
错误响应示例
{
"error": "简历不存在或已被删除",
"code": "RESUME_NOT_FOUND",
"details": {
"resumeId": "resume_123"
}
}
下一步
🎨 模板系统
了解如何使用模板 API 管理简历模板
🤖 AI 服务
学习如何使用 AI 分析和优化功能