1use crate::{controller::Controller, request::HttpRequest, response::HttpResponse, HttpHander};
2
3pub struct Route{
4 controller: Option<Controller>,
5}
6
7impl Route{
8 pub fn new()->Self{
9 Self{
10 controller: Some(Controller::new()),
11 }
12 }
13 pub fn get_controller(mut self) -> Controller {
14 self.controller.take().unwrap()
15 }
16}
17impl HttpHander for Route{
18 fn post<T>(&mut self, url: &str, controller: T)
19 where
20 T: Fn(HttpRequest, HttpResponse) + Sync + Send + 'static,
21 {
22 self.controller
23 .as_mut()
24 .unwrap()
25 .add_handler("POST", url, Box::new(controller));
26 }
27 fn get<T>(&mut self, url: &str, controller: T)
28 where
29 T: Fn(HttpRequest, HttpResponse) + Sync + Send + 'static,
30 {
31 self.controller
32 .as_mut()
33 .unwrap()
34 .add_handler("GET", url, Box::new(controller));
35 }
36 fn router(&mut self, url: &str, route:Route) {
37 todo!()
38 }
39}