mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
got rid of confirm matches
This commit is contained in:
parent
7caa7c476a
commit
85cfa15335
1 changed files with 0 additions and 50 deletions
|
|
@ -75,53 +75,3 @@ async def get_combined_results(
|
||||||
"offset": offset,
|
"offset": offset,
|
||||||
"limit": limit,
|
"limit": limit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.post("/{task_id}/confirm-matches")
|
|
||||||
async def confirm_matches(task_id: UUID, req: ConfirmMatchesRequest):
|
|
||||||
with get_db_session() as session:
|
|
||||||
upload = session.exec(
|
|
||||||
select(BulkAddressUpload).where(BulkAddressUpload.task_id == task_id)
|
|
||||||
).first()
|
|
||||||
if not upload:
|
|
||||||
raise HTTPException(status_code=404, detail="Upload not found")
|
|
||||||
|
|
||||||
rows = []
|
|
||||||
for row in req.accepted_rows:
|
|
||||||
address = row.address_line_1
|
|
||||||
if row.address_line_2:
|
|
||||||
address = f"{row.address_line_1}, {row.address_line_2}"
|
|
||||||
rows.append(
|
|
||||||
{
|
|
||||||
"uprn": row.uprn,
|
|
||||||
"address": address,
|
|
||||||
"postcode": row.postcode,
|
|
||||||
"portfolio_id": int(upload.portfolio_id),
|
|
||||||
"landlord_property_id": row.internal_reference,
|
|
||||||
"creation_status": PropertyCreationStatus.LOADING,
|
|
||||||
"status": PortfolioStatus.ASSESSMENT.value,
|
|
||||||
"has_pre_condition_report": False,
|
|
||||||
"has_recommendations": False,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
stmt = (
|
|
||||||
insert(PropertyModel)
|
|
||||||
.values(rows)
|
|
||||||
.on_conflict_do_nothing(
|
|
||||||
index_elements=["portfolio_id", "uprn"],
|
|
||||||
index_where=PropertyModel.uprn.isnot(None),
|
|
||||||
)
|
|
||||||
.returning(PropertyModel.id)
|
|
||||||
)
|
|
||||||
result = session.execute(stmt)
|
|
||||||
session.flush()
|
|
||||||
inserted = len(result.fetchall())
|
|
||||||
skipped = len(rows) - inserted
|
|
||||||
|
|
||||||
upload.status = "confirmed"
|
|
||||||
upload.updated_at = datetime.now(timezone.utc)
|
|
||||||
session.add(upload)
|
|
||||||
session.commit()
|
|
||||||
|
|
||||||
return {"inserted": inserted, "skipped": skipped}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue