Skip to content

Backend Documentation

pablo edited this page Apr 11, 2017 · 10 revisions

Table of Contents

User API

/api/users
(GET) returns all users
example:
/api/users returns

{
  "users": [
    {
      "_id": "58ec1ad5fd4e9b1103836d19",
      "cuid": "cj1crwsf00000czgaezowh3b7",
      "firstName": "Harry",
      "lastName": "Potter",
      "email": "harry@gmail.com",
      "password": "9171ad1004e86fbda3975a14ad827231f869c3588c30e681adeedc9e406fb7e94459806814866737f1ac6ca8cf07e0f3fdd4f8618f577231fb37b71472731fd4",
      "studentId": 15675334,
      "__v": 0,
      "studyGroups": [],
      "lastLogin": null,
      "dateAdded": "2017-04-10T23:52:53.688Z"
    },
   ...// more users
  ]
}

/api/users/me
(GET) refresh user session

/api/users/logout
(GET) logout current user

/api/users/:cuid
(GET) returns a specific user
example: /api/users/cj1crwsf00000czgaezowh3b7 returns

{
  "user": {
    "_id": "58ec1ad5fd4e9b1103836d19",
    "cuid": "cj1crwsf00000czgaezowh3b7",
    "firstName": "Harry",
    "lastName": "Potter",
    "email": "harry@gmail.com",
    "studentId": 15675334,
    "__v": 0,
    "studyGroups": [],
    "lastLogin": null,
    "dateAdded": "2017-04-10T23:52:53.688Z"
  }
}

/api/users/:cuid
(POST) create an user
example: /api/users/cj1crwsf00000czgaezowh3b7
submitting
{ "user" : {"firstName":"Harry", "lastName":"Potter","email":"harry@gmail.com", "password":"hermayoni", "studentId":"15675334"}}
returns

{
  "user": {
    "__v": 0,
    "cuid": "cj1crwsf00000czgaezowh3b7",
    "firstName": "Harry",
    "lastName": "Potter",
    "email": "harry@gmail.com",
    "password": "9171ad1004e86fbda3975a14ad827231f869c3588c30e681adeedc9e406fb7e94459806814866737f1ac6ca8cf07e0f3fdd4f8618f577231fb37b71472731fd4",
    "studentId": 15675334,
    "_id": "58ec1ad5fd4e9b1103836d19",
    "studyGroups": [],
    "lastLogin": null,
    "dateAdded": "2017-04-10T23:52:53.688Z"
  }
}

/api/users/:cuid
(PUT) update an user
example:
/api/users/cj1crwsf00000czgaezowh3b7
submitting
{ "user" : {"firstName":"Ron", "lastName":"Potter","email":"harry@gmail.com", "password":"hermayoni", "studentId":"15675334"}}
returns

{
  "user": {
    "__v": 0,
    "cuid": "cj1crwsf00000czgaezowh3b7",
    "firstName": "Ron",
    "lastName": "Potter",
    "email": "harry@gmail.com",
    "password": "9171ad1004e86fbda3975a14ad827231f869c3588c30e681adeedc9e406fb7e94459806814866737f1ac6ca8cf07e0f3fdd4f8618f577231fb37b71472731fd4",
    "studentId": 15675334,
    "_id": "58ec1ad5fd4e9b1103836d19",
    "studyGroups": [],
    "lastLogin": null,
    "dateAdded": "2017-04-10T23:52:53.688Z"
  }
}

/api/users/:cuid
(DELETE) deletes an user example:
/api/users/cj1crwsf00000czgaezowh3b7
deletes user and sends no response.

/api/users/login
(POST) login an existing user example: submitting
{"email":"Harry", "password":"leviozza"}
returns

{
  "user": {
    "_id": "58ec1ad5fd4e9b1103836d19",
    "cuid": "cj1crwsf00000czgaezowh3b7",
    "firstName": "Harry",
    "lastName": "Potter",
    "email": "harry@gmail.com",
    "studentId": 15675334,
    "__v": 0,
    "studyGroups": [],
    "lastLogin": null,
    "dateAdded": "2017-04-10T23:52:53.688Z"
  },
  "statusCode": 200
}

/api/users/:cuid/studyGroups
(GET) returns user's studygroups
example:
/api/users/cj1crwsf00000czgaezowh3b7/studyGroups

StudyGroup API

/api/studyGroups/
(GET) get all study groups

/api/studyGroups/
(POST) create a study group

/api/studyGroups/:guid/add/:cuid
(GET) add specific user (cuid) to specific study group (guid)

/api/studyGroups/:guid
(GET) get specific study group (guid)

/api/studyGroups/:guid/messages
(GET) get specific study group messages

/api/studyGroups/:guid/addMessage
(PUT) add a message to a study group

/api/studyGroups/:guid/deleteMessages
(DELETE) delete messages from a study group

Chat API

Database

The application uses MongoDB to store the data. MongoDB is a document-oriented database that uses JSON-like documents with schemas. It also makes use of Mongoose library that provides a straight-forward, schema-based solution to model the application data. The models are defined as follows

User Model

const userSchema = new Schema({
  cuid: { type: 'String', required: true },
  firstName: { type: 'String', required: true },
  lastName: { type: 'String', required: true },
  studentId: { type: 'Number', required: true },
  password: { type: 'String', required: true },
  email: { type: 'String', required: true },
  dateAdded: { type: 'Date', default: Date.now, required: true },
  lastLogin: { type: 'Date', default: null, required: false },
  studyGroups: ['studyGroup']
});

Study Group Model

const studyGroupSchema = new Schema({
  guid: { type: 'String', required: true },
  groupName: { type: 'String', required: true },
  course: { type: 'String', required: true },
  teacher: { type: 'String', required: true },
  description: { type: 'String', required: true },
  dateAdded: { type: 'Date', default: Date.now, required: true },
  chatMessages: ['message']
});

Message Model

const messageSchema = new Schema({
  cuid: { type: 'String', required: true },
  dateSent: { type: 'Date', default: Date.now, required: true },
  messageContent: { type: 'String', required: true },
  author: { type: 'String', required: true },
  studyGroup: { type: 'String', required: true },
});

Testing

The backend api endpoints were tested using 2 different methods;

  • using the POSTMAN application
  • using AVAjs assertion library
Clone this wiki locally