GithubHelp home page GithubHelp logo

fancy-to-do's Introduction

fancy-to-do

A simple to-do app created in node.js, express, postgres. It has following features:

  • RESTful endpoint to do CRUD actions on to-do item and returns JSON formatted response.
  • User system, separate to-dos by user
  • Stateless authentication using JSONWebToken
  • Uses Bored API to add new random activity to to-do list
  • Uses Google Sign-In for Websites to log in with Google Account

The client is a Single Page App created in HTML, CSS, and JavaScript using Materialize and jQuery

Available REST Endpoints

POST /register

Registers a new account

Request Header

{
	"Content-Type": "application/json"
}

Request Body

{
	"email": "[email protected]",
	"password": "passwordhere"
}

Responses

201 CREATED

{
    "id": 9,
    "email": "[email protected]",
    "password": "test"
}

400 BAD REQUEST

Happens when the validation doesn't pass or the e-mail has been registered

{
    "errors": [
        "This E-mail has been registered."
    ]
}
{
    "errors": [
        "password is required.",
        "email is required.",
        "email is not valid."
    ]
}

POST /login

Logs in to an account to access to-do item

Request Header

{
	"Content-Type": "application/json"
}

Request Body

{
	"email": "[email protected]",
	"password": "passwordhere"
}

Responses

201 CREATED

Returns an access token that you can use to access the to-do item

{
    "accessToken": "[ACCESS TOKEN HERE]"
}

400 BAD REQUEST

Happens when the password or e-mail entered is not valid

{
    "errors": "Invalid Username/Password"
}

GET /todos

Get the list of all to-dos created by logged in user

Request Header

{
	"accessToken": "ACCESS TOKEN HERE"
}

Response

200 OK

[
    {
        "id": 1,
        "title": "Todo 1",
        "description": "Todo List 1",
        "status": "uncompleted",
        "due_date": "2020-04-10T17:00:00.000Z"
    },
    {
        "id": 2,
        "title": "Todo 2",
        "description": "Todo List 2",
        "status": "uncompleted",
        "due_date": "2020-04-14T17:00:00.000Z"
    },
    {
        "id": 3,
        "title": "Todo 3",
        "description": "Todo List 3",
        "status": "completed",
        "due_date": "2020-04-18T17:00:00.000Z"
    }
]

401 UNAUTHORIZED

Happens if you haven't set "accessToken" request header or the token is invalid

{
    "errors": "Invalid or missing token"
}

GET /todos/[id]

Get the specific to-do item. Only can access todo item created by logged in user.

Parameters

Name Description
id ID of the to-do item

Request Header

{
	"accessToken": "ACCESS TOKEN HERE"
}

Responses

200 OK

Returns data of the to-dos

{
    "id": 1,
    "title": "Todo 1",
    "description": "Todo List 1",
    "status": "uncompleted",
    "due_date": "2020-04-10T17:00:00.000Z"
}

401 UNAUTHORIZED

Happens if you haven't set "accessToken" request header or the token is invalid

{
    "errors": "Invalid or missing token"
}

403 FORBIDDEN

Happens if you access other user to-do item

{
    "errors": "You are not authorized to access this item"
}

404 NOT FOUND

{
    "errors": "Todo not found"
}

POST /todos

Add new to-do item

Request Header

{
	"Content-Type": "application/json",
	"accessToken": "ACCESS TOKEN HERE"
}

Request Body

{
	"title": "Todo Title",
	"description": "Descriptions here",
	"status": "uncompleted",
	"due_date": "2020-01-01"
}

Responses

201 CREATED

Returns data of the created to-do item

{
    "id": 7,
    "title": "Todo Title",
    "description": "Descriptions here",
    "status": "uncompleted",
    "due_date": "2020-01-01T00:00:00.000Z"
}

400 BAD REQUEST

Usually returns validation errors

{
    "errors": [
        "title is empty",
        "description is empty",
        "status is empty",
        "due_date is empty",
        "due_date must be in date format: YYYY-MM-DD"
    ]
}

401 UNAUTHORIZED

Happens if you haven't set "accessToken" request header or the token is invalid

{
    "errors": "Invalid or missing token"
}

POST /todos/random

Add new to-do item with random activity

Request Header (Optional)

{
	"Content-Type": "application/json"
}

Request Body (Optional)

If omitted, the due date will be calculated by how accessible/possible the activity is ranged from 3 to 30 days

{
	"due_date": "2020-01-01"
}

Responses

201 CREATED

Returns data of the created to-do item

{
    "id": 15,
    "title": "Random activity #4708863",
    "description": "Listen to a new music genre",
    "status": "uncompleted",
    "due_date": "2020-04-03T13:49:10.974Z"
}

400 BAD REQUEST

Usually returns validation errors

{
    "errors": [
        "due_date must be in date format: YYYY-MM-DD"
    ]
}

401 UNAUTHORIZED

Happens if you haven't set "accessToken" request header or the token is invalid

{
    "errors": "Invalid or missing token"
}

PUT /todos/[id]

Edit specific to-do item. Only can access todo item created by logged in user.

Parameters

Name Description
id ID of the to-do item

Request Header

{
	"Content-Type": "application/json",
	"accessToken": "ACCESS TOKEN HERE"
}

Request Body

{
	"title": "Todo Title",
	"description": "Descriptions here",
	"status": "uncompleted",
	"due_date": "2020-01-01"
}

Responses

200 OK

Returns updated data of the edited to-do item

{
    "id": 7,
    "title": "Todo Title",
    "description": "Descriptions here",
    "status": "uncompleted",
    "due_date": "2020-01-01T00:00:00.000Z"
}

400 BAD REQUEST

Usually returns validation errors

{
    "errors": [
        "title is empty",
        "description is empty",
        "status is empty",
        "due_date is empty",
        "due_date must be in date format: YYYY-MM-DD"
    ]
}

401 UNAUTHORIZED

Happens if you haven't set "accessToken" request header or the token is invalid

{
    "errors": "Invalid or missing token"
}

403 FORBIDDEN

Happens if you access other user to-do item

{
    "errors": "You are not authorized to access this item"
}

404 NOT FOUND

{
    "errors": "Todo not found"
}

DELETE /todos/[id]

Delete specific to-do item. Only can access todo item created by logged in user.

Parameters

Name Description
id ID of the to-do item

Request Header

{
	"accessToken": "ACCESS TOKEN HERE"
}

Responses

200 OK

Returns data of the deleted to-do item

{
    "id": 7,
    "title": "Todo Title",
    "description": "Descriptions here",
    "status": "uncompleted",
    "due_date": "2020-01-01T00:00:00.000Z"
}

401 UNAUTHORIZED

Happens if you haven't set "accessToken" request header or the token is invalid

{
    "errors": "Invalid or missing token"
}

403 FORBIDDEN

Happens if you access other user to-do item

{
    "errors": "You are not authorized to access this item"
}

404 NOT FOUND

{
    "errors": "Todo not found"
}

fancy-to-do's People

Contributors

andievandy avatar stefkwan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.