use axum::http::StatusCode;
use axum::response::IntoResponse;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum HttpMethod {
Get,
Post,
Put,
Patch,
Delete,
}
impl std::fmt::Display for HttpMethod {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Get => write!(f, "GET"),
Self::Post => write!(f, "POST"),
Self::Put => write!(f, "PUT"),
Self::Patch => write!(f, "PATCH"),
Self::Delete => write!(f, "DELETE"),
}
}
}
#[derive(Debug, Clone)]
pub enum EndpointSecurity {
None,
Jwt,
}
#[derive(Debug, Clone)]
pub enum EndpointAuthorization {
Public,
Authenticated,
Scopes(Vec<String>),
Role(String),
}
#[derive(Debug, Clone)]
pub struct RateLimitConfig {
pub max_requests: u32,
pub window: std::time::Duration,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ErrorResponse {
pub error: ErrorBody,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ErrorBody {
pub code: String,
pub message: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub details: Option<serde_json::Value>,
pub request_id: String,
pub retryable: bool,
}
#[derive(Debug)]
pub struct Created<T>(pub T);
impl<T: Serialize> IntoResponse for Created<T> {
fn into_response(self) -> axum::response::Response {
(StatusCode::CREATED, axum::Json(self.0)).into_response()
}
}
#[derive(Debug)]
pub struct NoContent;
impl IntoResponse for NoContent {
fn into_response(self) -> axum::response::Response {
StatusCode::NO_CONTENT.into_response()
}
}
pub type AcubeResult<T, E> = Result<T, E>;
pub enum Never {}
impl std::fmt::Debug for Never {
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {}
}
}
impl IntoResponse for Never {
fn into_response(self) -> axum::response::Response {
match self {}
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct HealthStatus {
pub status: String,
pub version: String,
}
impl HealthStatus {
pub fn ok(version: &str) -> Self {
Self {
status: "ok".to_string(),
version: version.to_string(),
}
}
}