parent
c51f87e8cb
commit
eeea6a13b1
@ -0,0 +1,55 @@
|
||||
use super::*;
|
||||
use warp::Filter;
|
||||
use std::convert::Infallible;
|
||||
|
||||
use hard_format::{
|
||||
FormattedString,
|
||||
formats,
|
||||
};
|
||||
|
||||
pub fn setup(state: State) -> impl warp::Filter //TODO: What output should this have?
|
||||
{
|
||||
let root = warp::path("yuurei"); //TODO: configurable
|
||||
let state = warp::any().map(move || state.clone());
|
||||
|
||||
let post_api = warp::post()
|
||||
.and(warp::path("create"))
|
||||
.and(state.clone())
|
||||
//TODO: Filter to extract `User`. How? Dunno. Maybe cookies + IP or in the body itself.
|
||||
.and(warp::body::content_length_limit(defaults::MAX_CONTENT_LENGTH)) //TODO: configurable
|
||||
.and(warp::body::json())
|
||||
.and_then(|state: State, body: post::Post| { //TODO: post read is not this type, but another more restricted one
|
||||
async move {
|
||||
Ok::<_, Infallible>("test")
|
||||
}
|
||||
});
|
||||
let get_api = warp::get()
|
||||
.and(warp::path("get"))
|
||||
.and({
|
||||
let get_post_by_id = warp::any()
|
||||
.and(warp::path("post"))
|
||||
.and(state.clone())
|
||||
.and(warp::path::param().map(|opt: formats::HexFormattedString| opt)) //TODO: Convert to `PostID`.
|
||||
.and_then(|state: State, id: formats::HexFormattedString| {
|
||||
|
||||
async move {
|
||||
Ok::<_, Infallible>("test")
|
||||
}
|
||||
});
|
||||
let get_posts_by_user_id = warp::any()
|
||||
.and(warp::path("user"))
|
||||
.and(state.clone())
|
||||
.and(warp::path::param().map(|opt: formats::HexFormattedString| opt)) //TODO: Convert to `UserID`.
|
||||
.and_then(|state: State, id: formats::HexFormattedString| {
|
||||
|
||||
async move {
|
||||
Ok::<_, Infallible>("test")
|
||||
}
|
||||
});
|
||||
|
||||
get_post_by_id
|
||||
.or(get_posts_by_user_id)
|
||||
});
|
||||
root.and(post_api.
|
||||
or(get_api))
|
||||
}
|
Loading…
Reference in new issue