基础路径:
/api认证方式:Bearer Token(JWT)
在线文档:启动服务后访问 http://localhost:8000/docs
POST /api/auth/register
请求体:
{
"email": "user@example.com",
"nickname": "用户名",
"password": "密码"
}响应:
{
"access_token": "eyJhbGciOiJIUzI1NiIs...",
"user_id": "uuid-string",
"nickname": "用户名"
}错误:
400— 该邮箱已注册
POST /api/auth/login
请求体:
{
"email": "user@example.com",
"password": "密码"
}响应: 同注册接口
错误:
401— 邮箱或密码错误
🔒 所有接口需要认证
POST /api/garments/upload
Content-Type: multipart/form-data
参数:
file(File) — 衣物图片(JPEG/PNG/WEBP,≤10MB)
响应:
{
"task_id": "uuid-string",
"status": "pending"
}处理流程: 异步执行抠图+打标,前端通过状态接口轮询。
GET /api/garments/status/{task_id}
响应:
{
"task_id": "uuid-string",
"status": "success",
"garment_id": "uuid-string",
"error": null
}状态值:
| 状态 | 说明 |
|---|---|
| pending | 等待处理 |
| processing | 处理中 |
| removing_bg | 抠图中 |
| tagging | AI 打标中 |
| saving | 保存中 |
| success | 成功 |
| failed | 失败 |
GET /api/garments
查询参数:
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| category | string | - | 分类筛选(上衣/下装/外套/鞋/配饰) |
| wardrobe_id | string | - | 衣橱 ID 筛选 |
| is_favorite | bool | - | 收藏筛选 |
| page | int | 1 | 页码 |
| page_size | int | 20 | 每页数量 |
响应:
{
"items": [
{
"id": "uuid",
"original_url": "/static/uploads/xxx.jpg",
"processed_url": "/static/uploads/xxx.png",
"category": "上衣",
"tags": {
"color": "白色",
"material": "棉",
"style": ["休闲"],
"season": ["春", "夏"],
"occasion": ["日常"]
},
"temp_min": -30,
"temp_max": 50,
"wear_count": 5,
"last_wear_date": "2024-06-15",
"is_favorite": true,
"created_at": "2024-01-01T00:00:00"
}
],
"total": 42,
"page": 1,
"page_size": 20
}GET /api/garments/{garment_id}
PUT /api/garments/{garment_id}
请求体:
{
"category": "上衣",
"tags": {
"color": "蓝色",
"material": "牛仔布",
"style": ["复古"],
"season": ["春", "秋"],
"occasion": ["日常"]
},
"temp_min": 10,
"temp_max": 30,
"wardrobe_id": "wardrobe-uuid"
}DELETE /api/garments/{garment_id}
PUT /api/garments/{garment_id}/favorite
响应:
{
"id": "uuid",
"is_favorite": true
}PUT /api/garments/{garment_id}/lifecycle
查询参数:
purchase_date— 购买日期(YYYY-MM-DD)purchase_price— 购买价格(元)
POST /api/outfits
请求体:
{
"date": "2024-06-15",
"garment_ids": ["id1", "id2", "id3"]
}说明: 同一天同一用户只保留一条记录(覆盖更新)。保存时自动更新衣物穿着次数。
GET /api/outfits/calendar?month=2024-06
响应:
{
"year": 2024,
"month": 6,
"days": [
{
"date": "2024-06-01",
"outfit": {
"id": "uuid",
"garment_ids": ["id1", "id2"],
"garments": [...],
"weather": "晴",
"temperature": 28
}
},
{
"date": "2024-06-02",
"outfit": null
}
]
}POST /api/outfits/{outfit_id}/illustration
响应:
{
"status": "success",
"illustration_url": "/static/illustrations/xxx.jpg"
}POST /api/recommend
请求体:
{
"date": "2024-06-15",
"occasion": "工作",
"extra_requirements": "需要正式一点"
}响应:
{
"date": "2024-06-15",
"weather": "晴",
"temperature": 28,
"selected_garments": [
{
"id": "uuid",
"category": "上衣",
"tags": { "color": "白色", "style": ["商务"] },
"processed_url": "/static/uploads/xxx.png",
"is_cold_palace": false
}
],
"reason": "今天晴朗28°C,适合穿白色衬衫搭配深色西裤...",
"is_fallback": false
}GET /api/ai/recommend?city=Beijing&occasion=日常
GET /api/ai/style-analysis
响应:
{
"total_garments": 42,
"main_style": "休闲",
"style_tags": [["休闲", 45.2], ["简约", 30.1], ...],
"top_categories": [["上衣", 15], ["裤子", 10], ...],
"top_colors": [["黑色", 8], ["白色", 6], ...],
"suggestions": ["您的主要风格是「休闲」,舒适自然,日常百搭"]
}GET /api/wardrobes
POST /api/wardrobes
请求体:
{
"name": "运动",
"icon": "🏃"
}PUT /api/wardrobes/{wardrobe_id}
DELETE /api/wardrobes/{wardrobe_id}
说明: 衣物自动移至默认衣橱,不允许删除最后一个衣橱。
POST /api/wardrobes/{wardrobe_id}/garments
DELETE /api/wardrobes/{wardrobe_id}/garments/{garment_id}
GET /api/packing
POST /api/packing
GET /api/packing/{packing_id}
PUT /api/packing/{packing_id}
DELETE /api/packing/{packing_id}
POST /api/packing/{packing_id}/auto-fill
说明: 根据旅行天数自动从衣橱中按天分配衣物(上衣+下装+鞋)。
GET /api/stats/summary
GET /api/stats/wardrobe
GET /api/stats/cold-palace?days=30
GET /api/stats/wear-ranking?limit=10
GET /api/stats/monthly
GET /api/stats/category-distribution
GET /api/stats/cost-per-wear
GET /api/stats/season-distribution
GET /api/stats/wear-trend
说明: 最近 30 天每日穿着次数。
GET /api/weather/current?city=Beijing
GET /api/weather/forecast?city=Beijing&days=3
GET /api/user/me
PUT /api/user/me
PUT /api/user/password
POST /api/user/avatar/upload
Content-Type: multipart/form-data
POST /api/share/outfit/{outfit_id}
说明: 将穿搭衣物拼接成一行拼图,底部叠加日期和天气文字,返回可访问的图片 URL。
GET /health
响应:
{ "status": "ok" }| HTTP 状态码 | 说明 |
|---|---|
| 200 | 成功 |
| 400 | 请求参数错误 |
| 401 | 未认证或令牌失效 |
| 404 | 资源不存在 |
| 413 | 文件过大 |
| 500 | 服务器内部错误 |