From 383f48c71e4f11075543cfb0eae98b1d955fdec2 Mon Sep 17 00:00:00 2001 From: gahusb Date: Fri, 22 May 2026 01:40:44 +0900 Subject: [PATCH] =?UTF-8?q?feat(stock):=20GET=20/api/stock/holidays=20endp?= =?UTF-8?q?oint=20(SP-10=20task-watcher=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit holidays.json(list) 노출. task-watcher가 휴장일 판정에 조회. 인증 불필요. 주말은 task-watcher가 weekday로 별도 판정. Plan-B-Infra Phase 1. Co-Authored-By: Claude Opus 4.7 (1M context) --- stock/app/main.py | 11 +++++++++++ stock/app/test_holidays_endpoint.py | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 stock/app/test_holidays_endpoint.py diff --git a/stock/app/main.py b/stock/app/main.py index 3aab854..572e8bc 100644 --- a/stock/app/main.py +++ b/stock/app/main.py @@ -162,6 +162,17 @@ def get_indices(): """주요 지표(KOSPI 등) 실시간 크롤링 조회""" return fetch_major_indices() +@app.get("/api/stock/holidays") +def get_holidays(): + """task-watcher가 조회하는 휴장일 목록. holidays.json(list) 노출 (인증 불필요).""" + try: + with open(_HOLIDAYS_PATH, encoding="utf-8") as f: + data = json.load(f) + holidays = data if isinstance(data, list) else [] + except (OSError, ValueError): + holidays = [] + return {"holidays": holidays} + @app.post("/api/stock/scrap") def trigger_scrap(): """수동 스크랩 트리거""" diff --git a/stock/app/test_holidays_endpoint.py b/stock/app/test_holidays_endpoint.py new file mode 100644 index 0000000..f8baa76 --- /dev/null +++ b/stock/app/test_holidays_endpoint.py @@ -0,0 +1,22 @@ +"""GET /api/stock/holidays — task-watcher 휴장일 조회용.""" +from fastapi.testclient import TestClient +from app.main import app + +client = TestClient(app) + + +def test_holidays_returns_list(): + r = client.get("/api/stock/holidays") + assert r.status_code == 200 + data = r.json() + assert "holidays" in data + assert isinstance(data["holidays"], list) + + +def test_holidays_entries_are_iso_dates(): + r = client.get("/api/stock/holidays") + holidays = r.json()["holidays"] + if holidays: + import datetime as dt + for h in holidays[:5]: + dt.date.fromisoformat(h) # raise 안 하면 통과