Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
**/node_modules

DS_Store
40 changes: 40 additions & 0 deletions controllers/apiController.js
Original file line number Diff line number Diff line change
@@ -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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File looks good!
Once a file is complete, remove unused pseudocode and delete extra spaces.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Carlynn.

// // 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
// ]
// })
// });



5 changes: 5 additions & 0 deletions controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
api: require('./apiController'),
shops: require('./shopsController'),
// albumsSongs: require('./albumsSongscontroller')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadness. Make sure delete commented out code - especially if it's pasted from another project.

}
21 changes: 21 additions & 0 deletions controllers/shopCreateController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// shopsSongsController
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you use this file - there is no route to it? Maybe this should be deleted. Also again, if you're cutting and pasting from another project make sure you remove the comments (or change them) in the current project.

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
};
71 changes: 71 additions & 0 deletions controllers/shopsController.js
Original file line number Diff line number Diff line change
@@ -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);
});
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code style is just as important as the code itself. Moving forward we're going to be more focused on ensuring you're writing with the industry best practices. This many spaces between functions is not best practice.
















// export public methods here
module.exports = {
index: index,
create: create,
show: show,
destroy: destroy,
// update: update
};
7 changes: 6 additions & 1 deletion models/index.js
Original file line number Diff line number Diff line change
@@ -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;
23 changes: 23 additions & 0 deletions models/shop.js
Original file line number Diff line number Diff line change
@@ -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;





2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Binary file added public/images/adba.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/bakers.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/dbreeders.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/ddaycare.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/dog-grooming.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/dog-header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/dog_lovers.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/gshop.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/pup_eyes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/wallpaper.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
171 changes: 170 additions & 1 deletion public/scripts/app.js
Original file line number Diff line number Diff line change
@@ -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 = (`
<div class="card card-shop" data-shop-id = "${shop._id}">
<div class="card-image waves-effect waves-block waves-light">
<img class="activator" src="${shop.image}">
</div>
<div class="card-content">
<span class="card-title activator grey-text text-darken-4">${shop.shopName}<i class="material-icons right">${shop.careTakerType}</i></span>
<p><a href="#">${shop.website}</a></p>

</div>
<div class="card-reveal">
<span class="card-title grey-text text-darken-4">${shop.address}<i class="material-icons right">${shop.phoneNumber}</i></span>
<p>Here is some more information about this product that is only revealed once clicked on.</p>
</div>
<div class='card-footer hidden' >
<button class='btn btn-info edit-shop'>Edit Shop</button>
<button class='btn btn-danger delete-shop'>Delete</button>
</div>
</div>`);
$('#shops').prepend(shopsHTML)

};


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of spaces... are these needed?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No they're not Carlynn. Jevell tighten this code up!











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,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try editing the url. Instead of shopId use $(this).attr('data-id')

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);
});
}
Loading