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)