Commit 112dc71c authored by Nicolas Schmid's avatar Nicolas Schmid
Browse files

feat: add starttime filter to /project

parent 23daf469
......@@ -8,8 +8,13 @@ from ramsis.datamodel import SeismicityModelRun, Status, \
ForecastScenario, Project
def get_projects(db: Session) -> List[Project]:
def get_projects(
db: Session,
starttime: Optional[datetime] = None,
) -> List[Project]:
statement = select(Project)
if starttime:
statement = statement.filter(Project.starttime > starttime)
result = db.execute(statement).unique().all()
return [r[0] for r in result]
......
from datetime import datetime
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from typing import List
from typing import List, Optional
from ramsis_fastapi.schemas import ForecastSchema, InjectionWellSchema, \
ProjectSchema, SeismicCatalogSchema
......@@ -14,12 +15,12 @@ router = APIRouter(prefix='/project', tags=['project'])
@router.get("/",
response_model=List[ProjectSchema],
response_model_exclude_none=False)
async def read_projects(db: Session = Depends(get_db)):
async def read_projects(starttime: Optional[datetime] = None,
db: Session = Depends(get_db)):
"""
Returns a list of projects.
"""
db_result = crud.get_projects(db)
db_result = crud.get_projects(db, starttime)
if not db_result:
raise HTTPException(status_code=404, detail="No projects found.")
return db_result
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment