sharetribe / harmony

Availability management backend and API for Sharetribe marketplaces
https://www.sharetribe.com
Apache License 2.0
19 stars 11 forks source link

Optimistic `block` endpoints #34

Closed rap1ds closed 7 years ago

rap1ds commented 7 years ago

This PR adds two new endpoints: /bookables/createBlocks and /bookables/deleteBlocks

POST /bookables/createBlocks

This endpoint takes a list of start-end ranges and creates blocked timeslots. The body of the request is following:

{
  "marketplaceId": <uuid>,
  "refId": <uuid>,
  "blocks": [
    {
      "start": "2016-12-05T08:40:20.438Z",
      "end": "2016-12-05T08:40:20.438Z"
    },
    { ... },
    { ... }
  ]
}

The result is a 201 status and the body content is an array of newly created blocks:

{
  "data": [
    {
      "id": "string",
      "type": "string",
      "attributes": {
        "start": "2016-12-05T08:40:20.464Z",
        "end": "2016-12-05T08:40:20.464Z"
      },
      "relationships": {}
    },
    { ... },
    { ... }
  ],
  "meta": {},
  "included": [
    {
      "id": "string",
      "type": "string",
      "attributes": {},
      "relationships": {}
    }
  ]
}

Status 404 is returned if a bookable can't be found with marketplaceId / refId pair.

POST /bookables/deleteBlocks

This endpoint takes a list of block IDs and deletes those blocks. The body of the request is following:

{
  "marketplaceId": <uuid>,
  "refId": <uuid>,
  "blocks": [
    { "id": <uuid> },
    { ... },
    { ... }
  ]
}

The result is a 201 status and the body content is an array of deleted blocks:

{
  "data": [
    {
      "id": "string",
      "type": "string",
      "attributes": {
        "start": "2016-12-05T08:40:20.464Z",
        "end": "2016-12-05T08:40:20.464Z"
      },
      "relationships": {}
    },
    { ... },
    { ... }
  ],
  "meta": {},
  "included": [
    {
      "id": "string",
      "type": "string",
      "attributes": {},
      "relationships": {}
    }
  ]
}

Status 404 is returned if a bookable can't be found with marketplaceId / refId pair.

Todos / open questions

Questions:

Next PR:

ovan commented 7 years ago

Is the 201 correct status for deleteBlocks endpoint?

Nope. 200 OK sounds better since this is not about creating.

Is the body format correct? Is the response format correct?

These look good to me.

Should the deleteBlocks HTTP verb be DELETE?

Nope. We POST commands. This is a command that happens to delete things (sometimes) but we're not RESTfully deleting resources.