feat(api): add advertisement history API endpoint (Task 2.8)

Add GET /api/advertisements with optional pubkey filter and limit.
Enriches results with contact name lookup from cache.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
MarekWo
2026-03-01 17:26:37 +01:00
parent 5df10f0ab9
commit d89e276054
2 changed files with 48 additions and 0 deletions
+17
View File
@@ -414,6 +414,23 @@ class Database:
kwargs.get('raw_payload'))
)
def get_advertisements(self, limit: int = 100, public_key: str = None) -> list:
with self._connect() as conn:
if public_key:
rows = conn.execute(
"""SELECT * FROM advertisements
WHERE public_key = ?
ORDER BY timestamp DESC LIMIT ?""",
(public_key.lower(), limit)
).fetchall()
else:
rows = conn.execute(
"""SELECT * FROM advertisements
ORDER BY timestamp DESC LIMIT ?""",
(limit,)
).fetchall()
return [dict(r) for r in rows]
# ================================================================
# Read Status
# ================================================================