Close DDD cleanup and tests-support closure
This commit is contained in:
@@ -1,3 +1,58 @@
|
||||
//! 背包领域错误过渡落位。
|
||||
//! 背包领域错误。
|
||||
//!
|
||||
//! 错误保持可测试的业务语义,例如数量不足、槽位冲突和物品不存在。
|
||||
|
||||
use std::{error::Error, fmt};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum InventoryMutationFieldError {
|
||||
MissingMutationId,
|
||||
MissingRuntimeSessionId,
|
||||
MissingActorUserId,
|
||||
MissingSlotId,
|
||||
MissingItemId,
|
||||
MissingCategory,
|
||||
MissingName,
|
||||
InvalidQuantity,
|
||||
MissingStackKey,
|
||||
NonStackableItemMustStaySingleQuantity,
|
||||
EquipmentItemCannotStack,
|
||||
SlotScopeMismatch,
|
||||
ItemNotFound,
|
||||
ItemNotInBackpack,
|
||||
ItemNotEquipped,
|
||||
InsufficientQuantity,
|
||||
ItemNotEquippable,
|
||||
}
|
||||
|
||||
impl fmt::Display for InventoryMutationFieldError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::MissingMutationId => f.write_str("inventory_mutation.mutation_id 不能为空"),
|
||||
Self::MissingRuntimeSessionId => {
|
||||
f.write_str("inventory_mutation.runtime_session_id 不能为空")
|
||||
}
|
||||
Self::MissingActorUserId => f.write_str("inventory_mutation.actor_user_id 不能为空"),
|
||||
Self::MissingSlotId => f.write_str("inventory_slot.slot_id 不能为空"),
|
||||
Self::MissingItemId => f.write_str("inventory_item.item_id 不能为空"),
|
||||
Self::MissingCategory => f.write_str("inventory_item.category 不能为空"),
|
||||
Self::MissingName => f.write_str("inventory_item.name 不能为空"),
|
||||
Self::InvalidQuantity => f.write_str("inventory_item.quantity 必须大于 0"),
|
||||
Self::MissingStackKey => f.write_str("可堆叠物品必须提供 stack_key"),
|
||||
Self::NonStackableItemMustStaySingleQuantity => {
|
||||
f.write_str("不可堆叠物品必须固定为单槽位单数量")
|
||||
}
|
||||
Self::EquipmentItemCannotStack => f.write_str("可装备物品不能标记为 stackable"),
|
||||
Self::SlotScopeMismatch => {
|
||||
f.write_str("当前 inventory_slot 不属于本次 mutation 作用域")
|
||||
}
|
||||
Self::ItemNotFound => f.write_str("目标 inventory_slot 不存在"),
|
||||
Self::ItemNotInBackpack => f.write_str("目标物品当前不在背包中"),
|
||||
Self::ItemNotEquipped => f.write_str("目标物品当前不在装备位上"),
|
||||
Self::InsufficientQuantity => f.write_str("当前背包数量不足,无法完成扣减"),
|
||||
Self::ItemNotEquippable => f.write_str("目标物品当前不可装备"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for InventoryMutationFieldError {}
|
||||
|
||||
Reference in New Issue
Block a user