Added query settings to the generaliued templating mechanism

This commit is contained in:
Slatian
2023-10-29 18:10:57 +01:00
parent de179ea7fa
commit 51aa05fe13
7 changed files with 86 additions and 41 deletions

View File

@ -1,9 +1,14 @@
use axum::http::status::StatusCode;
use axum::Json;
use axum::response::IntoResponse;
use axum::response::Response;
use crate::DigResult;
use crate::IpResult;
use crate::config::DnsResolverConfig;
use crate::settings::QuerySettings;
use crate::settings::ResponseFormat;
use crate::mycelium::MycView;
@ -21,7 +26,7 @@ pub enum View {
NotFound,
}
impl MycView for View {
impl MycView<QuerySettings, ResponseFormat> for View {
fn get_template_name(&self) -> String {
match self {
View::Asn{..} => "asn",
@ -35,11 +40,29 @@ impl MycView for View {
}.to_string()
}
fn get_status_code(&self) -> StatusCode {
fn get_status_code(&self, _: &QuerySettings) -> StatusCode {
match self {
Self::NotFound => StatusCode::NOT_FOUND,
_ => StatusCode::OK,
}
}
fn get_api_response(self, settings: &QuerySettings) -> Response {
match self {
Self::Dig{result, ..} => {
Json(result).into_response()
},
Self::Index{result, ..} | Self::Ip{result, ..} => {
Json(result).into_response()
},
Self::DnsResolverList => {
Json(settings.available_dns_resolvers.clone()).into_response()
},
Self::DnsResolver{ config } => {
Json(config).into_response()
}
_ => Json(self).into_response(),
}
}
}