Skip to content

Commit

Permalink
add /overarching_goals/:id/status
Browse files Browse the repository at this point in the history
  • Loading branch information
calebbourg committed Sep 25, 2024
1 parent 1d384ff commit 7ec59c4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
39 changes: 39 additions & 0 deletions web/src/controller/overarching_goal_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,45 @@ pub async fn update(
)))
}

#[utoipa::path(
put,
path = "/overarching_goals/{id}/status",
params(
ApiVersion,
("id" = Id, Path, description = "Id of overarching goal to update"),
("value" = Option<String>, Query, description = "Status value to update"),
),
request_body = entity::actions::Model,
responses(
(status = 200, description = "Successfully Updated Overarching Goal", body = [entity::overarching_goals::Model]),
(status = 401, description = "Unauthorized"),
(status = 405, description = "Method not allowed")
),
security(
("cookie_auth" = [])
)
)]
pub async fn update_status(
CompareApiVersion(_v): CompareApiVersion,
AuthenticatedUser(_user): AuthenticatedUser,
Query(status): Query<String>,
Path(id): Path<Id>,
State(app_state): State<AppState>,
) -> Result<impl IntoResponse, Error> {
debug!("PUT Update Overarching Goal Status with id: {}", id);

let overarching_goal =
OverarchingGoalApi::update_status(app_state.db_conn_ref(), id, status.as_str().into())
.await?;

debug!("Updated Overarching Goal: {:?}", overarching_goal);

Ok(Json(ApiResponse::new(
StatusCode::OK.into(),
overarching_goal,
)))
}

#[utoipa::path(
get,
path = "/overarching_goals",
Expand Down
4 changes: 4 additions & 0 deletions web/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ pub fn overarching_goal_routes(app_state: AppState) -> Router {
"/overarching_goals/:id",
get(overarching_goal_controller::read),
)
.route(
"/overarching_goals/:id/status",
put(overarching_goal_controller::update_status),
)
.route_layer(login_required!(Backend, login_url = "/login"))
.with_state(app_state)
}
Expand Down

0 comments on commit 7ec59c4

Please sign in to comment.