sneedstr/src/usernames/routes.rs

66 lines
2.1 KiB
Rust

use crate::noose::user::User;
// use super::accounts::create_account;
use super::dto::{Account, UserQuery};
use super::filter::{validate_body_filter, validate_query_filter};
use super::handler::{get_account, get_user};
use crate::utils::filter::with_context;
use crate::utils::structs::Context;
use warp::{Filter, Rejection, Reply};
pub fn routes(context: Context) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
let cors = warp::cors().allow_any_origin();
let index = warp::path::end().map(|| warp::reply::html("<h1>SNEED!</h1>"));
index
.or(nip05_get(context.clone()))
// .or(account_create(context.clone()))
.with(&cors)
}
fn well_known() -> impl Filter<Extract = (), Error = Rejection> + Clone {
warp::get().and(warp::path(".well-known"))
}
fn nostr_well_known() -> impl Filter<Extract = (), Error = Rejection> + Clone {
well_known().and(warp::path("nostr.json"))
}
pub fn nip05_get(context: Context) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
nostr_well_known()
.and(validate_query_filter::<UserQuery>())
.and(with_context(context.clone()))
.and_then(get_user)
}
// pub fn account_create(
// context: Context,
// ) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
// warp::path("account")
// .and(warp::post())
// .and(validate_body_filter::<User>())
// .and(with_context(context))
// .and_then(create_account)
// }
// pub fn account_get(
// context: Context,
// ) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
// warp::path("account")
// .and(warp::get())
// .and(validate_body_filter::<Account>())
// .and(with_context(context))
// .and_then(get_account)
// }
// pub fn account_update(
// context: Context,
// ) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
// warp::path("account")
// .and(warp::put())
// .and(warp::body::json::<Account>())
// .then(validate_body)
// .and(with_context(context))
// .and_then(update_account)
// }