Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add fetch context from context condition #168

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading