Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
WSL0809 committed May 27, 2024
1 parent ce2576f commit 177475a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions api/get_all_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ def get_clients(db: Session, name: Optional[str], page: int, limit: int):
COALESCE(json_agg(b.*) FILTER (WHERE b.baby_id IS NOT NULL), '[]') AS babies
FROM client c
LEFT JOIN baby b ON c.id = b.client_id
GROUP BY c.id
"""

# 动态构建 WHERE 子句
Expand All @@ -148,6 +147,7 @@ def get_clients(db: Session, name: Optional[str], page: int, limit: int):
final_query = f"""
{base_query}
{where_clause}
GROUP BY c.id
ORDER BY c.id
OFFSET :offset ROWS FETCH NEXT :limit ROWS ONLY
"""
Expand All @@ -156,7 +156,8 @@ def get_clients(db: Session, name: Optional[str], page: int, limit: int):
params = {'name': f'%{name}%', 'offset': (page - 1) * limit, 'limit': limit} if name else {
'offset': (page - 1) * limit, 'limit': limit}
clients = db.execute(text(final_query), params).fetchall()
total = db.execute(text(count_query), {'name': f'%{name}%'} if name else {}).scalar()
total_params = {'name': f'%{name}%'} if name else {}
total = db.execute(text(count_query), total_params).scalar()

return total, clients
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion api/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class AddRoomRecv(BaseModel):
room_number: str
notes: Union[str, None]
notes: Union[str, None] = None


class DeleteRoomRecv(BaseModel):
Expand Down

0 comments on commit 177475a

Please sign in to comment.