first commit
This commit is contained in:
21
Dockerfile
Executable file
21
Dockerfile
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
FROM python:3.12-bullseye
|
||||||
|
|
||||||
|
ENV COMPANYID=1
|
||||||
|
|
||||||
|
ENV PYTHONFAULTHANDLER=1
|
||||||
|
|
||||||
|
ENV PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
|
RUN mkdir -p /app
|
||||||
|
|
||||||
|
COPY requirements.txt /app
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN pip3 install -r requirements.txt
|
||||||
|
|
||||||
|
EXPOSE 8003
|
||||||
|
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
|
||||||
0
app/__init__.py
Executable file
0
app/__init__.py
Executable file
BIN
app/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
app/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/__pycache__/database.cpython-312.pyc
Normal file
BIN
app/__pycache__/database.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/__pycache__/main.cpython-312.pyc
Normal file
BIN
app/__pycache__/main.cpython-312.pyc
Normal file
Binary file not shown.
21
app/database.py
Executable file
21
app/database.py
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
from sqlalchemy import create_engine
|
||||||
|
from sqlalchemy.engine import URL
|
||||||
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
from sqlalchemy.orm import declarative_base
|
||||||
|
|
||||||
|
url = URL.create(
|
||||||
|
drivername="postgresql",
|
||||||
|
username="postgres",
|
||||||
|
password="password",
|
||||||
|
host="192.168.1.204",
|
||||||
|
database="eamco",
|
||||||
|
port=5432
|
||||||
|
)
|
||||||
|
|
||||||
|
engine = create_engine(url)
|
||||||
|
|
||||||
|
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||||
|
session = Session()
|
||||||
|
|
||||||
|
Base = declarative_base()
|
||||||
|
Base.metadata.create_all(engine)
|
||||||
13
app/dependencies.py
Executable file
13
app/dependencies.py
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
from typing import Annotated
|
||||||
|
|
||||||
|
from fastapi import Header, HTTPException
|
||||||
|
|
||||||
|
|
||||||
|
async def get_token_header(x_token: Annotated[str, Header()]):
|
||||||
|
if x_token != "fake-super-secret-token":
|
||||||
|
raise HTTPException(status_code=400, detail="X-Token header invalid")
|
||||||
|
|
||||||
|
|
||||||
|
async def get_query_token(token: str):
|
||||||
|
if token != "jessica":
|
||||||
|
raise HTTPException(status_code=400, detail="No Jessica token provided")
|
||||||
31
app/main.py
Executable file
31
app/main.py
Executable file
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
from fastapi import FastAPI
|
||||||
|
from app.routers import info
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
origins = [
|
||||||
|
|
||||||
|
"https://auburnoil.com",
|
||||||
|
"https://www.auburnoil.com",
|
||||||
|
"http://localhost:5169",
|
||||||
|
]
|
||||||
|
|
||||||
|
app.add_middleware(
|
||||||
|
CORSMiddleware,
|
||||||
|
allow_origins=origins,
|
||||||
|
allow_credentials=True,
|
||||||
|
allow_methods=["*"],
|
||||||
|
allow_headers=["*"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
app.include_router(info.router)
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
def read_root():
|
||||||
|
return {"Status": "API Service is online"}
|
||||||
|
|
||||||
|
|
||||||
0
app/models/__init__.py
Executable file
0
app/models/__init__.py
Executable file
BIN
app/models/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
app/models/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/models/__pycache__/admin.cpython-312.pyc
Normal file
BIN
app/models/__pycache__/admin.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/models/__pycache__/delivery.cpython-312.pyc
Normal file
BIN
app/models/__pycache__/delivery.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/models/__pycache__/money.cpython-312.pyc
Normal file
BIN
app/models/__pycache__/money.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/models/__pycache__/pricing.cpython-312.pyc
Normal file
BIN
app/models/__pycache__/pricing.cpython-312.pyc
Normal file
Binary file not shown.
25
app/models/admin.py
Normal file
25
app/models/admin.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
from sqlalchemy import (Column, INTEGER, TIMESTAMP, VARCHAR)
|
||||||
|
from datetime import datetime
|
||||||
|
from app.database import Base
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Admin_Company(Base):
|
||||||
|
__tablename__ = 'admin_company'
|
||||||
|
__bind_key__ = 'eamco'
|
||||||
|
__table_args__ = {"schema": "public"}
|
||||||
|
|
||||||
|
id = Column(INTEGER,
|
||||||
|
primary_key=True,
|
||||||
|
autoincrement=True,
|
||||||
|
unique=False)
|
||||||
|
creation_date = Column(TIMESTAMP(), default=datetime.utcnow())
|
||||||
|
account_prefix = Column(VARCHAR(5))
|
||||||
|
company_name = Column(VARCHAR(250))
|
||||||
|
company_address = Column(VARCHAR(250))
|
||||||
|
company_town = Column(VARCHAR(100))
|
||||||
|
company_zip = Column(VARCHAR(25))
|
||||||
|
company_state = Column(INTEGER())
|
||||||
|
company_phone_number = Column(VARCHAR(50))
|
||||||
|
|
||||||
20
app/models/auto.py
Normal file
20
app/models/auto.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
from sqlalchemy import Column, Integer,\
|
||||||
|
DECIMAL, Text,\
|
||||||
|
VARCHAR, TIMESTAMP, Date
|
||||||
|
import datetime
|
||||||
|
from app.database import Base
|
||||||
|
|
||||||
|
|
||||||
|
class Auto_Temp(Base):
|
||||||
|
__tablename__ = 'auto_temp'
|
||||||
|
|
||||||
|
id = Column(Integer,
|
||||||
|
primary_key=True,
|
||||||
|
autoincrement=True,
|
||||||
|
unique=False)
|
||||||
|
todays_date = Column(TIMESTAMP(), default=datetime.utcnow())
|
||||||
|
temp = Column(DECIMAL(50, 2))
|
||||||
|
temp_max = Column(DECIMAL(50, 2))
|
||||||
|
temp_min = Column(DECIMAL(50, 2))
|
||||||
|
temp_avg = Column(DECIMAL(50, 2))
|
||||||
|
degree_day = Column(Integer)
|
||||||
29
app/models/customer.py
Normal file
29
app/models/customer.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
from sqlalchemy import Column, Integer,\
|
||||||
|
DECIMAL, Text,\
|
||||||
|
VARCHAR, TIMESTAMP, Date
|
||||||
|
import datetime
|
||||||
|
from app.database import Base
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Customer_Customer(Base):
|
||||||
|
__tablename__ = 'customer_customer'
|
||||||
|
|
||||||
|
|
||||||
|
id = Column(Integer,
|
||||||
|
primary_key=True,
|
||||||
|
autoincrement=True,
|
||||||
|
unique=False)
|
||||||
|
account_number = Column(VARCHAR(25))
|
||||||
|
customer_last_name = Column(VARCHAR(250))
|
||||||
|
customer_first_name = Column(VARCHAR(250))
|
||||||
|
customer_town = Column(VARCHAR(140))
|
||||||
|
customer_state = Column(Integer)
|
||||||
|
customer_zip = Column(VARCHAR(25))
|
||||||
|
customer_first_call = Column(TIMESTAMP(), default=datetime.utcnow())
|
||||||
|
customer_email = Column(VARCHAR(500))
|
||||||
|
customer_automatic = Column(Integer)
|
||||||
|
customer_phone_number = Column(VARCHAR(25))
|
||||||
|
customer_home_type = Column(Integer)
|
||||||
|
customer_apt = Column(VARCHAR(140))
|
||||||
|
customer_address = Column(VARCHAR(1000))
|
||||||
69
app/models/delivery.py
Executable file
69
app/models/delivery.py
Executable file
@@ -0,0 +1,69 @@
|
|||||||
|
from sqlalchemy import Column, Integer,\
|
||||||
|
DECIMAL, Text,\
|
||||||
|
VARCHAR, TIMESTAMP, Date
|
||||||
|
import datetime
|
||||||
|
from app.database import Base
|
||||||
|
|
||||||
|
|
||||||
|
class Delivery(Base):
|
||||||
|
__tablename__ = "delivery_delivery"
|
||||||
|
|
||||||
|
id = Column(Integer,
|
||||||
|
primary_key=True,
|
||||||
|
autoincrement=True,
|
||||||
|
unique=False)
|
||||||
|
|
||||||
|
customer_id = Column(Integer)
|
||||||
|
customer_name = Column(VARCHAR(1000))
|
||||||
|
customer_address = Column(VARCHAR(1000))
|
||||||
|
customer_town = Column(VARCHAR(140))
|
||||||
|
customer_state = Column(VARCHAR(140))
|
||||||
|
customer_zip = Column(Integer)
|
||||||
|
|
||||||
|
gallons_ordered = Column(Integer)
|
||||||
|
customer_asked_for_fill = Column(Integer)
|
||||||
|
gallons_delivered = Column(DECIMAL(50, 2))
|
||||||
|
customer_filled = Column(Integer)
|
||||||
|
|
||||||
|
delivery_status = Column(Integer)
|
||||||
|
when_ordered = Column(TIMESTAMP(), default=datetime.datetime.utcnow())
|
||||||
|
when_delivered = Column(TIMESTAMP(), default=None)
|
||||||
|
expected_delivery_date = Column(Date(), default=None)
|
||||||
|
automatic = Column(Integer)
|
||||||
|
oil_id = Column(Integer)
|
||||||
|
supplier_price = Column(DECIMAL(50, 2))
|
||||||
|
customer_price = Column(DECIMAL(50, 2))
|
||||||
|
customer_temperature = Column(DECIMAL(50, 2))
|
||||||
|
dispatcher_notes = Column(Text())
|
||||||
|
prime = Column(Integer)
|
||||||
|
same_day = Column(Integer)
|
||||||
|
payment_type = Column(Integer)
|
||||||
|
payment_card_id = Column(Integer)
|
||||||
|
cash_recieved = Column(DECIMAL(50, 2))
|
||||||
|
|
||||||
|
driver_employee_id = Column(Integer)
|
||||||
|
driver_first_name = Column(VARCHAR(140))
|
||||||
|
driver_last_name = Column(VARCHAR(140))
|
||||||
|
|
||||||
|
pre_charge_amount = Column(DECIMAL(50, 2))
|
||||||
|
total_price = Column(DECIMAL(50, 2))
|
||||||
|
final_price = Column(DECIMAL(50, 2))
|
||||||
|
|
||||||
|
|
||||||
|
class Auto_Delivery(Base):
|
||||||
|
__tablename__ = 'auto_delivery'
|
||||||
|
|
||||||
|
|
||||||
|
id = Column(Integer,
|
||||||
|
primary_key=True,
|
||||||
|
autoincrement=True,
|
||||||
|
unique=False)
|
||||||
|
customer_id = Column(Integer)
|
||||||
|
customer_full_name = Column(DECIMAL(50, 2))
|
||||||
|
last_fill = Column(TIMESTAMP())
|
||||||
|
last_updated = Column(TIMESTAMP())
|
||||||
|
estimated_gallons_left = Column(Integer)
|
||||||
|
estimated_gallons_left_prev_day = Column(Integer)
|
||||||
|
tank_height = Column(VARCHAR(25))
|
||||||
|
tank_size = Column(VARCHAR(25))
|
||||||
|
k_factor = Column(DECIMAL(50, 2))
|
||||||
28
app/models/money.py
Executable file
28
app/models/money.py
Executable file
@@ -0,0 +1,28 @@
|
|||||||
|
from sqlalchemy import Column, Integer,\
|
||||||
|
DECIMAL, Text,\
|
||||||
|
VARCHAR, TIMESTAMP, Date
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from app.database import Base
|
||||||
|
|
||||||
|
|
||||||
|
class MoneyDelivery(Base):
|
||||||
|
__tablename__ = 'money_delivery'
|
||||||
|
|
||||||
|
id = Column(Integer,
|
||||||
|
primary_key=True,
|
||||||
|
autoincrement=True,
|
||||||
|
unique=False)
|
||||||
|
|
||||||
|
delivery_id = Column(Integer)
|
||||||
|
time_added = Column(TIMESTAMP(), default=datetime.utcnow())
|
||||||
|
gallons_delivered = Column(DECIMAL(50, 2))
|
||||||
|
supplier_price = Column(DECIMAL(50, 2))
|
||||||
|
customer_price = Column(DECIMAL(50, 2))
|
||||||
|
total_amount_oil = Column(DECIMAL(50, 2))
|
||||||
|
total_amount_prime = Column(DECIMAL(50, 2))
|
||||||
|
total_amount_same_day = Column(DECIMAL(50, 2))
|
||||||
|
total_amount_fee = Column(DECIMAL(50, 2))
|
||||||
|
total_amount = Column(DECIMAL(50, 2))
|
||||||
|
taxes_paid = Column(DECIMAL(50, 2))
|
||||||
|
total_profit = Column(DECIMAL(50, 2))
|
||||||
|
|
||||||
34
app/models/pricing.py
Executable file
34
app/models/pricing.py
Executable file
@@ -0,0 +1,34 @@
|
|||||||
|
from sqlalchemy import (Column, Integer, DECIMAL, TIMESTAMP)
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from app.database import Base
|
||||||
|
|
||||||
|
|
||||||
|
class Pricing_Oil_Oil(Base):
|
||||||
|
__tablename__ = 'pricing_oil_oil'
|
||||||
|
|
||||||
|
|
||||||
|
id = Column(Integer,
|
||||||
|
primary_key=True,
|
||||||
|
autoincrement=True,
|
||||||
|
unique=False)
|
||||||
|
|
||||||
|
price_from_supplier = Column(DECIMAL(50, 2))
|
||||||
|
price_for_customer = Column(DECIMAL(50, 2))
|
||||||
|
price_for_employee = Column(DECIMAL(50, 2))
|
||||||
|
price_same_day = Column(DECIMAL(50, 2))
|
||||||
|
price_prime = Column(DECIMAL(50, 2))
|
||||||
|
date = Column(TIMESTAMP(), default=datetime.utcnow())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Pricing_Taxes(Base):
|
||||||
|
__tablename__ = 'pricing_taxes'
|
||||||
|
|
||||||
|
|
||||||
|
id = Column(Integer,
|
||||||
|
primary_key=True,
|
||||||
|
autoincrement=True,
|
||||||
|
unique=False)
|
||||||
|
state_id = Column(Integer)
|
||||||
|
taxes_oil = Column(DECIMAL(50, 2))
|
||||||
|
taxes_other = Column(DECIMAL(50, 2))
|
||||||
0
app/routers/__init__.py
Executable file
0
app/routers/__init__.py
Executable file
BIN
app/routers/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
app/routers/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/routers/__pycache__/command.cpython-312.pyc
Executable file
BIN
app/routers/__pycache__/command.cpython-312.pyc
Executable file
Binary file not shown.
BIN
app/routers/__pycache__/delivery.cpython-312.pyc
Normal file
BIN
app/routers/__pycache__/delivery.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/routers/__pycache__/info.cpython-312.pyc
Normal file
BIN
app/routers/__pycache__/info.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/routers/__pycache__/printstatus.cpython-312.pyc
Executable file
BIN
app/routers/__pycache__/printstatus.cpython-312.pyc
Executable file
Binary file not shown.
52
app/routers/info.py
Executable file
52
app/routers/info.py
Executable file
@@ -0,0 +1,52 @@
|
|||||||
|
|
||||||
|
|
||||||
|
from fastapi import APIRouter
|
||||||
|
from app.database import session
|
||||||
|
import os
|
||||||
|
from app.schema.price import SchemaPricing
|
||||||
|
from app.models.admin import Admin_Company
|
||||||
|
from app.models.pricing import Pricing_Oil_Oil
|
||||||
|
|
||||||
|
|
||||||
|
router = APIRouter(
|
||||||
|
prefix="/info",
|
||||||
|
tags=["info"],
|
||||||
|
responses={404: {"description": "Not found"}},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/price/today")
|
||||||
|
async def get_todays_price_of_oil():
|
||||||
|
|
||||||
|
get_current_prices = (session.query(Pricing_Oil_Oil)
|
||||||
|
.order_by(Pricing_Oil_Oil.id.desc())
|
||||||
|
.first())
|
||||||
|
|
||||||
|
current_price = str(get_current_prices.price_for_customer)
|
||||||
|
return {
|
||||||
|
"ok": True,
|
||||||
|
"todays_price": current_price
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/company")
|
||||||
|
async def get_company():
|
||||||
|
company = os.getenv("COMPANYID")
|
||||||
|
|
||||||
|
|
||||||
|
get_company_info = (session.query(Admin_Company)
|
||||||
|
.filter(Admin_Company.id == company)
|
||||||
|
.first())
|
||||||
|
|
||||||
|
company_phone_number = get_company_info.company_phone_number
|
||||||
|
company_name = get_company_info.company_name
|
||||||
|
|
||||||
|
return {
|
||||||
|
"ok": True,
|
||||||
|
"company_phone_number": company_phone_number,
|
||||||
|
"company_name": company_name
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
0
app/schema/__init__.py
Executable file
0
app/schema/__init__.py
Executable file
BIN
app/schema/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
app/schema/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/schema/__pycache__/delivery.cpython-312.pyc
Normal file
BIN
app/schema/__pycache__/delivery.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/schema/__pycache__/money.cpython-312.pyc
Normal file
BIN
app/schema/__pycache__/money.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/schema/__pycache__/price.cpython-312.pyc
Normal file
BIN
app/schema/__pycache__/price.cpython-312.pyc
Normal file
Binary file not shown.
17
app/schema/price.py
Normal file
17
app/schema/price.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
from pydantic import BaseModel, Field
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
|
||||||
|
def datetime_now() -> datetime:
|
||||||
|
return datetime.now(timezone.utc)
|
||||||
|
|
||||||
|
class SchemaPricing(BaseModel):
|
||||||
|
|
||||||
|
id: int
|
||||||
|
price_from_supplier: float
|
||||||
|
price_for_customer: str
|
||||||
|
price_for_employee: float
|
||||||
|
price_same_day: float
|
||||||
|
price_prime: float
|
||||||
|
date: datetime =Field(default_factory=datetime_now)
|
||||||
|
|
||||||
6
requirements.txt
Executable file
6
requirements.txt
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
fastapi
|
||||||
|
uvicorn[standard]
|
||||||
|
psycopg2-binary
|
||||||
|
sqlalchemy
|
||||||
|
python-multipart
|
||||||
|
pyowm
|
||||||
Reference in New Issue
Block a user