-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
62 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use diesel::prelude::*; | ||
|
||
use crate::{ | ||
db::establish_connection, | ||
feed::article::ArticleQueryResult, | ||
models::{self, Article}, | ||
schema, | ||
}; | ||
|
||
pub struct Common {} | ||
pub struct GlobalSearchQuery { | ||
pub query: String, | ||
pub limit: Option<i64>, | ||
pub cursor: Option<i64>, | ||
} | ||
|
||
impl Common { | ||
pub fn global_search(search: GlobalSearchQuery) -> Vec<models::Article> { | ||
let mut connection = establish_connection(); | ||
let query = search.query; | ||
let limit = search.limit.unwrap_or(12); | ||
let cursor = search.cursor.unwrap_or(1); | ||
|
||
let result = schema::articles::dsl::articles | ||
.filter(schema::articles::dsl::title.like(format!("%{}%", query))) | ||
.filter(schema::articles::dsl::content.like(format!("%{}%",query))) | ||
.limit(limit) | ||
.offset((cursor - 1) * limit) | ||
.load::<models::Article>(&mut connection) | ||
.unwrap(); | ||
|
||
println!("result {:?}", result); | ||
result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod common; | ||
pub mod tray; | ||
pub mod scraper; | ||
pub mod menu; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,39 @@ | ||
use actix_web::{get, post, web, Responder, Result}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::core; | ||
use crate::core::common; | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct SearchRequest { | ||
pub query: String, | ||
pub limit: Option<i64>, | ||
pub cursor: Option<i64>, | ||
} | ||
|
||
#[get("/api/search")] | ||
pub async fn handle_search() -> Result<impl Responder> {} | ||
pub async fn handle_search(search: web::Query<SearchRequest>) -> Result<impl Responder> { | ||
let result = common::Common::global_search(common::GlobalSearchQuery { | ||
query: search.query.to_string(), | ||
limit: search.limit, | ||
cursor: search.cursor | ||
}); | ||
|
||
Ok(web::Json(result)) | ||
} | ||
|
||
#[get("/api/favorite")] | ||
pub async fn handle_get_favorite() -> Result<impl Responder> {} | ||
pub async fn handle_get_favorite() -> Result<impl Responder> { | ||
Ok("") | ||
} | ||
|
||
#[post("/api/favorite")] | ||
pub async fn handle_update_favorite() -> Result<impl Responder> {} | ||
pub async fn handle_update_favorite() -> Result<impl Responder> { | ||
Ok("") | ||
} | ||
|
||
pub fn config(cfg: &mut web::ServiceConfig) { | ||
cfg | ||
.service(handle_search) | ||
.service(handle_favorite) | ||
.service(handle_get_favorite) | ||
.service(handle_update_favorite); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod common; | ||
pub mod article; | ||
pub mod feed; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters