Giter VIP home page Giter VIP logo

menu-bar-component's Introduction

menu-bar-component

This service renders Twitch streamer information. The information includes number of video streamed, and number of followers. It also makes available a list of the followed channels, and renders a sidebar that shows recommended channels.

Getting Started

  • Run npm install in the repo directory.

  • Run sudo mongod in a free terminal pane to start your local MongoDB server. (If you don't have MongoDB on your machine, you can install it using a tutorial found here)

  • While your Mongo server is running, use another terminal pane to access the repo directory and run npm run mongoSeed (This will seed your database with 10 million records. You can monitor progress in the console.)

  • Once the seed script is finished, you can run npm run react-dev in the repo directory to build the webpack bundle, and then run npm start to start the server.

  • Access the service @ http://localhost:3015. It will take about 10 seconds to load, since it it not optimized yet.

Routes:

/getProfile

  • Queries database for last 100 records of user profiles
  • Takes no request parameters
app.get('/getProfile', (req, res) => {
  mongo.client.connect((err) => {
    if (err) {
      console.log(err);
      res.status(500).end();
    } else {
      console.log('GET api called')
    }

    new Promise((resolve, reject) => {
      users.find({}, { "limit": 100, "skip": 9999900 })
      .toArray((err, docs) => {
        if (err) {
          console.log(err);
          res.status(500).end();
        } else {
          resolve(docs);
        }
      })
    })
    .then((data) => res.status(200).send(JSON.stringify(data)))
    .then(() => db.close(console.log('GET API complete')));
  })
});

/createProfile

  • Posts a new user profile to database
  • Request body key-value pairs mirror user profile schema
app.post(`/createProfile`, (req, res) => {
  mongo.client.connect((err) => {
    if (err) {
      console.log(err);
      res.status(500).end();
    } else {
      console.log('POST api called')
    }

    new Promise((resolve, reject) => {
      users.insertOne(req.body, (err, r) => {
        assert.equal(null, err);
        resolve(assert.equal(1, r.insertedCount));
      })
    })
      .then(() => res.status(200))
      .then(() => db.close(console.log('POST API complete')));
  })
})

/deleteProfile

  • Deletes user profile from database
  • Takes key-value pair. Possible keys are: user_id and display_name.
app.delete(`/deleteProfile`, (req, res) => {
  mongo.client.connect((err) => {
    if (err) {
      console.log(err);
      res.status(500).end();
    } else {
      console.log('DELETE api called')
    }

    new Promise((resolve, reject) => {
      users.deleteOne(req.body);
      resolve(e);
    })
      .then((e) => { console.log(e); })
      .then(() => res.status(200))
      .then(() => db.close(console.log('DELETE API complete')));
  })
})

/updateProfile

  • Replaces current user profile values with new ones.
  • Requires user_id key-value pair.
  • All other key-value pairs from user profile schema may be updated/changed.
app.put(`/updateProfile`, (req, res) => {
  mongo.client.connect((err) => {
    if (err) {
      console.log(err);
      res.status(500).end();
    } else {
      console.log('PUT api called')
    }

    new Promise((resolve, reject) => {
      users.updateOne(req.body.user_id, { $set: req.body.update });
      resolve(e);
    })
      .then((e) => { console.log(e); })
      .then(() => res.status(200))
      .then(() => db.close(console.log('PUT API complete')));
  })
})

menu-bar-component's People

Contributors

gdfekaris avatar

Watchers

James Cloos avatar D Lee  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.