Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

Medical-Cabinet-2/Back-End

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API User Guide

BASE URL https://node-server-med-cabinet.herokuapp.com

Table of Contents:

Authentication Routes | Recommendation Routes | Strain Routes | Helper Routes

Authentication Routes

User Registration:

POST /api/auth/register

Creates a new user account. Returns an object with user info and a JSON web token.

Input:

{
  email: "[email protected]", // string (required)
  password: "abc123!", // string (required)
  first_name: "firstname", // string (required)
  last_name: "lastname" // string (required)
}

Output:

{
  user: {
      id: 1,
      email: "[email protected]",
      first_name: "firstname",
      last_name: "lastname"
  },
  token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6OSwicm9sZV9pZCI6MSwiaWF0IjoxNTc3MTY1MDY3LCJleHAiOjE1NzcxNjg2Njd9.pg1rqfKM5BxyLssMVyL8xrCW9BjKZhmqIrODlZp16Kk"
}

User Login

back to top

POST /api/auth/login

Validates user credentials. Returns an object with user info and a JSON web token.

Input:

{
  email: "[email protected]", // string (required)
  password: "abc123!", // string (required)
}

Output:

{
  message: "Welcome ${user.first_name}!",
  credentials: {
    user: {
      id: 1,
      email: "[email protected]",
      first_name: "firstname",
      last_name: "lastname"
    },
    token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTc4NDE4NzY1LCJleHAiOjE1Nzg1MDUxNjV9.VIoyWSOLYiNKJR4araMaZxzAX-10fJzTsAu1NL-R0UE"
  }
}

Recommendation Routes

User Recommendation

back to top

GET /api/user/:id/recommendation

Returns an array of user recommended strains and the user id.

Request:

/api/user/1/recommendation

Response:

[
  {
    user_id: 1,
    strain_id: 7
  },
  {
    user_id: 1,
    strain_id: 8
  },
  {
    user_id: 1,
    strain_id: 9
  },
  ...
]

POST /api/user/:id/recommendation

Adds a strain to the user's recommendations. Returns a success message and an object listing the user id and strain id.

Request:

/api/user/1/recommendation

Input:

{
  strain_id: 7 // integer (required)
}

Output:

{
  message: "Blueberry Dream added",
  recommendations: {
    user_id: 1,
    strain_id: 7
  }
}

DELETE /api/user/:id/recommendation/:id

Removes recommended strain by strain id.

Request:

/api/user/1/recommendation/2

Response:

{
  message: "Recommendation removed"
}

Strain Routes

back to top

Strains

URL: https://node-server-med-cabinet.herokuapp.com/api/strains

GET /api/strains

Returns an array of all strains in the database.

Request:

// No input needed

Response:

[
  {
      id: 1,
      strain: "Ak-47"
  },
  {
      id: 2,
      strain: "Afghani"
  },
  {
      id: 3,
      strain: "Alohaberry"
  },
  ...
]

POST /api/strains

Creates a new strain in the database.

Input:

{
  strain: "Purple Kush" // string (required)
}

Output:

[
  {
      id: 1,
      strain: "Purple Kush"
  }
]

Helper Routes

back to top

PUT /api/user/:id

Updates user account information

Request:

/api/user/1

Input:

{
  email: "[email protected]" // string (required)
}

// or

{
  password: "abc123!"
}

// or

{
  first_name: "firstname"
}
...

Output:

{
  message: "User has been updated",
  user: [
    {
      id: 1,
      email: "[email protected]",
      password: "abc123!",
      first_name: "firstname",
      last_name: "lastname"
    }
  ]