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

Andrew Shea #26

Open
wants to merge 2 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
24 changes: 24 additions & 0 deletions controllers/notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const express = require('express')
const router = express.Router()
const Note = require('../models/Note')


//INDEX ROUTE
router.get("/", (req, res) => {
Note.find({}).then(notes => {
res.redirect('/notes')
})
})

//ALL NOTES ROUTE
router.get("/notes", (req, res) => {
Note.find({}).then(notes => res.json(notes))
})

//FIND-ONE ROUTE
router.get("/notes/:id", (req, res) => {
Note.findOne({_id: req.params.id}).then(thisNote => res.json(thisNote))
})


module.exports = router
18 changes: 18 additions & 0 deletions controllers/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const express = require('express')
const router = express.Router()
const User = require('../models/User')



//ALL NOTES ROUTE
router.get("/users", (req, res) => {
User.find({}).then(users => res.json(users))
})

//FIND-ONE ROUTE
router.get("/notes/:id", (req, res) => {
User.findOne({_id: req.params.id}).then(thisUser => res.json(thisUser))
})


module.exports = router
5 changes: 5 additions & 0 deletions db/seedData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{

}
]
20 changes: 20 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
const express = require('express')
const parser = require("body-parser")
const cors = require('cors')
const notesController = require('./controllers/notes.js')
const usersController = require('./controllers/users.js')
const app = express()



app.use(parser.urlencoded({ extended: true }));
app.use(parser.json());
app.use(cors())



app.use(notesController);
app.use(usersController)



app.listen(3000, () => console.log('app is running'))

// DO NOT REMOVE THIS LINE:
Expand Down
10 changes: 9 additions & 1 deletion models/Note.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
const mongoose = require('../db/connection')
const User = require('./User')

const noteSchema = new mongoose.Schema({})
const noteSchema = new mongoose.Schema({
title: String,
body: String,
// author: {
// type: mongoose.Schema.Types.ObjectId,
// ref: User
// }
})

module.exports = mongoose.model('Note', noteSchema)
10 changes: 9 additions & 1 deletion models/User.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
const mongoose = require('../db/connection')
const Note = require('./Note')

const userSchema = new mongoose.Schema({})
const userSchema = new mongoose.Schema({
username: String,
email: String,
// notes: {
// type: mongoose.Schema.Types.String,
// ref: Note
// }
})

module.exports = mongoose.model('User', userSchema)
Loading