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,8 +1,8 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use mongodb::bson::{oid::ObjectId, DateTime, doc};
|
||||
use mongodb::Collection;
|
||||
use futures::stream::StreamExt;
|
||||
use super::health_data::EncryptedField;
|
||||
use futures::stream::StreamExt;
|
||||
use mongodb::bson::{doc, oid::ObjectId, DateTime};
|
||||
use mongodb::Collection;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// ============================================================================
|
||||
// PILL IDENTIFICATION (Phase 2.8)
|
||||
|
|
@ -14,11 +14,11 @@ pub struct PillIdentification {
|
|||
/// Size of the pill (optional)
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub size: Option<PillSize>,
|
||||
|
||||
|
||||
/// Shape of the pill (optional)
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub shape: Option<PillShape>,
|
||||
|
||||
|
||||
/// Color of the pill (optional)
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub color: Option<PillColor>,
|
||||
|
|
@ -27,11 +27,11 @@ pub struct PillIdentification {
|
|||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum PillSize {
|
||||
Tiny, // < 5mm
|
||||
Small, // 5-10mm
|
||||
Medium, // 10-15mm
|
||||
Large, // 15-20mm
|
||||
ExtraLarge,// > 20mm
|
||||
Tiny, // < 5mm
|
||||
Small, // 5-10mm
|
||||
Medium, // 10-15mm
|
||||
Large, // 15-20mm
|
||||
ExtraLarge, // > 20mm
|
||||
#[serde(rename = "custom")]
|
||||
Custom(String),
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ pub struct Medication {
|
|||
pub created_at: DateTime,
|
||||
#[serde(rename = "updatedAt")]
|
||||
pub updated_at: DateTime,
|
||||
|
||||
|
||||
/// Physical pill identification (Phase 2.8 - optional)
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub pill_identification: Option<PillIdentification>,
|
||||
|
|
@ -167,7 +167,7 @@ pub struct CreateMedicationRequest {
|
|||
pub tags: Option<Vec<String>>,
|
||||
pub reminder_times: Option<Vec<String>>,
|
||||
pub profile_id: String,
|
||||
|
||||
|
||||
/// Pill identification (Phase 2.8 - optional)
|
||||
#[serde(rename = "pill_identification")]
|
||||
pub pill_identification: Option<PillIdentification>,
|
||||
|
|
@ -189,7 +189,7 @@ pub struct UpdateMedicationRequest {
|
|||
pub notes: Option<String>,
|
||||
pub tags: Option<Vec<String>>,
|
||||
pub reminder_times: Option<Vec<String>>,
|
||||
|
||||
|
||||
/// Pill identification (Phase 2.8 - optional)
|
||||
#[serde(rename = "pill_identification")]
|
||||
pub pill_identification: Option<PillIdentification>,
|
||||
|
|
@ -216,13 +216,19 @@ impl MedicationRepository {
|
|||
pub fn new(collection: Collection<Medication>) -> Self {
|
||||
Self { collection }
|
||||
}
|
||||
|
||||
pub async fn create(&self, medication: Medication) -> Result<Medication, Box<dyn std::error::Error>> {
|
||||
|
||||
pub async fn create(
|
||||
&self,
|
||||
medication: Medication,
|
||||
) -> Result<Medication, Box<dyn std::error::Error>> {
|
||||
let _result = self.collection.insert_one(medication.clone(), None).await?;
|
||||
Ok(medication)
|
||||
}
|
||||
|
||||
pub async fn find_by_user(&self, user_id: &str) -> Result<Vec<Medication>, Box<dyn std::error::Error>> {
|
||||
|
||||
pub async fn find_by_user(
|
||||
&self,
|
||||
user_id: &str,
|
||||
) -> Result<Vec<Medication>, Box<dyn std::error::Error>> {
|
||||
let filter = doc! { "userId": user_id };
|
||||
let mut cursor = self.collection.find(filter, None).await?;
|
||||
let mut medications = Vec::new();
|
||||
|
|
@ -231,9 +237,13 @@ impl MedicationRepository {
|
|||
}
|
||||
Ok(medications)
|
||||
}
|
||||
|
||||
pub async fn find_by_user_and_profile(&self, user_id: &str, profile_id: &str) -> Result<Vec<Medication>, Box<dyn std::error::Error>> {
|
||||
let filter = doc! {
|
||||
|
||||
pub async fn find_by_user_and_profile(
|
||||
&self,
|
||||
user_id: &str,
|
||||
profile_id: &str,
|
||||
) -> Result<Vec<Medication>, Box<dyn std::error::Error>> {
|
||||
let filter = doc! {
|
||||
"userId": user_id,
|
||||
"profileId": profile_id
|
||||
};
|
||||
|
|
@ -244,16 +254,23 @@ impl MedicationRepository {
|
|||
}
|
||||
Ok(medications)
|
||||
}
|
||||
|
||||
pub async fn find_by_id(&self, id: &ObjectId) -> Result<Option<Medication>, Box<dyn std::error::Error>> {
|
||||
|
||||
pub async fn find_by_id(
|
||||
&self,
|
||||
id: &ObjectId,
|
||||
) -> Result<Option<Medication>, Box<dyn std::error::Error>> {
|
||||
let filter = doc! { "_id": id };
|
||||
let medication = self.collection.find_one(filter, None).await?;
|
||||
Ok(medication)
|
||||
}
|
||||
|
||||
pub async fn update(&self, id: &ObjectId, updates: UpdateMedicationRequest) -> Result<Option<Medication>, Box<dyn std::error::Error>> {
|
||||
|
||||
pub async fn update(
|
||||
&self,
|
||||
id: &ObjectId,
|
||||
updates: UpdateMedicationRequest,
|
||||
) -> Result<Option<Medication>, Box<dyn std::error::Error>> {
|
||||
let mut update_doc = doc! {};
|
||||
|
||||
|
||||
if let Some(name) = updates.name {
|
||||
update_doc.insert("medicationData.name", name);
|
||||
}
|
||||
|
|
@ -301,21 +318,28 @@ impl MedicationRepository {
|
|||
update_doc.insert("pillIdentification", pill_doc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
update_doc.insert("updatedAt", mongodb::bson::DateTime::now());
|
||||
|
||||
|
||||
let filter = doc! { "_id": id };
|
||||
let medication = self.collection.find_one_and_update(filter, doc! { "$set": update_doc }, None).await?;
|
||||
let medication = self
|
||||
.collection
|
||||
.find_one_and_update(filter, doc! { "$set": update_doc }, None)
|
||||
.await?;
|
||||
Ok(medication)
|
||||
}
|
||||
|
||||
|
||||
pub async fn delete(&self, id: &ObjectId) -> Result<bool, Box<dyn std::error::Error>> {
|
||||
let filter = doc! { "_id": id };
|
||||
let result = self.collection.delete_one(filter, None).await?;
|
||||
Ok(result.deleted_count > 0)
|
||||
}
|
||||
|
||||
pub async fn calculate_adherence(&self, medication_id: &str, days: i64) -> Result<AdherenceStats, Box<dyn std::error::Error>> {
|
||||
|
||||
pub async fn calculate_adherence(
|
||||
&self,
|
||||
medication_id: &str,
|
||||
days: i64,
|
||||
) -> Result<AdherenceStats, Box<dyn std::error::Error>> {
|
||||
// For now, return a placeholder adherence calculation
|
||||
// In a full implementation, this would query the medication_doses collection
|
||||
Ok(AdherenceStats {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue