feat: 增加菜地图片
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user