Skip to content

API Contract

tguernier edited this page Apr 17, 2021 · 10 revisions

Sessions

Session Model

{
    _id: ObjectID,
    truncCode: String,
    isFinished: Boolean,
    preferences: Preference,
    results: [Restaurant]
}

Preference Model

{
    location: String,
    distance: Integer,
    price: Number,
    timer: Number,
    coordinates: Coordinates
}

Restaurant Model

{
    name: String,
    location: String,
    numberOfVotes: Number,
    coordinates: Coordinates
    price: Number,
    rating: Number,
    images: String
}

Coordinates Model

{
    lat: Number,
    lng: Number
}

POST /sessions

Create a new Session and return the sessionId and the truncated sessionId

  • URL Params: None
  • Example Data Params:
{
    "preferences": {},
    "results": []
}
  • Headers:
    • Content-Type: application/json
  • Success Response:
    • Code: 201
  • Example Content:
{
  "sessionId": "605334010727e7af37aa2824",
  "truncCode": "a2824"
}

GET /sessions/:id

Get the session object with the provided truncated sessionId

  • URL Params:

    • Required: id (truncated Id)
  • Example Data Params: None

  • Headers:

    • Content-Type: application/json
  • Success Response:

    • Code: 200
  • Error Response:

    • Code: 404
      • Content:
    {
        "message": "Could not find session with that id"
    }
    • Code: 500
  • Example Content:

{
    "_id": "60534086b68128b3509c0a73",
    "truncCode": "c0a73",
    "isFinished": true,
    "preferences": {
        "location": "Auckland",
        "distance": 10,
        "cuisines": [
            "Thai",
            "Japanese",
            "Chinese"
        ],
        "price": 20,
        "timer": 600,
        "coordinates": {
            "lat": 34.6424325,
            "lng": 10.2343462,
        }
    },
    "results": []
}

PATCH /sessions/:id

Updates fields on the specified session and returns the updated object

  • URL Params:
    • Required: id (truncated Id)
  • Example Data Params:
{
  "isFinished": true,

  "preferences": {
      "location": "Auckland",
      "distance": 10,
      "cuisines": ["Thai", "Japanese", "Chinese"],
      "price": 20,
      "timer": 600,
      "coordinates": {
          "lat": 34.6424325,
          "lng": 10.2343462
      },
  },

  "results": [
        {
          "name": "Thai Restaurant",
          "location": "1 Thai Street",
          "numberOfVotes": 5,
          "coords": {
            "lat": 34.6424325,
            "lng": 10.2343462,
          },
          "price": "$$",
          "rating": 3.5,
          "images": "",
        },
        {
          "name": "Japanese Restaurant",
          "location": "1 Japan Street",
          "numberOfVotes": 3,
          "coords": {
            "lat": 34.6424325,
            "lng": 10.2343462,
          },
          "price": "$$$",
          "rating": 4.5,
          "images": "",
        },
        {
          "name": "Chinese Restaurant",
          "location": "1 China Street",
          "numberOfVotes": 5,
          "coords": {
            "lat": 34.9876543,
            "lng": 10.2343462,
          },
          "price": "$",
          "rating": 4.1,
          "images": "",
        }
    ],
}
  • Headers:

    • Content-Type: application/json
  • Success Response:

    • Code: 200
  • Error Response:

    • Code: 404
      • Content:
    {
        "message": "Could not find session with that id"
    }
    • Code: 400
    • Code: 500
  • Example Content:

{
    "_id": "60534086b68128b3509c0a73",
    "truncCode": "c0a73",
    "isFinished": true,
    "preferences": {
        "location": "Auckland",
        "distance": 10,
        "cuisines": [
            "Thai",
            "Japanese",
            "Chinese"
        ],
        "price": 20,
        "timer": 600,
        "coordinates": {
            "lat": 34.6424325,
            "lng": 10.2343462
        }
    },
    "results": [
        {
          "name": "Thai Restaurant",
          "location": "1 Thai Street",
          "numberOfVotes": 5,
          "coords": {
            "lat": 34.6424325,
            "lng": 10.2343462,
          },
          "price": "$$",
          "rating": 3.5,
          "images": "",
        },
        {
          "name": "Japanese Restaurant",
          "location": "1 Japan Street",
          "numberOfVotes": 3,
          "coords": {
            "lat": 34.6424325,
            "lng": 10.2343462,
          },
          "price": "$$$",
          "rating": 4.5,
          "images": "",
        },
        {
          "name": "Chinese Restaurant",
          "location": "1 China Street",
          "numberOfVotes": 5,
          "coords": {
            "lat": 34.9876543,
            "lng": 10.2343462,
          },
          "price": "$",
          "rating": 4.1,
          "images": "",
        }
    ],
}

Clone this wiki locally