Skip to content

Commit

Permalink
feat: Add fetch context from context condition (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushjain17 committed Jul 17, 2024
1 parent ebd2f57 commit 6dd17f8
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion crates/context_aware_config/src/api/context/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use actix_web::web::Data;
use service_utils::service::types::{AppHeader, AppState, CustomHeaders};

use actix_web::{
delete, get, put,
delete, get, post, put,
web::{Json, Path, Query},
HttpResponse, Responder, Scope,
};
Expand Down Expand Up @@ -61,6 +61,7 @@ pub fn endpoints() -> Scope {
.service(delete_context)
.service(bulk_operations)
.service(list_contexts)
.service(get_context_from_condition)
.service(get_context)
.service(priority_recompute)
}
Expand Down Expand Up @@ -496,6 +497,23 @@ async fn move_handler(
})
}

#[post("/get")]
async fn get_context_from_condition(
db_conn: DbConnection,
req: Json<Map<String, Value>>,
) -> superposition::Result<impl Responder> {
use crate::db::schema::contexts::dsl::*;

let context_id = hash(&Value::Object(req.into_inner()));
let DbConnection(mut conn) = db_conn;

let ctx: Context = contexts
.filter(id.eq(context_id))
.get_result::<Context>(&mut conn)?;

Ok(Json(ctx))
}

#[get("/{ctx_id}")]
async fn get_context(
path: Path<String>,
Expand Down

0 comments on commit 6dd17f8

Please sign in to comment.