use crate::{
Context,
routing::{Path, RouteDef},
};
use async_trait::async_trait;
#[async_trait]
#[allow(unused)]
pub trait Route {
async fn model(&self, ctx: &impl Context, params: &Path<RouteDef>) -> anyhow::Result<bson::Document>;
fn name(&self) -> &'static str;
}
#[cfg(test)]
mod tests {
use super::Route;
use crate::{
Context,
routing::{Path, RouteDef},
};
use async_trait::async_trait;
use bson::doc;
#[test]
fn can_implement_route() {
struct MyRoute {}
#[async_trait]
impl Route for MyRoute {
async fn model(&self, _ctx: &impl Context, _params: &Path<RouteDef>) -> anyhow::Result<bson::Document> {
Ok(doc! {
"a": "A",
"b": "B",
})
}
fn name(&self) -> &'static str {
"my-route"
}
}
}
}