Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from fastapi import APIRouter, Depends, HTTPException, status
import crud
import schemas
from database import get_db
from models import Session
from routes.decorators import require_admin
studiesRouter = APIRouter(prefix="/studies", tags=["Studies"])
@require_admin("You do not have permission to create a study.")
@studiesRouter.post("", status_code=status.HTTP_201_CREATED)
def create_study(
study: schemas.StudyCreate,
db: Session = Depends(get_db),
):
return crud.create_study(db, study).id
@studiesRouter.get("", response_model=list[schemas.Study])
def get_studies(
skip: int = 0,
db: Session = Depends(get_db),
):
return crud.get_studies(db, skip)
@studiesRouter.get("/{study_id}", response_model=schemas.Study)
def get_study(
study_id: int,
db: Session = Depends(get_db),
):
study = crud.get_study(db, study_id)
if study is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="Study not found"
)
return study
@require_admin("You do not have permission to patch a study.")
@studiesRouter.patch("/{study_id}", status_code=status.HTTP_204_NO_CONTENT)
def update_study(
study_id: int,
study: schemas.StudyCreate,
db: Session = Depends(get_db),
):
return crud.update_study(db, study, study_id)
@require_admin("You do not have permission to delete a study.")
@studiesRouter.delete("/{study_id}", status_code=status.HTTP_204_NO_CONTENT)
def delete_study(
study_id: int,
db: Session = Depends(get_db),
):
return crud.delete_study(db, study_id)
@require_admin("You do not have permission to download this study.")
@studiesRouter.get("/{study_id}/download/surveys")
def download_study(
study_id: int,
db: Session = Depends(get_db),
):
study = crud.get_study(db, study_id)
if study is None:
raise HTTPException(status_code=404, detail="Study not found")
return crud.download_study(db, study_id)
@require_admin("You do not have permission to download this study.")
@studiesRouter.get("/{study_id}/download/surveys-wide")
study_id: int,
db: Session = Depends(get_db),
):
study = crud.get_study(db, study_id)
if study is None:
raise HTTPException(status_code=404, detail="Study not found")
return crud.download_study_wide(db, study_id)
@studiesRouter.post("/{study_id}/info", status_code=status.HTTP_201_CREATED)
def create_study_info(
study_id: int,
study_info: schemas.StudyInfoCreate,
db: Session = Depends(get_db),
):
return crud.create_study_info(db, study_id, study_info)