[feat] solution/backend,docs: 미니블로그 승인 → 쓰레드 자동 게재, 쓰레드 초안 생성 OpenAI 전환
사장님 지시: "쓰레드에 연동되어 있으면 같이 업로드 되는 기능". 미니블로그의 두 승인 경로(이메일 GET 토큰, 로그인 "바로 발행")를 공통 메서드로 묶고, 그 끝에서 쓰레드 연동을 시도한다. 미니블로그 승인 자체가 발화 동의로 취급되므로 쓰레드 쪽 별도 승인은 묻지 않는다(DECISIONS 7-1-2 개정, 문구를 그대로 재사용하는 경우에 한정). 겸사겸사 쓰레드 초안 생성(generate_social_post)이 LLM_PROVIDER 를 안 타고 Gemini 를 직접 호출하던 것도 다른 생성 함수와 같은 추상화로 맞췄다. - blog_jobs._published_places: sites.domain IS NOT NULL 조건 추가(쓰레드 기준과 통일) - social_service.publish_reused_text: 연동 없음/게시 비활성/domain 미확정이면 스킵, 정상이면 APPROVED 삽입 + run_post(job_type=9) enqueue — 새 게시 로직은 안 만든다 - post_service: decide/approve_by_owner → _approve_and_publish 로 공통화, _try_social_share 는 실패를 전부 삼켜 미니블로그 승인을 막지 않는다 - gemini_text.generate_social_post: services.llm.provider.active() 로 전환, Gemini 전용 import 제거 - DECISIONS.md 7-1-2, MINI_BLOG.md 5·8절, SOCIAL.md 갱신 test_blog_owner.py·test_social.py 다수 추가/수정, 관련 스위트 전체 PASS
This commit is contained in:
1 parent
07c53d30bf
commit
47da2f29b3
9 files changed
+861
-101
No files matched your search
@@ -23,7 +23,7 @@ from common.utils.gtime import GTime
|
||||
from router.v1.site.protocol import (
|
||||
GenerationBatch, PostData, Res_GenerateNow, Res_GenerateOne, Res_GenerationHistory, Res_MyPosts,
|
||||
)
|
||||
from services import blog_jobs, blog_service
|
||||
from services import blog_jobs, blog_service, social_service
|
||||
from services.job_service import enqueue_job
|
||||
|
||||
EXPIRED = "처리할 수 없는 링크입니다."
|
||||
@@ -75,10 +75,7 @@ class PostService:
|
||||
)
|
||||
return {"success": True, "message": SKIPPED}
|
||||
|
||||
await DB_SESSION_MNG.execute_lambda_run(
|
||||
[place_posts.DBType()], [lambda s: self.crud.approve(s, post_id)],
|
||||
)
|
||||
await self._enqueue_build(post_id, place_id)
|
||||
await self._approve_and_publish(post_id, place_id)
|
||||
return {"success": True, "message": APPROVED}
|
||||
|
||||
async def _load_place(self, user_info: UserInfo, place_id: str):
|
||||
@@ -191,7 +188,10 @@ class PostService:
|
||||
async def edit_by_owner(
|
||||
self, user_info: UserInfo, place_id: str, post_id: str, body: str
|
||||
) -> Res_WebPacketProtocol:
|
||||
"""로그인 세션으로 직접 고치기 — 메일이 아직 안 나간 REVIEWED 글도 여기서 바로 승인된다."""
|
||||
"""로그인 세션으로 직접 고치기 — 저장만 한다. ★ 승인은 여기서 하지 않는다(2026-09-21,
|
||||
사장님 지시: "승인되야 올라가도록 해야 한다") — 저장 후에는 이메일 승인 링크
|
||||
(router/v1/site/post.py approve_page → decide) 또는 바로 아래 approve_by_owner
|
||||
("바로 발행" 버튼)를 명시적으로 눌러야 게재된다."""
|
||||
res = Res_WebPacketProtocol()
|
||||
err_type, _place = await self._load_place(user_info, place_id)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
@@ -208,15 +208,13 @@ class PostService:
|
||||
await DB_SESSION_MNG.execute_lambda_run(
|
||||
[place_posts.DBType()], [lambda s: self.crud.update_body(s, pid, body)],
|
||||
)
|
||||
await DB_SESSION_MNG.execute_lambda_run(
|
||||
[place_posts.DBType()], [lambda s: self.crud.approve(s, pid)],
|
||||
)
|
||||
await self._enqueue_build(pid, uuid.UUID(place_id))
|
||||
res.msg = APPROVED
|
||||
res.msg = "저장했습니다. 이메일 승인 링크를 눌러야 사이트에 반영됩니다."
|
||||
return res
|
||||
|
||||
async def approve_by_owner(self, user_info: UserInfo, place_id: str, post_id: str) -> Res_WebPacketProtocol:
|
||||
"""로그인 세션으로 바로 발행 — 고치지 않고 그대로. edit_by_owner 와 승인·빌드 경로는 같다."""
|
||||
"""로그인 세션으로 바로 발행 — 고치지 않고 그대로, 또는 방금 edit_by_owner 로 고친
|
||||
그대로 승인한다(2026-09-21, 사장님 지시: "이메일 승인으로도 발행 가능하고
|
||||
바로발행버튼으로도 발행 가능하도록"). 이메일 승인 링크와 별개의 두 번째 경로다."""
|
||||
res = Res_WebPacketProtocol()
|
||||
err_type, _place = await self._load_place(user_info, place_id)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
@@ -224,13 +222,37 @@ class PostService:
|
||||
return res
|
||||
|
||||
pid = uuid.UUID(post_id)
|
||||
await DB_SESSION_MNG.execute_lambda_run(
|
||||
[place_posts.DBType()], [lambda s: self.crud.approve(s, pid)],
|
||||
)
|
||||
await self._enqueue_build(pid, uuid.UUID(place_id))
|
||||
await self._approve_and_publish(pid, uuid.UUID(place_id))
|
||||
res.msg = APPROVED
|
||||
return res
|
||||
|
||||
async def delete_by_owner(self, user_info: UserInfo, place_id: str, post_id: str) -> Res_WebPacketProtocol:
|
||||
"""소프트 삭제 — 상태 제한 없이 지운다. 이미 게재된 글이면 그 자리에서 빠지도록
|
||||
재발행 잡까지 큐에 넣는다(그 외 상태는 사이트에 나간 적이 없어 재발행이 필요 없다)."""
|
||||
res = Res_WebPacketProtocol()
|
||||
err_type, _place = await self._load_place(user_info, place_id)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
res.result.SetResult(err_type)
|
||||
return res
|
||||
|
||||
pid = uuid.UUID(post_id)
|
||||
row = await DB_SESSION_MNG.execute_lambda(
|
||||
place_posts.DBType(), DBWRType.DB_READ.value,
|
||||
lambda s: self.crud.by_id(s, pid),
|
||||
)
|
||||
if row is None or str(row.place_id) != str(place_id):
|
||||
res.result.SetResult(ErrorType.PLACE_NOT_FOUND)
|
||||
return res
|
||||
|
||||
was_published = row.status == PostStatus.PUBLISHED.value
|
||||
await DB_SESSION_MNG.execute_lambda_run(
|
||||
[place_posts.DBType()], [lambda s: self.crud.delete(s, pid)],
|
||||
)
|
||||
if was_published:
|
||||
await self._enqueue_build(pid, uuid.UUID(place_id))
|
||||
res.msg = "삭제했습니다."
|
||||
return res
|
||||
|
||||
async def generate_range(self, user_info: UserInfo, place_id: str, start_date: date, end_date: date) -> Res_GenerateNow:
|
||||
"""새벽 크론(04:10)을 기다리지 않고, 사장님이 고른 구간을 그 자리에서 채운다
|
||||
(2026-09-17, 사장님 지시: "지금 생성하기에서 시작이랑 끝 날짜를 정해야하지 않을까")."""
|
||||
@@ -274,6 +296,34 @@ class PostService:
|
||||
res.msg = "만들었습니다."
|
||||
return res
|
||||
|
||||
_SEND_NOW_MSG = {
|
||||
"MAIL_NOT_CONFIGURED": "메일 발송이 설정되어 있지 않습니다.",
|
||||
"NO_VALID_EMAIL": "받을 이메일 주소가 올바르지 않습니다.",
|
||||
"SEND_FAILED": "메일 발송에 실패했습니다.",
|
||||
}
|
||||
|
||||
async def send_now(self, user_info: UserInfo, place_id: str) -> Res_WebPacketProtocol:
|
||||
"""빌더 화면의 '지금 발송하기' — 아침 9시 스윕을 기다리지 않고 이 업장의 오늘 몫을
|
||||
바로 보낸다(2026-09-21, 사장님 요청). 보낼 게 없는 건 오류가 아니다 — generate_range
|
||||
의 '이미 다 있거나 소재가 없다'와 같은 결의 안내로 끝낸다."""
|
||||
res = Res_WebPacketProtocol()
|
||||
err_type, _place = await self._load_place(user_info, place_id)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
res.result.SetResult(err_type)
|
||||
return res
|
||||
|
||||
outcome = await blog_jobs.send_now_for_place(place_id)
|
||||
if outcome["sent"]:
|
||||
res.msg = "메일을 보냈습니다."
|
||||
return res
|
||||
reason = outcome.get("reason")
|
||||
if reason == "NOTHING_DUE":
|
||||
res.msg = "오늘 보낼 글이 없습니다."
|
||||
return res
|
||||
res.result.SetResult(ErrorType.INVALID_REQUEST_DATA)
|
||||
res.msg = self._SEND_NOW_MSG.get(reason, "지금은 발송할 수 없습니다.")
|
||||
return res
|
||||
|
||||
async def _owner_user_id(self, place_id):
|
||||
def query(session):
|
||||
return session.execute(select(places.owner_user_id).where(places.place_id == place_id))
|
||||
@@ -282,6 +332,28 @@ class PostService:
|
||||
row = result.first() if result is not None else None
|
||||
return row[0] if row else None
|
||||
|
||||
async def _approve_and_publish(self, post_id, place_id) -> None:
|
||||
await DB_SESSION_MNG.execute_lambda_run(
|
||||
[place_posts.DBType()], [lambda s: self.crud.approve(s, post_id)],
|
||||
)
|
||||
await self._enqueue_build(post_id, place_id)
|
||||
await self._try_social_share(post_id, place_id)
|
||||
|
||||
async def _try_social_share(self, post_id, place_id) -> None:
|
||||
"""쓰레드 연동 — 실패해도 미니블로그 승인은 이미 끝난 뒤라 예외를 밖으로 던지지
|
||||
않는다(2026-09-21, DECISIONS 7-1-2 개정)."""
|
||||
try:
|
||||
post = await DB_SESSION_MNG.execute_lambda(
|
||||
place_posts.DBType(), DBWRType.DB_READ.value,
|
||||
lambda s: self.crud.by_id(s, post_id),
|
||||
)
|
||||
owner_user_id = await self._owner_user_id(place_id)
|
||||
if post is None or owner_user_id is None or not post.body:
|
||||
return
|
||||
await social_service.publish_reused_text(owner_user_id, place_id, post.body)
|
||||
except Exception:
|
||||
LOG.w(f"[blog] post={post_id} 쓰레드 연동 실패 — 미니블로그 승인은 유지")
|
||||
|
||||
async def _enqueue_build(self, post_id, place_id) -> None:
|
||||
"""게재 = 그 사이트 하나를 다시 굽는 것. 전체 재굽기가 아니다(docs/PUBLISH_VERSION.md).
|
||||
|
||||
|
||||
Reference in new issue
Block a user