Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*__pycache__
venv
.vscode
8 changes: 8 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from flask import Flask, Blueprint
from .api.v1 import version1

def create_app():
app = Flask(__name__)
app.register_blueprint(version1)

return app
Empty file added app/api/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions app/api/v1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from flask import Blueprint
from flask_restful import Api
from .views import ParcelList

version1 = Blueprint('v1', __name__, url_prefix="/api/v1")

api = Api(version1)

api.add_resource(ParcelList, '/parcels')
21 changes: 21 additions & 0 deletions app/api/v1/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

parcels = []

class Parcels:

def __init__(self):
self.db = parcels

def create_order(self, item, pickup, dest, pricing):
payload = {
"id" : len(self.db) + 1,
"itemName" : item,
"pickupLocation" : pickup,
"destination" : dest,
"pricing" : pricing
}
self.db.append(payload)

def order(self):
return self.db

33 changes: 33 additions & 0 deletions app/api/v1/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from flask_restful import Resource
from flask import make_response, jsonify, request
from .models import Parcels


class ParcelList(Resource, Parcels):

def __init__(self):
self.order = Parcels()

def post(self):
data = request.get_json()
item = data['item']
pickup = data['pickup']
dest = data['dest']
pricing = data['pricing']

self.order.create_order(item, pickup, dest, pricing)

return make_response(jsonify({
"message" : "delivery order created successfully"
}), 201)

def get(self):
pass

class IndividualParcel(Resource):

def get(self, id):
pass

def put(self, id):
pass
Empty file added requirements.txt
Empty file.
3 changes: 3 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from app import create_app

app = create_app()