#![allow(
clippy::all,
clippy::pedantic,
clippy::nursery,
dead_code,
unused_imports,
unused_variables,
reason = "mechanically generated contract text: the OAS is emitted in full (every DTO, param struct and route, whether or not this workspace consumes it yet), so style and dead-code lints do not apply — the hand-written runtime and the implementing adapter carry the lint bar"
)]
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AdminEhrDeleteParams {
pub ehr_id: String,
}
impl AdminEhrDeleteParams {
pub const PARAMS: &'static [crate::rest::routes::Param] = &[crate::rest::routes::Param {
name: "ehr_id",
location: crate::rest::routes::ParamLocation::Path,
required: true,
explode: false,
kind: crate::rest::routes::ParamKind::Uuid,
identifier: Some(crate::rest::routes::IdentifierClass::HierObject),
}];
pub fn from_request(
matched: &crate::rest::routes::RouteMatch,
_query: Option<&str>,
_headers: &http::HeaderMap,
) -> Result<Self, crate::rest::runtime::ApiError> {
let path = crate::rest::decode::PathValues::from_route(matched)?;
Self::from_parts(&path)
}
pub(crate) fn from_parts(
path: &crate::rest::decode::PathValues,
) -> Result<Self, crate::rest::runtime::ApiError> {
Ok(Self {
ehr_id: path.value("ehr_id")?,
})
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AdminEhrDeleteAllParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub ehr_id: Option<String>,
}
impl AdminEhrDeleteAllParams {
pub const PARAMS: &'static [crate::rest::routes::Param] = &[crate::rest::routes::Param {
name: "ehr_id",
location: crate::rest::routes::ParamLocation::Query,
required: false,
explode: true,
kind: crate::rest::routes::ParamKind::Uuid,
identifier: None,
}];
pub fn from_request(
_matched: &crate::rest::routes::RouteMatch,
query: Option<&str>,
_headers: &http::HeaderMap,
) -> Result<Self, crate::rest::runtime::ApiError> {
let query = crate::rest::decode::QueryPairs::parse(query)?;
Self::from_parts(&query)
}
pub(crate) fn from_parts(
query: &crate::rest::decode::QueryPairs,
) -> Result<Self, crate::rest::runtime::ApiError> {
Ok(Self {
ehr_id: query.optional("ehr_id")?,
})
}
}
#[cfg(feature = "rest-server")]
pub mod server {
use super::*;
#[derive(Debug, Clone)]
pub enum AdminEhrDeleteResponse {
Accepted,
NoContent,
}
#[derive(Debug, Clone)]
pub enum AdminEhrDeleteAllResponse {
Accepted,
NoContent,
}
#[async_trait::async_trait]
pub trait AdminApi {
async fn admin_ehr_delete(
&self,
params: AdminEhrDeleteParams,
) -> Result<AdminEhrDeleteResponse, crate::rest::runtime::Refusal> {
Err(crate::rest::runtime::ApiError::NotImplemented.into())
}
async fn admin_ehr_delete_all(
&self,
params: AdminEhrDeleteAllParams,
) -> Result<AdminEhrDeleteAllResponse, crate::rest::runtime::Refusal> {
Err(crate::rest::runtime::ApiError::NotImplemented.into())
}
}
pub fn router<S>(api: std::sync::Arc<S>) -> axum::Router
where
S: AdminApi + Send + Sync + 'static,
{
axum::Router::new()
.route(
"/admin/ehr/{p3}",
axum::routing::on(
axum::routing::MethodFilter::DELETE,
handle_admin_ehr_delete::<S>,
),
)
.route(
"/admin/ehr/all",
axum::routing::on(
axum::routing::MethodFilter::DELETE,
handle_admin_ehr_delete_all::<S>,
),
)
.with_state(api)
}
async fn handle_admin_ehr_delete<S>(
axum::extract::State(api): axum::extract::State<std::sync::Arc<S>>,
path: Result<
axum::extract::RawPathParams,
axum::extract::rejection::RawPathParamsRejection,
>,
) -> axum::response::Response
where
S: AdminApi + Send + Sync + 'static,
{
let served: Result<axum::response::Response, crate::rest::runtime::Refusal> = async {
let path = crate::rest::server::path_captures(path, &[("p3", "ehr_id")])?;
let params = AdminEhrDeleteParams::from_parts(&path)?;
let reply: crate::rest::server::Reply = match api.admin_ehr_delete(params).await? {
AdminEhrDeleteResponse::Accepted => {
crate::rest::server::Reply::new(http::StatusCode::ACCEPTED)
}
AdminEhrDeleteResponse::NoContent => {
crate::rest::server::Reply::new(http::StatusCode::NO_CONTENT)
}
};
Ok(reply.finish())
}
.await;
crate::rest::server::respond(served)
}
async fn handle_admin_ehr_delete_all<S>(
axum::extract::State(api): axum::extract::State<std::sync::Arc<S>>,
axum::extract::RawQuery(query): axum::extract::RawQuery,
) -> axum::response::Response
where
S: AdminApi + Send + Sync + 'static,
{
let served: Result<axum::response::Response, crate::rest::runtime::Refusal> = async {
let query = crate::rest::decode::QueryPairs::parse(query.as_deref())?;
let params = AdminEhrDeleteAllParams::from_parts(&query)?;
let reply: crate::rest::server::Reply = match api.admin_ehr_delete_all(params).await? {
AdminEhrDeleteAllResponse::Accepted => {
crate::rest::server::Reply::new(http::StatusCode::ACCEPTED)
}
AdminEhrDeleteAllResponse::NoContent => {
crate::rest::server::Reply::new(http::StatusCode::NO_CONTENT)
}
};
Ok(reply.finish())
}
.await;
crate::rest::server::respond(served)
}
}
#[cfg(feature = "rest-client")]
pub mod client {
use super::*;
#[derive(Debug, Clone)]
pub enum AdminEhrDeleteOutcome {
Accepted,
NoContent,
NotFound {
body: crate::rest::client::ErrorBody,
},
}
#[derive(Debug, Clone)]
pub enum AdminEhrDeleteAllOutcome {
Accepted,
NoContent,
NotFound {
body: crate::rest::client::ErrorBody,
},
MethodNotAllowed {
body: crate::rest::client::ErrorBody,
},
}
#[derive(Debug, Clone)]
pub struct AdminClient<'c, T> {
client: &'c crate::rest::client::Client<T>,
options: crate::rest::client::CallOptions,
}
impl<'c, T: crate::rest::client::Transport> AdminClient<'c, T> {
#[must_use]
pub fn new(client: &'c crate::rest::client::Client<T>) -> Self {
Self {
client,
options: crate::rest::client::CallOptions::default(),
}
}
#[must_use]
pub fn with_options(mut self, options: crate::rest::client::CallOptions) -> Self {
self.options = options;
self
}
pub async fn admin_ehr_delete(
&self,
params: &AdminEhrDeleteParams,
) -> Result<AdminEhrDeleteOutcome, crate::rest::client::ClientError> {
let mut request = crate::rest::client::Request::new(
http::Method::DELETE,
format!(
"/admin/ehr/{}",
crate::rest::client::path_segment(¶ms.ehr_id)
),
);
request.apply_options(&self.options);
let answer = self.client.execute(request).await?;
match answer.status() {
http::StatusCode::ACCEPTED => Ok(AdminEhrDeleteOutcome::Accepted),
http::StatusCode::NO_CONTENT => Ok(AdminEhrDeleteOutcome::NoContent),
http::StatusCode::NOT_FOUND => Ok(AdminEhrDeleteOutcome::NotFound {
body: answer.error_body(),
}),
_ => Err(answer.into_undocumented()),
}
}
pub async fn admin_ehr_delete_all(
&self,
params: &AdminEhrDeleteAllParams,
) -> Result<AdminEhrDeleteAllOutcome, crate::rest::client::ClientError> {
let mut request = crate::rest::client::Request::new(
http::Method::DELETE,
String::from("/admin/ehr/all"),
);
if let Some(value) = params.ehr_id.as_ref() {
request.query("ehr_id", value);
}
request.apply_options(&self.options);
let answer = self.client.execute(request).await?;
match answer.status() {
http::StatusCode::ACCEPTED => Ok(AdminEhrDeleteAllOutcome::Accepted),
http::StatusCode::NO_CONTENT => Ok(AdminEhrDeleteAllOutcome::NoContent),
http::StatusCode::NOT_FOUND => Ok(AdminEhrDeleteAllOutcome::NotFound {
body: answer.error_body(),
}),
http::StatusCode::METHOD_NOT_ALLOWED => {
Ok(AdminEhrDeleteAllOutcome::MethodNotAllowed {
body: answer.error_body(),
})
}
_ => Err(answer.into_undocumented()),
}
}
}
}
pub const ROUTES: &[(&str, &str, &str)] = &[
("DELETE", "/admin/ehr/{ehr_id}", "admin_ehr_delete"),
("DELETE", "/admin/ehr/all{?ehr_id*}", "admin_ehr_delete_all"),
];
pub const ROUTE_PARAMS: &[&[crate::rest::routes::Param]] = &[
AdminEhrDeleteParams::PARAMS,
AdminEhrDeleteAllParams::PARAMS,
];
const _: () = assert!(
ROUTE_PARAMS.len() == ROUTES.len(),
"ROUTE_PARAMS carries one row per ROUTES entry"
);
pub const ROUTE_REQUEST_MEDIA: &[&[&str]] = &[&[], &[]];
const _: () = assert!(
ROUTE_REQUEST_MEDIA.len() == ROUTES.len(),
"ROUTE_REQUEST_MEDIA carries one row per ROUTES entry"
);