feat: 增加菜地图片

This commit is contained in:
2026-09-09 19:01:05 +08:00
parent 31af6e07e2
commit 8b563e8249
3 changed files with 22 additions and 28 deletions

View File

@@ -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)