init
This commit is contained in:
43
app/api/form.py
Normal file
43
app/api/form.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 form_crud
|
||||
from app.schemas import Form, FormCreate, FormUpdate
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.put("/{item_id}", response_model=Form)
|
||||
def update_form(item_id: int, form_in: FormUpdate, db: Session = Depends(get_db)):
|
||||
form_db = form_crud.form.get(db, item_id)
|
||||
if not form_db:
|
||||
raise HTTPException(status_code=404, detail="Form not found")
|
||||
return form_crud.form.update(db=db, db_obj=form_db, obj_in=form_in)
|
||||
|
||||
|
||||
@router.delete("/{item_id}")
|
||||
def delete_form(item_id: int, db: Session = Depends(get_db)):
|
||||
form_db = form_crud.form.get(db, item_id)
|
||||
if not form_db:
|
||||
raise HTTPException(status_code=404, detail="Form not found")
|
||||
return form_crud.form.remove(db=db, id=item_id)
|
||||
|
||||
|
||||
@router.get("/{item_id}", response_model=Form)
|
||||
def read_form(item_id: int, db: Session = Depends(get_db)):
|
||||
return form_crud.form.get(db, item_id)
|
||||
|
||||
|
||||
@router.post("/", response_model=Form)
|
||||
def create_form(form_in: FormCreate, db: Session = Depends(get_db)):
|
||||
form_db = form_crud.form.create(db=db, obj_in=form_in)
|
||||
return form_db
|
||||
|
||||
|
||||
@router.get("/", response_model=list[Form])
|
||||
def read_forms(db: Session = Depends(get_db), skip: int = 0, limit: int = 100):
|
||||
return form_crud.form.get_multi(db, skip=skip, limit=limit)
|
||||
Reference in New Issue
Block a user