/sm-server

Store Manager is a web application that enables a Store Owner to manage product inventory, sales, and manage sale attendants

Primary LanguagePython

Store Manager API

Coverage Status Build Status Maintainability contributions welcome

Run in Postman

Store Manager is a web application for use in a single store. There are two users: Administrator and Attendant.

The Administrator is the Store Owner and can add Store Attendants to the application. The Store Owner can also add, modify and delete products. The Store Owner will also be able to view all Sale Records created by the different Store Attendants.

The Store Attendant will be able to sell products and create Sale Records. The Attendant will also be able to view all his/her sale individual sale records.

The Front-End design of the application can be viewed here: Store Manager UI

The API is hosted on heroku and can be found here: Store Manager API

Testing and Usage

To test the application locally, first configure the environment as follows:

  1. Install PostgreSQL if not already installed and ensure it is up and running.

  2. Ensure Python3 is installed

  3. Create a folder on your computer, once in the newly created repository, clone the project by running the following command:

    git clone https://github.com/johnwayodi/sm-api-v2.git

  4. Install virtualenv which will aid in the creation of a vitual environment. Once virtual environment is installed, create a new virtual environment named venv

    virtualenv venv

  5. Activate the created virtual environment and install all the packages for use in the app,

    The packages used by the flask app are contained in a requirements.txt file:

    source venv/bin/activate

    pip install -r requirements.txt

  6. Set up the environment variables,

     export JWT_SECRET_KEY="your jwt secret key"
     export API_SECRET_KEY="your secret key"
     export DATABASE_NAME="name of database"
     export DATABASE_HOST="database host"
     export DATABASE_USER="database username"
     export DATABASE_PASS="database password"
     export FLASK_APP=run.py
    
  7. After all is set, run the application, export the application and pass the following command:

     flask run
    

Endpoints

The API exposes the following endpoints:

  1. Auth Endpoints

    The /auth endpoint allow the registration of users and a login route to allow registered. users to log into the application

    The users can also logout of the application, doing so will revoke their access token and to access the the protected endpoinnts they'll have to login again.

    POST /auth/register Register new user, first user to register will automatically be the Admin
    POST /auth/login Users can login to the system
    DELETE /auth/logout Users can logout of the system
  2. User Endpoints

    The /api/v2/users endpoint allows the management of attendants by the admin, the admin can add, update or remove an attendant accounts

    POST /users Create a new attendant, only accessible to admin
    PUT /users/{user_id} Update details of a user account, only accessible to the admin
    DELETE /users/{user_id} Remove a user account, only accessible to the admin
  3. Category Endpoints

    The /api/v2/categories endpoint allows all the CRUD operations on the category items.

    POST /categories Add new category, only accessible to the admin
    GET /categories Retrieve all categories, only accesible by admin
    GET /categories/{category_id} Retrieve a single category, only accesible by admin
    PUT /categories/{category_id} Update a specific category, only accesible by admin
    DELETE /categories/{category_id} Remove a category, only accesible by admin
  4. Product Endpoints

    The api/v2/products endpoint allows all CRUD operations on product items

    POST /products Add new product, only accessible to the admin
    GET /products Retrieve all products
    GET /products/{product_id} Retrieve a specific product
    PUT /products/{product_id} Update a specific product, only accessible to admin
    DELETE /products/{product_id} Remove a product, only accesible by admin
  5. Sales Endpoints

    The api/v2/sales endpoint allows the following operations on sale items

    POST /sales Add new sale, only accessible to the attendant
    GET /sales Retrieve all sales
    GET /sales/{sale_id} Retrieve a single sale, displays a list of sold products in the sale

Technologies used

The following software tools were used in the development of this application:

  1. Python: Programming language.
  2. Flask: The underlying web framework.
  3. Flask-RESTful: For the development of the API.
  4. Flasgger: For the generation of the API Docs.
  5. Pytest: For testing and debugging.
  6. PostgreSQL: Database.
Contributors

John Wayodi