forked from VallariAg/teuthology-api
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add presets routes, schema, model helper functions
creates the following: models/presets.py: create_preset, get_user_presets, get_preset routes/presets.py: GET /, GET list/, POST /add schemas/presets.py: PresetSchema Signed-off-by: Vallari Agrawal <[email protected]>
- Loading branch information
Showing
4 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from fastapi import APIRouter, HTTPException, Depends | ||
from models import get_db | ||
from models.presets import get_preset, get_user_presets, create_preset | ||
from schemas.presets import PresetSchema | ||
from sqlalchemy.orm import Session | ||
import logging | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
router = APIRouter( | ||
prefix="/presets", | ||
tags=["presets"], | ||
) | ||
|
||
@router.get("/", status_code=200) | ||
def read_preset(username: str, name: str, db: Session = Depends(get_db)): | ||
db_preset = get_preset(db, username, name) | ||
return db_preset | ||
|
||
@router.get("/list", status_code=200) | ||
def read_preset(username: str, db: Session = Depends(get_db)): | ||
db_presets = get_user_presets(db, username) | ||
return db_presets | ||
|
||
@router.post("/add", status_code=200, response_model=PresetSchema) | ||
def add_preset(preset: PresetSchema, db: Session = Depends(get_db)): | ||
db_preset = get_preset(db, username=preset.username, preset_name=preset.name) | ||
if db_preset: | ||
raise HTTPException(status_code=400, detail=f"Preset '{preset.name}' already exists.") | ||
return create_preset(db, preset) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from pydantic import BaseModel, Field | ||
from typing import Union | ||
|
||
|
||
class PresetSchema(BaseModel): | ||
# pylint: disable=too-few-public-methods | ||
""" | ||
Class for Base Args. | ||
""" | ||
username: Union[str, None] = Field(default=None) | ||
name: Union[str, None] = Field(default=None) | ||
suite: Union[str, None] = Field(default=None) | ||
cmd: Union[str, None] = Field(default=None) |