def delete_user(userid): """Delete a user""" udal = UserDAL(app.config['DB']) deletion = udal.delete(userid) if deletion: return '' else: return 'Not Found', status.HTTP_404_NOT_FOUND
def get_user(userid): """Get a user's details""" udal = UserDAL(app.config['DB']) user = udal.get(userid) if user: return json.dumps(user) else: return 'Not Found', status.HTTP_404_NOT_FOUND
def delete_group(group_name): """Delete a group""" gdal = UserDAL(app.config['DB']) deletion = gdal.delete(group_name) if deletion: return '' else: return 'Not Found', status.HTTP_404_NOT_FOUND
def update_user(): """Udate a user""" try: user = json.loads(request.data) except: return 'Bad Request', status.HTTP_400_BAD_REQUEST udal = UserDAL(app.config['DB']) try: udal.schema(user) except MultipleInvalid: return 'Bad Request', status.HTTP_400_BAD_REQUEST if udal.get(user['userid']): udal.save(user) return json.dumps(user) else: return 'Not Found', status.HTTP_404_NOT_FOUND
def create_user(): """Create a new user""" try: user = json.loads(request.data) except: return 'Bad Request', status.HTTP_400_BAD_REQUEST udal = UserDAL(app.config['DB']) try: udal.schema(user) except MultipleInvalid: return 'Bad Request', status.HTTP_400_BAD_REQUEST if udal.get(user['userid']): return 'Bad Request', status.HTTP_400_BAD_REQUEST udal.save(user) return json.dumps(user)