Initial commit: Ballet Production Suite ERP/CRM foundation
This commit is contained in:
38
frontend/api_client.py
Normal file
38
frontend/api_client.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import httpx
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
API_URL = os.getenv("API_URL", "http://localhost:8000")
|
||||
|
||||
class APIClient:
|
||||
def __init__(self):
|
||||
self.client = httpx.Client(base_url=API_URL)
|
||||
self.token = None
|
||||
|
||||
def login(self, username, password):
|
||||
response = self.client.post("/token", data={"username": username, "password": password})
|
||||
if response.status_code == 200:
|
||||
self.token = response.json()["access_token"]
|
||||
self.client.headers.update({"Authorization": f"Bearer {self.token}"})
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_materials(self):
|
||||
response = self.client.get("/materials/")
|
||||
return response.json()
|
||||
|
||||
def create_material(self, name, description, unit, stock_quantity, reorder_level, cost_per_unit):
|
||||
data = {
|
||||
"name": name,
|
||||
"description": description,
|
||||
"unit": unit,
|
||||
"stock_quantity": stock_quantity,
|
||||
"reorder_level": reorder_level,
|
||||
"cost_per_unit": cost_per_unit
|
||||
}
|
||||
response = self.client.post("/materials/", json=data)
|
||||
return response.json()
|
||||
|
||||
api = APIClient()
|
||||
Reference in New Issue
Block a user