Skip to content

Commit

Permalink
Tc
Browse files Browse the repository at this point in the history
  • Loading branch information
msune committed Jun 12, 2024
1 parent 5eb2dcd commit 9e9391f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/routes/turnilo_dashboard_routes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from fastapi import APIRouter, Depends, HTTPException, Query
from typing import List
from sqlalchemy.orm import Session
from sqlmodel import Session
from models.turnilo_dashboard import TurniloDashboard
from services import turnilo_dashboards as td

Expand Down
16 changes: 9 additions & 7 deletions src/services/turnilo_dashboards.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import List
from sqlalchemy.orm import Session
from sqlmodel import Session, select
from sqlalchemy import exc
from models.turnilo_dashboard import TurniloDashboard
from fastapi import HTTPException
Expand All @@ -8,12 +8,12 @@


def dashboards_get_all(session: Session, shortName: str, dataCube: str) -> List[TurniloDashboard]:
query = session.query(TurniloDashboard)
statement = select(TurniloDashboard)
if shortName:
query = query.filter(TurniloDashboard.shortName == shortName)
statement = statement.where(TurniloDashboard.shortName == shortName)
if dataCube:
query = query.filter(TurniloDashboard.dataCube == dataCube)
return query.all()
statement = statement.where(TurniloDashboard.dataCube == dataCube)
return list(session.exec(statement).all())


def _dashboards_return_single_obj(results: List[TurniloDashboard]):
Expand All @@ -25,7 +25,8 @@ def _dashboards_return_single_obj(results: List[TurniloDashboard]):


def dashboards_get_id(session: Session, _id: int) -> TurniloDashboard:
results: List[TurniloDashboard] = session.query(TurniloDashboard).filter_by(id=_id).all()
statement = select(TurniloDashboard).where(TurniloDashboard.id == _id)
results: List[TurniloDashboard] = list(session.exec(statement).all())
return _dashboards_return_single_obj(results)


Expand Down Expand Up @@ -67,7 +68,8 @@ def dashboards_update(session: Session, dashboard: TurniloDashboard) -> TurniloD
def dashboards_delete(session: Session, _id: int) -> TurniloDashboard:
dashboard = None
try:
dashboard = session.query(TurniloDashboard).filter_by(id=_id).one()
statement = select(TurniloDashboard).where(TurniloDashboard.id == _id)
dashboard = session.exec(statement).one()
except BaseException:
pass
if dashboard is None:
Expand Down

0 comments on commit 9e9391f

Please sign in to comment.