Code Monkey home page Code Monkey logo

project2-movie-api's People

Contributors

jamiemiller8 avatar

Watchers

 avatar  avatar

project2-movie-api's Issues

Error Handling

If I make a request for a movie that's not in your DB, the API just hangs. I.e. if I make a request to /movie/Princess%20Bride, it should maybe return an error that the movie isn't found.

Update Movie throws an error

When I send a PUT request to /movie/:id, I get the following error:

ReferenceError: req is not defined
    at updateMovie (/Users/zakk/ga/wdi/grading/02-project/jamie/controllers/movie.js:20:38)
    at Layer.handle [as handle_request] (/Users/zakk/ga/wdi/grading/02-project/jamie/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/zakk/ga/wdi/grading/02-project/jamie/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/Users/zakk/ga/wdi/grading/02-project/jamie/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/zakk/ga/wdi/grading/02-project/jamie/node_modules/express/lib/router/layer.js:95:5)
    at /Users/zakk/ga/wdi/grading/02-project/jamie/node_modules/express/lib/router/index.js:281:22
    at param (/Users/zakk/ga/wdi/grading/02-project/jamie/node_modules/express/lib/router/index.js:354:14)
    at param (/Users/zakk/ga/wdi/grading/02-project/jamie/node_modules/express/lib/router/index.js:365:14)
    at Function.process_params (/Users/zakk/ga/wdi/grading/02-project/jamie/node_modules/express/lib/router/index.js:410:3)
    at next (/Users/zakk/ga/wdi/grading/02-project/jamie/node_modules/express/lib/router/index.js:275:10)
    at Function.handle (/Users/zakk/ga/wdi/grading/02-project/jamie/node_modules/express/lib/router/index.js:174:3)
    at router (/Users/zakk/ga/wdi/grading/02-project/jamie/node_modules/express/lib/router/index.js:47:12)
    at Layer.handle [as handle_request] (/Users/zakk/ga/wdi/grading/02-project/jamie/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/zakk/ga/wdi/grading/02-project/jamie/node_modules/express/lib/router/index.js:317:13)
    at /Users/zakk/ga/wdi/grading/02-project/jamie/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/Users/zakk/ga/wdi/grading/02-project/jamie/node_modules/express/lib/router/index.js:335:12)

Root Route

app.get("/", (request, response) => {
response.send("Hello World");
});

Having a root route like this is a really great idea (great thinking!). Maybe consider having it send documentation to the user? I think that would be the best, but the other option is to redirect them to another route.

Add entity to route path

router.get('/:name', genreController.getByName);

We typically get a resource by it's id, so I think people would expect something like /genre/:id to work. Then, to get a document by some other property, we'd add that to the URL (i.e. genre/name/:name). That might be a cleaner way of doing your paths.

Movie routes

// get list of movies
router.get('/', movieController.index);
// get movie by id
router.get('/:id', movieController.getById);
//get movie by title
router.get('/title/:title', movieController.getByTitle);
//get genre of movie by the movie's id
router.get('/:id/genre', movieController.getGenre);
//create a new movie
router.post('/', movieController.createNewMovie);
//update a movie
router.put('/:id', movieController.updateMovie);
//delete a movie
router.delete('/:id', movieController.deleteMovie);

  • The comments you have here are great ๐Ÿ‘
  • Getting a move by ID and by title is ๐Ÿ”ฅ
  • The way you've done a movie's genre is great! Another cool way to do this is to populate the genre object

Repo organization tips

You've got a lot of stuff in the root of your respository. Consider reorganizing it a bit so the repo looks a little cleaner.

One thing you could do is move the json data and axios/ directory into a data/ directory.

Movie routes

// get list of movies
router.get('/', movieController.index);
// get movie by id
router.get('/:id', movieController.getById);
//get movie by title
router.get('/title/:title', movieController.getByTitle);
//get genre of movie by the movie's id
router.get('/:id/genre', movieController.getGenre);
//create a new movie
router.post('/', movieController.createNewMovie);
//update a movie
router.put('/:id', movieController.updateMovie);
//delete a movie
router.delete('/:id', movieController.deleteMovie);

  • The comments you have here are great ๐Ÿ‘
  • Getting a move by ID and by title is ๐Ÿ”ฅ
  • The way you've done a movie's genre is great! Another cool way to do this is to populate the genre object

Person routes

//get person by name
router.get('/:name', personController.getByName);
//get person by id
router.get('/:id', personController.getById);

These two routes are identical! The fact that you've given them separate parameters wont make a difference, any route that would match against either of these will always just match against the first one (because it's first).

Maybe change the route to get a document by it's name to add name to the path?

router.get('/name/:name', personController.getByName); 

Query Params

As a cool bonus, one thing you could do is implement query parameters for your urls. This would let you query for any document based on any property.

So to get by a movie name, you'd make a GET request to /movie?name=Princess%20Bride

We didn't cover these, so this would be a cool bonus!

Person Schema

const PersonSchema = new Schema ({
results:[{
name: String,
known_for:[{
id: Number,
title: String,
genre_ids:[{
type: Number
}]
}]
}]
});

This is a really interesting way of defining this model. It might make more sense to have name and known_for at the root of your schema, rather than nested under results. Also, for your genre_ids property, you probably want to use another ref.

Add setup instructions to the README

You currently don't have any documentation on how to get the project setup locally if someone (i.e. an instructor or a potential employer) wanted to do that.

Can you add setup instructions to your README?

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.