How to use the backend - SOEN-341-Project/Group-P-soen341project2022 GitHub Wiki
So, you want to use the backend, huh? 
It's pretty easy if you use this handy dandy reference guide!
Accessing the backend needs one crucial thing and another one is sometimes needed, request methods and authorization
There are 3 methods that this backend supports:
Get requests are the pretty simple, they are only used when you are only interested in getting data and not sending anything else except for parameters. These are mostly going to be used with search routes such as /all or /find
Delete requests are the simplest requests as they are only used when you want to delete something. These are most likely to be used with authorization and they'll only be used with the /delete route
Post requests are the most complex requests as they are the ones that are used when you want to send data to the server. These will be the main request method for creating and updating anything.
Authorization isn't that big of a deal. This API uses a token based authentication so whenever a request is made that requires authentication, you'll need to add a token to the authorization header of the request. The authorization header should look like this Authentication: Bearer <token>. It is very important that the Bearer keyword is there because it tells the server what type of authentication is being used. The token will most likely be stored in the cookies of the client and it'll have to be attached manually to the request.
Test routes are only there for you to test if the api is working properly
- 
- Method: GET
- Requires: nothing
- Optional: Any parameters and any body
- Returns: Parameters and body
 
- 
- Method: POST
- Requires: nothing
- Optional: Any parameters and any body
- Returns: Parameters and body
 
- 
- Method: DELETE
- Requires: nothing
- Optional: Any parameters and any body
- Returns: Parameters and body
 
- 
- Method: POST
- Requires:
- Headers:
- Authorization: Yes
 
 
- Headers:
- Optional: None
- Returns: The decrypted token
 
- 
- Method: POST
- Requires:
- Body:
- 
Key Value emailThe user's email passwordThe plain password of the user roleThe user's role address1The user's address 
 
- 
 
- Body:
- Optional:
- Body
- 
Key Value usernameThe user's username firstnameThe user's first name lastnameThe user's last name sellernameThe seller's display name 
 
- 
 
- Body
- Returns: User object named userand the encrypted user object namedtoken
 
- 
- Method: POST
- Requires:
- Body:
- 
Key Value emailThe user's email passwordThe plain password of the user 
 
- 
 
- Body:
- Optional: None
- Returns: User object named userand the encrypted user object namedtokenor failure message
 
- 
- 
Method: POST 
- 
Requires: - Authorization: Any User (they can only update their own account)
- Body:
- 
Key Value idThe user's id oldPasswordThe old plain password of the user 
 
- 
 
- 
Optional: - Body:
- 
Key Value emailThe user's email passwordThe new plain password of the user address1The user's address usernameThe user's username firstnameThe user's first name lastnameThe user's last name sellernameThe seller's display name 
 
- 
 
- Body:
- 
Returns: Updated User object named userand new token namedtoken
 
- 
- 
- Method: DELETE
- Requires:
- Authorization: Token, must be admin to have parameters to delete other users, Other users cannot put parameters but if they use this route, they get deleted. Use with caution
 
- Optional:
- Parameters:
- 
Key Value idThe to be deleted user's id 
 
- 
 
- Parameters:
- Returns: Deleted user. Warning! If an admin puts no parameters, their user account gets deleted
 
- 
- Method: GET
- Requires:
- Authorization: Token, must be admin to use route
 
- Optional: None
- Returns: All users
 
- 
- Method: POST
- Requires:
- Authorization: Token, user must be seller
- Body:
- 
Key Value nameThe item's name priceThe item's price descriptionThe item's description pictureThe seller's display name brandIdThe ID of the brand associated with this item sellerIdThe ID of the seller associated with this item 
 
- 
 
- Optional:
- Body:
- 
Key Value salePriceIf the item has a salePrice, it is on sale with this price totalQuantityThe quantity of that item in stock promotedIf the item is promoted (default: false) 
 
- 
 
- Body:
- Returns: New Item
 
- 
- 
Method: DELETE 
- 
Requires: - Authorization: Token, user must be the seller that created the item or an admin
- Parameters:
- 
Key Value idThe item's id 
 
- 
 
- 
Optional: None 
- 
Returns: Deleted Item 
 
- 
- 
- Method: POST
- Requires:
- Authorization: Token, user must be the seller that created the item or an admin
- Body:
- 
Key Value idThe item's id 
 
- 
 
- Optional:
- Body:
- 
Key Value nameThe item's name priceThe item's price descriptionThe item's description pictureThe picture associated with the item (file) brandIdThe ID of the brand associated with this item sellerIdThe ID of the seller associated with this item salePriceIf the item has a salePrice, it is on sale with this price totalQuantityThe quantity of that item in stock promotedIf the item is promoted (default: false) 
 
- 
 
- Body:
- Returns: Updated Item
 
- 
- Method: GET
- Requires:
- Parameters:
- 
Key Value idThe item's id 
 
- 
 
- Parameters:
- Optional: None
- Returns: All Items
 
- 
- Method: GET
- Requires: None
- Optional: None
- Returns all the items that have the promoted property as true
 
- 
- Method: GET
- Requires: None
- Optional:
- Parameters
- 
Key Value nameThe name of the item (can be a partial name) sellerThe ID of the seller brandThe ID of the brand 
 
- 
 
- Parameters
- Returns: Items that conform to the specified search parameters
 
- 
- Method: GET
- Requires: None
- Optional: None
- Returns: All Items
 
- 
- 
Method: POST 
- 
Requires: - Authorization: Token, User cannot be a Customer to use route
- Body:
- 
Key Value nameThe name of the brand 
 
- 
 
- 
Optional: - Body:
- 
Key Value pictureThe picture of the item (file) descriptionThe description of the brand 
 
- 
 
- Body:
- 
Returns: New Brand 
 
- 
- 
- Method: DELETE
- Requires:
- Authorization: Token, User cannot be a Customer to use route
- Parameters:
- 
Key Value idThe item's id 
 
- 
 
- Optional: None
- Returns: Deleted Brand
 
- 
- Method: POST
- Requires:
- Authorization: Token, User must be an Admin to use route
- Body:
- 
Key Value idThe brand's id 
 
- 
 
- Body:
- Optional:
- Body:
- 
Key Value nameThe name of the brand descriptionThe description of the brand pictureThe picture of the item (file) 
 
- 
 
- Body:
- Returns: Updated Brand
 
- 
- Method: GET
- Requires:
- Parameters:
- 
Key Value nameThe brand's name (can be a partial name) 
 
- 
 
- Parameters:
- Optional: None
- Returns: Brands that conform to the specified search parameter
 
- 
- Method: GET
- Requires: None
- Optional: None
- Returns: All Brands
 
- 
- Method: POST
- Requires:
- Authorization: Token, user must be Customer to use route
- Body:
- 
Key Value userIdThe ID of the user making the order itemIdsAn array of integers that represent the IDs of all the items in the order itemQuantitiesAn array of integers that represent the quantities of all the items in the order totalPriceFloat that holds the total price of the order 
 
- 
 
- Optional: None
- Returns: New Order
 
- 
- Method: DELETE
- Requires:
- Authorization: Token, user must be Customer that created the order they are trying to delete or an Admin to use route
- Parameters:
- 
Key Value idThe order's id 
 
- 
 
- Optional: None
- Returns: Deleted Order
 
- 
- Method: POST
- Requires:
- Authorization: Token, user must be Customer that created the order they are trying to delete or an Admin to use route
- Parameters:
- 
Key Value idThe order's id 
 
- 
- Body:
- 
Key Value itemIdsAn array of integers that represent the IDs of all the items in the order itemQuantitiesAn array of integers that represent the quantities of all the items in the order 
 
- 
 
- Optional:
- Body:
- 
Key Value totalPriceFloat that holds the total price of the order 
 
- 
 
- Body:
- Returns: Updated Order
 
- 
- Method: GET
- Requires:
- Parameters:
- 
Key Value idThe order id that is being searched for 
 
- 
 
- Parameters:
- Optional: None
- Returns: The order with that id
 
- 
- Method: GET
- Requires:
- Parameters:
- 
Key Value idThe item's id that is being searched for 
 
- 
 
- Parameters:
- Optional: None
- Returns: All orders with that item in it
 
- 
- Method: GET
- Requires:
- Authorization: Users can only check their own orders while admins can add a parameter to check another user's orders
- Parameters (For admin only):
- 
Key Value idThe user's id that is being searched for 
 
- 
 
- Returns: Array of all the orders that the specific user has made
 
- 
- Method: GET
- Requires: None
- Optional: None
- Returns: All Orders