1
0
Fork 0
forked from alemi/upub
upub/src/model/mod.rs

43 lines
1.9 KiB
Rust
Raw Normal View History

pub mod user;
pub mod object;
pub mod activity;
2024-03-16 20:09:06 +01:00
#[derive(Debug, Clone, thiserror::Error)]
#[error("missing required field: '{0}'")]
2024-03-19 01:00:44 +01:00
pub struct FieldError(pub &'static str);
2024-03-16 20:09:06 +01:00
2024-03-20 08:56:35 +01:00
pub async fn faker(db: &sea_orm::DatabaseConnection, domain: String) -> Result<(), sea_orm::DbErr> {
use sea_orm::EntityTrait;
user::Entity::insert(user::ActiveModel {
2024-03-20 08:56:35 +01:00
id: sea_orm::Set(format!("{domain}/users/root")),
name: sea_orm::Set("root".into()),
actor_type: sea_orm::Set(super::activitystream::object::actor::ActorType::Person),
}).exec(db).await?;
2024-03-20 07:53:45 +01:00
for i in (0..100).rev() {
let oid = uuid::Uuid::new_v4();
let aid = uuid::Uuid::new_v4();
object::Entity::insert(object::ActiveModel {
2024-03-20 08:56:35 +01:00
id: sea_orm::Set(format!("{domain}/objects/{oid}")),
2024-03-20 07:53:45 +01:00
name: sea_orm::Set(None),
object_type: sea_orm::Set(crate::activitystream::object::ObjectType::Note),
2024-03-20 08:56:35 +01:00
attributed_to: sea_orm::Set(Some(format!("{domain}/users/root"))),
2024-03-20 07:53:45 +01:00
summary: sea_orm::Set(None),
2024-03-20 08:56:35 +01:00
content: sea_orm::Set(Some(format!("[{i}] Tic(k). Quasiparticle of intensive multiplicity. Tics (or ticks) are intrinsically several components of autonomously numbering anorganic populations, propagating by contagion between segmentary divisions in the order of nature. Ticks - as nonqualitative differentially-decomposable counting marks - each designate a multitude comprehended as a singular variation in tic(k)-density."))),
2024-03-20 07:53:45 +01:00
published: sea_orm::Set(chrono::Utc::now() - std::time::Duration::from_secs(60*i)),
}).exec(db).await?;
2024-03-20 07:53:45 +01:00
activity::Entity::insert(activity::ActiveModel {
2024-03-20 08:56:35 +01:00
id: sea_orm::Set(format!("{domain}/activities/{aid}")),
2024-03-20 07:53:45 +01:00
activity_type: sea_orm::Set(crate::activitystream::object::activity::ActivityType::Create),
2024-03-20 08:56:35 +01:00
actor: sea_orm::Set(format!("{domain}/users/root")),
object: sea_orm::Set(Some(format!("{domain}/objects/{oid}"))),
2024-03-20 07:53:45 +01:00
target: sea_orm::Set(None),
published: sea_orm::Set(chrono::Utc::now() - std::time::Duration::from_secs(60*i)),
}).exec(db).await?;
}
Ok(())
}