Skip to content

Commit

Permalink
chg: [APi] Added an endpoint to get a TimeStampToken by scan UUID.
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricbonhomme committed Dec 19, 2023
1 parent e760e10 commit 19a2915
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions api/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ def create_tst(db: Session, data: schemas.TimeStampTokenCreate):
return db_tst


def get_tst(db: Session, skip: int = 0, limit: int = 100):
"""Filter TimeStampToken with a query."""
def get_tst(db: Session, skip: int = 0, limit: int = 100, scan_uuid = ""):
"""Returns a list of TimeStampToken or filter TimeStampToken with the
UUID of a scan."""
if scan_uuid:
return db.query(models.TimeStampToken).filter(models.TimeStampToken.scan_uuid == scan_uuid).first()
return db.query(models.TimeStampToken).offset(skip).limit(limit).all()


Expand Down
10 changes: 9 additions & 1 deletion api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,21 @@ async def create_tst(


@app.get("/tsts/", response_model=list[schemas.TimeStampToken])
async def read_tst(
async def read_tsts(
skip: int = 0, limit: int = 100, db: Session = db_session
) -> list[schemas.TimeStampToken]:
tsts = crud.get_tst(db, skip=skip, limit=limit)
return tsts


@app.get("/tsts/{scan_uuid}", response_model=schemas.TimeStampToken)
def get_tst(scan_uuid = "", db: Session = db_session) -> schemas.TimeStampToken:
db_tst = crud.get_tst(db, scan_uuid=scan_uuid)
if db_tst is None:
raise HTTPException(status_code=404, detail="TimeStampToken not found")
return db_tst


#
# System
#
Expand Down

0 comments on commit 19a2915

Please sign in to comment.