first commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"""API 路由:账户"""
|
||||
|
||||
from typing import List
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.database import get_db
|
||||
from app import crud, schemas
|
||||
|
||||
router = APIRouter(prefix="/api/accounts", tags=["账户"])
|
||||
|
||||
|
||||
@router.get("", response_model=List[schemas.AccountOut])
|
||||
def list_accounts(db: Session = Depends(get_db)):
|
||||
return crud.get_accounts(db)
|
||||
|
||||
|
||||
@router.post("", response_model=schemas.AccountOut, status_code=201)
|
||||
def create_account(data: schemas.AccountCreate, db: Session = Depends(get_db)):
|
||||
return crud.create_account(db, data)
|
||||
|
||||
|
||||
@router.put("/{account_id}", response_model=schemas.AccountOut)
|
||||
def update_account(account_id: int, data: schemas.AccountUpdate, db: Session = Depends(get_db)):
|
||||
obj = crud.update_account(db, account_id, data)
|
||||
if not obj:
|
||||
raise HTTPException(404, "账户不存在")
|
||||
return obj
|
||||
|
||||
|
||||
@router.delete("/{account_id}")
|
||||
def delete_account(account_id: int, db: Session = Depends(get_db)):
|
||||
if not crud.delete_account(db, account_id):
|
||||
raise HTTPException(404, "账户不存在")
|
||||
return {"ok": True}
|
||||
Reference in New Issue
Block a user