Skip to content

Back end for app that provides users the ability to manage their plants' watering schedules. Built with Node.js, Express, Knex.js, and PostgreSQL.

License

Notifications You must be signed in to change notification settings

ft-watermyplants-1/back-end

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Water My Plants API

---------- REGISTER / LOGIN ----------

Dummy Login Info

Usernames/Passwords
{
  "email": "fake@email.com",
  "password": "password"
}

[POST] /api/auth/register

  • Register a new user
    • email required (must be between 3 and 30 characters)
    • password required (must be between 6 and 30 characters)

What you send:

{
  "email": "SampleUser",
  "password": "abc123"
}

What you receive:

{
  "message": "Account successfully created. Welcome SampleUser!",
  "newUser": {
    "user_id": 5,
    "first_name": "SampleUser",
    "last_name": "FakeName",
    "email": "sampleuser@fake.com"
  }
}

[POST] /api/auth/login

  • Login
    • username and password required
    • provides a newly created token

What you send:

{
  "email": "sampleuser@fake.com",
  "password": "abc123"
}

What you receive:

{
  "message": "Welcome back SampleUser",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWJqZWN0Ijo1LCJ1c2VybmFtZSI6Ik5ld1VzZXIiLCJpYXQiOjE2MjcyNjY4MDYsImV4cCI6MTYyNzM1MzIwNn0.J1dFd3ghUPYVTodsaAU3Bg2RRcmYM_1oOe-96nvLLUg"
}

---------- USERS ----------

[GET] /api/users/:user_id

RESTRICTED ENDPOINT

  • Get information on a specific user
    • requires valid token in authorization header to access
    • (example uses "1" for :user_id in URL)

What you receive:

{
  "user_id": 1,
  "first_name": "test",
  "last_name": "account",
  "email": "fake@email.com",
  "plants": [
    {
      "plant_id": 1,
      "nickname": "Bob",
      "species": "Sunflower",
      "days_between_watering": 1,
      "notes": "Make sure to use clear water",
      "img_url": null
    },
    {
      "plant_id": 2,
      "nickname": "Rufus",
      "species": "Petunia",
      "days_between_watering": 3,
      "notes": null,
      "img_url": null
    }
  ]
}

[PUT] /api/users/:user_id

RESTRICTED ENDPOINT

  • Update an existing user
    • requires valid token in authorization header to send
    • can be used to update username or phone number
    • (example uses "5" for :user_id in URL)

What you send:

{
  "first_name": "updated",
  "last_name": "user",
  "email": "updated@email.com"
}

What you receive:

{
  "user_id": 5,
  "first_name": "updated",
  "last_name": "user",
  "email": "updated@email.com"
}

[DELETE] /api/users/:user_id

RESTRICTED ENDPOINT

  • Delete an existing user
    • requires valid token in authorization header to delete
    • (example uses "6" for :user_id in URL)

What you receive:

{
  "user_id": 6,
  "first_name": "deleted",
  "last_name": "user",
  "email": "deleted@email.com"
}

---------- PLANTS ----------

[GET] /api/plants

RESTRICTED ENDPOINT

  • Get an array of plants for a specific user
    • requires valid token in authorization header to access
    • (example uses "1" for :user_id in URL)

What you receive:

[
  {
    "plant_id": 1,
    "nickname": "Bob",
    "species": "Sunflower",
    "days_between_watering": 1,
    "notes": "Make sure to use clear water",
    "img_url": null,
    "user_id": 1
  },
  {
    "plant_id": 2,
    "nickname": "Rufus",
    "species": "Petunia",
    "days_between_watering": 3,
    "notes": null,
    "img_url": null,
    "user_id": 1
  }
]

[GET] /api/plants/:plant_id

RESTRICTED ENDPOINT

  • Get information for a specific plant
    • requires valid token in authorization header to access
    • (example uses "1" for :user_id and "1" for :plant_id in URL)

What you receive:

{
  "plant_id": 1,
  "nickname": "Bob",
  "species": "Sunflower",
  "days_between_watering": 1,
  "notes": "Make sure to use clear water",
  "img_url": null,
  "user_id": 1
}

[POST] /api/plants/

RESTRICTED ENDPOINT

  • Add a new plant for a user
    • requires valid token in authorization header to send
    • (example uses "1" for :user_id in URL)
    • required information:
      • nickname (string)
      • species (string)
      • days_between_watering (number)
    • optional information:
      • notes (string)
      • img_url (string)

What you send:

{
  "nickname": "Ted",
  "species": "Daffodil",
  "days_between_watering": 3,
  "notes": "Optional notes",
  "user_id": 1
}

What you receive:

{
  "plant_id": 8,
  "nickname": "Ted",
  "species": "Daffodil",
  "days_between_watering": 3,
  "notes": "Optional notes",
  "img_url": null,
  "user_id": 1
}

[PUT] /api/plants/:plant_id

RESTRICTED ENDPOINT

  • Update an existing plant
    • requires valid token in authorization header to send
    • (example uses "1" for :user_id and "8" for :plant_id in URL)
    • required information:
      • nickname (string)
      • species (string)
      • days_between_watering (number)
    • optional information:
      • notes (string)
      • img_url (string)

What you send:

{
  "nickname": "Updated Plant Nickname!!!",
  "species": "Updated species!!!",
  "days_between_watering": 6
}

What you receive:

{
  "plant_id": 8,
  "nickname": "Updated Plant Nickname!!!",
  "species": "Updated species!!!",
  "days_between_watering": 6,
  "notes": "Optional notes",
  "img_url": null,
  "user_id": 1
}

[DELETE] /api/plants/:plant_id

RESTRICTED ENDPOINT

  • Delete a plant
    • requires valid token in authorization header to delete
    • (example uses "1" for :user_id in URL)

What you receive:

{
  "plant_id": 1,
  "nickname": "Bob",
  "species": "Sunflower",
  "user_id": 1
}

About

Back end for app that provides users the ability to manage their plants' watering schedules. Built with Node.js, Express, Knex.js, and PostgreSQL.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published