refactor(diary): Phase 3 质量提升 — 201 状态码 + OpenAPI 文档 + DiaryEvent 类型安全
Some checks failed
Main Merge / backend (push) Has been cancelled
Main Merge / frontend (push) Has been cancelled

前端:
- fix(app): Isar native 文件直接导入 isar_database_native.dart,消除 5 个条件导出类型错误
- chore(app): build_runner 重新生成 .g.dart 文件 (102 outputs)
- fix(app): 移除 secure_token_store_factory 未使用的 kIsWeb import

后端:
- refactor(diary): 所有创建端点 POST 返回 201 Created (9 handler, 11 端点)
- feat(diary): DiaryApiDoc OpenApi derive — 42 路径 + 32 Schema 汇总到 Swagger
- feat(diary): DiaryEvent 枚举添加 event_type/payload/to_domain_event 方法 + 4 测试

测试: 84/84 erp-diary 通过, 509/509 全仓库通过, Flutter analyze 0 error
This commit is contained in:
iven
2026-06-03 17:06:03 +08:00
parent e8df3a9562
commit 38592d61ce
17 changed files with 1038 additions and 70 deletions

View File

@@ -1,6 +1,7 @@
// 贴纸与模板 API 处理器
use axum::extract::{Extension, FromRef, Path, Query, State};
use axum::http::StatusCode;
use axum::response::Json;
use serde::Deserialize;
use utoipa::IntoParams;
@@ -91,7 +92,7 @@ where
path = "/api/v1/diary/sticker-packs",
request_body = CreateStickerPackReq,
responses(
(status = 200, description = "创建成功", body = ApiResponse<StickerPackResp>),
(status = 201, description = "创建成功", body = ApiResponse<StickerPackResp>),
(status = 400, description = "验证失败"),
(status = 401, description = "未授权"),
(status = 403, description = "权限不足"),
@@ -106,7 +107,7 @@ pub async fn create_sticker_pack<S>(
State(state): State<DiaryState>,
Extension(ctx): Extension<TenantContext>,
Json(req): Json<CreateStickerPackReq>,
) -> Result<Json<ApiResponse<StickerPackResp>>, AppError>
) -> Result<(StatusCode, Json<ApiResponse<StickerPackResp>>), AppError>
where
DiaryState: FromRef<S>,
S: Clone + Send + Sync + 'static,
@@ -126,7 +127,7 @@ where
)
.await?;
Ok(Json(ApiResponse::ok(resp)))
Ok((StatusCode::CREATED, Json(ApiResponse::ok(resp))))
}
#[utoipa::path(
@@ -216,7 +217,7 @@ where
params(("pack_id" = Uuid, Path, description = "贴纸包ID")),
request_body = CreateStickerReq,
responses(
(status = 200, description = "创建成功", body = ApiResponse<StickerResp>),
(status = 201, description = "创建成功", body = ApiResponse<StickerResp>),
(status = 400, description = "验证失败"),
(status = 401, description = "未授权"),
(status = 403, description = "权限不足"),
@@ -233,7 +234,7 @@ pub async fn create_sticker<S>(
Extension(ctx): Extension<TenantContext>,
Path(pack_id): Path<Uuid>,
Json(req): Json<CreateStickerReq>,
) -> Result<Json<ApiResponse<StickerResp>>, AppError>
) -> Result<(StatusCode, Json<ApiResponse<StickerResp>>), AppError>
where
DiaryState: FromRef<S>,
S: Clone + Send + Sync + 'static,
@@ -254,7 +255,7 @@ where
)
.await?;
Ok(Json(ApiResponse::ok(resp)))
Ok((StatusCode::CREATED, Json(ApiResponse::ok(resp))))
}
#[derive(Debug, Deserialize, IntoParams)]
pub struct TemplateQuery {