Skip to content

Commit

Permalink
Remove async def
Browse files Browse the repository at this point in the history
  • Loading branch information
angely-dev committed Feb 23, 2024
1 parent e5278bb commit e28df60
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,52 +36,52 @@ def read_root():
return {'Welcome!': f'API docs is available at {API_URL}/docs'}

@router.get('/nas', tags=['nas'], status_code=200, response_model=List[str])
async def get_nas(response: Response, from_nasname: str = None):
def get_nas(response: Response, from_nasname: str = None):
nasnames = nas_repo.find_nasnames(from_nasname)
if nasnames:
last_nasname = nasnames[-1]
response.headers['Link'] = f'<{API_URL}/nas?from_nasname={last_nasname}>; rel="next"'
return nasnames

@router.get('/users', tags=['users'], status_code=200, response_model=List[str])
async def get_users(response: Response, from_username: str = None):
def get_users(response: Response, from_username: str = None):
usernames = user_repo.find_usernames(from_username)
if usernames:
last_username = usernames[-1]
response.headers['Link'] = f'<{API_URL}/users?from_username={last_username}>; rel="next"'
return usernames

@router.get('/groups', tags=['groups'], status_code=200, response_model=List[str])
async def get_groups(response: Response, from_groupname: str = None):
def get_groups(response: Response, from_groupname: str = None):
groupnames = group_repo.find_groupnames(from_groupname)
if groupnames:
last_groupname = groupnames[-1]
response.headers['Link'] = f'<{API_URL}/groups?from_groupname={last_groupname}>; rel="next"'
return groupnames

@router.get('/nas/{nasname}', tags=['nas'], status_code=200, response_model=Nas, responses={**e404_response})
async def get_nas(nasname: str):
def get_nas(nasname: str):
nas = nas_repo.find_one(nasname)
if not nas:
raise HTTPException(404, 'Given NAS does not exist')
return nas

@router.get('/users/{username}', tags=['users'], status_code=200, response_model=User, responses={**e404_response})
async def get_user(username: str):
def get_user(username: str):
user = user_repo.find_one(username)
if not user:
raise HTTPException(404, 'Given user does not exist')
return user

@router.get('/groups/{groupname}', tags=['groups'], status_code=200, response_model=Group, responses={**e404_response})
async def get_group(groupname: str):
def get_group(groupname: str):
group = group_repo.find_one(groupname)
if not group:
raise HTTPException(404, 'Given group does not exist')
return group

@router.post('/nas', tags=['nas'], status_code=201, response_model=Nas, responses={**e409_response})
async def post_nas(nas: Nas, response: Response):
def post_nas(nas: Nas, response: Response):
if nas_repo.exists(nas.nasname):
raise HTTPException(409, 'Given NAS already exists')

Expand All @@ -90,7 +90,7 @@ async def post_nas(nas: Nas, response: Response):
return nas

@router.post('/users', tags=['users'], status_code=201, response_model=User, responses={**e409_response})
async def post_user(user: User, response: Response):
def post_user(user: User, response: Response):
if user_repo.exists(user.username):
raise HTTPException(409, 'Given user already exists')

Expand All @@ -103,7 +103,7 @@ async def post_user(user: User, response: Response):
return user

@router.post('/groups', tags=['groups'], status_code=201, response_model=Group, responses={**e409_response})
async def post_group(group: Group, response: Response):
def post_group(group: Group, response: Response):
if group_repo.exists(group.groupname):
raise HTTPException(409, 'Given group already exists')

Expand All @@ -116,21 +116,21 @@ async def post_group(group: Group, response: Response):
return group

@router.delete('/nas/{nasname}', tags=['nas'], status_code=204, responses={**e404_response})
async def delete_nas(nasname: str):
def delete_nas(nasname: str):
if not nas_repo.exists(nasname):
raise HTTPException(404, 'Given NAS does not exist')

nas_repo.remove(nasname)

@router.delete('/users/{username}', tags=['users'], status_code=204, responses={**e404_response})
async def delete_user(username: str):
def delete_user(username: str):
if not user_repo.exists(username):
raise HTTPException(404, detail='Given user does not exist')

user_repo.remove(username)

@router.delete('/groups/{groupname}', tags=['groups'], status_code=204, responses={**e404_response})
async def delete_group(groupname: str, ignore_users: bool = False):
def delete_group(groupname: str, ignore_users: bool = False):
if not group_repo.exists(groupname):
raise HTTPException(404, 'Given group does not exist')

Expand Down

0 comments on commit e28df60

Please sign in to comment.