implement empty endpoints with openapi
This commit is contained in:
63
src/lib.rs
Normal file
63
src/lib.rs
Normal file
@ -0,0 +1,63 @@
|
||||
use axum::{debug_handler, extract::Json, response::IntoResponse};
|
||||
use schemas::Patient;
|
||||
use tracing::info;
|
||||
use utoipa::{OpenApi, openapi::Response};
|
||||
use utoipa_axum::{router::OpenApiRouter, routes};
|
||||
|
||||
use crate::openapi::route_docs;
|
||||
|
||||
pub mod models;
|
||||
pub mod openapi;
|
||||
pub mod schemas;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct AppState {}
|
||||
|
||||
#[derive(OpenApi)]
|
||||
struct Api;
|
||||
|
||||
pub async fn router() {
|
||||
let addr = "0.0.0.0:3000";
|
||||
tracing_subscriber::fmt::init();
|
||||
let (router, docs) = OpenApiRouter::with_openapi(Api::openapi())
|
||||
.routes(routes!(get_openapi))
|
||||
.routes(routes!(post_patient))
|
||||
.routes(routes!(get_patients))
|
||||
.routes(routes!(update_patient_by_id))
|
||||
.routes(routes!(delete_patient_by_id))
|
||||
.split_for_parts();
|
||||
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
|
||||
info!("Listening in {:?}", listener.local_addr());
|
||||
let router = route_docs(router, docs);
|
||||
axum::serve(listener, router).await.unwrap();
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
#[utoipa::path(get, path = "/api/patients", description="Get all patients", responses((status = OK, body = Patient)))]
|
||||
async fn get_patients() -> impl IntoResponse {
|
||||
axum::http::StatusCode::NOT_IMPLEMENTED
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
#[utoipa::path(get, path = "/api/openapi.json", description="Get openapi.json file", responses((status = OK)))]
|
||||
async fn get_openapi()-> impl IntoResponse {
|
||||
axum::http::StatusCode::NOT_IMPLEMENTED
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
#[utoipa::path(post, path = "/api/post_patient",description="Create a new patient", responses((status = OK)))]
|
||||
async fn post_patient(Json(patient): Json<Patient>)-> impl IntoResponse {
|
||||
axum::http::StatusCode::NOT_IMPLEMENTED
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
#[utoipa::path(post, path = "/api/update_patiend_by_id",description="Update patient by ID", responses((status = OK)))]
|
||||
async fn update_patient_by_id(Json(patient): Json<Patient>)-> impl IntoResponse {
|
||||
axum::http::StatusCode::NOT_IMPLEMENTED
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
#[utoipa::path(delete, path = "/api/delete_patient_by_id", description="Delete patient by ID", responses((status = OK)))]
|
||||
async fn delete_patient_by_id(Json(patinent): Json<Patient>)-> impl IntoResponse {
|
||||
axum::http::StatusCode::NOT_IMPLEMENTED
|
||||
}
|
||||
Reference in New Issue
Block a user