text: /**
  *  Developer controller
  *  Handles requests related to developer resources.
  
  *
  */
  const express = require('express')
  const api = express.Router()
  const LOG = require('../utils/logger.js')
  const Model = require('../models/addnewplace.js')
  const notfoundstring = 'Could not find user with id='
  
  // RESPOND WITH JSON DATA  --------------------------------------------
  
  // GET all JSON
  api.get('/findall', (req, res) => {
    LOG.info(`Handling /findall ${req}`)
    Model.find({}, (err, data) => {
      if (err) { return res.end('Error finding all') }
      res.json(data)
    })
  })
  
  // GET one JSON by ID
  api.get('/findone/:id', (req, res) => {
    LOG.info(`Handling /findone ${req}`)
    const id = parseInt(req.params.id)
    Model.find({ _id: id }, (err, results) => {
      if (err) { return res.end(`notfoundstring ${id}`) }
      res.json(results[0])
    })
  })
  
  // RESPOND WITH VIEWS  --------------------------------------------
  
  // GET /
  api.get('/', (req, res) => {
    LOG.info(`Handling GET / ${req}`)
    Model.find({}, (err, data) => {
      if (err) { return res.end('Error') }
      console.log(data);
      res.locals.addnewplaces = data
      res.render('addnewplace/index.ejs')
    })
  })
  
  // GET create
  api.get('/create', (req, res) => {
    LOG.info(`Handling GET /create ${req}`)
    Model.find({}, (err, data) => {
      if (err) { return res.end('error on create') }
      res.locals.addnewplaces = data
      res.locals.addnewplace = new Model()
      res.render('addnewplace/create.ejs')
    })
  })
  
  // GET /delete/:id
  api.get('/delete/:id', (req, res) => {
    LOG.info(`Handling GET /delete/:id ${req}`)
    const id = parseInt(req.params.id)
    Model.find({ _id: id }, (err, results) => {
      if (err) { return res.end(notfoundstring) }
      LOG.info(`RETURNING VIEW FOR ${JSON.stringify(results)}`)
      res.locals.addnewplace = results[0]
      return res.render('addnewplace/delete.ejs')
    })
  })
  
  // GET /details/:id
  api.get('/details/:id', (req, res) => {
    LOG.info(`Handling GET /details/:id ${req}`)
    const id = parseInt(req.params.id)
    Model.find({ _id: id }, (err, results) => {
      if (err) { return res.end(notfoundstring) }
      LOG.info(`RETURNING VIEW FOR ${JSON.stringify(results)}`)
      res.locals.addnewplace = results[0]
      return res.render('addnewplace/details.ejs')
    })
  })
  
  // GET one
  api.get('/edit/:id', (req, res) => {
    LOG.info(`Handling GET /edit/:id ${req}`)
    const id = parseInt(req.params.id)
    Model.find({ _id: id }, (err, results) => {
      if (err) { return res.end(notfoundstring) }
      LOG.info(`RETURNING VIEW FOR${JSON.stringify(results)}`)
      res.locals.addnewplace = results[0]
      return res.render('addnewplace/edit.ejs')
    })
  })
  
  // HANDLE EXECUTE DATA MODIFICATION REQUESTS --------------------------------------------
  
  // POST /save
  api.post('/save', (req, res) => {
    LOG.info(`Handling POST ${req}`)
    LOG.debug(JSON.stringify(req.body))
    const item = new Model()
    LOG.info(`NEW ID ${req.body._id}`)
    item._id = parseInt(req.body._id)
    item.address = req.body.address
    item.city = req.body.city
    item.state = req.body.state
    item.zip = req.body.zip
    item.country = req.body.country
    item.save((err) => {
      console.log(err);
      if (err) { return res.end(err) }
      LOG.info(`SAVING NEW item ${JSON.stringify(item)}`)
      return res.redirect('/addnewplace')
    })
  })
  
  // POST save with id
  api.post('/save/:id', (req, res) => {
    LOG.info(`Handling SAVE request ${req}`)
    const id = parseInt(req.params.id)
    LOG.info(`Handling SAVING ID=${id}`)
    Model.updateOne({ _id: id },
      { // use mongoose field update operator $set
        $set: {
          address: req.body.address,
          city: req.body.city,
          state: req.body.state,
          zip: req.body.zip,
          country: req.body.country,
        }
      },
      (err, item) => {
        if (err) { return res.end(notfoundstring) }
        LOG.info(`ORIGINAL VALUES ${JSON.stringify(item)}`)
        LOG.info(`UPDATED VALUES: ${JSON.stringify(req.body)}`)
        LOG.info(`SAVING UPDATED item ${JSON.stringify(item)}`)
        return res.redirect('/addnewplace')
      })
  })
  
  // DELETE id (uses HTML5 form method POST)
  api.post('/delete/:id', (req, res) => {
    LOG.info(`Handling DELETE request ${req}`)
    const id = parseInt(req.params.id)
    LOG.info(`Handling REMOVING ID=${id}`)
    Model.remove({ _id: id }).setOptions({ single: true }).exec((err, deleted) => {
      if (err) { return res.end(notfoundstring) }
      console.log(`Permanently deleted item ${JSON.stringify(deleted)}`)
      return res.redirect('/addnewplace')
    })
  })
  
  module.exports = api
  