Welcome to the official documentation for the Spitfire Superadmin API. This RESTful API is designed to provide administrators with comprehensive tools for managing shops, products, vendors, and ensuring the health of the system. Please refer to this documentation to understand the available endpoints, their functionality, and how to use them effectively.
- 1. Introduction
- 2. Features
- 3. Technologies Used
- 4. Getting Started
- 5. API Endpoints
- 6. Database Schema
- 7. Authentication
- 8. Error Handling
- 9. Testing
- 10. Deployment
- 11. Contributing -11.1 Commit Convention
- 12. License
- 13. Acknowledgments
The Spitfire Superadmin API is a powerful system administration tool designed to provide administrators with complete control over shops, products, and vendors. It enables you to ensure the health and stability of the system. This API is essential for managing an e-commerce platform effectively.
All API endpoints are meant for the superadmin and therefore require a verification token to access. Includes endpoints for product and shop management.
Utilizes technologies like Python, Flask, SQLAlchemy, and more.
To get started with the local development environment, clone the repository:
$ git clone https://github.com/hngx-org/spitfire-super-admin-one.git
$ cd super_admin_1
You can set up the environment using either venv
or pipenv
. Here are instructions for both:
Using venv
:
# create Virtual Environment
$ python3 -m venv venv
# Activate Virtual Env
$ source venv/bin/activate
# Install Dependencies
$ pip install -r requirements.txt
Using pipenv
:
$ pip install pipenv
# create virtuel environment
$ pipenv --python 3.10
# Activate virtual env
$ pipenv shell
# install dependencies in requirements.txt or pipfile
$ pipenv install
Make sure to set the following environment variables:
SECRET_KEY: [Your Secret Key]
SQLALCHEMY_DATABASE_URI: [Your Database URI]
$ python3 run.py
Endpoint : /api/admin
Endpoint : /shop
The Shop endpoints allow administrators to manage shops and vendors effectively.
- GET:
/endpoint
- Summary: Get information from the shop endpoint
- Description: This endpoint retrieves information from the shop endpoint. The user ID is automatically provided by the authorization logic.
- Responses:
200
: Successful response- Message: "This is the shop endpoint for user ID: <user_id>"
401
: Unauthorized - Invalid or missing authentication token403
: Forbidden - User does not have permission to access the resource
- GET:
/all
- Summary: Get information related to all shops
- Description: This endpoint retrieves information related to all shops in the system. Requires admin authentication.
- Responses:
200
: Successful response- Message: "All shops request successful"
- Data: Array of shop details
401
: Unauthorized - Invalid or missing authentication token403
: Forbidden - User does not have permission to access the resource500
: Internal Server Error
- GET:
/{shop_id}
- Summary: Get information related to a specific shop
- Description: This endpoint retrieves information related to a specific shop identified by the provided shop ID. Requires admin authentication.
- Parameters:
shop_id
(Path Parameter, Required): Unique identifier for the shop
- Responses:
200
: Successful response- Message: "Shop request successful"
- Data: Shop details
401
: Unauthorized - Invalid or missing authentication token403
: Forbidden - User does not have permission to access the resource404
: Not Found - Shop with the given ID not found500
: Internal Server Error
- PUT:
/ban_vendor/{vendor_id}
- Summary: Ban a vendor/shop by ID
- Parameters:
vendor_id
(Path Parameter, Required): Unique identifier for the vendorreason
(Request Body, Required): Ban reason
- Responses:
201
: Vendor banned successfully- Message: "Vendor account banned temporarily."
- Vendor details
- Reason
400
: Bad request - Vendor is already banned or missing reason404
: Vendor not found409
: Conflict - Vendor is already banned500
: Internal Server Error
- GET:
/banned_vendors
- Summary: Get a list of all temporarily banned vendors
- Responses:
200
: Successful response- Message: "Banned vendors retrieved successfully."
- Banned vendors
- PUT:
/unban_vendor/{vendor_id}
- Summary:
- Parameters:
vendor_id
(Path Parameter, Required): Unique identifier for the vendor
- Responses:
200
: Vendor unbanned successfully- Status: "Success"
- Message: "Vendor unbanned successfully."
- Vendor details
404
: Vendor not found400
: Vendor's shop is not active500
: Internal Server Error
- PATCH:
/restore_shop/{shop_id}
- Summary: Restore a temporarily deleted shop by ID
- Parameters:
shop_id
(Path Parameter, Required): Unique identifier for the shop
- Responses:
200
: Shop restored successfully- Message: "Shop restored successfully"
404
: Invalid Shop400
: Invalid JSON Data
- PATCH:
/delete_shop/{shop_id}
- Summary: Temporarily delete a shop and its associated products
- Parameters:
shop_id
(Path Parameter, Required): Unique identifier for the shop
- Responses:
204
: Shop temporarily deleted404
: Invalid Shop500
: Internal Server Error
- DELETE:
/permanent_delete_shop/{shop_id}
- Summary: Permanently delete a shop and its associated products
- Parameters:
shop_id
(Path Parameter, Required): Unique identifier for the shop
- Responses:
204
: Shop permanently deleted404
: Invalid Shop500
: Internal Server Error
- Get:
/temporarily_deleted_vendors
-Summary: Retrieve temporarily deleted vendors -Responses:200
: Successful response- Message: "Temporarily deleted vendors retrieved successfully"
500
: Internal Server Error
- Get:
/temporarily_deleted_vendor/{vendor_id}
-Summary: Retrieve details of a temporarily deleted vendor- Parameters:
vendor_id
(Path Parameter, Required): Unique identifier for the vendor
- Responses:
200
: Temporarily deleted vendor details retrieved successfully404
: Temporarily deleted vendor not found500
: Internal Server Error
- Parameters:
- Get:
/sanctioned
-Summary: Returns a list of all sanctioned shops -Responses:200
: Sanctioned shops retrieved successfully500
: Internal Server Error
Endpoint: /product
- GET:
/all
- Summary: Get information related to all products
- Description: Returns a list of all products in the system.
- Responses:
200
: Successful response- Message: "All products retrieved successfully."
- Data: List of products
500
: Internal Server Error
- GET:
/{product_id}
- Summary: Get information related to a product
- Description: Returns details of a specific product.
- Parameters:
product_id
(Path Parameter, Required): Unique identifier for the product
- Responses:
200
: Successful response- Message: "Product details retrieved successfully."
- Data: Product details
404
: Product not found500
: Internal Server Error
- PATCH:
/sanction/{product_id}
- Summary: Sanction a product by setting its status to 'suspended'
- Parameters:
product_id
(Path Parameter, Required): Unique identifier for the product
- Responses:
200
: Product sanctioned successfully- Message: "Product sanctioned successfully."
- Product details
404
: Product not found409
: Conflict - Product is already sanctioned500
: Internal Server Error
- GET:
/product_statistics
- Summary: Get statistics about products
- Responses:
200
: Product statistics retrieved successfully- TotalProducts: Total number of products
- SanctionedProducts: Total number of sanctioned products
- DeletedProducts: Total number of deleted products
400
: Bad request500
: Internal Server Error
- PATCH:
/delete_product/{id}
- Summary: Temporarily delete a product by ID
- Parameters:
id
(Path Parameter, Required): Unique identifier for the product
- Responses:
204
: Product temporarily deleted404
: Invalid Product409
: Action already carried out on this Product500
: Internal Server Error
- DELETE:
/permanent_delete_product/{id}
- Summary: Permanently delete a product by ID
- Parameters:
id
(Path Parameter, Required): Unique identifier for the product
- Responses:
204
: Product permanently deleted404
: Invalid Product500
: Internal Server Error
- PATCH:
/restore_product/{product_id}
- Summary: Restore a temporarily deleted product by id
- Parameters:
-
id
(Path Parameter, Required): Unique identifier for the product - Responses:
200
: Product restored successfully404
: Invalid Product
- PATCH:
/approve_product/{product_id}
- Summary: Approve a product by changing the admin status
- Parameters:
-
id
(Path Parameter, Required): Unique identifier for the product - Responses:
201
: Product approved successfully404
: Product not found409
: Conflict. Action already carried out on this Product500
: Internal Server Error
- GET:
/temporarily_deleted_products
- Responses:
200
: Successful response500
: Internal Server Error
- GET:
/download/log
- Responses:
200
: Successful response204
: No log entry exists
Endpoint: /health
- GET:
/
- Response:
200
: Successful health check500
: Internal Server Error
- GET:
/last_check
- Summary:
200
: Successful retrieval of the last health check log entry404
: No health check logs available500
: Internal Server Error
Endpoint: /test
- POST:
/user/create
- Response:
201
: User created successfully400
: Bad request - Invalid input data
- GET:
/user
- Response:
200
: Successful response
- DELETE:
/user/{user_id}
- Parameters:
-
user_id
(Path Parameter, Required): Unique identifier for the user - Response:
200
: User deleted successfully404
: User not found
- POST:
/user/{user_id}/shop
- Parameters:
-
user_id
(Path Parameter, Required): Unique identifier for the user - Response:
201
: Shop created successfully400
: Bad request - Invalid input data
- GET:
/
- Response:
200
: Successful response
- GET:
/{shop_id}
- Parameters:
-
shop_id
(Path Parameter, Required): Unique identifier for the shop - Response:
200
: Shop details retrieved successfully404
: Shop not foun
Endpoint: /logs
- GET:
/shops
- Response:
200
: Success response
- GET:
/shops/{shop_id}
- Parameters:
-
shop_id
(Path Parameter, Required): Unique identifier for the shop - Response:
200
: Success response
- GET:
/shops/download
- Summary: Download all shop logs as a text file.
- Response:
200
: Success response
- GET:
/shops/{shop_id}/download
- Summary: Download all logs for specific shop
- Response:
200
: Success response
- GET:
/shop/actions
- Method:
GET
- Summary: Get shop action logs.
- Response:
200
: Success response
- GET:
/product/download
- Summary: Download product logs.
- Response:
200
: Success response500
: Could not download audit logs
- GET:
/server/download
- Summary: Download server logs for the current date
- Response:
200
: Success response500
: Could not download server logs
Endpoint: /notification
- POST:
/
- Summary Send notifications to users
- Response:
200
: Email sent successfully400
: Bad request424
: Email not sent500
: an error occured during execution, try again
The Spitfire Superadmin API utilizes a PostgreSQL database to store and manage data efficiently. This schema defines the structure and relationships of the tables used to store information related to shops, products, vendors, and more. Tables: Shop table Product table Vendor table
Every endpoint in this API is meant to be used by the super admin user. To access any of the endpoints, you will need an authentication token.
Errors are returned as JSON objects in the following format with their error code
{
"error": "error name",
"message": "error description"
}
The API will return 5 error types, with diffreent descriptions when requests fail;
- 400: Request unprocessable
- 403: Forbidden
- 404: resource not found
- 422: Bad Request
- 429: Too Many Requests(rate limiting)
- 500: Internal server error
Note: ensure you are connected to the internet before running tests and are in spitfire-events
directory
# install test suite and HTTP requests library
$ pip install requests pytest
cd super_admin_1
$ pytest tests\* -v
The super admin 1 App is hosted for live testing at [https://spitfire-superadmin-1.onrender.com].
Before you create a Pull Request, please check whether your commits comply with the commit conventions used in this repository.
When you create a commit we kindly ask you to follow the convention
category(scope or module): message
in your commit message while using one of
the following categories:
feat / feature
: all changes that introduce completely new code or new featuresfix
: changes that fix a bug (ideally you will additionally reference an issue if present)refactor
: any code related change that is not a fix nor a featuredocs
: changing existing or creating new documentation (i.e. README, docs for usage of a lib or cli usage)build
: all changes regarding the build of the software, changes to dependencies or the addition of new dependenciestest
: all changes regarding tests (adding new tests or changing existing ones)ci
: all changes regarding the configuration of continuous integration (i.e. github actions, ci system)chore
: all changes to the repository that do not fit into any of the above categories.
This project is licensed under the MIT License - see the LICENSE file for details.
Appreciation and acknowledgments to contributors, libraries, or resources that helped in developing the API.