diff --git a/.env b/.env new file mode 100644 index 0000000..b22a99c --- /dev/null +++ b/.env @@ -0,0 +1 @@ +DATABASE_URL=sqlite://mydb.db diff --git a/Cargo.lock b/Cargo.lock index b3a1a76..c1d13c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -163,12 +163,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "base64" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" - [[package]] name = "base64" version = "0.21.7" @@ -199,12 +193,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bumpalo" -version = "3.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" - [[package]] name = "byteorder" version = "1.5.0" @@ -361,27 +349,6 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", "crypto-common", - "subtle", -] - -[[package]] -name = "dirs" -version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" -dependencies = [ - "dirs-sys", -] - -[[package]] -name = "dirs-sys" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" -dependencies = [ - "libc", - "redox_users", - "winapi", ] [[package]] @@ -470,6 +437,18 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0399f9d26e5191ce32c498bebd31e7a3ceabc2745f0ac54af3f335126c3f24b3" +[[package]] +name = "flume" +version = "0.10.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" +dependencies = [ + "futures-core", + "futures-sink", + "pin-project", + "spin", +] + [[package]] name = "fnv" version = "1.0.7" @@ -522,6 +501,17 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + [[package]] name = "futures-intrusive" version = "0.4.2" @@ -556,6 +546,7 @@ dependencies = [ "futures-task", "pin-project-lite", "pin-utils", + "slab", ] [[package]] @@ -656,21 +647,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] -name = "hkdf" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +name = "hospital_server" +version = "0.1.0" dependencies = [ - "hmac", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", + "axum", + "config", + "dotenvy", + "serde", + "sqlx", + "tokio", + "tracing", + "tracing-subscriber", + "utoipa", + "utoipa-axum", + "utoipa-scalar", ] [[package]] @@ -911,16 +901,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" -[[package]] -name = "js-sys" -version = "0.3.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305" -dependencies = [ - "once_cell", - "wasm-bindgen", -] - [[package]] name = "json5" version = "0.4.1" @@ -945,14 +925,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" [[package]] -name = "libredox" -version = "0.1.10" +name = "libsqlite3-sys" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb" +checksum = "898745e570c7d0453cc1fbc4a701eb6c662ed54e8fec8b7d14be137ebeeb9d14" dependencies = [ - "bitflags 2.9.4", - "libc", - "redox_syscall 0.5.18", + "cc", + "pkg-config", + "vcpkg", ] [[package]] @@ -988,16 +968,6 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" -[[package]] -name = "md-5" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" -dependencies = [ - "cfg-if", - "digest", -] - [[package]] name = "memchr" version = "2.7.6" @@ -1259,6 +1229,26 @@ dependencies = [ "sha2", ] +[[package]] +name = "pin-project" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + [[package]] name = "pin-project-lite" version = "0.2.16" @@ -1286,15 +1276,6 @@ dependencies = [ "zerovec", ] -[[package]] -name = "ppv-lite86" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" -dependencies = [ - "zerocopy", -] - [[package]] name = "proc-macro2" version = "1.0.101" @@ -1319,36 +1300,6 @@ version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom 0.2.16", -] - [[package]] name = "redox_syscall" version = "0.2.16" @@ -1367,24 +1318,13 @@ dependencies = [ "bitflags 2.9.4", ] -[[package]] -name = "redox_users" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" -dependencies = [ - "getrandom 0.2.16", - "libredox", - "thiserror", -] - [[package]] name = "ron" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" dependencies = [ - "base64 0.21.7", + "base64", "bitflags 2.9.4", "serde", "serde_derive", @@ -1419,12 +1359,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "rustversion" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" - [[package]] name = "ryu" version = "1.0.20" @@ -1556,17 +1490,6 @@ dependencies = [ "serde", ] -[[package]] -name = "sha1" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - [[package]] name = "sha2" version = "0.10.9" @@ -1624,6 +1547,15 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + [[package]] name = "sqlformat" version = "0.2.6" @@ -1652,37 +1584,31 @@ checksum = "fa8241483a83a3f33aa5fff7e7d9def398ff9990b2752b6c6112b83c6d246029" dependencies = [ "ahash 0.7.8", "atoi", - "base64 0.13.1", "bitflags 1.3.2", "byteorder", "bytes", "crc", "crossbeam-queue", - "dirs", "dotenvy", "either", "event-listener", + "flume", "futures-channel", "futures-core", + "futures-executor", "futures-intrusive", "futures-util", "hashlink 0.8.4", "hex", - "hkdf", - "hmac", "indexmap 1.9.3", "itoa", "libc", + "libsqlite3-sys", "log", - "md-5", "memchr", "once_cell", "paste", "percent-encoding", - "rand", - "serde", - "serde_json", - "sha1", "sha2", "smallvec", "sqlformat", @@ -1691,7 +1617,6 @@ dependencies = [ "thiserror", "tokio-stream", "url", - "whoami", ] [[package]] @@ -1742,12 +1667,6 @@ dependencies = [ "unicode-properties", ] -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - [[package]] name = "syn" version = "1.0.109" @@ -1800,22 +1719,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "test_exercise" -version = "0.1.0" -dependencies = [ - "axum", - "config", - "serde", - "sqlx", - "tokio", - "tracing", - "tracing-subscriber", - "utoipa", - "utoipa-axum", - "utoipa-scalar", -] - [[package]] name = "thiserror" version = "1.0.69" @@ -2212,92 +2115,6 @@ dependencies = [ "wit-bindgen", ] -[[package]] -name = "wasite" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" - -[[package]] -name = "wasm-bindgen" -version = "0.2.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d" -dependencies = [ - "cfg-if", - "once_cell", - "rustversion", - "wasm-bindgen-macro", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19" -dependencies = [ - "bumpalo", - "log", - "proc-macro2", - "quote", - "syn 2.0.106", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.106", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "web-sys" -version = "0.3.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9367c417a924a74cae129e6a2ae3b47fabb1f8995595ab474029da749a8be120" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "whoami" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d4a4db5077702ca3015d3d02d74974948aba2ad9e12ab7df718ee64ccd7e97d" -dependencies = [ - "libredox", - "wasite", - "web-sys", -] - [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index df9da5a..c2398aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "test_exercise" +name = "hospital_server" version = "0.1.0" edition = "2024" @@ -9,10 +9,11 @@ edition = "2024" 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"]} +sqlx = {version = "0.6.0", features = ["runtime-tokio-native-tls","sqlite"]} 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" +dotenvy = "0.15.7" diff --git a/migrations/20251114144629_db.down.sql b/migrations/20251114144629_db.down.sql new file mode 100644 index 0000000..a5ec4a2 --- /dev/null +++ b/migrations/20251114144629_db.down.sql @@ -0,0 +1,3 @@ +-- Add migration script here + +drop table "patients"; diff --git a/migrations/20251114144629_db.up.sql b/migrations/20251114144629_db.up.sql new file mode 100644 index 0000000..dbd71c9 --- /dev/null +++ b/migrations/20251114144629_db.up.sql @@ -0,0 +1,7 @@ +-- Add migration script here + +create table "patients" ( + "id" INTEGER PRIMARY KEY, + "full_name" TEXT NOT NULL, + "phone" TEXT NOT NULL +); diff --git a/mydb.db b/mydb.db new file mode 100644 index 0000000..9374e0b Binary files /dev/null and b/mydb.db differ diff --git a/queries/create_patient.sql b/queries/create_patient.sql new file mode 100644 index 0000000..f4fd8e0 --- /dev/null +++ b/queries/create_patient.sql @@ -0,0 +1,3 @@ +insert into patients ("full_name", "phone") +values($1,$2) +returning "id"; diff --git a/queries/delete_patient.sql b/queries/delete_patient.sql new file mode 100644 index 0000000..a707782 --- /dev/null +++ b/queries/delete_patient.sql @@ -0,0 +1,3 @@ +delete from patients +where id = $1 +returning *; diff --git a/queries/get_all.sql b/queries/get_all.sql new file mode 100644 index 0000000..1a00727 --- /dev/null +++ b/queries/get_all.sql @@ -0,0 +1 @@ +select * from "patients" diff --git a/queries/get_patient_by_id.sql b/queries/get_patient_by_id.sql new file mode 100644 index 0000000..3a6d1c4 --- /dev/null +++ b/queries/get_patient_by_id.sql @@ -0,0 +1,2 @@ +select * from "patients" +where id = $1; diff --git a/queries/update_patient.sql b/queries/update_patient.sql new file mode 100644 index 0000000..2697216 --- /dev/null +++ b/queries/update_patient.sql @@ -0,0 +1,3 @@ +update patients +set full_name = $2, phone = $3 +where id = $1; diff --git a/src/app_state.rs b/src/app_state.rs new file mode 100644 index 0000000..479af0a --- /dev/null +++ b/src/app_state.rs @@ -0,0 +1,6 @@ +use sqlx::SqlitePool; + +#[derive(Clone)] +pub struct AppState { + pub pool: SqlitePool, +} diff --git a/src/lib.rs b/src/lib.rs index 83709bc..5947e5b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,30 +1,40 @@ -use axum::{debug_handler, extract::Json, response::IntoResponse}; -use schemas::Patient; +use axum::{ + debug_handler, + extract::{Json, Path, State}, + http::StatusCode, + response::IntoResponse, +}; +use models::Patient; +use sqlx::{query_file, query_file_as, query_file_scalar}; use tracing::info; -use utoipa::{OpenApi, openapi::Response}; +use utoipa::OpenApi; use utoipa_axum::{router::OpenApiRouter, routes}; -use crate::openapi::route_docs; +use crate::{ + app_state::AppState, + models::{CreatePatient, PathParams}, + openapi::route_docs, +}; +pub mod app_state; pub mod models; pub mod openapi; pub mod schemas; -#[derive(Clone)] -struct AppState {} - #[derive(OpenApi)] struct Api; -pub async fn router() { +pub async fn router(state: AppState) { 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!(create_patient)) + .routes(routes!(get_all)) .routes(routes!(update_patient_by_id)) .routes(routes!(delete_patient_by_id)) + .routes(routes!(get_patient_by_id)) + .with_state(state) .split_for_parts(); let listener = tokio::net::TcpListener::bind(addr).await.unwrap(); info!("Listening in {:?}", listener.local_addr()); @@ -34,30 +44,80 @@ pub async fn router() { #[debug_handler] #[utoipa::path(get, path = "/api/patients", description="Get all patients", responses((status = OK, body = Patient)))] -async fn get_patients() -> impl IntoResponse { +async fn get_all(State(state): State) -> Json> { + let patients = query_file_as!(Patient, "queries/get_all.sql") + .fetch_all(&state.pool) + .await + .expect("Could not fetch patients"); + Json(patients) +} + +#[debug_handler] +#[utoipa::path(get, path = "/api/patients/{id}", description="Get all patients", responses((status = OK, body = Patient)))] +async fn get_patient_by_id( + State(state): State, + Path(path): Path, +) -> impl IntoResponse { + let patient = query_file_as!(Patient, "queries/get_patient_by_id.sql", path.id) + .fetch_optional(&state.pool) + .await + .expect("Could not fetch patients"); + match patient { + Some(p) => Json(p).into_response(), + None => StatusCode::NOT_FOUND.into_response(), + } +} + +#[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(get, path = "/api/openapi.json", description="Get openapi.json file", responses((status = OK)))] -async fn get_openapi()-> impl IntoResponse { - axum::http::StatusCode::NOT_IMPLEMENTED +#[utoipa::path(post, path = "/api/patients", description = "Create a new patient", responses((status = OK)))] +async fn create_patient( + State(state): State, + Json(patient): Json, +) -> Json { + let new_patient_id = query_file_scalar!( + "queries/create_patient.sql", + patient.full_name, + patient.phone + ) + .fetch_one(&state.pool) + .await + .expect("Could not create new patient"); + Json(new_patient_id) } #[debug_handler] -#[utoipa::path(post, path = "/api/post_patient",description="Create a new patient", responses((status = OK)))] -async fn post_patient(Json(patient): Json)-> impl IntoResponse { - axum::http::StatusCode::NOT_IMPLEMENTED +#[utoipa::path(post, path = "/api/patients/{id}", description = "Update patient by ID", responses((status = OK)))] +async fn update_patient_by_id( + State(state): State, + Path(path): Path, + Json(patient): Json, +) -> impl IntoResponse { + query_file!( + "queries/update_patient.sql", + path.id, + patient.full_name, + patient.phone + ) + .fetch_one(&state.pool) + .await + .expect("Could not create new patient"); + StatusCode::CREATED } #[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)-> 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)-> impl IntoResponse { - axum::http::StatusCode::NOT_IMPLEMENTED +#[utoipa::path(delete, path = "/api/patients/{id}", description = "Delete patient by ID", responses((status = OK)))] +async fn delete_patient_by_id( + State(state): State, + Path(path): Path, +) -> impl IntoResponse { + query_file_as!(Patient, "queries/delete_patient.sql", path.id) + .fetch_one(&state.pool) + .await + .expect("Could not delete patient"); } diff --git a/src/main.rs b/src/main.rs index c7eaf09..f2c1e86 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,16 @@ -use test_exercise::router; +use hospital_server::app_state::AppState; +use hospital_server::router; +use sqlx::SqlitePool; #[tokio::main] async fn main() { - router().await; + let _ = dotenvy::dotenv(); + let db_url = std::env::var("DATABASE_URL").expect("DATABASE_URL is not set"); + + let pool = SqlitePool::connect(&db_url) + .await + .expect("Cannot connect to db"); + let state = AppState { pool: pool }; + sqlx::migrate!().run(&state.pool).await.unwrap(); + router(state).await; } diff --git a/src/models.rs b/src/models.rs index 39807be..ae757b3 100644 --- a/src/models.rs +++ b/src/models.rs @@ -2,13 +2,19 @@ use serde::{Deserialize, Serialize}; use utoipa::ToSchema; #[derive(Debug, Clone, ToSchema, Serialize, Deserialize)] -struct PatientId { - id: i32, +pub struct Patient { + pub id: i64, + pub full_name: String, + pub phone: String, } #[derive(Debug, Clone, ToSchema, Serialize, Deserialize)] -pub struct Patient { - id: PatientId, - name: String, - diagnosis: String, //todo! enum +pub struct CreatePatient { + pub full_name: String, + pub phone: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PathParams { + pub id: i64, }