refactor(diary): Phase 3 质量提升 — 201 状态码 + OpenAPI 文档 + DiaryEvent 类型安全
前端: - 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:
@@ -1,6 +1,7 @@
|
||||
// 成就 API 处理器
|
||||
|
||||
use axum::extract::{Extension, FromRef, Path, State};
|
||||
use axum::http::StatusCode;
|
||||
use axum::response::Json;
|
||||
|
||||
use erp_core::error::AppError;
|
||||
@@ -44,7 +45,7 @@ where
|
||||
path = "/api/v1/diary/achievements/{code}/unlock",
|
||||
params(("code" = String, Path, description = "成就编码")),
|
||||
responses(
|
||||
(status = 200, description = "解锁成功", body = ApiResponse<AchievementResp>),
|
||||
(status = 201, description = "解锁成功", body = ApiResponse<AchievementResp>),
|
||||
(status = 404, description = "成就不存在"),
|
||||
),
|
||||
security(("bearer_auth" = [])),
|
||||
@@ -57,7 +58,7 @@ pub async fn unlock_achievement<S>(
|
||||
State(state): State<DiaryState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(code): Path<String>,
|
||||
) -> Result<Json<ApiResponse<AchievementResp>>, AppError>
|
||||
) -> Result<(StatusCode, Json<ApiResponse<AchievementResp>>), AppError>
|
||||
where
|
||||
DiaryState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
@@ -73,5 +74,5 @@ where
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(Json(ApiResponse::ok(resp)))
|
||||
Ok((StatusCode::CREATED, Json(ApiResponse::ok(resp))))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// 班级 API 处理器 — 创建班级、加入班级、查询班级
|
||||
|
||||
use axum::extract::{Extension, FromRef, Path, State};
|
||||
use axum::http::StatusCode;
|
||||
use axum::response::Json;
|
||||
use uuid::Uuid;
|
||||
use validator::Validate;
|
||||
@@ -18,7 +19,7 @@ use crate::state::DiaryState;
|
||||
path = "/api/v1/diary/classes",
|
||||
request_body = CreateClassReq,
|
||||
responses(
|
||||
(status = 200, description = "创建成功", body = ApiResponse<ClassResp>),
|
||||
(status = 201, description = "创建成功", body = ApiResponse<ClassResp>),
|
||||
(status = 400, description = "验证失败"),
|
||||
(status = 401, description = "未授权"),
|
||||
(status = 403, description = "权限不足"),
|
||||
@@ -33,7 +34,7 @@ pub async fn create_class<S>(
|
||||
State(state): State<DiaryState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Json(req): Json<CreateClassReq>,
|
||||
) -> Result<Json<ApiResponse<ClassResp>>, AppError>
|
||||
) -> Result<(StatusCode, Json<ApiResponse<ClassResp>>), AppError>
|
||||
where
|
||||
DiaryState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
@@ -55,7 +56,7 @@ where
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(Json(ApiResponse::ok(resp)))
|
||||
Ok((StatusCode::CREATED, Json(ApiResponse::ok(resp))))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
@@ -63,7 +64,7 @@ where
|
||||
path = "/api/v1/diary/classes/join",
|
||||
request_body = JoinClassReq,
|
||||
responses(
|
||||
(status = 200, description = "加入成功", body = ApiResponse<ClassResp>),
|
||||
(status = 201, description = "加入成功", body = ApiResponse<ClassResp>),
|
||||
(status = 400, description = "班级码无效或已过期"),
|
||||
(status = 401, description = "未授权"),
|
||||
(status = 403, description = "权限不足"),
|
||||
@@ -78,7 +79,7 @@ pub async fn join_class<S>(
|
||||
State(state): State<DiaryState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Json(req): Json<JoinClassReq>,
|
||||
) -> Result<Json<ApiResponse<ClassResp>>, AppError>
|
||||
) -> Result<(StatusCode, Json<ApiResponse<ClassResp>>), AppError>
|
||||
where
|
||||
DiaryState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
@@ -101,7 +102,7 @@ where
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(Json(ApiResponse::ok(resp)))
|
||||
Ok((StatusCode::CREATED, Json(ApiResponse::ok(resp))))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// 评语 API 处理器 — 老师点评学生日记
|
||||
|
||||
use axum::extract::{Extension, FromRef, Path, State};
|
||||
use axum::http::StatusCode;
|
||||
use axum::response::Json;
|
||||
use uuid::Uuid;
|
||||
use validator::Validate;
|
||||
@@ -19,7 +20,7 @@ use crate::state::DiaryState;
|
||||
params(("journal_id" = Uuid, Path, description = "日记ID")),
|
||||
request_body = CreateCommentReq,
|
||||
responses(
|
||||
(status = 200, description = "点评成功", body = ApiResponse<CommentResp>),
|
||||
(status = 201, description = "点评成功", body = ApiResponse<CommentResp>),
|
||||
(status = 400, description = "验证失败或内容安全检查未通过"),
|
||||
(status = 401, description = "未授权"),
|
||||
(status = 403, description = "权限不足或不是本班老师"),
|
||||
@@ -37,7 +38,7 @@ pub async fn create_comment<S>(
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(journal_id): Path<Uuid>,
|
||||
Json(req): Json<CreateCommentReq>,
|
||||
) -> Result<Json<ApiResponse<CommentResp>>, AppError>
|
||||
) -> Result<(StatusCode, Json<ApiResponse<CommentResp>>), AppError>
|
||||
where
|
||||
DiaryState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
@@ -59,7 +60,7 @@ where
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(Json(ApiResponse::ok(resp)))
|
||||
Ok((StatusCode::CREATED, Json(ApiResponse::ok(resp))))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// 日记 API 处理器 — CRUD + 列表
|
||||
|
||||
use axum::extract::{Extension, FromRef, Path, Query, State};
|
||||
use axum::http::StatusCode;
|
||||
use axum::response::Json;
|
||||
use serde::Deserialize;
|
||||
use utoipa::IntoParams;
|
||||
@@ -39,7 +40,7 @@ pub struct JournalListParams {
|
||||
path = "/api/v1/diary/journals",
|
||||
request_body = CreateJournalReq,
|
||||
responses(
|
||||
(status = 200, description = "创建成功", body = ApiResponse<JournalResp>),
|
||||
(status = 201, description = "创建成功", body = ApiResponse<JournalResp>),
|
||||
(status = 400, description = "验证失败"),
|
||||
(status = 401, description = "未授权"),
|
||||
(status = 403, description = "权限不足"),
|
||||
@@ -54,7 +55,7 @@ pub async fn create_journal<S>(
|
||||
State(state): State<DiaryState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Json(req): Json<CreateJournalReq>,
|
||||
) -> Result<Json<ApiResponse<JournalResp>>, AppError>
|
||||
) -> Result<(StatusCode, Json<ApiResponse<JournalResp>>), AppError>
|
||||
where
|
||||
DiaryState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
@@ -76,7 +77,7 @@ where
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(Json(ApiResponse::ok(resp)))
|
||||
Ok((StatusCode::CREATED, Json(ApiResponse::ok(resp))))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// 家长中心 API 处理器 — PIPL 合规: 绑定/查阅/导出/删除
|
||||
|
||||
use axum::extract::{Extension, FromRef, Path, Query, State};
|
||||
use axum::http::StatusCode;
|
||||
use axum::response::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::{IntoParams, ToSchema};
|
||||
@@ -71,7 +72,7 @@ pub struct DeleteResultResp {
|
||||
path = "/api/v1/diary/parent/bind",
|
||||
request_body = BindChildReq,
|
||||
responses(
|
||||
(status = 200, description = "绑定成功", body = ApiResponse<BindingResp>),
|
||||
(status = 201, description = "绑定成功", body = ApiResponse<BindingResp>),
|
||||
(status = 400, description = "已绑定该孩子"),
|
||||
(status = 401, description = "未授权"),
|
||||
(status = 403, description = "权限不足"),
|
||||
@@ -86,7 +87,7 @@ pub async fn bind_child<S>(
|
||||
State(state): State<DiaryState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Json(req): Json<BindChildReq>,
|
||||
) -> Result<Json<ApiResponse<BindingResp>>, AppError>
|
||||
) -> Result<(StatusCode, Json<ApiResponse<BindingResp>>), AppError>
|
||||
where
|
||||
DiaryState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
@@ -102,11 +103,11 @@ where
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(Json(ApiResponse::ok(BindingResp {
|
||||
Ok((StatusCode::CREATED, Json(ApiResponse::ok(BindingResp {
|
||||
binding_id: binding.id,
|
||||
child_id: binding.child_id,
|
||||
verified_at: binding.verified_at,
|
||||
})))
|
||||
}))))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
@@ -357,7 +358,7 @@ where
|
||||
path = "/api/v1/diary/parent/bindings/{binding_id}/confirm",
|
||||
params(("binding_id" = Uuid, Path, description = "绑定请求ID")),
|
||||
responses(
|
||||
(status = 200, description = "确认成功", body = ApiResponse<BindingResp>),
|
||||
(status = 201, description = "确认成功", body = ApiResponse<BindingResp>),
|
||||
(status = 401, description = "未授权"),
|
||||
(status = 403, description = "无权确认此绑定"),
|
||||
(status = 404, description = "绑定请求不存在"),
|
||||
@@ -372,7 +373,7 @@ pub async fn confirm_binding<S>(
|
||||
State(state): State<DiaryState>,
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(binding_id): Path<Uuid>,
|
||||
) -> Result<Json<ApiResponse<BindingResp>>, AppError>
|
||||
) -> Result<(StatusCode, Json<ApiResponse<BindingResp>>), AppError>
|
||||
where
|
||||
DiaryState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
@@ -386,11 +387,11 @@ where
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(Json(ApiResponse::ok(BindingResp {
|
||||
Ok((StatusCode::CREATED, Json(ApiResponse::ok(BindingResp {
|
||||
binding_id: binding.id,
|
||||
child_id: binding.parent_id,
|
||||
verified_at: binding.verified_at,
|
||||
})))
|
||||
}))))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// 主题布置 API 处理器 — 老师布置/查询主题
|
||||
|
||||
use axum::extract::{Extension, FromRef, Path, State};
|
||||
use axum::http::StatusCode;
|
||||
use axum::response::Json;
|
||||
use uuid::Uuid;
|
||||
use validator::Validate;
|
||||
@@ -19,7 +20,7 @@ use crate::state::DiaryState;
|
||||
params(("class_id" = Uuid, Path, description = "班级ID")),
|
||||
request_body = CreateTopicReq,
|
||||
responses(
|
||||
(status = 200, description = "布置成功", body = ApiResponse<TopicResp>),
|
||||
(status = 201, description = "布置成功", body = ApiResponse<TopicResp>),
|
||||
(status = 400, description = "验证失败"),
|
||||
(status = 401, description = "未授权"),
|
||||
(status = 403, description = "权限不足"),
|
||||
@@ -36,7 +37,7 @@ pub async fn assign_topic<S>(
|
||||
Extension(ctx): Extension<TenantContext>,
|
||||
Path(class_id): Path<Uuid>,
|
||||
Json(req): Json<CreateTopicReq>,
|
||||
) -> Result<Json<ApiResponse<TopicResp>>, AppError>
|
||||
) -> Result<(StatusCode, Json<ApiResponse<TopicResp>>), AppError>
|
||||
where
|
||||
DiaryState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
@@ -58,7 +59,7 @@ where
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(Json(ApiResponse::ok(resp)))
|
||||
Ok((StatusCode::CREATED, Json(ApiResponse::ok(resp))))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
|
||||
Reference in New Issue
Block a user