refactor: a couple of renames + use async where sensible

This commit is contained in:
surtur 2020-08-07 02:52:11 +02:00
parent 5c010a60b6
commit 5c8af2930b
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D

@ -40,7 +40,7 @@ def get_srv(service_id: int, db: Session):
@app.get("/api/v1/ping") @app.get("/api/v1/ping")
def pong(): async def pong():
return {"ping": "pong!"} return {"ping": "pong!"}
@app.get("/api/v1/service") @app.get("/api/v1/service")
@ -52,14 +52,14 @@ async def create_service(service: schemas.ServiceCreate, db: Session = Depends(g
return crud.create_service(db=db, service=service) return crud.create_service(db=db, service=service)
@app.get("/api/v1/service/{service_id}", response_model=schemas.Service) @app.get("/api/v1/service/{service_id}", response_model=schemas.Service)
def read_user(service_id: int, db: Session = Depends(get_db)): async def read_service(service_id: int, db: Session = Depends(get_db)):
db_service = get_srv(service_id, db) db_service = get_srv(service_id, db)
if db_service is None: if db_service is None:
raise HTTPException(status_code=404, detail="User not found") raise HTTPException(status_code=404, detail="User not found")
return db_service return db_service
@app.put("/api/v1/service/{service_id}") @app.put("/api/v1/service/{service_id}")
async def update_user(service_id: int, service: schemas.ServiceUpdate, db: Session = Depends(get_db)): async def update_service(service_id: int, service: schemas.ServiceUpdate, db: Session = Depends(get_db)):
if ((service.name is None) and (service.owner_id is None) and (service.is_private is None) and (service.description is None) and (service.service_type is None) and (service.url is None) and (service.is_active is None)): if ((service.name is None) and (service.owner_id is None) and (service.is_private is None) and (service.description is None) and (service.service_type is None) and (service.url is None) and (service.is_active is None)):
raise HTTPException(status_code=400, detail="No data provided") raise HTTPException(status_code=400, detail="No data provided")
db_service = get_srv(service_id, db) db_service = get_srv(service_id, db)
@ -69,7 +69,7 @@ async def update_user(service_id: int, service: schemas.ServiceUpdate, db: Sessi
return {"update":"success"} return {"update":"success"}
@app.delete("/api/v1/service/{service_id}") @app.delete("/api/v1/service/{service_id}")
async def del_user(service_id: int, db: Session = Depends(get_db)): async def delete_service(service_id: int, db: Session = Depends(get_db)):
db_service = get_srv(service_id, db) db_service = get_srv(service_id, db)
if db_service is None: if db_service is None:
raise HTTPException(status_code=422, detail="Unprocessable entity") raise HTTPException(status_code=422, detail="Unprocessable entity")
@ -90,7 +90,7 @@ async def read_users(skip: int = 0, limit: int = 100, db: Session = Depends(get_
return crud.get_users(db=db, skip=skip, limit=limit) return crud.get_users(db=db, skip=skip, limit=limit)
@app.get("/api/v1/users/{user_id}", response_model=schemas.User) @app.get("/api/v1/users/{user_id}", response_model=schemas.User)
def read_user(user_id: int, db: Session = Depends(get_db)): async def read_user(user_id: int, db: Session = Depends(get_db)):
db_user = get_usr(user_id, db) db_user = get_usr(user_id, db)
if db_user is None: if db_user is None:
raise HTTPException(status_code=404, detail="User not found") raise HTTPException(status_code=404, detail="User not found")
@ -107,7 +107,7 @@ async def update_user(user_id: int, user: schemas.UserUpdate, db: Session = Depe
return {"update":"success"} return {"update":"success"}
@app.delete("/api/v1/users/{user_id}") @app.delete("/api/v1/users/{user_id}")
async def del_user(user_id: int, db: Session = Depends(get_db)): async def delete_user(user_id: int, db: Session = Depends(get_db)):
db_user = read_usr(user_id, db) db_user = read_usr(user_id, db)
if db_user is None: if db_user is None:
raise HTTPException(status_code=422, detail="Unprocessable entity") raise HTTPException(status_code=422, detail="Unprocessable entity")