Inform Thyself
This will be the private repo for our SFWR ENG 4G06 capstone project. The group members for the project will be able to commit to the repo.
How To Setup The Whole Thing Locally
- Make sure you have NodeJS and MySQL (see How To Setup The Database -> Local Database -> Installation below) installed.
- Open your terminal and navigate to a directory of your choice.
- Clone the repository into that directory by running
git clone https://github.com/KevinHardy-Cooper/SFWRENG_4G06.git - Obtain a copy (or create your own)
SensitiveInfo.jsfile. See What Should Go In SensitiveInfo.js? below. - Create the database (see How To Setup The Database -> Local Database -> Getting Started below)
- Start the local MySQL server:
mysql -u root -pfor Mac/Linux,winpty mysql -u root -pfor Windows. - Run
npm install - Run
node src/App.jsto actually run the application. - Visit http://localhost:3000/setting/twitter or another endpoint of your choice
- All done!
How To Setup The Database
Remote Database
- Log into Azure Portal.
- Create a new Web App + MySQL resource by downloading the resource here.
- Make sure you name the Database VApp, and create your credentials.
- After the resources are created, navigate to the My SQL resource and find the connection string
- Update the SensitiveInfo.js with credential found in the connection string. #### Creating Database Tables
- Figure out a way to create table in remote DB.... I just run the SQL script in
migrations/database.sqlfile with RazorSQL. - Using Razor to login into the remote DB and run SQL Queries with Razor GUI
- Explore newly created tables with Razor GUI (As a test, check if Users Table exists) #### Deploying App
- Deploy the App with VSCode. Follow Steps to install Azure App Service extension.
- When Azure Extension is configured, you will be able to see the Web App you created on Azure. Right click and hit Deploy to Web App.
Local Database
Installation
- Download MySQL for your respective machine.
- Follow their setup instructions in order to install it on your machine. #### Getting Started
- Fire up the MySQL Server (there's usually a "Start MySQL Server" button somewhere).
- Once the server is started, open up a command prompt and type
mysql -u root -pwhich will then require your password. You may have to set up credentials so that you can use this command on your machine.- If you are using Git Bash for Windows, you may have to type
winpty mysql -u root -p
- If you are using Git Bash for Windows, you may have to type
- The
mysqlprompt should now show up. Now typecreate database VApp;. This command will create the database that we will load thedatabase.sqlfile into. I couldn't think of anything else to call the database :). - Now enter
exit; We are now going to load the database from thedatabase.sqlfile, so hopefully you remember the path to that file. mysql -u root -p VApp < full/path/to/database.sql. Enter your password once more, and the console should freeze for a bit as it executes the SQL.- If using Windows, to import the file:
- Copy the
database.sqlfile toC:\Program Files\MySQL\MySQL Shell 8.0\bin\ - In Git Bash, type
winpty mysql -u root -p - Enter your password
- Type
use VApp; - Type
source database.sql
- Copy the
- If using Windows, to import the file:
- Now log in again and check if it worked:
mysql -u root -porwinpty mysql -u root -pfor Windows. Use
show databases;and verify that VApp is there. use VApp;. We are selecting this database to use from hereon.show tables;. You should see 7 tables (Implications, Score_Types, Scores, Setting_States, Settings, Social Media, Users).- Let's run a query on one to see if it filled correctly.
select * from Score_Types;. The query should return two records,cumulativeandtwitter. And that's it! - Exit the prompt using
exit;, and turn off the MySQL server if you are done using it (Look for the button that says "Stop MySQL Server", should be in the window where you started the server from).
NOTE:
If you have made change to a table, such as inserted Implications or Settings, export the database as an SQL file,
replace the database.sql with this file (also name it database.sql), and make a pull request on GitHub with the
updated file.
## Database Migrations To manage our database we will be using database migrations. This is pretty standard for web applications. This is the basic idea: instead of manually updating the database (by using a tool like MySQL Workbench or having to run SQL queries manually in the terminal) we can create migration scripts. These scripts will make the updates to the database for us and they are very easy to use. Also, it will support upgrading and rolling back the database. For new developers, they can simply import the database.sql file and run the migration command and be good to go.
For an overview of how database migrations work in NodeJS, read this article.
We will be using db-migrate and db-migrate-mysql. You should install these packages globally for convenience by using the following command:
npm install -g db-migrate db-migrate-mysql
You will need to make sure have a database.json file. Simply copy the database-sample.json file, rename it to database.json and edit the contents as necessary (or ask someone)!
To update your database to the latest version, simply run:
db-migrate up
For more information on how to write scripts, refer to the official docs.
What Should Go In SensitiveInfo.js?
At this stage, there are only four fields, and each is required in order to make a database connection currently.
this.host = ''; This will contain the host of the database we are using. For a local database, the host is localhost;
this.user = ''; This will contain the user for the database we are using. For a local database, the user could be root,
or whatever you set up your local database user to be.
this.password = ''; This will contain the password for the database we are using. For a local database, this is not your
computer password, but rather the password that you set up to be used for your local database.
this.database = ''; This will contain the database name for the database we are using. For this project, we will be using
VApp.
this.port= ''; This will contain the database port for the database we are using. The default is 3306.
this.consumer_key = ''; This is one of the two keys required in order to use Twitter's APIs for our app. They are
associated with Kevin's Twitter developer account and can be found there. More information can be found here.
this.consumer_secret_key = ''; This is the other key required in order to use Twitter's APIS for our app. They are
associated with Kevin's Twitter developer account and can be found there. More information can be found here.
this.callback_url = ''; This is used to provide direction on where a user should go after signing in with their
Twitter credentials. This callback url has been explicitly declared in the app's settings on Kevin's Twitter developer
account. More information can be found here.
this.cookie_signer = ''; This is the secret used to sign the session ID cookie.
Linting
For JavaScript development, we will follow the following naming conventions:
- Classes and files are to be named in UpperCamelCase
- Variables, functions and objects are to be named in lowerCamelCase
- Literal constants are to be named in ALLCAPITALS, such as
const PI = 3.14orconst DATABASE = 'VApp - Non-literal constants are to be named in UpperCamelCase
For Database development, we will follow the following naming conventions:
- Database and tables will be named in Upper_Snake_Case
- Columns will be named in lower_snake_case
Endpoints
GET / - Home page
POST /signup - Sign up the user
POST /signout - Sign out the user
POST /signin - Sign in the user
GET /oauth - Start OAuth process
GET /oauth/callback - Receives access tokens from Twitter
GET /oauth/:socialMedia - Requests Twitter login page
GET /settings/:socialMedia - Gets user's Twitter settings
GET /cumulativeScore - Gets user's cumulative score
POST /cumulativeScore - Inserts user's cumulative score
GET /score/:userId - Gets user's scores
GET /score/:userId/:socialMedia - Gets user's scores by social media
POST /score/:socialMedia - Inserts user's social media score
GET /implications/:settingId - Gets implications by setting
GET /instructions/:implicationId - Gets instructions by implication
Log in or sign up for Devpost to join the conversation.