rrabinovitch / aetna_movie_api

0 stars 0 forks source link

Movie API Code Test

Setup

Version Requirements

Steps

  1. git clone git@github.com:rrabinovitch/aetna_movie_api.git
  2. cd aetna_movie_api
  3. bundle install
  4. rails db:{create,migrate} - note that as of 11/17/20, running this command from main will only set up the movies database and table and not the ratings ones
  5. run tests: bundle exec rspec
  6. run rails s and explore the endpoints documented below

Endpoint Documentation

Base URL: localhost:3000/api/v1

GET /movies

Examples

Request: GET localhost:3000/api/v1/movies?page=1
Response:

  {
    "data": [
        {
            "id": "2",
            "type": "movie",
            "attributes": {
                "imdbId": "tt0094675",
                "title": "Ariel",
                "releaseDate": "1988-10-21",
                "budget": "$0.00",
                "genres": "[{\"id\": 18, \"name\": \"Drama\"}, {\"id\": 80, \"name\": \"Crime\"}]"
            }
        },
        {
            "id": "3",
            "type": "movie",
            "attributes": {
                "imdbId": "tt0092149",
                "title": "Shadows in Paradise",
                "releaseDate": "1986-10-16",
                "budget": "$0.00",
                "genres": "[{\"id\": 18, \"name\": \"Drama\"}, {\"id\": 35, \"name\": \"Comedy\"}]"
            }
        },
        {
            "id": "5",
            "type": "movie",
            "attributes": {
                "imdbId": "tt0113101",
                "title": "Four Rooms",
                "releaseDate": "1995-12-09",
                "budget": "$4000000.00",
                "genres": "[{\"id\": 80, \"name\": \"Crime\"}, {\"id\": 35, \"name\": \"Comedy\"}]"
            }
        },
        {
            "id": "6",
            "type": "movie",
            "attributes": {
                "imdbId": "tt0107286",
                "title": "Judgment Night",
                "releaseDate": "1993-10-15",
                "budget": "$0.00",
                "genres": "[{\"id\": 28, \"name\": \"Action\"}, {\"id\": 53, \"name\": \"Thriller\"}, {\"id\": 80, \"name\": \"Crime\"}]"
            }
        },
      ...
    ]
  }

Request: GET localhost:3000/api/v1/movies?year=2005
Response:

  {
      "data": [
          {
              "id": "21705",
              "type": "movie",
              "attributes": {
                  "imdbId": "tt0795338",
                  "title": "Barbie Diaries",
                  "genres": "[{\"id\": 10751, \"name\": \"Family\"}, {\"id\": 16, \"name\": \"Animation\"}]",
                  "releaseDate": "2005-12-31",
                  "budget": "$0.00"
              }
          },
          {
              "id": "26147",
              "type": "movie",
              "attributes": {
                  "imdbId": "tt0453365",
                  "title": "FC Venus",
                  "genres": "[{\"id\": 35, \"name\": \"Comedy\"}, {\"id\": 10749, \"name\": \"Romance\"}]",
                  "releaseDate": "2005-12-30",
                  "budget": "$2196531.00"
              }
          },
          {
              "id": "45035",
              "type": "movie",
              "attributes": {
                  "imdbId": "tt0492835",
                  "title": "King and the Clown",
                  "genres": "[{\"id\": 18, \"name\": \"Drama\"}, {\"id\": 36, \"name\": \"History\"}, {\"id\": 53, \"name\": \"Thriller\"}]",
                  "releaseDate": "2005-12-29",
                  "budget": "$0.00"
              }
          },
        ...
          {
              "id": "40017",
              "type": "movie",
              "attributes": {
                  "imdbId": "tt0499041",
                  "title": "Kalyug",
                  "genres": "[{\"id\": 10769, \"name\": \"Foreign\"}, {\"id\": 53, \"name\": \"Thriller\"}]",
                  "releaseDate": "2005-12-09",
                  "budget": "$0.00"
              }
          }
      ]
    }

Request: GET localhost:3000/api/v1/movies?year=2005&page=5
Response:

   {
      "data": [
          {
              "id": "53935",
              "type": "movie",
              "attributes": {
                  "imdbId": "tt0419922",
                  "title": "Living 'til the End",
                  "genres": "[{\"id\": 18, \"name\": \"Drama\"}, {\"id\": 10749, \"name\": \"Romance\"}]",
                  "releaseDate": "2005-10-21",
                  "budget": "$0.00"
              }
          },
          {
              "id": "59958",
              "type": "movie",
              "attributes": {
                  "imdbId": "tt0487907",
                  "title": "Gideon's Daughter",
                  "genres": "[{\"id\": 18, \"name\": \"Drama\"}]",
                  "releaseDate": "2005-10-21",
                  "budget": "$0.00"
              }
          },
          {
              "id": "123858",
              "type": "movie",
              "attributes": {
                  "imdbId": "tt0460926",
                  "title": "Scab",
                  "genres": "[]",
                  "releaseDate": "2005-10-21",
                  "budget": "$0.00"
              }
          },
          ...
                  {
              "id": "9621",
              "type": "movie",
              "attributes": {
                  "imdbId": "tt0368709",
                  "title": "Elizabethtown",
                  "genres": "[{\"id\": 35, \"name\": \"Comedy\"}, {\"id\": 18, \"name\": \"Drama\"}, {\"id\": 10749, \"name\": \"Romance\"}]",
                  "releaseDate": "2005-10-06",
                  "budget": "$57000000.00"
              }
          }
      ]
  }

GET /movies/:id

Example

Request: GET localhost:3000/api/v1/movies/11
Response:

  {
      "data": {
          "id": "11",
          "type": "movie",
          "attributes": {
              "imdbId": "tt0076759",
              "title": "Star Wars",
              "description": "Princess Leia is captured and held hostage by the evil Imperial forces in their effort to take over the galactic Empire. Venturesome Luke Skywalker and dashing captain Han Solo team together with the loveable robot duo R2-D2 and C-3PO to rescue the beautiful princess and restore peace and justice in the Empire.",
              "releaseDate": "1977-05-25",
              "budget": "$11000000.00",
              "runtime": 121,
              "genres": "[{\"id\": 12, \"name\": \"Adventure\"}, {\"id\": 28, \"name\": \"Action\"}, {\"id\": 878, \"name\": \"Science Fiction\"}]",
              "originalLanguage": null,
              "productionCompanies": "[{\"name\": \"Lucasfilm\", \"id\": 1}, {\"name\": \"Twentieth Century Fox Film Corporation\", \"id\": 306}]"
          }
      }
  }

Reflections

Original Assignment Instructions

Pre-requisites

Task

Your task is to create an API on top of a couple different databases. It should conform to the user stories provided below. You are free to use whatever language you prefer. Google and the interwebs are at your disposal.

The Databases The databases are provided as a SQLite3 database in db/. It does not require any credentials to login. You can run SQL queries directly against the database using:

sqlite <path to db file>

.tables will return a list of available tables and .schema <table> will provide the schema.

Considerations

When developing your solution, please consider the following:

User Stories

List All Movies

AC:

Movie Details

AC:

Movies By Year

AC:

Movies By Genre

AC:

Tips