Skip to content

Commit

Permalink
added limit param
Browse files Browse the repository at this point in the history
  • Loading branch information
feijooso committed Jan 29, 2024
1 parent 93b1082 commit 9409646
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/controller/device_plant_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ def get_device_plant_relation(req: Request, id_plant: str):


@withSQLExceptionsHandle
def get_all_device_plant_relations(req: Request):
return req.app.database.find_all()
def get_all_device_plant_relations(req: Request, limit: int):
return req.app.database.find_all(limit)
5 changes: 2 additions & 3 deletions app/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


class SQLAlchemyClient():

db_url = engine.URL.create(
"postgresql",
database=environ["POSTGRES_DB"],
Expand Down Expand Up @@ -54,8 +53,8 @@ def find_by_plant_id(self, id_plant: str) -> DevicePlant:
result = self.session.scalars(query).one()
return result

def find_all(self) -> List[DevicePlant]:
query = select(DevicePlant).limit(10)
def find_all(self, limit: int) -> List[DevicePlant]:
query = select(DevicePlant).limit(limit)
result = self.session.scalars(query)
return result

Expand Down
4 changes: 2 additions & 2 deletions app/router/device_plant_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def update_all_in_device_plant(id_device: str,
status_code=status.HTTP_200_OK,
response_model=List[DevicePlantSchema]
)
async def get_device_plant(req: Request, id_plant: str = Query(None)):
async def get_device_plant(req: Request, id_plant: str = Query(None), limit: int = Query(10)):
if id_plant is None:
return controller.get_all_device_plant_relations(req)
return controller.get_all_device_plant_relations(req, limit)
return [controller.get_device_plant_relation(req, id_plant)]

0 comments on commit 9409646

Please sign in to comment.