Storing Stock Symbols by User and Displaying Them
You can find part 1 here.
This part of the tutorial we are going to start adding stock symbols to a user so they can pick which stocks they like and want to follow. At the moment, when our user enters a stock symbol and hits ‘Add New’ we are sending that to post at ‘/stocks’ but we haven’t created the route yet. So let’s add that to our routes like this:
Now we have to add the logic so that when we hit the route with a post containing a stock ticker we add it to our user. Also in our signup when we create the user we are going to have to add a field in which we will store the stock inputs.
Now if you do ‘Add New’ you should see it appear in the datastore of the vertex app for Stock-Tracker on the turbo 360 website like this:
Now let’s make it so when we hit the ‘/stocks’ route all the names of our stock are displayed. First let’s get the stocks when we hit ‘/stocks’ and push them to our templating engine.
Now So let’s go into our stocks.mustache file and add some LIs for our stock names.
So now when you refresh the page it should look something like this:
Let’s add a delete button to each of these posts and wire them up. So we start in the stock.mustache file and add an HTML form that does a post request to the route ‘/deletestock’. It sends a hidden input that contains the stock name.
Now we have to create that ‘/deletestock’ route we pointed the form to. In this route we will get the data of our user, separate out our current stocks, delete the one that had its button pressed from the list, and update the list of the user.
It will look like this:
In the next tutorial we will start hitting the APIs and displaying the information we get back.