Skip to content

Use-My-Tech-Stuff-1/backend

Repository files navigation

Back-End

Schema

Users

Field Type Notes
id integer primary key and autoincrements
email string required and unique
password string required
username string required
role integer required

Role

Field Type Notes
id integer foreign key and autoincrements
name string required and unique

Borrowing

Field Type Notes
borrower_id integer foreign key ID from the user table
p_id integer ID from the products table

Product

Field Type Notes
prod_id integer primary key and autoincrements
name string required; name of the item
image_URL string product image
price text price
content text required; review of the tech stuff
owner integer foreign key ID of the author of the listing

API

BASE URL: https://usemy-techstuff.herokuapp.com/ test account:

{
  "username": "testing",
  "password": "qwerty",
  "email": "someemail@somehting.com"
}

Table of Contents

Type Path Notes Example
POST /api/auth/register register a new user link
POST /api/auth/login login an user link
 
GET /api/users/ get all users info; requires authorization
GET /api/users/:user_id get user info; requires authorization link
PUT /api/users/:user_id/username update user username; requires authorization link
PUT /api/users/:user_id/email update user email; requires authorization link
PUT /api/users/:user_id/password update user password; requires authorization link
 
GET /api/product get products link
GET /api/product/:id get a product link
GET /api/product/find/available get products that are not borrowed by anyone link
GET /api/product/by-owner/:user_id get all products owned by a specific user link
GET /api/product/borrowing/:user_id get products a user is currently borrowing link
POST /api/product create a new product post; requires name and content link
POST /api/product/:id/borrow-item posts to the borrowers table to they are borrowing the project; link
PUT /api/product/:id update a product; requires authorization; link
DELETE /api/product/:id delete a product; requires authorization; link
DELETE /api/product/:id/return-item returns an item by deleting the borrowing record; requires authorization; link

Examples

POST /api/auth/register

request data:

{
  "email": "username@email.com",
  "password": "password",
  "username": "Name"
}

response data:

{
  "user": {
    "id": 1,
    "email": "username@email.com",
    "username": "Name"
  },
  "authorization": "really.long.token"
}

POST /api/auth/login

request data:

{
  "username": "test123",
  "password": "test"
}

response data:

{
  "user": {
    "id": 1,
    "email": "username@email.com",
    "username": "Name"
  },
  "authorization": "really.long.token"
}

GET /api/users/:user_id

response data

{
  "id": 1,
  "email": "username@email.com",
  "username": "Name"
}

PUT /api/users/:user_id/username

request data

{
  "username": "Name",
}

response data

{
  "id": 1,
  "email": "username@email.com",
  "username": "Name"
}

PUT /api/users/:user_id/email

request data

{
  "email": "username@email.com"
}

response data

{
  "id": 1,
  "email": "username@email.com",
  "username": "Name"
}

PUT /api/users/:user_id/password

request data

{
  "password": "new password"
}

response data

{
  "id": 1,
  "email": "username@email.com",
  "username": "Name"
}

DELETE /api/users/:user_id

response data

no content

GET /api/product/:product_id

response data

{
  "prod_id": 1,
  "name": "Name",
  "price": "Price here",
  "image_URL": "image.com",
  "content": "About the product text",
  "ownerName": "owners name",
  "owner": "owners id",
  "borrowerName": "borrowers name", //null if no borrower
  "borrower_ID": "borrowers id" //null if no borrower

}

PUT /api/product/:product_id

request data

{
  "name": "Name",
  "price": "Price here",
  "image_URL": "image.com",
  "content": "About the product text",

}

response data

{
  "id": 1,
  "name": "Name",
  "price": "Price here",
  "image_URL": "image.com",
  "content": "About the product text",

}

DELETE /api/product/:product_id

response data

no content

DELETE /api/product/:id/return-item

response data

no content

GET /api/product

response data

[
  {
    "prod_id": 1,
    "name": "Name",
    "price": "Price here",
    "image_URL": "image.com",
    "content": "About the product text",
    "ownerName": "owners name",
    "owner": "owners id",
    "borrowerName": "borrowers name", //null if no borrower
    "borrower_ID": "borrowers id" //null if no borrower
  },
  {
    "prod_id": 2,
    "name": "Name",
    "price": "Price here",
    "image_URL": "image.com",
    "content": "About the product text",
    "ownerName": "owners name",
    "owner": "owners id",
    "borrowerName": "borrowers name", //null if no borrower
    "borrower_ID": "borrowers id" //null if no borrower
  }
]

GET /api/product/find/available

response data

[
  {
    "prod_id": 1,
    "name": "Name",
    "price": "Price here",
    "image_URL": "image.com",
    "content": "About the product text",
    "ownerName": "owners name",
    "owner": "owners id",
    "borrowerName": null,
    "borrower_ID": null
  },
  {
    "prod_id": 2,
    "name": "Name",
    "price": "Price here",
    "image_URL": "image.com",
    "content": "About the product text",
    "ownerName": "owners name",
    "owner": "owners id",
    "borrowerName": null,
    "borrower_ID": null
  }
]

GET /api/product/by-owner/:user_id

response data

[
  {
    "prod_id": 1,
    "name": "Name",
    "price": "Price here",
    "image_URL": "image.com",
    "content": "About the product text",
    "ownerName": "owners name",
    "owner": "owners id",
    "borrowerName": null,
    "borrower_ID": null
  }
]

GET /api/product/borrowing/:user_id

response data

[
  {
    "prod_id": 1,
    "name": "Name",
    "price": "Price here",
    "image_URL": "image.com",
    "content": "About the product text",
    "ownerName": "owners name",
    "owner": "owners id",
    "borrowerName": "name of borrower",
    "borrower_ID": "borrowers id"
  }
]

POST /api/product

request data

{
  "name": "Name",
  "price": "Price here",
  "image_URL": "image.com",
  "content": "About the product text",
  "owner": "id of the user making the post"
}

response data

{
  "id": 1,
  "name": "Name",
  "price": "Price here",
  "image_URL": "image.com",
  "content": "About the product text",
  "owner": "id of the user making the post"
}

POST /api/product/:id/borrow-item

request data

{
  "p_id": "id of the product",
  "borrower_id": "id of the borrower"
}

response data

{
  "p_id": "id of the product",
  "borrower_id": "id of the borrower"
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors