- Updated `lib.rs` to selectively expose specific entities and services for better clarity. - Improved SurrealDB client initialization with detailed logging in `surrealdb/mod.rs`. - Enhanced resource definitions in `resource.rs` with additional utility methods for better resource management. - Refactored user data retrieval logic in `auth_middleware/mod.rs` for improved readability and efficiency. - Cleaned up middleware exports in `lib.rs` for clearer API surface. - Added detailed comments and documentation throughout the SurrealDB module for better maintainability. - Updated tests to ensure compatibility with new changes and improved structure. - Introduced new permissions module structure in `imphnen-utils` for future enhancements.
67 lines
1.6 KiB
Rust
67 lines
1.6 KiB
Rust
use crate::v1::gacha_rolls::gacha_rolls_dto::GachaRollQueryDto;
|
|
use crate::{make_thing};
|
|
use imphnen_iam::get_iso_date;
|
|
use imphnen_libs::ResourceEnum;
|
|
use serde::{Deserialize, Serialize};
|
|
use surrealdb::{Uuid, sql::Thing};
|
|
|
|
use crate::v1::gacha_claims::gacha_claims_dto::GachaClaimRequestDto;
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
pub struct GachaClaimSchema {
|
|
pub id: Thing,
|
|
pub user: Thing,
|
|
pub item: Thing,
|
|
pub is_deleted: bool,
|
|
pub created_at: Option<String>,
|
|
pub updated_at: Option<String>,
|
|
}
|
|
|
|
impl Default for GachaClaimSchema {
|
|
fn default() -> Self {
|
|
GachaClaimSchema {
|
|
id: make_thing(
|
|
&ResourceEnum::GachaClaims.to_string(),
|
|
&Uuid::new_v4().to_string(),
|
|
),
|
|
user: make_thing(
|
|
&ResourceEnum::Users.to_string(),
|
|
&Uuid::new_v4().to_string(),
|
|
),
|
|
item: make_thing(
|
|
&ResourceEnum::GachaItems.to_string(),
|
|
&Uuid::new_v4().to_string(),
|
|
),
|
|
is_deleted: false,
|
|
created_at: Some(get_iso_date()),
|
|
updated_at: Some(get_iso_date()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl GachaClaimSchema {
|
|
pub fn from(dto: GachaClaimRequestDto) -> Self {
|
|
Self {
|
|
id: make_thing(
|
|
&ResourceEnum::GachaClaims.to_string(),
|
|
&Uuid::new_v4().to_string(),
|
|
),
|
|
user: make_thing(&ResourceEnum::Users.to_string(), &dto.user_id),
|
|
item: make_thing(&ResourceEnum::GachaItems.to_string(), &dto.item_id),
|
|
..Default::default()
|
|
}
|
|
}
|
|
|
|
pub fn roll(roll: GachaRollQueryDto, user_id: Thing) -> Self {
|
|
Self {
|
|
id: make_thing(
|
|
&ResourceEnum::GachaClaims.to_string(),
|
|
&Uuid::new_v4().to_string(),
|
|
),
|
|
user: user_id,
|
|
item: roll.item.id.clone(),
|
|
..Default::default()
|
|
}
|
|
}
|
|
}
|