Skip to content

revamp home api #1307

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

Merged
merged 5 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 4 additions & 2 deletions src/handlers/http/modal/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ impl ParseableServer for Server {
}

impl Server {
pub fn get_prism_home() -> Resource {
web::resource("/home").route(web::get().to(http::prism_home::home_api))
pub fn get_prism_home() -> Scope {
web::scope("/home")
.service(web::resource("").route(web::get().to(http::prism_home::home_api)))
.service(web::resource("/search").route(web::get().to(http::prism_home::home_search)))
}

pub fn get_prism_logstream() -> Scope {
Expand Down
27 changes: 26 additions & 1 deletion src/handlers/http/prism_home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
use actix_web::{web, HttpRequest, Responder};

use crate::{
prism::home::{generate_home_response, PrismHomeError},
prism::home::{generate_home_response, generate_home_search_response, PrismHomeError},
utils::actix::extract_session_key_from_req,
};

const HOME_SEARCH_QUERY_PARAM: &str = "key";

/// Fetches the data to populate Prism's home
///
///
Expand All @@ -37,3 +39,26 @@ pub async fn home_api(req: HttpRequest) -> Result<impl Responder, PrismHomeError

Ok(web::Json(res))
}

pub async fn home_search(req: HttpRequest) -> Result<impl Responder, PrismHomeError> {
let key = extract_session_key_from_req(&req)
.map_err(|err| PrismHomeError::Anyhow(anyhow::Error::msg(err.to_string())))?;
let query_string = req.query_string();
if query_string.is_empty() {
return Ok(web::Json(serde_json::json!({})));
}
// Validate query string format
let query_parts: Vec<&str> = query_string.split('=').collect();
if query_parts.len() != 2 || query_parts[0] != HOME_SEARCH_QUERY_PARAM {
return Err(PrismHomeError::InvalidQueryParameter(
HOME_SEARCH_QUERY_PARAM.to_string(),
));
}

let query_value = query_parts[1].to_lowercase();
let res = generate_home_search_response(&key, &query_value).await?;
let json_res = serde_json::to_value(res)
.map_err(|err| PrismHomeError::Anyhow(anyhow::Error::msg(err.to_string())))?;

Ok(web::Json(json_res))
}
Loading
Loading