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

Ray's Personal API work #25

Open
wants to merge 10 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
**/node_modules
/node_modules

.DS_Stores
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Now that we're deployed, it's time to start coding your "personal" api!
- One cool way to do this is to create an endpoint at `/api` that describes all the available endpoints. We've set you up with an example in `server.js`. Make sure to update it to fill it in with your own information!
+ Here's a good example student `/api` endpoint:
<img width="500" alt="example api documentation" src="https://cloud.githubusercontent.com/assets/1489337/22841538/dc0b7f26-ef86-11e6-9a56-013bbe51792a.png">

+ See the [Open API Initiative](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#paths-object-example) for what this looks like in practice.
- **A Profile Endpoint** (`/api/profile`) that responds with *hard-coded* data:

Expand Down
16 changes: 16 additions & 0 deletions controllers/apiController.js
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
}
4 changes: 4 additions & 0 deletions controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
api: require('./apiController'),
profile: require('./profileController'),
}
107 changes: 107 additions & 0 deletions controllers/profileController.js
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
Copy link

Choose a reason for hiding this comment

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

Commented out code :(

// 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) {
Copy link

Choose a reason for hiding this comment

The 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);
Copy link

Choose a reason for hiding this comment

The 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
};
10 changes: 0 additions & 10 deletions models/campsite.js.example

This file was deleted.

9 changes: 7 additions & 2 deletions 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/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");
19 changes: 19 additions & 0 deletions models/profile.js
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;
43 changes: 43 additions & 0 deletions public/images/assets/edit.svg
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/social/github.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/social/linkedin.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/social/original/github.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/userimages/anil.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/userimages/carlynn.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/userimages/connor.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/userimages/ericchoi.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/userimages/ganesh.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/userimages/huan.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/userimages/jevell.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/userimages/krishna.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/userimages/ray.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/userimages/tommy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading