Exercise Monday

Goal: Focus on learning the basics of routing. Follow along with the weekend homework to build out the backend logic for adding CRUD functionality to an application. Once you are finished, follow along with the upcoming homework to add CRUD functionality to a Sinatra application.

Warm Up

• What is CRUD functionality?
• What is the difference between GET, POST, PATCH and DELETE?
• What is the difference between class methods and instance variables?
• Why would we use a class variable and why should they be avoided?

Code

Routing Practice

Follow along with the Basic Routing with Sinatra lesson. Make sure you hit each route mentioned in the lesson. Try adding a few custom routes and test that you can access them through the browser. Talk over routing with your pair and make sure you have a basic understanding of routing before moving to the next project.

Record Store Backend

Follow along with the weekend lessons and create a backend for a record store. Once you are finished, go through the upcoming homework lessons and add basic CRUD functionality to the record store application with Sinatra. You will also have the opportunity to continue building out the record store application over the next several days.

Triangles

To get further practice using Sinatra, build a basic application that doesn't need CRUD functionality. Create a Triangle class that includes methods for initializing new triangles and determining triangle type. Keep in mind that not all combinations of three numbers make valid triangles. For example, (2, 2, 8) does not make a triangle.

When unit testing on your Triangle class is complete, make a Sinatra application that lets the user input the lengths of the sides of a triangle and tells whether they form an equilateral, isosceles, or scalene triangle.

Here are the Triangle rules you'll need:

• Equilateral: all sides are equal;
• Isosceles: exactly 2 sides are equal;
• Scalene: no sides are equal;
• NOT a triangle: the sum of the lengths of any two sides of a triangle is less than or equal to the length of the third side.

Hint: Only two routes and two views are needed to complete this project:

• A route for a user input along with a view that has a form for entering the sides of a triangle.
• A route with the method to return the triangle type along with a view to display the result to the user.

Make sure to commit regularly and create a README file.

Parcels

Create a basic CRUD application for creating, updating and deleting `Parcel`s. First, start with the backend logic, which should provide functionality to:

• Create an instance of `Parcel`. A user should be able to specify the dimensions and weight of a `Parcel`.
• Update an instance of `Parcel`.
• Delete a `Parcel`.
• View all `Parcel`s.
• Find an instance of `Parcel`.

• Include a `volume()` instance method to calculate the volume of a `Parcel`.
• Add a `cost_to_ship()` instance method. This will return a cost based on a formula you make up (you might consider factors like speed of delivery, distance, dimensions, weight).
• Once the backend logic is complete and tested, build a website in Sinatra that lets users calculate shipping costs.

Make sure to commit regularly and create a README file.

For bonus points, consider:

• offering gift wrapping services that require the surface area of the parcel to determine cost;
• offering discounts based on size or date or some other property;
• adding CSS/Bootstrap to enhance the user experience.

Peer Code Review

• Are objects created from a custom class with custom methods?
• Does Sinatra process GET requests and responses correctly?
• Does Sinatra application have full CRUD functionality?
• Do routes follow RESTful naming conventions?
• Is the code clean and well-refactored?
• Does the backend logic have complete spec coverage?
• Are all specs passing?

Lesson 14 of 37
Last updated July 28, 2022