Skip to content

Commit

Permalink
fix: fix api response
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Aug 14, 2023
1 parent da7b0e7 commit 16b4477
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 0 additions & 2 deletions counit-server/src/repository/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ fn parse_payload(
.map(|(key, value)| (key, kind_to_value(value.kind)))
.collect::<HashMap<String, serde_json::Value>>();

println!("converted: {:?}", converted);

CodePayload {
lang: val_str!(converted, "lang"),
repo_name: val_str!(converted, "repo_name"),
Expand Down
22 changes: 15 additions & 7 deletions counit-server/src/server/semantic_api.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
use axum::{Extension, Json};
use axum::Extension;
use axum::body::HttpBody;
use axum::extract::Query;
use axum::http::StatusCode;
use axum::response::IntoResponse;
use serde::{Deserialize, Serialize};

use crate::application::Application;
use crate::repository::payload::CodePayload;
use crate::repository::semantic_query::SemanticQuery;
use crate::server::{Error, json};

pub(crate) async fn query(
Query(args): Query<ApiQuery>,
Extension(app): Extension<Application>,
) -> (StatusCode, Json<()>) {
) -> impl IntoResponse {
let q = SemanticQuery::from_str(args.q, args.repo_ref);
let results = app.semantic

let result = app.semantic
.unwrap()
.search(
&q,
Expand All @@ -22,10 +24,16 @@ pub(crate) async fn query(
0.0,
false,
)
.await.unwrap();
.await;

println!("results: {:?}", results);
(StatusCode::OK, Json(()))
match result {
Ok(vec) => {
Ok(json(QueryResponse { data: vec }))
}
Err(err) => {
Err(Error::from(err))
}
}
}

#[derive(Debug, Deserialize)]
Expand Down

0 comments on commit 16b4477

Please sign in to comment.