Skip to content

Commit

Permalink
feat: Add fetch context from context condition
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushjain17 committed Jul 15, 2024
1 parent ff1cde6 commit ec0fe1a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 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 @@ -496,6 +496,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 ec0fe1a

Please sign in to comment.