Skip to content

Air quality search application with authentication using the Weatherbit.io API.

Notifications You must be signed in to change notification settings

JaxonNarramore/air-qual

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Air Qual

An application that gets real-time air quality information and allows the user to log in, have an account, and add cities to your profile to have easier access to see that city's air quality. I was inspired to build this application after leaning about how much air quality affects the lives of everyone and everything on earth.

Features

  • User authintication
  • Password hashing
  • Search form for cities air quality
  • Ability to save cities to profile
  • Ability to update email

Languages, Frameworks, and Databases

  • Passport
  • Sessions
  • BCrypt
  • Axios
  • Ejs
  • Express
  • Sequelize
  • Postgres
  • SQL

Routes

Method Path Location Purpose
GET / server.js Home page
GET /auth/login auth.js Login form
GET /auth/signup auth.js Signup form
POST /auth/login auth.js Login user
POST /auth/signup auth.js Creates User
GET /auth/logout auth.js Removes session info
PUT /update server.js Updates email info
GET /profile server.js Regular User Profile
POST /profile server.js Adds city to databse
DELETE /profile server.js Deletes city from databse
GET /airquality airquality.js Search page
GET /airquality/location airquality.js Results from search

User Model

Column Name Data Type Notes
id Integer Serial Primary Key, Auto-generated
name String Must be provided
email String Must be unique / used for login
password String Stored as a hash
createdAt Date Auto-generated
updatedAt Date Auto-generated

City Model

Column Name Data Type Notes
id Integer Serial Primary Key, Auto-generated
name String City that was typed into search
state String State that was typed into search
userId Integer Associated with the users id in user model
createdAt Date Auto-generated
updatedAt Date Auto-generated

ERD

Models

The GET route grabbing data from the Weatherbit API in the airquality router

airRouter.get("/location", (req, res) => {
  const citystate = req.query.location;
  const state = req.query.state;
  axios
    .get(
      `https://api.weatherbit.io/v2.0/current/airquality?city=${citystate},${state}&key=${process.env.AIR_API_KEY}`
    )
    .then((response) => {
      const air = response.data;
      res.render("airquality", { query: air });
    })
    .catch((error) => {
      console.log(error);
    });
});

The POST route adding data to the city databse in the profile router

profileRouter.post("/", (req, res) => {
  const { city_name } = req.body;
  const state = req.body.state_code;
  db.city
    .create({
      name: city_name,
      state: state,
      userId: req.user.id,
    })
    .then(() => {
      res.redirect("/profile");
    })
    .catch((error) => {
      console.log(error);
    });
});

The GET route grabbing data from the city databse in the profile router

profileRouter.get("/", (req, res) => {
  db.city
    .findAll({
      where: { userId: req.user.id },
    })
    .then((city) => {
      const cities = city.map((item) => {
        return item.dataValues;
      });
      res.render("profile", { cities });
    });
});

The PUT route updating the user email from the user database in the server.js file

app.put("/update", (req, res) => {
  db.user
    .update(
      {
        email: req.body.email,
      },
      {
        where: { id: req.user.id },
      }
    )
    .then(() => {
      res.redirect("/profile");
    });
});

The DELETE route deleting data from the city databse in the profile router

profileRouter.delete("/", (req, res) => {
  const { id } = req.body;
  db.city
    .findOne({
      where: { id: id },
    })
    .then((foundCity) => {
      foundCity.destroy().then(() => {
        res.redirect("/profile");
      });
    });
});

Steps To Install On Local Machine

1. Fork and Clone to local machine using

https://github.com/JaxonNarramore/suncreen-or-no-sunscreen

2. Go to the file in the terminal

3. Install node modules from the package.json

npm install

(Or just npm i for short)

4. Add a .env file with the following fields:

  • SESSION_SECRET: Can be any random string; usually a hash in production
  • PORT: Usually 3000 or 8000
  • AIR-API_KEY: Must get an API key from Weatherbit.io
  • COOKIE_KEY: Can be any random string; usually a hash in production

10. Run server; make sure it works

nodemon

or

node index.js

Renderings of pages

Signup page Login page Search page Results page Saved cities page Update email page

Wireframes

Search page

Signup Page

Login page

Contact with the creator

Email: jaxon_narramore@hotmail.com

About

Air quality search application with authentication using the Weatherbit.io API.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published