Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ameer's API HW #12

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
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
53 changes: 53 additions & 0 deletions APIREADME.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
JSON API Endpoint Response JSON
============= =============

GET /api/profile [
name: "Ameer Brown",

profile_image: "https://scontent-lax3-1.xx.fbcdn.net/hphotos-xla1/v/t1.0-9/12938145_10206331753508701_5342059587620019442_n.jpg?oh=d6082eafa625e23dad5470cc10df75cd&oe=57BE0B76",

github_link: "https://github.com/Ameer-Brown/express-personal-api.git",

born: "Queens, NY",

current_city: "Oakland, CA",

height: "6'3",

favorite_food: "Italian",


]

POST /api/memories [
{
_id: 1,
name: 'Tony',
funniest_memory: 'Ran From Neighbors Dog',
},
]

PUT /api/memories/_id [
{
_id: 1,
name: 'Tony',
funniest_memory: 'Ran From Neighbors Dog',
},
]


GET /api/memories/_id [
{
_id: 1,
name: 'Tony',
funniest_memory: 'Ran From Neighbors Dog',
},
]

DELETE /api/memories/_id [
{
_id: 1,
name: 'Tony',
funniest_memory: 'Ran From Neighbors Dog',
},
]
10 changes: 0 additions & 10 deletions models/campsite.js.example

This file was deleted.

3 changes: 2 additions & 1 deletion models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ mongoose.connect( process.env.MONGOLAB_URI ||
process.env.MONGOHQ_URL ||
"mongodb://localhost/personal-api");

// module.exports.Campsite = require("./campsite.js.example");
module.exports.Profile = require("./profile.js");
module.exports.Memory = require("./memories.js");
12 changes: 12 additions & 0 deletions models/memories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var mongoose = require('mongoose'),
Schema = mongoose.Schema;

var memoriesSchema = new Schema({
_id: Number,
name: String,
funniest_memory: String,
});

var Memory = mongoose.model('Memory', memoriesSchema);

module.exports = Memory;
10 changes: 10 additions & 0 deletions models/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var mongoose = require('mongoose'),
Schema = mongoose.Schema;

var profileSchema = new Schema({
description: String
});

var Profile = mongoose.model('Profile', profileSchema);

module.exports = Profile;
Binary file added public/images/Brain.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 114 additions & 1 deletion public/scripts/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,120 @@
console.log("Sanity Check: JS is working!");

var template;
var $mems;
var allMemories = [];

$(document).ready(function(){

// your code
$mems = $('#mems');


var source = $('#memory-template').html();
template = Handlebars.compile(source);

$.ajax({
method: 'GET',
url: '/api/',
success: handleSuccess,
error: handleError
});

$.ajax({
method: 'GET',
url: '/api/profile',
success: handleSuccess,
error: handleError
});

$('#newMemoryForm').on('submit', function(e) {
e.preventDefault();
console.log('new mem serialized', $(this).serializeArray());
$.ajax({
method: 'POST',
url: '/api/memories',
data: $(this).serializeArray(),
success: newMemorySuccess,
error: newMemoryError
});
});

$mems.on('click', '.deleteBtn', function() {
console.log('clicked delete button to', '/api/memories/'+$(this).attr('data-id'));
$.ajax({
method: 'DELETE',
url: '/api/memories/'+$(this).attr('data-id'),
success: deleteMemorySuccess,
error: deleteMemoryError
});
});

$mems.on('submit', '#updateMemoryForm', function(e) {
e.preventDefault();
console.log('new memory');
$.ajax({
method: 'PUT',
url: '/api/memories/'+$(this).attr('data-id'),
data: $(this).serializeArray(),
success: newCharacterSuccess,
error: newCharacterError
});
});

});


function render () {
$mems.empty();
var memsHtml = template({ Memories: allMemories });
$mems.append(memsHtml);
}

function handleSuccess(json) {
allMemories = json;
render();
}

function handleError(e) {
console.log('woops');
$('#mems').text('Houston, we have a problem!');
}

function newMemorySuccess(json) {
$('#newMemoryForm input').val('');
allMemories.push(json);
render();
}

function newMemoryError() {
console.log('woops new mem!');
}


function updateMemorySuccess(json) {
$('#updateMemoryForm input').val('');
allMemories.push(json);
render();
}

function updateMemoryError() {
console.log('woops new mem!');
}

function deleteMemorySuccess(json) {
var memory = json;
console.log(json);
var memoryId = memory._id;
console.log('delete memory', memoryId);

for(var i = 0; i < allmemories.length; i++) {
if(allmemories[i]._id === memoryId) {
allMemories.splice(index, 1);
break;
}
}
render();
}

function deleteMemoryError() {
console.log('delete memory error!');
}
67 changes: 67 additions & 0 deletions public/styles/Style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
header {
text-align: center;
background: url(/images/Brain.JPG);
background-size: cover;
color: White;
}
h1 {
color: White;
text-align: center;
font-size: 75px;
font: Lucida Sans;
border-radius: 75px;
opacity: 1px;
}
h2 {text-align: center;
color: black;
font-size: 75px;
text-decoration: underline;
text-shadow: -0.06em 0 red, 0.06em 0 cyan;
padding-bottom: .1px;
}
h4 {text-align: center;
color: black;
}
ul {padding: 5px;
color: green;
}
img {
margin: 40px 0px 0px 0px;
border: 7px dotted white;
border-radius: 20px;*/
}
li {
display: inline;
padding: 8px;
margin-bottom: 7px;
background-color :#e3e8e8;
background-border: 5px black;
border-radius: 20px;
color: White;
opacity: .75;
}
a {
margin: 40px 0px 0px 0px
}
fieldset {
max-width: 300px;
}
article {
font: lucida;
max-width: 800px;
padding: 5px;
margin: 0 auto;
}
input {
display: block;
padding:
}
@media (max-width: 500px) {
h1 {
font-size: 36px;
}
li {
display: block;
padding: 5px;
}
}
40 changes: 31 additions & 9 deletions seed.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
// 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."}
var profile = [
{name: "Ameer Brown"},

// db.Campsite.create(new_campsite, function(err, campsite){
// if (err){
// return console.log("Error:", err);
// }
{profile_image: "https://scontent-lax3-1.xx.fbcdn.net/hphotos-xla1/v/t1.0-9/12938145_10206331753508701_5342059587620019442_n.jpg?oh=d6082eafa625e23dad5470cc10df75cd&oe=57BE0B76"},

// console.log("Created new campsite", campsite._id)
// process.exit(); // we're all done! Exit the program.
// })
{github_link: "https://github.com/Ameer-Brown/express-personal-api.git"},

{born: "Queens, NY"},

{current_city: "Oakland, CA"},

{height: "6'3"},

{favorite_food: "Italian"},


];

var new_memory = {_id: 1,
name: 'Tony',
funniest_memory: 'Ran From Neighbors Dog',
};

db.Memory.create(new_memory, function(err, memory){
if (err){ return console.log('err', err); }
else {
console.log("Created new memory");
}
});

process.exit(); // we're all done! Exit the program.
});
Loading