Skip to content

Commit a8cd217

Browse files
authored
Merge pull request #95 from refactor-group/create_new_coaching_sessions
Create New Coaching Sessions
2 parents c5587ec + 253cc18 commit a8cd217

22 files changed

+106
-21
lines changed

Cargo.lock

+17-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
22
name = "refactor_platform_rs"
3-
version = "0.1.0"
3+
version = "1.0.0-beta1"
44
edition = "2021"
55

66
default-run = "refactor_platform_rs"
77

88
[workspace]
9-
members = [".", "entity_api", "entity", "migration", "service", "web"]
9+
members = [".", "entity_api", "entity", "migration", "service", "web", "domain"]
1010

1111
[dependencies]
1212
service = { path = "service" }

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ _For additional commands, database utilities, and debugging tips, check the [Con
179179
180180
`docs` - project documentation including architectural records, DB schema, API docs, etc
181181
182+
`domain` - Layer of abstraction above `entity_api` and intended to encapsulate most business logic. Ex. interactions between `entity_api` and network calls to the outside world.
183+
182184
`entity_api` - data operations on the various `Entity` models
183185
184186
`entity` - shape of the data models and the relationships to each other

docs/db/refactor_platform_rs.dbml

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Table refactor_platform.organizations {
55
id uuid [primary key, unique, not null, default: `gen_random_uuid()`]
66
name varchar [not null, note: 'The name of the organization that the coach <--> coachee belong to']
77
logo varchar [note: 'A URI pointing to the organization\'s logo icon file']
8+
slug varchar [note: 'Canonical name for the record. Considered immutable by convention']
89
created_at timestamptz [not null, default: `now()`]
910
updated_at timestamptz [not null, default: `now()`, note: 'The last date and time fields were changed']
1011
}
@@ -16,6 +17,7 @@ Table refactor_platform.coaching_relationships {
1617
organization_id uuid [not null, note: 'The organization associated with this coaching relationship']
1718
coach_id uuid [not null, note: 'The coach associated with this coaching relationship']
1819
coachee_id uuid [not null, note: 'The coachee associated with this coaching relationship']
20+
slug varchar [note: 'Canonical name for the record. Considered immutable by convention']
1921
created_at timestamptz [not null, default: `now()`]
2022
updated_at timestamptz [not null, default: `now()`, note: 'The last date and time fields were changed']
2123
}

docs/db/refactor_platform_rs.png

15.4 KB
Loading

domain/Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "domain"
3+
version = "1.0.0-beta1"
4+
edition = "2021"
5+
6+
[dependencies]
7+
entity = { path = "../entity" }
8+
entity_api = { path = "../entity_api" }
9+
10+
[dependencies.sea-orm]
11+
version = "1.1.0" # sea-orm version
12+
features = ["debug-print", "runtime-tokio-native-tls", "sqlx-postgres"]
13+

domain/src/coaching_session.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use entity::coaching_sessions::Model;
2+
use entity_api::{coaching_session, error::Error};
3+
use sea_orm::DatabaseConnection;
4+
5+
pub async fn create(
6+
db: &DatabaseConnection,
7+
coaching_session_model: Model,
8+
) -> Result<Model, Error> {
9+
coaching_session::create(db, coaching_session_model).await
10+
}
11+
12+
pub async fn find_by_id(db: &DatabaseConnection, id: entity::Id) -> Result<Option<Model>, Error> {
13+
coaching_session::find_by_id(db, id).await
14+
}
15+
16+
pub async fn find_by_id_with_coaching_relationship(
17+
db: &DatabaseConnection,
18+
id: entity::Id,
19+
) -> Result<(Model, entity::coaching_relationships::Model), Error> {
20+
coaching_session::find_by_id_with_coaching_relationship(db, id).await
21+
}
22+
23+
pub async fn find_by(
24+
db: &DatabaseConnection,
25+
params: std::collections::HashMap<String, String>,
26+
) -> Result<Vec<Model>, Error> {
27+
coaching_session::find_by(db, params).await
28+
}

domain/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod coaching_session;

entity/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "entity"
3-
version = "0.1.0"
3+
version = "1.0.0-beta1"
44
edition = "2021"
55

66
[lib]

entity/src/coaching_relationships.rs

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub struct Model {
2020
pub coach_id: Id,
2121
pub coachee_id: Id,
2222
#[serde(skip_deserializing)]
23+
pub slug: String,
24+
#[serde(skip_deserializing)]
2325
#[schema(value_type = String, format = DateTime)] // Applies to OpenAPI schema
2426
pub created_at: DateTimeWithTimeZone,
2527
#[serde(skip_deserializing)]

entity/src/organizations.rs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ pub struct Model {
1616
pub name: String,
1717
pub logo: Option<String>,
1818
#[serde(skip_deserializing)]
19+
pub slug: String,
20+
#[serde(skip_deserializing)]
1921
#[schema(value_type = String, format = DateTime)] // Applies to OpenAPI schema
2022
pub created_at: DateTimeWithTimeZone,
2123
#[serde(skip_deserializing)]

entity_api/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "entity_api"
3-
version = "0.1.0"
3+
version = "1.0.0-beta1"
44
edition = "2021"
55

66
[dependencies]

entity_api/src/coaching_relationship.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ mod tests {
248248
db.into_transaction_log(),
249249
[Transaction::from_sql_and_values(
250250
DatabaseBackend::Postgres,
251-
r#"SELECT "coaching_relationships"."id", "coaching_relationships"."organization_id", "coaching_relationships"."coach_id", "coaching_relationships"."coachee_id", "coaching_relationships"."created_at", "coaching_relationships"."updated_at" FROM "refactor_platform"."coaching_relationships" WHERE "coaching_relationships"."id" = $1 LIMIT $2"#,
251+
r#"SELECT "coaching_relationships"."id", "coaching_relationships"."organization_id", "coaching_relationships"."coach_id", "coaching_relationships"."coachee_id", "coaching_relationships"."slug", "coaching_relationships"."created_at", "coaching_relationships"."updated_at" FROM "refactor_platform"."coaching_relationships" WHERE "coaching_relationships"."id" = $1 LIMIT $2"#,
252252
[
253253
coaching_relationship_id.into(),
254254
sea_orm::Value::BigUnsigned(Some(1))
@@ -270,7 +270,7 @@ mod tests {
270270
db.into_transaction_log(),
271271
[Transaction::from_sql_and_values(
272272
DatabaseBackend::Postgres,
273-
r#"SELECT "coaching_relationships"."id", "coaching_relationships"."organization_id", "coaching_relationships"."coach_id", "coaching_relationships"."coachee_id", "coaching_relationships"."created_at", "coaching_relationships"."updated_at" FROM "refactor_platform"."coaching_relationships" WHERE "coaching_relationships"."coach_id" = $1 OR "coaching_relationships"."coachee_id" = $2"#,
273+
r#"SELECT "coaching_relationships"."id", "coaching_relationships"."organization_id", "coaching_relationships"."coach_id", "coaching_relationships"."coachee_id", "coaching_relationships"."slug", "coaching_relationships"."created_at", "coaching_relationships"."updated_at" FROM "refactor_platform"."coaching_relationships" WHERE "coaching_relationships"."coach_id" = $1 OR "coaching_relationships"."coachee_id" = $2"#,
274274
[user_id.into(), user_id.into()]
275275
)]
276276
);
@@ -289,7 +289,7 @@ mod tests {
289289
db.into_transaction_log(),
290290
[Transaction::from_sql_and_values(
291291
DatabaseBackend::Postgres,
292-
r#"SELECT "coaching_relationships"."id", "coaching_relationships"."organization_id", "coaching_relationships"."coach_id", "coaching_relationships"."coachee_id", "coaching_relationships"."created_at", "coaching_relationships"."updated_at" FROM "refactor_platform"."coaching_relationships" WHERE "coaching_relationships"."organization_id" IN (SELECT "organizations"."id" FROM "refactor_platform"."organizations" WHERE "organizations"."id" = $1)"#,
292+
r#"SELECT "coaching_relationships"."id", "coaching_relationships"."organization_id", "coaching_relationships"."coach_id", "coaching_relationships"."coachee_id", "coaching_relationships"."slug", "coaching_relationships"."created_at", "coaching_relationships"."updated_at" FROM "refactor_platform"."coaching_relationships" WHERE "coaching_relationships"."organization_id" IN (SELECT "organizations"."id" FROM "refactor_platform"."organizations" WHERE "organizations"."id" = $1)"#,
293293
[organization_id.clone().into()]
294294
)]
295295
);

entity_api/src/coaching_session.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ mod tests {
160160
db.into_transaction_log(),
161161
[Transaction::from_sql_and_values(
162162
DatabaseBackend::Postgres,
163-
r#"SELECT "coaching_sessions"."id" AS "A_id", "coaching_sessions"."coaching_relationship_id" AS "A_coaching_relationship_id", "coaching_sessions"."date" AS "A_date", "coaching_sessions"."timezone" AS "A_timezone", "coaching_sessions"."created_at" AS "A_created_at", "coaching_sessions"."updated_at" AS "A_updated_at", "coaching_relationships"."id" AS "B_id", "coaching_relationships"."organization_id" AS "B_organization_id", "coaching_relationships"."coach_id" AS "B_coach_id", "coaching_relationships"."coachee_id" AS "B_coachee_id", "coaching_relationships"."created_at" AS "B_created_at", "coaching_relationships"."updated_at" AS "B_updated_at" FROM "refactor_platform"."coaching_sessions" LEFT JOIN "refactor_platform"."coaching_relationships" ON "coaching_sessions"."coaching_relationship_id" = "coaching_relationships"."id" WHERE "coaching_sessions"."id" = $1 LIMIT $2"#,
163+
r#"SELECT "coaching_sessions"."id" AS "A_id", "coaching_sessions"."coaching_relationship_id" AS "A_coaching_relationship_id", "coaching_sessions"."date" AS "A_date", "coaching_sessions"."timezone" AS "A_timezone", "coaching_sessions"."created_at" AS "A_created_at", "coaching_sessions"."updated_at" AS "A_updated_at", "coaching_relationships"."id" AS "B_id", "coaching_relationships"."organization_id" AS "B_organization_id", "coaching_relationships"."coach_id" AS "B_coach_id", "coaching_relationships"."coachee_id" AS "B_coachee_id", "coaching_relationships"."slug" AS "B_slug", "coaching_relationships"."created_at" AS "B_created_at", "coaching_relationships"."updated_at" AS "B_updated_at" FROM "refactor_platform"."coaching_sessions" LEFT JOIN "refactor_platform"."coaching_relationships" ON "coaching_sessions"."coaching_relationship_id" = "coaching_relationships"."id" WHERE "coaching_sessions"."id" = $1 LIMIT $2"#,
164164
[
165165
coaching_session_id.into(),
166166
sea_orm::Value::BigUnsigned(Some(1))

entity_api/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub async fn seed_database(db: &DatabaseConnection) {
9797

9898
let refactor_coaching = organizations::ActiveModel {
9999
name: Set("Refactor Coaching".to_owned()),
100+
slug: Set("refactor-coaching".to_owned()),
100101
created_at: Set(now.into()),
101102
updated_at: Set(now.into()),
102103
..Default::default()
@@ -107,6 +108,7 @@ pub async fn seed_database(db: &DatabaseConnection) {
107108

108109
let acme_corp = organizations::ActiveModel {
109110
name: Set("Acme Corp".to_owned()),
111+
slug: Set("acme-corp".to_owned()),
110112
created_at: Set(now.into()),
111113
updated_at: Set(now.into()),
112114
..Default::default()
@@ -119,6 +121,7 @@ pub async fn seed_database(db: &DatabaseConnection) {
119121
coach_id: Set(jim_hodapp.id.clone().unwrap()),
120122
coachee_id: Set(caleb_bourg.id.clone().unwrap()),
121123
organization_id: Set(refactor_coaching.id.unwrap()),
124+
slug: Set("jim-caleb".to_owned()),
122125
created_at: Set(now.into()),
123126
updated_at: Set(now.into()),
124127
..Default::default()
@@ -131,6 +134,7 @@ pub async fn seed_database(db: &DatabaseConnection) {
131134
coach_id: Set(jim_hodapp.id.clone().unwrap()),
132135
coachee_id: Set(other_user.id.clone().unwrap()),
133136
organization_id: Set(acme_corp.id.unwrap()),
137+
slug: Set("jim-other".to_owned()),
134138
created_at: Set(now.into()),
135139
updated_at: Set(now.into()),
136140
..Default::default()

entity_api/src/organization.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub async fn update(db: &DatabaseConnection, id: Id, model: Model) -> Result<Mod
4343
id: Unchanged(organization.id),
4444
logo: Set(model.logo),
4545
name: Set(model.name),
46+
slug: Unchanged(organization.slug),
4647
updated_at: Unchanged(organization.updated_at),
4748
created_at: Unchanged(organization.created_at),
4849
};
@@ -144,13 +145,15 @@ mod tests {
144145
organizations::Model {
145146
id: Id::new_v4(),
146147
name: "Organization One".to_owned(),
148+
slug: "organization-one".to_owned(),
147149
created_at: now.into(),
148150
updated_at: now.into(),
149151
logo: None,
150152
},
151153
organizations::Model {
152154
id: Id::new_v4(),
153155
name: "Organization One".to_owned(),
156+
slug: "organization-one".to_owned(),
154157
created_at: now.into(),
155158
updated_at: now.into(),
156159
logo: None,
@@ -176,7 +179,7 @@ mod tests {
176179
db.into_transaction_log(),
177180
[Transaction::from_sql_and_values(
178181
DatabaseBackend::Postgres,
179-
r#"SELECT DISTINCT "organizations"."id", "organizations"."name", "organizations"."logo", "organizations"."created_at", "organizations"."updated_at" FROM "refactor_platform"."organizations" INNER JOIN "refactor_platform"."coaching_relationships" ON "organizations"."id" = "coaching_relationships"."organization_id" WHERE "coaching_relationships"."coach_id" = $1 OR "coaching_relationships"."coachee_id" = $2"#,
182+
r#"SELECT DISTINCT "organizations"."id", "organizations"."name", "organizations"."logo", "organizations"."slug", "organizations"."created_at", "organizations"."updated_at" FROM "refactor_platform"."organizations" INNER JOIN "refactor_platform"."coaching_relationships" ON "organizations"."id" = "coaching_relationships"."organization_id" WHERE "coaching_relationships"."coach_id" = $1 OR "coaching_relationships"."coachee_id" = $2"#,
180183
[user_id.clone().into(), user_id.into()]
181184
)]
182185
);

migration/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "migration"
3-
version = "0.1.0"
3+
version = "1.0.0-beta1"
44
edition = "2021"
55
publish = false
66

migration/src/refactor_platform_rs.sql

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- SQL dump generated using DBML (dbml.dbdiagram.io)
22
-- Database: PostgreSQL
3-
-- Generated at: 2025-01-04T15:25:10.725Z
3+
-- Generated at: 2025-01-05T12:30:08.165Z
44

55

66
CREATE TYPE "refactor_platform"."status" AS ENUM (
@@ -14,6 +14,7 @@ CREATE TABLE "refactor_platform"."organizations" (
1414
"id" uuid UNIQUE PRIMARY KEY NOT NULL DEFAULT (gen_random_uuid()),
1515
"name" varchar NOT NULL,
1616
"logo" varchar,
17+
"slug" varchar,
1718
"created_at" timestamptz NOT NULL DEFAULT (now()),
1819
"updated_at" timestamptz NOT NULL DEFAULT (now())
1920
);
@@ -23,6 +24,7 @@ CREATE TABLE "refactor_platform"."coaching_relationships" (
2324
"organization_id" uuid NOT NULL,
2425
"coach_id" uuid NOT NULL,
2526
"coachee_id" uuid NOT NULL,
27+
"slug" varchar,
2628
"created_at" timestamptz NOT NULL DEFAULT (now()),
2729
"updated_at" timestamptz NOT NULL DEFAULT (now())
2830
);
@@ -96,6 +98,8 @@ COMMENT ON COLUMN "refactor_platform"."organizations"."name" IS 'The name of the
9698

9799
COMMENT ON COLUMN "refactor_platform"."organizations"."logo" IS 'A URI pointing to the organization''s logo icon file';
98100

101+
COMMENT ON COLUMN "refactor_platform"."organizations"."slug" IS 'A human-friendly canonical name for a record. Considered immutable by convention. Must be unique.';
102+
99103
COMMENT ON COLUMN "refactor_platform"."organizations"."updated_at" IS 'The last date and time fields were changed';
100104

101105
COMMENT ON COLUMN "refactor_platform"."coaching_relationships"."organization_id" IS 'The organization associated with this coaching relationship';
@@ -104,6 +108,8 @@ COMMENT ON COLUMN "refactor_platform"."coaching_relationships"."coach_id" IS 'Th
104108

105109
COMMENT ON COLUMN "refactor_platform"."coaching_relationships"."coachee_id" IS 'The coachee associated with this coaching relationship';
106110

111+
COMMENT ON COLUMN "refactor_platform"."coaching_relationships"."slug" IS 'A human-friendly canonical name for a record. Considered immutable by convention. Must be unique.';
112+
107113
COMMENT ON COLUMN "refactor_platform"."coaching_relationships"."updated_at" IS 'The last date and time fields were changed';
108114

109115
COMMENT ON COLUMN "refactor_platform"."users"."display_name" IS 'If a user wants to go by something other than first & last names';

service/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "service"
3-
version = "0.1.0"
3+
version = "1.0.0-beta1"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

web/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
[package]
22
name = "web"
3-
version = "0.1.0"
3+
version = "1.0.0-beta1"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9+
domain = { path = "../domain" }
910
entity = { path = "../entity" }
1011
entity_api = { path = "../entity_api" }
1112
service = { path = "../service" }

web/src/controller/coaching_session_controller.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use axum::extract::{Query, State};
77
use axum::http::StatusCode;
88
use axum::response::IntoResponse;
99
use axum::Json;
10+
use domain::coaching_session as CoachingSessionApi;
1011
use entity::coaching_sessions::Model;
11-
use entity_api::coaching_session as CoachingSessionApi;
1212
use service::config::ApiVersion;
1313
use std::collections::HashMap;
1414

0 commit comments

Comments
 (0)