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

Raymond Levengood #9

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


const Note = require('../models/Note.js')

router.get('/', (req, res) => {
Note.find({})
.then(allNotes => res.json(allNotes))
})

router.get('/:title', (req, res) => {
Note.find({ title: req.params.title})
.then(oneNotes => res.json(oneNotes))
})

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 mongoose = require('mongoose');
const express = require('express');
const router = express.Router();


const User = require('../models/User.js')

router.get('/', (req, res) => {
User.find({})
.then(allUsers => res.json(allUsers))
})

router.get('/:name', (req, res) => {
Note.find({ name: req.params.name})
.then(oneName => res.json(oneName))
})

module.exports = router;
18 changes: 18 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
const mongoose = require('../db/connection.js')
const express = require('express');
const parser = require("body-parser")
const server = express();

const notesController = require('./controllers/notes.js')
const usersController = require('./controllers/users.js')

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

server.get('/', (req, res) => {
res.redirect("/notes");
});

server.use('./controllers/users.js', usersController)
server.use('./controllers/notes.js', notesController)

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

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

const noteSchema = new mongoose.Schema({})
const noteSchema = new mongoose.Schema({
title: String,
body: String,
author: {User}
})

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

const userSchema = new mongoose.Schema({})

const userSchema = new mongoose.Schema({
username: String,
email: String,
notes: [Note]
})

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