Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions questionpy_sdk/webserver/routes/attempt.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def post(self) -> web.Response:

data = await self.request.json()
await self.controller.save_attempt(question_id, attempt_id, data)
return web.Response()
return self.json_success_response()

async def delete(self) -> web.Response:
"""Deletes the attempt from the state storage."""
Expand All @@ -59,7 +59,7 @@ async def delete(self) -> web.Response:
except webserver_errors.MissingAttemptStateError as err:
raise HTTPNotFound from err

return web.json_response()
return self.json_success_response()


@routes.view(f"/question/{{question_id:{ID_RE}}}/attempts", name="attempt.list")
Expand All @@ -82,7 +82,7 @@ async def post(self) -> web.Response:
await self.controller.score_attempt(question_id, attempt_id)
except webserver_errors.MissingStateError as err:
raise web.HTTPBadRequest(text=str(err)) from err
return web.Response()
return self.json_success_response()


@routes.view(
Expand All @@ -103,4 +103,4 @@ async def post(self) -> web.Response:
except webserver_errors.DuplicateAttemptError as err:
raise web.HTTPConflict(text=str(err)) from err

return web.Response()
return self.json_success_response()
4 changes: 4 additions & 0 deletions questionpy_sdk/webserver/routes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ def controller(self) -> CT:
def json_model_response(self, model: BaseModel, **kwargs: Any) -> web.Response:
"""Create JSON response from model using Pydantic's serializer."""
return web.json_response(text=model.model_dump_json(**kwargs))

def json_success_response(self, msg: str = "Success") -> web.Response:
"""Create JSON response signalling success."""
return web.json_response({"msg": msg})
8 changes: 4 additions & 4 deletions questionpy_sdk/webserver/routes/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def delete(self) -> web.Response:
except MissingQuestionStateError as err:
raise HTTPNotFound from err

return web.json_response()
return self.json_success_response()


@routes.view("/questions", name="question.list")
Expand All @@ -48,7 +48,7 @@ async def get(self) -> web.Response:
async def delete(self) -> web.Response:
"""Deletes all questions and its attempts from the state storage."""
await self.controller.delete_all_questions()
return web.json_response()
return self.json_success_response()


@routes.view(f"/question/{{question_id:{ID_RE}}}/state", name="question.state")
Expand All @@ -69,7 +69,7 @@ async def post(self) -> web.Response:
except OptionsFormValidationError as err:
return web.json_response(err.errors, status=HTTPUnprocessableEntity.status_code)

return web.json_response()
return self.json_success_response()


@routes.view(f"/question/{{question_id:{ID_RE}}}/clone/{{new_question_id:{ID_RE}}}", name="question.clone")
Expand All @@ -86,4 +86,4 @@ async def post(self) -> web.Response:
except DuplicateQuestionError as err:
raise web.HTTPConflict(text=str(err)) from err

return web.Response()
return self.json_success_response()