use warp::Filter; use super::handlers; /// The COMMENTs filters combined. pub fn comments() -> impl Filter + Clone { index_page() .or( show_few_comments() ) .or( show_comments_for_session_id() ) .or( show_comments_for() ) .or( add_comment() ) .or( update_comment_status() ) .or( update_comment_msg() ) .or( trash_comment() ) .or( get_static_file() ) .or( add_reply() ) .or( get_image() ) .or( get_icon() ) .or( update_reply_msg() ) .or( trash_reply() ) .or( upvote() ) .or( downvote() ) } /// GET / -> index page (also referred as Home page) pub fn index_page() -> impl Filter + Clone { warp::get() .and( warp::path::end() ) .and_then( handlers::index ) } /// GET /comments pub fn show_few_comments() -> impl Filter + Clone { warp::path!("comments") .and(warp::get()) .and_then(handlers::show_few_comments) } /// GET /comments/session_id/:id pub fn show_comments_for_session_id() -> impl Filter + Clone { warp::path!("comments"/ "session_id" / String) .and(warp::get()) .and_then(handlers::show_comments_for_session_id) } /// GET /comments/count pub fn show_comments_for() -> impl Filter + Clone { warp::path!("comments" / usize) .and(warp::get()) .and_then(handlers::show_comments_for) } /// POST /comments -> to add a comment pub fn add_comment() -> impl Filter + Clone { warp::path!("comments") .and(warp::post()) .and(warp::body::form()) .and_then(handlers::add_comment) } /// POST /comment/comment_id -> to enable or disable a comment pub fn update_comment_status() -> impl Filter + Clone { warp::path!("comment" / String ) .and(warp::post()) .and(warp::body::form()) .and_then(handlers::update_comment_status) } /// POST /comment_message -> to update message/text in a comment pub fn update_comment_msg() -> impl Filter + Clone { warp::path!("comment_message") .and(warp::post()) .and(warp::body::form()) .and_then(handlers::update_comment_msg) } /// DELETE /comments/unique_id/user_id -> to trash a comment, i.e. mark a comment as deleted pub fn trash_comment() -> impl Filter + Clone { warp::path!("comments" / String / String) .and(warp::delete()) .and_then(handlers::trash_comment) } /// POST /reply_message -> to update message/text in a reply pub fn update_reply_msg() -> impl Filter + Clone { warp::path!("reply_message") .and(warp::post()) .and(warp::body::form()) .and_then(handlers::update_reply_msg) } /// POST /replies -> to add a reply pub fn add_reply() -> impl Filter + Clone { warp::path!("replies") .and(warp::post()) .and(warp::body::form()) .and_then(handlers::add_reply) } /// DELETE /replies/unique_id -> to trash a reply, i.e. mark a reply as deleted pub fn trash_reply() -> impl Filter + Clone { warp::path!("replies" / String ) .and(warp::delete()) .and_then(handlers::trash_reply) } /// GET /static/comment.js pub fn get_static_file() -> impl Filter + Clone { warp::path!("static" / String) .and(warp::get()) .and_then(handlers::get_static_file) } /// GET /images/name pub fn get_image() -> impl Filter + Clone { warp::path!("images" / String) .and(warp::get()) .and_then(handlers::get_image) } /// GET /images/icons/name pub fn get_icon() -> impl Filter + Clone { warp::path!("images" / String / String) .and(warp::get()) .and_then(handlers::get_image_type) } /// POST /upvotes -> add/remove an upvote (or simple toggle an upvote) pub fn upvote() -> impl Filter + Clone { warp::path!("upvotes") .and(warp::post()) .and(warp::body::form()) .and_then(handlers::upvote) } /// POST /downvotes -> add/remove an downvote (or simple toggle an downvote) pub fn downvote() -> impl Filter + Clone { warp::path!("downvotes") .and(warp::post()) .and(warp::body::form()) .and_then(handlers::downvote) }