Skip to content

CoryMci/pomodoro-api

Repository files navigation

Pomodoro API

This is the backend component for the Pomodoro-React web application. It's built with Node.js, Express, and MongoDB, Passport.js, and provides the API endpoints that the frontend interacts with.

Getting Started

  1. Clone this repository and cd into the project directory.

  2. Install dependencies with npm install.

  3. Create a .env file in the root directory with the following variables:

    PORT='port-number'
    URI= 'mongo-db-uri'
    PRIV= 'private key (RSA)'
    PUB= 'public key (RSA)'
    

    Replace 'port-number' with the desired port number for the server to run on, 'mongo-db-uri' with the URI for your MongoDB database, and PRIV and PUB with RSA keys of your choosing to sign JSON web tokens.

  4. Start the server with npm start.

API Endpoints


/register POST

Registers a new user.

Request body (Form or URL Params):


{
  "username": "username",
  "password": "password"
}

Returns a JSON object containing a success or failure message:


{
  "message": "successfully registered",
}

/login POST

Logs a user in and returns a JSON web token.

Request body (Form or URL Params):


{
  "username": "username",
  "password": "password"
}

Returns a JSON object containing the JWT:


{
  "success": BOOLEAN,
  "token": STRING(JSON Web Token),
  "expiresIn": DATE
}

Authenticated Routes

Requires JWT Authorization in header:


Bearer: "Authorization STRING(JSON Web Token)"

/api/user/summary GET

Gets a summary of a user.

Returns a JSON object containing the user's summary:


{
  "projects": [
    {
      "id": INTEGER,
      "title": STRING,
      "user": MONGOID,
      "description": STRING,
      "start_date": DATE,
      "end_date": DATE
    }
  ],
  "tasks": [
     {
        "id": MONGOID,
        "project": MONGOID,
        "user": MONGOID,
        "title": STRING,
        "created": DATE,
        "completed": BOOLEAN,
        "timeSpent": INTEGER,
        "estimatedTime": INTEGER,
     }
    ],
  "logs": [
     {
        "_id": MONGOID,
        "task": MONGOID,
        "user": MONGOID,
        "completed": BOOLEAN,
        "duration": INTEGER,
        "startTime": DATE,
     }
  ]
}

/api/project GET

Gets a list of all projects.

Returns a JSON object containing the list of projects for a user:


{
  "projects": [
    {
      "id": INTEGER,
      "title": STRING,
      "user": MONGOID,
      "description": STRING,
      "start_date": DATE,
      "end_date": DATE
    }
  ]

/api/project POST

Creates a new project for a user.

Request body (Form or URL Params):


{
  "title": STRING
  "estimatedTime": INTEGER,
}

Returns a JSON object containing a success or failure message:


{ message: "success" }

/api/project/:id GET

Gets a specific project.

Returns a JSON object containing the project details:


{
  "project": {
    "id": MONGOID,
    "user":MONGOID,
    "title": STRING,
    "description": STRING,
    "start_date": DATE,
    "end_date": DATE
  }
}

/api/project/:id PUT

Updates a specific project.

Request body (Form or URL Params):


{
  "title": STRING,
  "timeSpent": INTEGER,
  "estimatedTime: INTEGER,
  "completed": BOOLEAN,
}

Returns a JSON object containing a success or failure message:


{
  "message": "success",
}


/api/project/:id DELETE

Deletes a specific project.

Returns a JSON object containing a success or failure message:


{
  "message": "success",
}

/api/task GET

Gets a list of all tasks.

Returns a JSON object containing the list of tasks:


{
"tasks": [
            {
            "id": MONGOID,
            "project": MONGOID,
            "user": MONGOID,
            "title": STRING,
            "created": DATE,
            "completed": BOOLEAN,
            "timeSpent": INTEGER,
            "estimatedTime": INTEGER,
            }
        ]
}

/api/task POST

Creates a new task.

Request body (Form or URL Params):


{
  "project_id": PROJECT_ID,
  "title": STRING
  "estimatedTime": INTEGER,
  "due_date": DATE
}

Returns a JSON object containing a success or failure message:


{ message: "success" }

/api/task/:id DELETE

Deletes the task with the specified id.

Request parameters:


{
  "id": TASK_ID,
}

Returns a JSON object containing a success or failure message:


{
  "message": "task deleted successfully",
}

/api/task/:id PUT

Updates the task with the specified id.

Request parameters:


{
  "id": MONGOID,
}

Request body (Form or URL Params):


{
  "title": STRING,
  "timeSpent": INTEGER,
  "estimatedTime": INTEGER,
  "completed": BOOLEAN,
  "project": MONGOID,
}

Returns a JSON object with a success or failure message


{
  "message":"success"
}

/api/log POST

Creates a new time log.

Request body (Form or URL Params):


{
  "task": MONGOID,
  "completed": BOOLEAN,
  "duration": INTEGER
}

Returns a JSON object containing the ID of the created log entry:


{
  "id": MONGOID
}

/api/log/:id PUT

Updates an existing time log.

Request body (Form or URL Params):


{
  "task": MONGOID
  "completed": BOOLEAN,
  "duration": INTEGER
}

Returns a JSON object containing a success message:


{
  "message": "success",
}

/api/log/:id GET

Gets an existing time log.

Returns a JSON object containing the time log:


{
  "log": {
    "_id": MONGOID,
    "task": MONGOID,
    "user": MONGOID,
    "completed": BOOLEAN,
    "duration": INTEGER,
    "startTime": DATE,
  }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published