Skip to content

Instantly share code, notes, and snippets.

@Enigo
Created December 21, 2023 06:02
Show Gist options
  • Save Enigo/cef9912ec5aef00370c1c652e47d474f to your computer and use it in GitHub Desktop.
Save Enigo/cef9912ec5aef00370c1c652e47d474f to your computer and use it in GitHub Desktop.
use actix_web::{get, web, HttpResponse, Responder};
use serde::Deserialize;
use sqlx::{Pool, Postgres};
use crate::db::assets_handler;
#[derive(Deserialize)]
pub struct SearchParams {
search: String,
}
#[get("/api/search")]
pub async fn get_search_results(
pool: web::Data<Pool<Postgres>>,
params: web::Query<SearchParams>,
) -> actix_web::Result<impl Responder> {
return match assets_handler::get_search_results(&pool, &params.search).await {
None => Ok(HttpResponse::NotFound().finish()),
Some(asset) => Ok(HttpResponse::Ok().json(asset)),
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment