Skip to content

This is the repository for the Backend team of WaterMyPlants2

License

Notifications You must be signed in to change notification settings

WaterMyPlants2/Backend

Repository files navigation

Backend

This is the repository for the Backend team of WaterMyPlants2

Back-end

Water My Plants 2

Documentation:

Base URL for Deployed API

https://water-my-plants-backend-drake.herokuapp.com/

Endpoints

Request URL Description
POST /api/auth/register creates a new user with username, phone number and password
POST /api/auth/login login valid user with username and password
POST /api/users/:id/plants adds plant for a specific user (REQUIRES TOKEN)
GET /api/auth/plants gets an array of all plants for all users
GET /api/users gets an array of all users (REQUIRES TOKEN)
GET /api/users/:id gets user info for a user with given ID (REQUIRES TOKEN)
GET /api/users/:id/plants gets an array of plants for a specific user (REQUIRES TOKEN)
GET /api/plants/:id gets info for a plant with a given ID (REQUIRES TOKEN)
PUT /api/users/:id updates info for a user with a given ID (REQUIRES TOKEN)
PUT /api/plants/:id updates info for a plant with a given ID (REQUIRES TOKEN)
DELETE /api/users/:id deletes a user with a given ID (REQUIRES TOKEN)
DELETE /api/plants/:id deletes a plant with a given ID (REQUIRES TOKEN)

Table Requirements

Users

Name Type Required Unique Notes
id integer yes yes users id (auto generated by API)
username string yes yes users name
password string yes no users password
phoneNumber string yes yes users phoneNumber

Plants

Name Type Required Unique Notes
id integer yes yes plants id (auto generated by API)
nickname string yes no plants nickname
species string yes no plants species
h2oFrequency string yes no how many times the plants need to be watered (twice a week)
image string no no url address for image of that plant (optional)
user_id integer yes no user's ID associated with plant - foreign key (will auto populate when a new seed is created)

Successfull Requests & Returns

Examples:

POST /api/auth/register

Request Body:

{
    "username": "jon",
    "password": "snow",
    "phoneNumber": "123123"
}

Returns:

{
    "newUser": {
        "id": 6,
        "username": "jon",
        "phoneNumber": "123123"
    },
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjYsInVzZXJuYW1lIjoiam9uIiwiaWF0IjoxNTkyOTQ4MjY4LCJleHAiOjE1OTMyMDc0Njh9.3vG0YC7Cf0I-w6IPxnjGkVx0u0wx8dxMCx-7TltDVqk"
}

POST /api/auth/login

Request Body:

{
   "username": "jon",
   "password": "snow"
}

Returns:

{
   "welcome": "jon",
   "user_id": 6,
   "phoneNumber": "123123",
   "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjYsInVzZXJuYW1lIjoiam9uIiwiaWF0IjoxNTkyOTQ4NjU4LCJleHAiOjE1OTMyMDc4NTh9.kMLo7IG8kmpBx-K948w3Hw7bONsAUkOlrckTerjcX1o"
}

POST /api/users/:id/plants (REQUIRES TOKEN)

Request Body:

{
    "nickname": "Green", 
    "species": "Mr.Green", 
    "h2oFrequency": "300 times a week", 
    "image": "https://images.unsplash.com/photo-1558350315-8aa00e8e4590?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1234&q=80"
}

Returns:

{
    "id": 6,
    "nickname": "Green",
    "species": "Mr.Green",
    "h2oFrequency": "300 times a week",
    "image": "https://images.unsplash.com/photo-1558350315-8aa00e8e4590?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1234&q=80",
    "user_id": 1
}

GET /api/auth/plants

Returns:

[
    {
        "id": 4,
        "species": "Allium genus",
        "h2oFrequency": "5 times a week",
        "image": "https://images.unsplash.com/photo-1558350315-8aa00e8e4590?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1234&q=80"
    },
    {
        "id": 6,
        "species": "Mr.Green",
        "h2oFrequency": "300 times a week",
        "image": "https://images.unsplash.com/photo-1558350315-8aa00e8e4590?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1234&q=80"
    }
]

GET /api/users (REQUIRES TOKEN)

Returns:

[
    {
        "id": 1,
        "username": "cat",
        "phoneNumber": "676767"
    },
    {
        "id": 2,
        "username": "liz",
        "phoneNumber": "3232"
    },
    {
        "id": 3,
        "username": "mark",
        "phoneNumber": "7171"
    },
    {
        "id": 4,
        "username": "brian",
        "phoneNumber": "56565"
    },
    {
        "id": 6,
        "username": "jon",
        "phoneNumber": "123123"
    }
]

GET /api/users/:id (REQUIRES TOKEN)

Returns:

{
    "id": 6,
    "username": "jon",
    "phoneNumber": "123123"
}

GET /api/users/:id/plants (REQUIRES TOKEN)

Returns:

[
    {
        "plant_id": 4,
        "nickname": "Allen",
        "species": "Allium genus",
        "h2oFrequency": "5 times a week",
        "image": "https://images.unsplash.com/photo-1558350315-8aa00e8e4590?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1234&q=80",
        "user": "cat"
    },
    {
        "plant_id": 6,
        "nickname": "Green",
        "species": "Mr.Green",
        "h2oFrequency": "300 times a week",
        "image": "https://images.unsplash.com/photo-1558350315-8aa00e8e4590?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1234&q=80",
        "user": "cat"
    }
]

GET /api/plants/:id (REQUIRES TOKEN)

Returns:

{
    "id": 6,
    "nickname": "Green",
    "species": "Mr.Green",
    "h2oFrequency": "300 times a week",
    "image": "https://images.unsplash.com/photo-1558350315-8aa00e8e4590?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1234&q=80",
    "user_id": 1
}

PUT /api/users/:id (REQUIRES TOKEN)

Request Body(Can updates user's info):

{   "username": "jon",
    "password": "stark",
    "phoneNumber": "555"
}

Returns(Password will update BUT it will not return the password for security purposes):

{
    "id": 6,
    "username": "jon",
    "phoneNumber": "555"
}

PUT /api/plants/:id (REQUIRES TOKEN)

Request Body:

{
    "nickname": "Tomato",
    "species": "Mr.Red",
    "h2oFrequency": "2 times a week",
    "image": "https://images.unsplash.com/photo-1558350315-8aa00e8e4590?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1234&q=80"
}

Returns:

{
    "id": 6,
    "nickname": "Tomato",
    "species": "Mr.Red",
    "h2oFrequency": "2 times a week",
    "image": "https://images.unsplash.com/photo-1558350315-8aa00e8e4590?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1234&q=80",
    "user_id": 1
}

DELETE /api/users/:id (REQUIRES TOKEN)

Returns:

{
    "message": "User with ID 6 has been removed"
}

DELETE /api/plants/:id (REQUIRES TOKEN)

Returns:

{
    "message": "Plant with ID 6 has been removed"
}

# Dependencies Used 

"dependencies": {
  "bcryptjs": "^2.4.3",
  "dotenv": "^8.2.0",
  "express": "^4.17.1",
  "helmet": "^3.23.1",
  "jsonwebtoken": "^8.5.1",
  "knex": "^0.21.1",
  "cors": "^2.8.5",
  "sqlite3": "^4.2.0",
},
"devDependencies": {
  "jest": "^24.3.1",
  "nodemon": "^1.18.10",
  "supertest": "^4.0.0"
}

Author

  • Drake Alia

About

This is the repository for the Backend team of WaterMyPlants2

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published