This repository contains my solution to the problem of creating variable risk types for the BriteCore Engineering Code Challenge. The app itself is live and can be accessed from the urls in the tl;dr
- This file
- Links to the live app are Listed Here
- Model file can be found here
- The entity diagram can be found here, and here
- Backend Api link is shown here
- Can be checked here
- Live UI app is linked here along with the details to log in and test
- Same as above
- If you are reading this then you've made it to the github repo, lol. But here is the link anyway
- Quiz file is here
- And finally Live app is here and user guide can be found here
- Sent
The following link points to the app's frontend. The frontend is hosted on one of my linodes and accesses the backend server which runs on Amazon Lambda.
I originally wrote the UI using Angular because that was the framework I was most comfortable with. However after finishing, I decided to see what I could learn about Vue.js because it was mentioned as an option in the requirement document.
One thing led to another, and I now have the UI written in Vue.js as well. The link above leads to the Vue.js version of the app.
I removed the older angular app because It was no longer needed and was a hustle to maintain. So now we only have the Vue app. The old code still lives if you roll back to (a89bc7b23fd819d096acde780843e3ee94278975)
The Api can be accessed at
The Solution comes in two parts, the first is the backend API written in Django using the Rest Framework. The second is the UI written in Angular Communication between the two is in json, and there is currently basic JWT token authentication in place.
The server provides a JSON API that allows one to manipulate RiskTypes. Sample JSON structures for this api can be found here along with a few python scripts that make calls to the api
Before any calls are made to the api though you need to get authenticate and receive a JWT Token which you will use for all other communication.
Endpoint | Description |
---|---|
api-token-auth/ | Authentication Endpoint, Post to this endpoint to get the access token. |
risk-types/ | Create, Read, Update and Delete RiskTypes endpoint. |
risks/ | Create, Read, Update and Delete Risks here. |
Requirement is to create a solution that allows insurers to create their own data models for their risks. I tackled this by creating three models, RiskType,FieldType and FieldOption. These three allow users to define their own Risk data models and forms.
RiskType is the basic object and contains general data about the risk type such as it's name, label that will appear on the form and a description. Each RiskType can have multiple FieldTypes.
Attribute | Description |
---|---|
Name | A name to identify an instance of RiskType |
Label | A Label that will be displayed on the Risk Data Model |
Description | Description or note about the RiskType |
Tooltip | Helpful Information that is displayed when you mouse over a component |
Active | Flag that determines if the RiskType is active or not |
fields | A list of fieldTypes attached to this RiskType |
Created | Date Created |
Owner | Owner of the RiskType |
Field Types represent a single field for the risk data model. Each field type has it's own name, type and label which determine how it will behave on the front end. For enumerated types FieldType can have multiple Options. The solution supports two types of enumerated types:
- Radio Buttons
- Dropdown Boxes
Attribute | Description |
---|---|
Name | A name to identify an instance of RiskType |
Label | A Label that will be displayed on the Risk Data Model |
Type | Determines field type, i.e. Is it Text, Number, Email, Date, Dropdown etc. |
Tooltip | Helpful Information that is displayed when you mouse over a component |
Required | Flag that determines if the field will be required |
Visible | Flag that determines if the field is visible |
Hidden | Flag that determines if the field is a hidden field |
Options | A list of Options for an enumerated type |
This is used for enumerated types and contains a key and value describing the options available.
The UI application demonstrates how forms are generated, and on submit they create json objects that can be parsed and worked on. For this demo however I just encoded the object and saved it to database. The Risk Model receives the name, type and data for a new Risk and saves it to db.
The back end runs on Amazon AWS lambda, to deploy:
-
Set up Amazon
- You need an Amazon account and you need to create appropriate AWS Access Key and Secret Access key.
- you need a RDS running postgres database
- S3 instance if you plan to deploy the angular site on Amazon
-
download this repository to your working directory
git clone git@github.com:phoexer/bce.git
-
Create your python environment
cd bce virtualenv env
-
Install dependencies
pip install -r requirements.txt
-
Configure Zappa copy the zappa_settings.bak.json to zappa_settings.json and edit the zappa_settings.json file with your own settings.
Or alternatively you can runzappa init
to generate a new one -
copy the settings.bak.py to settings.py and go through it with your own details. Of Note are the following:
- SECRET_KEY
- ALLOWED_HOSTS
- DATABASES
- YOUR_S3_BUCKET
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- CORS_ORIGIN_WHITELIST
-
Once you are done you should be ready to deploy and create a default user
zappa deploy zappa migrate zappa invoke --raw dev "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@phoexer.com', 'ncdBXf5KBFTKyeFqLp8E')"
-
To get the single page app up, you run
python manage.py collectstatic --noinput
or copy the contents bce-ui/dist into a web server like apache
If everything went well you should now have the api running on lambda.