""" @router StorefrontRouter (Backend/app/api/v1/routers/StorefrontRouter.py) @purpose Read-only public endpoints for footer info, store settings, mega menu, catalog filters, trust badges, blog posts, and product reviews — all backed by StorefrontCmsService. """ from fastapi import APIRouter, Depends, Query from sqlalchemy.orm import Session from typing import Any, Dict, List, Optional from app.core.database.db_session import get_db from app.services.StorefrontCmsService import StorefrontCmsService router = APIRouter(prefix="/api/v1/storefront", tags=["Storefront Dynamic Services"]) @router.get("/footer-info") def get_footer_info(db: Session = Depends(get_db)) -> Any: """Returns dynamic footer contact info, social links, navigation columns, and payment icons.""" svc = StorefrontCmsService(db) return svc.get_footer_info() @router.get("/settings") def get_storefront_settings(db: Session = Depends(get_db)) -> Any: """Returns store branding settings (logo, wordmark, support phone, advance_percent, etc.).""" svc = StorefrontCmsService(db) return svc.get_settings() @router.get("/mega-menu") def get_mega_menu( nav_key: Optional[str] = Query(None, pattern="^(shop|deals|products)$"), db: Session = Depends(get_db), ) -> Any: """ Returns mega-menu configuration. If nav_key is supplied returns single menu config. If omitted returns all three (shop, deals, products) in one payload. """ svc = StorefrontCmsService(db) return svc.get_mega_menu(nav_key) @router.get("/catalog-filters") def get_catalog_filters(db: Session = Depends(get_db)) -> Any: """Returns highlight filter tabs and price range buckets for the shop catalog page.""" svc = StorefrontCmsService(db) return svc.get_catalog_filters() @router.get("/reviews/{product_id}") def get_product_reviews(product_id: str, db: Session = Depends(get_db)) -> List[Any]: """Returns only approved customer reviews for a given product (live from DB).""" from app.services.StorefrontService import StorefrontService svc = StorefrontService(db) return svc.get_reviews(product_id) @router.get("/trust-badges") def get_trust_badges() -> List[Dict[str, Any]]: """Returns dynamic storefront trust badges.""" return [ {"id": "tb1", "title": "Free Shipping", "subtitle": "On order over ₹1,000", "icon": "truck"}, {"id": "tb2", "title": "Flexible & Easy Return", "subtitle": "Return within 14 days", "icon": "refresh"}, {"id": "tb3", "title": "24/7 Support Services", "subtitle": "Any Time Customer Support", "icon": "headset"}, {"id": "tb4", "title": "Secure payment", "subtitle": "100% Fast & Secure Payment", "icon": "shield"}, ] @router.get("/blog-posts") def get_blog_posts() -> List[Dict[str, Any]]: """Returns dynamic tech blog articles.""" return [ {"post_id": "bp1", "title": "How to Write a Blog Post Your Readers Will Love in 5 Steps", "excerpt": "Why the world would end without travel coupons. The 16 worst...", "author": "Admin", "date": "July 24, 2026", "image_url": ""}, {"post_id": "bp2", "title": "9 Content Marketing Trends and Ideas to Increase Traffic", "excerpt": "Why do people think wholesale accessories are a good idea? Unbelievable...", "author": "Technician", "date": "July 22, 2026", "image_url": ""}, {"post_id": "bp3", "title": "The Ultimate Guide to Marketing Strategies to Improve Sales", "excerpt": "Many things about electronic devices your kids don't want you to...", "author": "Store Manager", "date": "July 19, 2026", "image_url": ""}, {"post_id": "bp4", "title": "50 Best Sales Questions to Determine Your Customer's Needs", "excerpt": "The unconventional guide to the software applications...", "author": "Support Desk", "date": "July 15, 2026", "image_url": ""}, ] @router.get("/banners") def get_storefront_banners(db: Session = Depends(get_db)) -> List[Dict[str, Any]]: """Returns hero banners for the storefront homepage (BUG-04 fix).""" svc = StorefrontCmsService(db) banners = svc.get_content_by_region(page="home", region="hero", content_type="hero_banner") if banners: return [ { "banner_id": b.content_id, "title": b.title, "subtitle": b.subtitle or "", "image_url": b.image_url or "", "button_text": b.button_text or "Shop Now", "button_url": b.button_url or "/shop" } for b in banners ] return [ { "banner_id": "b1", "title": "Smartphone Repair & Spare Parts", "subtitle": "100% Genuine OEM Displays, Batteries & Accessories", "image_url": "/assets/hero-banner-1.webp", "button_text": "Explore Catalog", "button_url": "/shop" }, { "banner_id": "b2", "title": "Fast Doorstep Repair Service", "subtitle": "Certified Engineers & 6-Month iFixKart Warranty", "image_url": "/assets/hero-banner-2.webp", "button_text": "Book Repair", "button_url": "/services" } ]