feat(diary): 添加贴纸包 UpdateStickerPackReq DTO + update service/handler — Task 13
This commit is contained in:
@@ -6,7 +6,7 @@ use sea_orm::{
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::dto::{CreateStickerPackReq, CreateStickerReq, StickerPackResp, StickerResp, TemplateResp};
|
||||
use crate::dto::{CreateStickerPackReq, CreateStickerReq, StickerPackResp, StickerResp, TemplateResp, UpdateStickerPackReq};
|
||||
use crate::entity::{sticker, sticker_pack, template};
|
||||
use crate::error::{DiaryError, DiaryResult};
|
||||
|
||||
@@ -192,6 +192,67 @@ impl StickerService {
|
||||
})
|
||||
}
|
||||
|
||||
/// 更新贴纸包(部分更新,仅修改传入的字段)
|
||||
pub async fn update_sticker_pack(
|
||||
tenant_id: Uuid,
|
||||
pack_id: Uuid,
|
||||
user_id: Uuid,
|
||||
req: &UpdateStickerPackReq,
|
||||
db: &DatabaseConnection,
|
||||
) -> DiaryResult<StickerPackResp> {
|
||||
let model = sticker_pack::Entity::find()
|
||||
.filter(sticker_pack::Column::Id.eq(pack_id))
|
||||
.filter(sticker_pack::Column::TenantId.eq(tenant_id))
|
||||
.filter(sticker_pack::Column::DeletedAt.is_null())
|
||||
.one(db)
|
||||
.await?
|
||||
.ok_or_else(|| DiaryError::NotFound(format!("贴纸包 {} 不存在", pack_id)))?;
|
||||
|
||||
let now = chrono::Utc::now();
|
||||
let mut active: sticker_pack::ActiveModel = model.into();
|
||||
|
||||
if let Some(ref name) = req.name {
|
||||
active.name = Set(name.clone());
|
||||
}
|
||||
if let Some(ref description) = req.description {
|
||||
active.description = Set(Some(description.clone()));
|
||||
}
|
||||
if let Some(ref thumbnail_url) = req.thumbnail_url {
|
||||
active.thumbnail_url = Set(Some(thumbnail_url.clone()));
|
||||
}
|
||||
if let Some(is_free) = req.is_free {
|
||||
active.is_free = Set(is_free);
|
||||
}
|
||||
if let Some(price) = req.price {
|
||||
active.price = Set(price);
|
||||
}
|
||||
if let Some(ref category) = req.category {
|
||||
active.category = Set(Some(category.clone()));
|
||||
}
|
||||
|
||||
active.updated_at = Set(now);
|
||||
active.updated_by = Set(user_id);
|
||||
|
||||
let updated = active.update(db).await?;
|
||||
|
||||
// 查询贴纸数量
|
||||
let sticker_count = sticker::Entity::find()
|
||||
.filter(sticker::Column::PackId.eq(updated.id))
|
||||
.filter(sticker::Column::DeletedAt.is_null())
|
||||
.count(db)
|
||||
.await? as i32;
|
||||
|
||||
Ok(StickerPackResp {
|
||||
id: updated.id,
|
||||
name: updated.name,
|
||||
description: updated.description,
|
||||
cover_image_url: updated.thumbnail_url,
|
||||
sticker_count,
|
||||
is_free: updated.is_free,
|
||||
category: updated.category,
|
||||
})
|
||||
}
|
||||
|
||||
/// 删除贴纸包(软删除)
|
||||
pub async fn delete_sticker_pack(
|
||||
tenant_id: Uuid,
|
||||
|
||||
Reference in New Issue
Block a user