{"size": 1329, "ext": "js", "max_stars_repo_path": "server/routes/dreams.js", "max_stars_repo_name": "indigophillips/Te-Mauri-Moemoea", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/routes/dreams.js", "max_issues_repo_name": "indigophillips/Te-Mauri-Moemoea", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server/routes/dreams.js", "max_forks_repo_name": "indigophillips/Te-Mauri-Moemoea", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.1636363636, "max_line_length": 51, "alphanum_fraction": 0.6282919488}
const express = require('express')

const dreamDB = require('../db/dreams')
const errorHandler = require('./errorHandler')

const router = express.Router()

router.get('/public', (req, res) => {
  dreamDB.getPublicDreams()
    .then(dreams => {
      res.status(200).json(dreams)
    })
    .catch(err => errorHandler(res, err,
      'error retrieving public dreams'
    ))
})

router.get('/personal/:dreamerId', (req, res) => {
  const {dreamerId} = req.params

  dreamDB.getPersonalDreamsByUserID(dreamerId)
    .then(personalDreams => {
      res.status(200).json(personalDreams)
    })
    .catch(err => errorHandler(res, err,
      'error retrieving personal dreams'
    ))
})

// router.get('/whanau/:whanau_id', (req, res) => {
//   const { whanau_id } = req.params

//   dreamDB.getDreamsByWhanauID(dreamer_id)
//     .then(whanauDreams => {
//       res.status(200).json(whanauDreams)
//     })
//     .catch(err => errorHandler(res, err,
//       'error retrieving whanau dreams'
//     ))
// })
//
router.get('/contributing/:id', (req, res) => {
  const {id} = req.params

  dreamDB.getDreamsByContributorID(id)
    .then(contributorDreams => {
      res.status(200).json(contributorDreams)
    })
    .catch(err => errorHandler(res, err,
      'error retrieving contributor dreams'
    ))
})

module.exports = router
