This commit is contained in:
admin
2026-01-22 22:37:02 +09:00
parent 50e534094d
commit 1868591704
4 changed files with 28 additions and 9 deletions

View File

@@ -2,7 +2,7 @@ from dotenv import load_dotenv
load_dotenv()
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from fastapi.responses import JSONResponse, RedirectResponse
from pydantic import ValidationError
from fastapi.middleware.cors import CORSMiddleware
@@ -32,9 +32,9 @@ async def validation_exception_handler(request: Request, exc: ValidationError):
# ─────────────────────────
# ルート(稼働確認)
# ─────────────────────────
@app.get("/", include_in_schema=False)
def root():
return RedirectResponse(url="/index.html")
#@app.get("/", include_in_schema=False)
#def root():
# return RedirectResponse(url="/index.html")
# ─────────────────────────
# ルーター登録(※ 必ず app 定義の後)
@@ -124,10 +124,18 @@ app.mount(
# )
# フロントエンドファイル配信
frontend_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "frontend")
if os.path.exists(frontend_path):
from fastapi.staticfiles import StaticFiles
from pathlib import Path
# フロントエンド配信(/app/frontend
BASE_DIR = Path(__file__).resolve().parent.parent # /app
frontend_path = BASE_DIR / "frontend"
print("Frontend path =", frontend_path)
if frontend_path.exists():
app.mount(
"/frontend",
"/",
StaticFiles(directory=frontend_path, html=True),
name="frontend",
)

View File

@@ -204,6 +204,15 @@ def create_insurance_rate(rate: schemas.InsuranceRateCreate):
"""保険料率を作成"""
with get_connection() as conn:
with conn.cursor() as cur:
# 既存の同キーrate_year, rate_type, calculation_target, prefectureが存在しないか確認
cur.execute(
"SELECT 1 FROM insurance_rates WHERE rate_year = %s AND rate_type = %s AND calculation_target = %s AND prefecture = %s LIMIT 1",
(rate.rate_year, rate.rate_type, rate.calculation_target, rate.prefecture)
)
if cur.fetchone():
# 重複があればクライアントに分かりやすく 409 を返す
raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail="指定された年度・種類・計算対象・都道府県の保険料率は既に存在します")
cur.execute(
"""
INSERT INTO insurance_rates (