diff --git a/README.md b/README.md new file mode 100644 index 0000000..e6e84f9 --- /dev/null +++ b/README.md @@ -0,0 +1,215 @@ +# SHOP API +Simple API (still WIP) + +# Routes + +## Hello World +### `GET /` +- **Description:** A simple route that returns a JSON message saying 'Hello, Flask!'. +- **Response:** + - JSON with the following structure: + ```json + { + "message": "Hello, Flask!" + } + ``` +- **Status Code:** + - 200: Success. + + +## Users +### `POST /register` +- **Description:** Register a new user. +- **Request Body:** + - JSON with the following fields: + - `username` (string): User's username. + - `displayname` (string): User's display name. + - `email` (string): User's email address. + - `password` (string): User's password. +- **Response:** + - JSON indicating the success of the registration. +- **Status Codes:** + - 200: Success. + - 400: Bad Request (if any required field is missing). + +### `POST /login` +- **Description:** Log in a user. +- **Request Body:** + - JSON with the following fields: + - `username` (string): User's username. + - `password` (string): User's password. +- **Response:** + - JSON containing authentication token and user information. +- **Status Codes:** + - 200: Success. + - 400: Bad Request (if any required field is missing). + +### `DELETE /logout` +- **Description:** Log out a user by invalidating the JWT token. +- **Authentication:** + - Requires a valid JWT token. +- **Response:** + - JSON indicating the success of the logout. +- **Status Codes:** + - 200: Success. + - 401: Unauthorized (if JWT token is missing or invalid). + +### `PUT /update/username` +- **Description:** Update the username of the authenticated user. +- **Authentication:** + - Requires a valid JWT token. +- **Request Body:** + - JSON with the following field: + - `new_username` (string): New username. +- **Response:** + - JSON indicating the success of the username update. +- **Status Codes:** + - 200: Success. + - 400: Bad Request (if new_username is missing). + - 401: Unauthorized (if JWT token is missing or invalid). + +### `PUT /update/displayname` +- **Description:** Update the display name of the authenticated user. +- **Authentication:** + - Requires a valid JWT token. +- **Request Body:** + - JSON with the following field: + - `new_displayname` (string): New display name. +- **Response:** + - JSON indicating the success of the display name update. +- **Status Codes:** + - 200: Success. + - 400: Bad Request (if new_displayname is missing). + - 401: Unauthorized (if JWT token is missing or invalid). + +### `PUT /update/email` +- **Description:** Update the email address of the authenticated user. +- **Authentication:** + - Requires a valid JWT token. +- **Request Body:** + - JSON with the following field: + - `new_email` (string): New email address. +- **Response:** + - JSON indicating the success of the email update. +- **Status Codes:** + - 200: Success. + - 400: Bad Request (if new_email is missing). + - 401: Unauthorized (if JWT token is missing or invalid). + +### `PUT /update/password` +- **Description:** Update the password of the authenticated user. +- **Authentication:** + - Requires a valid JWT token. +- **Request Body:** + - JSON with the following field: + - `new_password` (string): New password. +- **Response:** + - JSON indicating the success of the password update. +- **Status Codes:** + - 200: Success. + - 400: Bad Request (if new_password is missing). + - 401: Unauthorized (if JWT token is missing or invalid). + +### `DELETE /delete` +- **Description:** Delete the account of the authenticated user. +- **Authentication:** + - Requires a valid JWT token. +- **Response:** + - JSON indicating the success of the account deletion. +- **Status Codes:** + - 200: Success. + - 401: Unauthorized (if JWT token is missing or invalid). + +## Cart +### `GET /` +- **Description:** Retrieve the contents of the user's shopping cart. +- **Authentication:** + - Requires a valid JWT token. +- **Response:** + - JSON containing a list of dictionaries representing the cart contents. +- **Status Codes:** + - 200: Success. + - 401: Unauthorized (if JWT token is missing or invalid). + +### `PUT /add/` +- **Description:** Add a specified quantity of a product to the user's shopping cart. +- **Authentication:** + - Requires a valid JWT token. +- **Parameters:** + - `count` (optional, int): Quantity of the product to add. Defaults to 1. +- **Response:** + - JSON indicating the success of adding the product to the cart. +- **Status Codes:** + - 200: Success. + - 400: Bad Request (if count is less than 1). + - 401: Unauthorized (if JWT token is missing or invalid). + +### `DELETE /remove/` +- **Description:** Remove a specific product from the user's shopping cart. +- **Authentication:** + - Requires a valid JWT token. +- **Response:** + - JSON indicating the success of removing the product from the cart. +- **Status Codes:** + - 200: Success. + - 401: Unauthorized (if JWT token is missing or invalid). + +### `PUT /update/` +- **Description:** Update the quantity of a product in the user's shopping cart. +- **Authentication:** + - Requires a valid JWT token. +- **Parameters:** + - `count` (int): New quantity of the product. +- **Response:** + - JSON indicating the success of updating the product quantity in the cart. +- **Status Codes:** + - 200: Success. + - 400: Bad Request (if count is missing or not a valid integer). + - 401: Unauthorized (if JWT token is missing or invalid). + +### `GET /purchase` +- **Description:** Complete a purchase, transferring items from the user's cart to the purchase history. +- **Authentication:** + - Requires a valid JWT token. +- **Response:** + - JSON indicating the success of the purchase. +- **Status Codes:** + - 200: Success. + - 401: Unauthorized (if JWT token is missing or invalid). + +## Products +### `GET /get` +- **Description:** Retrieve a paginated list of products. +- **Parameters:** + - `page` (optional, int): Page number for pagination. Defaults to 0. +- **Response:** + - JSON containing a list of products. +- **Status Codes:** + - 200: Success. + - 400: Bad Request (if the page is less than 0). + +### `GET /` +- **Description:** Retrieve information about a specific product. +- **Parameters:** + - `id` (int): Product identifier. + - `fields` (optional, string): Comma-separated list of fields to retrieve (e.g., 'name,price,image'). +- **Response:** + - JSON containing information about the specified product. +- **Status Codes:** + - 200: Success. + - 400: Bad Request (if invalid fields are provided). + +### `POST /create` +- **Description:** Create a new product listing. +- **Authentication:** + - Requires a valid JWT token. +- **Request Body:** + - JSON with the following fields: + - `name` (string): Product name. + - `price` (float): Product price. +- **Response:** + - JSON indicating the success of the product listing creation. +- **Status Codes:** + - 200: Success. + - 400: Bad Request (if name or price is missing or if price is not a valid float). + - 401: Unauthorized (if JWT token is missing or invalid).