feat(diary): 数据层 + 班级系统 (Phase F1 + B3)

Flutter 数据层 (Phase F1):
- journal_entry.dart: 日记数据模型 (Mood/Weather/tags/version)
- journal_element.dart: 元素模型 (text/image/sticker/handwriting_ref/tape)
- school_class.dart: 班级模型
- user_settings.dart: 用户设置 (主题/画笔/字号)
- isar_database.dart: Isar 初始化
- api_client.dart: Dio + JWT注入 + 离线感知 + 401处理
- journal_repository.dart: 抽象接口 + InMemory实现 (乐观锁)
- sync_engine.dart: WiFi同步 + 操作队列 + 重试(5次) + 快照持久化

Rust 班级系统 (Phase B3):
- class_service.rs: 创建班级(6位码) + 加入班级 + 成员管理
- topic_service.rs: 老师布置主题 + 主题列表
- comment_service.rs: 老师点评 + 评语列表
- class_handler.rs: 5个API端点 + 权限守卫
- topic_handler.rs: 2个API端点
- comment_handler.rs: 2个API端点
- dto.rs: 新增5个DTO (ClassMemberResp/CreateTopicReq/TopicResp/CreateCommentReq/CommentResp)
- 6条新路由注册

验证: cargo check 通过, 433测试全绿, flutter analyze 1 warning
This commit is contained in:
iven
2026-06-01 00:55:51 +08:00
parent d0653614e0
commit 5e6c6fdd62
18 changed files with 2205 additions and 1 deletions

View File

@@ -0,0 +1,90 @@
// 主题布置 API 处理器 — 老师布置/查询主题
use axum::extract::{Extension, FromRef, Path, State};
use axum::response::Json;
use uuid::Uuid;
use erp_core::error::AppError;
use erp_core::rbac::require_permission;
use erp_core::types::{ApiResponse, TenantContext};
use crate::dto::{CreateTopicReq, TopicResp};
use crate::service::topic_service::TopicService;
use crate::state::DiaryState;
#[utoipa::path(
post,
path = "/api/v1/diary/classes/{class_id}/topics",
params(("class_id" = Uuid, Path, description = "班级ID")),
request_body = CreateTopicReq,
responses(
(status = 200, description = "布置成功", body = ApiResponse<TopicResp>),
(status = 400, description = "验证失败"),
(status = 401, description = "未授权"),
(status = 403, description = "权限不足"),
(status = 404, description = "班级不存在"),
),
security(("bearer_auth" = [])),
tag = "主题布置"
)]
/// POST /api/v1/diary/classes/:class_id/topics
///
/// 布置日记主题。需要 `diary.topic.assign` 权限(老师角色)。
pub async fn assign_topic<S>(
State(state): State<DiaryState>,
Extension(ctx): Extension<TenantContext>,
Path(class_id): Path<Uuid>,
Json(req): Json<CreateTopicReq>,
) -> Result<Json<ApiResponse<TopicResp>>, AppError>
where
DiaryState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
require_permission(&ctx, "diary.topic.assign")?;
if req.title.trim().is_empty() {
return Err(AppError::Validation("主题标题不能为空".to_string()));
}
let resp = TopicService::assign_topic(
ctx.tenant_id,
ctx.user_id,
class_id,
&req,
&state.db,
&state.event_bus,
)
.await?;
Ok(Json(ApiResponse::ok(resp)))
}
#[utoipa::path(
get,
path = "/api/v1/diary/classes/{class_id}/topics",
params(("class_id" = Uuid, Path, description = "班级ID")),
responses(
(status = 200, description = "成功", body = ApiResponse<Vec<TopicResp>>),
(status = 401, description = "未授权"),
(status = 403, description = "权限不足"),
),
security(("bearer_auth" = [])),
tag = "主题布置"
)]
/// GET /api/v1/diary/classes/:class_id/topics
///
/// 获取班级主题列表。需要 `diary.journal.read` 权限。
pub async fn list_topics<S>(
State(state): State<DiaryState>,
Extension(ctx): Extension<TenantContext>,
Path(class_id): Path<Uuid>,
) -> Result<Json<ApiResponse<Vec<TopicResp>>>, AppError>
where
DiaryState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
require_permission(&ctx, "diary.journal.read")?;
let resp = TopicService::list_topics(ctx.tenant_id, class_id, &state.db).await?;
Ok(Json(ApiResponse::ok(resp)))
}