diff --git a/controllers/thoughtController.js b/controllers/thoughtController.js index 1fe9194..e32a1cc 100644 --- a/controllers/thoughtController.js +++ b/controllers/thoughtController.js @@ -2,13 +2,53 @@ var mongoose = require('mongoose'); var thoughtModel = mongoose.model('thoughtModel'); +var userModel = mongoose.model('userModel'); + //GET - Return all tvshows in the DB exports.findAllThoughts = function(req, res) { + thoughtModel.find(function(err, thoughts) { - if(err) res.send(500, err.message); + if(err) res.send(500, err.message); + + console.log(thoughts.length); + thoughts=JSON.parse(JSON.stringify(thoughts)); + + thoughts.forEach(function(thought, index, array){ + +array=JSON.parse(JSON.stringify(array)); + + userModel.find({ + username: thought.authorname + }, function(err, user) { + + if (err) throw err; + + if (!user) { + + } else if (user) { + + /*console.log(thought); + console.log(user);*/ + array[index].usericon=user[0].icon; + + console.log("icon: " + array[index].usericon); + //thought.set('icon', user.icon); + //console.log(thought); + + + } + + if(index === array.length-1) + { + console.log('GET /thoughts'); + console.log(array); + res.status(200).jsonp(array); + } + }); + + + }); - console.log('GET /thoughts'); - res.status(200).jsonp(thoughts); }); }; diff --git a/controllers/userController.js b/controllers/userController.js index c4e8ef1..415241d 100644 --- a/controllers/userController.js +++ b/controllers/userController.js @@ -22,7 +22,7 @@ exports.findAllUsers = function(req, res) { //GET - Return a TVShow with specified ID exports.findById = function(req, res) { - ActivityModel.findById(req.params.id, function(err, user) { + userModel.findById(req.params.id, function(err, user) { if(err) return res.send(500, err.message); console.log('GET /users/' + req.params.id); @@ -30,6 +30,25 @@ exports.findById = function(req, res) { }); }; +exports.findUserByUsername = function(req, res) { + userModel.find({ + username: req.params.username + }, function(err, user) { + + if (err) throw err; + + if (!user) { + res.json({ success: false, message: 'no user found' }); + } else if (user) { + console.log(user); + // return the information including token as JSON + res.jsonp(user); + + + } + + }); +}; //POST - Insert a new TVShow in the DB exports.addUser = function(req, res) { diff --git a/server.js b/server.js index 84fc2c0..c60dfcc 100755 --- a/server.js +++ b/server.js @@ -46,6 +46,10 @@ var apiRoutes = express.Router(); apiRoutes.route('/users') .get(userCtrl.findAllUsers) .post(userCtrl.addUser); +apiRoutes.route('/users/:id') + .get(userCtrl.findById); +apiRoutes.route('/users/byusername/:username') + .get(userCtrl.findUserByUsername); apiRoutes.route('/thoughts/user/:userid') .get(thoughtCtrl.findAllThoughtsFromUsername); @@ -91,7 +95,6 @@ apiRoutes.use(function(req, res, next) { }); apiRoutes.route('/users/:id') - .get(userCtrl.findById) .put(userCtrl.updateActivity) .delete(userCtrl.deleteActivity); diff --git a/web/img/icons/animals/anteater.png b/web/img/icons/animals/anteater.png new file mode 100644 index 0000000..798416a Binary files /dev/null and b/web/img/icons/animals/anteater.png differ diff --git a/web/img/icons/animals/bat.png b/web/img/icons/animals/bat.png new file mode 100644 index 0000000..0516c08 Binary files /dev/null and b/web/img/icons/animals/bat.png differ diff --git a/web/img/icons/animals/beetle.png b/web/img/icons/animals/beetle.png new file mode 100644 index 0000000..0f9bd08 Binary files /dev/null and b/web/img/icons/animals/beetle.png differ diff --git a/web/img/icons/animals/bulldog.png b/web/img/icons/animals/bulldog.png new file mode 100644 index 0000000..a40bf36 Binary files /dev/null and b/web/img/icons/animals/bulldog.png differ diff --git a/web/img/icons/animals/butterfly.png b/web/img/icons/animals/butterfly.png new file mode 100644 index 0000000..e880707 Binary files /dev/null and b/web/img/icons/animals/butterfly.png differ diff --git a/web/img/icons/animals/camel.png b/web/img/icons/animals/camel.png new file mode 100644 index 0000000..dedf394 Binary files /dev/null and b/web/img/icons/animals/camel.png differ diff --git a/web/img/icons/animals/cat.png b/web/img/icons/animals/cat.png new file mode 100644 index 0000000..2da894e Binary files /dev/null and b/web/img/icons/animals/cat.png differ diff --git a/web/img/icons/animals/chameleon.png b/web/img/icons/animals/chameleon.png new file mode 100644 index 0000000..91f30f6 Binary files /dev/null and b/web/img/icons/animals/chameleon.png differ diff --git a/web/img/icons/animals/clown-fish.png b/web/img/icons/animals/clown-fish.png new file mode 100644 index 0000000..2473fcc Binary files /dev/null and b/web/img/icons/animals/clown-fish.png differ diff --git a/web/img/icons/animals/cobra.png b/web/img/icons/animals/cobra.png new file mode 100644 index 0000000..bdede1f Binary files /dev/null and b/web/img/icons/animals/cobra.png differ diff --git a/web/img/icons/animals/cow.png b/web/img/icons/animals/cow.png new file mode 100644 index 0000000..36c0ab0 Binary files /dev/null and b/web/img/icons/animals/cow.png differ diff --git a/web/img/icons/animals/crab.png b/web/img/icons/animals/crab.png new file mode 100644 index 0000000..673710d Binary files /dev/null and b/web/img/icons/animals/crab.png differ diff --git a/web/img/icons/animals/crocodile.png b/web/img/icons/animals/crocodile.png new file mode 100644 index 0000000..a0cc9fb Binary files /dev/null and b/web/img/icons/animals/crocodile.png differ diff --git a/web/img/icons/animals/duck.png b/web/img/icons/animals/duck.png new file mode 100644 index 0000000..2c48212 Binary files /dev/null and b/web/img/icons/animals/duck.png differ diff --git a/web/img/icons/animals/elephant.png b/web/img/icons/animals/elephant.png new file mode 100644 index 0000000..8fc8238 Binary files /dev/null and b/web/img/icons/animals/elephant.png differ diff --git a/web/img/icons/animals/frog.png b/web/img/icons/animals/frog.png new file mode 100644 index 0000000..c41de7c Binary files /dev/null and b/web/img/icons/animals/frog.png differ diff --git a/web/img/icons/animals/giraffe.png b/web/img/icons/animals/giraffe.png new file mode 100644 index 0000000..178bfcc Binary files /dev/null and b/web/img/icons/animals/giraffe.png differ diff --git a/web/img/icons/animals/hen.png b/web/img/icons/animals/hen.png new file mode 100644 index 0000000..7bd5bbf Binary files /dev/null and b/web/img/icons/animals/hen.png differ diff --git a/web/img/icons/animals/hippopotamus.png b/web/img/icons/animals/hippopotamus.png new file mode 100644 index 0000000..b8987cf Binary files /dev/null and b/web/img/icons/animals/hippopotamus.png differ diff --git a/web/img/icons/animals/kangaroo.png b/web/img/icons/animals/kangaroo.png new file mode 100644 index 0000000..c73debf Binary files /dev/null and b/web/img/icons/animals/kangaroo.png differ diff --git a/web/img/icons/animals/lion.png b/web/img/icons/animals/lion.png new file mode 100644 index 0000000..3865da6 Binary files /dev/null and b/web/img/icons/animals/lion.png differ diff --git a/web/img/icons/animals/llama.png b/web/img/icons/animals/llama.png new file mode 100644 index 0000000..d02bfef Binary files /dev/null and b/web/img/icons/animals/llama.png differ diff --git a/web/img/icons/animals/macaw.png b/web/img/icons/animals/macaw.png new file mode 100644 index 0000000..d8306a6 Binary files /dev/null and b/web/img/icons/animals/macaw.png differ diff --git a/web/img/icons/animals/monkey.png b/web/img/icons/animals/monkey.png new file mode 100644 index 0000000..433176d Binary files /dev/null and b/web/img/icons/animals/monkey.png differ diff --git a/web/img/icons/animals/moose.png b/web/img/icons/animals/moose.png new file mode 100644 index 0000000..cbae9e8 Binary files /dev/null and b/web/img/icons/animals/moose.png differ diff --git a/web/img/icons/animals/mouse.png b/web/img/icons/animals/mouse.png new file mode 100644 index 0000000..1d6d69a Binary files /dev/null and b/web/img/icons/animals/mouse.png differ diff --git a/web/img/icons/animals/octopus.png b/web/img/icons/animals/octopus.png new file mode 100644 index 0000000..427c31c Binary files /dev/null and b/web/img/icons/animals/octopus.png differ diff --git a/web/img/icons/animals/ostrich.png b/web/img/icons/animals/ostrich.png new file mode 100644 index 0000000..e4497e4 Binary files /dev/null and b/web/img/icons/animals/ostrich.png differ diff --git a/web/img/icons/animals/owl.png b/web/img/icons/animals/owl.png new file mode 100644 index 0000000..732dc88 Binary files /dev/null and b/web/img/icons/animals/owl.png differ diff --git a/web/img/icons/animals/panda.png b/web/img/icons/animals/panda.png new file mode 100644 index 0000000..e06893c Binary files /dev/null and b/web/img/icons/animals/panda.png differ diff --git a/web/img/icons/animals/pelican.png b/web/img/icons/animals/pelican.png new file mode 100644 index 0000000..547041f Binary files /dev/null and b/web/img/icons/animals/pelican.png differ diff --git a/web/img/icons/animals/penguin.png b/web/img/icons/animals/penguin.png new file mode 100644 index 0000000..295e7f1 Binary files /dev/null and b/web/img/icons/animals/penguin.png differ diff --git a/web/img/icons/animals/pig.png b/web/img/icons/animals/pig.png new file mode 100644 index 0000000..1f3f237 Binary files /dev/null and b/web/img/icons/animals/pig.png differ diff --git a/web/img/icons/animals/rabbit.png b/web/img/icons/animals/rabbit.png new file mode 100644 index 0000000..cf23843 Binary files /dev/null and b/web/img/icons/animals/rabbit.png differ diff --git a/web/img/icons/animals/racoon.png b/web/img/icons/animals/racoon.png new file mode 100644 index 0000000..c4d3418 Binary files /dev/null and b/web/img/icons/animals/racoon.png differ diff --git a/web/img/icons/animals/ray.png b/web/img/icons/animals/ray.png new file mode 100644 index 0000000..f421efd Binary files /dev/null and b/web/img/icons/animals/ray.png differ diff --git a/web/img/icons/animals/rhinoceros.png b/web/img/icons/animals/rhinoceros.png new file mode 100644 index 0000000..0d2601e Binary files /dev/null and b/web/img/icons/animals/rhinoceros.png differ diff --git a/web/img/icons/animals/sea-cow.png b/web/img/icons/animals/sea-cow.png new file mode 100644 index 0000000..6585715 Binary files /dev/null and b/web/img/icons/animals/sea-cow.png differ diff --git a/web/img/icons/animals/shark.png b/web/img/icons/animals/shark.png new file mode 100644 index 0000000..24804b7 Binary files /dev/null and b/web/img/icons/animals/shark.png differ diff --git a/web/img/icons/animals/sheep.png b/web/img/icons/animals/sheep.png new file mode 100644 index 0000000..451bfde Binary files /dev/null and b/web/img/icons/animals/sheep.png differ diff --git a/web/img/icons/animals/siberian-husky.png b/web/img/icons/animals/siberian-husky.png new file mode 100644 index 0000000..9de786f Binary files /dev/null and b/web/img/icons/animals/siberian-husky.png differ diff --git a/web/img/icons/animals/sloth.png b/web/img/icons/animals/sloth.png new file mode 100644 index 0000000..2f7322a Binary files /dev/null and b/web/img/icons/animals/sloth.png differ diff --git a/web/img/icons/animals/snake.png b/web/img/icons/animals/snake.png new file mode 100644 index 0000000..19567d9 Binary files /dev/null and b/web/img/icons/animals/snake.png differ diff --git a/web/img/icons/animals/spider.png b/web/img/icons/animals/spider.png new file mode 100644 index 0000000..4c5fc5b Binary files /dev/null and b/web/img/icons/animals/spider.png differ diff --git a/web/img/icons/animals/squirrel.png b/web/img/icons/animals/squirrel.png new file mode 100644 index 0000000..f4afbd3 Binary files /dev/null and b/web/img/icons/animals/squirrel.png differ diff --git a/web/img/icons/animals/swan.png b/web/img/icons/animals/swan.png new file mode 100644 index 0000000..713525a Binary files /dev/null and b/web/img/icons/animals/swan.png differ diff --git a/web/img/icons/animals/tiger.png b/web/img/icons/animals/tiger.png new file mode 100644 index 0000000..b85ee3d Binary files /dev/null and b/web/img/icons/animals/tiger.png differ diff --git a/web/img/icons/animals/toucan.png b/web/img/icons/animals/toucan.png new file mode 100644 index 0000000..d16afd8 Binary files /dev/null and b/web/img/icons/animals/toucan.png differ diff --git a/web/img/icons/animals/turtle.png b/web/img/icons/animals/turtle.png new file mode 100644 index 0000000..b589cba Binary files /dev/null and b/web/img/icons/animals/turtle.png differ diff --git a/web/img/icons/animals/whale.png b/web/img/icons/animals/whale.png new file mode 100644 index 0000000..db39b49 Binary files /dev/null and b/web/img/icons/animals/whale.png differ diff --git a/web/index.html b/web/index.html new file mode 100644 index 0000000..607817e --- /dev/null +++ b/web/index.html @@ -0,0 +1,64 @@ + + + + + + + + thoughts - main + + + + + + + + + + + + + + + + + + +
+
+ +
+ + + + + + + + + diff --git a/web/index.js b/web/index.js new file mode 100644 index 0000000..89ca382 --- /dev/null +++ b/web/index.js @@ -0,0 +1,89 @@ +var listThoughts; + + +var urlapi = "http://localhost:3000/api"; + +function OnLoadIndex(){ + listThoughts=getAllThoughts(); +} +function getAllThoughts(){ + $.ajax({ + type: "GET", + dataType: "json", + url: urlapi + "/thoughts", + success: function(data){ + listThoughts=data; + + document.getElementById('listThoughtsHtml').innerHTML=generateHtmlListThoughts(); + } + }); +} +function generateHtmlListThoughts(){ + var html=""; + html+="
"; + html+="
"; + html+=""; + + + return(html); +} + + + + + + + + + + + + + + + + + + +/* +############################## +userpage.html +############################## +*/ + +function OnLoadUserPage(){ + var username=window.location.href.split("?value=")[1]; + $.ajax({ + type: "GET", + dataType: "json", + url: urlapi + "/users/byusername/" + username, + success: function(data){ + + document.getElementById('userpagehtml').innerHTML=generateHtmlUserPage(data[0]); + } + }); +} +function generateHtmlUserPage(user){ + var html=""; + html+="
"; + html+="

" + user.username + "

"; + html+="description: " + user.description; + + html+="
mail: " + user.mail; + html+=""; + html+=""; + html+=""; + html+="
"; + return(html); +} diff --git a/web/own.css b/web/own.css new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/web/own.css @@ -0,0 +1 @@ + diff --git a/web/userpage.html b/web/userpage.html new file mode 100644 index 0000000..e6f7200 --- /dev/null +++ b/web/userpage.html @@ -0,0 +1,62 @@ + + + + + + + + thoughts - main + + + + + + + + + + + + + + + + +
+
+ +
+ + + + + + + + +