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

API endpoints #22

Open
dartandrevinsky opened this issue Jun 28, 2021 · 9 comments
Open

API endpoints #22

dartandrevinsky opened this issue Jun 28, 2021 · 9 comments
Assignees
Labels
backend documentation Improvements or additions to documentation frontend maintenance

Comments

@dartandrevinsky
Copy link
Collaborator

Document API endpoints for ease of implementation

@dartandrevinsky
Copy link
Collaborator Author

dartandrevinsky commented Jun 28, 2021

POST /address

Exchanges address and delivery time for a list of restaurants

Body:

{
  address, 
  time
}

Response:

{
  address, 
  time
  restaurants: Array<{
    id, 
    name,
    cuisine,
    street1,
    street2,
    locality,
    region,
    postcode,
    country,
    'delivery-fee',
    avgDeliveryTime
  }>
}

GET /restaurants/:restaurantId

Obtain detail info for a given restaurant including the menu

Response:

{
  id, 
  name,
  cuisine,
  street1,
  street2,
  locality,
  region,
  postcode,
  country,
  'delivery-fee',
  avgDeliveryTime,
  menu: Array<{
    id,
    name,
    price,
    category_name
  }>
}

GET /cart

Retrieves a blank cart object for the user.

Body:

none required

Response:

{
  orderId,
  total,
  subTotal,
  tax,
  taxAmount,
  delivery,
  items: []
}

PUT /cart

Updates the cart items

Body:

{ 
  restaurantId, 
  itemId, 
  quantity 
}

Response:

{
  orderId,
  total,
  subTotal,
  tax,
  taxAmount,
  delivery,
  items: Array<{ 
    id, 
    count,
    restaurantId
  }>
}

POST /payment/intent

Creates a (like-Stripe) Payment Intent object based on the submitted cart items and responds with the clientSecret value for this transaction.

Body:

{ 
   items: Array<{ 
    id, 
    count,
    restaurantId
  }>
}

Response:

{
  {
    clientSecret // paymentIntent.client_secret
  }
}

POST /payment/confirm

Accepts a credit card data, validates it, responds with confirmed payment or declined (with a given reason).

Body:

{ 
  clientSecret,
  paymentMethod: {
    card: {
      card_number,
      exp_year,
      exp_month,
      cvv, 
      zip
    }
  }
}

Response:
OK:
Status 200,

{
  sucess: true
}

Failure:
Status: 400

{
  error: {
    message
  },
  errors: {
    card_field: String
  }
}

@cer
Copy link
Contributor

cer commented Jun 28, 2021

The delivery address and time is part of the shopping cart. POST /address -> POST /cart/address

@cer
Copy link
Contributor

cer commented Jun 28, 2021

cuisine_name -> cuisine and is an attribute of the restaurant, not the menu item

@cer
Copy link
Contributor

cer commented Jun 28, 2021

What is the structure of the restaurant's address?

@cer
Copy link
Contributor

cer commented Jun 28, 2021

Regarding POST /cart

  • As discussed previously, the cartId should not be part of the API. There is simply a cart that in the real application would be associated with the logged in user.
  • When the UI starts, it should query the the server GET /cart to retrieve the current state of the cart
  • meta: { restaurantId } makes no sense - the should just be a restaurantId attribute

@cer
Copy link
Contributor

cer commented Jun 28, 2021

Regarding PUT /cart/:cartId

  • A response should be an object, not an array
  • please spell out qty
  • meta: { restaurantId } makes no sense - the should just be a restaurantId attribute
  • This endpoint should return the menuItems, quantities and also the order subtotal - the same response as GET /cart described above

@dartandrevinsky
Copy link
Collaborator Author

dartandrevinsky commented Jun 28, 2021

What is the structure of the restaurant's address?

It's a simple string. As per our correspondence.

@dartandrevinsky
Copy link
Collaborator Author

cuisine_name -> cuisine and is an attribute of the restaurant, not the menu item

I actually used this source to collect several sample items: https://codebeautify.org/jsonviewer/cb51497a
I understand what needs to be changed, thank you!

@cer
Copy link
Contributor

cer commented Jun 28, 2021

What is the structure of the restaurant's address?

It's a simple string. As per our correspondence.

The address entered by the user is a string.
The address of a restaurant must be structured data. e.g.:

  • street1
  • street2
  • locality - e.g. city
  • region - e.g. state
  • postcode
  • country

dartandrevinsky added a commit that referenced this issue Jun 29, 2021
 - reworked API docs,
 - server
 - client
@dartandrevinsky dartandrevinsky added the documentation Improvements or additions to documentation label Jul 8, 2021
dartandrevinsky added a commit that referenced this issue Jul 14, 2021
 - created a simple payment server endpoint to confirm payment (moved logic from client to server) (ref: #22)
 - added e2e-assisting values to the selectors dictionary
 - placed these e2e-assisting properties into their corresponding elements on the checkout page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend documentation Improvements or additions to documentation frontend maintenance
Projects
None yet
Development

No branches or pull requests

2 participants