Skip to content

Commit 4bfb6d1

Browse files
committed
feat: Updated json encoder to be async
1 parent aefe669 commit 4bfb6d1

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

app/controllers/auth_controller.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def signup(request: Request, sign_up_request: SignUpRequest) -> JSONRespon
4848
if existing_user:
4949
return JSONResponse(
5050
status_code=status.HTTP_409_CONFLICT,
51-
content=json_encoder(
51+
content= await json_encoder(
5252
{
5353
"detail": "user_already_exists",
5454
}
@@ -60,7 +60,7 @@ async def signup(request: Request, sign_up_request: SignUpRequest) -> JSONRespon
6060
})
6161
return JSONResponse(
6262
status_code=status.HTTP_200_OK,
63-
content=json_encoder(
63+
content= await json_encoder(
6464
{
6565
"detail": "signup_success",
6666
}
@@ -81,7 +81,7 @@ async def login(request: Request, login_request: Annotated[LoginRequest, Body()]
8181
if user is None:
8282
return JSONResponse(
8383
status_code=status.HTTP_400_BAD_REQUEST,
84-
content=json_encoder(
84+
content= await json_encoder(
8585
{
8686
"detail": "user_no_exist",
8787
}
@@ -91,7 +91,7 @@ async def login(request: Request, login_request: Annotated[LoginRequest, Body()]
9191
if not await verify_password(login_request.password, hashed_pass):
9292
return JSONResponse(
9393
status_code=status.HTTP_400_BAD_REQUEST,
94-
content=json_encoder(
94+
content= await json_encoder(
9595
{
9696
"detail": "user_incorrect_password",
9797
}
@@ -102,7 +102,7 @@ async def login(request: Request, login_request: Annotated[LoginRequest, Body()]
102102
refresh_token = await create_refresh_token(user_id)
103103
response = JSONResponse(
104104
status_code=status.HTTP_200_OK,
105-
content=json_encoder({
105+
content= await json_encoder({
106106
"user_id": user_id,
107107
"detail": "login_success",
108108
}),
@@ -125,14 +125,14 @@ async def logout(request: Request) -> JSONResponse:
125125
if not refresh_token:
126126
return JSONResponse(
127127
status_code=status.HTTP_400_BAD_REQUEST,
128-
content=json_encoder({
128+
content= await json_encoder({
129129
"detail": "missing_refresh_token",
130130
}),
131131
)
132132
await create_revoked_token(refresh_token, await read_expiration_date(refresh_token))
133133
response = JSONResponse(
134134
status_code=status.HTTP_200_OK,
135-
content=json_encoder({
135+
content= await json_encoder({
136136
"detail": "logout_success",
137137
}),
138138
)
@@ -153,7 +153,7 @@ async def account_exists(request: Request, account_exists_request: AccountExists
153153
user = await read_user_by_email(account_exists_request.email)
154154
return JSONResponse(
155155
status_code=status.HTTP_200_OK,
156-
content=json_encoder(
156+
content= await json_encoder(
157157
{
158158
"user_exists": True if user else False,
159159
"detail": "account_exists_success",
@@ -176,7 +176,7 @@ async def change_password(request: Request, change_password_request: ChangePassw
176176
if user is None:
177177
return JSONResponse(
178178
status_code=status.HTTP_400_BAD_REQUEST,
179-
content=json_encoder(
179+
content= await json_encoder(
180180
{
181181
"detail": "user_no_exist",
182182
}
@@ -185,7 +185,7 @@ async def change_password(request: Request, change_password_request: ChangePassw
185185
if not await verify_password(change_password_request.old_password, user.password):
186186
return JSONResponse(
187187
status_code=status.HTTP_400_BAD_REQUEST,
188-
content=json_encoder(
188+
content= await json_encoder(
189189
{
190190
"detail": "user_invalid_old_password",
191191
}
@@ -196,7 +196,7 @@ async def change_password(request: Request, change_password_request: ChangePassw
196196
await update_user_password(user)
197197
return JSONResponse(
198198
status_code=status.HTTP_200_OK,
199-
content=json_encoder(
199+
content= await json_encoder(
200200
{
201201
"detail": "change_password_success",
202202
}
@@ -217,7 +217,7 @@ async def check_token(request: Request, verify_token_request: VerifyTokenRequest
217217
if not token:
218218
return JSONResponse(
219219
status_code=status.HTTP_400_BAD_REQUEST,
220-
content=json_encoder({
220+
content= await json_encoder({
221221
"valid": False,
222222
"detail": "token_missing",
223223
}),
@@ -226,7 +226,7 @@ async def check_token(request: Request, verify_token_request: VerifyTokenRequest
226226
payload = await verify_access_token(token)
227227
return JSONResponse(
228228
status_code=status.HTTP_200_OK,
229-
content=json_encoder({
229+
content= await json_encoder({
230230
"valid": True,
231231
"user_id": payload.get("user_id"),
232232
"detail": "token_verification_success",
@@ -235,23 +235,23 @@ async def check_token(request: Request, verify_token_request: VerifyTokenRequest
235235
except ExpiredSignatureError:
236236
return JSONResponse(
237237
status_code=status.HTTP_401_UNAUTHORIZED,
238-
content=json_encoder({
238+
content= await json_encoder({
239239
"valid": False,
240240
"detail": "token_expired",
241241
}),
242242
)
243243
except InvalidTokenError:
244244
return JSONResponse(
245245
status_code=status.HTTP_401_UNAUTHORIZED,
246-
content=json_encoder({
246+
content= await json_encoder({
247247
"valid": False,
248248
"detail": "token_invalid",
249249
}),
250250
)
251251
except Exception:
252252
return JSONResponse(
253253
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
254-
content=json_encoder({
254+
content= await json_encoder({
255255
"valid": False,
256256
"detail": "token_error",
257257
}),
@@ -271,14 +271,14 @@ async def refresh_token_endpoint(request: Request) -> JSONResponse:
271271
if not refresh_token:
272272
return JSONResponse(
273273
status_code=status.HTTP_400_BAD_REQUEST,
274-
content=json_encoder({
274+
content= await json_encoder({
275275
"detail": "missing_refresh_token",
276276
}),
277277
)
278278
if await is_token_revoked(refresh_token):
279279
return JSONResponse(
280280
status_code=status.HTTP_401_UNAUTHORIZED,
281-
content=json_encoder({
281+
content= await json_encoder({
282282
"detail": "token_revoked",
283283
}),
284284
)
@@ -287,7 +287,7 @@ async def refresh_token_endpoint(request: Request) -> JSONResponse:
287287
new_access_token = await create_access_token(payload["user_id"])
288288
response = JSONResponse(
289289
status_code=status.HTTP_200_OK,
290-
content=json_encoder({
290+
content= await json_encoder({
291291
"detail": "refresh_token_success",
292292
}),
293293
)
@@ -303,21 +303,21 @@ async def refresh_token_endpoint(request: Request) -> JSONResponse:
303303
except ExpiredSignatureError:
304304
return JSONResponse(
305305
status_code=status.HTTP_401_UNAUTHORIZED,
306-
content=json_encoder({
306+
content= await json_encoder({
307307
"detail": "token_expired",
308308
}),
309309
)
310310
except InvalidTokenError:
311311
return JSONResponse(
312312
status_code=status.HTTP_401_UNAUTHORIZED,
313-
content=json_encoder({
313+
content= await json_encoder({
314314
"detail": "token_invalid",
315315
}),
316316
)
317317
except Exception:
318318
return JSONResponse(
319319
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
320-
content=json_encoder({
320+
content= await json_encoder({
321321
"detail": "token_error",
322322
}),
323323
)

app/controllers/health_controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
tags=["Secure Chain Auth Health"]
1515
)
1616
@limiter.limit("25/minute")
17-
def health_check(request: Request) -> JSONResponse:
17+
async def health_check(request: Request) -> JSONResponse:
1818
return JSONResponse(
19-
status_code=status.HTTP_200_OK, content=json_encoder(
19+
status_code=status.HTTP_200_OK, content= await json_encoder(
2020
{
2121
"detail": "healthy",
2222
}

app/utils/json_encoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ def default(self, o: Any) -> Any:
1414
return JSONEncoder.default(self, o)
1515

1616

17-
def json_encoder(raw_response: dict[str, Any]) -> Any:
17+
async def json_encoder(raw_response: dict[str, Any]) -> Any:
1818
return loads(JSONencoder().encode(raw_response))

0 commit comments

Comments
 (0)