microservices-patterns / ftgo-consumer-web-ui

Other
17 stars 26 forks source link

API endpoints #22

Open dartandrevinsky opened 3 years ago

dartandrevinsky commented 3 years ago

Document API endpoints for ease of implementation

dartandrevinsky commented 3 years ago

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 commented 3 years ago

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

cer commented 3 years ago

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

cer commented 3 years ago

What is the structure of the restaurant's address?

cer commented 3 years ago

Regarding POST /cart

cer commented 3 years ago

Regarding PUT /cart/:cartId

dartandrevinsky commented 3 years ago

What is the structure of the restaurant's address?

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

dartandrevinsky commented 3 years ago

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 commented 3 years ago

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.: