mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
Fetch all uploaded files for a set of properties by landlord_property_id 🟥
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
da3e0cd4b4
commit
910f7cc06c
2 changed files with 45 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
from typing import Optional, Sequence
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlmodel import Session, col
|
||||
|
|
@ -24,5 +24,14 @@ class UploadedFilePostgresRepository:
|
|||
)
|
||||
return self._session.execute(stmt).scalars().one_or_none() # pyright: ignore[reportDeprecated]
|
||||
|
||||
def by_landlord_property_ids(
|
||||
self, landlord_property_ids: Sequence[str]
|
||||
) -> list[UploadedFile]:
|
||||
"""Every uploaded file held for the given properties, matched by
|
||||
`landlord_property_id` (ADR-0060), across all Document Types. Returns
|
||||
the raw rows — latest-per-Document-Type selection and null-type
|
||||
skipping are the Download Package plan's job, not the query's."""
|
||||
raise NotImplementedError
|
||||
|
||||
def insert(self, uploaded_file: UploadedFile) -> None:
|
||||
self._session.add(uploaded_file)
|
||||
|
|
|
|||
|
|
@ -78,3 +78,38 @@ def test_does_not_return_row_with_different_file_type(db_engine: Engine) -> None
|
|||
|
||||
# Assert
|
||||
assert result is None
|
||||
|
||||
|
||||
def _landlord_file(
|
||||
landlord_property_id: str,
|
||||
s3_file_key: str,
|
||||
file_type: FileTypeEnum = FileTypeEnum.SITE_NOTE,
|
||||
) -> UploadedFile:
|
||||
return UploadedFile(
|
||||
s3_file_bucket=_BUCKET,
|
||||
s3_file_key=s3_file_key,
|
||||
s3_upload_timestamp=datetime(2026, 1, 1, 12, 0, 0, tzinfo=timezone.utc),
|
||||
landlord_property_id=landlord_property_id,
|
||||
file_type=file_type.value,
|
||||
)
|
||||
|
||||
|
||||
def test_by_landlord_property_ids_returns_only_requested_properties(
|
||||
db_engine: Engine,
|
||||
) -> None:
|
||||
# Arrange — files for three properties; only two are requested.
|
||||
with Session(db_engine) as session:
|
||||
session.add(_landlord_file("LP1", "one.pdf"))
|
||||
session.add(_landlord_file("LP2", "two.pdf"))
|
||||
session.add(_landlord_file("LP3", "three.pdf"))
|
||||
session.commit()
|
||||
|
||||
# Act
|
||||
with Session(db_engine) as session:
|
||||
found = UploadedFilePostgresRepository(session).by_landlord_property_ids(
|
||||
["LP1", "LP2"]
|
||||
)
|
||||
result = {(f.landlord_property_id, f.s3_file_key) for f in found}
|
||||
|
||||
# Assert
|
||||
assert result == {("LP1", "one.pdf"), ("LP2", "two.pdf")}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue