fix: align api_key_handler.go comments with actual routes

- Routes are /api/v1/keys (not /api/v1/api-keys)
- Update CLAUDE.md and DEV_GUIDE.md with correct API paths
This commit is contained in:
Developer
2026-04-03 00:00:23 +08:00
parent dc92194b2b
commit 413db94aeb
3 changed files with 19 additions and 11 deletions

View File

@@ -157,7 +157,7 @@ go generate ./cmd/server
- Logger 测试因 zap Fsync() 超时,使用 `-skip "logger"` 跳过
2. **E2E 测试坑点**
- API Key 路由是 `/api/v1/api-keys``/api/v1/keys`
- API Key 路由是 `/api/v1/keys`用户端)/admin `/api/v1/admin/api-keys`
- 余额调整 Payload`{balance, operation, notes}`
- Rate Multiplier Payload`{entries: [{user_id, rate_multiplier}]}`
- tests 目录在 .gitignore 中,需用 `git add -f tests/` 强制添加
@@ -166,6 +166,14 @@ go generate ./cmd/server
- 使用 Google Wire 进行依赖注入
- 修改 wire.go 后运行 `go mod tidy` 确保依赖完整
4. **前端测试覆盖**
- `src/views/auth/` 测试覆盖率为 0%
- `src/views/user/` 测试覆盖率约 20%
- 建议优先补充 auth 登录相关测试
5. **代码注释一致性**
- api_key_handler.go 注释已更新为正确路由 `/api/v1/keys`
### Gitea 远程仓库
| 属性 | 值 |

View File

@@ -249,19 +249,19 @@ git add ent/ # 生成的文件也要提交
### 坑 12E2E 测试 API 路径必须与后端路由一致
**问题**E2E 测试调用 `/api/v1/keys` 但后端路由是 `/api/v1/api-keys`,导致所有 API Key 测试返回 404。
**问题**:测试调用 `/api/v1/api-keys` 但后端路由是 `/api/v1/keys`,导致所有 API Key 测试返回 404。
**原因**测试文件使用了与后端路由不匹配的 API 路径
**原因**后端路由是 `/api/v1/keys`(不是 `/api/v1/api-keys`
**后端路由**`backend/internal/server/routes/user.go`
```go
keys := authenticated.Group("/api-keys") // 注意是 api-keys不是 keys
keys := authenticated.Group("/keys") // 用户端点是 /keys
```
**解决**
```bash
# 将所有 /api/v1/keys 改为 /api/v1/api-keys
sed -i 's|/api/v1/keys|/api/v1/api-keys|g' tests/e2e/*.spec.ts
# 将所有 /api/v1/api-keys 改为 /api/v1/keys(用户端点)
sed -i 's|/api/v1/api-keys|/api/v1/keys|g' tests/e2e/*.spec.ts
```
---

View File

@@ -63,7 +63,7 @@ type UpdateAPIKeyRequest struct {
}
// List handles listing user's API keys with pagination
// GET /api/v1/api-keys
// GET /api/v1/keys
func (h *APIKeyHandler) List(c *gin.Context) {
subject, ok := middleware2.GetAuthSubjectFromContext(c)
if !ok {
@@ -104,7 +104,7 @@ func (h *APIKeyHandler) List(c *gin.Context) {
}
// GetByID handles getting a single API key
// GET /api/v1/api-keys/:id
// GET /api/v1/keys/:id
func (h *APIKeyHandler) GetByID(c *gin.Context) {
subject, ok := middleware2.GetAuthSubjectFromContext(c)
if !ok {
@@ -134,7 +134,7 @@ func (h *APIKeyHandler) GetByID(c *gin.Context) {
}
// Create handles creating a new API key
// POST /api/v1/api-keys
// POST /api/v1/keys
func (h *APIKeyHandler) Create(c *gin.Context) {
subject, ok := middleware2.GetAuthSubjectFromContext(c)
if !ok {
@@ -179,7 +179,7 @@ func (h *APIKeyHandler) Create(c *gin.Context) {
}
// Update handles updating an API key
// PUT /api/v1/api-keys/:id
// PUT /api/v1/keys/:id
func (h *APIKeyHandler) Update(c *gin.Context) {
subject, ok := middleware2.GetAuthSubjectFromContext(c)
if !ok {
@@ -242,7 +242,7 @@ func (h *APIKeyHandler) Update(c *gin.Context) {
}
// Delete handles deleting an API key
// DELETE /api/v1/api-keys/:id
// DELETE /api/v1/keys/:id
func (h *APIKeyHandler) Delete(c *gin.Context) {
subject, ok := middleware2.GetAuthSubjectFromContext(c)
if !ok {