commit 11b023cd2b1fe50c0f028af3a1bfec4a74a670d6 Author: Anekdotin Date: Fri Jun 14 16:09:27 2024 -0400 first commit diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 0000000..c56cc93 --- /dev/null +++ b/Dockerfile @@ -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 + + diff --git a/app/__init__.py b/app/__init__.py new file mode 100755 index 0000000..e69de29 diff --git a/app/__pycache__/__init__.cpython-312.pyc b/app/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..7adc33f Binary files /dev/null and b/app/__pycache__/__init__.cpython-312.pyc differ diff --git a/app/__pycache__/database.cpython-312.pyc b/app/__pycache__/database.cpython-312.pyc new file mode 100644 index 0000000..18b138b Binary files /dev/null and b/app/__pycache__/database.cpython-312.pyc differ diff --git a/app/__pycache__/main.cpython-312.pyc b/app/__pycache__/main.cpython-312.pyc new file mode 100644 index 0000000..a368c79 Binary files /dev/null and b/app/__pycache__/main.cpython-312.pyc differ diff --git a/app/database.py b/app/database.py new file mode 100755 index 0000000..0242857 --- /dev/null +++ b/app/database.py @@ -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) \ No newline at end of file diff --git a/app/dependencies.py b/app/dependencies.py new file mode 100755 index 0000000..49d6ead --- /dev/null +++ b/app/dependencies.py @@ -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") \ No newline at end of file diff --git a/app/main.py b/app/main.py new file mode 100755 index 0000000..7602021 --- /dev/null +++ b/app/main.py @@ -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"} + + diff --git a/app/models/__init__.py b/app/models/__init__.py new file mode 100755 index 0000000..e69de29 diff --git a/app/models/__pycache__/__init__.cpython-312.pyc b/app/models/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..3baf897 Binary files /dev/null and b/app/models/__pycache__/__init__.cpython-312.pyc differ diff --git a/app/models/__pycache__/admin.cpython-312.pyc b/app/models/__pycache__/admin.cpython-312.pyc new file mode 100644 index 0000000..d6752d4 Binary files /dev/null and b/app/models/__pycache__/admin.cpython-312.pyc differ diff --git a/app/models/__pycache__/delivery.cpython-312.pyc b/app/models/__pycache__/delivery.cpython-312.pyc new file mode 100644 index 0000000..2b0091e Binary files /dev/null and b/app/models/__pycache__/delivery.cpython-312.pyc differ diff --git a/app/models/__pycache__/money.cpython-312.pyc b/app/models/__pycache__/money.cpython-312.pyc new file mode 100644 index 0000000..5758d7c Binary files /dev/null and b/app/models/__pycache__/money.cpython-312.pyc differ diff --git a/app/models/__pycache__/pricing.cpython-312.pyc b/app/models/__pycache__/pricing.cpython-312.pyc new file mode 100644 index 0000000..fe58caa Binary files /dev/null and b/app/models/__pycache__/pricing.cpython-312.pyc differ diff --git a/app/models/admin.py b/app/models/admin.py new file mode 100644 index 0000000..8295ec9 --- /dev/null +++ b/app/models/admin.py @@ -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)) + diff --git a/app/models/auto.py b/app/models/auto.py new file mode 100644 index 0000000..a3afb18 --- /dev/null +++ b/app/models/auto.py @@ -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) \ No newline at end of file diff --git a/app/models/customer.py b/app/models/customer.py new file mode 100644 index 0000000..4414fde --- /dev/null +++ b/app/models/customer.py @@ -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)) \ No newline at end of file diff --git a/app/models/delivery.py b/app/models/delivery.py new file mode 100755 index 0000000..9765ae1 --- /dev/null +++ b/app/models/delivery.py @@ -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)) \ No newline at end of file diff --git a/app/models/money.py b/app/models/money.py new file mode 100755 index 0000000..5194633 --- /dev/null +++ b/app/models/money.py @@ -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)) + \ No newline at end of file diff --git a/app/models/pricing.py b/app/models/pricing.py new file mode 100755 index 0000000..e3707e0 --- /dev/null +++ b/app/models/pricing.py @@ -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)) diff --git a/app/routers/__init__.py b/app/routers/__init__.py new file mode 100755 index 0000000..e69de29 diff --git a/app/routers/__pycache__/__init__.cpython-312.pyc b/app/routers/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..22febae Binary files /dev/null and b/app/routers/__pycache__/__init__.cpython-312.pyc differ diff --git a/app/routers/__pycache__/command.cpython-312.pyc b/app/routers/__pycache__/command.cpython-312.pyc new file mode 100755 index 0000000..bc5914f Binary files /dev/null and b/app/routers/__pycache__/command.cpython-312.pyc differ diff --git a/app/routers/__pycache__/delivery.cpython-312.pyc b/app/routers/__pycache__/delivery.cpython-312.pyc new file mode 100644 index 0000000..0c2ce8d Binary files /dev/null and b/app/routers/__pycache__/delivery.cpython-312.pyc differ diff --git a/app/routers/__pycache__/info.cpython-312.pyc b/app/routers/__pycache__/info.cpython-312.pyc new file mode 100644 index 0000000..18e94a9 Binary files /dev/null and b/app/routers/__pycache__/info.cpython-312.pyc differ diff --git a/app/routers/__pycache__/printstatus.cpython-312.pyc b/app/routers/__pycache__/printstatus.cpython-312.pyc new file mode 100755 index 0000000..e7b82bf Binary files /dev/null and b/app/routers/__pycache__/printstatus.cpython-312.pyc differ diff --git a/app/routers/info.py b/app/routers/info.py new file mode 100755 index 0000000..53afe51 --- /dev/null +++ b/app/routers/info.py @@ -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 + } + + + diff --git a/app/schema/__init__.py b/app/schema/__init__.py new file mode 100755 index 0000000..e69de29 diff --git a/app/schema/__pycache__/__init__.cpython-312.pyc b/app/schema/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..6600c24 Binary files /dev/null and b/app/schema/__pycache__/__init__.cpython-312.pyc differ diff --git a/app/schema/__pycache__/delivery.cpython-312.pyc b/app/schema/__pycache__/delivery.cpython-312.pyc new file mode 100644 index 0000000..474abcb Binary files /dev/null and b/app/schema/__pycache__/delivery.cpython-312.pyc differ diff --git a/app/schema/__pycache__/money.cpython-312.pyc b/app/schema/__pycache__/money.cpython-312.pyc new file mode 100644 index 0000000..c58ddcd Binary files /dev/null and b/app/schema/__pycache__/money.cpython-312.pyc differ diff --git a/app/schema/__pycache__/price.cpython-312.pyc b/app/schema/__pycache__/price.cpython-312.pyc new file mode 100644 index 0000000..faef3f0 Binary files /dev/null and b/app/schema/__pycache__/price.cpython-312.pyc differ diff --git a/app/schema/price.py b/app/schema/price.py new file mode 100644 index 0000000..521c303 --- /dev/null +++ b/app/schema/price.py @@ -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) + \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100755 index 0000000..710d751 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +fastapi +uvicorn[standard] +psycopg2-binary +sqlalchemy +python-multipart +pyowm \ No newline at end of file