Skip to content
Snippets Groups Projects
Commit 5ebb7620 authored by Sabine Schröder's avatar Sabine Schröder
Browse files

#3: now nested human readable download is established for timeseries; TBD: do...

#3: now nested human readable download is established for timeseries; TBD: do this for all other modesl
parent a26adfd2
No related branches found
No related tags found
No related merge requests found
Pipeline #39739 passed
......@@ -235,8 +235,8 @@ class StationmetaGlobalService(StationmetaGlobalServiceBase):
class StationmetaRoleBase(BaseModel):
id: int = None
role: int
status: int
role: str
status: str
person_id: int
......
......@@ -7,6 +7,8 @@ from fastapi import APIRouter, Depends, HTTPException, Body
from sqlalchemy.orm import Session
from . import crud, schemas
from toardb.utils.database import ToarDbSession, get_db
from toardb.generic.models import RC_enum, RS_enum
from toardb.utils.utils import get_str_from_value
router = APIRouter()
......@@ -15,8 +17,15 @@ router = APIRouter()
#get all entries of table timeseries
@router.get('/timeseries/', response_model=List[schemas.Timeseries])
def get_all_timeseries(skip: int = 0, limit: int = None, db: Session = Depends(get_db)):
timeseries = crud.get_all_timeseries(db, skip=skip, limit=limit)
return timeseries
db_timeseries = crud.get_all_timeseries(db, skip=skip, limit=limit)
for timeseries in db_timeseries:
if timeseries.roles:
for r in timeseries.roles:
# Attention! Do not change the same object twice!
if type(r.role) is int:
r.role = get_str_from_value(db,RC_enum,r.role)
r.status = get_str_from_value(db, RS_enum, r.status)
return db_timeseries
#get all metadata of one timeseries
@router.get('/timeseries/{timeseries_id}', response_model=schemas.Timeseries)
......@@ -24,6 +33,10 @@ def get_timeseries(timeseries_id: int, db: Session = Depends(get_db)):
db_timeseries = crud.get_timeseries(db, timeseries_id=timeseries_id)
if db_timeseries is None:
raise HTTPException(status_code=404, detail="Timeseries not found.")
if db_timeseries.roles:
for r in db_timeseries.roles:
r.role = get_str_from_value(db,RC_enum,r.role)
r.status = get_str_from_value(db, RS_enum, r.status)
return db_timeseries
#some more gets to be tested:
......@@ -37,5 +50,10 @@ def create_timeseries(timeseries: schemas.TimeseriesCreate = Body(..., embed = T
variable_id=timeseries.variable_id, label=timeseries.label)
if db_timeseries:
raise HTTPException(status_code=400, detail="Timeseries already registered.")
return crud.create_timeseries(db=db, timeseries=timeseries)
db_timeseries=crud.create_timeseries(db=db, timeseries=timeseries)
if db_timeseries.roles:
for r in db_timeseries.roles:
r.role = get_str_from_value(db,RC_enum,r.role)
r.status = get_str_from_value(db, RS_enum, r.status)
return db_timeseries
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment