chicken-sloths / bangazon-api-sprint1

API for a mock Amazon + Etsy platform providing developers access to the company's employee & product data
0 stars 0 forks source link

Orders Endpoints #106

Closed jordan-castelloe closed 6 years ago

jordan-castelloe commented 6 years ago

Description

Adds the following endpoints:

Related Ticket(s)

fixes #4 and #10

Steps to Test Solution

  1. npm run db:generate

  2. Comment out non-orders routes

  3. npm start to start your server.

  4. http://localhost:8080/api/v1/orders should give you all the orders

  5. http://localhost:8080/api/v1/orders/10 should give you information about that order with an array of products associated on that order. The format should look like this, as specified in issue #10:

{
   OrderId: 21,
   CustomerId: 16,
   PaymentTypeId: 83,
   Products: [
      {
         ProductId: 156,
         Name: "Kite",
         Price: 14.25
         Quantity: 1
      },
      {
         ProductId: 212,
         Name: "Roller blades",
         Price: 88.99
         Quantity: 1
      }
   ]
}
  1. POST the following JSON to http://localhost:8080/api/v1/orders: { "customer_id": 0, "payment_option_id": 100 } Should return 35 and you should be able to run a GET for http://localhost:8080/api/v1/orders/35 and see the stuff you just posted plus an empty array where products would normally be.

  2. PUT the following JSON to http://localhost:8080/api/v1/orders/1 { "customer_id": 0, "payment_option_id": 100 } Run aGET for http://localhost:8080/api/v1/orders/1. You should see that the customer_ids and payment_option_ids on each product object have changed to 0 and 100.

  3. Run a DELETE on http://localhost:8080/api/v1/orders/35 and it should return 35.

A couple other notes

I didn't really do error handling on the orders route (checking to make sure all the info was passed in, etc) because I figure when orders are created they won't have a payment_type_id? And then that'll get added later? I honestly can't remember if we decided on a way to handle that or not. If anyone remembers or has a concrete idea, I'd be glad to include it on this PR. Otherwise, we can go ahead and merge this in for basic MVP functionality and work out the details post-MVP.

DavidLarsKetch commented 6 years ago

testing!

Regarding your note: I'm happy to pull it in for MVP and work out the details later. But, yes, orders presumably won't have a payment_type_id.

jordan-castelloe commented 6 years ago

Fixed the bug with deleting and getting orders (thanks @DavidLarsKetch)! Now you should be able to delete an order, try to get the same order, and get a friendly 404 error back. I just realized we should probably delete all associated products and product_orders when we delete an order, but I think that might be a new PR/ new issue for the sake of expediency