feat: 카드 해시태그(hashtags) — 인스타 캡션 뒤에만 붙고 날씨각 피드에는 안 나감
This commit is contained in:
1 parent
a630faea4c
commit
14ca71a41c
5 files changed
+7
-4
No files matched your search
@@ -323,6 +323,7 @@ class CardSet(Base):
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
published_at: Mapped[Optional[datetime]] = mapped_column(DateTime(timezone=True), nullable=True)
|
||||
ig_media_id: Mapped[Optional[str]] = mapped_column(String(40), nullable=True)
|
||||
hashtags: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
|
||||
|
||||
class CardImage(Base):
|
||||
|
||||
@@ -196,6 +196,7 @@ CREATE TABLE IF NOT EXISTS public.card_set (
|
||||
published_at TIMESTAMPTZ NULL
|
||||
);
|
||||
ALTER TABLE public.card_set ADD COLUMN IF NOT EXISTS ig_media_id VARCHAR(40) NULL; -- 인스타에 올렸으면 그 미디어 id
|
||||
ALTER TABLE public.card_set ADD COLUMN IF NOT EXISTS hashtags TEXT NULL; -- 인스타 캡션 뒤에만 붙는 해시태그
|
||||
CREATE TABLE IF NOT EXISTS public.card_image (
|
||||
card_id BIGINT NOT NULL REFERENCES public.card_set (card_id) ON DELETE CASCADE,
|
||||
seq SMALLINT NOT NULL, -- 1부터, 슬라이드 순서
|
||||
|
||||
@@ -82,7 +82,7 @@ async def list_cards(limit: int = Query(50, ge=1, le=200)) -> Res_CardList:
|
||||
@router.post("", response_model=Res_Card, response_model_exclude_none=True, summary="카드뉴스 저장 (관리자). publish 면 바로 그날 피드에 올린다", dependencies=[Depends(require_admin)])
|
||||
async def create_card(req: Req_CardCreate) -> Res_Card:
|
||||
images = _jpegs(req.images)
|
||||
card = CardSet(template=req.template, topic=req.topic, title=req.title, caption=req.caption, copy=req.texts, status=CardStatus.WAITING.value)
|
||||
card = CardSet(template=req.template, topic=req.topic, title=req.title, caption=req.caption, hashtags=req.hashtags.strip() or None, copy=req.texts, status=CardStatus.WAITING.value)
|
||||
err, card = await DB_SESSION_MNG.execute_lambda_write(lambda s: _crud.create(s, card, images))
|
||||
if err is not ErrorType.SUCCESS:
|
||||
return Res_Card(result=error_info(err))
|
||||
@@ -129,7 +129,7 @@ async def publish_instagram(card_id: int = Path(...)) -> Res_Card:
|
||||
return Res_Card(card_id=card.card_id, status=CardStatus(card.status), post_id=card.post_id, ig_media_id=card.ig_media_id)
|
||||
_, counts = await DB_SESSION_MNG.execute_lambda(lambda s: _crud.image_counts(s, [card_id]))
|
||||
urls = [instagram.public_image_url(image_url(card_id, i)) for i in range(1, (counts or {}).get(card_id, 0) + 1)]
|
||||
caption = f"{card.title}\n\n{card.caption}".strip()
|
||||
caption = "\n\n".join(part for part in (card.title, card.caption, card.hashtags) if part)
|
||||
try:
|
||||
media_id = await instagram.publish_carousel(urls, caption)
|
||||
except instagram.InstagramError as e:
|
||||
|
||||
@@ -12,6 +12,7 @@ class Req_CardCreate(WebPacketProtocol):
|
||||
topic: Optional[str] = Field(default=None, max_length=60)
|
||||
title: str = Field(max_length=80, description="피드 포스트 제목")
|
||||
caption: str = Field(default="", max_length=2000)
|
||||
hashtags: str = Field(default="", max_length=600, description="인스타 캡션 뒤에만 붙는 해시태그. 날씨각 피드에는 안 나간다")
|
||||
texts: dict = Field(default_factory=dict, description="카드 문구 (다시 그릴 때 쓴다)")
|
||||
images: list[str] = Field(min_length=1, max_length=20, description="1080×1350 JPEG, base64. 슬라이드 순서대로")
|
||||
publish: bool = Field(default=False, description="true 면 만들자마자 그날 피드에 올린다. false 면 승인 대기")
|
||||
|
||||
@@ -112,7 +112,7 @@ async def test_instagram_publish_carousel_and_store_media_id(offline, admin_key,
|
||||
assert data["access_token"] == "tok"
|
||||
if request.url.path.endswith("/1789/media"):
|
||||
if data.get("media_type") == "CAROUSEL":
|
||||
assert data["children"] == "c1,c2,c3" and data["caption"].startswith("오늘의 썸 타로")
|
||||
assert data["children"] == "c1,c2,c3" and data["caption"] == "오늘의 썸 타로\n\n한 장 골라 보세요\n\n#날씨각 #날씨타로"
|
||||
return httpx.Response(200, json={"id": "car"})
|
||||
assert data["image_url"].startswith("https://weather.example/v1/card/") and data["is_carousel_item"] == "true"
|
||||
return httpx.Response(200, json={"id": f"c{len([c for c in calls if 'is_carousel_item' in c[1]])}"})
|
||||
@@ -126,7 +126,7 @@ async def test_instagram_publish_carousel_and_store_media_id(offline, admin_key,
|
||||
real = httpx.AsyncClient
|
||||
monkeypatch.setattr(instagram.httpx, "AsyncClient", lambda **kw: real(transport=httpx.MockTransport(handler)))
|
||||
async with client() as c:
|
||||
made = (await c.post("/v1/card", json=body(publish=True), headers=admin_key)).json()
|
||||
made = (await c.post("/v1/card", json=body(publish=True, hashtags="#날씨각 #날씨타로"), headers=admin_key)).json()
|
||||
res = (await c.post(f"/v1/card/{made['card_id']}/instagram", headers=admin_key)).json()
|
||||
again = (await c.post(f"/v1/card/{made['card_id']}/instagram", headers=admin_key)).json()
|
||||
listed = (await c.get("/v1/card", headers=admin_key)).json()["items"][0]
|
||||
|
||||
Reference in new issue
Block a user