From ab57d868b62fd410e2233b2e46aeb57290359162 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Fri, 14 Mar 2025 22:53:59 +0800 Subject: [PATCH] update --- app/api/endpoints/station.py | 25 +++++++++++++++++++++++++ jobs.sqlite | Bin 24576 -> 24576 bytes 2 files changed, 25 insertions(+) diff --git a/app/api/endpoints/station.py b/app/api/endpoints/station.py index 331cd2c..db543ef 100644 --- a/app/api/endpoints/station.py +++ b/app/api/endpoints/station.py @@ -23,6 +23,31 @@ async def create_station( db.refresh(db_station) return success_response(data=StationInfo.model_validate(db_station)) + +@router.get("/group_by_community", response_model=ResponseModel) +async def get_stations_group_by_community( + community_id: Optional[int] = None, + db: Session = Depends(get_db) +): + """获取驿站列表,按社区分组""" + stations = db.query(StationDB, CommunityDB.name.label('community_name')).join(CommunityDB, StationDB.community_id == CommunityDB.id) + if community_id: + stations = stations.filter(StationDB.community_id == community_id) + stations = stations.all() + + # 按社区分组 + grouped_results = {} + for station, community_name in stations: + if station.community_id not in grouped_results: + grouped_results[station.community_id] = { + "community_id": station.community_id, + "community_name": community_name, + "stations": [] + } + grouped_results[station.community_id]["stations"].append({"station_id": station.id, "station_name": station.name}) + + return success_response(data=list(grouped_results.values())) + @router.get("", response_model=ResponseModel) async def get_stations( community_id: Optional[int] = None, diff --git a/jobs.sqlite b/jobs.sqlite index 8d2b5fcd841fd1f0e91d7a97c6bf53a8b1f6bac8..62d79cb1fb7c51f3b3ed89f5a8a9471ec95ae263 100644 GIT binary patch delta 19 acmZoTz}Rqrae_2s?L--8#@dYu3*rGsy9X)& delta 19 acmZoTz}Rqrae_2s{zMsP#{7*53*rGr=?4w~