From 8b563e8249c9d0c7b202e0902d0a7da1520b8699 Mon Sep 17 00:00:00 2001
From: Cxx0822 <1556464090@qq.com>
Date: Wed, 9 Sep 2026 19:01:05 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=8F=9C=E5=9C=B0?=
=?UTF-8?q?=E5=9B=BE=E7=89=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/workspace.xml | 31 +++++--------------------------
schemas/patch.py | 1 +
service/patch_service.py | 18 ++++++++++++++++--
3 files changed, 22 insertions(+), 28 deletions(-)
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 97edfec..4e6e3c6 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,30 +5,9 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
@@ -111,7 +90,7 @@
1788917189828
-
+
@@ -119,6 +98,6 @@
-
+
\ No newline at end of file
diff --git a/schemas/patch.py b/schemas/patch.py
index 4e68e37..b8b48da 100644
--- a/schemas/patch.py
+++ b/schemas/patch.py
@@ -29,6 +29,7 @@ class CropUpdate(BaseModel):
class CropResponse(CropCreate):
id: int
+ images: Optional[list[str]] = None
model_config = {
"from_attributes": True
diff --git a/service/patch_service.py b/service/patch_service.py
index b81a752..5fe0fec 100644
--- a/service/patch_service.py
+++ b/service/patch_service.py
@@ -21,13 +21,27 @@ def get_patches(db: Session) -> list[PatchResponse]:
crop = db.execute(
select(Crops).where(Crops.patch_id == p.id)
).scalar_one_or_none()
+
data = PatchResponse.model_validate(p)
- data.crop = CropResponse.from_orm(crop) if crop else None
+
+ if crop:
+ latest_record = db.execute(
+ select(Records)
+ .where(Records.crop_id == crop.id)
+ .order_by(Records.date.desc())
+ .limit(1)
+ ).scalar_one_or_none()
+
+ crop_data = CropResponse.from_orm(crop)
+ crop_data.images = latest_record.images if latest_record else []
+ data.crop = crop_data
+ else:
+ data.crop = None
+
result.append(data)
return result
-
def get_patch(db: Session, patch_id: int) -> PatchResponse | None:
patch = db.execute(
select(Patches).where(Patches.id == patch_id)