Skip to content

Commit 6274b0c

Browse files
committed
pull user_id from user sessions
1 parent b7527ae commit 6274b0c

File tree

12 files changed

+51
-34
lines changed

12 files changed

+51
-34
lines changed

entity/src/actions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct Model {
1212
#[sea_orm(primary_key)]
1313
pub id: Id,
1414
pub coaching_session_id: Id,
15+
#[serde(skip_deserializing)]
1516
pub user_id: Id,
1617
pub body: Option<String>,
1718
pub due_by: Option<DateTimeWithTimeZone>,

entity/src/agreements.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub struct Model {
1515
#[sea_orm(unique)]
1616
pub coaching_session_id: Id,
1717
pub body: Option<String>,
18+
#[serde(skip_deserializing)]
1819
pub user_id: Id,
1920
#[serde(skip_deserializing)]
2021
pub status: status::Status,

entity/src/notes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct Model {
1414
pub id: Id,
1515
pub coaching_session_id: Id,
1616
pub body: Option<String>,
17+
#[serde(skip_deserializing)]
1718
pub user_id: Id,
1819
#[serde(skip_deserializing)]
1920
pub created_at: DateTimeWithTimeZone,

entity/src/overarching_goals.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct Model {
1212
#[sea_orm(primary_key)]
1313
pub id: Id,
1414
pub coaching_session_id: Option<Id>,
15+
#[serde(skip_deserializing)]
1516
pub user_id: Id,
1617
pub title: Option<String>,
1718
pub body: Option<String>,

entity_api/src/action.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ use std::collections::HashMap;
1111

1212
use log::*;
1313

14-
pub async fn create(db: &DatabaseConnection, action_model: Model) -> Result<Model, Error> {
14+
pub async fn create(
15+
db: &DatabaseConnection,
16+
action_model: Model,
17+
user_id: Id,
18+
) -> Result<Model, Error> {
1519
debug!("New Action Model to be inserted: {:?}", action_model);
1620

1721
let now = chrono::Utc::now();
1822

1923
let action_active_model: ActiveModel = ActiveModel {
2024
coaching_session_id: Set(action_model.coaching_session_id),
21-
user_id: Set(action_model.user_id),
25+
user_id: Set(user_id),
2226
due_by: Set(action_model.due_by),
2327
body: Set(action_model.body),
2428
created_at: Set(now.into()),
@@ -127,10 +131,10 @@ mod tests {
127131

128132
let action_model = Model {
129133
id: Id::new_v4(),
134+
user_id: Id::new_v4(),
130135
coaching_session_id: Id::new_v4(),
131136
body: Some("This is a action".to_owned()),
132137
due_by: Some(now.into()),
133-
user_id: Id::new_v4(),
134138
status_changed_at: None,
135139
status: Default::default(),
136140
created_at: now.into(),
@@ -141,7 +145,7 @@ mod tests {
141145
.append_query_results(vec![vec![action_model.clone()]])
142146
.into_connection();
143147

144-
let action = create(&db, action_model.clone().into()).await?;
148+
let action = create(&db, action_model.clone().into(), Id::new_v4()).await?;
145149

146150
assert_eq!(action.id, action_model.id);
147151

entity_api/src/agreement.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ use std::collections::HashMap;
1111

1212
use log::*;
1313

14-
pub async fn create(db: &DatabaseConnection, agreement_model: Model) -> Result<Model, Error> {
14+
pub async fn create(
15+
db: &DatabaseConnection,
16+
agreement_model: Model,
17+
user_id: Id,
18+
) -> Result<Model, Error> {
1519
debug!("New Agreement Model to be inserted: {:?}", agreement_model);
1620

1721
let now = chrono::Utc::now();
1822

1923
let agreement_active_model: ActiveModel = ActiveModel {
2024
coaching_session_id: Set(agreement_model.coaching_session_id),
2125
body: Set(agreement_model.body),
22-
user_id: Set(agreement_model.user_id),
26+
user_id: Set(user_id),
2327
created_at: Set(now.into()),
2428
updated_at: Set(now.into()),
2529
status_changed_at: Set(None),
@@ -127,9 +131,9 @@ mod tests {
127131

128132
let agreement_model = Model {
129133
id: Id::new_v4(),
134+
user_id: Id::new_v4(),
130135
coaching_session_id: Id::new_v4(),
131136
body: Some("This is a agreement".to_owned()),
132-
user_id: Id::new_v4(),
133137
status_changed_at: None,
134138
status: Default::default(),
135139
created_at: now.into(),
@@ -140,7 +144,7 @@ mod tests {
140144
.append_query_results(vec![vec![agreement_model.clone()]])
141145
.into_connection();
142146

143-
let agreement = create(&db, agreement_model.clone().into()).await?;
147+
let agreement = create(&db, agreement_model.clone().into(), Id::new_v4()).await?;
144148

145149
assert_eq!(agreement.id, agreement_model.id);
146150

entity_api/src/note.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ use std::collections::HashMap;
1111

1212
use log::*;
1313

14-
pub async fn create(db: &DatabaseConnection, note_model: Model) -> Result<Model, Error> {
14+
pub async fn create(
15+
db: &DatabaseConnection,
16+
note_model: Model,
17+
user_id: Id,
18+
) -> Result<Model, Error> {
1519
debug!("New Note Model to be inserted: {:?}", note_model);
1620

1721
let now = chrono::Utc::now();
1822

1923
let note_active_model: ActiveModel = ActiveModel {
2024
coaching_session_id: Set(note_model.coaching_session_id),
2125
body: Set(note_model.body),
22-
user_id: Set(note_model.user_id),
26+
user_id: Set(user_id),
2327
created_at: Set(now.into()),
2428
updated_at: Set(now.into()),
2529
..Default::default()
@@ -123,9 +127,9 @@ mod tests {
123127

124128
let note_model = Model {
125129
id: Id::new_v4(),
130+
user_id: Id::new_v4(),
126131
coaching_session_id: Id::new_v4(),
127132
body: Some("This is a note".to_owned()),
128-
user_id: Id::new_v4(),
129133
created_at: now.into(),
130134
updated_at: now.into(),
131135
};
@@ -134,7 +138,7 @@ mod tests {
134138
.append_query_results(vec![vec![note_model.clone()]])
135139
.into_connection();
136140

137-
let note = create(&db, note_model.clone().into()).await?;
141+
let note = create(&db, note_model.clone().into(), Id::new_v4()).await?;
138142

139143
assert_eq!(note.id, note_model.id);
140144

entity_api/src/overarching_goal.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use log::*;
1515
pub async fn create(
1616
db: &DatabaseConnection,
1717
overarching_goal_model: Model,
18+
user_id: Id,
1819
) -> Result<Model, Error> {
1920
debug!(
2021
"New Overarching Goal Model to be inserted: {:?}",
@@ -25,7 +26,7 @@ pub async fn create(
2526

2627
let overarching_goal_active_model: ActiveModel = ActiveModel {
2728
coaching_session_id: Set(overarching_goal_model.coaching_session_id),
28-
user_id: Set(overarching_goal_model.user_id),
29+
user_id: Set(user_id),
2930
title: Set(overarching_goal_model.title),
3031
body: Set(overarching_goal_model.body),
3132
created_at: Set(now.into()),
@@ -135,20 +136,19 @@ pub async fn find_by(
135136
mod tests {
136137
use super::*;
137138
use entity::{overarching_goals::Model, Id};
138-
use sea_orm::{DatabaseBackend, MockDatabase, Transoverarching_goal};
139+
use sea_orm::{DatabaseBackend, MockDatabase, Transaction};
139140

140141
#[tokio::test]
141142
async fn create_returns_a_new_overarching_goal_model() -> Result<(), Error> {
142143
let now = chrono::Utc::now();
143144

144145
let overarching_goal_model = Model {
145146
id: Id::new_v4(),
146-
coaching_session_id: Id::new_v4(),
147-
body: Some("This is a overarching_goal".to_owned()),
148-
due_by: Some(now.into()),
149147
user_id: Id::new_v4(),
150-
status_changed_at: None,
151-
status: Default::default(),
148+
coaching_session_id: Some(Id::new_v4()),
149+
title: Some("title".to_owned()),
150+
body: Some("This is a overarching_goal".to_owned()),
151+
completed_at: Some(now.into()),
152152
created_at: now.into(),
153153
updated_at: now.into(),
154154
};
@@ -157,7 +157,8 @@ mod tests {
157157
.append_query_results(vec![vec![overarching_goal_model.clone()]])
158158
.into_connection();
159159

160-
let overarching_goal = create(&db, overarching_goal_model.clone().into()).await?;
160+
let overarching_goal =
161+
create(&db, overarching_goal_model.clone().into(), Id::new_v4()).await?;
161162

162163
assert_eq!(overarching_goal.id, overarching_goal_model.id);
163164

@@ -170,12 +171,11 @@ mod tests {
170171

171172
let overarching_goal_model = Model {
172173
id: Id::new_v4(),
173-
coaching_session_id: Id::new_v4(),
174-
due_by: Some(now.into()),
174+
coaching_session_id: Some(Id::new_v4()),
175+
title: Some("title".to_owned()),
175176
body: Some("This is a overarching_goal".to_owned()),
176177
user_id: Id::new_v4(),
177-
status_changed_at: None,
178-
status: Default::default(),
178+
completed_at: Some(now.into()),
179179
created_at: now.into(),
180180
updated_at: now.into(),
181181
};
@@ -215,9 +215,9 @@ mod tests {
215215

216216
assert_eq!(
217217
db.into_transaction_log(),
218-
[Transoverarching_goal::from_sql_and_values(
218+
[Transaction::from_sql_and_values(
219219
DatabaseBackend::Postgres,
220-
r#"SELECT "overarching_goals"."id", "overarching_goals"."coaching_session_id", "overarching_goals"."user_id", "overarching_goals"."body", "overarching_goals"."title", "overarching_goals"."created_at", "overarching_goals"."updated_at" FROM "refactor_platform"."overarching_goals" WHERE "overarching_goals"."coaching_session_id" = $1"#,
220+
r#"SELECT "overarching_goals"."id", "overarching_goals"."coaching_session_id", "overarching_goals"."user_id", "overarching_goals"."title", "overarching_goals"."body", "overarching_goals"."completed_at", "overarching_goals"."created_at", "overarching_goals"."updated_at" FROM "refactor_platform"."overarching_goals" WHERE "overarching_goals"."coaching_session_id" = $1"#,
221221
[coaching_session_id.into()]
222222
)]
223223
);

web/src/controller/action_controller.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ use log::*;
3333

3434
pub async fn create(
3535
CompareApiVersion(_v): CompareApiVersion,
36-
AuthenticatedUser(_user): AuthenticatedUser,
36+
AuthenticatedUser(user): AuthenticatedUser,
3737
// TODO: create a new Extractor to authorize the user to access
3838
// the data requested
3939
State(app_state): State<AppState>,
4040
Json(action_model): Json<Model>,
4141
) -> Result<impl IntoResponse, Error> {
4242
debug!("POST Create a New Action from: {:?}", action_model);
4343

44-
let action = ActionApi::create(app_state.db_conn_ref(), action_model).await?;
44+
let action = ActionApi::create(app_state.db_conn_ref(), action_model, user.id).await?;
4545

4646
debug!("New Action: {:?}", action);
4747

web/src/controller/agreement_controller.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ use log::*;
3333

3434
pub async fn create(
3535
CompareApiVersion(_v): CompareApiVersion,
36-
AuthenticatedUser(_user): AuthenticatedUser,
36+
AuthenticatedUser(user): AuthenticatedUser,
3737
// TODO: create a new Extractor to authorize the user to access
3838
// the data requested
3939
State(app_state): State<AppState>,
4040
Json(agreement_model): Json<Model>,
4141
) -> Result<impl IntoResponse, Error> {
4242
debug!("POST Create a New Agreement from: {:?}", agreement_model);
4343

44-
let agreement = AgreementApi::create(app_state.db_conn_ref(), agreement_model).await?;
44+
let agreement = AgreementApi::create(app_state.db_conn_ref(), agreement_model, user.id).await?;
4545

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

0 commit comments

Comments
 (0)