Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more resources #62

Merged
merged 10 commits into from
Aug 23, 2024
19 changes: 15 additions & 4 deletions docs/db/refactor_platform_rs.dbml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ Table refactor_platform.coaching_sessions {

Table refactor_platform.overarching_goals {
id uuid [primary key, unique, not null, default: `gen_random_uuid()`]
user_id uuid [not null, note: 'User that created (owns) the overarching goal']
coaching_session_id uuid [note: 'The coaching session that an overarching goal is associated with']
title varchar [note: 'A short description of an overarching goal']
details varchar [note: 'A long description of an overarching goal']
body varchar [note: 'Main text of the overarching goal supporting Markdown']
completed_at timestamptz [note: 'The date and time an overarching goal was completed']
created_at timestamptz [not null, default: `now()`]
updated_at timestamptz [not null, default: `now()`, note: 'The last date and time fields were changed']
Expand All @@ -64,8 +65,10 @@ Table refactor_platform.notes {
Table refactor_platform.agreements {
id uuid [primary key, unique, not null, default: `gen_random_uuid()`]
coaching_session_id uuid [not null]
details varchar [note: 'Either a short or long description of an agreement reached between coach and coachee in a coaching session']
body varchar [note: 'Either a short or long description of an agreement reached between coach and coachee in a coaching session']
user_id uuid [not null, note: 'User that created (owns) the agreement']
status status [not null]
status_changed_at timestamptz
created_at timestamptz [not null, default: `now()`]
updated_at timestamptz [not null, default: `now()`, note: 'The last date and time an overarching agreement\'s fields were changed']
}
Expand All @@ -76,13 +79,21 @@ Table refactor_platform.actions {
// It will carry forward to every future session until
// its due_by is passed or it was completed by the coachee
coaching_session_id uuid [not null]
body varchar [note: 'Main text of the action supporting Markdown']
user_id uuid [not null, note: 'User that created (owns) the action']
due_by timestamptz
completed boolean // May be unnecessary if there's a valid completed_at timestamp
completed_at timestamptz
status status [not null]
status_changed_at timestamptz
created_at timestamp [not null, default: `now()`]
updated_at timestamp [not null, default: `now()`]
}

enum status {
in_progress
completed
wont_do
}

// coaching_relationships relationships
Ref: refactor_platform.coaching_relationships.organization_id > refactor_platform.organizations.id
Ref: refactor_platform.coaching_relationships.coachee_id > refactor_platform.users.id
Expand Down
3 changes: 2 additions & 1 deletion entity/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Entity Schema Diagram - Definitions and Relationships

![refactor_platform_erd_may_2024](https://github.com/Jim-Hodapp-Coaching/refactor-platform-rs/assets/14064042/f7cb9197-6f24-422a-953c-f44dd01c40ec)
![Untitled (1)](https://github.com/user-attachments/assets/1eea6ba9-b689-4bcb-8b7b-1d9cf725c16c)


## Example Data - A User as a Coach and Coachee in Two Different Organizations

Expand Down
31 changes: 27 additions & 4 deletions entity/src/actions.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3

use crate::Id;
use crate::{status, Id};
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize, ToSchema)]
#[sea_orm(schema_name = "refactor_platform", table_name = "actions")]
pub struct Model {
#[serde(skip_deserializing)]
#[sea_orm(primary_key)]
pub id: Id,
pub coaching_session_id: Id,
#[serde(skip_deserializing)]
pub user_id: Id,
pub body: Option<String>,
pub due_by: Option<DateTimeWithTimeZone>,
pub completed: Option<bool>,
pub completed_at: Option<DateTimeWithTimeZone>,
#[serde(skip_deserializing)]
pub status: status::Status,
#[serde(skip_deserializing)]
pub status_changed_at: Option<DateTimeWithTimeZone>,
#[serde(skip_deserializing)]
pub created_at: DateTimeWithTimeZone,
#[serde(skip_deserializing)]
pub updated_at: DateTimeWithTimeZone,
}

Expand All @@ -27,6 +36,14 @@ pub enum Relation {
on_delete = "NoAction"
)]
CoachingSessions,
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::UserId",
to = "super::users::Column::Id",
on_update = "NoAction",
on_delete = "NoAction"
)]
Users,
}

impl Related<super::coaching_sessions::Entity> for Entity {
Expand All @@ -35,4 +52,10 @@ impl Related<super::coaching_sessions::Entity> for Entity {
}
}

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

impl ActiveModelBehavior for ActiveModel {}
16 changes: 13 additions & 3 deletions entity/src/agreements.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3

use crate::Id;
use crate::{status, Id};
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize, ToSchema)]
#[schema(as = entity::agreements::Model)]
#[sea_orm(schema_name = "refactor_platform", table_name = "agreements")]
pub struct Model {
#[serde(skip_deserializing)]
#[sea_orm(primary_key)]
pub id: Id,
#[sea_orm(unique)]
pub coaching_session_id: Id,
pub details: Option<String>,
pub body: Option<String>,
#[serde(skip_deserializing)]
pub user_id: Id,
#[serde(skip_deserializing)]
pub status: status::Status,
#[serde(skip_deserializing)]
pub status_changed_at: Option<DateTimeWithTimeZone>,
#[serde(skip_deserializing)]
pub created_at: DateTimeWithTimeZone,
#[serde(skip_deserializing)]
pub updated_at: DateTimeWithTimeZone,
}

Expand Down
1 change: 1 addition & 0 deletions entity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod coaching_sessions;
pub mod notes;
pub mod organizations;
pub mod overarching_goals;
pub mod status;
pub mod users;

/// A type alias that represents any Entity's internal id field data type.
Expand Down
1 change: 1 addition & 0 deletions entity/src/notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct Model {
pub id: Id,
pub coaching_session_id: Id,
pub body: Option<String>,
#[serde(skip_deserializing)]
pub user_id: Id,
#[serde(skip_deserializing)]
pub created_at: DateTimeWithTimeZone,
Expand Down
25 changes: 23 additions & 2 deletions entity/src/overarching_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@
use crate::Id;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize, ToSchema)]
#[sea_orm(schema_name = "refactor_platform", table_name = "overarching_goals")]
pub struct Model {
#[serde(skip_deserializing)]
#[sea_orm(primary_key)]
pub id: Id,
pub coaching_session_id: Option<Id>,
#[serde(skip_deserializing)]
pub user_id: Id,
pub title: Option<String>,
pub details: Option<String>,
pub body: Option<String>,
#[serde(skip_deserializing)]
pub completed_at: Option<DateTimeWithTimeZone>,
#[serde(skip_deserializing)]
pub created_at: DateTimeWithTimeZone,
#[serde(skip_deserializing)]
pub updated_at: DateTimeWithTimeZone,
}

Expand All @@ -27,6 +34,14 @@ pub enum Relation {
on_delete = "NoAction"
)]
CoachingSessions,
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::UserId",
to = "super::users::Column::Id",
on_update = "NoAction",
on_delete = "NoAction"
)]
Users,
}

impl Related<super::coaching_sessions::Entity> for Entity {
Expand All @@ -35,4 +50,10 @@ impl Related<super::coaching_sessions::Entity> for Entity {
}
}

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

impl ActiveModelBehavior for ActiveModel {}
19 changes: 19 additions & 0 deletions entity/src/status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Eq, PartialEq, EnumIter, Deserialize, Serialize, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "status")]
pub enum Status {
#[sea_orm(string_value = "InProgress")]
InProgress,
#[sea_orm(string_value = "Completed")]
Completed,
#[sea_orm(string_value = "WontDo")]
WontDo,
}

impl std::default::Default for Status {
fn default() -> Self {
Self::InProgress
}
}
Loading
Loading