Skip to content
williamlixu edited this page Mar 30, 2020 · 4 revisions

All Flats API endpoints require authorization to enable authorization to follow these steps

  1. Call the user Login endpoint
  2. retrieve the token from the response of the login
  3. add "Bearer <jwt token>" to the Authorisation Header field
  4. Send the Flats API request

1. /api/Flat/getMembers

Method: GET

Description: This method is used to get all the members in the flat

Response

example request URL: https://localhost:44394/api/Flat/getMembers

StatusCode: 200 OK

   {
    "flatMembers": [
        {
            "id": 0,
            "userName": "BeboBryan",
            "firstName": "Bryan",
            "lastName": "Ang",
            "dateOfBirth": "1984-02-09T00:00:00",
            "phoneNumber": "02243926392",
            "email": "BryanAng@Gmail.com",
            "medicalInformation": "N/A",
            "bankAccount": "98-7654-3211234-210",
            "hashedPassword": null
        },
        {
            "id": 0,
            "userName": "YinWang",
            "firstName": "Yin",
            "lastName": "Wang",
            "dateOfBirth": "1994-12-23T00:00:00",
            "phoneNumber": "0279284492",
            "email": "YinWang@qq.com",
            "medicalInformation": "N/A",
            "bankAccount": "00-0000-0000000-000",
            "hashedPassword": null
        },
        {
            "id": 0,
            "userName": "TreesAreGreen",
            "firstName": "Teresa",
            "lastName": "Green",
            "dateOfBirth": "1996-02-12T00:00:00",
            "phoneNumber": "0228937228",
            "email": "GreenTrees@Yahoo.com",
            "medicalInformation": "Vegan, Gluten-Free, Lactose Intolerant",
            "bankAccount": "12-3456-1234567-123",
            "hashedPassword": null
        },
        {
            "id": 0,
            "userName": "TonOfClay",
            "firstName": "Clay",
            "lastName": "Ton",
            "dateOfBirth": "1985-06-16T00:00:00",
            "phoneNumber": "02106849475",
            "email": "ClayTon@Gmail.com",
            "medicalInformation": "N/A",
            "bankAccount": "11-5723-2835024-110",
            "hashedPassword": null
        }
    ]
} 

2. /api/Flat/AddUserToFlat/{username}

Method: GET

Description: This method is used to add a user to an existing flat with a username

The result code enum

        /// <summary>`
        /// 0  Default/Nothing`
        /// 1  Success`
        /// 2  NoUser`
        /// 3  NoFlat`
        /// 4  UserAlreadyInFlat`
        /// 5  UserInOtherFlat`
        /// </summary>`

Response

example request URL: https://localhost:44394/api/Flat/AddUserToFlat/TestUser2

STATUS CODE: 200 OK

{
  "addedUser": {
    "id": 999,
    "userName": "TestUser2",
    "firstName": "Test",
    "lastName": "Test",
    "dateOfBirth": "1984-02-09T00:00:00",
    "phoneNumber": null,
    "email": null,
    "medicalInformation": null,
    "bankAccount": null,
    "hashedPassword": "AQAAAAEAACcQAAAAEBuR1UrmeN466pDREWZHZ7uy8RkhO80iPlMes0vvrWQ4tNEtOIjXQBqyiIAXfnHTFg=="
  },
  "resultCode": 1
}

3. /api/Flat/createFlat/

Method: POST

Description: This method is used to create a new flat

Response

example request URL: https://localhost:44394/api/Flat/creatFlat/

STATUS CODE: 201: Able to find the user and create a new flat for them

STATUS CODE: 401: Not an authorized user

STATUS CODE: 403: Attempting to create a new flat while already part of one

The JSON representation of the user's newly created flat

{
  "flatMembers": [
    {
      "id": 0,
      "userName": "string",
      "firstName": "string",
      "lastName": "string",
      "dateOfBirth": "2020-03-19T07:16:09.584Z",
      "phoneNumber": "string",
      "email": "string",
      "medicalInformation": "string",
      "bankAccount": "string",
      "hashedPassword": "string"
    }
  ]
}

4. /api/Flat/{deleteUserName}

Method: DELETE

Description: Remove a member out of a flat

Response

example request URL: https://localhost:44394/api/Flat/YinWang

The response body is the flat members. The user have successfully remove her/himself from the flat, and be redirected to create flat page. StatusCode: 202 ACCEPTED

   {
    "flatMembers": [
        {
            "id": 0,
            "userName": "BeboBryan",
            "firstName": "Bryan",
            "lastName": "Ang",
            "dateOfBirth": "1984-02-09T00:00:00",
            "phoneNumber": "02243926392",
            "email": "BryanAng@Gmail.com",
            "medicalInformation": "N/A",
            "bankAccount": "98-7654-3211234-210",
            ... (see api/Flat/getMembers)
        } ...
    ]
} 
Clone this wiki locally