REST API description of Events resource - lrcry/ExpertMind GitHub Wiki

Events Resource REST API

Contents

Introduction

Events are used to keep records of nodes changes i.e. new node creation, child node addition and votes.
An Event will be look like the following object:

{
    "status": "EVENT_UNREAD",
    "user_id": "333333",
    "create_at": "2015-10-23 08:38:42.103949",
    "node_id": "0d1e10d8b720cfb2",
    "operation": "CREATE_NEW_NODE",
    "_id": "0d48c012e42093f4"
}

For an Event object, there are four permitted operations:

CREATE_NEW_NODE
ADD_CHILD_NODE
VOTE_UP
VOTE_DOWN

Also two valid status:

EVENT_UNREAD
EVENT_READ

Events retrieval operations

Get an Event by ID

GET /api/events/{event_id}
The response will look like

{
  "data": {
    "status": "EVENT_UNREAD",
    "user_id": "333333",
    "create_at": "2015-10-23 08:38:42.103949",
    "node_id": "0d1e10d8b720cfb2",
    "operation": "CREATE_NEW_NODE",
    "_id": "0d48c012e42093f4"
  },
  "success": "true"
}

If an ID is given but does not exist in database, an error will be returned as a response:

{
  "data": {},
  "err_message": "No event found with given id=333333333333",
  "success": "false"
}

Get all Events

GET /api/events

Search among Events

Searching by user_id and/or node_id and/or status are supported at present by accessing the following URI:
GET /api/events[?user_id={user_id}&node_id={node_id}&status={status}]
The request parameters can be in any combination and any order.
The only restriction on the search parameters will be the status. If an invalid status is given during searching, an error message will be returned as a response:

{
  "data": {},
  "err_message": "Status 3333 is not valid",
  "success": "false"
}

Valid operation and status click here.

Events modification operations

Create a new event

POST /api/events

The API accept a request body in JSON as follows:

{
    "user_id": "222222",
    "node_id": "0d3ed9e33f205d2e",
    "operation": "VOTE_DOWN"
}

At server side there is a check of the body. When the given user ID or node ID does not exist in database, or the operation is not permitted, an error message will be returned. Valid operation and status click here.
If the create successful, a JSON array of all events whose status=EVENT_UNREAD with current user_id will be returned in the response like the following:

{
  "data": [
    {
      "status": "EVENT_UNREAD",
      "user_id": "444444",
      "create_at": "2015-10-23 10:15:20.707341",
      "node_id": "0d3ed9e33f205d2e",
      "operation": "VOTE_UP",
      "_id": "0d49188dbe2093f8"
    }
  ],
  "success": "true"
}

Update an existing event

PUT /api/events/{event_id}

The request body will look like the following:

{
  "status": "EVENT_READ",
  "user_id": "333333",
  "create_at": "2015-10-23 08:38:42.103949",
  "node_id": "0d1e10d8b720cfb2",
  "operation": "CREATE_NEW_NODE",
  "_id": "0d48c012e42093f4"
}

Valid operation and status click here.
Like creating a new event, if the update successful, a JSON array of events not yet read by this user will be returned.
Note: to avoid the service retrieving the Event by its ID and check it first (free tier of Orchestrate offers rather a slow connection), a complete Event object is required when updating an existing event.