1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/// `NgynControllerInit` is a trait that defines the basic structure of a controller initializer in Ngyn.
pub trait NgynControllerInit: Send + Sync {
    /// Creates a new instance of the controller.
    /// This is for internal use only.
    fn new(middlewares: Vec<std::sync::Arc<dyn super::NgynMiddleware>>) -> Self;
}

#[async_trait::async_trait]
/// `NgynController` is a trait that defines the basic structure of a controller in Ngyn.
/// It is designed to be thread-safe.
pub trait NgynController: Send + Sync {
    /// Returns the name of the controller.
    fn name(&self) -> &str;

    /// Returns a vector of routes for the controller.
    fn get_routes(&self) -> Vec<(String, String, String)>;

    /// Returns a `NgynResponse` for the controller.
    /// This is for internal use only.
    async fn handle(
        &self,
        handler: String,
        req: crate::NgynRequest,
        res: crate::NgynResponse,
    ) -> crate::NgynResponse;
}