style: apply rustfmt to backend codebase
- Apply rustfmt to all Rust source files in backend/ - Fix trailing whitespace inconsistencies - Standardize formatting across handlers, models, and services - Improve code readability with consistent formatting These changes are purely stylistic and do not affect functionality. All CI checks now pass with proper formatting.
This commit is contained in:
parent
6b7e4d4016
commit
ee0feb77ef
41 changed files with 1266 additions and 819 deletions
|
|
@ -1,14 +1,17 @@
|
|||
use axum::{
|
||||
extract::{Path, Query, State, Extension, Json},
|
||||
extract::{Extension, Json, Path, Query, State},
|
||||
http::StatusCode,
|
||||
};
|
||||
use mongodb::bson::oid::ObjectId;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::{
|
||||
models::medication::{Medication, MedicationRepository, CreateMedicationRequest, UpdateMedicationRequest, LogDoseRequest},
|
||||
auth::jwt::Claims, // Fixed: import from auth::jwt instead of handlers::auth
|
||||
auth::jwt::Claims, // Fixed: import from auth::jwt instead of handlers::auth
|
||||
config::AppState,
|
||||
models::medication::{
|
||||
CreateMedicationRequest, LogDoseRequest, Medication, MedicationRepository,
|
||||
UpdateMedicationRequest,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
|
|
@ -25,7 +28,7 @@ pub async fn create_medication(
|
|||
) -> Result<Json<Medication>, StatusCode> {
|
||||
let database = state.db.get_database();
|
||||
let repo = MedicationRepository::new(database.collection("medications"));
|
||||
|
||||
|
||||
let now = SystemTime::now();
|
||||
let medication_id = uuid::Uuid::new_v4().to_string();
|
||||
|
||||
|
|
@ -59,12 +62,15 @@ pub async fn create_medication(
|
|||
user_id: claims.sub,
|
||||
profile_id: req.profile_id.clone(),
|
||||
medication_data,
|
||||
reminders: req.reminder_times.unwrap_or_default().into_iter().map(|time| {
|
||||
crate::models::medication::MedicationReminder {
|
||||
reminders: req
|
||||
.reminder_times
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(|time| crate::models::medication::MedicationReminder {
|
||||
reminder_id: uuid::Uuid::new_v4().to_string(),
|
||||
scheduled_time: time,
|
||||
}
|
||||
}).collect(),
|
||||
})
|
||||
.collect(),
|
||||
created_at: now.into(),
|
||||
updated_at: now.into(),
|
||||
pill_identification: req.pill_identification, // Phase 2.8
|
||||
|
|
@ -83,13 +89,10 @@ pub async fn list_medications(
|
|||
) -> Result<Json<Vec<Medication>>, StatusCode> {
|
||||
let database = state.db.get_database();
|
||||
let repo = MedicationRepository::new(database.collection("medications"));
|
||||
|
||||
|
||||
let _limit = query.limit.unwrap_or(100);
|
||||
|
||||
match repo
|
||||
.find_by_user(&claims.sub)
|
||||
.await
|
||||
{
|
||||
match repo.find_by_user(&claims.sub).await {
|
||||
Ok(medications) => Ok(Json(medications)),
|
||||
Err(_) => Err(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
}
|
||||
|
|
@ -102,7 +105,7 @@ pub async fn get_medication(
|
|||
) -> Result<Json<Medication>, StatusCode> {
|
||||
let database = state.db.get_database();
|
||||
let repo = MedicationRepository::new(database.collection("medications"));
|
||||
|
||||
|
||||
match ObjectId::parse_str(&id) {
|
||||
Ok(oid) => match repo.find_by_id(&oid).await {
|
||||
Ok(Some(medication)) => Ok(Json(medication)),
|
||||
|
|
@ -121,7 +124,7 @@ pub async fn update_medication(
|
|||
) -> Result<Json<Medication>, StatusCode> {
|
||||
let database = state.db.get_database();
|
||||
let repo = MedicationRepository::new(database.collection("medications"));
|
||||
|
||||
|
||||
match ObjectId::parse_str(&id) {
|
||||
Ok(oid) => match repo.update(&oid, req).await {
|
||||
Ok(Some(medication)) => Ok(Json(medication)),
|
||||
|
|
@ -139,7 +142,7 @@ pub async fn delete_medication(
|
|||
) -> Result<StatusCode, StatusCode> {
|
||||
let database = state.db.get_database();
|
||||
let repo = MedicationRepository::new(database.collection("medications"));
|
||||
|
||||
|
||||
match ObjectId::parse_str(&id) {
|
||||
Ok(oid) => match repo.delete(&oid).await {
|
||||
Ok(true) => Ok(StatusCode::NO_CONTENT),
|
||||
|
|
@ -157,9 +160,9 @@ pub async fn log_dose(
|
|||
Json(req): Json<LogDoseRequest>,
|
||||
) -> Result<StatusCode, StatusCode> {
|
||||
let database = state.db.get_database();
|
||||
|
||||
|
||||
let now = SystemTime::now();
|
||||
|
||||
|
||||
let dose = crate::models::medication::MedicationDose {
|
||||
id: None,
|
||||
medication_id: id.clone(),
|
||||
|
|
@ -169,8 +172,12 @@ pub async fn log_dose(
|
|||
taken: req.taken.unwrap_or(true),
|
||||
notes: req.notes,
|
||||
};
|
||||
|
||||
match database.collection("medication_doses").insert_one(dose.clone(), None).await {
|
||||
|
||||
match database
|
||||
.collection("medication_doses")
|
||||
.insert_one(dose.clone(), None)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Ok(StatusCode::CREATED),
|
||||
Err(_) => Err(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
}
|
||||
|
|
@ -183,7 +190,7 @@ pub async fn get_adherence(
|
|||
) -> Result<Json<crate::models::medication::AdherenceStats>, StatusCode> {
|
||||
let database = state.db.get_database();
|
||||
let repo = MedicationRepository::new(database.collection("medications"));
|
||||
|
||||
|
||||
match repo.calculate_adherence(&id, 30).await {
|
||||
Ok(stats) => Ok(Json(stats)),
|
||||
Err(_) => Err(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue