Giter Site home page Giter Site logo

diptochakrabarty / flask-online-store Goto Github PK

View Code? Open in Web Editor NEW
44.0 5.0 23.0 13.89 MB

An online e commerce stores management and order placing system API built using flask and sqlalchemy . Various functionalities present and further functionalities being added to make it as real life as possible . Contributions welcome .

License: MIT License

Shell 0.33% Python 87.86% CSS 0.18% HTML 10.18% Mako 1.04% Dockerfile 0.42%
flask flask-application flask-api flask-restful mysql api marshmallow migrations flask-mail stripe

flask-online-store's Introduction

Flask Online Store

About the Project ๐Ÿ“–

  • API built using flask a simple project
  • This is a simple API you can use as a guide for you flask projects
  • The api comes with a bunch of functionalities
  • The api is being upgraded with more features which I plan to work on, you can checkout issues here
  • Different functionalities and modules used are listed below
  • Here are the API Docs they are being further updated
  • If you like the project please do โญ it ๐Ÿ˜‡

How to run the project ๐Ÿ‡

To run locally
* Clone the repository 
 git clone https://github.com/DiptoChakrabarty/flask-online-store.git

* Enter directory 
 cd flask-online-store

* Activate virtual environment
  source venv/bin/activate

* Install packages
  pip3 install -r requirements.txt

* Set environment variables
 cp .env.example .env

* Fill the parameters

  CLIENT_ID= {Github Client Id}
  CILENT_SECRET= {Github Client Secret}
  STRIPE_API= {Stripe token}
  MAIL_USERNAME = {Email Id }
  MAIL_PASSWORD = {Email Password}

* Remove site.db to start from fresh database
  rm site.db

* Start app
  python3 app.py

* Head over to http://localhost:5000
  (it is preferable if you use something as postman as most are post requests)

To run in docker
 * Set environment variables
   cp .env.example .env

* Fill the required parameters

* If you have removed site.db then remove the following line in Dockerfile
  RUN rm site.db

* Run using 
  docker-compose up -d to start as background process

* Head over to http://localhost:5000

Repository Structure ๐ŸŒณ

Based on the directories present

  • Model directory contains all the database model class and methods associated

  • Resource directory contains api resource classes

  • Schemas is for the marshmallow schemas

  • Split contains sample code which can help you understand the code base

  • Static is the directory where user images are uploaded

  • Templates conatins html templates

DataBase Architecture ๐Ÿ–ฅ๏ธ

There are mainly four schemas 

* Users - which contains details about the users
* Store - which contains details about the store
* Items - which contains details about the items
* Order - which is for ordering stuff

### DataBase Architecture

- store and item : one to many 
- item and order: many to many 

Functionalities present

1) flask_jwt_extended

      access_token = create_access_token(identity=user.id,fresh=True)
      refresh_token = create_refresh_token(user.id)

      return {
          "access_token": access_token,
          "refresh_token": refresh_token
      },200
  • For all post and put methods jwt token is required

  • Deletion requires a fresh jwt token so might prompt you to sign in again

2) flask restful

  • Read about it here

  • Used for creating resource class

  • You can define the endpoints using flask restful

 class Item(Resource):
 
   def get(self):
       try:
           data = item_schema.load(request.get_json())
           print(data.name)
       except ValidationError as err:
           return err.messages,400
       print(data)
       name = data.name
       item = ItemModel.find_by_name(name)

       if item:
           return item_schema.dump(item)
       return {
           "msg": "Item not found"
       }

3) flask marshmallow

  • Read about it here

  • flask marshmallow allows us to easily seralize and desarlize data

  • Check marsh_app.py file under split directory which contains simple example of using flask marshmallow

     class RewardSchema(ma.SQLAlchemyAutoSchema):
         class Meta:
             model = Reward
             load_instance = True

     class MarshSchema(ma.SQLAlchemyAutoSchema):
         rewards = ma.Nested(RewardSchema,many=True)
         class Meta:
             model = Marsh
             load_instance = True
  • The example used above has been similarly implemented in the project

  • flask marshmallow latest version has syantax different from previous versions

  • marshamllow integrates well with SQLAlchemy

4) OAuth2

  • Read about it here

  • For OAuth we are now using GitHub

  • The relevant methods are in github_login file in resource directory

  • Go to Github -> Settings -> Developer settings -> OAuth Apps and get your own client id and secret

  • Populate those values in .env to use github oauth

5) flask migrate

  • Read about it here

  • flask migrate can be used to migrate the database easily

  • app.py under split folder contains sample code

 Command used for migration 

   flask db migrate 

   This does the initial migration and creates the relevant files 

   flask db upgrade 

   This finally upgrades your database

Command used for downgrade

   flask db downgrade
 

6) flask mail

  • Read about it here

  • flask mail allows us to integrate mailing service with flask easily

  • Check mail.py file under split directory which contains simple example to use flask mail

      msg= Message("Confirm Email",recipients=[email])
      link = url_for("token_verify",token=tok,_external=True)
      msg.body = "Verify email address by clicking here {}".format(link)
      mail.send(msg)
  • This is used for user confirmation during signup

7) Stripe

  • Read about it here

  • Payments using stripe is integrated within the app

  • Create an account in stripe and generate stripe api keys and add the secret key in .env

  • Test token to make payements is generated using the function

 token=stripe.Token.create(
     card={
         "number": "4242424242424242",
         "exp_month": 9,
         "exp_year": 2021,
         "cvc": "314",
         }, )
  The values given here are all sample values 
  • For performing Indian payments we have to provide the following parameters
 stripe.Charge.create(
           amount=self.amount,
           currency=CURRENCY,
           description=self.description,
           source=token["id"],
           shipping={
             'name': "John",
             'address': {
             'line1': '510 Townsend St',
             'postal_code': '98140',
             'city': 'Kolkata',
             'state': 'WB',
             'country': 'India',
         }
     })
  • If you check you payments page in stripe dashboard you should receive fake payments

Contribution Guidelines ๐Ÿ™‚

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

If anyone wants to take up an issuse they are free to do so .

Pull Request Process

  • Ensure any install or build dependencies are removed before the end of the layer when doing a build.
  • Update the README.md with details of changes to the interface, this includes new environment variables, exposed ports, useful file locations and container parameters.
  • Only send your pull requests to the development branch where once we reach a stable point it will be merged with the master branch .
  • Associate each Pull Request with the required issue number.
  • Please provide relevant steps to use your codebase adding few extra lines of comments or commands to run would be helpful for others to follow along .

Branch Policy

  • development: If you are making a contribution make sure to send your Pull Request to this branch . All developments goes in this branch.

  • master: After significant features/bug-fixes are accumulated in development branch we merge it with the master branch.

Contribution Practices

  • Please be respectful of others , do not indulge in unacceptable behaviour
  • If a person is working or has been assigned an issue and you want to work on it please ask him/her if he is working on it
  • We are happy to allow you to work on your issues , but in case of long period of inactivity the issue will be approved to another volunteer
  • If you report a bug please provide steps to reproduce the bug.
  • In case of changing the backend routes please submit an updated routes documentation for the same.
  • If there is an UI related change it would be great if you could attach a screenshot with the resultant changes so it is easier to review for the maintainers

flask-online-store's People

Contributors

amitshindegit avatar benji011 avatar diptochakrabarty avatar gabrielhicks avatar pulkitsapra avatar rpdswtk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

flask-online-store's Issues

paypal oauth

It would be really cool if we could have a paypal integration within the application

items count

we are currently assuming that count of item present in a store is infinite , we have to limit the count of items in a store and decrease its count as per the order of user.

If no item is present return the appropriate response and also have option to add items by store creator

Docker deployment of the app

Currently we are able to run the application locally using python.

It would be great if we could have docker images and a docker compose file to launch the application .

Images for flask app and database would be required.

password of user

Due to use github oauth as we do not consider any password , the password parameter in database has been kept as nullable= False , this must be changed to True.

For users using github login random sample passwords must be generated to store in database.

Please check the code to understand further.

store creation access

Currently anyone who logs in can create a store , we want to have two classes of people customers and sellers.

We can achieve that by adding a parameter to all users which determines whether they are customers or sellers , if parameter is not passed during user creation they must be customer .

Only sellers must have permission to create stores and delete them , so database schema and request parameters must be handled appropriately .

ER diagram of DB

Would be good to have an ER diagram of the databse under the database architecture part of the readme .

order input modification

Currently to order a single item multiple times we have to enter the item name that many times , this should be changed to just order item and no of items as inputs

Something similar to mango,5 which confirms ordering 5 mangos

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.