feat(안내문 발송): DM 수동 보내기 — 이름 지우기·본문 편집·저장한 본문 목록

- 이름 목록: × 한 명씩 빼기·[전체 삭제], 이름 넣기는 목록에 더함
- 본문: 바로 고침(plaintext-only), {이름} 자리 = 분홍 칩, 이름 누르면 고친 글 + 이름 복사
- 저장한 본문(본문 오른쪽): 설정 DM 문구 + 저장한 것, 고르기·[저장]·[새 본문으로 저장]·× 지우기
- outreach_db 마이그레이션 002 outreach_dm_bodies + POST/PUT/DELETE /outreach/api/dm-bodies
  (002 미적용이면 목록 안내만, API 503)
- 캐시 버전 20261030c, 단위·API·실제 PG·브라우저 테스트

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 16:51:10 +09:00
parent 456dfe376f
commit 48cd7f0878
16 changed files with 454 additions and 63 deletions
+31
View File
@@ -10,6 +10,7 @@ from __future__ import annotations
from datetime import datetime
from typing import Any
from psycopg.errors import UndefinedTable
from psycopg.rows import dict_row
from psycopg.types.json import Jsonb
from psycopg_pool import ConnectionPool
@@ -211,6 +212,36 @@ class OutreachDBStore:
"WHERE status = '발송중'")
return cur.rowcount
# ── DM 수동 보내기 탭의 저장한 본문(마이그레이션 002) ──────────
def list_dm_bodies(self) -> list[dict[str, Any]] | None:
"""새로 고친 것부터. 표가 없으면(002 미적용) None — 화면이 저장 목록만 숨긴다."""
try:
with self._pool.connection() as conn:
rows = conn.execute("SELECT id, title, body, created_by, updated_by, updated_at FROM outreach_dm_bodies "
"ORDER BY updated_at DESC, id DESC").fetchall()
except UndefinedTable:
return None
return [{**dict(r), "id": int(r["id"]), "updated_at": _iso(r["updated_at"])} for r in rows]
def save_dm_body(self, body: Any, *, by: str, body_id: int | None = None) -> int:
"""새로 저장(body_id 없음) 또는 그 본문 고치기. 저장한 id. 없는 id = KeyError."""
title, text = store.dm_saved_body(body)
by = (by or "").lower()
with self._pool.connection() as conn:
if body_id is None:
return int(conn.execute(
"INSERT INTO outreach_dm_bodies (title, body, created_by, updated_by) VALUES (%s, %s, %s, %s) RETURNING id",
(title, text, by, by)).fetchone()["id"])
row = conn.execute("UPDATE outreach_dm_bodies SET title = %s, body = %s, updated_by = %s, updated_at = now() "
"WHERE id = %s RETURNING id", (title, text, by, body_id)).fetchone()
if row is None:
raise KeyError(body_id)
return int(row["id"])
def delete_dm_body(self, body_id: int) -> None:
with self._pool.connection() as conn:
conn.execute("DELETE FROM outreach_dm_bodies WHERE id = %s", (body_id,))
def list_logs(self, *, limit: int = 200) -> list[dict[str, Any]]:
with self._pool.connection() as conn:
rows = conn.execute("SELECT * FROM outreach_logs ORDER BY sent_at DESC, id DESC LIMIT %s", (limit,)).fetchall()