Merge remote-tracking branch 'origin/dev' into sub_laptop_1
This commit is contained in:
@@ -269,10 +269,13 @@ async def _load(connection: Any, project_id: UUID) -> tuple[dict[str, Any] | Non
|
||||
return legacy, legacy is not None
|
||||
|
||||
|
||||
def _view(network: dict[str, Any] | None, legacy: bool, base: dict[str, Any]) -> dict[str, Any]:
|
||||
def _view(
|
||||
network: dict[str, Any] | None, legacy: bool, base: dict[str, Any], year_start: int | None
|
||||
) -> dict[str, Any]:
|
||||
return {
|
||||
"status": "success",
|
||||
"base": base,
|
||||
"year_start": year_start,
|
||||
"network": network,
|
||||
"derived": derive(network) if network else None,
|
||||
"legacy": legacy,
|
||||
@@ -284,8 +287,13 @@ async def get_plan_network(project_id: UUID) -> dict[str, Any]:
|
||||
base = await plan_base.load_base(project_id)
|
||||
async with get_db_pool().acquire() as connection:
|
||||
network, legacy = await _load(connection, project_id)
|
||||
async with connection.cursor(aiomysql.DictCursor) as cursor:
|
||||
await cursor.execute(
|
||||
"SELECT project_year FROM projects WHERE id = %s", (str(project_id),)
|
||||
)
|
||||
row = await cursor.fetchone()
|
||||
try:
|
||||
return _view(network, legacy, base)
|
||||
return _view(network, legacy, base, row["project_year"] if row else None)
|
||||
except NetworkError as error:
|
||||
raise HTTPException(status_code=409, detail=f"저장된 노선이 틀립니다 — {error}") from error
|
||||
|
||||
@@ -425,4 +433,4 @@ async def put_plan_network(
|
||||
except Exception:
|
||||
await connection.rollback()
|
||||
raise
|
||||
return {**_view(network, False, base), "derived": derived}
|
||||
return {**_view(network, False, base, project["project_year"]), "derived": derived}
|
||||
|
||||
@@ -214,12 +214,13 @@ def test_get_saved_legacy_or_empty(client) -> None:
|
||||
client.db.answers["FROM plan_networks"] = [{"network_json": json.dumps(_network())}]
|
||||
got = client.get(URL).json()
|
||||
assert got["legacy"] is False and len(got["derived"]["pieces"]) == 3
|
||||
assert got["base"]["end"] == {"x": 90.0, "y": 180.0}
|
||||
assert got["base"]["end"] == {"x": 90.0, "y": 180.0} and got["year_start"] == 2026
|
||||
|
||||
|
||||
def test_put_stores_network_pieces_years(client) -> None:
|
||||
got = client.put(URL, json=_network())
|
||||
assert got.status_code == 200 and got.json()["derived"]["pieces"][1]["from_m"] == 75.0
|
||||
assert got.json()["year_start"] == 2026
|
||||
log = client.db.log
|
||||
assert log[-1][0] == "COMMIT"
|
||||
pieces = [a for s, a in log if s.startswith("INSERT INTO plan_route_pieces")]
|
||||
|
||||
Reference in New Issue
Block a user