update
This commit is contained in:
parent
74e18eda89
commit
ab57d868b6
@ -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,
|
||||
|
||||
BIN
jobs.sqlite
BIN
jobs.sqlite
Binary file not shown.
Loading…
Reference in New Issue
Block a user