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
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
6 changes: 4 additions & 2 deletions src/handlers/http/modal/server.rs
Original file line number Diff line number Diff line change
@@ -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 {
27 changes: 26 additions & 1 deletion src/handlers/http/prism_home.rs
Original file line number Diff line number Diff line change
@@ -16,13 +16,17 @@
*
*/

use std::collections::HashMap;

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
///
///
@@ -37,3 +41,24 @@ 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_map = web::Query::<HashMap<String, String>>::from_query(req.query_string())
.map_err(|_| PrismHomeError::InvalidQueryParameter(HOME_SEARCH_QUERY_PARAM.to_string()))?;

if query_map.is_empty() {
return Ok(web::Json(serde_json::json!({})));
}

let query_value = query_map
.get(HOME_SEARCH_QUERY_PARAM)
.ok_or_else(|| PrismHomeError::InvalidQueryParameter(HOME_SEARCH_QUERY_PARAM.to_string()))?
.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