use crate::{
Context,
routing::{Path, RouteDef},
};
use anyhow::Result;
use async_trait::async_trait;
use serde_json::Value;
#[async_trait]
#[allow(unused)]
pub trait Route {
async fn model(&self, ctx: &impl Context, params: &Path<RouteDef>) -> Result<Value>;
fn name(&self) -> &'static str;
}
#[cfg(test)]
mod tests {
use super::Route;
use crate::{
Context,
routing::{Path, RouteDef},
};
use async_trait::async_trait;
use serde_json::{Value, json};
#[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<Value> {
Ok(json!({
"a": "A",
"b": "B",
}))
}
fn name(&self) -> &'static str {
"my-route"
}
}
}
}