feat(diary): B4+B5+B6 后端服务 + F5/F6/F7 前端模块

后端 (erp-diary):
- B4: CommentService 班级成员验证 + 删除评语 + SSE 通知推送
- B4: NotificationService 评语/主题/成就三类通知事件
- B5: StickerService 贴纸包列表 + 贴纸查询 + 模板管理
- B5: AchievementService 成就列表 + 解锁 + SSE 通知
- B6: MoodStatsService 心情统计 + 连续天数
- B6: ContentSafetyService 敏感词过滤框架
- SSE handler 增加 diary.notification.* 事件处理
- 新增 14 个 API 端点 + diary.comment.delete 权限

前端 (Flutter):
- F5: CalendarBloc + 月视图日历 + 日记列表
- F6: MoodBloc + fl_chart 心情饼图 + 统计卡片 + 连续天数
- F7: 贴纸库分类浏览 + 模板画廊
- 首页改为日记流 + 心情快速选择
- 成就页改为徽章收集展示

验证: cargo check ✓ cargo test 17/17 ✓ flutter analyze 0 error
This commit is contained in:
iven
2026-06-01 09:32:09 +08:00
parent 482eb244d5
commit 7e3597dc77
25 changed files with 3286 additions and 39 deletions

View File

@@ -0,0 +1,157 @@
// 贴纸与模板 API 处理器
use axum::extract::{Extension, FromRef, Path, Query, State};
use axum::response::Json;
use serde::Deserialize;
use utoipa::IntoParams;
use uuid::Uuid;
use erp_core::error::AppError;
use erp_core::rbac::require_permission;
use erp_core::types::{ApiResponse, TenantContext};
use crate::dto::{StickerPackResp, StickerResp, TemplateResp};
use crate::service::sticker_service::StickerService;
use crate::state::DiaryState;
/// 贴纸包查询参数
#[derive(Debug, Deserialize, IntoParams)]
pub struct StickerPackQuery {
pub category: Option<String>,
}
#[utoipa::path(
get,
path = "/api/v1/diary/sticker-packs",
params(StickerPackQuery),
responses(
(status = 200, description = "成功", body = ApiResponse<Vec<StickerPackResp>>),
),
security(("bearer_auth" = [])),
tag = "贴纸管理"
)]
/// GET /api/v1/diary/sticker-packs
///
/// 获取贴纸包列表。需要 `diary.journal.read` 权限。
pub async fn list_sticker_packs<S>(
State(state): State<DiaryState>,
Extension(ctx): Extension<TenantContext>,
Query(query): Query<StickerPackQuery>,
) -> Result<Json<ApiResponse<Vec<StickerPackResp>>>, AppError>
where
DiaryState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
require_permission(&ctx, "diary.journal.read")?;
let resp = StickerService::list_sticker_packs(
ctx.tenant_id,
query.category,
&state.db,
)
.await?;
Ok(Json(ApiResponse::ok(resp)))
}
#[utoipa::path(
get,
path = "/api/v1/diary/sticker-packs/{pack_id}/stickers",
params(("pack_id" = Uuid, Path, description = "贴纸包ID")),
responses(
(status = 200, description = "成功", body = ApiResponse<Vec<StickerResp>>),
(status = 404, description = "贴纸包不存在"),
),
security(("bearer_auth" = [])),
tag = "贴纸管理"
)]
/// GET /api/v1/diary/sticker-packs/:pack_id/stickers
///
/// 获取贴纸包内的贴纸列表。需要 `diary.journal.read` 权限。
pub async fn list_stickers_in_pack<S>(
State(state): State<DiaryState>,
Extension(ctx): Extension<TenantContext>,
Path(pack_id): Path<Uuid>,
) -> Result<Json<ApiResponse<Vec<StickerResp>>>, AppError>
where
DiaryState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
require_permission(&ctx, "diary.journal.read")?;
let resp =
StickerService::list_stickers_in_pack(ctx.tenant_id, pack_id, &state.db).await?;
Ok(Json(ApiResponse::ok(resp)))
}
/// 模板查询参数
#[derive(Debug, Deserialize, IntoParams)]
pub struct TemplateQuery {
pub category: Option<String>,
}
#[utoipa::path(
get,
path = "/api/v1/diary/templates",
params(TemplateQuery),
responses(
(status = 200, description = "成功", body = ApiResponse<Vec<TemplateResp>>),
),
security(("bearer_auth" = [])),
tag = "模板管理"
)]
/// GET /api/v1/diary/templates
///
/// 获取模板列表。需要 `diary.journal.read` 权限。
pub async fn list_templates<S>(
State(state): State<DiaryState>,
Extension(ctx): Extension<TenantContext>,
Query(query): Query<TemplateQuery>,
) -> Result<Json<ApiResponse<Vec<TemplateResp>>>, AppError>
where
DiaryState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
require_permission(&ctx, "diary.journal.read")?;
let resp = StickerService::list_templates(
ctx.tenant_id,
query.category,
&state.db,
)
.await?;
Ok(Json(ApiResponse::ok(resp)))
}
#[utoipa::path(
get,
path = "/api/v1/diary/templates/{template_id}",
params(("template_id" = Uuid, Path, description = "模板ID")),
responses(
(status = 200, description = "成功", body = ApiResponse<TemplateResp>),
(status = 404, description = "模板不存在"),
),
security(("bearer_auth" = [])),
tag = "模板管理"
)]
/// GET /api/v1/diary/templates/:template_id
///
/// 获取模板详情(含布局数据)。需要 `diary.journal.read` 权限。
pub async fn get_template<S>(
State(state): State<DiaryState>,
Extension(ctx): Extension<TenantContext>,
Path(template_id): Path<Uuid>,
) -> Result<Json<ApiResponse<TemplateResp>>, AppError>
where
DiaryState: FromRef<S>,
S: Clone + Send + Sync + 'static,
{
require_permission(&ctx, "diary.journal.read")?;
let resp =
StickerService::get_template(ctx.tenant_id, template_id, &state.db).await?;
Ok(Json(ApiResponse::ok(resp)))
}