feat: 계절 이야기에 사진 연결 (띠·목록·상세·피드, CC BY 계열 출처 표기)
This commit is contained in:
1 parent
e8382f450b
commit
ba62e82f1b
15 files changed
+77
-21
No files matched your search
@@ -280,6 +280,8 @@ class Article(Base):
|
||||
show_from: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
|
||||
show_until: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
|
||||
sort_order: Mapped[int] = mapped_column(SmallInteger, default=0)
|
||||
image_url: Mapped[Optional[str]] = mapped_column(String(200), nullable=True)
|
||||
image_credit: Mapped[Optional[str]] = mapped_column(String(60), nullable=True)
|
||||
|
||||
|
||||
class Post(Base):
|
||||
|
||||
@@ -374,5 +374,9 @@ CREATE TABLE IF NOT EXISTS public.article (
|
||||
body JSONB NOT NULL, -- 문단 목록
|
||||
show_from DATE NULL, -- 계절 소식이 보이는 기간 (NULL = 늘)
|
||||
show_until DATE NULL,
|
||||
sort_order SMALLINT NOT NULL DEFAULT 0
|
||||
sort_order SMALLINT NOT NULL DEFAULT 0,
|
||||
image_url VARCHAR(200) NULL, -- 사진 (frontend/public/season/, NULL = 아이콘)
|
||||
image_credit VARCHAR(60) NULL -- 사진 출처 표기 ("ⓒ저작자 · CC BY-SA 4.0"), 표기가 필요 없으면 NULL
|
||||
);
|
||||
ALTER TABLE public.article ADD COLUMN IF NOT EXISTS image_url VARCHAR(200) NULL;
|
||||
ALTER TABLE public.article ADD COLUMN IF NOT EXISTS image_credit VARCHAR(60) NULL;
|
||||
@@ -171,6 +171,8 @@ class BandArticle(WebPacketProtocol):
|
||||
title: str
|
||||
meta: str
|
||||
icon: str
|
||||
image: Optional[str] = None
|
||||
image_credit: Optional[str] = None
|
||||
|
||||
|
||||
class Bands(WebPacketProtocol):
|
||||
|
||||
@@ -17,6 +17,8 @@ class ArticleSummary(WebPacketProtocol):
|
||||
title: str
|
||||
read_minutes: int
|
||||
icon: str
|
||||
image: Optional[str] = None # 있으면 아이콘 대신 사진
|
||||
image_credit: Optional[str] = None # 사진 출처 표기 ("ⓒ저작자 · CC BY-SA 4.0")
|
||||
|
||||
|
||||
class Res_SeasonWeek(Res_WebPacketProtocol):
|
||||
|
||||
@@ -12,7 +12,8 @@ router = APIRouter(prefix="/v1/season", tags=["season"])
|
||||
|
||||
|
||||
def _summary(a: Article) -> ArticleSummary:
|
||||
return ArticleSummary(article_id=a.article_id, code=a.code, category=ArticleCategory(a.category), title=a.title, read_minutes=a.read_minutes, icon=a.icon)
|
||||
return ArticleSummary(article_id=a.article_id, code=a.code, category=ArticleCategory(a.category), title=a.title, read_minutes=a.read_minutes, icon=a.icon,
|
||||
image=a.image_url, image_credit=a.image_credit)
|
||||
|
||||
|
||||
@router.get("/week", response_model=Res_SeasonWeek, response_model_exclude_none=True, summary="이번 주 계절 책: 시, 절기, 계절 소식")
|
||||
|
||||
@@ -70,7 +70,8 @@ async def main() -> int:
|
||||
]
|
||||
articles = [
|
||||
{**a, "show_from": date.fromisoformat(a["show_from"]) if a["show_from"] else None,
|
||||
"show_until": date.fromisoformat(a["show_until"]) if a["show_until"] else None}
|
||||
"show_until": date.fromisoformat(a["show_until"]) if a["show_until"] else None,
|
||||
"image_url": a.get("image_url"), "image_credit": a.get("image_credit")}
|
||||
for a in _json("article.json")
|
||||
]
|
||||
weeks = _json("season_week.json")
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
"title": "설악산 첫 단풍, 절정은 언제?",
|
||||
"read_minutes": 3,
|
||||
"icon": "maple",
|
||||
"image_url": "/season/maple.jpg",
|
||||
"image_credit": "ⓒJoycekim77 · CC BY-SA 3.0",
|
||||
"show_from": "2026-09-20",
|
||||
"show_until": "2026-10-25",
|
||||
"body": [
|
||||
@@ -20,6 +22,8 @@
|
||||
"title": "하늘공원 억새가 반짝이는 시간",
|
||||
"read_minutes": 2,
|
||||
"icon": "sheaf",
|
||||
"image_url": "/season/reed.jpg",
|
||||
"image_credit": "ⓒJocelyndurrey · CC BY-SA 4.0",
|
||||
"show_from": "2026-09-25",
|
||||
"show_until": "2026-10-31",
|
||||
"body": [
|
||||
@@ -34,6 +38,8 @@
|
||||
"title": "대관령 첫서리, 서울은 한 달 뒤",
|
||||
"read_minutes": 2,
|
||||
"icon": "snow",
|
||||
"image_url": "/season/frost.jpg",
|
||||
"image_credit": "ⓒSally V · CC BY-SA 4.0",
|
||||
"show_from": "2026-10-01",
|
||||
"show_until": "2026-11-15",
|
||||
"body": [
|
||||
@@ -77,6 +83,7 @@
|
||||
"title": "노을은 왜 해 지고 15분 뒤가 더 붉을까?",
|
||||
"read_minutes": 3,
|
||||
"icon": "sunset",
|
||||
"image_url": "/season/sunset.jpg",
|
||||
"show_from": null,
|
||||
"show_until": null,
|
||||
"body": [
|
||||
@@ -91,6 +98,7 @@
|
||||
"title": "비 확률 30%면 우산을 챙겨야 할까?",
|
||||
"read_minutes": 2,
|
||||
"icon": "umbrella",
|
||||
"image_url": "/season/umbrella.jpg",
|
||||
"show_from": null,
|
||||
"show_until": null,
|
||||
"body": [
|
||||
@@ -251,6 +259,7 @@
|
||||
"title": "햇밤, 바로 먹을까 두었다 먹을까?",
|
||||
"read_minutes": 2,
|
||||
"icon": "chestnut",
|
||||
"image_url": "/season/chestnut_new.jpg",
|
||||
"show_from": "2026-09-15",
|
||||
"show_until": "2026-10-31",
|
||||
"body": [
|
||||
@@ -281,6 +290,8 @@
|
||||
"title": "은행 냄새 나는 길, 언제까지일까",
|
||||
"read_minutes": 2,
|
||||
"icon": "fallen_leaf",
|
||||
"image_url": "/season/ginkgo.jpg",
|
||||
"image_credit": "ⓒKorea.net · CC BY-SA 2.0",
|
||||
"show_from": "2026-10-10",
|
||||
"show_until": "2026-11-15",
|
||||
"body": [
|
||||
@@ -296,6 +307,8 @@
|
||||
"title": "군고구마가 생각나는 첫 추위",
|
||||
"read_minutes": 2,
|
||||
"icon": "sweet_potato",
|
||||
"image_url": "/season/sweet_potato.jpg",
|
||||
"image_credit": "ⓒ국립국어원 · CC BY-SA 2.0 KR",
|
||||
"show_from": "2026-10-15",
|
||||
"show_until": "2026-12-31",
|
||||
"body": [
|
||||
@@ -311,6 +324,7 @@
|
||||
"title": "노지 귤이 나오기 시작해요",
|
||||
"read_minutes": 2,
|
||||
"icon": "tangerine",
|
||||
"image_url": "/season/tangerine.jpg",
|
||||
"show_from": "2026-10-20",
|
||||
"show_until": "2026-12-31",
|
||||
"body": [
|
||||
@@ -326,6 +340,8 @@
|
||||
"title": "부사 사과가 나오는 때",
|
||||
"read_minutes": 2,
|
||||
"icon": "apple",
|
||||
"image_url": "/season/apple_fuji.jpg",
|
||||
"image_credit": "ⓒAomorikuma · CC BY-SA 4.0",
|
||||
"show_from": "2026-10-20",
|
||||
"show_until": "2026-11-30",
|
||||
"body": [
|
||||
@@ -341,6 +357,7 @@
|
||||
"title": "김장, 언제 하면 좋을까?",
|
||||
"read_minutes": 2,
|
||||
"icon": "kimchi",
|
||||
"image_url": "/season/kimjang.jpg",
|
||||
"show_from": "2026-11-01",
|
||||
"show_until": "2026-12-15",
|
||||
"body": [
|
||||
|
||||
@@ -362,7 +362,8 @@ class FeedService:
|
||||
image=e.event.image_url, image_credit=image_credit(e.event)) for e in mix_kinds(events)[:4]],
|
||||
top5=[_top(i) for i in items[:5]],
|
||||
season=[
|
||||
BandArticle(article_id=a.article_id, title=a.title, meta=f"{_CATEGORY_META[a.category]} · {a.read_minutes}분", icon=a.icon)
|
||||
BandArticle(article_id=a.article_id, title=a.title, meta=f"{_CATEGORY_META[a.category]} · {a.read_minutes}분", icon=a.icon,
|
||||
image=a.image_url, image_credit=a.image_credit)
|
||||
for a in articles or [] if a.category == ArticleCategory.SEASON.value
|
||||
],
|
||||
),
|
||||
@@ -450,7 +451,8 @@ class FeedService:
|
||||
if t in (PostType.SEASON, PostType.TIP) and p.ref_id in c.articles:
|
||||
a = c.articles[p.ref_id]
|
||||
return PostData(**base, title=a.title, icon=a.icon, caption=" ".join(a.body[1:2]) or a.body[0],
|
||||
slides=[RowsSlide(kind="rows", eyebrow=_CATEGORY_META[a.category], line=a.body[0], icon=a.icon)], share_messages=[a.title])
|
||||
slides=[RowsSlide(kind="rows", eyebrow=_CATEGORY_META[a.category], line=a.body[0], icon=a.icon, image=a.image_url, image_credit=a.image_credit)],
|
||||
share_messages=[a.title])
|
||||
if t is PostType.EVENT:
|
||||
soon = mix_kinds([e for e in c.events if e.event.start_date <= c.now.date() + timedelta(days=7) and e.event.end_date >= c.now.date()])
|
||||
rank = p.index_rank or 1
|
||||
|
||||
@@ -2,8 +2,10 @@ from datetime import timedelta
|
||||
|
||||
import pytest
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
from sqlalchemy import text
|
||||
|
||||
import services.season_service as season_service
|
||||
from common.database.db_session_manager import DB_SESSION_MNG
|
||||
from common.utils.kma_time import now_kst
|
||||
from router.router import app
|
||||
|
||||
@@ -38,3 +40,15 @@ async def test_article_detail_and_not_found():
|
||||
missing = (await client.get("/v1/season/article/9999")).json()
|
||||
assert first["body"] and first["article"]["title"] == listed[0]["title"]
|
||||
assert missing["result"]["desc"] == "NOT_FOUND"
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_article_photo_only_when_seeded():
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
listed = {a["code"]: a for a in (await client.get("/v1/season/article/list")).json()["articles"]}
|
||||
umbrella = (await client.get(f"/v1/season/article/{listed['umbrella']['article_id']}")).json()["article"]
|
||||
_, maple_id = await DB_SESSION_MNG.execute_lambda(lambda s: s.scalar(text("SELECT article_id FROM article WHERE code = 'maple'")))
|
||||
maple = (await client.get(f"/v1/season/article/{maple_id}")).json()["article"]
|
||||
assert umbrella["image"] == "/season/umbrella.jpg" and "image_credit" not in umbrella
|
||||
assert maple["image"] == "/season/maple.jpg" and maple["image_credit"] == "ⓒJoycekim77 · CC BY-SA 3.0"
|
||||
assert "image" not in listed["howgak"] and "image" not in listed["di"]
|
||||
Reference in new issue
Block a user