Compare commits

...

2 Commits

Author SHA1 Message Date
e287d7bbde 初始化 2025-10-18 16:18:20 +08:00
cf2273e6da 修改接口文档 2025-10-17 16:21:14 +08:00
44 changed files with 24521 additions and 610 deletions

372
.trae/rules/save.md Normal file
View File

@@ -0,0 +1,372 @@
# 存入胶囊功能 API 文档
## 概述
存入胶囊功能允许用户将邮件保存为时光胶囊状态,邮件将以草稿形式保存,用户可以随时编辑或发送。
## API 接口
### 创建胶囊邮件
**接口地址:** `POST /api/v1/mails`
**接口描述:** 创建一个新邮件并将其保存为时光胶囊状态(草稿)
#### 请求参数
| 参数名 | 类型 | 必填 | 说明 |
|--------|------|------|------|
| title | string | 是 | 邮件标题 |
| content | string | 是 | 邮件内容 |
| recipientType | string | 是 | 收件人类型SELF自己、SPECIFIC指定收件人、PUBLIC公开信 |
| recipientEmail | string | 否 | 指定收件人邮箱当recipientType为SPECIFIC时必填 |
| sendTime | string | 否 | 发送时间ISO格式时间字符串2025-12-31T23:59:59Z |
| triggerType | string | 否 | 触发类型TIME时间、LOCATION地点、EVENT事件 |
| triggerCondition | object | 否 | 触发条件 |
| triggerCondition.location | object | 否 | 地点触发条件 |
| triggerCondition.location.latitude | number | 否 | 纬度 |
| triggerCondition.location.longitude | number | 否 | 经度 |
| triggerCondition.location.city | string | 否 | 城市 |
| triggerCondition.event | object | 否 | 事件触发条件 |
| triggerCondition.event.keywords | array | 否 | 关键词列表 |
| triggerCondition.event.type | string | 否 | 事件类型 |
| attachments | array | 否 | 附件列表 |
| attachments[].type | string | 否 | 附件类型IMAGE、VOICE、VIDEO |
| attachments[].url | string | 否 | 附件URL |
| attachments[].thumbnail | string | 否 | 缩略图URL |
| isEncrypted | boolean | 否 | 是否加密 |
| capsuleStyle | string | 否 | 胶囊样式 |
| status | string | 是 | 邮件状态存入胶囊时固定为DRAFT |
#### 请求示例
```json
{
"title": "写给未来的自己",
"content": "亲爱的未来的我,当你读到这封信时,希望你已经实现了现在的梦想...",
"recipientType": "SELF",
"sendTime": "2025-12-31T23:59:59Z",
"triggerType": "TIME",
"attachments": [
{
"type": "IMAGE",
"url": "https://example.com/image.jpg",
"thumbnail": "https://example.com/thumb.jpg"
}
],
"isEncrypted": false,
"capsuleStyle": "default",
"status": "DRAFT"
}
```
#### 响应参数
| 参数名 | 类型 | 说明 |
|--------|------|------|
| code | number | 响应状态码200表示成功 |
| message | string | 响应消息 |
| data | object | 响应数据 |
| data.mailId | string | 邮件ID |
| data.capsuleId | string | 胶囊ID |
| data.status | string | 邮件状态DRAFT、PENDING、DELIVERING、DELIVERED |
| data.createdAt | string | 创建时间ISO格式时间字符串 |
#### 响应示例
```json
{
"code": 200,
"message": "success",
"data": {
"mailId": "mail_1234567890",
"capsuleId": "capsule_1234567890",
"status": "DRAFT",
"createdAt": "2023-07-20T10:30:00Z"
}
}
```
### 获取胶囊列表
**接口地址:** `GET /api/v1/mails`
**接口描述:** 获取用户的胶囊邮件列表
#### 请求参数
| 参数名 | 类型 | 必填 | 说明 |
|--------|------|------|------|
| type | string | 否 | 邮件类型INBOX、SENT、DRAFT获取胶囊时使用DRAFT |
| status | string | 否 | 状态筛选PENDING、DELIVERING、DELIVERED、DRAFT |
| page | number | 否 | 页码默认为1 |
| size | number | 否 | 每页数量默认为10 |
#### 请求示例
```
GET /api/v1/mails?type=DRAFT&page=1&size=10
```
#### 响应参数
| 参数名 | 类型 | 说明 |
|--------|------|------|
| code | number | 响应状态码200表示成功 |
| message | string | 响应消息 |
| data | object | 响应数据 |
| data.list | array | 邮件列表 |
| data.list[].mailId | string | 邮件ID |
| data.list[].title | string | 邮件标题 |
| data.list[].sender | object | 发件人信息 |
| data.list[].recipient | object | 收件人信息 |
| data.list[].sendTime | string | 发送时间 |
| data.list[].deliveryTime | string | 送达时间 |
| data.list[].status | string | 邮件状态 |
| data.list[].hasAttachments | boolean | 是否有附件 |
| data.list[].isEncrypted | boolean | 是否加密 |
| data.list[].capsuleStyle | string | 胶囊样式 |
| data.total | number | 总数量 |
| data.page | number | 当前页码 |
| data.size | number | 每页数量 |
#### 响应示例
```json
{
"code": 200,
"message": "success",
"data": {
"list": [
{
"mailId": "mail_1234567890",
"title": "写给未来的自己",
"sender": {
"userId": "user_123",
"username": "张三",
"avatar": "https://example.com/avatar.jpg"
},
"recipient": {
"userId": "user_123",
"username": "张三",
"avatar": "https://example.com/avatar.jpg"
},
"sendTime": "2025-12-31T23:59:59Z",
"deliveryTime": null,
"status": "DRAFT",
"hasAttachments": true,
"isEncrypted": false,
"capsuleStyle": "default"
}
],
"total": 1,
"page": 1,
"size": 10
}
}
```
### 获取胶囊详情
**接口地址:** `GET /api/v1/mails/{mailId}`
**接口描述:** 获取指定胶囊邮件的详细信息
#### 请求参数
| 参数名 | 类型 | 必填 | 说明 |
|--------|------|------|------|
| mailId | string | 是 | 邮件ID |
#### 请求示例
```
GET /api/v1/mails/mail_1234567890
```
#### 响应参数
| 参数名 | 类型 | 说明 |
|--------|------|------|
| code | number | 响应状态码200表示成功 |
| message | string | 响应消息 |
| data | object | 响应数据 |
| data.mailId | string | 邮件ID |
| data.title | string | 邮件标题 |
| data.content | string | 邮件内容 |
| data.sender | object | 发件人信息 |
| data.recipient | object | 收件人信息 |
| data.sendTime | string | 发送时间 |
| data.createdAt | string | 创建时间 |
| data.deliveryTime | string | 送达时间 |
| data.status | string | 邮件状态 |
| data.triggerType | string | 触发类型 |
| data.triggerCondition | object | 触发条件 |
| data.attachments | array | 附件列表 |
| data.isEncrypted | boolean | 是否加密 |
| data.capsuleStyle | string | 胶囊样式 |
| data.canEdit | boolean | 是否可编辑草稿状态为true |
| data.canRevoke | boolean | 是否可撤销待投递状态为true |
#### 响应示例
```json
{
"code": 200,
"message": "success",
"data": {
"mailId": "mail_1234567890",
"title": "写给未来的自己",
"content": "亲爱的未来的我,当你读到这封信时,希望你已经实现了现在的梦想...",
"sender": {
"userId": "user_123",
"username": "张三",
"avatar": "https://example.com/avatar.jpg",
"email": "zhangsan@example.com"
},
"recipient": {
"userId": "user_123",
"username": "张三",
"avatar": "https://example.com/avatar.jpg",
"email": "zhangsan@example.com"
},
"sendTime": "2025-12-31T23:59:59Z",
"createdAt": "2023-07-20T10:30:00Z",
"deliveryTime": null,
"status": "DRAFT",
"triggerType": "TIME",
"triggerCondition": {},
"attachments": [
{
"id": "attach_123",
"type": "IMAGE",
"url": "https://example.com/image.jpg",
"thumbnail": "https://example.com/thumb.jpg",
"size": 1024000
}
],
"isEncrypted": false,
"capsuleStyle": "default",
"canEdit": true,
"canRevoke": false
}
}
```
### 更新胶囊邮件
**接口地址:** `PUT /api/v1/mails/{mailId}`
**接口描述:** 更新胶囊邮件内容(仅草稿状态可更新)
#### 请求参数
| 参数名 | 类型 | 必填 | 说明 |
|--------|------|------|------|
| mailId | string | 是 | 邮件ID路径参数 |
| title | string | 否 | 邮件标题 |
| content | string | 否 | 邮件内容 |
| recipientType | string | 否 | 收件人类型SELF、SPECIFIC、PUBLIC |
| recipientEmail | string | 否 | 指定收件人邮箱当recipientType为SPECIFIC时必填 |
| sendTime | string | 否 | 发送时间ISO格式时间字符串 |
| triggerType | string | 否 | 触发类型TIME、LOCATION、EVENT |
| triggerCondition | object | 否 | 触发条件 |
| attachments | array | 否 | 附件列表 |
| isEncrypted | boolean | 否 | 是否加密 |
| capsuleStyle | string | 否 | 胶囊样式 |
#### 请求示例
```json
{
"title": "更新后的标题",
"content": "更新后的内容...",
"sendTime": "2026-12-31T23:59:59Z"
}
```
#### 响应参数
| 参数名 | 类型 | 说明 |
|--------|------|------|
| code | number | 响应状态码200表示成功 |
| message | string | 响应消息 |
| data | object | 响应数据 |
| data.mailId | string | 邮件ID |
| data.capsuleId | string | 胶囊ID |
| data.status | string | 邮件状态 |
| data.updatedAt | string | 更新时间ISO格式时间字符串 |
#### 响应示例
```json
{
"code": 200,
"message": "success",
"data": {
"mailId": "mail_1234567890",
"capsuleId": "capsule_1234567890",
"status": "DRAFT",
"updatedAt": "2023-07-21T14:30:00Z"
}
}
```
### 删除胶囊邮件
**接口地址:** `DELETE /api/v1/mails/{mailId}`
**接口描述:** 删除指定的胶囊邮件
#### 请求参数
| 参数名 | 类型 | 必填 | 说明 |
|--------|------|------|------|
| mailId | string | 是 | 邮件ID路径参数 |
#### 请求示例
```
DELETE /api/v1/mails/mail_1234567890
```
#### 响应参数
| 参数名 | 类型 | 说明 |
|--------|------|------|
| code | number | 响应状态码200表示成功 |
| message | string | 响应消息 |
| data | object | 响应数据 |
| data.mailId | string | 已删除的邮件ID |
#### 响应示例
```json
{
"code": 200,
"message": "success",
"data": {
"mailId": "mail_1234567890"
}
}
```
## 错误码
| 错误码 | 说明 |
|--------|------|
| 200 | 成功 |
| 400 | 请求参数错误 |
| 401 | 未授权,需要登录 |
| 403 | 权限不足 |
| 404 | 资源不存在 |
| 422 | 验证失败 |
| 500 | 服务器内部错误 |
## 注意事项
1. 存入胶囊的邮件状态为DRAFT可以在任何时候编辑或发送
2. 只有草稿状态的邮件可以编辑或删除
3. 发送时间必须晚于当前时间
4. 附件大小限制为10MB
5. 免费用户每月最多可创建10个胶囊邮件
6. 加密邮件需要额外验证才能查看内容

307
.trae/rules/seed.md Normal file
View File

@@ -0,0 +1,307 @@
# 发送至未来功能 API 文档
## 概述
发送至未来功能允许用户将邮件设置为在未来特定时间自动发送,邮件状态将变为待投递(PENDING),系统会在指定时间自动处理发送。
## API 接口
### 发送至未来
**接口地址:** `POST /api/v1/mails/send-to-future`
**接口描述:** 将草稿状态的邮件设置为在未来特定时间自动发送
#### 请求参数
| 参数名 | 类型 | 必填 | 说明 |
|--------|------|------|------|
| mailId | string | 是 | 邮件ID |
| sendTime | string | 是 | 发送时间ISO格式时间字符串2025-12-31T23:59:59Z |
| triggerType | string | 否 | 触发类型TIME时间、LOCATION地点、EVENT事件默认为TIME |
| triggerCondition | object | 否 | 触发条件 |
| triggerCondition.location | object | 否 | 地点触发条件 |
| triggerCondition.location.latitude | number | 否 | 纬度 |
| triggerCondition.location.longitude | number | 否 | 经度 |
| triggerCondition.location.city | string | 否 | 城市 |
| triggerCondition.event | object | 否 | 事件触发条件 |
| triggerCondition.event.keywords | array | 否 | 关键词列表 |
| triggerCondition.event.type | string | 否 | 事件类型 |
#### 请求示例
```json
{
"mailId": "mail_1234567890",
"sendTime": "2025-12-31T23:59:59Z",
"triggerType": "TIME",
"triggerCondition": {}
}
```
#### 响应参数
| 参数名 | 类型 | 说明 |
|--------|------|------|
| code | number | 响应状态码200表示成功 |
| message | string | 响应消息 |
| data | object | 响应数据 |
| data.mailId | string | 邮件ID |
| data.capsuleId | string | 胶囊ID |
| data.status | string | 邮件状态PENDING |
| data.sendTime | string | 发送时间 |
| data.countdown | number | 倒计时秒数 |
| data.updatedAt | string | 更新时间ISO格式时间字符串 |
#### 响应示例
```json
{
"code": 200,
"message": "success",
"data": {
"mailId": "mail_1234567890",
"capsuleId": "capsule_1234567890",
"status": "PENDING",
"sendTime": "2025-12-31T23:59:59Z",
"countdown": 94608000,
"updatedAt": "2023-07-20T10:30:00Z"
}
}
```
### 获取待发送邮件列表
**接口地址:** `GET /api/v1/mails`
**接口描述:** 获取用户的待发送邮件列表
#### 请求参数
| 参数名 | 类型 | 必填 | 说明 |
|--------|------|------|------|
| type | string | 否 | 邮件类型INBOX、SENT、DRAFT获取待发送时使用SENT |
| status | string | 否 | 状态筛选PENDING、DELIVERING、DELIVERED、DRAFT获取待发送时使用PENDING |
| page | number | 否 | 页码默认为1 |
| size | number | 否 | 每页数量默认为10 |
#### 请求示例
```
GET /api/v1/mails?type=SENT&status=PENDING&page=1&size=10
```
#### 响应参数
| 参数名 | 类型 | 说明 |
|--------|------|------|
| code | number | 响应状态码200表示成功 |
| message | string | 响应消息 |
| data | object | 响应数据 |
| data.list | array | 邮件列表 |
| data.list[].mailId | string | 邮件ID |
| data.list[].title | string | 邮件标题 |
| data.list[].sender | object | 发件人信息 |
| data.list[].recipient | object | 收件人信息 |
| data.list[].sendTime | string | 发送时间 |
| data.list[].deliveryTime | string | 送达时间 |
| data.list[].status | string | 邮件状态 |
| data.list[].hasAttachments | boolean | 是否有附件 |
| data.list[].isEncrypted | boolean | 是否加密 |
| data.list[].capsuleStyle | string | 胶囊样式 |
| data.list[].countdown | number | 倒计时秒数 |
| data.total | number | 总数量 |
| data.page | number | 当前页码 |
| data.size | number | 每页数量 |
#### 响应示例
```json
{
"code": 200,
"message": "success",
"data": {
"list": [
{
"mailId": "mail_1234567890",
"title": "写给未来的自己",
"sender": {
"userId": "user_123",
"username": "张三",
"avatar": "https://example.com/avatar.jpg"
},
"recipient": {
"userId": "user_123",
"username": "张三",
"avatar": "https://example.com/avatar.jpg"
},
"sendTime": "2025-12-31T23:59:59Z",
"deliveryTime": null,
"status": "PENDING",
"hasAttachments": true,
"isEncrypted": false,
"capsuleStyle": "default",
"countdown": 94608000
}
],
"total": 1,
"page": 1,
"size": 10
}
}
```
### 获取待发送邮件详情
**接口地址:** `GET /api/v1/mails/{mailId}`
**接口描述:** 获取指定待发送邮件的详细信息
#### 请求参数
| 参数名 | 类型 | 必填 | 说明 |
|--------|------|------|------|
| mailId | string | 是 | 邮件ID |
#### 请求示例
```
GET /api/v1/mails/mail_1234567890
```
#### 响应参数
| 参数名 | 类型 | 说明 |
|--------|------|------|
| code | number | 响应状态码200表示成功 |
| message | string | 响应消息 |
| data | object | 响应数据 |
| data.mailId | string | 邮件ID |
| data.title | string | 邮件标题 |
| data.content | string | 邮件内容 |
| data.sender | object | 发件人信息 |
| data.recipient | object | 收件人信息 |
| data.sendTime | string | 发送时间 |
| data.createdAt | string | 创建时间 |
| data.deliveryTime | string | 送达时间 |
| data.status | string | 邮件状态 |
| data.triggerType | string | 触发类型 |
| data.triggerCondition | object | 触发条件 |
| data.attachments | array | 附件列表 |
| data.isEncrypted | boolean | 是否加密 |
| data.capsuleStyle | string | 胶囊样式 |
| data.canEdit | boolean | 是否可编辑待发送状态为false |
| data.canRevoke | boolean | 是否可撤销待发送状态为true |
| data.countdown | number | 倒计时秒数 |
#### 响应示例
```json
{
"code": 200,
"message": "success",
"data": {
"mailId": "mail_1234567890",
"title": "写给未来的自己",
"content": "亲爱的未来的我,当你读到这封信时,希望你已经实现了现在的梦想...",
"sender": {
"userId": "user_123",
"username": "张三",
"avatar": "https://example.com/avatar.jpg",
"email": "zhangsan@example.com"
},
"recipient": {
"userId": "user_123",
"username": "张三",
"avatar": "https://example.com/avatar.jpg",
"email": "zhangsan@example.com"
},
"sendTime": "2025-12-31T23:59:59Z",
"createdAt": "2023-07-20T10:30:00Z",
"deliveryTime": null,
"status": "PENDING",
"triggerType": "TIME",
"triggerCondition": {},
"attachments": [
{
"id": "attach_123",
"type": "IMAGE",
"url": "https://example.com/image.jpg",
"thumbnail": "https://example.com/thumb.jpg",
"size": 1024000
}
],
"isEncrypted": false,
"capsuleStyle": "default",
"canEdit": false,
"canRevoke": true,
"countdown": 94608000
}
}
```
### 撤销待发送邮件
**接口地址:** `POST /api/v1/mails/{mailId}/revoke`
**接口描述:** 撤销待发送的邮件,将状态改回草稿
#### 请求参数
| 参数名 | 类型 | 必填 | 说明 |
|--------|------|------|------|
| mailId | string | 是 | 邮件ID路径参数 |
#### 请求示例
```
POST /api/v1/mails/mail_1234567890/revoke
```
#### 响应参数
| 参数名 | 类型 | 说明 |
|--------|------|------|
| code | number | 响应状态码200表示成功 |
| message | string | 响应消息 |
| data | object | 响应数据 |
| data.mailId | string | 邮件ID |
| data.status | string | 邮件状态DRAFT |
| data.revokedAt | string | 撤销时间ISO格式时间字符串 |
#### 响应示例
```json
{
"code": 200,
"message": "success",
"data": {
"mailId": "mail_1234567890",
"status": "DRAFT",
"revokedAt": "2023-07-21T14:30:00Z"
}
}
```
## 错误码
| 错误码 | 说明 |
|--------|------|
| 200 | 成功 |
| 400 | 请求参数错误 |
| 401 | 未授权,需要登录 |
| 403 | 权限不足 |
| 404 | 资源不存在 |
| 422 | 验证失败 |
| 500 | 服务器内部错误 |
## 注意事项
1. 发送至未来的邮件状态为PENDING表示等待系统在未来指定时间自动发送
2. 只有草稿状态(DRAFT)的邮件可以设置为发送至未来
3. 发送时间必须晚于当前时间至少1小时
4. 待发送状态的邮件不能编辑内容,但可以撤销发送
5. 撤销后的邮件状态将变回草稿(DRAFT),可以重新编辑或设置发送时间
6. 系统会在发送时间到达前10分钟进入投递中状态(DELIVERING)
7. 免费用户每月最多可设置5封邮件发送至未来
8. 附件大小限制为10MB
9. 加密邮件需要额外验证才能查看内容

View File

@@ -1,90 +0,0 @@
# API接口修改完成总结
## 概述
根据项目规则中的接口规范我已经完成了所有API接口的修改和实现使其与规范完全一致。所有接口已经测试通过API服务器正常运行在http://localhost:5001。
## 完成的工作
### 1. 用户认证模块
- **修改内容**
- 创建了新的 `AuthController.cs`,路径为 `api/v1/auth`
- 实现了用户注册、登录、刷新令牌和注销接口
- 移除了 `UsersController.cs` 中的认证相关接口,只保留用户信息管理功能
### 2. 邮件管理模块
- **修改内容**
- 修改了 `MailsController.cs` 中的参数名,将 `id` 改为 `mailId`
- 修改了以下接口的参数名:
- `GET /api/v1/mails/{mailId}`
- `PUT /api/v1/mails/{mailId}`
- `DELETE /api/v1/mails/{mailId}`
- `POST /api/v1/mails/{mailId}/revoke`
- 修改了 `CreatedAtAction` 调用中的参数名
### 3. 时光胶囊模块
- **修改内容**
- 创建了新的 `CapsulesController.cs`,路径为 `api/v1/capsules`
- 实现了获取时间胶囊视图和更新胶囊样式接口
- 修改了 `TimeCapsulesController.cs` 中的参数名,将 `id` 改为 `capsuleId`
- 修改了以下接口的参数名:
- `GET /api/v1/timecapsules/{capsuleId}`
- `PUT /api/v1/timecapsules/{capsuleId}`
- `DELETE /api/v1/timecapsules/{capsuleId}`
- `POST /api/v1/timecapsules/public/{capsuleId}/claim`
- `PUT /api/v1/timecapsules/{capsuleId}/style`
- 修改了 `CreatedAtAction` 调用中的参数名
### 4. AI助手模块
- **修改内容**
- 创建了新的 `AIController.cs`,路径为 `api/v1/ai`
- 实现了以下接口:
- `POST /api/v1/ai/writing-assistant` - AI写作辅助
- `POST /api/v1/ai/sentiment-analysis` - 情感分析
- `POST /api/v1/ai/future-prediction` - 未来预测
### 5. 个人空间模块
- **修改内容**
- 创建了新的 `TimelineController.cs`,路径为 `api/v1/timeline`
- 创建了新的 `StatisticsController.cs`,路径为 `api/v1/statistics`
- 创建了新的 `UserController.cs`,路径为 `api/v1/user`
- 实现了以下接口:
- `GET /api/v1/timeline` - 获取时间线
- `GET /api/v1/statistics` - 获取统计数据
- `GET /api/v1/user/subscription` - 获取用户订阅信息
- `GET /api/v1/user/profile` - 获取用户资料
### 6. 文件上传模块
- **修改内容**
- 创建了新的 `UploadController.cs`,路径为 `api/v1/upload`
- 实现了以下接口:
- `POST /api/v1/upload/attachment` - 上传附件
- `POST /api/v1/upload/avatar` - 上传头像
### 7. 推送通知模块
- **修改内容**
- 重新创建了 `NotificationController.cs`,路径为 `api/v1/notification`
- 实现了以下接口:
- `POST /api/v1/notification/device` - 注册设备
- `GET /api/v1/notification/settings` - 获取通知设置
## 测试结果
1. API服务器成功启动在http://localhost:5001
2. Swagger UI可以正常访问
3. 接口授权验证正常工作
4. 公开接口可以正常访问并返回数据
## 总结
所有API接口已经按照项目规则中的规范进行了修改和实现路径、参数名和功能都与规范完全一致。原有的控制器保留了额外的功能实现新的控制器提供了符合规范的接口。
## 注意事项
1. 所有新创建的控制器都使用了JWT授权验证
2. 所有接口都返回统一的ApiResponse格式
3. 所有控制器都实现了适当的错误处理和日志记录
4. 参数验证和业务逻辑验证都已实现
5. 所有接口都使用了正确的HTTP方法和状态码
## 下一步建议
1. 可以通过Swagger UI (http://localhost:5001/swagger) 查看所有API接口的详细文档
2. 建议进行更全面的功能测试,包括各种边界情况
3. 可以考虑添加API版本控制以便未来升级
4. 建议添加更详细的日志记录,以便于问题排查

View File

@@ -1,76 +0,0 @@
# API接口实现完成报告
## 概述
根据项目规则中的接口规范我已经完成了所有API接口的修改和实现使其与规范完全一致。以下是详细的修改内容
## 1. 用户认证模块
- **修改内容**
- 创建了新的 `AuthController.cs`,路径为 `api/v1/auth`
- 实现了用户注册、登录、刷新令牌和注销接口
- 移除了 `UsersController.cs` 中的认证相关接口,只保留用户信息管理功能
## 2. 邮件管理模块
- **修改内容**
- 修改了 `MailsController.cs` 中的参数名,将 `id` 改为 `mailId`
- 修改了以下接口的参数名:
- `GET /api/v1/mails/{mailId}`
- `PUT /api/v1/mails/{mailId}`
- `DELETE /api/v1/mails/{mailId}`
- `POST /api/v1/mails/{mailId}/revoke`
- 修改了 `CreatedAtAction` 调用中的参数名
## 3. 时光胶囊模块
- **修改内容**
- 创建了新的 `CapsulesController.cs`,路径为 `api/v1/capsules`
- 实现了获取时间胶囊视图和更新胶囊样式接口
- 修改了 `TimeCapsulesController.cs` 中的参数名,将 `id` 改为 `capsuleId`
- 修改了以下接口的参数名:
- `GET /api/v1/timecapsules/{capsuleId}`
- `PUT /api/v1/timecapsules/{capsuleId}`
- `DELETE /api/v1/timecapsules/{capsuleId}`
- `POST /api/v1/timecapsules/public/{capsuleId}/claim`
- `PUT /api/v1/timecapsules/{capsuleId}/style`
- 修改了 `CreatedAtAction` 调用中的参数名
## 4. AI助手模块
- **修改内容**
- 创建了新的 `AIController.cs`,路径为 `api/v1/ai`
- 实现了以下接口:
- `POST /api/v1/ai/writing-assistant` - AI写作辅助
- `POST /api/v1/ai/sentiment-analysis` - 情感分析
- `POST /api/v1/ai/future-prediction` - 未来预测
## 5. 个人空间模块
- **修改内容**
- 创建了新的 `TimelineController.cs`,路径为 `api/v1/timeline`
- 创建了新的 `StatisticsController.cs`,路径为 `api/v1/statistics`
- 创建了新的 `UserController.cs`,路径为 `api/v1/user`
- 实现了以下接口:
- `GET /api/v1/timeline` - 获取时间线
- `GET /api/v1/statistics` - 获取统计数据
- `GET /api/v1/user/subscription` - 获取用户订阅信息
- `GET /api/v1/user/profile` - 获取用户资料
## 6. 文件上传模块
- **修改内容**
- 创建了新的 `UploadController.cs`,路径为 `api/v1/upload`
- 实现了以下接口:
- `POST /api/v1/upload/attachment` - 上传附件
- `POST /api/v1/upload/avatar` - 上传头像
## 7. 推送通知模块
- **修改内容**
- 重新创建了 `NotificationController.cs`,路径为 `api/v1/notification`
- 实现了以下接口:
- `POST /api/v1/notification/device` - 注册设备
- `GET /api/v1/notification/settings` - 获取通知设置
## 总结
所有API接口已经按照项目规则中的规范进行了修改和实现路径、参数名和功能都与规范完全一致。原有的控制器保留了额外的功能实现新的控制器提供了符合规范的接口。
## 注意事项
1. 所有新创建的控制器都使用了JWT授权验证
2. 所有接口都返回统一的ApiResponse格式
3. 所有控制器都实现了适当的错误处理和日志记录
4. 参数验证和业务逻辑验证都已实现
5. 所有接口都使用了正确的HTTP方法和状态码

View File

@@ -1,217 +0,0 @@
# FutureMail API 接口实现对比报告
## 1. 用户认证模块
### 已实现的接口
#### 1.1 用户注册
- **规范路径**: `POST /api/v1/auth/register`
- **实际路径**: `POST /api/v1/users/register`
- **状态**: 已实现
- **对比**: 路径略有不同,使用`users`而不是`auth`,但功能一致
#### 1.2 用户登录
- **规范路径**: `POST /api/v1/auth/login`
- **实际路径**: `POST /api/v1/users/login`
- **状态**: 已实现
- **对比**: 路径略有不同,使用`users`而不是`auth`,但功能一致
#### 1.3 刷新Token
- **规范路径**: `POST /api/v1/auth/refresh`
- **实际路径**: `POST /api/v1/users/refresh-token`
- **状态**: 已实现
- **对比**: 路径略有不同,使用`users`而不是`auth`,但功能一致
#### 1.4 用户信息管理
- **规范路径**: 未明确指定
- **实际路径**:
- `GET /api/v1/users/{id}`
- `PUT /api/v1/users/{id}`
- `POST /api/v1/users/{id}/change-password`
- **状态**: 已实现
- **对比**: 额外实现了用户信息管理功能
## 2. 邮件管理模块
### 已实现的接口
#### 2.1 创建未来邮件
- **规范路径**: `POST /api/v1/mails`
- **实际路径**: `POST /api/v1/mails`
- **状态**: 已实现
#### 2.2 获取邮件列表
- **规范路径**: `GET /api/v1/mails`
- **实际路径**: `GET /api/v1/mails`
- **状态**: 已实现
#### 2.3 获取邮件详情
- **规范路径**: `GET /api/v1/mails/{mailId}`
- **实际路径**: `GET /api/v1/mails/{id}`
- **状态**: 已实现
- **对比**: 参数名为`id`而不是`mailId`,但功能一致
#### 2.4 更新邮件
- **规范路径**: `PUT /api/v1/mails/{mailId}`
- **实际路径**: `PUT /api/v1/mails/{id}`
- **状态**: 已实现
- **对比**: 参数名为`id`而不是`mailId`,但功能一致
#### 2.5 撤销发送
- **规范路径**: `POST /api/v1/mails/{mailId}/revoke`
- **实际路径**: `POST /api/v1/mails/{id}/revoke`
- **状态**: 已实现
- **对比**: 参数名为`id`而不是`mailId`,但功能一致
#### 2.6 额外实现的接口
- **实际路径**:
- `DELETE /api/v1/mails/{id}` ✅ (删除邮件)
- `GET /api/v1/mails/received` ✅ (获取收到的邮件列表)
- `GET /api/v1/mails/received/{id}` ✅ (获取收到的邮件详情)
- `POST /api/v1/mails/received/{id}/mark-read` ✅ (标记收到的邮件为已读)
- **状态**: 已实现
- **对比**: 额外实现了接收邮件管理功能
## 3. 时光胶囊模块
### 已实现的接口
#### 3.1 获取时光胶囊视图
- **规范路径**: `GET /api/v1/capsules`
- **实际路径**: `GET /api/v1/timecapsules/view`
- **状态**: 已实现
- **对比**: 路径略有不同,使用`timecapsules`而不是`capsules`,但功能一致
#### 3.2 更新胶囊样式
- **规范路径**: `PUT /api/v1/capsules/{capsuleId}/style`
- **实际路径**: `PUT /api/v1/timecapsules/{id}/style`
- **状态**: 已实现
- **对比**: 路径略有不同,使用`timecapsules`而不是`capsules`,参数名为`id`而不是`capsuleId`,但功能一致
#### 3.3 额外实现的接口
- **实际路径**:
- `POST /api/v1/timecapsules` ✅ (创建时光胶囊)
- `GET /api/v1/timecapsules/{id}` ✅ (获取时光胶囊详情)
- `GET /api/v1/timecapsules` ✅ (获取时光胶囊列表)
- `PUT /api/v1/timecapsules/{id}` ✅ (更新时光胶囊)
- `DELETE /api/v1/timecapsules/{id}` ✅ (删除时光胶囊)
- `GET /api/v1/timecapsules/public` ✅ (获取公共时光胶囊)
- `POST /api/v1/timecapsules/public/{id}/claim` ✅ (认领公共时光胶囊)
- **状态**: 已实现
- **对比**: 额外实现了完整的时光胶囊CRUD功能
## 4. AI助手模块
### 已实现的接口
#### 4.1 AI写作辅助
- **规范路径**: `POST /api/v1/ai/writing-assistant`
- **实际路径**: `POST /api/v1/ai/writing-assistant`
- **状态**: 已实现
#### 4.2 情感分析
- **规范路径**: `POST /api/v1/ai/sentiment-analysis`
- **实际路径**: `POST /api/v1/ai/sentiment-analysis`
- **状态**: 已实现
#### 4.3 未来预测
- **规范路径**: `POST /api/v1/ai/future-prediction`
- **实际路径**: `POST /api/v1/ai/future-prediction`
- **状态**: 已实现
## 5. 个人空间模块
### 已实现的接口
#### 5.1 获取时间线
- **规范路径**: `GET /api/v1/timeline`
- **实际路径**: `GET /api/v1/personalspace/timeline`
- **状态**: 已实现
- **对比**: 路径略有不同,使用`personalspace`而不是直接使用`timeline`,但功能一致
#### 5.2 获取统计数据
- **规范路径**: `GET /api/v1/statistics`
- **实际路径**: `GET /api/v1/personalspace/statistics`
- **状态**: 已实现
- **对比**: 路径略有不同,使用`personalspace`而不是直接使用`statistics`,但功能一致
#### 5.3 获取用户订阅信息
- **规范路径**: `GET /api/v1/user/subscription`
- **实际路径**: `GET /api/v1/personalspace/subscription`
- **状态**: 已实现
- **对比**: 路径略有不同,使用`personalspace`而不是`user`,但功能一致
#### 5.4 获取用户信息
- **规范路径**: `GET /api/v1/user/profile`
- **实际路径**: `GET /api/v1/personalspace/profile`
- **状态**: 已实现
- **对比**: 路径略有不同,使用`personalspace`而不是`user`,但功能一致
## 6. 文件上传模块
### 已实现的接口
#### 6.1 上传附件
- **规范路径**: `POST /api/v1/upload/attachment`
- **实际路径**: `POST /api/v1/fileupload/attachment`
- **状态**: 已实现
- **对比**: 路径略有不同,使用`fileupload`而不是`upload`,但功能一致
#### 6.2 上传头像
- **规范路径**: `POST /api/v1/upload/avatar`
- **实际路径**: `POST /api/v1/fileupload/avatar`
- **状态**: 已实现
- **对比**: 路径略有不同,使用`fileupload`而不是`upload`,但功能一致
#### 6.3 额外实现的接口
- **实际路径**:
- `GET /api/v1/fileupload/info/{fileId}` ✅ (获取文件信息)
- **状态**: 已实现
- **对比**: 额外实现了获取文件信息功能
## 7. 推送通知模块
### 已实现的接口
#### 7.1 注册设备
- **规范路径**: `POST /api/v1/notification/device`
- **实际路径**: `POST /api/v1/notification/device`
- **状态**: 已实现
#### 7.2 获取通知设置
- **规范路径**: `GET /api/v1/notification/settings`
- **实际路径**: `GET /api/v1/notification/settings`
- **状态**: 已实现
#### 7.3 额外实现的接口
- **实际路径**:
- `DELETE /api/v1/notification/device/{deviceId}` ✅ (注销设备)
- `PUT /api/v1/notification/settings` ✅ (更新通知设置)
- `GET /api/v1/notification` ✅ (获取通知列表)
- `POST /api/v1/notification/{id}/mark-read` ✅ (标记通知为已读)
- `POST /api/v1/notification/mark-all-read` ✅ (标记所有通知为已读)
- **状态**: 已实现
- **对比**: 额外实现了完整的通知管理功能
## 总结
### 已实现的功能
1. **用户认证模块**: 基本功能已实现,路径略有不同
2. **邮件管理模块**: 基本功能已实现,额外增加了接收邮件管理功能
3. **时光胶囊模块**: 基本功能已实现额外增加了完整的CRUD功能
4. **AI助手模块**: 所有功能已实现
5. **个人空间模块**: 基本功能已实现,路径略有不同
6. **文件上传模块**: 基本功能已实现,额外增加了获取文件信息功能
7. **推送通知模块**: 基本功能已实现,额外增加了完整的通知管理功能
### 主要差异
1. **路径命名**: 部分接口使用了不同的路径命名,如使用`users`代替`auth`,使用`timecapsules`代替`capsules`
2. **参数命名**: 部分接口使用了`id`代替`mailId``capsuleId`
3. **额外功能**: 实现了许多规范中未提及但实际需要的功能,如删除操作、接收邮件管理等
### 建议
1. 考虑统一接口路径命名使其更符合RESTful规范
2. 考虑统一参数命名提高API的一致性
3. 当前的实现已经覆盖了所有核心功能,并且增加了许多实用的额外功能
总体而言当前的API实现已经非常完善不仅覆盖了规范中定义的所有核心功能还增加了许多实用的额外功能。主要的差异在于路径命名和参数命名这些差异不影响功能但可以考虑统一以提高API的一致性。

View File

@@ -0,0 +1,794 @@
# FutureMail API 接口文档详细说明
## 项目概述
FutureMail 是一个未来邮件系统,允许用户创建定时发送的邮件,支持多种触发条件(时间、位置、事件),并提供时光胶囊可视化功能。
## 基础信息
- **API 基础地址**: `http://localhost:5003/api/v1`
- **认证方式**: JWT Bearer Token
- **数据格式**: JSON
- **字符编码**: UTF-8
## 认证说明
所有需要认证的接口都需要在请求头中添加:
```
Authorization: Bearer <your_jwt_token>
```
## 1. 用户认证模块
### 1.1 用户注册
**接口地址**: `POST /api/v1/auth/register`
**请求参数**:
```json
{
"username": "string", // 用户名,必填
"email": "string", // 邮箱,必填
"password": "string", // 密码,必填
"avatar": "string" // 头像URL可选
}
```
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"userId": "string",
"username": "string",
"email": "string",
"avatar": "string",
"token": "string",
"refreshToken": "string"
}
}
```
### 1.2 用户登录
**接口地址**: `POST /api/v1/auth/login`
**请求参数**:
```json
{
"email": "string", // 邮箱,必填
"password": "string" // 密码,必填
}
```
**响应示例**: 同注册接口
### 1.3 刷新令牌
**接口地址**: `POST /api/v1/auth/refresh`
**请求参数**:
```json
{
"refreshToken": "string" // 刷新令牌,必填
}
```
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"token": "string",
"refreshToken": "string"
}
}
```
### 1.4 用户登出
**接口地址**: `POST /api/v1/auth/logout`
**请求头**: 需要包含有效的JWT令牌
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": null
}
```
## 2. 邮件管理模块
### 2.1 创建未来邮件
**接口地址**: `POST /api/v1/mails/create` (兼容前端格式)
**请求参数**:
```json
{
"title": "string", // 邮件标题,必填
"content": "string", // 邮件内容,必填
"recipientType": "SELF", // 收件人类型,必填,可选值: SELF(自己), SPECIFIC(指定), PUBLIC(公开)
"recipientEmail": "string", // 指定收件人邮箱当recipientType为SPECIFIC时必填
"sendTime": "2026-10-16T08:03:58.479Z", // 发送时间必填ISO时间格式
"triggerType": "TIME", // 触发类型,必填,可选值: TIME(时间), LOCATION(位置), EVENT(事件)
"triggerCondition": { // 触发条件,可选
"location": {
"latitude": "number", // 纬度
"longitude": "number", // 经度
"city": "string" // 城市
},
"event": {
"keywords": ["string"], // 关键词列表
"type": "string" // 事件类型
}
},
"attachments": [ // 附件列表,可选
{
"type": "IMAGE", // 附件类型,可选值: IMAGE, VOICE, VIDEO
"url": "string", // 附件URL
"thumbnail": "string" // 缩略图URL
}
],
"isEncrypted": false, // 是否加密,可选
"capsuleStyle": "default" // 胶囊样式,可选
}
```
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"mailId": "string",
"capsuleId": "string",
"status": "DRAFT", // 状态: DRAFT(草稿), PENDING(待投递), DELIVERING(投递中), DELIVERED(已投递)
"createdAt": "string"
}
}
```
### 2.2 获取邮件列表
**接口地址**: `GET /api/v1/mails`
**查询参数**:
- `type`: 邮件类型,可选值: INBOX(收件箱), SENT(已发送), DRAFT(草稿)
- `status`: 状态筛选,可选值: PENDING, DELIVERING, DELIVERED
- `page`: 页码从1开始
- `size`: 每页数量
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"list": [
{
"mailId": "string",
"title": "string",
"sender": {
"userId": "string",
"username": "string",
"avatar": "string"
},
"recipient": {
"userId": "string",
"username": "string",
"avatar": "string"
},
"sendTime": "string",
"deliveryTime": "string",
"status": "string",
"hasAttachments": true,
"isEncrypted": false,
"capsuleStyle": "string",
"countdown": 86400 // 倒计时秒数仅status=PENDING时返回
}
],
"total": 100,
"page": 1,
"size": 20
}
}
```
### 2.3 获取邮件详情
**接口地址**: `GET /api/v1/mails/{mailId}`
**路径参数**:
- `mailId`: 邮件ID
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"mailId": "string",
"title": "string",
"content": "string",
"sender": {
"userId": "string",
"username": "string",
"avatar": "string",
"email": "string"
},
"recipient": {
"userId": "string",
"username": "string",
"avatar": "string",
"email": "string"
},
"sendTime": "string",
"createdAt": "string",
"deliveryTime": "string",
"status": "string",
"triggerType": "string",
"triggerCondition": {},
"attachments": [
{
"id": "string",
"type": "string",
"url": "string",
"thumbnail": "string",
"size": 1024
}
],
"isEncrypted": false,
"capsuleStyle": "string",
"canEdit": false, // 是否可编辑(仅草稿状态)
"canRevoke": true // 是否可撤销(仅待投递状态)
}
}
```
### 2.4 更新邮件(投递前)
**接口地址**: `PUT /api/v1/mails/{mailId}`
**路径参数**:
- `mailId`: 邮件ID
**请求参数**: 同创建邮件,但所有字段可选
**响应示例**: 同创建邮件
### 2.5 撤销发送
**接口地址**: `POST /api/v1/mails/{mailId}/revoke`
**路径参数**:
- `mailId`: 邮件ID
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"mailId": "string",
"status": "REVOKED"
}
}
```
## 3. 时光胶囊模块
### 3.1 获取时光胶囊视图
**接口地址**: `GET /api/v1/capsules`
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"capsules": [
{
"capsuleId": "string",
"mailId": "string",
"title": "string",
"sendTime": "string",
"deliveryTime": "string",
"progress": 0.5, // 0-1 的进度
"position": {
"x": 0.5, // 0-1 相对位置
"y": 0.5,
"z": 0.5
},
"style": "string",
"glowIntensity": 0.8 // 发光强度
}
],
"scene": "SPACE", // 场景类型: SPACE, OCEAN
"background": "string" // 背景配置
}
}
```
### 3.2 更新胶囊样式
**接口地址**: `PUT /api/v1/capsules/{capsuleId}/style`
**路径参数**:
- `capsuleId`: 胶囊ID
**请求参数**:
```json
{
"style": "string", // 胶囊样式
"glowIntensity": 0.8 // 发光强度
}
```
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"capsuleId": "string",
"style": "string",
"glowIntensity": 0.8
}
}
```
## 4. AI助手模块
### 4.1 AI写作辅助
**接口地址**: `POST /api/v1/ai/writing-assistant`
**请求参数**:
```json
{
"prompt": "string", // 用户输入,必填
"type": "OUTLINE", // 辅助类型,必填,可选值: OUTLINE(大纲), DRAFT(草稿), COMPLETE(完整)
"tone": "FORMAL", // 语气,必填,可选值: FORMAL(正式), CASUAL(随意), EMOTIONAL(情感), INSPIRATIONAL(励志)
"length": "MEDIUM", // 长度,必填,可选值: SHORT(短), MEDIUM(中), LONG(长)
"context": "string" // 上下文信息,可选
}
```
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"content": "string",
"suggestions": ["string"],
"estimatedTime": 5 // 预计写作时间(分钟)
}
}
```
### 4.2 情感分析
**接口地址**: `POST /api/v1/ai/sentiment-analysis`
**请求参数**:
```json
{
"content": "string" // 待分析内容,必填
}
```
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"sentiment": "POSITIVE", // 情感倾向: POSITIVE(积极), NEUTRAL(中性), NEGATIVE(消极), MIXED(混合)
"confidence": 0.85, // 0-1 置信度
"emotions": [
{
"type": "HAPPY", // 情感类型: HAPPY, SAD, HOPEFUL, NOSTALGIC, EXCITED
"score": 0.7 // 情感分数
}
],
"keywords": ["string"],
"summary": "string"
}
}
```
### 4.3 未来预测
**接口地址**: `POST /api/v1/ai/future-prediction`
**请求参数**:
```json
{
"content": "string", // 邮件内容,必填
"deliveryTime": "string", // 投递时间,必填
"context": "string" // 上下文信息,可选
}
```
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"prediction": "string", // 预测结果
"confidence": 0.75, // 0-1 置信度
"factors": ["string"], // 影响因素
"suggestions": ["string"] // 建议
}
}
```
## 5. 个人空间模块
### 5.1 获取时间线
**接口地址**: `GET /api/v1/timeline`
**查询参数**:
- `startDate`: 开始日期,可选
- `endDate`: 结束日期,可选
- `type`: 类型,可选值: ALL(全部), SENT(已发送), RECEIVED(已接收)
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"timeline": [
{
"date": "2025-10-16",
"events": [
{
"type": "SENT", // 事件类型: SENT, RECEIVED
"mailId": "string",
"title": "string",
"time": "08:00:00",
"withUser": {
"userId": "string",
"username": "string",
"avatar": "string"
},
"emotion": "string"
}
]
}
]
}
}
```
### 5.2 获取统计数据
**接口地址**: `GET /api/v1/statistics`
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"totalSent": 50, // 总发送数
"totalReceived": 30, // 总接收数
"timeTravelDuration": 365, // 总时间旅行时长(天)
"mostFrequentRecipient": "string", // 最常联系的收件人
"mostCommonYear": 2025, // 最常见的投递年份
"keywordCloud": [ // 关键词云
{
"word": "string",
"count": 10,
"size": 1.0
}
],
"monthlyStats": [ // 月度统计
{
"month": "2025-10",
"sent": 5,
"received": 3
}
]
}
}
```
### 5.3 获取用户信息
**接口地址**: `GET /api/v1/user/profile`
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"userId": "string",
"username": "string",
"email": "string",
"avatar": "string",
"nickname": "string",
"preferredBackground": "string", // 偏好背景
"preferredScene": "string", // 偏好场景
"createdAt": "string",
"lastLoginAt": "string"
}
}
```
### 5.4 更新用户信息
**接口地址**: `PUT /api/v1/user/profile`
**请求参数**:
```json
{
"nickname": "string", // 昵称,可选
"avatar": "string", // 头像URL可选
"preferredBackground": "string", // 偏好背景,可选
"preferredScene": "string" // 偏好场景,可选
}
```
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"userId": "string",
"username": "string",
"email": "string",
"nickname": "string",
"avatar": "string",
"preferredBackground": "string",
"preferredScene": "string",
"updatedAt": "string"
}
}
```
## 6. 文件上传模块
### 6.1 上传附件
**接口地址**: `POST /api/v1/upload/attachment`
**请求类型**: `multipart/form-data`
**请求参数**:
- `file`: 文件,必填
- `type`: 文件类型,必填,可选值: IMAGE, VOICE, VIDEO
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"fileId": "string",
"fileName": "string",
"fileSize": 1024,
"fileType": "string",
"url": "string",
"thumbnailUrl": "string"
}
}
```
### 6.2 上传头像
**接口地址**: `POST /api/v1/upload/avatar`
**请求类型**: `multipart/form-data`
**请求参数**:
- `file`: 图片文件,必填
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"avatarUrl": "string"
}
}
```
## 7. 推送通知模块
### 7.1 注册设备
**接口地址**: `POST /api/v1/notification/device`
**请求参数**:
```json
{
"deviceId": "string", // 设备ID必填
"platform": "string", // 平台,必填,可选值: IOS, ANDROID, WEB
"token": "string", // 推送令牌,必填
"isEnabled": true // 是否启用通知,可选
}
```
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"deviceId": "string",
"isRegistered": true
}
}
```
### 7.2 获取通知设置
**接口地址**: `GET /api/v1/notification/settings`
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"emailNotification": true, // 邮件通知
"pushNotification": true, // 推送通知
"deliveryReminder": true, // 投递提醒
"receivedNotification": true // 接收通知
}
}
```
### 7.3 更新通知设置
**接口地址**: `PUT /api/v1/notification/settings`
**请求参数**:
```json
{
"emailNotification": true, // 邮件通知,可选
"pushNotification": true, // 推送通知,可选
"deliveryReminder": true, // 投递提醒,可选
"receivedNotification": true // 接收通知,可选
}
```
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"emailNotification": true,
"pushNotification": true,
"deliveryReminder": true,
"receivedNotification": true,
"updatedAt": "string"
}
}
```
## 8. 系统管理模块
### 8.1 获取用户订阅信息
**接口地址**: `GET /api/v1/user/subscription`
**响应示例**:
```json
{
"code": 200,
"message": "success",
"data": {
"plan": "FREE", // 订阅计划: FREE, PREMIUM
"remainingMails": 10, // 剩余邮件数量
"maxAttachmentSize": 10485760, // 最大附件大小(字节)
"features": {
"advancedTriggers": false, // 高级触发器
"customCapsules": false, // 自定义胶囊
"aiAssistant": true // AI助手
},
"expireDate": "string" // 到期日期
}
}
```
## 错误响应格式
所有错误响应都遵循统一格式:
```json
{
"code": 400, // 错误代码
"message": "error message", // 错误消息
"errors": { // 详细错误信息(可选)
"field": "error description"
}
}
```
### 常见错误代码
- `400`: 请求参数错误
- `401`: 未授权(令牌无效或过期)
- `403`: 禁止访问(权限不足)
- `404`: 资源不存在
- `409`: 资源冲突(如邮箱已存在)
- `429`: 请求频率限制
- `500`: 服务器内部错误
## 使用示例
### 完整的邮件创建流程
1. **用户登录**
```bash
curl -X POST "http://localhost:5003/api/v1/auth/login" \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password123"
}'
```
2. **创建未来邮件**
```bash
curl -X POST "http://localhost:5003/api/v1/mails/create" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <your_jwt_token>" \
-d '{
"title": "给未来的一封信",
"content": "亲爱的未来的我,...",
"recipientType": "SELF",
"sendTime": "2026-10-16T08:03:58.479Z",
"triggerType": "TIME",
"triggerCondition": {},
"attachments": [],
"isEncrypted": false,
"capsuleStyle": "default"
}'
```
3. **获取邮件列表**
```bash
curl -X GET "http://localhost:5003/api/v1/mails?type=SENT&page=1&size=10" \
-H "Authorization: Bearer <your_jwt_token>"
```
## 注意事项
1. 所有时间字段均使用ISO 8601格式`2025-10-16T08:03:58.479Z`
2. 文件上传大小限制为100MB
3. JWT令牌有效期为24小时
4. 刷新令牌有效期为7天
5. 免费用户每月可创建10封未来邮件
6. 高级触发器(位置、事件)仅限高级用户使用
## 版本历史
- **v1.0.0**: 初始版本,包含基本邮件功能
- **v1.1.0**: 添加AI助手功能
- **v1.2.0**: 添加时光胶囊可视化
- **v1.3.0**: 添加高级触发条件
## 联系方式
如有问题或建议,请联系:
- 邮箱support@futuremail.com
- 文档https://docs.futuremail.com
- GitHubhttps://github.com/futuremail/api

View File

@@ -1,120 +0,0 @@
# API控制器重构总结
## 修改概述
为了统一用户身份验证逻辑,我们将所有控制器从继承`ControllerBase`改为继承`BaseController`,并更新了`GetCurrentUserId`的调用方式。
## 修改内容
### 1. BaseController.cs
- 保留原有的`GetCurrentUserIdNullable()`方法(返回`int?`
- 新增`GetCurrentUserId()`方法(返回`int`未认证时返回0
### 2. 修改的控制器从ControllerBase改为BaseController
以下控制器已从继承`ControllerBase`改为继承`BaseController`,并更新了`GetCurrentUserId`的调用方式:
1. **UsersController.cs**
- 继承关系:`ControllerBase``BaseController`
- 更新了`GetUser``UpdateUser``ChangePassword`方法中的用户ID验证逻辑
- 移除了私有的`GetCurrentUserId`方法
2. **MailsController.cs**
- 继承关系:`ControllerBase``BaseController`
- 更新了所有方法中的用户ID验证逻辑`== null`改为`<= 0`
- 移除了服务调用中的`.Value`访问
3. **UserController.cs**
- 继承关系:`ControllerBase``BaseController`
- 更新了用户ID验证逻辑
4. **AIAssistantController.cs**
- 继承关系:`ControllerBase``BaseController`
- 更新了用户ID验证逻辑
5. **AIController.cs**
- 继承关系:`ControllerBase``BaseController`
- 更新了用户ID验证逻辑
6. **CapsulesController.cs**
- 继承关系:`ControllerBase``BaseController`
- 更新了用户ID验证逻辑
7. **NotificationController.cs**
- 继承关系:`ControllerBase``BaseController`
- 更新了用户ID验证逻辑
8. **PersonalSpaceController.cs**
- 继承关系:`ControllerBase``BaseController`
- 更新了用户ID验证逻辑
9. **StatisticsController.cs**
- 继承关系:`ControllerBase``BaseController`
- 更新了用户ID验证逻辑
10. **TimeCapsulesController.cs**
- 继承关系:`ControllerBase``BaseController`
- 更新了用户ID验证逻辑
11. **TimelineController.cs**
- 继承关系:`ControllerBase``BaseController`
- 更新了用户ID验证逻辑
### 3. 已继承BaseController的控制器无需修改
1. **FileUploadController.cs**
- 已继承`BaseController`
- 已使用正确的`GetCurrentUserId`调用方式
2. **UploadController.cs**
- 已继承`BaseController`
- 已使用正确的`GetCurrentUserId`调用方式
### 4. 不需要身份验证的控制器(保持原样)
1. **TempFixController.cs**
- 不需要身份验证
- 继承`ControllerBase`
2. **OAuthController.cs**
- 处理OAuth登录流程需要匿名访问
- 继承`ControllerBase`
3. **AuthController.cs**
- 处理认证流程,需要匿名访问
- 继承`ControllerBase`
- 保留私有的`GetCurrentUserIdNullable`方法,并重命名为`GetCurrentUserIdNullable`以避免冲突
## 修改后的用户ID验证逻辑
### 修改前
```csharp
var currentUserId = GetCurrentUserId();
if (currentUserId == null)
{
return Unauthorized();
}
// 使用currentUserId.Value
```
### 修改后
```csharp
var currentUserId = GetCurrentUserId();
if (currentUserId <= 0)
{
return Unauthorized();
}
// 直接使用currentUserId
```
## 优势
1. **代码一致性**:所有控制器使用相同的用户身份验证方法
2. **减少重复代码**:移除了各个控制器中重复的`GetCurrentUserId`实现
3. **更简洁的API**`GetCurrentUserId()`返回`int`类型,使用更方便
4. **更好的可维护性**:身份验证逻辑集中在`BaseController`
## 测试
API服务已成功启动并运行没有出现编译错误说明所有修改都是正确的。

View File

View File

@@ -80,6 +80,108 @@ namespace FutureMailAPI.Controllers
result);
}
// 直接接收前端原始格式的创建邮件接口
[HttpPost("create-raw")]
public async Task<IActionResult> CreateMailRaw()
{
try
{
// 读取请求体
var request = HttpContext.Request;
using var reader = new StreamReader(request.Body);
var body = await reader.ReadToEndAsync();
// 解析JSON
var rawMail = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, object>>(body);
if (rawMail == null)
{
return BadRequest(ApiResponse<SentMailResponseDto>.ErrorResult("请求数据为空"));
}
// 创建兼容DTO
var compatDto = new SentMailCreateCompatDto();
// 解析各个字段
if (rawMail.ContainsKey("title") && rawMail["title"] != null)
compatDto.title = rawMail["title"].ToString() ?? string.Empty;
if (rawMail.ContainsKey("content") && rawMail["content"] != null)
compatDto.content = rawMail["content"].ToString() ?? string.Empty;
if (rawMail.ContainsKey("recipientType") && rawMail["recipientType"] != null)
{
var recipientTypeStr = rawMail["recipientType"].ToString();
if (Enum.TryParse<RecipientTypeEnum>(recipientTypeStr, true, out var recipientType))
compatDto.recipientType = recipientType;
}
if (rawMail.ContainsKey("recipientEmail") && rawMail["recipientEmail"] != null)
compatDto.recipientEmail = rawMail["recipientEmail"].ToString();
if (rawMail.ContainsKey("sendTime") && rawMail["sendTime"] != null)
{
if (DateTime.TryParse(rawMail["sendTime"].ToString(), out var sendTime))
compatDto.sendTime = sendTime;
}
if (rawMail.ContainsKey("triggerType") && rawMail["triggerType"] != null)
{
var triggerTypeStr = rawMail["triggerType"].ToString();
if (Enum.TryParse<TriggerTypeEnum>(triggerTypeStr, true, out var triggerType))
compatDto.triggerType = triggerType;
}
if (rawMail.ContainsKey("triggerCondition"))
compatDto.triggerCondition = rawMail["triggerCondition"];
if (rawMail.ContainsKey("attachments"))
{
try
{
compatDto.attachments = System.Text.Json.JsonSerializer.Deserialize<List<object>>(rawMail["attachments"].ToString());
}
catch
{
compatDto.attachments = new List<object>();
}
}
if (rawMail.ContainsKey("isEncrypted"))
compatDto.isEncrypted = bool.Parse(rawMail["isEncrypted"].ToString());
if (rawMail.ContainsKey("capsuleStyle"))
compatDto.capsuleStyle = rawMail["capsuleStyle"].ToString() ?? "default";
// 从JWT令牌中获取当前用户ID
var currentUserId = GetCurrentUserId();
if (currentUserId <= 0)
{
return Unauthorized(ApiResponse<SentMailResponseDto>.ErrorResult("未授权访问"));
}
// 转换为内部DTO
var internalDto = compatDto.ToInternalDto();
var result = await _mailService.CreateMailAsync(currentUserId, internalDto);
if (!result.Success)
{
return BadRequest(result);
}
return CreatedAtAction(
nameof(GetMail),
new { mailId = result.Data!.Id },
result);
}
catch (Exception ex)
{
_logger.LogError(ex, "创建邮件时发生错误");
return StatusCode(500, ApiResponse<SentMailResponseDto>.ErrorResult("服务器内部错误"));
}
}
[HttpGet("{mailId}")]
public async Task<IActionResult> GetMail(int mailId)
{
@@ -255,5 +357,198 @@ namespace FutureMailAPI.Controllers
return Ok(result);
}
/// <summary>
/// 存入胶囊 - 创建胶囊邮件
/// </summary>
/// <param name="dto">存入胶囊请求</param>
/// <returns>操作结果</returns>
[HttpPost("capsule")]
public async Task<IActionResult> SaveToCapsule([FromBody] SaveToCapsuleDto dto)
{
if (!ModelState.IsValid)
{
return BadRequest(ApiResponse<SaveToCapsuleResponseDto>.ErrorResult("请求参数无效"));
}
var currentUserId = GetCurrentUserId();
if (currentUserId <= 0)
{
return Unauthorized(ApiResponse<SaveToCapsuleResponseDto>.ErrorResult("未授权访问"));
}
var result = await _mailService.SaveToCapsuleAsync(currentUserId, dto);
if (!result.Success)
{
return BadRequest(result);
}
return CreatedAtAction(
nameof(GetCapsuleMail),
new { id = result.Data!.Id },
result);
}
/// <summary>
/// 获取胶囊邮件列表
/// </summary>
/// <param name="pageIndex">页码</param>
/// <param name="pageSize">页大小</param>
/// <param name="status">状态筛选</param>
/// <param name="recipientType">收件人类型筛选</param>
/// <param name="keyword">关键词搜索</param>
/// <param name="startDate">开始日期</param>
/// <param name="endDate">结束日期</param>
/// <returns>胶囊邮件列表</returns>
[HttpGet("capsule")]
public async Task<IActionResult> GetCapsuleMails(
[FromQuery] int pageIndex = 1,
[FromQuery] int pageSize = 10,
[FromQuery] int? status = null,
[FromQuery] int? recipientType = null,
[FromQuery] string? keyword = null,
[FromQuery] DateTime? startDate = null,
[FromQuery] DateTime? endDate = null)
{
var queryDto = new MailListQueryDto
{
PageIndex = pageIndex,
PageSize = pageSize,
Status = status,
RecipientType = recipientType,
Keyword = keyword,
StartDate = startDate,
EndDate = endDate
};
var currentUserId = GetCurrentUserId();
if (currentUserId <= 0)
{
return Unauthorized(ApiResponse<PagedResponse<CapsuleMailListResponseDto>>.ErrorResult("未授权访问"));
}
var result = await _mailService.GetCapsuleMailsAsync(currentUserId, queryDto);
if (!result.Success)
{
return BadRequest(result);
}
return Ok(result);
}
/// <summary>
/// 获取胶囊邮件详情
/// </summary>
/// <param name="id">邮件ID</param>
/// <returns>胶囊邮件详情</returns>
[HttpGet("capsule/{id}")]
public async Task<IActionResult> GetCapsuleMail(int id)
{
var currentUserId = GetCurrentUserId();
if (currentUserId <= 0)
{
return Unauthorized(ApiResponse<CapsuleMailDetailResponseDto>.ErrorResult("未授权访问"));
}
var result = await _mailService.GetCapsuleMailByIdAsync(currentUserId, id);
if (!result.Success)
{
return NotFound(result);
}
return Ok(result);
}
/// <summary>
/// 更新胶囊邮件
/// </summary>
/// <param name="id">邮件ID</param>
/// <param name="dto">更新请求</param>
/// <returns>更新后的胶囊邮件详情</returns>
[HttpPut("capsule/{id}")]
public async Task<IActionResult> UpdateCapsuleMail(int id, [FromBody] UpdateCapsuleMailDto dto)
{
if (!ModelState.IsValid)
{
return BadRequest(ApiResponse<CapsuleMailDetailResponseDto>.ErrorResult("请求参数无效"));
}
var currentUserId = GetCurrentUserId();
if (currentUserId <= 0)
{
return Unauthorized(ApiResponse<CapsuleMailDetailResponseDto>.ErrorResult("未授权访问"));
}
var result = await _mailService.UpdateCapsuleMailAsync(currentUserId, id, dto);
if (!result.Success)
{
return BadRequest(result);
}
return Ok(result);
}
/// <summary>
/// 撤销胶囊邮件
/// </summary>
/// <param name="id">邮件ID</param>
/// <returns>操作结果</returns>
[HttpPost("capsule/{id}/revoke")]
public async Task<IActionResult> RevokeCapsuleMail(int id)
{
var currentUserId = GetCurrentUserId();
if (currentUserId <= 0)
{
return Unauthorized(ApiResponse<bool>.ErrorResult("未授权访问"));
}
var result = await _mailService.RevokeCapsuleMailAsync(currentUserId, id);
if (!result.Success)
{
return BadRequest(result);
}
return Ok(result);
}
/// <summary>
/// 发送至未来 - 将草稿状态的邮件设置为在未来特定时间自动发送
/// </summary>
/// <param name="sendToFutureDto">发送至未来请求DTO</param>
/// <returns>发送至未来响应DTO</returns>
[HttpPost("send-to-future")]
public async Task<IActionResult> SendToFuture([FromBody] SendToFutureDto sendToFutureDto)
{
if (!ModelState.IsValid)
{
return BadRequest(ApiResponse<SendToFutureResponseDto>.ErrorResult("请求参数无效"));
}
var currentUserId = GetCurrentUserId();
if (currentUserId <= 0)
{
return Unauthorized(ApiResponse<SendToFutureResponseDto>.ErrorResult("未授权访问"));
}
var result = await _mailService.SendToFutureAsync(currentUserId, sendToFutureDto);
if (!result.Success)
{
return BadRequest(result);
}
return Ok(result);
}
}
}

View File

@@ -189,4 +189,130 @@ namespace FutureMailAPI.DTOs
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
}
// 存入胶囊请求DTO
public class SaveToCapsuleDto
{
[Required(ErrorMessage = "标题是必填项")]
[StringLength(200, ErrorMessage = "标题长度不能超过200个字符")]
public string Title { get; set; } = string.Empty;
[Required(ErrorMessage = "内容是必填项")]
public string Content { get; set; } = string.Empty;
[Required(ErrorMessage = "收件人类型是必填项")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public RecipientTypeEnum RecipientType { get; set; }
public string? RecipientEmail { get; set; }
public DateTime? SendTime { get; set; }
[Required(ErrorMessage = "触发条件类型是必填项")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public TriggerTypeEnum TriggerType { get; set; } = TriggerTypeEnum.TIME;
public object? TriggerCondition { get; set; }
public List<object>? Attachments { get; set; }
public bool IsEncrypted { get; set; } = false;
[Required(ErrorMessage = "胶囊样式是必填项")]
public string CapsuleStyle { get; set; } = "default";
}
// 存入胶囊响应DTO
public class SaveToCapsuleResponseDto
{
public int Id { get; set; }
public string MailId { get; set; } = string.Empty;
public string CapsuleId { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public DateTime CreatedAt { get; set; }
}
// 胶囊邮件列表响应DTO
public class CapsuleMailListResponseDto
{
public string MailId { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public UserInfoDto Sender { get; set; } = new();
public UserInfoDto Recipient { get; set; } = new();
public DateTime SendTime { get; set; }
public DateTime? DeliveryTime { get; set; }
public string Status { get; set; } = string.Empty;
public bool HasAttachments { get; set; }
public bool IsEncrypted { get; set; }
public string CapsuleStyle { get; set; } = string.Empty;
public int? Countdown { get; set; } // 倒计时秒数仅status=PENDING时返回
}
// 胶囊邮件详情响应DTO
public class CapsuleMailDetailResponseDto
{
public string MailId { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public string Content { get; set; } = string.Empty;
public UserInfoDto Sender { get; set; } = new();
public UserInfoDto Recipient { get; set; } = new();
public DateTime SendTime { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime? DeliveryTime { get; set; }
public string Status { get; set; } = string.Empty;
public string TriggerType { get; set; } = string.Empty;
public object? TriggerCondition { get; set; }
public List<AttachmentDto> Attachments { get; set; } = new();
public bool IsEncrypted { get; set; }
public string CapsuleStyle { get; set; } = string.Empty;
public bool CanEdit { get; set; } // 是否可编辑(仅草稿状态)
public bool CanRevoke { get; set; } // 是否可撤销(仅待投递状态)
}
// 附件DTO
public class AttachmentDto
{
public string Id { get; set; } = string.Empty;
public string Type { get; set; } = string.Empty;
public string Url { get; set; } = string.Empty;
public string? Thumbnail { get; set; }
public long Size { get; set; }
}
// 更新胶囊邮件DTO
public class UpdateCapsuleMailDto
{
public string? Title { get; set; }
public string? Content { get; set; }
public RecipientTypeEnum? RecipientType { get; set; }
public string? RecipientEmail { get; set; }
public DateTime? SendTime { get; set; }
public TriggerTypeEnum? TriggerType { get; set; }
public object? TriggerCondition { get; set; }
public List<object>? Attachments { get; set; }
public bool? IsEncrypted { get; set; }
public string? CapsuleStyle { get; set; }
}
// 发送至未来请求DTO
public class SendToFutureDto
{
[Required(ErrorMessage = "邮件ID是必填项")]
public int MailId { get; set; }
[Required(ErrorMessage = "投递时间是必填项")]
public DateTime DeliveryTime { get; set; }
}
// 发送至未来响应DTO
public class SendToFutureResponseDto
{
public int MailId { get; set; }
public string Title { get; set; } = string.Empty;
public DateTime DeliveryTime { get; set; }
public string Status { get; set; } = string.Empty;
public DateTime SentAt { get; set; }
}
}

View File

@@ -60,6 +60,7 @@ namespace FutureMailAPI.DTOs
public int UserId { get; set; }
public string Username { get; set; } = string.Empty;
public string? Avatar { get; set; }
public string Email { get; set; } = string.Empty;
}
public class SubscriptionResponseDto

View File

@@ -36,7 +36,7 @@ namespace FutureMailAPI.Data
.HasForeignKey(e => e.SenderId)
.OnDelete(DeleteBehavior.Restrict);
entity.HasOne<User>()
entity.HasOne(e => e.Recipient)
.WithMany()
.HasForeignKey(e => e.RecipientId)
.OnDelete(DeleteBehavior.SetNull);
@@ -52,8 +52,8 @@ namespace FutureMailAPI.Data
.HasForeignKey(e => e.SentMailId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne<User>()
.WithMany()
entity.HasOne(e => e.Recipient)
.WithMany(u => u.ReceivedMails)
.HasForeignKey(e => e.RecipientId)
.OnDelete(DeleteBehavior.Cascade);
@@ -68,9 +68,10 @@ namespace FutureMailAPI.Data
.HasForeignKey(e => e.UserId)
.OnDelete(DeleteBehavior.Cascade);
// 一对一关系配置
entity.HasOne<SentMail>()
.WithMany()
.HasForeignKey(e => e.SentMailId)
.WithOne(m => m.TimeCapsule)
.HasForeignKey<TimeCapsule>(e => e.SentMailId)
.OnDelete(DeleteBehavior.Cascade);
entity.Property(e => e.CreatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP");

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,495 @@
// <auto-generated />
using System;
using FutureMailAPI.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace FutureMailAPI.Migrations
{
[DbContext(typeof(FutureMailDbContext))]
[Migration("20251018051334_AddSentMailCreatedAt")]
partial class AddSentMailCreatedAt
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.9");
modelBuilder.Entity("FutureMailAPI.Models.OAuthClient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClientId")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("ClientSecret")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<bool>("IsActive")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("RedirectUris")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Scopes")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("UpdatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.HasKey("Id");
b.HasIndex("ClientId")
.IsUnique();
b.ToTable("OAuthClients");
});
modelBuilder.Entity("FutureMailAPI.Models.OAuthToken", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("AccessToken")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<int>("ClientId")
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<DateTime>("ExpiresAt")
.HasColumnType("TEXT");
b.Property<string>("RefreshToken")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<DateTime?>("RevokedAt")
.HasColumnType("TEXT");
b.Property<string>("Scope")
.HasColumnType("TEXT");
b.Property<string>("TokenType")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("TEXT");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("AccessToken")
.IsUnique();
b.HasIndex("ClientId");
b.HasIndex("RefreshToken")
.IsUnique();
b.HasIndex("UserId");
b.ToTable("OAuthTokens");
});
modelBuilder.Entity("FutureMailAPI.Models.ReceivedMail", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<bool>("IsRead")
.HasColumnType("INTEGER");
b.Property<bool>("IsReplied")
.HasColumnType("INTEGER");
b.Property<DateTime?>("ReadAt")
.HasColumnType("TEXT");
b.Property<DateTime>("ReceivedAt")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<int>("RecipientId")
.HasColumnType("INTEGER");
b.Property<int>("RecipientId1")
.HasColumnType("INTEGER");
b.Property<int?>("ReplyMailId")
.HasColumnType("INTEGER");
b.Property<int>("SentMailId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("RecipientId");
b.HasIndex("RecipientId1");
b.HasIndex("SentMailId");
b.ToTable("ReceivedMails");
});
modelBuilder.Entity("FutureMailAPI.Models.SentMail", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Attachments")
.HasColumnType("TEXT");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<DateTime>("DeliveryTime")
.HasColumnType("TEXT");
b.Property<string>("EncryptionKey")
.HasColumnType("TEXT");
b.Property<bool>("IsEncrypted")
.HasColumnType("INTEGER");
b.Property<int?>("RecipientId")
.HasColumnType("INTEGER");
b.Property<int?>("RecipientId1")
.HasColumnType("INTEGER");
b.Property<int>("RecipientType")
.HasColumnType("INTEGER");
b.Property<int>("SenderId")
.HasColumnType("INTEGER");
b.Property<DateTime>("SentAt")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<int>("Status")
.HasColumnType("INTEGER");
b.Property<string>("Theme")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("TEXT");
b.Property<string>("TriggerDetails")
.HasColumnType("TEXT");
b.Property<int>("TriggerType")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("RecipientId");
b.HasIndex("RecipientId1");
b.HasIndex("SenderId");
b.ToTable("SentMails");
});
modelBuilder.Entity("FutureMailAPI.Models.TimeCapsule", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Color")
.HasMaxLength(20)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<double>("GlowIntensity")
.HasColumnType("REAL");
b.Property<double>("Opacity")
.HasColumnType("REAL");
b.Property<double>("PositionX")
.HasColumnType("REAL");
b.Property<double>("PositionY")
.HasColumnType("REAL");
b.Property<double>("PositionZ")
.HasColumnType("REAL");
b.Property<double>("Rotation")
.HasColumnType("REAL");
b.Property<int>("SentMailId")
.HasColumnType("INTEGER");
b.Property<int>("SentMailId1")
.HasColumnType("INTEGER");
b.Property<double>("Size")
.HasColumnType("REAL");
b.Property<int>("Status")
.HasColumnType("INTEGER");
b.Property<string>("Style")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("SentMailId")
.IsUnique();
b.HasIndex("SentMailId1");
b.HasIndex("UserId");
b.ToTable("TimeCapsules");
});
modelBuilder.Entity("FutureMailAPI.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Avatar")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<string>("Email")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<bool>("IsActive")
.HasColumnType("INTEGER");
b.Property<DateTime?>("LastLoginAt")
.HasColumnType("TEXT");
b.Property<string>("Nickname")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("PasswordHash")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<string>("PreferredBackground")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("PreferredScene")
.HasMaxLength(20)
.HasColumnType("TEXT");
b.Property<string>("RefreshToken")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<DateTime?>("RefreshTokenExpiryTime")
.HasColumnType("TEXT");
b.Property<string>("Salt")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Email")
.IsUnique();
b.HasIndex("Username")
.IsUnique();
b.ToTable("Users");
});
modelBuilder.Entity("FutureMailAPI.Models.OAuthToken", b =>
{
b.HasOne("FutureMailAPI.Models.OAuthClient", "Client")
.WithMany("Tokens")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FutureMailAPI.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("User");
});
modelBuilder.Entity("FutureMailAPI.Models.ReceivedMail", b =>
{
b.HasOne("FutureMailAPI.Models.User", null)
.WithMany()
.HasForeignKey("RecipientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FutureMailAPI.Models.User", "Recipient")
.WithMany("ReceivedMails")
.HasForeignKey("RecipientId1")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FutureMailAPI.Models.SentMail", "SentMail")
.WithMany()
.HasForeignKey("SentMailId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Recipient");
b.Navigation("SentMail");
});
modelBuilder.Entity("FutureMailAPI.Models.SentMail", b =>
{
b.HasOne("FutureMailAPI.Models.User", null)
.WithMany()
.HasForeignKey("RecipientId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("FutureMailAPI.Models.User", "Recipient")
.WithMany()
.HasForeignKey("RecipientId1");
b.HasOne("FutureMailAPI.Models.User", "Sender")
.WithMany("SentMails")
.HasForeignKey("SenderId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Recipient");
b.Navigation("Sender");
});
modelBuilder.Entity("FutureMailAPI.Models.TimeCapsule", b =>
{
b.HasOne("FutureMailAPI.Models.SentMail", null)
.WithOne("TimeCapsule")
.HasForeignKey("FutureMailAPI.Models.TimeCapsule", "SentMailId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FutureMailAPI.Models.SentMail", "SentMail")
.WithMany()
.HasForeignKey("SentMailId1")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FutureMailAPI.Models.User", "User")
.WithMany("TimeCapsules")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("SentMail");
b.Navigation("User");
});
modelBuilder.Entity("FutureMailAPI.Models.OAuthClient", b =>
{
b.Navigation("Tokens");
});
modelBuilder.Entity("FutureMailAPI.Models.SentMail", b =>
{
b.Navigation("TimeCapsule");
});
modelBuilder.Entity("FutureMailAPI.Models.User", b =>
{
b.Navigation("ReceivedMails");
b.Navigation("SentMails");
b.Navigation("TimeCapsules");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,71 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace FutureMailAPI.Migrations
{
/// <inheritdoc />
public partial class AddSentMailCreatedAt : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_TimeCapsules_SentMailId",
table: "TimeCapsules");
migrationBuilder.AddColumn<double>(
name: "GlowIntensity",
table: "TimeCapsules",
type: "REAL",
nullable: false,
defaultValue: 0.0);
migrationBuilder.AddColumn<string>(
name: "Style",
table: "TimeCapsules",
type: "TEXT",
maxLength: 50,
nullable: true);
migrationBuilder.AddColumn<DateTime>(
name: "CreatedAt",
table: "SentMails",
type: "TEXT",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
migrationBuilder.CreateIndex(
name: "IX_TimeCapsules_SentMailId",
table: "TimeCapsules",
column: "SentMailId",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_TimeCapsules_SentMailId",
table: "TimeCapsules");
migrationBuilder.DropColumn(
name: "GlowIntensity",
table: "TimeCapsules");
migrationBuilder.DropColumn(
name: "Style",
table: "TimeCapsules");
migrationBuilder.DropColumn(
name: "CreatedAt",
table: "SentMails");
migrationBuilder.CreateIndex(
name: "IX_TimeCapsules_SentMailId",
table: "TimeCapsules",
column: "SentMailId");
}
}
}

View File

@@ -0,0 +1,475 @@
// <auto-generated />
using System;
using FutureMailAPI.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace FutureMailAPI.Migrations
{
[DbContext(typeof(FutureMailDbContext))]
[Migration("20251018071917_FixDuplicateForeignKeys")]
partial class FixDuplicateForeignKeys
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.9");
modelBuilder.Entity("FutureMailAPI.Models.OAuthClient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClientId")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("ClientSecret")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<bool>("IsActive")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("RedirectUris")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Scopes")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("UpdatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.HasKey("Id");
b.HasIndex("ClientId")
.IsUnique();
b.ToTable("OAuthClients");
});
modelBuilder.Entity("FutureMailAPI.Models.OAuthToken", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("AccessToken")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<int>("ClientId")
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<DateTime>("ExpiresAt")
.HasColumnType("TEXT");
b.Property<string>("RefreshToken")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<DateTime?>("RevokedAt")
.HasColumnType("TEXT");
b.Property<string>("Scope")
.HasColumnType("TEXT");
b.Property<string>("TokenType")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("TEXT");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("AccessToken")
.IsUnique();
b.HasIndex("ClientId");
b.HasIndex("RefreshToken")
.IsUnique();
b.HasIndex("UserId");
b.ToTable("OAuthTokens");
});
modelBuilder.Entity("FutureMailAPI.Models.ReceivedMail", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<bool>("IsRead")
.HasColumnType("INTEGER");
b.Property<bool>("IsReplied")
.HasColumnType("INTEGER");
b.Property<DateTime?>("ReadAt")
.HasColumnType("TEXT");
b.Property<DateTime>("ReceivedAt")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<int>("RecipientId")
.HasColumnType("INTEGER");
b.Property<int?>("ReplyMailId")
.HasColumnType("INTEGER");
b.Property<int>("SentMailId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("RecipientId");
b.HasIndex("SentMailId");
b.ToTable("ReceivedMails");
});
modelBuilder.Entity("FutureMailAPI.Models.SentMail", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Attachments")
.HasColumnType("TEXT");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<DateTime>("DeliveryTime")
.HasColumnType("TEXT");
b.Property<string>("EncryptionKey")
.HasColumnType("TEXT");
b.Property<bool>("IsEncrypted")
.HasColumnType("INTEGER");
b.Property<int?>("RecipientId")
.HasColumnType("INTEGER");
b.Property<int>("RecipientType")
.HasColumnType("INTEGER");
b.Property<int>("SenderId")
.HasColumnType("INTEGER");
b.Property<DateTime>("SentAt")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<int>("Status")
.HasColumnType("INTEGER");
b.Property<string>("Theme")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("TEXT");
b.Property<string>("TriggerDetails")
.HasColumnType("TEXT");
b.Property<int>("TriggerType")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("RecipientId");
b.HasIndex("SenderId");
b.ToTable("SentMails");
});
modelBuilder.Entity("FutureMailAPI.Models.TimeCapsule", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Color")
.HasMaxLength(20)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<double>("GlowIntensity")
.HasColumnType("REAL");
b.Property<double>("Opacity")
.HasColumnType("REAL");
b.Property<double>("PositionX")
.HasColumnType("REAL");
b.Property<double>("PositionY")
.HasColumnType("REAL");
b.Property<double>("PositionZ")
.HasColumnType("REAL");
b.Property<double>("Rotation")
.HasColumnType("REAL");
b.Property<int>("SentMailId")
.HasColumnType("INTEGER");
b.Property<int>("SentMailId1")
.HasColumnType("INTEGER");
b.Property<double>("Size")
.HasColumnType("REAL");
b.Property<int>("Status")
.HasColumnType("INTEGER");
b.Property<string>("Style")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.Property<int>("UserId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("SentMailId")
.IsUnique();
b.HasIndex("SentMailId1");
b.HasIndex("UserId");
b.ToTable("TimeCapsules");
});
modelBuilder.Entity("FutureMailAPI.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Avatar")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<string>("Email")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<bool>("IsActive")
.HasColumnType("INTEGER");
b.Property<DateTime?>("LastLoginAt")
.HasColumnType("TEXT");
b.Property<string>("Nickname")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("PasswordHash")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<string>("PreferredBackground")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("PreferredScene")
.HasMaxLength(20)
.HasColumnType("TEXT");
b.Property<string>("RefreshToken")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<DateTime?>("RefreshTokenExpiryTime")
.HasColumnType("TEXT");
b.Property<string>("Salt")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Email")
.IsUnique();
b.HasIndex("Username")
.IsUnique();
b.ToTable("Users");
});
modelBuilder.Entity("FutureMailAPI.Models.OAuthToken", b =>
{
b.HasOne("FutureMailAPI.Models.OAuthClient", "Client")
.WithMany("Tokens")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FutureMailAPI.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("User");
});
modelBuilder.Entity("FutureMailAPI.Models.ReceivedMail", b =>
{
b.HasOne("FutureMailAPI.Models.User", "Recipient")
.WithMany("ReceivedMails")
.HasForeignKey("RecipientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FutureMailAPI.Models.SentMail", "SentMail")
.WithMany()
.HasForeignKey("SentMailId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Recipient");
b.Navigation("SentMail");
});
modelBuilder.Entity("FutureMailAPI.Models.SentMail", b =>
{
b.HasOne("FutureMailAPI.Models.User", "Recipient")
.WithMany()
.HasForeignKey("RecipientId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("FutureMailAPI.Models.User", "Sender")
.WithMany("SentMails")
.HasForeignKey("SenderId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Recipient");
b.Navigation("Sender");
});
modelBuilder.Entity("FutureMailAPI.Models.TimeCapsule", b =>
{
b.HasOne("FutureMailAPI.Models.SentMail", null)
.WithOne("TimeCapsule")
.HasForeignKey("FutureMailAPI.Models.TimeCapsule", "SentMailId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FutureMailAPI.Models.SentMail", "SentMail")
.WithMany()
.HasForeignKey("SentMailId1")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FutureMailAPI.Models.User", "User")
.WithMany("TimeCapsules")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("SentMail");
b.Navigation("User");
});
modelBuilder.Entity("FutureMailAPI.Models.OAuthClient", b =>
{
b.Navigation("Tokens");
});
modelBuilder.Entity("FutureMailAPI.Models.SentMail", b =>
{
b.Navigation("TimeCapsule");
});
modelBuilder.Entity("FutureMailAPI.Models.User", b =>
{
b.Navigation("ReceivedMails");
b.Navigation("SentMails");
b.Navigation("TimeCapsules");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,80 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace FutureMailAPI.Migrations
{
/// <inheritdoc />
public partial class FixDuplicateForeignKeys : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_ReceivedMails_Users_RecipientId1",
table: "ReceivedMails");
migrationBuilder.DropForeignKey(
name: "FK_SentMails_Users_RecipientId1",
table: "SentMails");
migrationBuilder.DropIndex(
name: "IX_SentMails_RecipientId1",
table: "SentMails");
migrationBuilder.DropIndex(
name: "IX_ReceivedMails_RecipientId1",
table: "ReceivedMails");
migrationBuilder.DropColumn(
name: "RecipientId1",
table: "SentMails");
migrationBuilder.DropColumn(
name: "RecipientId1",
table: "ReceivedMails");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "RecipientId1",
table: "SentMails",
type: "INTEGER",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "RecipientId1",
table: "ReceivedMails",
type: "INTEGER",
nullable: false,
defaultValue: 0);
migrationBuilder.CreateIndex(
name: "IX_SentMails_RecipientId1",
table: "SentMails",
column: "RecipientId1");
migrationBuilder.CreateIndex(
name: "IX_ReceivedMails_RecipientId1",
table: "ReceivedMails",
column: "RecipientId1");
migrationBuilder.AddForeignKey(
name: "FK_ReceivedMails_Users_RecipientId1",
table: "ReceivedMails",
column: "RecipientId1",
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_SentMails_Users_RecipientId1",
table: "SentMails",
column: "RecipientId1",
principalTable: "Users",
principalColumn: "Id");
}
}
}

View File

@@ -148,9 +148,6 @@ namespace FutureMailAPI.Migrations
b.Property<int>("RecipientId")
.HasColumnType("INTEGER");
b.Property<int>("RecipientId1")
.HasColumnType("INTEGER");
b.Property<int?>("ReplyMailId")
.HasColumnType("INTEGER");
@@ -161,8 +158,6 @@ namespace FutureMailAPI.Migrations
b.HasIndex("RecipientId");
b.HasIndex("RecipientId1");
b.HasIndex("SentMailId");
b.ToTable("ReceivedMails");
@@ -181,6 +176,9 @@ namespace FutureMailAPI.Migrations
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<DateTime>("DeliveryTime")
.HasColumnType("TEXT");
@@ -193,9 +191,6 @@ namespace FutureMailAPI.Migrations
b.Property<int?>("RecipientId")
.HasColumnType("INTEGER");
b.Property<int?>("RecipientId1")
.HasColumnType("INTEGER");
b.Property<int>("RecipientType")
.HasColumnType("INTEGER");
@@ -229,8 +224,6 @@ namespace FutureMailAPI.Migrations
b.HasIndex("RecipientId");
b.HasIndex("RecipientId1");
b.HasIndex("SenderId");
b.ToTable("SentMails");
@@ -251,6 +244,9 @@ namespace FutureMailAPI.Migrations
.HasColumnType("TEXT")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<double>("GlowIntensity")
.HasColumnType("REAL");
b.Property<double>("Opacity")
.HasColumnType("REAL");
@@ -278,6 +274,10 @@ namespace FutureMailAPI.Migrations
b.Property<int>("Status")
.HasColumnType("INTEGER");
b.Property<string>("Style")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
@@ -286,7 +286,8 @@ namespace FutureMailAPI.Migrations
b.HasKey("Id");
b.HasIndex("SentMailId");
b.HasIndex("SentMailId")
.IsUnique();
b.HasIndex("SentMailId1");
@@ -387,15 +388,9 @@ namespace FutureMailAPI.Migrations
modelBuilder.Entity("FutureMailAPI.Models.ReceivedMail", b =>
{
b.HasOne("FutureMailAPI.Models.User", null)
.WithMany()
.HasForeignKey("RecipientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FutureMailAPI.Models.User", "Recipient")
.WithMany("ReceivedMails")
.HasForeignKey("RecipientId1")
.HasForeignKey("RecipientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -412,15 +407,11 @@ namespace FutureMailAPI.Migrations
modelBuilder.Entity("FutureMailAPI.Models.SentMail", b =>
{
b.HasOne("FutureMailAPI.Models.User", null)
b.HasOne("FutureMailAPI.Models.User", "Recipient")
.WithMany()
.HasForeignKey("RecipientId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("FutureMailAPI.Models.User", "Recipient")
.WithMany()
.HasForeignKey("RecipientId1");
b.HasOne("FutureMailAPI.Models.User", "Sender")
.WithMany("SentMails")
.HasForeignKey("SenderId")
@@ -435,8 +426,8 @@ namespace FutureMailAPI.Migrations
modelBuilder.Entity("FutureMailAPI.Models.TimeCapsule", b =>
{
b.HasOne("FutureMailAPI.Models.SentMail", null)
.WithMany()
.HasForeignKey("SentMailId")
.WithOne("TimeCapsule")
.HasForeignKey("FutureMailAPI.Models.TimeCapsule", "SentMailId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -462,6 +453,11 @@ namespace FutureMailAPI.Migrations
b.Navigation("Tokens");
});
modelBuilder.Entity("FutureMailAPI.Models.SentMail", b =>
{
b.Navigation("TimeCapsule");
});
modelBuilder.Entity("FutureMailAPI.Models.User", b =>
{
b.Navigation("ReceivedMails");

View File

@@ -28,6 +28,9 @@ namespace FutureMailAPI.Models
// 发送时间
public DateTime SentAt { get; set; } = DateTime.UtcNow;
// 创建时间
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
// 投递时间
[Required]
public DateTime DeliveryTime { get; set; }
@@ -61,5 +64,7 @@ namespace FutureMailAPI.Models
public virtual User Sender { get; set; } = null!;
public virtual User? Recipient { get; set; }
public virtual TimeCapsule? TimeCapsule { get; set; }
}
}

View File

@@ -32,6 +32,13 @@ namespace FutureMailAPI.Models
// 胶囊旋转角度
public double Rotation { get; set; } = 0;
// 胶囊样式/皮肤
[MaxLength(50)]
public string? Style { get; set; }
// 发光强度
public double GlowIntensity { get; set; } = 0.8;
// 胶囊状态: 0-未激活, 1-漂浮中, 2-即将到达, 3-已开启
[Required]
public int Status { get; set; } = 0;

View File

@@ -17,5 +17,15 @@ namespace FutureMailAPI.Services
Task<ApiResponse<bool>> MarkReceivedMailAsReadAsync(int userId, int mailId);
Task<ApiResponse<bool>> MarkAsReadAsync(int userId, int mailId);
Task<ApiResponse<bool>> RevokeMailAsync(int userId, int mailId);
// 存入胶囊相关方法
Task<ApiResponse<SaveToCapsuleResponseDto>> SaveToCapsuleAsync(int userId, SaveToCapsuleDto saveToCapsuleDto);
Task<ApiResponse<PagedResponse<CapsuleMailListResponseDto>>> GetCapsuleMailsAsync(int userId, MailListQueryDto queryDto);
Task<ApiResponse<CapsuleMailDetailResponseDto>> GetCapsuleMailByIdAsync(int userId, int mailId);
Task<ApiResponse<CapsuleMailDetailResponseDto>> UpdateCapsuleMailAsync(int userId, int mailId, UpdateCapsuleMailDto updateDto);
Task<ApiResponse<bool>> RevokeCapsuleMailAsync(int userId, int mailId);
// 发送至未来功能
Task<ApiResponse<SendToFutureResponseDto>> SendToFutureAsync(int userId, SendToFutureDto sendToFutureDto);
}
}

View File

@@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore;
using FutureMailAPI.Data;
using FutureMailAPI.Models;
using FutureMailAPI.DTOs;
using System.Text.Json;
namespace FutureMailAPI.Services
{
@@ -382,6 +383,393 @@ namespace FutureMailAPI.Services
return ApiResponse<bool>.SuccessResult(true, "邮件已撤销");
}
// 存入胶囊相关方法实现
public async Task<ApiResponse<SaveToCapsuleResponseDto>> SaveToCapsuleAsync(int userId, SaveToCapsuleDto saveToCapsuleDto)
{
// 验证收件人类型
if (saveToCapsuleDto.RecipientType == RecipientTypeEnum.SPECIFIC && string.IsNullOrEmpty(saveToCapsuleDto.RecipientEmail))
{
return ApiResponse<SaveToCapsuleResponseDto>.ErrorResult("指定收件人时,收件人邮箱是必填项");
}
// 验证发送时间
if (saveToCapsuleDto.SendTime.HasValue && saveToCapsuleDto.SendTime.Value <= DateTime.UtcNow)
{
return ApiResponse<SaveToCapsuleResponseDto>.ErrorResult("发送时间必须是未来时间");
}
// 创建邮件
var mail = new SentMail
{
Title = saveToCapsuleDto.Title,
Content = saveToCapsuleDto.Content,
SenderId = userId,
RecipientType = (int)saveToCapsuleDto.RecipientType,
SentAt = DateTime.UtcNow,
CreatedAt = DateTime.UtcNow,
DeliveryTime = saveToCapsuleDto.SendTime ?? DateTime.UtcNow.AddDays(1), // 默认一天后发送
Status = 0, // 草稿状态
TriggerType = (int)saveToCapsuleDto.TriggerType,
TriggerDetails = saveToCapsuleDto.TriggerCondition != null ? JsonSerializer.Serialize(saveToCapsuleDto.TriggerCondition) : null,
Attachments = saveToCapsuleDto.Attachments != null ? JsonSerializer.Serialize(saveToCapsuleDto.Attachments) : null,
IsEncrypted = saveToCapsuleDto.IsEncrypted,
Theme = saveToCapsuleDto.CapsuleStyle
};
// 如果是指定收件人查找收件人ID
if (saveToCapsuleDto.RecipientType == RecipientTypeEnum.SPECIFIC && !string.IsNullOrEmpty(saveToCapsuleDto.RecipientEmail))
{
var recipient = await _context.Users
.FirstOrDefaultAsync(u => u.Email == saveToCapsuleDto.RecipientEmail);
if (recipient == null)
{
return ApiResponse<SaveToCapsuleResponseDto>.ErrorResult("收件人不存在");
}
mail.RecipientId = recipient.Id;
}
_context.SentMails.Add(mail);
await _context.SaveChangesAsync();
// 创建时间胶囊
var timeCapsule = new TimeCapsule
{
UserId = userId,
SentMailId = mail.Id,
Status = 0, // 草稿状态
CreatedAt = DateTime.UtcNow,
PositionX = 0.5f, // 默认位置
PositionY = 0.5f,
PositionZ = 0.5f,
Style = saveToCapsuleDto.CapsuleStyle,
GlowIntensity = 0.8f // 默认发光强度
};
_context.TimeCapsules.Add(timeCapsule);
await _context.SaveChangesAsync();
var response = new SaveToCapsuleResponseDto
{
Id = mail.Id,
MailId = mail.Id.ToString(),
CapsuleId = timeCapsule.Id.ToString(),
Status = "DRAFT",
CreatedAt = mail.CreatedAt
};
return ApiResponse<SaveToCapsuleResponseDto>.SuccessResult(response, "邮件已存入胶囊");
}
public async Task<ApiResponse<PagedResponse<CapsuleMailListResponseDto>>> GetCapsuleMailsAsync(int userId, MailListQueryDto queryDto)
{
var query = _context.SentMails
.Where(m => m.SenderId == userId && m.Status == 0) // 只查询草稿状态的邮件
.Include(m => m.Sender)
.Include(m => m.Recipient)
.Include(m => m.TimeCapsule)
.AsQueryable();
// 应用筛选条件
if (queryDto.Status.HasValue)
{
query = query.Where(m => m.Status == queryDto.Status.Value);
}
if (queryDto.RecipientType.HasValue)
{
query = query.Where(m => m.RecipientType == queryDto.RecipientType.Value);
}
if (!string.IsNullOrEmpty(queryDto.Keyword))
{
query = query.Where(m => m.Title.Contains(queryDto.Keyword) || m.Content.Contains(queryDto.Keyword));
}
if (queryDto.StartDate.HasValue)
{
query = query.Where(m => m.SentAt >= queryDto.StartDate.Value);
}
if (queryDto.EndDate.HasValue)
{
query = query.Where(m => m.SentAt <= queryDto.EndDate.Value);
}
// 排序
query = query.OrderByDescending(m => m.SentAt);
// 分页
var totalCount = await query.CountAsync();
var mails = await query
.Skip((queryDto.PageIndex - 1) * queryDto.PageSize)
.Take(queryDto.PageSize)
.ToListAsync();
var mailDtos = mails.Select(MapToCapsuleMailListResponseDto).ToList();
var pagedResponse = new PagedResponse<CapsuleMailListResponseDto>(
mailDtos, queryDto.PageIndex, queryDto.PageSize, totalCount);
return ApiResponse<PagedResponse<CapsuleMailListResponseDto>>.SuccessResult(pagedResponse);
}
public async Task<ApiResponse<CapsuleMailDetailResponseDto>> GetCapsuleMailByIdAsync(int userId, int mailId)
{
var mail = await _context.SentMails
.Include(m => m.Sender)
.Include(m => m.Recipient)
.Include(m => m.TimeCapsule)
.FirstOrDefaultAsync(m => m.Id == mailId && m.SenderId == userId);
if (mail == null)
{
return ApiResponse<CapsuleMailDetailResponseDto>.ErrorResult("邮件不存在");
}
var mailDto = MapToCapsuleMailDetailResponseDto(mail);
return ApiResponse<CapsuleMailDetailResponseDto>.SuccessResult(mailDto);
}
public async Task<ApiResponse<CapsuleMailDetailResponseDto>> UpdateCapsuleMailAsync(int userId, int mailId, UpdateCapsuleMailDto updateDto)
{
var mail = await _context.SentMails
.Include(m => m.Sender)
.Include(m => m.Recipient)
.Include(m => m.TimeCapsule)
.FirstOrDefaultAsync(m => m.Id == mailId && m.SenderId == userId);
if (mail == null)
{
return ApiResponse<CapsuleMailDetailResponseDto>.ErrorResult("邮件不存在");
}
// 检查邮件状态,只有草稿状态的邮件才能编辑
if (mail.Status != 0)
{
return ApiResponse<CapsuleMailDetailResponseDto>.ErrorResult("只有草稿状态的邮件才能编辑");
}
// 更新邮件信息
if (!string.IsNullOrEmpty(updateDto.Title))
{
mail.Title = updateDto.Title;
}
if (!string.IsNullOrEmpty(updateDto.Content))
{
mail.Content = updateDto.Content;
}
if (updateDto.RecipientType.HasValue)
{
mail.RecipientType = (int)updateDto.RecipientType.Value;
// 如果是指定收件人查找收件人ID
if (updateDto.RecipientType.Value == RecipientTypeEnum.SPECIFIC && !string.IsNullOrEmpty(updateDto.RecipientEmail))
{
var recipient = await _context.Users
.FirstOrDefaultAsync(u => u.Email == updateDto.RecipientEmail);
if (recipient == null)
{
return ApiResponse<CapsuleMailDetailResponseDto>.ErrorResult("收件人不存在");
}
mail.RecipientId = recipient.Id;
}
}
if (updateDto.SendTime.HasValue)
{
if (updateDto.SendTime.Value <= DateTime.UtcNow)
{
return ApiResponse<CapsuleMailDetailResponseDto>.ErrorResult("发送时间必须是未来时间");
}
mail.DeliveryTime = updateDto.SendTime.Value;
}
if (updateDto.TriggerType.HasValue)
{
mail.TriggerType = (int)updateDto.TriggerType.Value;
}
if (updateDto.TriggerCondition != null)
{
mail.TriggerDetails = JsonSerializer.Serialize(updateDto.TriggerCondition);
}
if (updateDto.Attachments != null)
{
mail.Attachments = JsonSerializer.Serialize(updateDto.Attachments);
}
if (updateDto.IsEncrypted.HasValue)
{
mail.IsEncrypted = updateDto.IsEncrypted.Value;
}
if (!string.IsNullOrEmpty(updateDto.CapsuleStyle))
{
mail.Theme = updateDto.CapsuleStyle;
// 更新时间胶囊样式
if (mail.TimeCapsule != null)
{
mail.TimeCapsule.Style = updateDto.CapsuleStyle;
}
}
await _context.SaveChangesAsync();
var mailResponse = MapToCapsuleMailDetailResponseDto(mail);
return ApiResponse<CapsuleMailDetailResponseDto>.SuccessResult(mailResponse, "胶囊邮件更新成功");
}
public async Task<ApiResponse<bool>> RevokeCapsuleMailAsync(int userId, int mailId)
{
var mail = await _context.SentMails
.Include(m => m.TimeCapsule)
.FirstOrDefaultAsync(m => m.Id == mailId && m.SenderId == userId);
if (mail == null)
{
return ApiResponse<bool>.ErrorResult("邮件不存在");
}
// 检查邮件状态,只有草稿或待投递状态的邮件才能撤销
if (mail.Status > 1)
{
return ApiResponse<bool>.ErrorResult("已投递的邮件不能撤销");
}
// 更新邮件状态为已撤销
mail.Status = 4; // 4-已撤销
await _context.SaveChangesAsync();
// 更新相关的时间胶囊状态
if (mail.TimeCapsule != null)
{
mail.TimeCapsule.Status = 3; // 3-已撤销
await _context.SaveChangesAsync();
}
return ApiResponse<bool>.SuccessResult(true, "胶囊邮件已撤销");
}
private static CapsuleMailListResponseDto MapToCapsuleMailListResponseDto(SentMail mail)
{
return new CapsuleMailListResponseDto
{
MailId = mail.Id.ToString(),
Title = mail.Title,
Sender = MapToUserInfoDto(mail.Sender),
Recipient = mail.Recipient != null ? MapToUserInfoDto(mail.Recipient) : new UserInfoDto(),
SendTime = mail.SentAt,
DeliveryTime = mail.DeliveryTime,
Status = mail.Status switch
{
0 => "DRAFT",
1 => "PENDING",
2 => "DELIVERING",
3 => "DELIVERED",
_ => "UNKNOWN"
},
HasAttachments = !string.IsNullOrEmpty(mail.Attachments),
IsEncrypted = mail.IsEncrypted,
CapsuleStyle = mail.Theme ?? "default",
Countdown = mail.Status == 1 ? (int)(mail.DeliveryTime - DateTime.UtcNow).TotalSeconds : null
};
}
private static CapsuleMailDetailResponseDto MapToCapsuleMailDetailResponseDto(SentMail mail)
{
List<AttachmentDto> attachments = new List<AttachmentDto>();
if (!string.IsNullOrEmpty(mail.Attachments))
{
try
{
var attachmentList = JsonSerializer.Deserialize<List<object>>(mail.Attachments);
if (attachmentList != null)
{
attachments = attachmentList.Select(a => new AttachmentDto
{
Id = Guid.NewGuid().ToString(),
Type = "IMAGE", // 默认类型,实际应根据数据解析
Url = a.ToString() ?? "",
Size = 0 // 默认大小,实际应根据数据解析
}).ToList();
}
}
catch
{
// 解析失败时忽略附件
}
}
object? triggerCondition = null;
if (!string.IsNullOrEmpty(mail.TriggerDetails))
{
try
{
triggerCondition = JsonSerializer.Deserialize<object>(mail.TriggerDetails);
}
catch
{
// 解析失败时忽略触发条件
}
}
return new CapsuleMailDetailResponseDto
{
MailId = mail.Id.ToString(),
Title = mail.Title,
Content = mail.Content,
Sender = MapToUserInfoDto(mail.Sender),
Recipient = mail.Recipient != null ? MapToUserInfoDto(mail.Recipient) : new UserInfoDto(),
SendTime = mail.SentAt,
CreatedAt = mail.CreatedAt,
DeliveryTime = mail.DeliveryTime,
Status = mail.Status switch
{
0 => "DRAFT",
1 => "PENDING",
2 => "DELIVERING",
3 => "DELIVERED",
_ => "UNKNOWN"
},
TriggerType = mail.TriggerType switch
{
0 => "TIME",
1 => "LOCATION",
2 => "EVENT",
_ => "UNKNOWN"
},
TriggerCondition = triggerCondition,
Attachments = attachments,
IsEncrypted = mail.IsEncrypted,
CapsuleStyle = mail.Theme ?? "default",
CanEdit = mail.Status == 0, // 只有草稿状态可编辑
CanRevoke = mail.Status <= 1 // 草稿或待投递状态可撤销
};
}
private static UserInfoDto MapToUserInfoDto(User user)
{
return new UserInfoDto
{
UserId = user.Id,
Username = user.Username,
Avatar = user.Avatar ?? "",
Email = user.Email
};
}
private async Task<SentMailResponseDto> GetSentMailWithDetailsAsync(int mailId)
{
var mail = await _context.SentMails
@@ -471,5 +859,70 @@ namespace FutureMailAPI.Services
_ => "未知"
};
}
/// <summary>
/// 发送至未来 - 将草稿状态的邮件设置为在未来特定时间自动发送
/// </summary>
/// <param name="userId">用户ID</param>
/// <param name="sendToFutureDto">发送至未来请求DTO</param>
/// <returns>发送至未来响应DTO</returns>
public async Task<ApiResponse<SendToFutureResponseDto>> SendToFutureAsync(int userId, SendToFutureDto sendToFutureDto)
{
// 检查投递时间是否在未来
if (sendToFutureDto.DeliveryTime <= DateTime.UtcNow)
{
return ApiResponse<SendToFutureResponseDto>.ErrorResult("投递时间必须是未来时间");
}
// 查找邮件
var mail = await _context.SentMails
.Include(m => m.Sender)
.FirstOrDefaultAsync(m => m.Id == sendToFutureDto.MailId && m.SenderId == userId);
if (mail == null)
{
return ApiResponse<SendToFutureResponseDto>.ErrorResult("邮件不存在");
}
// 检查邮件是否为草稿状态
if (mail.Status != 0)
{
return ApiResponse<SendToFutureResponseDto>.ErrorResult("只有草稿状态的邮件可以设置为发送至未来");
}
// 更新邮件状态和投递时间
mail.DeliveryTime = sendToFutureDto.DeliveryTime;
mail.Status = 1; // 设置为已发送(待投递)状态
mail.SentAt = DateTime.UtcNow; // 设置发送时间为当前时间
await _context.SaveChangesAsync();
// 创建时间胶囊
var timeCapsule = new TimeCapsule
{
UserId = userId,
SentMailId = mail.Id,
PositionX = 0,
PositionY = 0,
PositionZ = 0,
Status = 1, // 漂浮中
Type = 0 // 普通
};
_context.TimeCapsules.Add(timeCapsule);
await _context.SaveChangesAsync();
// 构建响应
var response = new SendToFutureResponseDto
{
MailId = mail.Id,
Title = mail.Title,
DeliveryTime = mail.DeliveryTime,
Status = GetStatusText(mail.Status),
SentAt = mail.SentAt
};
return ApiResponse<SendToFutureResponseDto>.SuccessResult(response, "邮件已设置为发送至未来");
}
}
}

View File

@@ -83,6 +83,55 @@
<param name="fileId">文件ID</param>
<returns>文件信息</returns>
</member>
<member name="M:FutureMailAPI.Controllers.MailsController.SaveToCapsule(FutureMailAPI.DTOs.SaveToCapsuleDto)">
<summary>
存入胶囊 - 创建胶囊邮件
</summary>
<param name="dto">存入胶囊请求</param>
<returns>操作结果</returns>
</member>
<member name="M:FutureMailAPI.Controllers.MailsController.GetCapsuleMails(System.Int32,System.Int32,System.Nullable{System.Int32},System.Nullable{System.Int32},System.String,System.Nullable{System.DateTime},System.Nullable{System.DateTime})">
<summary>
获取胶囊邮件列表
</summary>
<param name="pageIndex">页码</param>
<param name="pageSize">页大小</param>
<param name="status">状态筛选</param>
<param name="recipientType">收件人类型筛选</param>
<param name="keyword">关键词搜索</param>
<param name="startDate">开始日期</param>
<param name="endDate">结束日期</param>
<returns>胶囊邮件列表</returns>
</member>
<member name="M:FutureMailAPI.Controllers.MailsController.GetCapsuleMail(System.Int32)">
<summary>
获取胶囊邮件详情
</summary>
<param name="id">邮件ID</param>
<returns>胶囊邮件详情</returns>
</member>
<member name="M:FutureMailAPI.Controllers.MailsController.UpdateCapsuleMail(System.Int32,FutureMailAPI.DTOs.UpdateCapsuleMailDto)">
<summary>
更新胶囊邮件
</summary>
<param name="id">邮件ID</param>
<param name="dto">更新请求</param>
<returns>更新后的胶囊邮件详情</returns>
</member>
<member name="M:FutureMailAPI.Controllers.MailsController.RevokeCapsuleMail(System.Int32)">
<summary>
撤销胶囊邮件
</summary>
<param name="id">邮件ID</param>
<returns>操作结果</returns>
</member>
<member name="M:FutureMailAPI.Controllers.MailsController.SendToFuture(FutureMailAPI.DTOs.SendToFutureDto)">
<summary>
发送至未来 - 将草稿状态的邮件设置为在未来特定时间自动发送
</summary>
<param name="sendToFutureDto">发送至未来请求DTO</param>
<returns>发送至未来响应DTO</returns>
</member>
<member name="M:FutureMailAPI.Controllers.NotificationController.RegisterDevice(FutureMailAPI.DTOs.NotificationDeviceRequestDto)">
<summary>
注册设备
@@ -207,5 +256,37 @@
<member name="M:FutureMailAPI.Migrations.AddSaltToUser.Down(Microsoft.EntityFrameworkCore.Migrations.MigrationBuilder)">
<inheritdoc />
</member>
<member name="T:FutureMailAPI.Migrations.AddSentMailCreatedAt">
<inheritdoc />
</member>
<member name="M:FutureMailAPI.Migrations.AddSentMailCreatedAt.Up(Microsoft.EntityFrameworkCore.Migrations.MigrationBuilder)">
<inheritdoc />
</member>
<member name="M:FutureMailAPI.Migrations.AddSentMailCreatedAt.Down(Microsoft.EntityFrameworkCore.Migrations.MigrationBuilder)">
<inheritdoc />
</member>
<member name="M:FutureMailAPI.Migrations.AddSentMailCreatedAt.BuildTargetModel(Microsoft.EntityFrameworkCore.ModelBuilder)">
<inheritdoc />
</member>
<member name="T:FutureMailAPI.Migrations.FixDuplicateForeignKeys">
<inheritdoc />
</member>
<member name="M:FutureMailAPI.Migrations.FixDuplicateForeignKeys.Up(Microsoft.EntityFrameworkCore.Migrations.MigrationBuilder)">
<inheritdoc />
</member>
<member name="M:FutureMailAPI.Migrations.FixDuplicateForeignKeys.Down(Microsoft.EntityFrameworkCore.Migrations.MigrationBuilder)">
<inheritdoc />
</member>
<member name="M:FutureMailAPI.Migrations.FixDuplicateForeignKeys.BuildTargetModel(Microsoft.EntityFrameworkCore.ModelBuilder)">
<inheritdoc />
</member>
<member name="M:FutureMailAPI.Services.MailService.SendToFutureAsync(System.Int32,FutureMailAPI.DTOs.SendToFutureDto)">
<summary>
发送至未来 - 将草稿状态的邮件设置为在未来特定时间自动发送
</summary>
<param name="userId">用户ID</param>
<param name="sendToFutureDto">发送至未来请求DTO</param>
<returns>发送至未来响应DTO</returns>
</member>
</members>
</doc>

View File

@@ -1 +1 @@
51372bde626c0ba3aa5386f92d0ea465adcc4b558852e21737182a326708e608
96b95197304e11878aba7d6a0ad52cc38a6b9883e011012e3da5e389d5e93831

View File

@@ -83,6 +83,55 @@
<param name="fileId">文件ID</param>
<returns>文件信息</returns>
</member>
<member name="M:FutureMailAPI.Controllers.MailsController.SaveToCapsule(FutureMailAPI.DTOs.SaveToCapsuleDto)">
<summary>
存入胶囊 - 创建胶囊邮件
</summary>
<param name="dto">存入胶囊请求</param>
<returns>操作结果</returns>
</member>
<member name="M:FutureMailAPI.Controllers.MailsController.GetCapsuleMails(System.Int32,System.Int32,System.Nullable{System.Int32},System.Nullable{System.Int32},System.String,System.Nullable{System.DateTime},System.Nullable{System.DateTime})">
<summary>
获取胶囊邮件列表
</summary>
<param name="pageIndex">页码</param>
<param name="pageSize">页大小</param>
<param name="status">状态筛选</param>
<param name="recipientType">收件人类型筛选</param>
<param name="keyword">关键词搜索</param>
<param name="startDate">开始日期</param>
<param name="endDate">结束日期</param>
<returns>胶囊邮件列表</returns>
</member>
<member name="M:FutureMailAPI.Controllers.MailsController.GetCapsuleMail(System.Int32)">
<summary>
获取胶囊邮件详情
</summary>
<param name="id">邮件ID</param>
<returns>胶囊邮件详情</returns>
</member>
<member name="M:FutureMailAPI.Controllers.MailsController.UpdateCapsuleMail(System.Int32,FutureMailAPI.DTOs.UpdateCapsuleMailDto)">
<summary>
更新胶囊邮件
</summary>
<param name="id">邮件ID</param>
<param name="dto">更新请求</param>
<returns>更新后的胶囊邮件详情</returns>
</member>
<member name="M:FutureMailAPI.Controllers.MailsController.RevokeCapsuleMail(System.Int32)">
<summary>
撤销胶囊邮件
</summary>
<param name="id">邮件ID</param>
<returns>操作结果</returns>
</member>
<member name="M:FutureMailAPI.Controllers.MailsController.SendToFuture(FutureMailAPI.DTOs.SendToFutureDto)">
<summary>
发送至未来 - 将草稿状态的邮件设置为在未来特定时间自动发送
</summary>
<param name="sendToFutureDto">发送至未来请求DTO</param>
<returns>发送至未来响应DTO</returns>
</member>
<member name="M:FutureMailAPI.Controllers.NotificationController.RegisterDevice(FutureMailAPI.DTOs.NotificationDeviceRequestDto)">
<summary>
注册设备
@@ -207,5 +256,37 @@
<member name="M:FutureMailAPI.Migrations.AddSaltToUser.Down(Microsoft.EntityFrameworkCore.Migrations.MigrationBuilder)">
<inheritdoc />
</member>
<member name="T:FutureMailAPI.Migrations.AddSentMailCreatedAt">
<inheritdoc />
</member>
<member name="M:FutureMailAPI.Migrations.AddSentMailCreatedAt.Up(Microsoft.EntityFrameworkCore.Migrations.MigrationBuilder)">
<inheritdoc />
</member>
<member name="M:FutureMailAPI.Migrations.AddSentMailCreatedAt.Down(Microsoft.EntityFrameworkCore.Migrations.MigrationBuilder)">
<inheritdoc />
</member>
<member name="M:FutureMailAPI.Migrations.AddSentMailCreatedAt.BuildTargetModel(Microsoft.EntityFrameworkCore.ModelBuilder)">
<inheritdoc />
</member>
<member name="T:FutureMailAPI.Migrations.FixDuplicateForeignKeys">
<inheritdoc />
</member>
<member name="M:FutureMailAPI.Migrations.FixDuplicateForeignKeys.Up(Microsoft.EntityFrameworkCore.Migrations.MigrationBuilder)">
<inheritdoc />
</member>
<member name="M:FutureMailAPI.Migrations.FixDuplicateForeignKeys.Down(Microsoft.EntityFrameworkCore.Migrations.MigrationBuilder)">
<inheritdoc />
</member>
<member name="M:FutureMailAPI.Migrations.FixDuplicateForeignKeys.BuildTargetModel(Microsoft.EntityFrameworkCore.ModelBuilder)">
<inheritdoc />
</member>
<member name="M:FutureMailAPI.Services.MailService.SendToFutureAsync(System.Int32,FutureMailAPI.DTOs.SendToFutureDto)">
<summary>
发送至未来 - 将草稿状态的邮件设置为在未来特定时间自动发送
</summary>
<param name="userId">用户ID</param>
<param name="sendToFutureDto">发送至未来请求DTO</param>
<returns>发送至未来响应DTO</returns>
</member>
</members>
</doc>

File diff suppressed because it is too large Load Diff

View File

@@ -1 +1 @@
{"GlobalPropertiesHash":"1nyXR9zdL54Badakr4zt6ZsTCwUunwdqRSmf7XLLUwI=","FingerprintPatternsHash":"gq3WsqcKBUGTSNle7RKKyXRIwh7M8ccEqOqYvIzoM04=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["PSBb4S8lcZQPImBE8id7O4eeN8h3whFn6j1jGYFQciQ=","FLPLXKwQVK16UZsWKzZrjH5kq4sMEtCZqAIkpUwa2pU=","/ljuLPXzsWglGr0uHSpqYQARCPlOQrAX6k6LWku0gdQ=","XAE6ulqLzJRH50\u002Bc9Nteizd/x9s3rvSHUFwFL265XX4=","talZRfyIQIv4aZc27HTn01\u002B12VbY6LMFOy3\u002B3r448jo=","8GY2MSzr2E/Yc9xFiAqxn3IhTsjnylxYZUVwMfrW5vw="],"CachedAssets":{},"CachedCopyCandidates":{}}
{"GlobalPropertiesHash":"1nyXR9zdL54Badakr4zt6ZsTCwUunwdqRSmf7XLLUwI=","FingerprintPatternsHash":"gq3WsqcKBUGTSNle7RKKyXRIwh7M8ccEqOqYvIzoM04=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["PSBb4S8lcZQPImBE8id7O4eeN8h3whFn6j1jGYFQciQ=","FLPLXKwQVK16UZsWKzZrjH5kq4sMEtCZqAIkpUwa2pU=","ed7if\u002BhRbLX5eYApJ6Bg4oF5be3kjR0VKVKgf\u002BgmyVo=","XAE6ulqLzJRH50\u002Bc9Nteizd/x9s3rvSHUFwFL265XX4=","talZRfyIQIv4aZc27HTn01\u002B12VbY6LMFOy3\u002B3r448jo=","R7hxHyYox4qeYIBY\u002Bo3l0eo8ZIIfGZeN7PS3V61Q7Ks="],"CachedAssets":{},"CachedCopyCandidates":{}}

View File

@@ -1 +1 @@
{"GlobalPropertiesHash":"hRzLFfhtQD0jC2zNthCXf5A5W0LGZjQdHMs0v5Enof8=","FingerprintPatternsHash":"gq3WsqcKBUGTSNle7RKKyXRIwh7M8ccEqOqYvIzoM04=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["PSBb4S8lcZQPImBE8id7O4eeN8h3whFn6j1jGYFQciQ=","FLPLXKwQVK16UZsWKzZrjH5kq4sMEtCZqAIkpUwa2pU=","/ljuLPXzsWglGr0uHSpqYQARCPlOQrAX6k6LWku0gdQ=","XAE6ulqLzJRH50\u002Bc9Nteizd/x9s3rvSHUFwFL265XX4=","talZRfyIQIv4aZc27HTn01\u002B12VbY6LMFOy3\u002B3r448jo=","8GY2MSzr2E/Yc9xFiAqxn3IhTsjnylxYZUVwMfrW5vw="],"CachedAssets":{},"CachedCopyCandidates":{}}
{"GlobalPropertiesHash":"hRzLFfhtQD0jC2zNthCXf5A5W0LGZjQdHMs0v5Enof8=","FingerprintPatternsHash":"gq3WsqcKBUGTSNle7RKKyXRIwh7M8ccEqOqYvIzoM04=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["PSBb4S8lcZQPImBE8id7O4eeN8h3whFn6j1jGYFQciQ=","FLPLXKwQVK16UZsWKzZrjH5kq4sMEtCZqAIkpUwa2pU=","ed7if\u002BhRbLX5eYApJ6Bg4oF5be3kjR0VKVKgf\u002BgmyVo=","XAE6ulqLzJRH50\u002Bc9Nteizd/x9s3rvSHUFwFL265XX4=","talZRfyIQIv4aZc27HTn01\u002B12VbY6LMFOy3\u002B3r448jo=","R7hxHyYox4qeYIBY\u002Bo3l0eo8ZIIfGZeN7PS3V61Q7Ks="],"CachedAssets":{},"CachedCopyCandidates":{}}

138
README.md Normal file
View File

@@ -0,0 +1,138 @@
# FutureMail API 项目
这是一个基于.NET Core 9.0的未来邮件系统API支持创建定时邮件、时光胶囊、AI辅助等功能。
## 功能特性
- 用户认证与授权
- 创建和管理未来邮件
- 时光胶囊可视化
- AI写作辅助和情感分析
- 个人时间线和统计数据
- 文件上传功能
## 技术栈
- .NET Core 9.0
- Entity Framework Core (Code First)
- MySQL数据库
- JWT身份验证
- Swagger API文档
- Quartz.NET任务调度
## 快速开始
### 1. 运行项目
最简单的方法是使用提供的启动脚本:
```bash
start_project.bat
```
这将:
- 启动API服务器
- 打开Swagger文档页面
- 打开API测试页面
### 2. 手动运行
如果需要手动运行,请按照以下步骤:
1. 启动API服务器
```bash
cd FutureMailAPI
dotnet run
```
2. 访问Swagger文档
```
http://localhost:5003/swagger
```
3. 使用API测试页面
```
打开 api_test.html 文件
```
## API文档
详细的API文档请参考
- [API接口文档详细说明.md](./API接口文档详细说明.md)
- Swagger交互式文档http://localhost:5003/swagger
## 主要接口
### 认证相关
- `POST /api/v1/auth/register` - 用户注册
- `POST /api/v1/auth/login` - 用户登录
- `POST /api/v1/auth/refresh` - 刷新令牌
- `POST /api/v1/auth/logout` - 用户登出
### 邮件管理
- `POST /api/v1/mails/create` - 创建邮件
- `GET /api/v1/mails` - 获取邮件列表
- `GET /api/v1/mails/{mailId}` - 获取邮件详情
- `PUT /api/v1/mails/{mailId}` - 更新邮件
- `DELETE /api/v1/mails/{mailId}` - 删除邮件
- `POST /api/v1/mails/{mailId}/revoke` - 撤销发送
### 时光胶囊
- `GET /api/v1/capsules` - 获取胶囊视图
- `PUT /api/v1/capsules/{capsuleId}/style` - 更新胶囊样式
### AI助手
- `POST /api/v1/ai/writing-assistant` - AI写作辅助
- `POST /api/v1/ai/sentiment-analysis` - 情感分析
### 个人空间
- `GET /api/v1/timeline` - 获取时间线
- `GET /api/v1/statistics` - 获取统计数据
- `GET /api/v1/user/profile` - 获取用户信息
### 文件上传
- `POST /api/v1/upload/attachment` - 上传附件
- `POST /api/v1/upload/avatar` - 上传头像
## 数据库配置
数据库连接字符串配置在 `appsettings.json` 文件中:
```json
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=FutureMailDB;User=root;Password=yourpassword;"
}
}
```
请根据您的MySQL配置修改连接字符串。
## 项目结构
```
FutureMailAPI/
├── Controllers/ # API控制器
├── DTOs/ # 数据传输对象
├── Data/ # 数据模型和上下文
├── Helpers/ # 辅助类
├── Middleware/ # 中间件
├── Services/ # 服务类
├── Program.cs # 应用程序入口点
└── appsettings.json # 配置文件
```
## 测试
项目包含一个完整的API测试页面 `api_test.html`可以测试所有主要API接口。
## 注意事项
1. 确保MySQL服务器已安装并运行
2. 首次运行时EF Core会自动创建数据库和表
3. JWT密钥应在生产环境中更改为安全的值
4. 文件上传功能需要配置适当的存储路径
## 许可证
本项目仅供学习和演示使用。

803
api_test.html Normal file
View File

@@ -0,0 +1,803 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FutureMail API 测试</title>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background-color: white;
border-radius: 8px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
h1, h2 {
color: #333;
}
.section {
margin-bottom: 30px;
border-bottom: 1px solid #eee;
padding-bottom: 20px;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 15px;
margin: 5px;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
button:disabled {
background-color: #cccccc;
cursor: not-allowed;
}
.result {
background-color: #f8f8f8;
border: 1px solid #ddd;
border-radius: 4px;
padding: 10px;
margin-top: 10px;
white-space: pre-wrap;
font-family: monospace;
max-height: 300px;
overflow-y: auto;
}
.error {
background-color: #ffebee;
border-color: #f44336;
color: #c62828;
}
.success {
background-color: #e8f5e9;
border-color: #4caf50;
color: #2e7d32;
}
input, select, textarea {
width: 100%;
padding: 8px;
margin: 5px 0;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
.form-group {
margin-bottom: 15px;
}
.form-row {
display: flex;
gap: 10px;
}
.form-row > div {
flex: 1;
}
.tabs {
display: flex;
border-bottom: 1px solid #ddd;
}
.tab {
padding: 10px 15px;
cursor: pointer;
border-bottom: 2px solid transparent;
}
.tab.active {
border-bottom-color: #4CAF50;
font-weight: bold;
}
.tab-content {
display: none;
padding: 15px 0;
}
.tab-content.active {
display: block;
}
</style>
</head>
<body>
<h1>FutureMail API 测试</h1>
<div class="container">
<h2>认证状态</h2>
<div id="auth-status">
<p>未登录</p>
<button id="login-btn">登录</button>
<button id="register-btn">注册</button>
<button id="logout-btn" style="display:none;">登出</button>
</div>
</div>
<div class="tabs">
<div class="tab active" data-tab="mails">邮件管理</div>
<div class="tab" data-tab="capsules">时光胶囊</div>
<div class="tab" data-tab="ai">AI助手</div>
<div class="tab" data-tab="personal">个人空间</div>
<div class="tab" data-tab="upload">文件上传</div>
</div>
<!-- 邮件管理 -->
<div id="mails" class="tab-content active">
<div class="container">
<h2>创建邮件</h2>
<div class="form-group">
<label for="mail-title">标题</label>
<input type="text" id="mail-title" placeholder="邮件标题">
</div>
<div class="form-group">
<label for="mail-content">内容</label>
<textarea id="mail-content" rows="5" placeholder="邮件内容"></textarea>
</div>
<div class="form-row">
<div class="form-group">
<label for="mail-recipient-type">收件人类型</label>
<select id="mail-recipient-type">
<option value="SELF">自己</option>
<option value="SPECIFIC">指定收件人</option>
<option value="PUBLIC">公开</option>
</select>
</div>
<div class="form-group">
<label for="mail-recipient-email">收件人邮箱</label>
<input type="email" id="mail-recipient-email" placeholder="收件人邮箱">
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="mail-send-time">发送时间</label>
<input type="datetime-local" id="mail-send-time">
</div>
<div class="form-group">
<label for="mail-trigger-type">触发类型</label>
<select id="mail-trigger-type">
<option value="TIME">时间</option>
<option value="LOCATION">位置</option>
<option value="EVENT">事件</option>
</select>
</div>
</div>
<div class="form-group">
<label for="mail-capsule-style">胶囊样式</label>
<input type="text" id="mail-capsule-style" value="default" placeholder="胶囊样式">
</div>
<button id="create-mail-btn">创建邮件</button>
<div id="create-mail-result" class="result"></div>
</div>
<div class="container">
<h2>获取邮件列表</h2>
<div class="form-row">
<div class="form-group">
<label for="mail-list-type">邮件类型</label>
<select id="mail-list-type">
<option value="SENT">已发送</option>
<option value="INBOX">收件箱</option>
<option value="DRAFT">草稿</option>
</select>
</div>
<div class="form-group">
<label for="mail-list-status">状态筛选</label>
<select id="mail-list-status">
<option value="">全部</option>
<option value="PENDING">待投递</option>
<option value="DELIVERING">投递中</option>
<option value="DELIVERED">已投递</option>
</select>
</div>
</div>
<button id="get-mails-btn">获取邮件列表</button>
<div id="get-mails-result" class="result"></div>
</div>
<div class="container">
<h2>获取邮件详情</h2>
<div class="form-group">
<label for="mail-detail-id">邮件ID</label>
<input type="text" id="mail-detail-id" placeholder="邮件ID">
</div>
<button id="get-mail-detail-btn">获取邮件详情</button>
<div id="get-mail-detail-result" class="result"></div>
</div>
</div>
<!-- 时光胶囊 -->
<div id="capsules" class="tab-content">
<div class="container">
<h2>获取时光胶囊视图</h2>
<button id="get-capsules-btn">获取胶囊视图</button>
<div id="get-capsules-result" class="result"></div>
</div>
</div>
<!-- AI助手 -->
<div id="ai" class="tab-content">
<div class="container">
<h2>AI写作辅助</h2>
<div class="form-group">
<label for="ai-prompt">提示词</label>
<textarea id="ai-prompt" rows="3" placeholder="输入您的写作提示"></textarea>
</div>
<div class="form-row">
<div class="form-group">
<label for="ai-type">辅助类型</label>
<select id="ai-type">
<option value="OUTLINE">大纲</option>
<option value="DRAFT">草稿</option>
<option value="COMPLETE">完整</option>
</select>
</div>
<div class="form-group">
<label for="ai-tone">语气</label>
<select id="ai-tone">
<option value="FORMAL">正式</option>
<option value="CASUAL">随意</option>
<option value="EMOTIONAL">情感</option>
<option value="INSPIRATIONAL">励志</option>
</select>
</div>
<div class="form-group">
<label for="ai-length">长度</label>
<select id="ai-length">
<option value="SHORT"></option>
<option value="MEDIUM"></option>
<option value="LONG"></option>
</select>
</div>
</div>
<button id="ai-writing-btn">AI写作辅助</button>
<div id="ai-writing-result" class="result"></div>
</div>
<div class="container">
<h2>情感分析</h2>
<div class="form-group">
<label for="sentiment-content">待分析内容</label>
<textarea id="sentiment-content" rows="5" placeholder="输入待分析的内容"></textarea>
</div>
<button id="sentiment-analysis-btn">情感分析</button>
<div id="sentiment-analysis-result" class="result"></div>
</div>
</div>
<!-- 个人空间 -->
<div id="personal" class="tab-content">
<div class="container">
<h2>获取时间线</h2>
<div class="form-row">
<div class="form-group">
<label for="timeline-start-date">开始日期</label>
<input type="date" id="timeline-start-date">
</div>
<div class="form-group">
<label for="timeline-end-date">结束日期</label>
<input type="date" id="timeline-end-date">
</div>
<div class="form-group">
<label for="timeline-type">类型</label>
<select id="timeline-type">
<option value="ALL">全部</option>
<option value="SENT">已发送</option>
<option value="RECEIVED">已接收</option>
</select>
</div>
</div>
<button id="get-timeline-btn">获取时间线</button>
<div id="get-timeline-result" class="result"></div>
</div>
<div class="container">
<h2>获取统计数据</h2>
<button id="get-statistics-btn">获取统计数据</button>
<div id="get-statistics-result" class="result"></div>
</div>
<div class="container">
<h2>获取用户信息</h2>
<button id="get-profile-btn">获取用户信息</button>
<div id="get-profile-result" class="result"></div>
</div>
</div>
<!-- 文件上传 -->
<div id="upload" class="tab-content">
<div class="container">
<h2>上传附件</h2>
<div class="form-group">
<label for="attachment-file">选择文件</label>
<input type="file" id="attachment-file">
</div>
<div class="form-group">
<label for="attachment-type">文件类型</label>
<select id="attachment-type">
<option value="IMAGE">图片</option>
<option value="VOICE">语音</option>
<option value="VIDEO">视频</option>
</select>
</div>
<button id="upload-attachment-btn">上传附件</button>
<div id="upload-attachment-result" class="result"></div>
</div>
<div class="container">
<h2>上传头像</h2>
<div class="form-group">
<label for="avatar-file">选择头像文件</label>
<input type="file" id="avatar-file">
</div>
<button id="upload-avatar-btn">上传头像</button>
<div id="upload-avatar-result" class="result"></div>
</div>
</div>
<script>
// API基础URL
const API_BASE_URL = 'http://localhost:5003/api/v1';
// 当前JWT令牌
let authToken = '';
// DOM元素
const authStatus = document.getElementById('auth-status');
const loginBtn = document.getElementById('login-btn');
const registerBtn = document.getElementById('register-btn');
const logoutBtn = document.getElementById('logout-btn');
// 初始化
document.addEventListener('DOMContentLoaded', function() {
// 从本地存储获取令牌
authToken = localStorage.getItem('futuremail_token') || '';
updateAuthStatus();
// 绑定事件
loginBtn.addEventListener('click', showLoginDialog);
registerBtn.addEventListener('click', showRegisterDialog);
logoutBtn.addEventListener('click', logout);
// 绑定标签页切换
document.querySelectorAll('.tab').forEach(tab => {
tab.addEventListener('click', function() {
const tabName = this.getAttribute('data-tab');
switchTab(tabName);
});
});
// 绑定邮件相关按钮
document.getElementById('create-mail-btn').addEventListener('click', createMail);
document.getElementById('get-mails-btn').addEventListener('click', getMails);
document.getElementById('get-mail-detail-btn').addEventListener('click', getMailDetail);
// 绑定时光胶囊相关按钮
document.getElementById('get-capsules-btn').addEventListener('click', getCapsules);
// 绑定AI相关按钮
document.getElementById('ai-writing-btn').addEventListener('click', aiWritingAssistant);
document.getElementById('sentiment-analysis-btn').addEventListener('click', sentimentAnalysis);
// 绑定个人空间相关按钮
document.getElementById('get-timeline-btn').addEventListener('click', getTimeline);
document.getElementById('get-statistics-btn').addEventListener('click', getStatistics);
document.getElementById('get-profile-btn').addEventListener('click', getProfile);
// 绑定文件上传相关按钮
document.getElementById('upload-attachment-btn').addEventListener('click', uploadAttachment);
document.getElementById('upload-avatar-btn').addEventListener('click', uploadAvatar);
});
// 更新认证状态
function updateAuthStatus() {
if (authToken) {
authStatus.innerHTML = `
<p>已登录</p>
<button id="logout-btn">登出</button>
`;
document.getElementById('logout-btn').addEventListener('click', logout);
} else {
authStatus.innerHTML = `
<p>未登录</p>
<button id="login-btn">登录</button>
<button id="register-btn">注册</button>
`;
document.getElementById('login-btn').addEventListener('click', showLoginDialog);
document.getElementById('register-btn').addEventListener('click', showRegisterDialog);
}
}
// 切换标签页
function switchTab(tabName) {
// 更新标签样式
document.querySelectorAll('.tab').forEach(tab => {
tab.classList.remove('active');
});
document.querySelector(`[data-tab="${tabName}"]`).classList.add('active');
// 更新内容显示
document.querySelectorAll('.tab-content').forEach(content => {
content.classList.remove('active');
});
document.getElementById(tabName).classList.add('active');
}
// 显示登录对话框
function showLoginDialog() {
const email = prompt('请输入邮箱:');
const password = prompt('请输入密码:');
if (email && password) {
login(email, password);
}
}
// 显示注册对话框
function showRegisterDialog() {
const username = prompt('请输入用户名:');
const email = prompt('请输入邮箱:');
const password = prompt('请输入密码:');
if (username && email && password) {
register(username, email, password);
}
}
// 登录
async function login(email, password) {
try {
const response = await axios.post(`${API_BASE_URL}/auth/login`, {
email: email,
password: password
});
authToken = response.data.data.token;
localStorage.setItem('futuremail_token', authToken);
updateAuthStatus();
showResult('auth-status', '登录成功', 'success');
} catch (error) {
showResult('auth-status', `登录失败: ${error.response?.data?.message || error.message}`, 'error');
}
}
// 注册
async function register(username, email, password) {
try {
const response = await axios.post(`${API_BASE_URL}/auth/register`, {
username: username,
email: email,
password: password
});
authToken = response.data.data.token;
localStorage.setItem('futuremail_token', authToken);
updateAuthStatus();
showResult('auth-status', '注册成功', 'success');
} catch (error) {
showResult('auth-status', `注册失败: ${error.response?.data?.message || error.message}`, 'error');
}
}
// 登出
function logout() {
authToken = '';
localStorage.removeItem('futuremail_token');
updateAuthStatus();
showResult('auth-status', '已登出', 'success');
}
// 创建邮件
async function createMail() {
if (!checkAuth()) return;
const title = document.getElementById('mail-title').value;
const content = document.getElementById('mail-content').value;
const recipientType = document.getElementById('mail-recipient-type').value;
const recipientEmail = document.getElementById('mail-recipient-email').value;
const sendTime = document.getElementById('mail-send-time').value;
const triggerType = document.getElementById('mail-trigger-type').value;
const capsuleStyle = document.getElementById('mail-capsule-style').value;
if (!title || !content || !sendTime) {
showResult('create-mail-result', '请填写必填字段', 'error');
return;
}
try {
const mailData = {
title: title,
content: content,
recipientType: recipientType,
recipientEmail: recipientEmail || undefined,
sendTime: new Date(sendTime).toISOString(),
triggerType: triggerType,
triggerCondition: {},
attachments: [],
isEncrypted: false,
capsuleStyle: capsuleStyle
};
const response = await axios.post(`${API_BASE_URL}/mails/create`, mailData, {
headers: {
'Authorization': `Bearer ${authToken}`,
'Content-Type': 'application/json'
}
});
showResult('create-mail-result', JSON.stringify(response.data, null, 2), 'success');
} catch (error) {
showResult('create-mail-result', `创建邮件失败: ${error.response?.data?.message || error.message}`, 'error');
}
}
// 获取邮件列表
async function getMails() {
if (!checkAuth()) return;
const type = document.getElementById('mail-list-type').value;
const status = document.getElementById('mail-list-status').value;
try {
let url = `${API_BASE_URL}/mails?type=${type}`;
if (status) {
url += `&status=${status}`;
}
url += '&page=1&size=20';
const response = await axios.get(url, {
headers: {
'Authorization': `Bearer ${authToken}`
}
});
showResult('get-mails-result', JSON.stringify(response.data, null, 2), 'success');
} catch (error) {
showResult('get-mails-result', `获取邮件列表失败: ${error.response?.data?.message || error.message}`, 'error');
}
}
// 获取邮件详情
async function getMailDetail() {
if (!checkAuth()) return;
const mailId = document.getElementById('mail-detail-id').value;
if (!mailId) {
showResult('get-mail-detail-result', '请输入邮件ID', 'error');
return;
}
try {
const response = await axios.get(`${API_BASE_URL}/mails/${mailId}`, {
headers: {
'Authorization': `Bearer ${authToken}`
}
});
showResult('get-mail-detail-result', JSON.stringify(response.data, null, 2), 'success');
} catch (error) {
showResult('get-mail-detail-result', `获取邮件详情失败: ${error.response?.data?.message || error.message}`, 'error');
}
}
// 获取时光胶囊视图
async function getCapsules() {
if (!checkAuth()) return;
try {
const response = await axios.get(`${API_BASE_URL}/capsules`, {
headers: {
'Authorization': `Bearer ${authToken}`
}
});
showResult('get-capsules-result', JSON.stringify(response.data, null, 2), 'success');
} catch (error) {
showResult('get-capsules-result', `获取胶囊视图失败: ${error.response?.data?.message || error.message}`, 'error');
}
}
// AI写作辅助
async function aiWritingAssistant() {
if (!checkAuth()) return;
const prompt = document.getElementById('ai-prompt').value;
const type = document.getElementById('ai-type').value;
const tone = document.getElementById('ai-tone').value;
const length = document.getElementById('ai-length').value;
if (!prompt) {
showResult('ai-writing-result', '请输入提示词', 'error');
return;
}
try {
const response = await axios.post(`${API_BASE_URL}/ai/writing-assistant`, {
prompt: prompt,
type: type,
tone: tone,
length: length
}, {
headers: {
'Authorization': `Bearer ${authToken}`,
'Content-Type': 'application/json'
}
});
showResult('ai-writing-result', JSON.stringify(response.data, null, 2), 'success');
} catch (error) {
showResult('ai-writing-result', `AI写作辅助失败: ${error.response?.data?.message || error.message}`, 'error');
}
}
// 情感分析
async function sentimentAnalysis() {
if (!checkAuth()) return;
const content = document.getElementById('sentiment-content').value;
if (!content) {
showResult('sentiment-analysis-result', '请输入待分析内容', 'error');
return;
}
try {
const response = await axios.post(`${API_BASE_URL}/ai/sentiment-analysis`, {
content: content
}, {
headers: {
'Authorization': `Bearer ${authToken}`,
'Content-Type': 'application/json'
}
});
showResult('sentiment-analysis-result', JSON.stringify(response.data, null, 2), 'success');
} catch (error) {
showResult('sentiment-analysis-result', `情感分析失败: ${error.response?.data?.message || error.message}`, 'error');
}
}
// 获取时间线
async function getTimeline() {
if (!checkAuth()) return;
const startDate = document.getElementById('timeline-start-date').value;
const endDate = document.getElementById('timeline-end-date').value;
const type = document.getElementById('timeline-type').value;
try {
let url = `${API_BASE_URL}/timeline?type=${type}`;
if (startDate) {
url += `&startDate=${startDate}`;
}
if (endDate) {
url += `&endDate=${endDate}`;
}
const response = await axios.get(url, {
headers: {
'Authorization': `Bearer ${authToken}`
}
});
showResult('get-timeline-result', JSON.stringify(response.data, null, 2), 'success');
} catch (error) {
showResult('get-timeline-result', `获取时间线失败: ${error.response?.data?.message || error.message}`, 'error');
}
}
// 获取统计数据
async function getStatistics() {
if (!checkAuth()) return;
try {
const response = await axios.get(`${API_BASE_URL}/statistics`, {
headers: {
'Authorization': `Bearer ${authToken}`
}
});
showResult('get-statistics-result', JSON.stringify(response.data, null, 2), 'success');
} catch (error) {
showResult('get-statistics-result', `获取统计数据失败: ${error.response?.data?.message || error.message}`, 'error');
}
}
// 获取用户信息
async function getProfile() {
if (!checkAuth()) return;
try {
const response = await axios.get(`${API_BASE_URL}/user/profile`, {
headers: {
'Authorization': `Bearer ${authToken}`
}
});
showResult('get-profile-result', JSON.stringify(response.data, null, 2), 'success');
} catch (error) {
showResult('get-profile-result', `获取用户信息失败: ${error.response?.data?.message || error.message}`, 'error');
}
}
// 上传附件
async function uploadAttachment() {
if (!checkAuth()) return;
const fileInput = document.getElementById('attachment-file');
const fileType = document.getElementById('attachment-type').value;
if (!fileInput.files.length) {
showResult('upload-attachment-result', '请选择文件', 'error');
return;
}
const formData = new FormData();
formData.append('file', fileInput.files[0]);
formData.append('type', fileType);
try {
const response = await axios.post(`${API_BASE_URL}/upload/attachment`, formData, {
headers: {
'Authorization': `Bearer ${authToken}`,
'Content-Type': 'multipart/form-data'
}
});
showResult('upload-attachment-result', JSON.stringify(response.data, null, 2), 'success');
} catch (error) {
showResult('upload-attachment-result', `上传附件失败: ${error.response?.data?.message || error.message}`, 'error');
}
}
// 上传头像
async function uploadAvatar() {
if (!checkAuth()) return;
const fileInput = document.getElementById('avatar-file');
if (!fileInput.files.length) {
showResult('upload-avatar-result', '请选择头像文件', 'error');
return;
}
const formData = new FormData();
formData.append('file', fileInput.files[0]);
try {
const response = await axios.post(`${API_BASE_URL}/upload/avatar`, formData, {
headers: {
'Authorization': `Bearer ${authToken}`,
'Content-Type': 'multipart/form-data'
}
});
showResult('upload-avatar-result', JSON.stringify(response.data, null, 2), 'success');
} catch (error) {
showResult('upload-avatar-result', `上传头像失败: ${error.response?.data?.message || error.message}`, 'error');
}
}
// 检查认证状态
function checkAuth() {
if (!authToken) {
showResult('auth-status', '请先登录', 'error');
return false;
}
return true;
}
// 显示结果
function showResult(elementId, message, type = 'info') {
const resultElement = document.getElementById(elementId);
resultElement.textContent = message;
resultElement.className = `result ${type}`;
}
</script>
</body>
</html>

307
simple_test.html Normal file
View File

@@ -0,0 +1,307 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API测试</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.section {
margin-bottom: 30px;
padding: 15px;
border: 1px solid #ddd;
border-radius: 5px;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input, textarea, select, button {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
button {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
margin-top: 10px;
}
button:hover {
background-color: #45a049;
}
.result {
margin-top: 15px;
padding: 10px;
background-color: #f9f9f9;
border-radius: 4px;
white-space: pre-wrap;
font-family: monospace;
}
.error {
background-color: #ffebee;
color: #c62828;
}
.success {
background-color: #e8f5e9;
color: #2e7d32;
}
</style>
</head>
<body>
<h1>API测试</h1>
<div class="section">
<h2>用户注册</h2>
<div class="form-group">
<label for="username">用户名:</label>
<input type="text" id="username" value="testuser123">
</div>
<div class="form-group">
<label for="email">邮箱:</label>
<input type="email" id="email" value="test123@example.com">
</div>
<div class="form-group">
<label for="password">密码:</label>
<input type="password" id="password" value="password123">
</div>
<button onclick="register()">注册</button>
<div id="registerResult" class="result"></div>
</div>
<div class="section">
<h2>用户登录</h2>
<div class="form-group">
<label for="loginUsername">用户名或邮箱:</label>
<input type="text" id="loginUsername" value="testuser123">
</div>
<div class="form-group">
<label for="loginPassword">密码:</label>
<input type="password" id="loginPassword" value="password123">
</div>
<button onclick="login()">登录</button>
<div id="loginResult" class="result"></div>
</div>
<div class="section">
<h2>创建邮件</h2>
<div class="form-group">
<label for="mailTitle">标题:</label>
<input type="text" id="mailTitle" value="测试邮件">
</div>
<div class="form-group">
<label for="mailContent">内容:</label>
<textarea id="mailContent" rows="4">这是一封测试邮件内容</textarea>
</div>
<div class="form-group">
<label for="recipientType">收件人类型:</label>
<select id="recipientType">
<option value="SELF">自己</option>
<option value="SPECIFIC">指定用户</option>
<option value="PUBLIC">公开时间胶囊</option>
</select>
</div>
<div class="form-group">
<label for="recipientEmail">收件人邮箱 (如果是指定用户):</label>
<input type="email" id="recipientEmail">
</div>
<div class="form-group">
<label for="sendTime">发送时间:</label>
<input type="datetime-local" id="sendTime">
</div>
<div class="form-group">
<label for="triggerType">触发类型:</label>
<select id="triggerType">
<option value="TIME">时间</option>
<option value="LOCATION">地点</option>
<option value="EVENT">事件</option>
</select>
</div>
<div class="form-group">
<label for="capsuleStyle">胶囊样式:</label>
<input type="text" id="capsuleStyle" value="default">
</div>
<button onclick="createMail()">创建邮件</button>
<div id="createMailResult" class="result"></div>
</div>
<div class="section">
<h2>获取邮件列表</h2>
<div class="form-group">
<label for="mailType">邮件类型:</label>
<select id="mailType">
<option value="SENT">已发送</option>
<option value="DRAFT">草稿</option>
</select>
</div>
<button onclick="getMails()">获取邮件列表</button>
<div id="getMailsResult" class="result"></div>
</div>
<script>
const API_BASE_URL = 'http://localhost:5003/api/v1';
let authToken = '';
// 设置默认发送时间为明天
document.getElementById('sendTime').value = new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString().slice(0, 16);
// 显示结果
function showResult(elementId, data, isError = false) {
const element = document.getElementById(elementId);
element.textContent = typeof data === 'object' ? JSON.stringify(data, null, 2) : data;
element.className = 'result ' + (isError ? 'error' : 'success');
}
// 注册
async function register() {
const username = document.getElementById('username').value;
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
try {
const response = await fetch(`${API_BASE_URL}/auth/register`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
username,
email,
password
})
});
const data = await response.json();
if (response.ok) {
authToken = data.data.token;
showResult('registerResult', data);
} else {
showResult('registerResult', data, true);
}
} catch (error) {
showResult('registerResult', '错误: ' + error.message, true);
}
}
// 登录
async function login() {
const usernameOrEmail = document.getElementById('loginUsername').value;
const password = document.getElementById('loginPassword').value;
try {
const response = await fetch(`${API_BASE_URL}/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
usernameOrEmail,
password
})
});
const data = await response.json();
if (response.ok) {
authToken = data.data.token;
showResult('loginResult', data);
} else {
showResult('loginResult', data, true);
}
} catch (error) {
showResult('loginResult', '错误: ' + error.message, true);
}
}
// 创建邮件
async function createMail() {
if (!authToken) {
showResult('createMailResult', '请先登录', true);
return;
}
const title = document.getElementById('mailTitle').value;
const content = document.getElementById('mailContent').value;
const recipientType = document.getElementById('recipientType').value;
const recipientEmail = document.getElementById('recipientEmail').value;
const sendTime = document.getElementById('sendTime').value;
const triggerType = document.getElementById('triggerType').value;
const capsuleStyle = document.getElementById('capsuleStyle').value;
try {
const response = await fetch(`${API_BASE_URL}/mails/create`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${authToken}`
},
body: JSON.stringify({
title,
content,
recipientType,
recipientEmail,
sendTime: new Date(sendTime).toISOString(),
triggerType,
triggerCondition: {},
attachments: [],
isEncrypted: false,
capsuleStyle
})
});
const data = await response.json();
if (response.ok) {
showResult('createMailResult', data);
} else {
showResult('createMailResult', data, true);
}
} catch (error) {
showResult('createMailResult', '错误: ' + error.message, true);
}
}
// 获取邮件列表
async function getMails() {
if (!authToken) {
showResult('getMailsResult', '请先登录', true);
return;
}
const mailType = document.getElementById('mailType').value;
try {
const response = await fetch(`${API_BASE_URL}/mails?type=${mailType}&page=1&size=20`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${authToken}`
}
});
const data = await response.json();
if (response.ok) {
showResult('getMailsResult', data);
} else {
showResult('getMailsResult', data, true);
}
} catch (error) {
showResult('getMailsResult', '错误: ' + error.message, true);
}
}
</script>
</body>
</html>

12
start_project.bat Normal file
View File

@@ -0,0 +1,12 @@
@echo off
echo 正在启动FutureMail API服务器...
cd /d "%~dp0FutureMailAPI"
start "FutureMail API Server" cmd /k "dotnet run"
echo API服务器正在启动请等待几秒钟...
timeout /t 5 /nobreak > nul
echo 正在打开Swagger文档...
start http://localhost:5003/swagger
echo 正在打开API测试页面...
start "%~dp0api_test.html"
echo 完成!
pause

53
test_api.js Normal file
View File

@@ -0,0 +1,53 @@
const axios = require('axios');
const API_BASE_URL = 'http://localhost:5003/api/v1';
async function testAPI() {
try {
// 1. 注册用户
console.log('1. 注册用户...');
const registerResponse = await axios.post(`${API_BASE_URL}/auth/register`, {
username: 'testuser',
email: 'test@example.com',
password: 'password123'
});
const token = registerResponse.data.data.token;
console.log('注册成功获取到token:', token);
// 2. 创建邮件
console.log('\n2. 创建邮件...');
const mailData = {
title: '测试邮件',
content: '这是一封测试邮件内容',
recipientType: 'SELF',
sendTime: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(), // 明天这个时候
triggerType: 'TIME',
triggerCondition: {},
attachments: [],
isEncrypted: false,
capsuleStyle: 'default'
};
const createMailResponse = await axios.post(`${API_BASE_URL}/mails/create`, mailData, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});
console.log('创建邮件成功:', createMailResponse.data);
// 3. 获取邮件列表
console.log('\n3. 获取邮件列表...');
const mailsResponse = await axios.get(`${API_BASE_URL}/mails?type=SENT&page=1&size=20`, {
headers: {
'Authorization': `Bearer ${token}`
}
});
console.log('获取邮件列表成功:', mailsResponse.data);
} catch (error) {
console.error('测试失败:', error.response?.data || error.message);
}
}
testAPI();

56
test_api.ps1 Normal file
View File

@@ -0,0 +1,56 @@
# 测试API的PowerShell脚本
$API_BASE_URL = "http://localhost:5003/api/v1"
try {
# 1. 注册用户
Write-Host "1. 注册用户..."
$registerBody = @{
username = "testuser"
email = "test@example.com"
password = "password123"
} | ConvertTo-Json
$registerResponse = Invoke-RestMethod -Uri "$API_BASE_URL/auth/register" -Method Post -Body $registerBody -ContentType "application/json"
$token = $registerResponse.data.token
Write-Host "注册成功获取到token: $token"
# 2. 创建邮件
Write-Host "`n2. 创建邮件..."
$sendTime = (Get-Date).AddDays(1).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
$mailData = @{
title = "测试邮件"
content = "这是一封测试邮件内容"
recipientType = "SELF"
sendTime = $sendTime
triggerType = "TIME"
triggerCondition = @{}
attachments = @()
isEncrypted = $false
capsuleStyle = "default"
} | ConvertTo-Json -Depth 10
$headers = @{
"Authorization" = "Bearer $token"
"Content-Type" = "application/json"
}
$createMailResponse = Invoke-RestMethod -Uri "$API_BASE_URL/mails/create" -Method Post -Body $mailData -Headers $headers
Write-Host "创建邮件成功:"
$createMailResponse | ConvertTo-Json -Depth 10
# 3. 获取邮件列表
Write-Host "`n3. 获取邮件列表..."
$mailsResponse = Invoke-RestMethod -Uri "$API_BASE_URL/mails?type=SENT&page=1&size=20" -Method Get -Headers $headers
Write-Host "获取邮件列表成功:"
$mailsResponse | ConvertTo-Json -Depth 10
} catch {
Write-Host "测试失败: $($_.Exception.Message)"
if ($_.Exception.Response) {
$reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
$reader.BaseStream.Position = 0
$errorBody = $reader.ReadToEnd()
Write-Host "错误详情: $errorBody"
}
}

View File

@@ -1,63 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>邮件创建测试</title>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
<h1>邮件创建测试</h1>
<button onclick="testLogin()">登录</button>
<button onclick="testCreateMail()">创建邮件</button>
<div id="result"></div>
<script>
let authToken = '';
async function testLogin() {
try {
const response = await axios.post('http://localhost:5003/api/v1/auth/login', {
email: 'test@example.com',
password: 'test123'
});
authToken = response.data.data.token;
document.getElementById('result').innerHTML = '<pre>登录成功,令牌: ' + authToken + '</pre>';
} catch (error) {
document.getElementById('result').innerHTML = '<pre>登录失败: ' + JSON.stringify(error.response.data, null, 2) + '</pre>';
}
}
async function testCreateMail() {
if (!authToken) {
document.getElementById('result').innerHTML = '<pre>请先登录</pre>';
return;
}
try {
const mailData = {
title: "测试邮件标题",
content: "这是一封测试邮件的内容",
recipientType: "SELF",
sendTime: "2026-10-16T08:03:58.479Z",
triggerType: "TIME",
triggerCondition: {},
attachments: [],
isEncrypted: false,
capsuleStyle: "default"
};
const response = await axios.post('http://localhost:5003/api/v1/mails/create', mailData, {
headers: {
'Authorization': 'Bearer ' + authToken,
'Content-Type': 'application/json'
}
});
document.getElementById('result').innerHTML = '<pre>邮件创建成功: ' + JSON.stringify(response.data, null, 2) + '</pre>';
} catch (error) {
document.getElementById('result').innerHTML = '<pre>邮件创建失败: ' + JSON.stringify(error.response.data, null, 2) + '</pre>';
}
}
</script>
</body>
</html>

View File

@@ -1,11 +0,0 @@
{
"title": "测试邮件标题",
"content": "这是一封测试邮件的内容",
"recipientType": "SELF",
"sendTime": "2026-10-16T08:03:58.479Z",
"triggerType": "TIME",
"triggerCondition": {},
"attachments": [],
"isEncrypted": false,
"capsuleStyle": "default"
}