Skip to content

Commit

Permalink
add users_hoops migration, model and schema
Browse files Browse the repository at this point in the history
  • Loading branch information
wildonion committed Jul 31, 2024
1 parent 1b22395 commit 9bd6a76
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 44 deletions.
Binary file modified infra/hoopoe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 17 additions & 28 deletions infra/hoopoe.uml
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,21 @@
hide circle
skinparam linetype ortho

class "**geography_columns**" {
---
* <b>""coord_dimension""</b>: //""integer"" //
* <b>""f_geography_column""</b>: //""name"" //
* <b>""f_table_catalog""</b>: //""name"" //
* <b>""f_table_name""</b>: //""name"" //
* <b>""f_table_schema""</b>: //""name"" //
* <b>""srid""</b>: //""integer"" //
* <b>""type""</b>: //""text"" //
}

class "**geometry_columns**" {
---
* <b>""coord_dimension""</b>: //""integer"" //
* <b>""f_geometry_column""</b>: //""name"" //
* <b>""f_table_catalog""</b>: //""character varying"" //
* <b>""f_table_name""</b>: //""name"" //
* <b>""f_table_schema""</b>: //""name"" //
* <b>""srid""</b>: //""integer"" //
* <b>""type""</b>: //""character varying"" //
}

class "**hoops**" {
# <b>""id""</b>: //""integer"" <b><color:goldenrod>(PK) </color></b> //
---
* <b>""capacity""</b>: //""bigint"" //
* <b>""cover""</b>: //""character varying"" //
* <b>""created_at""</b>: //""timestamp with time zone"" //
* <b>""description""</b>: //""character varying"" //
* <b>""duration""</b>: //""bigint"" //
* <b>""entrance_fee""</b>: //""bigint"" //
* <b>""etype""</b>: //""character"" //
* <b>""is_finished""</b>: //""boolean"" //
* <b>""is_locked""</b>: //""boolean"" //
* <b>""manager""</b>: //""integer"" //
* <b>""started_at""</b>: //""timestamp with time zone"" //
* <b>""title""</b>: //""character varying"" //
* <b>""updated_at""</b>: //""timestamp with time zone"" //
}

Expand All @@ -53,16 +39,19 @@ class "**seaql_migrations**" {
* <b>""applied_at""</b>: //""bigint"" //
}

class "**spatial_ref_sys**" {
# <b>""srid""</b>: //""integer"" <b><color:goldenrod>(PK) </color></b> //
class "**users_hoops**" {
# <b>""id""</b>: //""integer"" <b><color:goldenrod>(PK) </color></b> //
---
* <b>""auth_name""</b>: //""character varying"" //
* <b>""auth_srid""</b>: //""integer"" //
* <b>""proj4text""</b>: //""character varying"" //
* <b>""srtext""</b>: //""character varying"" //
* <b>""hoop_id""</b>: //""integer"" <b><color:701fc6>(FK) </color></b> //
* <b>""is_invited""</b>: //""boolean"" //
* <b>""joined_at""</b>: //""bigint"" //
* <b>""left_at""</b>: //""bigint"" //
* <b>""user_id""</b>: //""integer"" //
}


"**users_hoops**" }o--|| "**hoops**"


@enduml

2 changes: 2 additions & 0 deletions migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub use sea_orm_migration::prelude::*;

mod m20240503_190902_hoops;
mod m20240508_213126_notifs;
mod m20240731_082953_users_hoops;

pub struct Migrator;

Expand All @@ -11,6 +12,7 @@ impl MigratorTrait for Migrator {
vec![
Box::new(m20240503_190902_hoops::Migration),
Box::new(m20240508_213126_notifs::Migration),
Box::new(m20240731_082953_users_hoops::Migration),
]
}
}
2 changes: 1 addition & 1 deletion migration/src/m20240503_190902_hoops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl MigrationTrait for Migration {
}

#[derive(DeriveIden)]
enum Hoops {
pub enum Hoops {
Table, // reserved for table name
Id, // primary key to bring the entity into life
Etype,
Expand Down
66 changes: 66 additions & 0 deletions migration/src/m20240731_082953_users_hoops.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use sea_orm_migration::prelude::*;
use crate::m20240503_190902_hoops::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {

manager
.create_table(
Table::create()
.table(UsersHoops::Table)
.if_not_exists()
.col(
ColumnDef::new(UsersHoops::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(UsersHoops::UserId).integer().not_null())
.col(ColumnDef::new(UsersHoops::HoopId).integer().not_null())
.col(ColumnDef::new(UsersHoops::IsInvited).boolean().not_null())
.col(ColumnDef::new(UsersHoops::JoinedAt).big_integer().not_null())
.col(ColumnDef::new(UsersHoops::LeftAt).big_integer().not_null())
.to_owned(),
)
.await;

manager.create_foreign_key(
sea_query::ForeignKey::create()
.name("FK_hoop_id")
// HoopId from users_hoops table is a fk to the hoops table
.from(UsersHoops::Table, UsersHoops::HoopId)
.to(Hoops::Table, Hoops::Id)
.on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade)
.to_owned()
).await;

Ok(())

}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(UsersHoops::Table).to_owned())
.await;

Ok(())

}
}

#[derive(DeriveIden)]
enum UsersHoops {
Table,
Id,
UserId,
HoopId,
IsInvited,
JoinedAt,
LeftAt,
}
14 changes: 4 additions & 10 deletions src/apis/v1/http/hoop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ use crate::*;



// todo
// check token middleware from gem server
// get event cover in add_hoop api
// store images in aws s3 or digispaces
// user_hoops table => joined_at, left_at, user_id, hoop_id, is_invited




/* -ˋˏ✄┈┈┈┈
------------------------
| Hoop CRUD controller
Expand All @@ -32,7 +23,7 @@ use crate::*;
|
NOTE: authenticating and KYCing process will be done using gem server
NOTE: authorizing and KYCing process will be done using gem server
*/

Expand All @@ -46,6 +37,9 @@ pub async fn add_hoop(
hoop_info: FormBody<HoopEventForm>
){

// check token and kyc middlewares from gem server
// store cover in aws s3 or digispaces

let cover = req.file("cover").await;
let etype = match hoop_info.etype.as_str(){
"social" => EventType::SocialGathering,
Expand Down
3 changes: 2 additions & 1 deletion src/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

pub mod prelude;

pub mod hoops;
pub mod users_hoops;
pub mod notifs;
pub mod hoops;
3 changes: 2 additions & 1 deletion src/entities/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.15

pub use super::hoops::Entity as Hoops;
pub use super::users_hoops::Entity as UsersHoops;
pub use super::notifs::Entity as Notifs;
pub use super::hoops::Entity as Hoops;
37 changes: 37 additions & 0 deletions src/entities/users_hoops.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.15

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "users_hoops")]
pub struct Model {
#[sea_orm(primary_key)]
#[serde(skip_deserializing)]
pub id: i32,
pub user_id: i32,
pub hoop_id: i32,
pub is_invited: bool,
pub joined_at: i64,
pub left_at: i64,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::hoops::Entity",
from = "Column::HoopId",
to = "super::hoops::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Hoops,
}

impl Related<super::hoops::Entity> for Entity {
fn to() -> RelationDef {
Relation::Hoops.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
8 changes: 5 additions & 3 deletions src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl<J: std::future::Future<Output: Send + Sync + 'static> +
type Task = Self;

async fn execute(&self, t: String) {

let this = self.clone();
let job = this.clone().job.clone();
tokio::spawn(job); // job is of type future, we're executing it inside another free thread
Expand Down Expand Up @@ -212,12 +212,14 @@ impl<J: std::future::Future<Output = O> + Send + Sync + 'static + Clone, S, O: S

pub fn executex_bfs(&mut self){
// execute all tasks in bfs order

// level order traversal

}

pub fn execute_dfs(&mut self){
// execute all tasks in dfs order
// inorder, preorder, postorder traversal

}

}

0 comments on commit 9bd6a76

Please sign in to comment.