feat: 오늘 탭 아이콘 줄 — 오늘 타로·오늘 코디는 창으로, 단풍 지도·쇼츠·동네 이야기는 페이지로, 내 각은 그 줄로
- 오늘 한 장 칸을 오늘 타로 창으로 옮김. 안 뽑았으면 빨간 점, 뽑았으면 n일째 (로그인 안 하면 기기 기록으로 계산) - 오늘 코디: 오늘 피드에 올린 코디 카드를 창으로 (GET /v1/card/latest?template=ootd), 오늘 처음 보면 빨간 점 - 단풍 지도 아이콘은 단풍철에만, 아이콘 4개 추가 (Fluent 3D) - GA4 today_icon
This commit is contained in:
1 parent
c37773f48f
commit
045d8d6cf0
20 files changed
+347
-70
No files matched your search
@@ -26,6 +26,13 @@ class CardCRUD:
|
||||
"""만든 순서 역순. 올린 것·승인 대기·반려 모두."""
|
||||
return list((await s.scalars(select(CardSet).order_by(CardSet.card_id.desc()).limit(limit))).all())
|
||||
|
||||
async def latest_published(self, s: AsyncSession, template: str) -> Optional[CardSet]:
|
||||
"""그 틀로 가장 최근에 피드에 올린 카드뉴스"""
|
||||
return await s.scalar(
|
||||
select(CardSet).where(CardSet.template == template, CardSet.status == CardStatus.PUBLISHED.value, CardSet.post_id.is_not(None))
|
||||
.order_by(CardSet.published_at.desc()).limit(1)
|
||||
)
|
||||
|
||||
async def many(self, s: AsyncSession, card_ids: list[int]) -> list[CardSet]:
|
||||
if not card_ids:
|
||||
return []
|
||||
|
||||
@@ -14,7 +14,7 @@ from common.models.errors import error_info
|
||||
from common.utils.kma_time import KST, kst_midnight, now_kst
|
||||
from crud.card_crud import CardCRUD
|
||||
from crud.feed_crud import FeedCRUD
|
||||
from router.v1.card.protocol import CardItem, Req_CardCreate, Res_Card, Res_CardList
|
||||
from router.v1.card.protocol import CardItem, Req_CardCreate, Res_Card, Res_CardList, Res_LatestCard
|
||||
from services.bot_comment import fill_bot_comments
|
||||
from services.external import instagram
|
||||
from services.feed_service import _FEED_DAY_START, clear_feed_cache, feed_day
|
||||
@@ -82,6 +82,16 @@ async def list_cards(limit: int = Query(50, ge=1, le=200)) -> Res_CardList:
|
||||
])
|
||||
|
||||
|
||||
@router.get("/latest", response_model=Res_LatestCard, response_model_exclude_none=True, summary="그 틀로 가장 최근에 피드에 올린 카드뉴스의 포스트 (오늘 탭 '오늘 코디' 아이콘)")
|
||||
async def latest_card(template: str = Query(..., pattern=r"^[a-z_]{1,20}$")) -> Res_LatestCard:
|
||||
err, card = await DB_SESSION_MNG.execute_lambda(lambda s: _crud.latest_published(s, template))
|
||||
if err is not ErrorType.SUCCESS:
|
||||
return Res_LatestCard(result=error_info(err))
|
||||
if card is None:
|
||||
return Res_LatestCard()
|
||||
return Res_LatestCard(post_id=card.post_id, published_at=card.published_at.astimezone(KST) if card.published_at else None)
|
||||
|
||||
|
||||
@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)
|
||||
|
||||
@@ -18,6 +18,11 @@ class Req_CardCreate(WebPacketProtocol):
|
||||
publish: bool = Field(default=False, description="true 면 만들자마자 그날 피드에 올린다. false 면 승인 대기")
|
||||
|
||||
|
||||
class Res_LatestCard(Res_WebPacketProtocol):
|
||||
post_id: Optional[int] = None
|
||||
published_at: Optional[datetime] = None
|
||||
|
||||
|
||||
class Res_Card(Res_WebPacketProtocol):
|
||||
card_id: Optional[int] = None
|
||||
status: Optional[CardStatus] = None
|
||||
|
||||
@@ -142,3 +142,16 @@ async def test_instagram_requires_token(offline, admin_key, monkeypatch):
|
||||
made = (await c.post("/v1/card", json=body(), headers=admin_key)).json()
|
||||
res = (await c.post(f"/v1/card/{made['card_id']}/instagram", headers=admin_key)).json()
|
||||
assert res["result"]["success"] is False and "INSTAGRAM" in res["msg"]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_latest_card_by_template_is_public(offline, admin_key):
|
||||
async with client() as c:
|
||||
assert "post_id" not in (await c.get("/v1/card/latest", params={"template": "ootd"})).json()
|
||||
ootd = (await c.post("/v1/card", json=body(template="ootd", title="오늘 코디", publish=True), headers=admin_key)).json()
|
||||
await c.post("/v1/card", json=body(template="ootd", title="승인 대기 코디"), headers=admin_key)
|
||||
await c.post("/v1/card", json=body(publish=True), headers=admin_key)
|
||||
# 그 틀로 피드에 올린 것 중 가장 최근 (승인 대기·다른 틀은 빼고)
|
||||
latest = (await c.get("/v1/card/latest", params={"template": "ootd"})).json()
|
||||
assert latest["post_id"] == ootd["post_id"] and latest["published_at"]
|
||||
assert (await c.get("/v1/card/latest", params={"template": "../x"})).status_code == 422
|
||||
Reference in new issue
Block a user