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 8d2b5fc..62d79cb 100644 Binary files a/jobs.sqlite and b/jobs.sqlite differ