Open Sanchay-T opened 5 months ago
nginx
and gunicorn
for load balancing and serving the endpoints. This will be connected to a MySQL
database for storing the data.instance
refers to a single survey or poll, or any other entity (election, form, audit etc.) managed by a creator. I will not enforce a specific entity type in the backend, but rather provide a generic structure that can be used for multiple types of entities. This will make the system highly configurable and extensible for future use cases. The specifications of the instance
are:
instance
will have its own set of rules and permissions, managed by the creator.instance
will be hosted on a separate URL, and will be accessible to the users via a unique link. Backend will identify the instance
based on the URL and who is accessing it (creator or user).instance
based on the rules and permissions set by the creator. They will be able to submit their responses, view the results, and interact with the instance
as per the creator's settings.instance
, including response rates, user demographics, question-wise responses, and other relevant data. The creator will be able to view these analytics in real-time and make informed decisions based on the data.config
as project root.flake8
lint and GitHub actions: Ensures code quality and consistency both locally and via checks.Note: This code can be found in config
project at project/config
flake8
lint ignored files : To not give lint errors when parsing config files/api/v1
{{base}}/auth/users/
: To create a user and send a verification email{{base}}/auth/users/resend_activation/
: To resend the activation email{{base}}/auth/users/activation/
: To activate the user{{base}}/auth/jwt/create
: To get the JWT token{{base}}/auth/jwt/refresh
: To refresh the JWT token{{base}}/auth/jwt/verify
: To verify the JWT token{{base}}/auth/status
: To check the status of the user (authenticated or not){{base}}/auth/users/
: To get the user details{{base}}/auth/users/me/
: To get, modify and delete the current user details{{base}}/auth/users/reset_password/
: To reset the password and send an email{{base}}/auth/users/reset_password_confirm/
: To confirm the password reset{{base}}/auth/users/reset_username/
: To reset the username and send an email{{base}}/auth/users/reset_username_confirm/
: To confirm the username resetNote: All of these endpoints and their corresponding functionalities can be found in core
app at project/core
.
Created the instance creation and management workflow, including the creation, update, delete, and listing of instances. Also mapped the creator to the instance and implemented the user permission workflow for all individual instances.
Following scenarios are taken care of:
Creator creates a instance (name
, description
) -> gets back all the details including the unique hash
.
Creator uses their JWT to access instance -> Middleware to check if the creator is accessing their instance or not.
Who can poll?
0x1 << 0, 'Open to All'
Everyone has access via link
0x1 << 1, 'Open within Ogranization'
Only OAuth users can vote
authorize
and callback
routes for OAuthSocialUser
model. Hence we know who voted.instance_auth_status
and accepts a JWT token for this scenario.
SocialUser
model (custom made tokens) as payload.0x1 << 2, 'Open to Specific Users
Only specific users can vote
instance_auth_status
and accepts a JWT token for this scenario.
SocialUser
model (custom made tokens) as payload./admin
route{{base}}/live/instance/
: To get and create a new instance.{{base}}/live/instance/<hash>/
: To get, update and delete the instance.{{base}}/live/instance/info
: To get the instance auth type and status for the instance based on the hash.{{base}}/live/<str:hash>/google-oauth2/?<redirect_uri>
: To authorize the user via Google OAuth for a specific instance.{{base}}/live/<str:hash>/google-oauth2/?state=<state>&code=<code>
: Callback route for Google OAuth to get the JWT token and register the user as a Social User for a specific instance.{{base}}/live/instance/ORG/<str:hash>/
: To get the list of Social ORG users for a specific instance.{{base}}/live/instance/ORG/<str:hash>/download?format=<csv/json>
: To download the list of users for a specific instance in JSON/CSV format.{{base}}/live/instance/CSV/<str:hash>/
: To upload a CSV file with the list of users for a specific instance.{{base}}/live/instance/JSON/<str:hash>/
: To upload a JSON file with the list of users for a specific instance.{{base}}/live/instance/CSV/<str:hash>/download
: To download the list of users for a specific instance in CSV format.{{base}}/live/instance/JSON/<str:hash>/download
: To download the list of users for a specific instance in JSON format.{{base}}/live/instance/(CSV/JSON)/<str:hash>/<str:username>
: To get, update and delete a specific user from the list for a specific instance.{{base}}/live/instance/<str:hash>/login
: To login a user via username and password for a specific instance.Note: All of these endpoints and their corresponding functionalities can be found in live
app at project/live
.
Provided configuration to support multiple types of databases (cloud/local) in the project. Some of them could be useful if we want live data analytics.
MySQL
, SQlite
and PostgreSQL
..env
file.Developed form creation and management workflow, including the creation, update, delete, and listing of forms. Also mapped the form to the instance (and hence, the creator) and implemented the user permission workflow for all individual forms. The creators can now create forms with multiple question types and options, and have CRUD operations for the same.
data
for form CRUD operations{{base}}/data/<hash>/form/
: To get and create a form mapped to a particular instance.{{base}}/data/<hash>/form/<formpk>
: To update and delete the form.{{base}}/data/<hash>/form/<formpk>/question/
: To get and create internal questions for a form.{{base}}/data/<hash>/form/<formpk>/question/<quespk>
: To update and delete the internal questions for a form.{{base}}/data/<hash>/voter/get-data?access={{social_token}}
: To allow all types of users to get form data.Below is the form structure:
{
"title": "General Survey ",
"createdAt": 1720720166108,
"fields": [
{
"title": "Enter your email",
"type": "short-text",
"required": true
},
{
"title": "Enter your name",
"required": true,
"type": "short-text"
},
{
"title": "Tell something about you",
"required": false,
"type": "long-text"
},
{
"title": "Enter your mobile no",
"required": false,
"type": "number"
},
{
"title": "You like cat?",
"required": true,
"options": [
"yes",
"no"
],
"type": "multioption-singleanswer"
},
{
"title": "Um can't decide",
"required": true,
"options": [
"you decide",
"opt a",
"none"
],
"type": "multioption-multianswer"
},
{
"title": "Upload an emoji",
"required": true,
"type": "file",
"accepted": [
"jpg",
"png"
]
}
],
"endMessage": "thanks for nothing",
}
The database internally breaks every form into skeleton
and fields
, each of them completely modular.
Note: All of these endpoints and their corresponding functionalities can be found in data
app at project/data
.
Open to All
, the user id is stored in the response and we can track who voted.
{{base}}/data/<hash>/voter/post-data?access={{social_token}}
: To allow all types of users to post form data.{{base}}/data/<hash>/responses
: To get all form responses.{{base}}/data/<hash>/responses/<id>
: To delete the specific response.Below is the form response structure:
{
"answers": [
{
"id": "16",
"value": "hackme@gmail.com"
},
{
"id": "17",
"value": "yea its password"
}
]
}
Note: For type 2 and 3 (when form is not open to all), we can also track who voted, there is a user field which is populated when any social user votes and their status turns to voted
. Also, the responses only support view and delete operations to stop any kind of tampering.
Note: All of these endpoints and their corresponding functionalities can be found in data
app at project/data
.
Worked on improving the OpenAPI documentation via configuration and adding more details. Now the documentation can serve as a guide for the users and developers to understand the API endpoints and their functionalities.
Raised a PR - #10 which adds the OpenAPI documentation for the APIs:
swagger
UI for the documentation<domain>:<port>/swagger
to access the documentation.openapi.yml
file into Swagger UI to access the documentation.Raised a PR - #11 which fixes a bug in the data
app. Now the instance/form only accepts responses when all the required fields are entered.
Worked on deploying the system on A2I servers using apache2
and mod_wsgi
Separately deployed the backend code on a standalone server.
Researched, fixed and suggested solution to the following bugs:
dotenv
package parsing error.header
containing auth token was not being processed.All the problems were resolved and the system was successfully deployed on the A2I servers.
pytest
.pytest.yml
to automate testing on GitHub.core
& config
applive
appdata
applive
, core
and data
app
Ticket Contents
Description
The Sp Polling Backend feature is aimed at enhancing the functionality of the Sp Polling application within the healthcare domain. This feature will streamline the authentication processes for both creators and users, introduce a forms builder, and establish critical endpoints necessary for the application's operation. The overall objective is to improve user experience and ensure secure, efficient data handling.
Goals & Mid-Point Milestone
Month 1:
Setup/Installation
No response
Expected Outcome
No response
Acceptance Criteria
No response
Implementation Details
Mockups/Wireframes
No response
Product Name
Sp Polling Backend
Organisation Name
a2i (aspire to innovate)
Domain
Healthcare
Tech Skills Needed
Django, Python, React
Mentor(s)
@Sanchay-T
Category
API