Giter VIP home page Giter VIP logo

mongo-iii's Introduction

Mongo III

Topics

  • Separation of Concerns
    • MVC Architecture
  • Relational Data in mongo
  • Joins: Populate

Running the project

  • For this sprint you're going to be combining a bunch of the concepts that you've been working on thus far. Be sure to run yarn install in the root of your project and also in the client directory. Once you have all of your dependancies, fire up the client by running yarn start. (note we're using Yarn,and you may have some issues if you use npm instead for the client server).
  • To run the app server, run npm start in the root of the project and ensure that your mongod server is running as well!
  • Your client has the following client side routes. You'll have to implement the backend in order to be able to navigate and use the client side application. You shouldn't have any thing to do on the front end. When your back end works your front end should start to work as well.
    • '/' our root route is a simple login page. This login form will hit submit a POST request to find a user in the DB and send that response back to the client. Note We are storing the user's _id in localstorage. and using it to submit more data throughout the app.
    • '/create-user' this route has a create user form. This create user for will hit /new-user' and add a user to the DB
    • '/posts' this route will display all of the blog posts in the DB. Just the title will be shown. Each post will be a link to a 'single' blog post page.
    • /posts:id this route will take the user to the single blog post page. You can add comments on this page to a blog post.
    • /new-post this route will allow the user to create a new blog post. A title and content are given and sent up to the Server.
  • NOTE

    • It is important to understand that READING THE CONSOLE will tell you whether or not your endpoints are working. If they're not working, you'll see an error message in the console explaining where the break down might possibly be.

Todo

  • You'll need implement the following routes/models/controllers in order for things to start to come together.
  • You will want to start with the Models. You'll have a User Schema and Post Schema to implement.

POST '/new-user'

  • The object that the client is sending is {username: foo, password: bar}. You'll need to implement the controller to handle this user object.

POST '/login'

  • This route will be responsible for looking at the same type of object as above, but this time instead of using save you'll need to find the user in the DB an send it back to the client.

POST '/new-post'

  • This route will take in a new blog post object and save it to the database. You'll need set this up to take an array of comments that can be referenced users by ObjectId.
  • /new-post will also need a reference to the author (user) of the post.
{
  title: 'This is a fake blog post title', 
  author: {
    name: 'Jen Urso'
    _id: '2lkj3j23,
  },
  _id: '234lj23kjh', 
  content: 'This is some classy fake content', 
  comments: [
    {text:'This is a class comment', author: 'Stanley Yelnats'},
  ]
}

GET '/posts'

  • This route will return all of the blog posts you have stored in your database.
  • All we're concerned about here is the blog title and the blog ID. Those are the only neccessary fields you'll need to send back to the client.
  • The client is using the data like this, so at minimum you'll need to return out an array of objects like so:
posts: [
  {title: 'This is a fake post', _id: '325kjlljh'},
  {title: 'This is another fake post', _id: '234sdjlk'}
],

GET '/posts/:id'

  • This get Post by Id end point should return an object of a single post's data:
post: {
  title: 'This is a fake blog post title', 
  author: {
    name: 'Jen Urso'
    _id: '2lkj3j23,
  },
  _id: '234lj23kjh', 
  content: 'This is some classy fake content', 
  comments: [
    {text:'This is a class comment', author: 'Stanley Yelnats'},
  ]
},

UPDATE '/posts/:id'

  • Your main concern with this PUT/UPDATE is to add a comment to the array of comments on a single blog post.
  • You'll need to pull off the ID of the post from the route params to query for the post data.
  • The data coming into this PUT should look like this:
  {text:'This is a class comment', author: 'AuthorId(ObjectId)'}

Finished Product

  • When all is said and done, you should be able to create a blog post and add comments to the previously created post. You can test that all of your joining/refs are working on the backend, by creating a new user and logging in as that user and commenting on a blog post.

Extra Credit

  • Add an additional schema for comments. Make sure it references both the user who authored the comment, as well as the comment's parent post.
  • Add a new /posts/:id/comments from which new comments will be POSTed to.
  • Don't forget to update your GET /posts and GET /posts/:id controller methods to populate the array of comments on each post.

mongo-iii's People

Contributors

seanchen1991 avatar sperrye avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.