Skip to content

Commit

Permalink
Add a CREATE route for creating a new CoachingRelationship. Also put …
Browse files Browse the repository at this point in the history
…the routes in alphabetical order.
  • Loading branch information
jhodapp committed Oct 28, 2024
1 parent db1bf84 commit 702cd21
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,54 @@ use axum::extract::{Path, State};
use axum::http::StatusCode;
use axum::response::IntoResponse;
use axum::Json;
use entity::Id;
use entity::{coaching_relationships, Id};
use entity_api::coaching_relationship as CoachingRelationshipApi;
use service::config::ApiVersion;

use log::*;

/// CREATE a new CoachingRelationship.
#[utoipa::path(
post,
path = "/organizations/{organization_id}/coaching_relationships",
params(
ApiVersion,
),
request_body = entity::coaching_relationships::Model,
responses(
(status = 200, description = "Successfully created a new Coaching Relationship", body = [entity::coaching_relationships::Model]),
(status = 401, description = "Unauthorized"),
(status = 405, description = "Method not allowed")
),
security(
("cookie_auth" = [])
)
)]
pub async fn create(
CompareApiVersion(_v): CompareApiVersion,
State(app_state): State<AppState>,
Json(coaching_relationship_model): Json<coaching_relationships::Model>,
) -> Result<impl IntoResponse, Error> {
debug!(
"CREATE new Coaching Relationship from: {:?}",
coaching_relationship_model
);

let coaching_relationship: coaching_relationships::Model =
CoachingRelationshipApi::create(app_state.db_conn_ref(), coaching_relationship_model)
.await?;

debug!(
"Newly created Coaching Relationship: {:?}",
&coaching_relationship
);

Ok(Json(ApiResponse::new(
StatusCode::CREATED.into(),
coaching_relationship,
)))
}

/// GET a particular CoachingRelationship specified by the organization Id and relationship Id.
#[utoipa::path(
get,
Expand Down
63 changes: 35 additions & 28 deletions web/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use utoipa::{
};
use utoipa_rapidoc::RapiDoc;

use self::organization::coaching_relationship_controller;

// This is the global definition of our OpenAPI spec. To be a part
// of the rendered spec, a path and schema must be listed here.
#[derive(OpenApi)]
Expand Down Expand Up @@ -48,6 +50,7 @@ use utoipa_rapidoc::RapiDoc;
organization_controller::create,
organization_controller::update,
organization_controller::delete,
organization::coaching_relationship_controller::create,
organization::coaching_relationship_controller::index,
organization::coaching_relationship_controller::read,
overarching_goal_controller::create,
Expand Down Expand Up @@ -112,20 +115,6 @@ pub fn define_routes(app_state: AppState) -> Router {
.fallback_service(static_routes())
}

fn organization_coaching_relationship_routes(app_state: AppState) -> Router {
Router::new()
.route(
"/organizations/:organization_id/coaching_relationships",
get(organization::coaching_relationship_controller::index),
)
.route(
"/organizations/:organization_id/coaching_relationships/:relationship_id",
get(organization::coaching_relationship_controller::read),
)
.route_layer(login_required!(Backend, login_url = "/login"))
.with_state(app_state)
}

fn action_routes(app_state: AppState) -> Router {
Router::new()
.route("/actions", post(action_controller::create))
Expand All @@ -149,6 +138,20 @@ fn agreement_routes(app_state: AppState) -> Router {
.with_state(app_state)
}

pub fn coaching_sessions_routes(app_state: AppState) -> Router {
Router::new()
.route(
"/coaching_sessions",
post(coaching_session_controller::create),
)
.route(
"/coaching_sessions",
get(coaching_session_controller::index),
)
.route_layer(login_required!(Backend, login_url = "/login"))
.with_state(app_state)
}

fn note_routes(app_state: AppState) -> Router {
Router::new()
.route("/notes", post(note_controller::create))
Expand All @@ -159,6 +162,24 @@ fn note_routes(app_state: AppState) -> Router {
.with_state(app_state)
}

fn organization_coaching_relationship_routes(app_state: AppState) -> Router {
Router::new()
.route(
"/organizations/:organization_id/coaching_relationships",
post(coaching_relationship_controller::create),
)
.route(
"/organizations/:organization_id/coaching_relationships",
get(organization::coaching_relationship_controller::index),
)
.route(
"/organizations/:organization_id/coaching_relationships/:relationship_id",
get(organization::coaching_relationship_controller::read),
)
.route_layer(login_required!(Backend, login_url = "/login"))
.with_state(app_state)
}

pub fn organization_routes(app_state: AppState) -> Router {
Router::new()
// The goal will be able to do something like the follow Node.js code does for
Expand Down Expand Up @@ -203,20 +224,6 @@ pub fn overarching_goal_routes(app_state: AppState) -> Router {
.with_state(app_state)
}

pub fn coaching_sessions_routes(app_state: AppState) -> Router {
Router::new()
.route(
"/coaching_sessions",
post(coaching_session_controller::create),
)
.route(
"/coaching_sessions",
get(coaching_session_controller::index),
)
.route_layer(login_required!(Backend, login_url = "/login"))
.with_state(app_state)
}

pub fn user_session_protected_routes() -> Router {
Router::new()
.route("/protected", get(user_session_controller::protected))
Expand Down

0 comments on commit 702cd21

Please sign in to comment.