Coder Social home page Coder Social logo

mackenzie-frey / express_sweater_weather Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 284 KB

Express Sweater Weather utilizes API's to provide weather data endpoints.

Home Page: https://express-sweater-weather.herokuapp.com/

JavaScript 97.85% HTML 1.32% CSS 0.83%

express_sweater_weather's Introduction

README

Description

Express Sweater Weather is a 6-day, solo project during module four of four, of Turing School's Back-End Engineering Program.

Express Sweater Weather is a web application designed to consume/produce API's. The application utilizes Node.js, Expess and Sequelize, with a PostgreSQL database, to consume the Dark Sky API for weather, and the Google Maps API for geocoding.

Schema

Alt text

Getting Started

To run Express Sweater Weather on a local machine, navigate to the directory in which you would like the project to be located in, then execute the following commands:

$ git clone [email protected]:Mackenzie-Frey/express_sweater_weather.git
$ cd express_sweater_weather
$ npm install

Environment Variable Setup:

Sign Up for the following APIs:

Create a .env file in the root directory of the project. Add .env to the .gitignore file. Make sure to insert the secret key without the alligator clips ( < > ).

google_key=<insert>
dark_sky_key=<insert>

Running Tests

To run the test suite, execute the following command: npm test. The tests will automatically run each time an update is made to the application.

Deployment

To view Express Sweater Weather in development, execute the following command from the project directory: nodemon npm start. To view the application in a web browser, visit localhost:3000 and navigate the the desired endpoint.

Available Endpoints

POST /api/v1/users, params: { email: [email protected], password: password123, password_confirmation: password123 }
POST /api/v1/sessions, params: { email: [email protected], password: password123 }
GET /api/v1/forecast?location=<location name ie denver,co>
POST /api/v1/favorites, body: {"location": "Denver, CO", "api_key": "<returned api_key>"}
GET /api/v1/favorites, body: {"api_key": "<returned api_key>"}
DELETE /api/v1/favorites, body: {"location": "Denver, CO", "api_key": "<returned api_key>"}

Tools

  • Dark Sky API
  • Google Maps API
  • Postman
  • bcrypt
  • dotenv
  • node-fetch
  • pryjs
  • babel-jest
  • nodemon
  • scriptjs
  • shelljs
  • supertest

Known Issues

  • Account Creation -> Non-Unique Email
  • Upon account creation via a POST request to /api/v1/users, users are currently able to create a duplicate record in the system, utilizing the same email address.

How to Contribute

Contributing Code:
  1. Fork the project.
  2. Write a failing test.
  3. Commit that failing tests.
  4. Commit changes that fix the tests.
  5. Submit a pull request detailing the change that was made.
Submitting a Bug:
  1. Search the existing issues.
  2. Create a new issue if applicable, or contribute to an existing issue.

Related Links:

Author

Mackenzie Frey

Collaborators

express_sweater_weather's People

Contributors

mackenzie-frey avatar

Watchers

James Cloos avatar

express_sweater_weather's Issues

Refactors

  • Refactor routes/api/v1/sessions.js & routes/api/v1/users.js to utilizing async await. Change the router.post functions to utilizing ES6 syntax for the first line of the function.

  • Extract logic to create modules for; finding the user via an API key & catching with 500 errors

  • Ensure all variables are set to const (rather than let or var), where applicable.

  • Pull logic out of controllers

Forecast for City -Testing

  • If no API key is provided it returns 401 (Unauthorized)
  • If an incorrect API key is provided it returns 401 (Unauthorized)
  • Includes sad path testing

Forecast for City - Authorization

Alter the current code to execute the following functionality.

  • If no API key is provided it returns 401 (Unauthorized)
  • If an incorrect API key is provided it returns 401 (Unauthorized)

Login

When a user sends a POST request to /api/v1/sessions, in the format of JSON, with the following in the body of the request:

{
  "email": "[email protected]",
  "password": "password"
}

The user receives the following response:

status: 200
body:

{
  "api_key": "jgn983hy48thw9begh98h4539h4",
}
  • If the user sends an email and password that do not match, they receive a 401 error - Unauthorized.

Favoriting Locations

When a user sends a POST request to /api/v1/favorites, in the format of JSON, and with the following in the body:

body:

{
  "location": "Denver, CO",
  "api_key": "jgn983hy48thw9begh98h4539h4"
}

The user receives the following response:

status: 200
body:

{
  "message": "Denver, CO has been added to your favorites",
}
  • If no API key is provided it returns 401 (Unauthorized)
  • If an incorrect API key is provided it returns 401 (Unauthorized)

Peer Feedback

  • You need to make the PR and tag them with a specific review ask
  • They need to respond in the PR conversation with actionable feedback
  • You need to make a change, tag them again for their review (you may need to ask a clarifying question before doing so, if that’s the case, ask in the PR conversation instead of Slack or in person)
  • If they continue the conversation great, if not, that’s fine at this point

Account Creation - Testing

Create tests for when a user sends a POST request to /api/v1/users.

  • Test for non-unique email
  • Test for password/password confirmation not matching
  • Test user is created in the database, along with the user's attributes.
  • Include Sad Path Testing

Save Lat & Long to DB

When I save a favorite via a POST request to api/v1/favorites, it checks the Locations table for a location in existence, if a matching location does not exist, it saves the location, along with the locations coordinates to the database.

When a GET request is made to api/v1/favorites it utilizes the lat and long in the database (if the location already exists in the databse), rather than making an API call to get the lat and long.

Environment Variable Setup

When I visit the endpoints for Dark Sky & Google Maps, the API keys work and the environment variables are concealed in the application.

Forecast for City

When a user sends a GET request to /api/v1/forecast?location=denver,co, in the format of JSON, with the following in the body of the request:

body:
{
  "api_key": "jgn983hy48thw9begh98h4539h4"
}

A response modeling the following is received (the following response contains only 1 object in the data array for both the hourly and daily. The actual response will contain at least 8 hourly objects and 7 daily objects):

{
  "location": "Denver, C0",
  "currently": {
      "summary": "Overcast",
      "icon": "cloudy",
      "precipIntensity": 0,
      "precipProbability": 0,
      "temperature": 54.91,
      "humidity": 0.65,
      "pressure": 1020.51,
      "windSpeed": 11.91,
      "windGust": 23.39,
      "windBearing": 294,
      "cloudCover": 1,
      "visibility": 9.12,
    },
  "hourly": {
    "summary": "Partly cloudy throughout the day and breezy this evening.",
    "icon": "wind",
    "data": [
      {
      "time": 1555016400,
      "summary": "Overcast",
      "icon": "cloudy",
      "precipIntensity": 0,
      "precipProbability": 0,
      "temperature": 54.9,
      "humidity": 0.65,
      "pressure": 1020.8,
      "windSpeed": 11.3,
      "windGust": 22.64,
      "windBearing": 293,
      "cloudCover": 1,
      "visibility": 9.02,
      },
    ]
  },
  "daily": {
    "summary": "No precipitation throughout the week, with high temperatures bottoming out at 58°F on Monday.",
    "icon": "clear-day",
    "data": [
      {
        "time": 1554966000,
        "summary": "Partly cloudy throughout the day and breezy in the evening.",
        "icon": "wind",
        "sunriseTime": 1554990063,
        "sunsetTime": 1555036947,
        "precipIntensity": 0.0001,
        "precipIntensityMax": 0.0011,
        "precipIntensityMaxTime": 1555045200,
        "precipProbability": 0.11,
        "precipType": "rain",
        "temperatureHigh": 57.07,
        "temperatureLow": 51.47,
        "humidity": 0.66,
        "pressure": 1020.5,
        "windSpeed": 10.94,
        "windGust": 33.93,
        "cloudCover": 0.38,
        "visibility": 9.51,
        "temperatureMin": 53.49,
        "temperatureMax": 58.44,
      },
    ]
  }
}
  • There are at least 8 hourly objects and 7 daily objects in the response

Account Creation

When a user sends a POST request to /api/v1/users, in the format of JSON, with the following in the body of the request:

{
  "email": "[email protected]",
  "password": "password"
  "password_confirmation": "password"
}

The following response is received:

status: 201
body:

{
  "api_key": "jgn983hy48thw9begh98h4539h4",
}
  • Securely store passwords in the database. Consider utilizing bcrypt.
  • If the password and password confirmation do not match, the account is not created and the user receives a 400 error - Bad Request

Listing Favorite Locations

When a user sends a GET request to /api/v1/favorites, in the format of JSON, with the following in the body:

body:

{
  "api_key": "jgn983hy48thw9begh98h4539h4"
}

They receive the following response:

status: 200
body:
[
  {
    "location": "Denver, CO",
    "current_weather": {
      "summary": "Overcast",
      "icon": "cloudy",
      "precipIntensity": 0,
      "precipProbability": 0,
      "temperature": 54.91,
      "humidity": 0.65,
      "pressure": 1020.51,
      "windSpeed": 11.91,
      "windGust": 23.39,
      "windBearing": 294,
      "cloudCover": 1,
      "visibility": 9.12,
    },
    "location": "Golden, CO",
    "current_weather": {
      "summary": "Sunny",
      "icon": "sunny",
      "precipIntensity": 0,
      "precipProbability": 0,
      "temperature": 71.00,
      "humidity": 0.50,
      "pressure": 1015.10,
      "windSpeed": 10.16,
      "windGust": 13.40,
      "windBearing": 200,
      "cloudCover": 0,
      "visibility": 8.11,
    }
  }
]
  • If no API key is provided it returns 401 (Unauthorized)
  • If an incorrect API key is provided it returns 401 (Unauthorized)

Account Creation - Unique Email

When a user sends a POST request to /api/v1/users, with an email address that is not unique (aka it already exists in the database), the account is not created and the user receives a 400 error - Bad Request.

Update README

Clearly document:

  • Introduction
  • Initial Setup
  • How to Use
  • Known Issues
  • Running Tests
  • How to Contribute
  • Core Contributors
  • Schema Design
  • Tech Stack List

Peer Feedback #2

  • You need to make the PR and tag them with a specific review ask
  • They need to respond in the PR conversation with actionable feedback
  • You need to make a change, tag them again for their review (you may need to ask a clarifying question before doing so, if that’s the case, ask in the PR conversation instead of Slack or in person)
  • If they continue the conversation great, if not, that’s fine at this point

Removing Favorite Locations

When a user sends a DELETE request to /api/v1/favorites, in the format of JSON, with the following in the body:

body:

{
  "location": "Denver, CO",
  "api_key": "jgn983hy48thw9begh98h4539h4"
}

The following response is received:

status: 204
  • If no API key is provided it returns 401 (Unauthorized)
  • If an incorrect API key is provided it returns 401 (Unauthorized)

Login - Testing

  • Tests for correct password
  • Tests for incorrect password
  • Includes sad path testing

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.