Routes (API)

src.core.routes.__init__.register_routes(app: Flask) None[source]

Register application blueprints.

This keeps route registration centralized and tidy.

Parameters:

app (Flask) – Flask instance

src.core.routes.docs.openapi_spec()[source]

Serve the OpenAPI specification as JSON.

Returns:

The OpenAPI document.

Return type:

JSON

src.core.routes.auth.login()[source]

Handles user login and generates JWT tokens.

Returns:

A JSON response containing access and refresh tokens.

Return type:

JSON

src.core.routes.auth.logout()[source]

Handles user logout and revokes the refresh token.

Returns:

A JSON response confirming successful logout.

Return type:

JSON

src.core.routes.auth.me()[source]

Handles user profile retrieval.

Returns:

A JSON response containing user profile information.

Return type:

JSON

src.core.routes.auth.refresh()[source]

Handles token refresh and generates a new access token.

Returns:

A JSON response containing a new access token.

Return type:

JSON

src.core.routes.anonymous.resolve_anonymous() tuple[dict, int][source]

Upload anonymous survey and its questions by token.

Query parameters: - token: str (required) - survey_id: int (optional)

Returns:

JSON response with survey_id, token_id, and questions, status code 200 on success

Return type:

tuple[dict, int]

src.core.routes.anonymous.submit_anonymous() tuple[dict, int][source]

Submit anonymous responses using a one-time survey token.

Body JSON: - token: str (required) - survey_id: int (optional, for extra validation) - responses: list[{question_id: int, answer: str}] (required)

Returns:

JSON response with saved_count, token_id, and survey_id, status code 201 on success

Return type:

tuple[dict, int]

src.core.routes.maintenance.cleanup_tokens() tuple[dict, int][source]

Clean up expired tokens.

Returns:

{“matched”: int, “deleted”: int}, status code 200

Return type:

tuple[dict, int]

src.core.routes.metrics.dashboard_metrics() tuple[dict, int][source]

Return aggregated metrics for the admin dashboard.

Returns:

Dictionary with keys: cards, charts.

Return type:

tuple[dict, int]

src.core.routes.questions.change_question_state(question_id: int) tuple[dict, int][source]

Change question state.

Parameters:

question_id (int) – Question ID.

Returns:

Serialized question with updated state and HTTP status code.

Return type:

tuple[dict, int]

src.core.routes.questions.create_question() tuple[dict, int][source]

Create a new question.

Returns:

Serialized question with created fields and HTTP status code.

Return type:

tuple[dict, int]

src.core.routes.questions.get_question(question_id: int) tuple[dict, int][source]

Get question by ID.

Parameters:

question_id (int) – Question ID.

Returns:

Serialized question and HTTP status code.

Return type:

tuple[dict, int]

src.core.routes.questions.list_questions() tuple[dict, int][source]

List questions.

Returns:

Serialized questions and HTTP status code.

Return type:

tuple[dict, int]

src.core.routes.questions.serialize_question(q: Question) dict[source]

Serialize a question.

Parameters:

q (Question) – Question instance.

Returns:

Serialized question.

Return type:

dict

src.core.routes.questions.update_question(question_id: int) tuple[dict, int][source]

Update question.

Parameters:

question_id (int) – Question ID.

Returns:

Serialized question with updated fields and HTTP status code.

Return type:

tuple[dict, int]

src.core.routes.reports.export_reports() tuple[str, int, dict][source]

Export survey or team summary as CSV.

Returns:

CSV content, status code, and headers.

Return type:

tuple[str, int, dict]

src.core.routes.reports.survey_summary(survey_id: int) tuple[dict, int][source]

Aggregate responses for a survey, optionally filtered by team and date range.

Parameters:

survey_id (int) – ID of the survey.

Returns:

Formatted summary and status code.

Return type:

tuple[dict, int]

src.core.routes.reports.team_summary(team_id: int) tuple[dict, int][source]

Aggregate responses for a team, optionally filtered by survey and date range.

Parameters:

team_id (int) – ID of the team.

Returns:

Formatted summary and status code.

Return type:

tuple[dict, int]

src.core.routes.surveys.change_survey_state(survey_id: int) tuple[dict, int][source]

Change survey state.

Parameters:

survey_id (int) – Survey ID.

Returns:

Serialized survey with updated state and HTTP status code.

Return type:

tuple[dict, int]

src.core.routes.surveys.create_survey() tuple[dict, int][source]

Create a new survey.

Returns:

Serialized survey and HTTP status code.

Return type:

tuple[dict, int]

src.core.routes.surveys.get_survey(survey_id: int) tuple[dict, int][source]

Get a survey.

Parameters:

survey_id (int) – Survey ID.

Returns:

Serialized survey and HTTP status code.

Return type:

tuple[dict, int]

src.core.routes.surveys.list_surveys() tuple[dict, int][source]

List surveys.

Returns:

Serialized surveys and HTTP status code.

Return type:

tuple[dict, int]

src.core.routes.surveys.serialize_survey(s: Survey) dict[source]

Serialize a survey.

Parameters:

s (Survey) – Survey instance.

Returns:

Serialized survey.

Return type:

dict

src.core.routes.surveys.update_survey(survey_id: int) tuple[dict, int][source]

Update survey.

Parameters:

survey_id (int) – Survey ID.

Returns:

Serialized survey with updated fields and HTTP status code.

Return type:

tuple[dict, int]

src.core.routes.teams.change_team_state(team_id: int) tuple[dict, int][source]

Change a team state.

Parameters:

team_id (int) – Team ID.

Returns:

Serialized team and HTTP status code.

Return type:

tuple[dict, int]

src.core.routes.teams.create_team() tuple[dict, int][source]

Create a team.

Returns:

Serialized team and HTTP status code.

Return type:

tuple[dict, int]

src.core.routes.teams.get_team(team_id: int) tuple[dict, int][source]

Get a team.

Parameters:

team_id (int) – Team ID.

Returns:

Serialized team and HTTP status code.

Return type:

tuple[dict, int]

src.core.routes.teams.list_teams() tuple[dict, int][source]

List teams.

Returns:

Serialized teams and HTTP status code.

Return type:

tuple[dict, int]

src.core.routes.teams.serialize_team(team: Team) dict[source]

Serialize a team.

Parameters:

team (Team) – Team instance.

Returns:

Serialized team.

Return type:

dict

src.core.routes.teams.update_team(team_id: int) tuple[dict, int][source]

Update a team.

Parameters:

team_id (int) – Team ID.

Returns:

Serialized team and HTTP status code.

Return type:

tuple[dict, int]

src.core.routes.tokens.export_tokens(survey_id: int) tuple[str, int, dict][source]

Export survey tokens to CSV.

Parameters:

survey_id (int) – Survey ID

Returns:

CSV content, status code, headers

Return type:

tuple[str, int, dict]

src.core.routes.tokens.generate_tokens(survey_id: int) tuple[list[dict], int][source]

Generate survey tokens.

Parameters:

survey_id (int) – Survey ID

Returns:

List of generated tokens, status code

Return type:

tuple[list[dict], int]

src.core.routes.tokens.list_tokens(survey_id: int) tuple[list[dict], int][source]

List survey tokens.

Parameters:

survey_id (int) – Survey ID

Returns:

List of tokens, status code

Return type:

tuple[list[dict], int]