Added basic request handler skeleton
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Martin Slot 2022-10-10 19:55:08 +02:00
parent 3a76059722
commit 34e8b21c19
3 changed files with 40 additions and 1 deletions

View File

@ -45,6 +45,7 @@ pub struct ArgumentParser {}
impl ArgumentParser {
pub fn parse(&self, parameters: &Vec<String>) -> Result<Action, ArgumentParserError> {
let matches = command!()
.subcommand(Command::new("request"))
.subcommand(Command::new("list"))
.subcommand(
Command::new("register")

View File

@ -10,6 +10,7 @@ use crate::register_current::models::CurrentRequest;
use crate::register_current::RegisterCurrentHandler;
use crate::register_origin::models::OriginRequest;
use crate::register_origin::RegisterOriginHandler;
use crate::request::RequestHandler;
use crate::routing::Router;
pub mod configuration;
@ -17,6 +18,7 @@ pub mod console;
pub mod list_overview;
pub mod register_current;
pub mod register_origin;
pub mod request;
mod routing;
mod embedded {
@ -37,6 +39,7 @@ pub struct Application<'a> {
register_origin_handler: RegisterOriginHandler<'a>,
register_current_handler: RegisterCurrentHandler<'a>,
overview_handler: OverviewHandler<'a>,
request_handler: RequestHandler<'a>,
}
impl<'a> Application<'a> {
@ -50,9 +53,12 @@ impl<'a> Application<'a> {
settings,
argument_parser,
arguments,
// TODO: this init should be rethought to be more extensible if possible
register_origin_handler: register_origin::init(settings),
register_current_handler: register_current::init(settings),
overview_handler: list_overview::init(settings, console),
request_handler: request::init(settings, console),
}
}
@ -81,7 +87,9 @@ impl<'a> Application<'a> {
count: 100, //TODO: hardcoded for now, but needs to be supplied through a cli parameter
})
};
let request = || {};
let request = || {
self.request_handler.execute();
};
let action = self.argument_parser.parse(&self.arguments).unwrap();
let router = Router::new(register_origin, register_current, list, request);

View File

@ -0,0 +1,30 @@
use crate::{Print, Settings};
pub fn init<'a>(settings: &'a Settings, console: &'a dyn Print) -> RequestHandler<'a> {
let request_gateway = RequestGateway::new(settings);
RequestHandler {
settings,
request_gateway: request_gateway,
console,
}
}
pub struct RequestHandler<'a> {
pub settings: &'a Settings,
console: &'a dyn Print,
request_gateway: RequestGateway<'a>,
}
pub struct RequestGateway<'a> {
pub settings: &'a Settings,
}
impl<'a> RequestHandler<'a> {
pub fn execute(&self) {}
}
impl<'a> RequestGateway<'a> {
pub fn new(settings: &Settings) -> RequestGateway {
RequestGateway { settings }
}
}