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 = (` +
+
+ +
+
+ ${shop.shopName}${shop.careTakerType} +

${shop.website}

+ +
+
+ ${shop.address}${shop.phoneNumber} +

Here is some more information about this product that is only revealed once clicked on.

+
+ +
`); +$('#shops').prepend(shopsHTML) + +}; + + + + + + + + + + + + +function handleAddShopClick(e) { + console.log('add-shop clicked!'); + var currentShopId = $(this).closest('.card-shop').data('shop-id'); // "5665ff1678209c64e51b4e7b" + console.log('id',currentShopId); + $('#modal1').data('shop-id', currentShopId); + $('#modal1').modal(); // display the modal! +} + + + + +function handleDeleteShopClick(e) { + console.log('store deleted!'); + var shop = $(this).closest('.card-shop'); + console.log(shop); + var shopId = shop.data('shop-id') + console.log('id', shopId); + $.ajax ({ + method: 'DELETE', + url: '/api/shops/' + shopId, + success: function() { + shop.remove() + } + + }) +} + + + + + + + + + + + + + + + + +// when the song modal submit button is clicked: +function handleNewShopSubmit(e) { + e.preventDefault(); + var $modal = $('#modal1'); + var $NameField = $modal.find('#name'); + var $Address = $modal.find('#textarea1'); + var $telephone = $modal.find('#tel'); + var $website = $modal.find('#url'); + // get data from modal fields + // note the server expects the keys to be 'name', 'trackNumber' so we use those. + var dataToPost = { + name: $NameField.val(), + address: $Address.val(), + phoneNumber: $telephone.val(), + website: $website.val(), + }; + + + + // POST to SERVER + var shopPostToServerUrl = '/api/shops/' ; + $.post(shopPostToServerUrl, dataToPost, function(data) { + console.log('received data from post to /shops:', data); + + // clear form + $NameField.val(''); + $Address.val(''); + $telephone.val(''); + $website.val(''); + // close modal + + // update the correct shop to show the new song + // re-render it with the new shop data (including songs) + renderShop(data); + }).fail(function(err) { + console.log('post to /api/shops/:shopId/shops resulted in error', err); + }); +} \ No newline at end of file diff --git a/public/styles/styles.css b/public/styles/styles.css index 57b4da0e..b612e10e 100644 --- a/public/styles/styles.css +++ b/public/styles/styles.css @@ -1,10 +1,39 @@ body { + color: #333; font-family: Helvetica, Arial, sans-serif; - background-color: skyblue; /* Sanity Check! */ + background-color: white; /* Sanity Check! */ } h1 { margin-top: 100px; text-align: center; } + +#dlover { + + max-width: 100%; +} + +.nav-wrapper { + background-color: black; + color: black; +} + +.rating { + unicode-bidi: bidi-override; + direction: rtl; +} +.rating > span { + display: inline-block; + position: relative; + width: 1.1em; +} +.rating > span:hover:before, +.rating > span:hover ~ span:before { + content: "\2605"; + position: absolute; +} +.check { + display: inline-block; +} \ No newline at end of file diff --git a/seed.js b/seed.js index 896dead0..2916ba63 100644 --- a/seed.js +++ b/seed.js @@ -1,7 +1,7 @@ // This file allows us to seed our application with data // simply run: `node seed.js` from the root of this project folder. -// var db = require('./models'); +var db = require('./models'); // var new_campsite = {description: "Sharp rocks. Middle of nowhere."} @@ -13,3 +13,54 @@ // console.log("Created new campsite", campsite._id) // process.exit(); // we're all done! Exit the program. // }) + + +var dogShop =[]; + +dogShop.push({ + shopName: 'dogs R Us', + careTakerType: 'GROOMER', + address: '1234 jank drive ', + phoneNumber: [ '281-330-8004' ], + website: ['www.checkmeOut.com'], + image: '../images/gshop.jpg', + }); +dogShop.push({ + shopName: 'dogs 4 you', + careTakerType: 'Breeder', + address: '3456 chillout drive', + phoneNumber: [ '281-330-8004' ], + website: ['www.checkOnMe.com'], + image: '../images/dbreeders.jpeg', + }); +dogShop.push({ + shopName: 'My Dogz', + careTakerType: 'Breeder', + address: '777 The Homies lane', + phoneNumber: [ '414-444-4444' ], + website: ['doggyduties.com'], + image: '../images/ddaycare.jpg', + }); +dogShop.push({ + shopName: 'PAWS PLEASE', + careTakerType: 'Groomer', + address: '3487 Nth GA drive', + phoneNumber: [ '925-949-7278' ], + website: ['www.Pawsplease.com'], + image: '../images/adba.jpg', + }); + + + + + +db.Shop.remove({}, function(err, shops){ + + db.Shop.create(dogShop, function(err, shops){ + if (err) { return console.log('ERROR', err); } + console.log("all shops:", shops); + console.log("created", shops.length, "shops"); + process.exit(); + }); + +}); \ No newline at end of file diff --git a/server.js b/server.js index fd366289..72259a5a 100644 --- a/server.js +++ b/server.js @@ -1,6 +1,6 @@ // require express and other modules -var express = require('express'), - app = express(); +var express = require('express') +var app = express(); // parse incoming urlencoded form data // and populate the req.body object @@ -19,7 +19,8 @@ app.use(function(req, res, next) { * DATABASE * ************/ -// var db = require('./models'); + +var controllers = require('./controllers'); /********** * ROUTES * @@ -33,6 +34,8 @@ app.use(express.static('public')); * HTML Endpoints */ + + app.get('/', function homepage(req, res) { res.sendFile(__dirname + '/views/index.html'); }); @@ -42,22 +45,12 @@ app.get('/', function homepage(req, res) { * JSON API Endpoints */ -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: "http://YOUR-APP-NAME.herokuapp.com", // CHANGE ME - 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 - ] - }) -}); +app.get('/api', controllers.api.index); +app.get('/api/shops', controllers.shops.index); +app.get('/api/shops', controllers.shops.show); + +app.post('/api/shops', controllers.shops.create); +app.delete('/api/shops/:shopId', controllers.shops.destroy); /********** * SERVER * diff --git a/views/index.html b/views/index.html index 48e39ae6..088610ca 100644 --- a/views/index.html +++ b/views/index.html @@ -1,29 +1,128 @@ - - - + + + - Blank + Dog Shop - - - + + + + + - - + + + - - - - -
-
+ + + + + + + + +
+ +
+
+
-

Under Construction

-

Read My API Documentation

+ + + + +
- +
+
+ + + + + +

Under Construction

+
+
+
+
+
+
+
+ + + +
+
+ +