feat: 날씨각 백엔드 API (날씨·노을·지수·주말·계절·피드·로그인·반응)

- FastAPI + PostgreSQL + Redis, web·worker 분리, compose 에 backend·worker·postgres·redis 추가
- 기상청 단기·초단기·중기·특보, 에어코리아, Open-Meteo, TourAPI, 특일정보 연동 (첫 조회 때 받고 캐시)
- 매일 03:00 worker 가 전국 공통 피드 칸을 정하고 지난 데이터를 정리
- 시드: 시군구 256곳, 지수 23개, 노을 대표 지점·명소, 데이트 명소, 읽을거리
- pytest 66개 (테스트 전용 DB·Redis 사용)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
minaChoiandClaude Opus 5.5 committed 2026-10-02 11:32:22 +09:00
1 parent 9cdc0d8fea
commit e134295ce5
135 files changed
+9123

No files matched your search

View File
Whitespace-only changes.
+42
View File
@@ -0,0 +1,42 @@
from typing import Optional
from fastapi import APIRouter, Depends, Path, Query
from common.auth import optional_user
from common.database.model.models import User
from common.enums import ErrorType
from common.models.errors import error_info
from router.v1.feed.protocol import Res_Feed, Res_Post
from services.feed_service import FeedService
from services.reaction_service import ReactionService
router = APIRouter(prefix="/v1/feed", tags=["feed"])
@router.get("", response_model=Res_Feed, response_model_exclude_none=True, summary="메인 피드: 하늘 영역, 오늘의 각, 오늘 포스트 전부, 띠")
async def get_feed(
region: str = Query(..., description="구 행정코드"), user: Optional[User] = Depends(optional_user),
service: FeedService = Depends(), reactions: ReactionService = Depends(),
) -> Res_Feed:
err, feed = await service.feed(region)
if err is not ErrorType.SUCCESS:
return Res_Feed(result=error_info(err))
ids = [p.post_id for p in feed.posts]
counts = await reactions.counts(ids)
liked, saved = await reactions.marks(user, ids)
for p in feed.posts:
p.like_count, p.comment_count = counts.get(p.post_id, (p.like_count, p.comment_count))
if user is not None:
p.liked, p.saved = p.post_id in liked, p.post_id in saved
return feed
@router.get("/post/{post_id}", response_model=Res_Post, response_model_exclude_none=True, summary="포스트 하나 (공유 링크로 들어왔을 때)")
async def get_post(post_id: int = Path(...), region: str = Query(...), service: FeedService = Depends()) -> Res_Post:
err, feed = await service.feed(region)
if err is not ErrorType.SUCCESS:
return Res_Post(result=error_info(err))
post = next((p for p in feed.posts if p.post_id == post_id), None)
if post is None:
return Res_Post(result=error_info(ErrorType.NOT_FOUND))
return Res_Post(post=post)
+151
View File
@@ -0,0 +1,151 @@
from datetime import date, datetime
from typing import Annotated, Literal, Optional, Union
from pydantic import Field
from common.enums import PostType, SlotTone
from common.models.gmodel import Res_WebPacketProtocol, WebPacketProtocol
class Row(WebPacketProtocol):
label: str
value: str
class HourCell(WebPacketProtocol):
label: str
icon: str
temp_c: Optional[float] = None
tone: SlotTone
class HoursSlide(WebPacketProtocol):
kind: Literal["hours"]
eyebrow: str
line: str
hours: list[HourCell]
class RowsSlide(WebPacketProtocol):
"""우산·미세먼지·계절 소식·행사·상식처럼 '한 줄 + 표' 모양."""
kind: Literal["rows"]
eyebrow: str
line: str
icon: str
rows: list[Row] = []
class GakSlide(WebPacketProtocol):
kind: Literal["gak"]
index_id: int
code: str
name: str
rank: int
score: int
line: str
summary: str
class Cut(WebPacketProtocol):
at: datetime
kind: str
label: str
class SunsetSlide(WebPacketProtocol):
kind: Literal["sunset"]
eyebrow: str
line: str
score: int
grade_label: str
cuts: list[Cut]
class WeekDay(WebPacketProtocol):
day: date
weekday: str
icon: str
text: str
class WeekSlide(WebPacketProtocol):
kind: Literal["week"]
eyebrow: str
line: str
days: list[WeekDay]
Slide = Annotated[Union[HoursSlide, RowsSlide, GakSlide, SunsetSlide, WeekSlide], Field(discriminator="kind")]
class PostData(WebPacketProtocol):
post_id: int
post_type: PostType
title: str
icon: str
caption: str
slides: list[Slide]
share_messages: list[str] = []
like_count: int
comment_count: int
published_at: datetime
liked: Optional[bool] = None
saved: Optional[bool] = None
class TopIndex(WebPacketProtocol):
index_id: int
code: str
name: str
icon: str
score: int
rank: int
summary: Optional[str] = None
class Hero(WebPacketProtocol):
now_at: datetime
sky_mode: Literal["morning", "day", "sunset", "night"]
temp_c: Optional[float] = None
feels_c: Optional[float] = None
discomfort: Optional[int] = None
discomfort_label: Optional[str] = None
rain_2h_text: Optional[str] = None
will_rain_2h: Optional[bool] = None
weather_score: Optional[int] = None
top3: list[TopIndex] = []
bubble: Optional[str] = None
class BandEvent(WebPacketProtocol):
event_id: int
name: str
status_label: str
icon: str
class BandArticle(WebPacketProtocol):
article_id: int
title: str
meta: str
icon: str
class Bands(WebPacketProtocol):
events: list[BandEvent] = []
top5: list[TopIndex] = []
season: list[BandArticle] = []
class Res_Feed(Res_WebPacketProtocol):
region_code: Optional[str] = None
region_name: Optional[str] = None
hero: Optional[Hero] = None
stories: list[TopIndex] = []
posts: list[PostData] = []
bands: Optional[Bands] = None
class Res_Post(Res_WebPacketProtocol):
post: Optional[PostData] = None