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

Jen Valladares #8

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

router.get("/notes", (req, res) => {
Note.find({}).then(note => res.json(note));
});

router.get("/notes/:id", (req, res) => {
Note.findOne({ _id: req.params.id }).then(note => res.json(note));
});

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

router.get("/users", (req, res) => {
User.find({}).then(user => res.json(user));
});

router.get("/users/:id", (req, res) => {
User.findOne({ _id: req.params.id }).then(user => res.json(user));
});

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

const noteController = require("./controllers/notes");
const userController = require("./controllers/users");

app.use("/notes", noteController);
app.use("/users", userController);

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

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

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

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

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

const userSchema = new mongoose.Schema({})
const userSchema = new mongoose.Schema({
username: String,
email: String,
notes: Note.schema.obj
});

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