API Endpoints - UOA-SE701-Group3-2021/3Lancers GitHub Wiki

Journal

Get widgets

Get widgets which appear in the journal for a date range.
Endpoint: /api/journal/{date}
Method: GET

Response body:

Parameter Type Description
widgetData widget[] (data model) widgets in the journal for the date range
calendarData calendar_event[] (data model) all calendar widget data
habitData habit[] all habit tracker widget data
textData text[] (data model) all text widget data
todoData todo[] all todolist widget data
habit: {
  "_id": string,
  "date": yyyy-mm-dd,
  "name": string,
  "completed": bool
}
todo: {
  "completed": bool,
  "_id": string,
  "name": string,
  "createdDate": yyyy-mm-dd,
  "dueDate": yyyy-mm-dd,
  "__v": int,
  "isOverdue": bool
}

Example:
GET /api/journal/2021-02-03

Response:

200 OK

{
  "widgetData": [
    {
      "_id": "60586d12bbf8b300088c80b7",
      "date": "2021-02-03T00:00:00.000Z",
      "position": {
        "row": 1,
        "col": 1
      },
      "type": "todo",
      "__v": 0
    }
  ],
  "calendarData": [],
  "habitData": [],
  "textData": [],
  "todoData": [
    {
      "completed": false,
      "_id": "60585cde2577662678bad90b",
      "name": "Lorem",
      "createdDate": "2021-01-01T00:00:00.000Z",
      "dueDate": "2021-01-01T00:00:00.000Z",
      "__v": 0,
      "isOverdue": true
    }
  ]
}

Status codes:

200 OK: all widgets and associated data found and returned

Add widget

Add widget in journal (widget data must be created separately).
Endpoint: /api/journal
Method: POST

Request body:

Parameter Type Description
date string date (yyyy-mm-dd) in the journal to add the widget to
position position position of widget in journal for specified date
type string type of widget (fixed values: "todo", "calendar", "text", "habit_tracker")
position: {
  "row": int,
  "col": int
}

Response body:

Parameter Type Description
widget widget newly created widget
data variable data associated with new widget; type depends on widget type

Example:
POST /api/journal

Request body:

{
  "date": "2021-02-03",
  "position": {
    "row": 1,
    "col": 1
  },
  "type": "todo"
}

Response:

201 Created

{
  "widget": {
    "_id": "60586d12bbf8b300088c80b7",
    "date": "2021-02-03T00:00:00.000Z",
    "position": {
      "row": 1,
      "col": 1
    },
    "type": "todo",
    "__v": 0
  },
  "data": [
    {
      "completed": false,
      "_id": "60585cde2577662678bad90b",
      "name": "Lorem",
      "createdDate": "2021-01-01T00:00:00.000Z",
      "dueDate": "2021-01-01T00:00:00.000Z",
      "__v": 0,
      "isOverdue": true
    }
  ]
}

Status codes:

201 Created: widget added successfully
400 Bad Request: invalid request body

Update widget

Update widget in journal (e.g. change position).
Endpoint: /api/journal/{id}
Method: PUT

Request body:

Parameter Type Description
date string new date (yyyy-mm-dd) in the journal to move the widget to
position position new position in journal for specified date to move the widget to
type string new type of widget (i.e. 'todo', 'calendar', etc.)
position: {
  "row": int,
  "col": int
}

Example:
PUT /api/journal/60586d12bbf8b300088c80b7

Request body:

{
  "date": "2021-02-04",
  "position": {
    "row": 2,
    "col": 2
  },
  "type": "todo"
}

Response:

204 No Content

Status codes:

204 No Content: widget updated successfully
400 Bad Request: invalid request id or body

Delete widget

Delete widget in journal.
Endpoint: /api/journal/{id}
Method: DELETE

Example:
DELETE /api/journal/60586d12bbf8b300088c80b7

Response:

204 No Content

Status codes:

204 No Content: widget deleted successfully
400 Bad Request: invalid request id

Todo

Create todo task

Create new task for the todolist widget.
Endpoint: /api/todo
Method: POST

Request body:

Parameter Type Description
name string name of task
createdDate string date task created (yyyy-mm-dd)
dueDate string date task due (yyyy-mm-dd)
completed bool is task completed

Response body:

Parameter Type Description
name string name of new task
createdDate string date new task created (yyyy-mm-dd)
dueDate string date new task due (yyyy-mm-dd)
completed bool is new task completed
_id string implicit database id of new task
__v int version key

Example:
POST /api/todo

Request body:

{
  "name": "task1",
  "createdDate": "2021-01-01",
  "dueDate": "2021-01-02",
  "completed": false
}

Response:

201 Created

{
  "completed": false,
  "_id": "6058fdff00f89713cc5cefcf",
  "name": "task1",
  "createdDate": "2021-01-01T00:00:00.000Z",
  "dueDate": "2021-01-02T00:00:00.000Z",
  "__v": 0
}

Status codes:

201 Created: todo task created successfully
400 Bad Request: invalid request body

Update todo task

Update existing todo task.
Endpoint: /api/todo/{id}
Method: PUT

Request body:

Parameter Type Description
name string name of task
createdDate string date task created (yyyy-mm-dd)
dueDate string date task due (yyyy-mm-dd)
completed bool is task completed

Example:
PUT /api/todo/6058fdff00f89713cc5cefcf

Request body:

{
  "name": "task1",
  "createdDate": "2021-01-01",
  "dueDate": "2021-01-03",
  "completed": true
}

Response:

204 No Content

Status codes:

204 No Content: todo task updated successfully
400 Bad Request: invalid request id or body

Delete todo task

Delete existing todo task.
Endpoint: /api/todo/{id}
Method: DELETE

Example:
DELETE /api/todo/6058fdff00f89713cc5cefcf

Response:

204 No Content

Status codes:

204 No Content: todo task deleted successfully
400 Bad Request: invalid request id

Calendar

Create calendar event

Create new event for the calendar widget.
Endpoint: /api/calendar
Method: POST

Request body:

Parameter Type Description
name string name of event
startTime string event start time (yyyy-mm-ddThh:mm:ss)
endTime string event end time (yyyy-mm-ddThh:mm:ss)

Response body:

Parameter Type Description
name string name of new event
startTime string new event start time (yyyy-mm-ddThh:mm:ss)
endTime string new event end time (yyyy-mm-ddThh:mm:sst)
_id string implicit database id of new event
__v int version key

Example:
POST /api/calendar

Request body:

{
  "name": "event1",
  "startTime": "2021-01-01T00:00:00",
  "endTime": "2021-01-01T12:00:00"
}

Response:

201 Created

{
  "_id": "60590dad00f89713cc5cefd0",
  "name": "event1",
  "startTime": "2020-12-31T11:00:00.000Z",
  "endTime": "2020-12-31T23:00:00.000Z",
  "__v": 0
}

Status codes:

201 Created: calendar event created successfully
400 Bad Request: invalid request body

Update calendar event

Update existing calendar event.
Endpoint: /api/calendar/{id}
Method: PUT

Request body:

Parameter Type Description
name string name of event
startTime string event start time (yyyy-mm-ddThh:mm:ss)
endTime string event end time (yyyy-mm-ddThh:mm:ss)

Example:
PUT /api/calendar/60590dad00f89713cc5cefd0

Request body:

{
  "name": "event1",
  "startTime": "2021-01-01T00:00:00",
  "endTime": "2021-01-01T23:59:59"
}

Response:

204 No Content

Status codes:

204 No Content: calendar event updated successfully
400 Bad Request: invalid request id or body

Delete calendar event

Delete existing calendar event.
Endpoint: /api/calendar/{id}
Method: DELETE

Example:
DELETE /api/calendar/60590dad00f89713cc5cefd0

Response:

204 No Content

Status codes:

204 No Content: calendar event deleted successfully
400 Bad Request: invalid request id

Text

Create text

Create new text data for the text widget.
Endpoint: /api/text
Method: POST

Request body:

Parameter Type Description
text string text content
widgetId string id of associated widget for text to appear in

Response body:

Parameter Type Description
text string new text content
widgetId string id of associated widget for new text to appear in
_id string implicit database id of new text data
__v int version key

Example:
POST /api/text

Request body:

{
  "text": "text1",
  "widgetId": "60590f5a00f89713cc5cefd1"
}

Response:

201 Created

{
  "_id": "60590f7000f89713cc5cefd3",
  "text": "2021-02-03",
  "widgetId": "60590f5a00f89713cc5cefd1",
  "__v": 0
}

Status codes:

201 Created: text data created successfully
400 Bad Request: invalid request body

Update text

Update existing text data.
Endpoint: /api/text/{id}
Method: PUT

Request body:

Parameter Type Description
text string text content
widgetId string id of associated widget for text to appear in

Example:
PUT /api/text/60590f7000f89713cc5cefd3

Request body:

{
  "text": "abc",
  "widgetId": "60590f5a00f89713cc5cefd1"
}

Response:

204 No Content

Status codes:

204 No Content: text data updated successfully
400 Bad Request: invalid request id or body

Delete text

Delete existing text data.
Endpoint: /api/text/{id}
Method: DELETE

Example:
DELETE /api/text/60590f7000f89713cc5cefd3

Response:

204 No Content

Status codes:

204 No Content: text data deleted successfully
400 Bad Request: invalid request id

Habit tracker

Create habit

Create new habit for the habit tracker widget.
Endpoint: /api/habittracker
Method: POST

Request body:

Parameter Type Description
name string name of habit
startDate string habit start date (yyyy-mm-dd)
endDate string habit end date (yyyy-mm-dd)
daysOfWeek string[] days of the week the habit is active for (fixed values: mon, tue, wed, thu, fri, sat, sun)
completedDates string[] dates for which the habit has been completed (yyyy-mm-dd)

Response body:

Parameter Type Description
name string name of new habit
startDate string new habit start date (yyyy-mm-dd)
endDate string new habit end date (yyyy-mm-dd)
daysOfWeek string[] days of the week the new habit is active for (fixed values: mon, tue, wed, thu, fri, sat, sun)
completedDates string[] dates for which the new habit has been completed (yyyy-mm-dd)
_id string implicit database id of habit
__v int version key

Example:
POST /api/habittracker

Request body:

{
  "name": "habit1",
  "startDate": "2021-01-01",
  "endDate": "2022-01-01",
  "daysOfWeek": [
    "mon",
    "fri"
  ],
  "completedDates": []
}

Response:

201 Created

{
  "endDate": "2022-01-01T00:00:00.000Z",
  "daysOfWeek": [
    "mon",
    "fri"
  ],
  "completedDates": [],
  "_id": "6059649d92598138508e1766",
  "name": "habit1",
  "startDate": "2021-01-01T00:00:00.000Z",
   "__v": 0
}

Status codes:

201 Created: habit created successfully
400 Bad Request: invalid request body

Update habit

Update existing habit.
Endpoint: /api/habittracker/{id}
Method: PUT

Request body:

Parameter Type Description
name string name of habit
startDate string habit start date (yyyy-mm-dd)
endDate string habit end date (yyyy-mm-dd)
daysOfWeek string[] days of the week the habit is active for (fixed values: mon, tue, wed, thu, fri, sat, sun)
completedDates string[] dates for which the habit has been completed (yyyy-mm-dd)

Example:
PUT /api/habittracker/6059649d92598138508e1766

Request body:

{
  "name": "habit1",
  "startDate": "2021-01-01",
  "endDate": "2022-01-01",
  "daysOfWeek": [
    "wed",
    "thu"
  ],
  "completedDates": []
}

Response:

204 No Content

Status codes:

204 No Content: habit updated successfully
400 Bad Request: invalid request id or body

Delete habit

Delete existing habit.
Endpoint: /api/habittracker/{id}
Method: DELETE

Example:
DELETE /api/habittracker/6059649d92598138508e1766

Response:

204 No Content

Status codes:

204 No Content: habit deleted successfully
400 Bad Request: invalid request id

Steam games widget

Get steam library

Use the given username to retrieve their game library
Endpoint: /api/steam/
Method: GET

Example:
GET /api/steam?steamVanity=CyberDeath11111

Response:

200 Game widget created: Game library retrieved and returned successfully

Status codes:

200 Game widget created: Game library retrieved and returned successfully
400 Malformed Request: SteamVanity query parameter is invalid
404 Username not found: Invalid username
404 No games found for given username: Profile may be private
500 Error: No steam key found in environment

Health check

Check status of API
Endpoint: /api/steam/ping
Method: GET

Example:
GET /PING

Response: 200 Ok

Status codes:

200 Ok