CloudClub-uoft / cloud-club-website

Club Website
https://cloudclub.ca
4 stars 4 forks source link

Create Backend for Serverless Functions: '/submit' #104

Open harsimrat99 opened 1 year ago

harsimrat99 commented 1 year ago

We want to create a route that allows users to submit their functions to the Serverless Functions application.

Expected Behavior

The user should be able to paste, or type, their code into the webpage and press the submit button to submit their code to the database.

Possible Implementation

An express POST route is create to allow users to submit their code in a form element. The backend server will save that code into the database.

Detailed Steps For Implementation

  1. Create a table inside the database named: 'functions' (Brady)
    • Each row in that table should have the following columns.
    • function_id (primary ID is automatically added)
    • user_id
    • function_contents
    • timestamp (added automatically)
    • language
    • trigger_type (functions either invoke themselves automatically or they are maunally triggered)

(Noa, Sophia, Sasha)

1.5. Create a frontend EJS page that allows the user to enter their data.

  1. Create a POST route called '/submit' that stores the user's funciton into the database. Create a frontend form that allows the user to enter their function, choose the trigger type and the language. (In this case, there is going to be a text box, radio buttons for language, radio button for trigger type)

  2. Save that data, i.e. the function body, the langauge, the trigger type, into the database. (Need to use SQL in this step)

  3. Return a message indicating to the user that the step was completed succesfully or unsucessfuly.

harsimrat99 commented 1 year ago

Install db-migrate: npm i db-migrate

Command to create a migration:

Run this command at the root of your directory. db-migrate create functions-table --config .\database\database.json

After modifying your newly created migration, execute the following command in the terminal: db-migrate up --config database/database.json

harsimrat99 commented 1 year ago

Example of a migration file with autoincrements and primary keys and timestamps.

20230312230950-add-harsimratstable.txt