diff --git a/src/framework_driver/ui/app.py b/src/framework_driver/ui/app.py deleted file mode 100644 index e6e8e7e..0000000 --- a/src/framework_driver/ui/app.py +++ /dev/null @@ -1,27 +0,0 @@ -from flask import Flask, render_template, redirect, url_for - -app = Flask(__name__) - -@app.route('/') -def home(): - return redirect(url_for('products')) - -@app.route('/cart') -def cart(): - cart_items = [ - {'name': 'Item 1', 'quantity': 2}, - {'name': 'Item 2', 'quantity': 1} - ] - return render_template('cart.html', cart_items=cart_items) - -@app.route('/products') -def products(): - products = [ - {'name': 'Product 1', 'price': 2.5}, - {'name': 'Product 2', 'price': 1.5} - ] - return render_template('product.html', products=products) - - -if __name__ == '__main__': - app.run(debug=True, port=5000) \ No newline at end of file diff --git a/src/framework_driver/ui/static/css/style.css b/src/framework_driver/ui/static/css/style.css index e69de29..ed01269 100644 --- a/src/framework_driver/ui/static/css/style.css +++ b/src/framework_driver/ui/static/css/style.css @@ -0,0 +1,19 @@ +body { + font-family: Arial, sans-serif; +} + +header { + background-color: #f8f9fa; + padding: 1rem; + text-align: center; +} + +main { + padding: 1rem; +} + +button { + padding: 0.5rem 1rem; + margin-top: 1rem; + cursor: pointer; +} \ No newline at end of file diff --git a/src/framework_driver/ui/static/js/script.js b/src/framework_driver/ui/static/js/script.js index e69de29..3035a99 100644 --- a/src/framework_driver/ui/static/js/script.js +++ b/src/framework_driver/ui/static/js/script.js @@ -0,0 +1,3 @@ +document.addEventListener('DOMContentLoaded', function() { + console.log('JavaScript is loaded'); +}); \ No newline at end of file diff --git a/src/framework_driver/ui/templates/base.html b/src/framework_driver/ui/templates/base.html index 84b0250..310dab3 100644 --- a/src/framework_driver/ui/templates/base.html +++ b/src/framework_driver/ui/templates/base.html @@ -4,7 +4,7 @@ {% block title %}My Shop{% endblock %} - +
@@ -13,6 +13,6 @@
{% block content %}{% endblock %}
- + \ No newline at end of file diff --git a/src/framework_driver/ui/templates/cart.html b/src/framework_driver/ui/templates/cart.html index af078b7..403f895 100644 --- a/src/framework_driver/ui/templates/cart.html +++ b/src/framework_driver/ui/templates/cart.html @@ -9,4 +9,7 @@
  • {{ item.name }} - {{ item.quantity }}
  • {% endfor %} + +Back to the prodcuts + {% endblock %} \ No newline at end of file diff --git a/src/framework_driver/ui/templates/product.html b/src/framework_driver/ui/templates/products.html similarity index 70% rename from src/framework_driver/ui/templates/product.html rename to src/framework_driver/ui/templates/products.html index fff92ae..3f07482 100644 --- a/src/framework_driver/ui/templates/product.html +++ b/src/framework_driver/ui/templates/products.html @@ -10,5 +10,6 @@ {% endfor %} -Go to Cart +Go to Cart + {% endblock %} \ No newline at end of file diff --git a/src/main.py b/src/main.py index df10211..f8e74ed 100644 --- a/src/main.py +++ b/src/main.py @@ -1,11 +1,67 @@ from interface_adapters.controllers.cart_controller import router as cart_router - +from fastapi.middleware.cors import CORSMiddleware +from fastapi.staticfiles import StaticFiles +from fastapi.templating import Jinja2Templates +from fastapi.responses import RedirectResponse +from fastapi.responses import HTMLResponse +from fastapi.responses import FileResponse +from fastapi.requests import Request +from fastapi.exceptions import HTTPException from fastapi import FastAPI +import uvicorn +import os + app = FastAPI() app.include_router(cart_router) -@app.get("/") -async def root(): - return {"message": "Hello World"} +# Allow CORS for all origins (for simplicity) +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) +# Serve static files +# TODO fix this +#app.mount("/static", StaticFiles(directory="framework_driver/ui/static"), name="static") +# TODO so this is not needed +@app.get("/custom_static/{filename:path}", response_class=FileResponse, name="custom_static", include_in_schema=False) +async def custom_static(filename: str): + file_path = os.path.join("framework_driver/ui/static", filename) + if not os.path.exists(file_path): + raise HTTPException(status_code=404, detail="File not found") + return FileResponse(file_path) + + +# Set up templates +templates = Jinja2Templates(directory="framework_driver/ui/templates") + +@app.get("/", include_in_schema=False) +async def root(): + return RedirectResponse(url="/docs") + + +@app.get("/ui", response_class=HTMLResponse) +async def ui(request: Request): + products = [ + {"id": 1, "name": "Product 1", "price": 10.0}, + {"id": 2, "name": "Product 2", "price": 20.0} + ] + return templates.TemplateResponse("products.html", {"request": request, "products": products}) + +@app.get("/ui/view_cart", response_class=HTMLResponse, name="ui_view_cart") +async def ui_view_cart(request: Request): + # Dummy cart data for demonstration + cart_items = [ + {"product_id": 1, "name": "Product 1", "quantity": 2}, + {"product_id": 2, "name": "Product 2", "quantity": 1} + ] + + return templates.TemplateResponse("cart.html", {"request": request, "cart_items": cart_items}) + + +if __name__ == "__main__": + uvicorn.run(app, host="127.0.0.1", port=8000) \ No newline at end of file