-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow adding other entities to collections (#401)
* feat(backend): add table for entity to collection * feat(backend): generate entities for new models * refactor(backend): move common stuff out of dedicated modules * feat(backend): make fk names better * feat(backend): migration to drop useless tables * chore(backend): remove useless associations * fix(backend): remove useless table code * feat(backend): mostly migrate to new models * style(backend): remove useless model variants * fix(backend): correct usage of entity of collection * chore(graphql): regenrate types * chore(frontend): adapt to new gql schema * fix(backend): skip exercises which we don't have in db * feat(backend): allow adding other entities to collections * chore(frontend, graphql): adapt to new gql schema * feat(backend): allow removing any entity from collection * chore(frontend): adapt to new gql schema * refactor(backend): change name of query * chore(frontend): adapt to new gql schema * feat(backend): allow getting collections for any entity * feat(backend): return collections for people * refactor(graphql): extract common stuff to fragment * feat(backend): include collections for people * refactor(backend): rename model to better name * feat(backend): allow adding exercises to collections * feat(backend): allow adding/removing exercises to collections * refactor(backend): change name of mutations * chore(graphql): adapt to new gql schema * refactor(backend): extract fn to add entity to collection * feat(backend): allow custom exercises to collection * fix(backend): change name of field * feat(backend): update col_to_entity association * feat(backend): return entity lot for collection contents * chore(frontend): adapt to new schema * feat(frontend): open timer drawer when rest timer enabled * feat(backend): return all data types for collection contents * fix(backend): return year for people * fix(frontend): render correct metadata * refactor(frontend): extract component to add entity to collection * feat(frontend): allow adding people to collections * feat(backend): do not clean up people that have been added to collections * refactor(frontend): component to display collections * feat(frontend): display collections for people * feat(backend): extract fn to get collections for entities * chore(graphql): use fragments where possible * feat(backend): resolver to get user's metadata group details * feat(frontend): UI to add metadata group to collection * fix(frontend): do not display entire entity lot * Revert "fix(frontend): do not display entire entity lot" This reverts commit aa8118e. * feat(backend): return collections for exercises * feat(backend): return exercise collections data * fix(frontend): adapt to new gql schema * feat(frontend): allow adding exercise to collection * fix(frontend): do not display useless tabs * fix(frontend): adapt to new gql schema * fix(backend): change name of column * build(backend): bump version
- Loading branch information
Showing
50 changed files
with
1,384 additions
and
722 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3 | ||
use async_trait::async_trait; | ||
use sea_orm::entity::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::utils::associate_user_with_metadata; | ||
|
||
use super::prelude::Collection; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] | ||
#[sea_orm(table_name = "collection_to_entity")] | ||
pub struct Model { | ||
#[sea_orm(primary_key)] | ||
pub id: i32, | ||
pub last_updated_on: DateTimeUtc, | ||
pub collection_id: i32, | ||
pub metadata_id: Option<i32>, | ||
pub person_id: Option<i32>, | ||
pub metadata_group_id: Option<i32>, | ||
pub exercise_id: Option<i32>, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation { | ||
#[sea_orm( | ||
belongs_to = "super::collection::Entity", | ||
from = "Column::CollectionId", | ||
to = "super::collection::Column::Id", | ||
on_update = "Cascade", | ||
on_delete = "Cascade" | ||
)] | ||
Collection, | ||
#[sea_orm( | ||
belongs_to = "super::metadata::Entity", | ||
from = "Column::MetadataId", | ||
to = "super::metadata::Column::Id", | ||
on_update = "Cascade", | ||
on_delete = "Cascade" | ||
)] | ||
Metadata, | ||
#[sea_orm( | ||
belongs_to = "super::metadata_group::Entity", | ||
from = "Column::MetadataGroupId", | ||
to = "super::metadata_group::Column::Id", | ||
on_update = "Cascade", | ||
on_delete = "Cascade" | ||
)] | ||
MetadataGroup, | ||
#[sea_orm( | ||
belongs_to = "super::person::Entity", | ||
from = "Column::PersonId", | ||
to = "super::person::Column::Id", | ||
on_update = "Cascade", | ||
on_delete = "Cascade" | ||
)] | ||
Person, | ||
#[sea_orm( | ||
belongs_to = "super::exercise::Entity", | ||
from = "Column::ExerciseId", | ||
to = "super::exercise::Column::Id", | ||
on_update = "Cascade", | ||
on_delete = "Cascade" | ||
)] | ||
Exercise, | ||
} | ||
|
||
impl Related<super::collection::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Collection.def() | ||
} | ||
} | ||
|
||
impl Related<super::metadata::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Metadata.def() | ||
} | ||
} | ||
|
||
impl Related<super::metadata_group::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::MetadataGroup.def() | ||
} | ||
} | ||
|
||
impl Related<super::person::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Person.def() | ||
} | ||
} | ||
|
||
impl Related<super::exercise::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Exercise.def() | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl ActiveModelBehavior for ActiveModel { | ||
async fn after_save<C>(model: Model, db: &C, insert: bool) -> Result<Model, DbErr> | ||
where | ||
C: ConnectionTrait, | ||
{ | ||
if let Some(metadata_id) = model.metadata_id { | ||
if insert { | ||
let collection = Collection::find_by_id(model.collection_id) | ||
.one(db) | ||
.await? | ||
.unwrap(); | ||
associate_user_with_metadata(&collection.user_id, &metadata_id, db) | ||
.await | ||
.ok(); | ||
} | ||
} | ||
Ok(model) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.