init
This commit is contained in:
43
app/api/result.py
Normal file
43
app/api/result.py
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db.base import get_db
|
||||
from app.crud import result_crud
|
||||
from app.schemas import Result, ResultCreate, ResultUpdate
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.put("/{item_id}", response_model=Result)
|
||||
def update_result(item_id: int, result_in: ResultUpdate, db: Session = Depends(get_db)):
|
||||
result_db = result_crud.result.get(db, item_id)
|
||||
if not result_db:
|
||||
raise HTTPException(status_code=404, detail="Result not found")
|
||||
return result_crud.result.update(db=db, db_obj=result_db, obj_in=result_in)
|
||||
|
||||
|
||||
@router.delete("/{item_id}")
|
||||
def delete_result(item_id: int, db: Session = Depends(get_db)):
|
||||
result_db = result_crud.result.get(db, item_id)
|
||||
if not result_db:
|
||||
raise HTTPException(status_code=404, detail="Result not found")
|
||||
return result_crud.result.remove(db=db, id=item_id)
|
||||
|
||||
|
||||
@router.get("/{item_id}", response_model=Result)
|
||||
def read_result(item_id: int, db: Session = Depends(get_db)):
|
||||
return result_crud.result.get(db, item_id)
|
||||
|
||||
|
||||
@router.post("/", response_model=Result)
|
||||
def create_result(result_in: ResultCreate, db: Session = Depends(get_db)):
|
||||
result_db = result_crud.result.create(db=db, obj_in=result_in)
|
||||
return result_db
|
||||
|
||||
|
||||
@router.get("/", response_model=list[Result])
|
||||
def read_results(db: Session = Depends(get_db), skip: int = 0, limit: int = 100):
|
||||
return result_crud.result.get_multi(db, skip=skip, limit=limit)
|
||||
Reference in New Issue
Block a user