feat(medications): persist real active flag + filter

The active flag was synthesized as always-true. Now it's a real top-level field
on the Medication document (serde default=true so old rows stay active),
wired through create (default true), update ($set the field, not the data blob),
and list (the previously-ignored ?active= query param now filters at Mongo level
via find_by_user_filtered). Fixed stale comments claiming updates.active was
'accepted but not persisted' (the field didn't even exist on UpdateMedicationRequest).

Verified: cargo fmt/clippy 0 warnings, 23 tests pass; frontend build + 20 tests.
This commit is contained in:
goose 2026-06-28 12:49:02 -03:00
parent 8bcb03cd09
commit 0921d73a6d
2 changed files with 56 additions and 10 deletions

View file

@ -72,6 +72,7 @@ pub async fn create_medication(
.collect(),
created_at: now.into(),
updated_at: now.into(),
active: req.active,
pill_identification: req.pill_identification, // Phase 2.8
};
@ -89,9 +90,11 @@ pub async fn list_medications(
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 {
// Honor the active filter (and optional profile_id) when provided.
match repo
.find_by_user_filtered(&claims.sub, query.active, query.profile_id.as_deref())
.await
{
Ok(medications) => {
let resp: Vec<MedicationResponse> = medications.into_iter().map(Into::into).collect();
Ok(Json(resp))