Compare commits
2 Commits
a0587512eb
...
8e81b99f63
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e81b99f63 | |||
| ae1084c1c3 |
2539
Cargo.lock
generated
Normal file
2539
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
Cargo.toml
14
Cargo.toml
@ -1,6 +1,18 @@
|
||||
[package]
|
||||
name = "user-server"
|
||||
name = "test_exercise"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
|
||||
|
||||
[dependencies]
|
||||
axum = {version = "0.8.4", features = ["macros"]}
|
||||
tokio = {version = "1.47.1", features = ["full"]}
|
||||
utoipa = "5.4.0"
|
||||
sqlx = {version = "0.6.0", features = ["runtime-tokio-native-tls","postgres"]}
|
||||
config = "0.15.6"
|
||||
utoipa-axum = {version = "0.2.0" }
|
||||
utoipa-scalar = { version = "0.3", features = ["axum"] }
|
||||
tracing = "0.1.41"
|
||||
serde = "1.0.228"
|
||||
tracing-subscriber = "0.3.20"
|
||||
|
||||
3
README.md
Normal file
3
README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# test_exercise
|
||||
|
||||
Небольшой тестовый репозиторий на раст для ликвидации skill issue
|
||||
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
|
||||
}
|
||||
@ -1,3 +1,6 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use test_exercise::router;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
router().await;
|
||||
}
|
||||
|
||||
14
src/models.rs
Normal file
14
src/models.rs
Normal file
@ -0,0 +1,14 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Debug, Clone, ToSchema, Serialize, Deserialize)]
|
||||
struct PatientId {
|
||||
id: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, ToSchema, Serialize, Deserialize)]
|
||||
pub struct Patient {
|
||||
id: PatientId,
|
||||
name: String,
|
||||
diagnosis: String, //todo! enum
|
||||
}
|
||||
9
src/openapi.rs
Normal file
9
src/openapi.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use axum::Router;
|
||||
use utoipa::openapi::OpenApi;
|
||||
use utoipa_scalar::{Scalar, Servable};
|
||||
|
||||
struct ApiDocs;
|
||||
|
||||
pub fn route_docs(router: Router, docs: OpenApi) -> Router {
|
||||
router.merge(Scalar::with_url("/", docs))
|
||||
}
|
||||
8
src/schemas.rs
Normal file
8
src/schemas.rs
Normal file
@ -0,0 +1,8 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Debug, Clone, ToSchema, Serialize, Deserialize)]
|
||||
pub struct Patient {
|
||||
name: String,
|
||||
diagnosis: String, //todo! enum
|
||||
}
|
||||
Reference in New Issue
Block a user