2024-03-16 03:27:36 +01:00
|
|
|
pub mod user;
|
2024-03-16 05:45:58 +01:00
|
|
|
pub mod object;
|
2023-12-30 05:08:05 +01:00
|
|
|
pub mod activity;
|
2024-03-16 05:45:58 +01:00
|
|
|
|
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-16 05:45:58 +01:00
|
|
|
pub async fn faker(db: &sea_orm::DatabaseConnection) -> Result<(), sea_orm::DbErr> {
|
|
|
|
use sea_orm::EntityTrait;
|
|
|
|
|
|
|
|
user::Entity::insert(user::ActiveModel {
|
|
|
|
id: sea_orm::Set("http://localhost:3000/users/root".into()),
|
|
|
|
name: sea_orm::Set("root".into()),
|
2024-03-19 06:49:21 +01:00
|
|
|
actor_type: sea_orm::Set(super::activitystream::object::actor::ActorType::Person),
|
2024-03-16 05:45:58 +01:00
|
|
|
}).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 {
|
|
|
|
id: sea_orm::Set(format!("http://localhost:3000/objects/{oid}")),
|
|
|
|
name: sea_orm::Set(None),
|
|
|
|
object_type: sea_orm::Set(crate::activitystream::object::ObjectType::Note),
|
|
|
|
attributed_to: sea_orm::Set(Some("http://localhost:3000/users/root".into())),
|
|
|
|
summary: sea_orm::Set(None),
|
|
|
|
content: sea_orm::Set(Some(format!("Hello world! {i}"))),
|
|
|
|
published: sea_orm::Set(chrono::Utc::now() - std::time::Duration::from_secs(60*i)),
|
|
|
|
}).exec(db).await?;
|
2024-03-16 05:45:58 +01:00
|
|
|
|
2024-03-20 07:53:45 +01:00
|
|
|
activity::Entity::insert(activity::ActiveModel {
|
|
|
|
id: sea_orm::Set(format!("http://localhost:3000/activities/{aid}")),
|
|
|
|
activity_type: sea_orm::Set(crate::activitystream::object::activity::ActivityType::Create),
|
|
|
|
actor: sea_orm::Set("http://localhost:3000/users/root".into()),
|
|
|
|
object: sea_orm::Set(Some(format!("http://localhost:3000/objects/{oid}"))),
|
|
|
|
target: sea_orm::Set(None),
|
|
|
|
published: sea_orm::Set(chrono::Utc::now() - std::time::Duration::from_secs(60*i)),
|
|
|
|
}).exec(db).await?;
|
|
|
|
}
|
2024-03-16 05:45:58 +01:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|