Skip to content

nasrulfuad/todo-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MERN Todo App

Todo App built with Mongodb, Express, React, NodeJS

Quick Start

Add your MONGO_URI to the default.json file. Make sure you set an env var for that and the jwtSecret on deployment

# Install dependencies for server
npm install

# Install dependencies for client
npm run client-install

# Run the client & server with concurrently
npm run dev

# Run the Express server only
npm run server

# Run the React client only
npm run client

# Server runs on http://localhost:5000 and client on http://localhost:3000

API Documentation

HOST: http://localhost:3000/api/

Allowed HTTPs requests:

POST    : Register / Login, Add new todo
GET     : Get user data
PUT     : Update todo

Description Of Usual Server Responses:

  • 201 Created - the request was successful and a resource was created.
  • 202 Accepted - response status code indicates that the request has been received but not yet acted upon
  • 400 Bad Request - the request could not be understood or was missing required parameters.
  • 401 Unauthorized - authentication failed or user doesn't have permissions for requested operation.
  • 403 Forbidden - access denied.

User collections:

  • name (String) : mandatory
  • email (String) : unique, mandatory
  • password (String) : mandatory, min(6)
  • todos (Array) : default(null)
  • registerDate (Date) : default(Date.now)

Todos document :

  • name (String)
  • createdAt (Date)

User Route [/api/users]

Register new User [POST]

@route   POST /api/users
@desc    Register new user
@access  Public
  • Request (application/json) | Contoh API request di postman

          {
              "name": "johndoe",
              "email": "johndoe@email.com",
              "password": "Johndoe123!"
          }
    
  • Response 201 (application/json) | Registrasi berhasil

          {
              "msg": "Registrasi berhasil",
              "token" : "blablabla",
              "user": {
                  "id": "blabla",
                  "name": "blabla",
                  "email": "blabla"
              }
          }
    
  • Response 400 (application/json) | Email sudah terdaftar

          {
              "msg": "Email sudah terdaftar"
          }
    
  • Response 400 (application/json) | Semua kolom harus di isi

          {
              "msg": "Mohon isi semua kolom"
          }
    

Authenticate user / Login

@route    POST /api/auth/
@desc     Authenticate user
@access   public
  • Response 202 | Get data and token

  • Response 400 (application/json) | Semua kolom harus di isi

          {
              "msg": "Mohon isi semua kolom"
          }
    
  • Response 400 (application/json) | Email belum terdaftar

          {
              "msg": "Email belum terdaftar"
          }
    
  • Response 400 (application/json) | Password salah

          {
              "msg": "Password salah"
          }
    

Get user data after login

@route    GET /api/auth/user
@desc     Get user data
@access   private
  • Response 202 | Get data and token

  • Response 401 (application/json) | No token available

          {
              "msg": "No token, authorization denied"
          }
    
  • Response 400 (application/json) | Token does not match

          {
              "msg": "Invalid token"
          }
    

Get user todos

@route    GET /api/todos
@desc     Get user todos
@access   private
  • Response 200 | Get todos

  • Response 401 (application/json) | No token available

          {
              "msg": "No token, authorization denied"
          }
    
  • Response 400 (application/json) | Token does not match

          {
              "msg": "Invalid token"
          }
    

Create new user todo

@route    POST /api/todos
@desc     Create a todo
@access   private
  • Response 202 | Todo berhasil di tambahkan

  • Response 401 (application/json) | No token available

          {
              "msg": "No token, authorization denied"
          }
    
  • Response 400 (application/json) | Token does not match

          {
              "msg": "Invalid token"
          }
    
  • Response 400 (application/json) | Todo tidak boleh kosong

          {
              "msg": "Todo tidak boleh kosong"
          }
    
  • Response 400 (application/json) | Todo sudah ada

          {
              "msg": "Todo sudah ada"
          }
    
  • Response 400 (application/json) | Todo tidak boleh kosong

          {
              "msg": "Todo tidak boleh kosong"
          }
    

Delete user todo

@route    DELETE /api/todos/:id
@desc     Delete a todo
@access   private
  • Response 202 | Todo berhasil di hapus

  • Response 401 (application/json) | No token available

          {
              "msg": "No token, authorization denied"
          }
    
  • Response 400 (application/json) | Token does not match

          {
              "msg": "Invalid token"
          }
    

Edit user todo

@route    PUT /api/todos/:id
@desc     Edit a todo
@access   private
  • Response 202 | Todo berhasil di update

  • Response 401 (application/json) | No token available

          {
              "msg": "No token, authorization denied"
          }
    
  • Response 400 (application/json) | Token does not match

          {
              "msg": "Invalid token"
          }
    
  • Response 400 (application/json) | Todo name kosong

          {
              "msg": "Nama todo tidak boleh kosong"
          }
    

About

Built with Mongodb, ExpressJS, ReactJS, Nodejs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published