NAV Navbar
javascript
  • DocManger API Documentation
  • Users
  • Documents
  • Roles
  • DocManger API Documentation

    Introduction

    Docmanger API contains several end points that allows users to create, edit, retrieve and delete documents. It also sets access privileges so only authorized users can perform certain operations.

    Development

    The application was developed with NodeJs and Express is used for routing. The Postgres database was used with sequelize as the ORM.

    Installation

    Follow the steps below to setup a local development environment. First ensure you have Postgresql installed, and a version of Node.js equal or greater than v6.8.0.

    1. Clone the repository to your local machine: git clone ttps://github.com/andela-mugochukwu/DocManager.git.
    2. Cd into the project directory: cd DocManager
    3. Install project dependencies yarn install
    4. Start the express server in development mode: yarn start:dev.

    API Summary

    Users

    EndPoint Functionality
    POST /api/v1/users/login Logs in a user.
    POST /api/v1/users/ Creates a new user.
    GET /api/v1/users/ Gets all registered users (available only to the Admin).
    GET /api/v1/users/:id Finds a particular user by his/her id.
    PUT /api/v1/users/:id Updates a user's attributes based on the id specified (available to the profile owner or admin)
    DELETE /api/v1/users/:id Deletes a user (available only to the profile owner)
    GET /api/v1/users/:id/documents Gets all documents belonging to a particular user

    Documents

    EndPoint Functionality
    POST /api/v1/documents/ Creates a new document.
    GET /api/v1/documents/ Gets all documents.
    GET /api/v1/documents/:id Find a particular document by it's id.
    PUT /api/v1/documents/:id Updates a document attributes. (available only to the owner)
    DELETE /api/v1/documents/:id Delete a particular document. (available only to the owner)
    GET /api/search/documents/?searchKey=${query} Get all documents with title or content containing the search query

    Roles (available only to the SuperAdmin)

    EndPoint Functionality
    GET /api/v1/roles/ Get all created Roles.
    POST /api/v1/roles/ Create a new Role.
    DELETE /api/v1/roles/:id Delete a Role.

    Users

    List All Users

    Sample JSON structured response:

    {
      "users": [
          {
              "id": 12,
              "userName": "Tolu",
              "fullname": "Tolu Afobs",
              "roleId": 2,
              "email": "tolu@gmail.com"
          },
          {
              "id": 11,
              "userName": "biodun",
              "fullname": "biodun",
              "roleId": 2,
              "email": "biodun@gmail.com"
          },
          {
              "id": 8,
              "userName": "Rob",
              "fullname": "Robert Ludlum",
              "roleId": 2,
              "email": "robert@robert.com"
          },
          {
              "id": 7,
              "userName": "Johnie",
              "fullname": "John Grisham",
              "roleId": 2,
              "email": "john@grisham.com"
          },
          {
              "id": 6,
              "userName": "Dorian",
              "fullname": "Dorian Gray",
              "roleId": 2,
              "email": "dorian@gray.com"
          },
          {
              "id": 5,
              "userName": "Max",
              "fullname": "Gruocho",
              "roleId": 2,
              "email": "max@max.com"
          }
      ],
      "paginationMetaData": {
          "totalCount": 9,
          "pages": 2,
          "page": 1,
          "pageSize": 6
      }
    }
    

    Request

    Query Parameters

    Parameter Default Description
    limit 6 Sets the limit.
    offset 0 Sets the offset.

    Response

    Create User

    Request:

    {
      "username": "doro",
      "email": "doro@bucci.com",
      "roleId": "3",
      "password": "dorobucci",
      "confirmPassword": "dorobucci",
    }
    

    Sample JSON structured response:

    {
       "status": "successfull",
        "userId": 1,
        "userName": "tolu",
        "roleType": "Fellow",
        "roleId": 3,
        "email": "tolu@gmail.com",
        "createdAt": "Apr 4 2018",
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsInJvbGVJZCI6MSwiaWF0IjoxNTAyMTAwMzA5LCJleHAiOjE1MDIxODY3MDl9.vzMK6Mr7cLr7rk5mXF5KeRXlJn913XBJXQjaOGJEiXo",
    }
    

    Request

    Response

    Get User

    Sample JSON structured response:

    {
      "userName": "Mikail",
      "userEmail": "mikahil.stanislaski@gmail.com",
      "userRole": " "Fellow"
    }
    

    Request

    Response

    Edit User

    Request:

    {
      "email": "mike@gmail.com",
    }
    

    Sample JSON structured response:

    {
      "status": "successful"
    }
    

    Request

    Response

    Delete User

    Sample JSON structured response:

    {
        "status": "successful"
      "message": "User deleted successfully"
    }
    

    Request

    Response

    Login User

    Request:

    {
      "userName": "tolu",
      "password": "afolabi"
    }
    

    Sample JSON structured response:

    {
        "status": "successfull",
        "userId": 1,
        "userName": "tolu",
        "roleType": "Fellow",
        "roleId": 3,
        "email": "tolu@gmail.com",
        "createdAt": "Apr 4 2018",
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsInJvbGVJZCI6MSwiaWF0IjoxNTAyMTAwMzA5LCJleHAiOjE1MDIxODY3MDl9.vzMK6Mr7cLr7rk5mXF5KeRXlJn913XBJXQjaOGJEiXo",    
    }
    
    ### Request
    - Endpoint: GET: `/api/v1/users/:id/documents`
    - Requires: Authentication
    
    ### Response
    - Status: `200: OK`
    - Body: `(application/json)`
    
    
    ## Search Users
    
    > Sample JSON structured response:
    
    ```javascript
    {
      "users": [
          {
              "id": 12,
              "username": "Tolu",
              "isactive": "True",
              "roleId": 2,
              "createdAt": "Jun 4 2017",
              "email": "tolu@gmail.com"
          },
          {
              "id": 12,
              "username": "James",
              "isactive": "True",
              "roleId": 2,
              "createdAt": "Jun 4 2017",
              "email": "james@gmail.com"
          },
          {
             "id": 12,
              "username": "Mattew",
              "isactive": "True",
              "roleId": 2,
              "createdAt": "Jun 4 2017",
              "email": "mattew@gmail.com"
          },
      ],
      "paginationMetaData": {
          "pageCount": 2,
          "page": 1,
          "pageSize": 6
      }
    }
    

    Request

    Query Parameters

    Parameter Default Description
    searchKey "" Search query.

    Response

    Documents

    List All Documents

    Sample JSON structured response:

    {
      "documents": [
          {
              "id": 15,
              "userId": 1,
              "title": "Biodun's Dilemma",
              "access": "Private",
              "body": "So, what will I eat for breakfast now that there's an election going on????",
              "createdAt": "2017-07-22T06:53:06.520Z",
              "updatedAt": "2017-07-22T06:53:06.520Z",
          },
          {
               "id": 14,
              "userId": 1,
              "title": "Biodun's is Dilemma",
              "access": "Private",
              "body": "So, what will I eat for breakfast and now that there's an election going on????",
              "createdAt": "2017-07-22T06:53:06.520Z",
              "updatedAt": "2017-07-22T06:53:06.520Z",
          },
          {
               "id": 11,
              "userId": 1,
              "title": "Biodun's is my Dilemma",
              "access": "Public",
              "body": "So, what will I eat now that there's an election going on????",
              "createdAt": "2017-07-22T06:53:06.520Z",
              "updatedAt": "2017-07-22T06:53:06.520Z",
          },
      ],
      "paginationMetaData": {
          "totalCount": 7,
          "pages": 2,
          "currentPage": 1,
          "pageSize": 3
      }
    }
    

    Request

    Query Parameters

    Parameter Default Description
    limit 6 Sets the limit.
    offset 0 Sets the offset.

    Response

    Create Document

    Request:

    {
      "title": "Chester",
      "body": "I'm so high, I can hear heaven. Oh, but Heaven can't hear me",
      "access": "Public"
    }
    

    Sample JSON structured response:

    {
      "status": "successful",
      "documentId": 4
    }
    

    Request

    Response

    Get Document

    Sample JSON structured response:

    {
      "status": "successful",
      "documents": {
               "id": 11,
              "userId": 1,
              "title": "Biodun's is my Dilemma",
              "access": "Public",
              "body": "So, what will I eat now that there's an election going on????",
              "createdAt": "2017-07-22T06:53:06.520Z",
              "updatedAt": "2017-07-22T06:53:06.520Z",
      }
    }
    

    Request

    Response

    Edit Document

    Request:

    {
      "body": "What's new?"
    }
    

    Sample JSON structured response:

    {
      status: "successful"
    }
    

    Request

    Response

    Delete Document

    Sample JSON structured response:

    {
      "status": "successful"
      "message": "'Jungle Boy' has been deleted!"
    }
    

    Request

    Response

    Search Documents

    Request

    Response

    Sample JSON structured response:

    {
      "documents": [
          {
              "id": 15,
              "userId": 1,
              "title": "Biodun's Dilemma",
              "access": "Private",
              "body": "So, what will I eat for breakfast now that there's an election going on????",
              "createdAt": "2017-07-22T06:53:06.520Z",
              "updatedAt": "2017-07-22T06:53:06.520Z",
          },
          {
               "id": 14,
              "userId": 1,
              "title": "Biodun's is Dilemma",
              "access": "Private",
              "body": "So, what will I eat for breakfast and now that there's an election going on????",
              "createdAt": "2017-07-22T06:53:06.520Z",
              "updatedAt": "2017-07-22T06:53:06.520Z",
          },
          {
               "id": 11,
              "userId": 1,
              "title": "Biodun's is my Dilemma",
              "access": "Public",
              "body": "So, what will I eat now that there's an election going on????",
              "createdAt": "2017-07-22T06:53:06.520Z",
              "updatedAt": "2017-07-22T06:53:06.520Z",
          },
      ],
      "paginationMetaData": {
          "pages": 2,
          "currentPage": 1,
          "pageSize": 3
      }
    }
    

    Request

    Query Parameters

    Parameter Default Description
    searchKey "" Search query.

    Response

    Roles

    List All Roles

    Sample JSON structured response:

    [
      {
        "id": 1,
        "title": "admin"
      },
      {
        "id": 2,
        "title": "user"
      }
    ]
    

    Request

    Response

    Create Role

    Request:

    {
      "title": "guest",
    }
    

    Sample JSON structured response:

    {
      "id": 3,
      "title": "guest",
    }
    

    Request

    Response

    Delete Role

    Sample JSON structured response:

    {
      "message": "Role deleted successfully"
    }
    

    Request

    Response