GithubHelp home page GithubHelp logo

sinatra-starter-code's Introduction

Intro-to-Sinatra-2

Announcments

  • We will be available next week for project help.

SWABATS

  • Define User stories
  • Create Entity Relationship Model (ERM)
  • Create Database based on ERM
  • Create CRUD Endpoints in Sinatra

Getting started with creating a Sinatra API - (The Process)

  • Create a Entity Relationship Model
    • This will be something that will evolve over time
    • The more time that you spend on this, the easier it will be to write your code
  • Translate ERM to Active Record
    • Create migrations
    • Create models
    • Add ActiveRecord relationship macros
    • Add seed data
    • Test model relationships
  • Create CRUD endpoints
    • CREATE rider POST "localhost:9292/riders"
    • READ rider GET "localhost:9292/riders" (Same URL - different endpoint)
    • UPDATE rider PATCH "localhost:9292/riders/:id"
    • DESTROY rider DELETE "localhost:9292/riders/:id"

Domain Model (Relationships)

Researching the domain

ERM: https://lucid.app/lucidchart/f5d8bef7-7bc1-40c5-ab1e-e9caac7de84d/edit?view_items=kWBYMBmO7AJt&invitationId=inv_07e57e63-6b60-4ce2-b4fb-4265d3c37e5c#

Rider

- belongs_to :team
- has_many :rider_races
- has_many :races, through: :rider_races
- has_many :seasons, through: :races (How can we make modify this so that collection returned is uniq)

RiderRace (Join Table - many to many)

- belongs_to :rider
- belongs_to :race

Race

- has_many :rider_races
- has_many :riders, through: :rider_races
- belongs_to :track
- belongs_to :season

Team

  • has_many :riders
  • has_many :races
  • has_many :seasons, through: :riders (How can we make modify this so that collection returned is uniq)

Season

- has_many :races
- has_many :tracks, through: :races
- has_many :riders
- has_many :teams

Track

- has_many :races
- belongs_to :location
- has_many :seasons, through: :races

Location

- has_many :tracks

Now we can code!

Setting up Active Record

  • Create Migrations
  • Create Models
  • Add association macros
  • Add Seed data
  • Test the associations in a rake console
    • Rider.all
    • Rider.first.races
    • Rider.first.races.last.track
    • Rider.first.races.last.track.location
    • Location.first.tracks
    • Team.first.seasons
    • Team.first.seasons.first.races
    • Rider.first.rider_races
    • Rider.first.rider_races.first.rider_points
    • Rider.first.races.first.track.location

Setting up Sinatra

  • Create Controller (Pay attention to naming convention here as well)
    • Inherit from ApplicationController (Base controller)
  • Add use <controller> to config.ru file

Additional Endpoints

  • Create endpoint for Season winner "localhost:9292/seasons/1/winner"
    • Create a method in the Rider model that returns the total amount of points that rider scored for a given season. Rider#season_points(season)
    • Create a method in the Season model that returns the winner of a particular season. Use the Rider#season_points method as a helper.

sinatra-starter-code's People

Watchers

James Cloos avatar Tom Tobar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.