Skip to content

Commit b3f4155

Browse files
committed
add status and status_changed_at
1 parent 2ff714b commit b3f4155

File tree

9 files changed

+91
-14
lines changed

9 files changed

+91
-14
lines changed

docs/db/refactor_platform_rs.dbml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ Table refactor_platform.agreements {
6666
coaching_session_id uuid [not null]
6767
details varchar [note: 'Either a short or long description of an agreement reached between coach and coachee in a coaching session']
6868
user_id uuid [not null, note: 'User that created (owns) the agreement']
69+
status status [not null]
70+
status_changed_at timestamptz
6971
created_at timestamptz [not null, default: `now()`]
7072
updated_at timestamptz [not null, default: `now()`, note: 'The last date and time an overarching agreement\'s fields were changed']
7173
}
@@ -77,12 +79,18 @@ Table refactor_platform.actions {
7779
// its due_by is passed or it was completed by the coachee
7880
coaching_session_id uuid [not null]
7981
due_by timestamptz
80-
completed boolean // May be unnecessary if there's a valid completed_at timestamp
81-
completed_at timestamptz
82+
status status [not null]
83+
status_changed_at timestamptz
8284
created_at timestamp [not null, default: `now()`]
8385
updated_at timestamp [not null, default: `now()`]
8486
}
8587

88+
enum status {
89+
in_progress
90+
completed
91+
wont_do
92+
}
93+
8694
// coaching_relationships relationships
8795
Ref: refactor_platform.coaching_relationships.organization_id > refactor_platform.organizations.id
8896
Ref: refactor_platform.coaching_relationships.coachee_id > refactor_platform.users.id

entity/src/actions.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
22
3-
use crate::Id;
3+
use crate::{status, Id};
44
use sea_orm::entity::prelude::*;
55
use serde::{Deserialize, Serialize};
66

@@ -13,6 +13,8 @@ pub struct Model {
1313
pub due_by: Option<DateTimeWithTimeZone>,
1414
pub completed: Option<bool>,
1515
pub completed_at: Option<DateTimeWithTimeZone>,
16+
pub status: status::Status,
17+
pub status_changed_at: Option<DateTimeWithTimeZone>,
1618
pub created_at: DateTimeWithTimeZone,
1719
pub updated_at: DateTimeWithTimeZone,
1820
}

entity/src/agreements.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
22
3-
use crate::Id;
3+
use crate::{status, Id};
44
use sea_orm::entity::prelude::*;
55
use serde::{Deserialize, Serialize};
66
use utoipa::ToSchema;
@@ -17,6 +17,10 @@ pub struct Model {
1717
pub details: Option<String>,
1818
pub user_id: Id,
1919
#[serde(skip_deserializing)]
20+
pub status: status::Status,
21+
#[serde(skip_deserializing)]
22+
pub status_changed_at: Option<DateTimeWithTimeZone>,
23+
#[serde(skip_deserializing)]
2024
pub created_at: DateTimeWithTimeZone,
2125
#[serde(skip_deserializing)]
2226
pub updated_at: DateTimeWithTimeZone,

entity/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub mod coaching_sessions;
1111
pub mod notes;
1212
pub mod organizations;
1313
pub mod overarching_goals;
14+
pub mod status;
1415
pub mod users;
1516

1617
/// A type alias that represents any Entity's internal id field data type.

entity/src/status.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use sea_orm::entity::prelude::*;
2+
use serde::{Deserialize, Serialize};
3+
4+
#[derive(Debug, Clone, Eq, PartialEq, EnumIter, Deserialize, Serialize, DeriveActiveEnum)]
5+
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "status")]
6+
pub enum Status {
7+
#[sea_orm(string_value = "InProgress")]
8+
InProgress,
9+
#[sea_orm(string_value = "Completed")]
10+
Completed,
11+
#[sea_orm(string_value = "WontDo")]
12+
WontDo,
13+
}
14+
15+
impl std::default::Default for Status {
16+
fn default() -> Self {
17+
Self::InProgress
18+
}
19+
}

entity_api/src/agreement.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub async fn create(db: &DatabaseConnection, agreement_model: Model) -> Result<M
2222
user_id: Set(agreement_model.user_id),
2323
created_at: Set(now.into()),
2424
updated_at: Set(now.into()),
25+
status_changed_at: Set(None),
2526
..Default::default()
2627
};
2728

@@ -40,6 +41,8 @@ pub async fn update(db: &DatabaseConnection, id: Id, model: Model) -> Result<Mod
4041
coaching_session_id: Unchanged(agreement.coaching_session_id),
4142
details: Set(model.details),
4243
user_id: Unchanged(agreement.user_id),
44+
status: Unchanged(agreement.status),
45+
status_changed_at: Unchanged(agreement.status_changed_at),
4346
updated_at: Set(chrono::Utc::now().into()),
4447
created_at: Unchanged(agreement.created_at),
4548
};

migration/src/refactor_platform_rs.sql

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
-- SQL dump generated using DBML (dbml-lang.org)
22
-- Database: PostgreSQL
3-
-- Generated at: 2024-06-28T21:45:29.597Z
3+
-- Generated at: 2024-08-09T12:23:43.194Z
44

55

6+
CREATE TYPE "status" AS ENUM (
7+
'in_progress',
8+
'completed',
9+
'wont_do'
10+
);
11+
612
CREATE TABLE "refactor_platform"."organizations" (
713
"id" uuid UNIQUE PRIMARY KEY NOT NULL DEFAULT (gen_random_uuid()),
814
"name" varchar NOT NULL,
@@ -66,6 +72,8 @@ CREATE TABLE "refactor_platform"."agreements" (
6672
"coaching_session_id" uuid NOT NULL,
6773
"details" varchar,
6874
"user_id" uuid NOT NULL,
75+
"status" status NOT NULL,
76+
"status_changed_at" timestamptz,
6977
"created_at" timestamptz NOT NULL DEFAULT (now()),
7078
"updated_at" timestamptz NOT NULL DEFAULT (now())
7179
);
@@ -74,8 +82,8 @@ CREATE TABLE "refactor_platform"."actions" (
7482
"id" uuid UNIQUE PRIMARY KEY NOT NULL DEFAULT (gen_random_uuid()),
7583
"coaching_session_id" uuid NOT NULL,
7684
"due_by" timestamptz,
77-
"completed" boolean,
78-
"completed_at" timestamptz,
85+
"status" status NOT NULL,
86+
"status_changed_at" timestamptz,
7987
"created_at" timestamp NOT NULL DEFAULT (now()),
8088
"updated_at" timestamp NOT NULL DEFAULT (now())
8189
);

web/src/controller/agreement_controller.rs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,40 @@ pub async fn create(
4545

4646
debug!("New Agreement: {:?}", agreement);
4747

48-
Ok(Json(ApiResponse::new(StatusCode::CREATED.into(), agreement)))
48+
Ok(Json(ApiResponse::new(
49+
StatusCode::CREATED.into(),
50+
agreement,
51+
)))
52+
}
53+
54+
/// GET a particular Agreement specified by its id.
55+
#[utoipa::path(
56+
get,
57+
path = "/agreements/{id}",
58+
params(
59+
ApiVersion,
60+
("id" = String, Path, description = "Agreement id to retrieve")
61+
),
62+
responses(
63+
(status = 200, description = "Successfully retrieved a specific Agreement by its id", body = [entity::notes::Model]),
64+
(status = 401, description = "Unauthorized"),
65+
(status = 404, description = "Note not found"),
66+
(status = 405, description = "Method not allowed")
67+
),
68+
security(
69+
("cookie_auth" = [])
70+
)
71+
)]
72+
pub async fn read(
73+
CompareApiVersion(_v): CompareApiVersion,
74+
State(app_state): State<AppState>,
75+
Path(id): Path<Id>,
76+
) -> Result<impl IntoResponse, Error> {
77+
debug!("GET Agreement by id: {}", id);
78+
79+
let note: Option<Model> = AgreementApi::find_by_id(app_state.db_conn_ref(), id).await?;
80+
81+
Ok(Json(ApiResponse::new(StatusCode::OK.into(), note)))
4982
}
5083

5184
#[utoipa::path(
@@ -114,8 +147,5 @@ pub async fn index(
114147

115148
debug!("Found Agreements: {:?}", agreements);
116149

117-
Ok(Json(ApiResponse::new(
118-
StatusCode::OK.into(),
119-
agreements,
120-
)))
150+
Ok(Json(ApiResponse::new(StatusCode::OK.into(), agreements)))
121151
}

web/src/router.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use entity_api::user::Backend;
88
use tower_http::services::ServeDir;
99

1010
use crate::controller::{
11-
agreement_controller, coaching_session_controller, note_controller, organization, organization_controller,
12-
user_session_controller,
11+
agreement_controller, coaching_session_controller, note_controller, organization,
12+
organization_controller, user_session_controller,
1313
};
1414

1515
use utoipa::{
@@ -29,6 +29,7 @@ use utoipa_rapidoc::RapiDoc;
2929
agreement_controller::create,
3030
agreement_controller::update,
3131
agreement_controller::index,
32+
agreement_controller::read,
3233
note_controller::create,
3334
note_controller::update,
3435
note_controller::index,
@@ -108,6 +109,7 @@ fn agreement_routes(app_state: AppState) -> Router {
108109
.route("/agreements", post(agreement_controller::create))
109110
.route("/agreements/:id", put(agreement_controller::update))
110111
.route("/agreements", get(agreement_controller::index))
112+
.route("/agreements/:id", get(agreement_controller::read))
111113
.route_layer(login_required!(Backend, login_url = "/login"))
112114
.with_state(app_state)
113115
}

0 commit comments

Comments
 (0)