feat: support rejected application status
This commit is contained in:
1 parent
08ec58c7e9
commit
cd33a382c0
5 files changed
+47
-15
No files matched your search
@@ -227,7 +227,7 @@ class ApplicationStore:
|
||||
|
||||
def list(self, *, status: str | None = None, limit: int = 500) -> list[dict[str, Any]]:
|
||||
"""Возвращает заявки, ограничивая выборку и опционально фильтруя статус."""
|
||||
if status not in (None, "pending", "accepted"):
|
||||
if status not in (None, "pending", "accepted", "rejected"):
|
||||
raise ApplicationError("Неизвестный статус заявки")
|
||||
limit = max(1, min(int(limit), 500))
|
||||
if self.database_url.startswith(("postgres://", "postgresql://")):
|
||||
@@ -253,27 +253,34 @@ class ApplicationStore:
|
||||
|
||||
def accept(self, application_id: int) -> dict[str, Any] | None:
|
||||
"""Атомарно переводит заявку в accepted и возвращает её снимок."""
|
||||
return self.review(application_id, status="accepted")
|
||||
|
||||
def review(self, application_id: int, *, status: str) -> dict[str, Any] | None:
|
||||
"""Атомарно присваивает новой заявке итоговый статус рассмотрения."""
|
||||
if application_id <= 0:
|
||||
raise ApplicationError("ID заявки должен быть положительным")
|
||||
if status not in ("accepted", "rejected"):
|
||||
raise ApplicationError("Некорректный статус рассмотрения")
|
||||
if self.database_url.startswith(("postgres://", "postgresql://")):
|
||||
with self._psycopg.connect(self.database_url) as connection:
|
||||
row = connection.execute("""UPDATE belki_applications SET status = 'accepted', reviewed_at = NOW()
|
||||
row = connection.execute("""UPDATE belki_applications SET status = %s, reviewed_at = NOW()
|
||||
WHERE id = %s AND status = 'pending'
|
||||
RETURNING id, actor_id, reply_peer_id, source, application_json, status, created_at, reviewed_at""", (application_id,)).fetchone()
|
||||
RETURNING id, actor_id, reply_peer_id, source, application_json, status, created_at, reviewed_at""", (status, application_id)).fetchone()
|
||||
else:
|
||||
with sqlite3.connect(self.sqlite_path) as connection:
|
||||
cursor = connection.execute("UPDATE applications SET status = 'accepted', reviewed_at = CURRENT_TIMESTAMP WHERE id = ? AND status = 'pending'", (application_id,))
|
||||
cursor = connection.execute("UPDATE applications SET status = ?, reviewed_at = CURRENT_TIMESTAMP WHERE id = ? AND status = 'pending'", (status, application_id))
|
||||
if not cursor.rowcount:
|
||||
return None
|
||||
application = next((item for item in self.list(limit=500) if item["id"] == application_id), None)
|
||||
if application:
|
||||
if application and status == "accepted":
|
||||
self.enqueue_export(application_id, "application_accepted", application)
|
||||
return application
|
||||
if row is None:
|
||||
return None
|
||||
application = {"id": row[0], "actor_id": row[1], "reply_peer_id": row[2], "source": row[3],
|
||||
"application": row[4], "status": row[5], "created_at": row[6].isoformat(), "reviewed_at": row[7].isoformat()}
|
||||
self.enqueue_export(application_id, "application_accepted", application)
|
||||
if status == "accepted":
|
||||
self.enqueue_export(application_id, "application_accepted", application)
|
||||
return application
|
||||
|
||||
def enqueue_export(self, application_id: int, event_type: str, snapshot: dict[str, Any]) -> int:
|
||||
|
||||
Reference in new issue
Block a user