forked from sf-wdi-25/express_self_api
-
Notifications
You must be signed in to change notification settings - Fork 54
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
Ray's Personal API work #25
Open
raybchoi
wants to merge
10
commits into
SF-WDI-LABS:master
Choose a base branch
from
raybchoi:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
64533ba
ready for heroku deploy attempt #1
raybchoi b6e9cd3
added GET route and updated SRP and Profile view
raybchoi f01a292
ability to update a user profile
raybchoi 6523b85
updated with ability to edit and new seed data
raybchoi f09076b
upload photo and create a new perosn working
raybchoi 931bba9
catch message
raybchoi dc98d9e
added ability to edit and update
raybchoi 0fadf4a
updated mailto, functionality, and contact me
raybchoi 31c1030
upaded spelling, seed, css, and ability to add photo upon create and …
raybchoi 54c7eb2
update the the toggle
raybchoi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
**/node_modules | ||
/node_modules | ||
|
||
.DS_Stores |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function index(req, res) { | ||
res.json({ | ||
message: "Welcome to my personal api! Here's what you need to know!", | ||
documentation_url: "https://github.com/example-username/express-personal-api/README.md", | ||
base_url: "localhost:3000", | ||
endpoints: [ | ||
{ | ||
method: "GET", path: "/api", description: "Describes available endpoints" | ||
} | ||
] | ||
}); | ||
} | ||
|
||
module.exports = { | ||
index: index | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
api: require('./apiController'), | ||
profile: require('./profileController'), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/************ | ||
* DATABASE * | ||
************/ | ||
|
||
const db = require('../models'); | ||
|
||
|
||
// GET renderSearchResults => on load of the page what to be able to render the search results page which loads the 10 people in the database | ||
// append profileSRP from the SRP section | ||
// fill in the correct user information | ||
|
||
// Function to send back everything | ||
// function searchResultsPage(req, res) { | ||
// console.log('SRP is getting data') | ||
// db.Profile.find({}, function(err, allProfiles) { | ||
// res.json(allProfiles) | ||
// }) | ||
// res.status(200) | ||
// }; | ||
|
||
// function that ONLY sends back ones that are NOT marked for delation => used for initial SRP | ||
function searchResultsPage(req, res) { | ||
console.log('SRP is getting data') | ||
db.Profile.find({}, function(err, allProfiles) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. db.Profile.find({markedForDeletion: false}, ...) |
||
let arrayOfProfilesToBeShown = []; | ||
let arrayOfProfilesMarkedForDeletion = []; | ||
allProfiles.forEach(function(profile) { | ||
if ( profile.markedForDeletion === false) { | ||
arrayOfProfilesToBeShown.push(profile); | ||
} else { | ||
arrayOfProfilesMarkedForDeletion.push(profile); | ||
} | ||
}); | ||
res.json(arrayOfProfilesToBeShown); | ||
console.log('DONT SEND BACK', arrayOfProfilesMarkedForDeletion); | ||
}); | ||
}; | ||
|
||
// GET (SEND user ID) and renderProfile need to be able to click on a person, take that id and route them to a profile page | ||
|
||
function showOneProfile(req, res) { | ||
console.log('showOneProfile Route is getting hit', req.params.profileId); | ||
db.Profile.findById(req.params.profileId, function(err, foundProfile) { | ||
if (err) { | ||
console.log('showOneProfile in controller had an error', err); | ||
} | ||
// send back the Profile info the DB via json file | ||
res.json(foundProfile); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation is off, should be one left |
||
}); | ||
|
||
}; | ||
|
||
// POST createNewUser => able to create a new user on the SRP and then render that new person | ||
function createNewProfile(req, res) { | ||
console.log('CREATE NEW PROFILE', req.body) | ||
db.Profile.create(req.body, function(err, newProfile) { | ||
if (err) { | ||
console.log('ERROR ON CREATE', err) | ||
} | ||
res.json(newProfile); | ||
console.log('NEW PROFILE INFO SENT BACK', newProfile) | ||
}) | ||
}; | ||
|
||
|
||
|
||
// PUT able to update the user on the renderProfile page (able to update each spot individually) | ||
|
||
function updateOneProfile(req, res) { | ||
console.log('updateOneProfile Route is getting hit!!!', req.body) | ||
db.Profile.findByIdAndUpdate(req.params.profileId, {$set: { | ||
name: req.body.name, | ||
title: req.body.title, | ||
workPlace: req.body.workPlace, | ||
quote: req.body.quote, | ||
image: req.body.image, | ||
}}, {new: true}, function(err, saveProfile) { | ||
if (err) { | ||
console.log('THERE WAS AN ERROR DURING updateOneProfile Save', err); | ||
} | ||
console.log('updateOneProfile SAVED AND JSON IS SENT BACK', saveProfile); | ||
res.json(saveProfile) | ||
}) | ||
}; | ||
|
||
// DELETE / PUT able to 'hit the delete flag' and not show up the user anymore vs actually deleting their information | ||
|
||
function removeOneProfile(req, res) { | ||
console.log('removeOneProfile IS GETTING HITTT!!!!!', req.body) | ||
db.Profile.findByIdAndUpdate(req.params.profileId, {$set: { | ||
markedForDeletion: req.body.markedForDeletion}}, {new: true}, function(err, removedProfile) { | ||
if (err) { | ||
console.log ('THERE WAS AN ERROR DURING removeOneProfile', err); | ||
} | ||
console.log('removeOneProfile SAVED and removed profile JSON sent back', removedProfile); | ||
res.json(removedProfile); | ||
}); | ||
|
||
}; | ||
|
||
module.exports = { | ||
searchResultsPage: searchResultsPage, | ||
createNewProfile: createNewProfile, | ||
showOneProfile: showOneProfile, | ||
updateOneProfile: updateOneProfile, | ||
removeOneProfile: removeOneProfile | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/personal-api", {useMongoClient: true}); | ||
mongoose.connect( process.env.MONGODB_URI || 'mongodb://localhost/personal-api' ); | ||
|
||
mongoose.Promise = global.Promise; // use native Promise | ||
|
||
// module.exports.Campsite = require("./campsite.js.example"); | ||
const Profile = require('./profile'); | ||
|
||
|
||
module.exports.Profile = require("./profile.js"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const mongoose = require("mongoose"); | ||
const Schema = mongoose.Schema; | ||
|
||
const ProfileSchema = new Schema({ | ||
name: String, | ||
userName: String, | ||
image: String, | ||
title: String, | ||
workPlace: String, | ||
quote: String, | ||
aboutMe: String, | ||
socialNetwork: [String], | ||
skills: [String], | ||
markedForDeletion: Boolean, | ||
}); | ||
|
||
const Profile = mongoose.model('Profile', ProfileSchema); | ||
|
||
module.exports = Profile; |
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.
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.
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.
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.
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.
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.
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented out code :(