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

Checkpoint Express Mongoose Short (Kyle Clabough) #141

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

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

router.get('/:id', function(req, res) {
Note.findById(req.params.id).then(note => res.json(note))
})

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

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

router.get('/:id', function(req, res) {
User.findById(req.params.id).then(user => res.json(user))
})

module.exports = router;
18 changes: 16 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
app.listen(3000, () => console.log('app is running'))
const express = require('express');
const app = express();
const router = express.Router();
const parser = require('body-parser')

app.use(parser.json())

router.get('/', function(req, res) {
res.redirect('/api/notes');
})

router.use('/api/users', require('./controllers/users'));
router.use('/api/notes', require('./controllers/notes'));

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

// DO NOT REMOVE THIS LINE:
module.exports = app
module.exports = app;
6 changes: 5 additions & 1 deletion models/Note.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const mongoose = require('../db/connection')

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

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

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

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