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

@@ -3,6 +3,9 @@ use utoipa::OpenApi;
use crate::{ApiDoc, AuthApiDoc, ConfigApiDoc, MessageApiDoc, WorkflowApiDoc};
#[cfg(feature = "diary")]
use crate::DiaryApiDoc;
/// GET /docs/openapi.json
///
/// 返回 OpenAPI 3.0 规范 JSON 文档,合并所有模块的路径和 schema。
@@ -15,6 +18,10 @@ pub async fn openapi_spec() -> Response {
spec.merge(ConfigApiDoc::openapi());
spec.merge(WorkflowApiDoc::openapi());
spec.merge(MessageApiDoc::openapi());
#[cfg(feature = "diary")]
spec.merge(DiaryApiDoc::openapi());
Json(serde_json::to_value(spec).unwrap_or_default()).into_response()
}

View File

@@ -161,6 +161,90 @@ struct WorkflowApiDoc;
)]
struct MessageApiDoc;
/// Diary 模块的 OpenAPI 路径收集
#[cfg(feature = "diary")]
#[derive(OpenApi)]
#[openapi(
paths(
erp_diary::handler::journal_handler::create_journal,
erp_diary::handler::journal_handler::get_journal,
erp_diary::handler::journal_handler::update_journal,
erp_diary::handler::journal_handler::delete_journal,
erp_diary::handler::journal_handler::list_journals,
erp_diary::handler::class_handler::create_class,
erp_diary::handler::class_handler::join_class,
erp_diary::handler::class_handler::get_class,
erp_diary::handler::class_handler::list_members,
erp_diary::handler::class_handler::my_classes,
erp_diary::handler::class_handler::list_all_classes,
erp_diary::handler::class_handler::update_class,
erp_diary::handler::class_handler::deactivate_class,
erp_diary::handler::class_handler::reset_class_code,
erp_diary::handler::comment_handler::create_comment,
erp_diary::handler::comment_handler::list_comments,
erp_diary::handler::comment_handler::delete_comment,
erp_diary::handler::topic_handler::assign_topic,
erp_diary::handler::topic_handler::list_topics,
erp_diary::handler::topic_handler::update_topic,
erp_diary::handler::topic_handler::deactivate_topic,
erp_diary::handler::sticker_handler::list_sticker_packs,
erp_diary::handler::sticker_handler::list_stickers_in_pack,
erp_diary::handler::sticker_handler::create_sticker_pack,
erp_diary::handler::sticker_handler::update_sticker_pack,
erp_diary::handler::sticker_handler::delete_sticker_pack,
erp_diary::handler::sticker_handler::create_sticker,
erp_diary::handler::sticker_handler::list_templates,
erp_diary::handler::sticker_handler::get_template,
erp_diary::handler::achievement_handler::list_achievements,
erp_diary::handler::achievement_handler::unlock_achievement,
erp_diary::handler::stats_handler::get_mood_stats,
erp_diary::handler::sync_handler::sync_journals,
erp_diary::handler::parent_handler::bind_child,
erp_diary::handler::parent_handler::list_children,
erp_diary::handler::parent_handler::get_child_journals,
erp_diary::handler::parent_handler::export_child_data,
erp_diary::handler::parent_handler::delete_child_data,
erp_diary::handler::parent_handler::unbind_child,
erp_diary::handler::parent_handler::list_pending_bindings,
erp_diary::handler::parent_handler::confirm_binding,
erp_diary::handler::parent_handler::reject_binding,
),
components(schemas(
erp_diary::dto::CreateJournalReq,
erp_diary::dto::UpdateJournalReq,
erp_diary::dto::JournalResp,
erp_diary::dto::CreateClassReq,
erp_diary::dto::JoinClassReq,
erp_diary::dto::UpdateClassReq,
erp_diary::dto::ResetClassCodeResp,
erp_diary::dto::ClassResp,
erp_diary::dto::SyncReq,
erp_diary::dto::SyncResp,
erp_diary::dto::ConflictInfo,
erp_diary::dto::ClassMemberResp,
erp_diary::dto::CreateTopicReq,
erp_diary::dto::TopicResp,
erp_diary::dto::UpdateTopicReq,
erp_diary::dto::CreateCommentReq,
erp_diary::dto::CommentResp,
erp_diary::dto::NotificationPayload,
erp_diary::dto::MoodStatsResp,
erp_diary::dto::MoodCount,
erp_diary::dto::StickerPackResp,
erp_diary::dto::StickerResp,
erp_diary::dto::TemplateResp,
erp_diary::dto::AchievementResp,
erp_diary::dto::CreateStickerPackReq,
erp_diary::dto::UpdateStickerPackReq,
erp_diary::dto::CreateStickerReq,
erp_diary::handler::parent_handler::BindChildReq,
erp_diary::handler::parent_handler::DeleteChildDataReq,
erp_diary::handler::parent_handler::BindingResp,
erp_diary::handler::parent_handler::DeleteResultResp,
))
)]
struct DiaryApiDoc;
use axum::Router;
use axum::middleware as axum_middleware;
use config::AppConfig;