diff --git a/.gitignore b/.gitignore index cf709889..368a3d3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ **/node_modules + +DS_Store \ No newline at end of file diff --git a/controllers/apiController.js b/controllers/apiController.js new file mode 100644 index 00000000..af519ccd --- /dev/null +++ b/controllers/apiController.js @@ -0,0 +1,40 @@ +function index(req, res) { + res.json({ + message: "Welcome to dogShopz!", + documentation_url: "https://agile-wildwood-44374.herokuapp.com/", + base_url: "localhost:3000", + endpoints: [ + { + method: "GET", path: "/api", description: "Describes available endpoints" + } + ] + }); +} + + + + + module.exports = { + index: index +} + + +// app.get('/api', function apiIndex(req, res) { +// // TODO: Document all your api endpoints below as a simple hardcoded JSON object. +// // It would be seriously overkill to save any of this to your database. +// // But you should change almost every line of this response. +// res.json({ +// // woopsIForgotToDocumentAllMyEndpoints: true, // CHANGE ME ;) +// message: "Welcome to my personal api! Here's what you need to know!", +// documentationUrl: "https://github.com/example-username/express-personal-api/README.md", // CHANGE ME +// baseUrl: "localhost:3000", +// endpoints: [ +// {method: "GET", path: "/api", description: "Describes all available endpoints"}, +// // {method: "GET", path: "/api/profile", description: "Data about me"}, // CHANGE ME +// // {method: "POST", path: "/api/campsites", description: "E.g. Create a new campsite"} // CHANGE ME +// ] +// }) +// }); + + + diff --git a/controllers/index.js b/controllers/index.js new file mode 100644 index 00000000..2354cea8 --- /dev/null +++ b/controllers/index.js @@ -0,0 +1,5 @@ +module.exports = { + api: require('./apiController'), + shops: require('./shopsController'), + // albumsSongs: require('./albumsSongscontroller') +} diff --git a/controllers/shopCreateController.js b/controllers/shopCreateController.js new file mode 100644 index 00000000..ce403df4 --- /dev/null +++ b/controllers/shopCreateController.js @@ -0,0 +1,21 @@ +// shopsSongsController +var db = require('../models'); + + +// POST '/api/shops/:shopId/songs' +function create(req, res) { + db.Shop.findById(req.params.shopId, function(err, foundShop) { + console.log(req.body); + var newShop = new db.Shop(req.body); // dangerous, in a real app we'd validate the incoming data + foundShop.shops.push(newShop); + foundShop.save(function(err, savedShop) { + console.log('newShop created: ', newShop); + res.json(newShop); // responding with just the song, some APIs may respond with the parent object (Album in this case) + }); + }); +} + + +module.exports = { + create: create +}; diff --git a/controllers/shopsController.js b/controllers/shopsController.js new file mode 100644 index 00000000..5169c717 --- /dev/null +++ b/controllers/shopsController.js @@ -0,0 +1,71 @@ +//Database + +var db = require('../models'); + +// GET /api/shops +function index(req, res) { + // send back all shops as JSON + db.Shop.find({}, function(err, allShops) { + res.json(allShops); + }); +} + +// POST /api/shops +function create(req, res) { + // create an shop based on request body and send it back as JSON + console.log('body', req.body); + + // split at comma and remove and trailing space + + db.Shop.create(req.body, function(err, shop) { + if (err) { console.log('error', err); } + console.log(shop); + res.json(shop); + }); +} + +// GET /api/albums/:shopId +function show(req, res) { + // find one album by id and send it back as JSON + db.Show.findById(req.params.showId, function(err, foundShop) { + if(err) { console.log('albumsController.show error', err); } + console.log('shopsController.show responding with', foundShop); + res.json(foundShop); + }); +} + + +// DELETE /api/albums/:albumId +function destroy(req, res) { + console.log(req.params.shopId) + // find one album by id, delete it, and send it back as JSON + db.Shop.findByIdAndRemove(req.params.shopId, function(err, deleteShop) { + if(err) { console.log('albumsController.destroy error', err); } + console.log('albumsController.destroy responding with', deleteShop); + res.json(deleteShop); + }); +} + + + + + + + + + + + + + + + + +// export public methods here +module.exports = { + index: index, + create: create, + show: show, + destroy: destroy, + // update: update +}; diff --git a/models/index.js b/models/index.js index 66997fe0..794829c0 100644 --- a/models/index.js +++ b/models/index.js @@ -1,5 +1,10 @@ var mongoose = require("mongoose"); -mongoose.connect( process.env.MONGODB_URI || "mongodb://localhost/personal-api", {useMongoClient: true}); +mongoose.connect( process.env.MONGODB_URI || "mongodb://localhost/dogs", {useMongoClient: true}); mongoose.Promise = global.Promise; // use native Promise // module.exports.Campsite = require("./campsite.js.example"); + + +var Shop = require('./shop'); + +module.exports.Shop = Shop; diff --git a/models/shop.js b/models/shop.js new file mode 100644 index 00000000..c8b19f59 --- /dev/null +++ b/models/shop.js @@ -0,0 +1,23 @@ +var mongoose = require("mongoose"); +var Schema = mongoose.Schema; + + +var Shop = require('./shop'); + +var ShopSchema = new Schema({ + shopName: String, + careTakerType: String, + address: String, + phoneNumber: String , + website: String, + image: String, +}); + +var Shop = mongoose.model('Shop', ShopSchema); + +module.exports = Shop; + + + + + diff --git a/package.json b/package.json index 22718d9e..23ebec1d 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "homepage": "https://github.com/SF-WDI-LABS/express-personal-api", "dependencies": { "body-parser": "^1.15.0", - "express": "^4.13.4", + "express": "^4.15.4", "mongoose": "^4.4.10" } } diff --git a/public/images/adba.jpg b/public/images/adba.jpg new file mode 100644 index 00000000..e47d5b5c Binary files /dev/null and b/public/images/adba.jpg differ diff --git a/public/images/bakers.jpg b/public/images/bakers.jpg new file mode 100644 index 00000000..8de23dd6 Binary files /dev/null and b/public/images/bakers.jpg differ diff --git a/public/images/dbreeders.jpeg b/public/images/dbreeders.jpeg new file mode 100644 index 00000000..448b3f6e Binary files /dev/null and b/public/images/dbreeders.jpeg differ diff --git a/public/images/ddaycare.jpg b/public/images/ddaycare.jpg new file mode 100644 index 00000000..12ab91cc Binary files /dev/null and b/public/images/ddaycare.jpg differ diff --git a/public/images/dog-grooming.png b/public/images/dog-grooming.png new file mode 100644 index 00000000..5028a5ca Binary files /dev/null and b/public/images/dog-grooming.png differ diff --git a/public/images/dog-header.png b/public/images/dog-header.png new file mode 100644 index 00000000..5bd5d5a9 Binary files /dev/null and b/public/images/dog-header.png differ diff --git a/public/images/dog_lovers.jpg b/public/images/dog_lovers.jpg new file mode 100644 index 00000000..0682fac8 Binary files /dev/null and b/public/images/dog_lovers.jpg differ diff --git a/public/images/dog_png_by_hammylulufluff_fluff-d5362a7.png b/public/images/dog_png_by_hammylulufluff_fluff-d5362a7.png new file mode 100644 index 00000000..6743b4b6 Binary files /dev/null and b/public/images/dog_png_by_hammylulufluff_fluff-d5362a7.png differ diff --git a/public/images/gshop.jpg b/public/images/gshop.jpg new file mode 100644 index 00000000..9b1173d5 Binary files /dev/null and b/public/images/gshop.jpg differ diff --git a/public/images/pup_eyes.png b/public/images/pup_eyes.png new file mode 100644 index 00000000..6743b4b6 Binary files /dev/null and b/public/images/pup_eyes.png differ diff --git a/public/images/wallpaper.jpg b/public/images/wallpaper.jpg new file mode 100644 index 00000000..ac2be3be Binary files /dev/null and b/public/images/wallpaper.jpg differ diff --git a/public/scripts/app.js b/public/scripts/app.js index 00988cd4..ab58ed5d 100644 --- a/public/scripts/app.js +++ b/public/scripts/app.js @@ -1,7 +1,176 @@ console.log("Sanity Check: JS is working!"); $(document).ready(function(){ + //initialize all modals + $('.modal').modal(); + $('select').material_select(); + + $.ajax({ + method: 'GET', + url: '/api/shops', + success: renderAllShops + }); + + + + + + + $('#shop-form form').on('submit', function(e) { + e.preventDefault(); + var formData = $(this).serialize(); + console.log('formData', formData); + $.post('/api/shops', formData, function(shop) { + console.log('shop after POST', shop); + renderShop(shop); //render the server's response + }); + $(this).trigger("reset"); + }); + + // catch and handle the click on an add song button + $('#modal1').on('click', '#submit', handleAddShopClick); + $('#submit').on('click', handleNewShopSubmit); + $('#shops').on('click','.delete-shop', handleDeleteShopClick); + + -// your code }); + + + +function renderAllShops (shops) { + + shops.forEach(function (shop) { + console.log(shops) + renderShop(shop); + }); +} + + + + + + + + + + +// render shop function +function renderShop (shop) { + console.log('Rending these damn pet shops', shop) + +var shopsHTML = (` +
Here is some more information about this product that is only revealed once clicked on.
+