~busykoala/pwned_api

394790ae7ed40109d9a5d0292db427f8eba1f43a — Matthias Osswald 2 years ago c9acb81
Improve output and replace double ticks.
1 files changed, 7 insertions(+), 6 deletions(-)

M app/routes.py
M app/routes.py => app/routes.py +7 -6
@@ 34,7 34,8 @@ async def fetch_pw(password: str) -> Dict[str, Any]:
    await conn.close()

    if not results:
        return {}
        return {'hash': password_hash,
                'occurences': 0}

    return dict(results[0])



@@ 49,22 50,22 @@ def handle_json_error(
            raise
        except Exception as ex:
            return web.json_response(
                {"status": "failed", "reason": str(ex)}, status=400
                {'status': 'failed', 'reason': str(ex)}, status=400
            )

    return handler


@router.get("/")
@router.get('/')
@handle_json_error
async def index(request: web.Request) -> web.Response:
    return web.json_response({"status": 200})
    return web.json_response({'status': 200})


@router.get("/api/{password}")
@router.get('/api/{password}')
@handle_json_error
async def api_get_post(request: web.Request) -> web.Response:
    password = request.match_info["password"]
    password = request.match_info['password']
    db_ret = await fetch_pw(password)
    return web.json_response(
        {'status': 'ok', 'password': password, 'data': db_ret})