2025-12-05 14:22:39 +01:00
|
|
|
"""
|
|
|
|
|
BMC Hub - FastAPI Application
|
|
|
|
|
Main application entry point
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import logging
|
2025-12-24 10:34:13 +01:00
|
|
|
from pathlib import Path
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
from fastapi import FastAPI, Request
|
2025-12-05 14:22:39 +01:00
|
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
from fastapi.staticfiles import StaticFiles
|
2025-12-16 15:36:11 +01:00
|
|
|
from fastapi.responses import RedirectResponse
|
2025-12-05 14:22:39 +01:00
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
|
|
|
|
|
|
from app.core.config import settings
|
|
|
|
|
from app.core.database import init_db
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
from app.core.auth_service import AuthService
|
|
|
|
|
from app.core.database import execute_query_single
|
2025-12-06 02:22:01 +01:00
|
|
|
|
2025-12-24 10:34:13 +01:00
|
|
|
def get_version():
|
|
|
|
|
"""Read version from VERSION file"""
|
|
|
|
|
try:
|
|
|
|
|
version_file = Path(__file__).parent / "VERSION"
|
|
|
|
|
return version_file.read_text().strip()
|
|
|
|
|
except Exception:
|
|
|
|
|
return "unknown"
|
|
|
|
|
|
2025-12-16 15:36:11 +01:00
|
|
|
# Import Feature Routers
|
2025-12-06 02:22:01 +01:00
|
|
|
from app.customers.backend import router as customers_api
|
|
|
|
|
from app.customers.backend import views as customers_views
|
2026-01-06 08:21:24 +01:00
|
|
|
from app.customers.backend import bmc_office_router
|
2026-01-31 23:16:24 +01:00
|
|
|
# from app.hardware.backend import router as hardware_api # Replaced by hardware module
|
2025-12-06 02:22:01 +01:00
|
|
|
from app.billing.backend import router as billing_api
|
2025-12-16 22:07:20 +01:00
|
|
|
from app.billing.frontend import views as billing_views
|
2025-12-06 02:22:01 +01:00
|
|
|
from app.system.backend import router as system_api
|
2025-12-19 13:09:42 +01:00
|
|
|
from app.system.backend import sync_router
|
2025-12-06 02:22:01 +01:00
|
|
|
from app.dashboard.backend import views as dashboard_views
|
2026-02-01 11:58:44 +01:00
|
|
|
from app.dashboard.backend import router as dashboard_api
|
2025-12-16 15:36:11 +01:00
|
|
|
from app.prepaid.backend import router as prepaid_api
|
|
|
|
|
from app.prepaid.backend import views as prepaid_views
|
feat(ticket-module): Implement ticket system with comprehensive database schema, permissions, and testing suite
- Added migration 025 for the Ticket System, creating tables for tickets, comments, attachments, worklogs, prepaid cards, and audit logs.
- Introduced migration 026 to add ticket-related permissions to the auth system and assign them to user groups.
- Developed a test suite for the Ticket Module, validating database schema, ticket number generation, prepaid card constraints, service logic, worklog creation, audit logging, and views.
2025-12-15 23:40:23 +01:00
|
|
|
from app.ticket.backend import router as ticket_api
|
|
|
|
|
from app.ticket.frontend import views as ticket_views
|
2025-12-16 15:36:11 +01:00
|
|
|
from app.vendors.backend import router as vendors_api
|
|
|
|
|
from app.vendors.backend import views as vendors_views
|
2025-12-16 22:07:20 +01:00
|
|
|
from app.timetracking.backend import router as timetracking_api
|
|
|
|
|
from app.timetracking.frontend import views as timetracking_views
|
|
|
|
|
from app.contacts.backend import views as contacts_views
|
2025-12-17 16:38:08 +01:00
|
|
|
from app.contacts.backend import router_simple as contacts_api
|
2025-12-17 07:56:33 +01:00
|
|
|
from app.tags.backend import router as tags_api
|
|
|
|
|
from app.tags.backend import views as tags_views
|
2025-12-19 07:51:49 +01:00
|
|
|
from app.emails.backend import router as emails_api
|
|
|
|
|
from app.emails.frontend import views as emails_views
|
|
|
|
|
from app.settings.backend import router as settings_api
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
from app.settings.backend import email_templates as email_templates_api
|
2025-12-19 07:51:49 +01:00
|
|
|
from app.settings.backend import views as settings_views
|
2026-01-02 12:52:47 +01:00
|
|
|
from app.backups.backend.router import router as backups_api
|
2026-01-02 01:21:00 +01:00
|
|
|
from app.backups.frontend import views as backups_views
|
2026-01-06 15:11:28 +01:00
|
|
|
from app.backups.backend.scheduler import backup_scheduler
|
2026-01-11 19:23:21 +01:00
|
|
|
from app.conversations.backend import router as conversations_api
|
|
|
|
|
from app.conversations.frontend import views as conversations_views
|
2026-01-28 07:48:10 +01:00
|
|
|
from app.opportunities.backend import router as opportunities_api
|
|
|
|
|
from app.opportunities.frontend import views as opportunities_views
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
from app.auth.backend import router as auth_api
|
|
|
|
|
from app.auth.backend import views as auth_views
|
|
|
|
|
from app.auth.backend import admin as auth_admin_api
|
2025-12-05 14:22:39 +01:00
|
|
|
|
2026-01-25 03:29:28 +01:00
|
|
|
# Modules
|
|
|
|
|
from app.modules.webshop.backend import router as webshop_api
|
|
|
|
|
from app.modules.webshop.frontend import views as webshop_views
|
2026-01-31 23:16:24 +01:00
|
|
|
from app.modules.sag.backend import router as sag_api
|
2026-02-06 10:47:14 +01:00
|
|
|
from app.modules.sag.backend import reminders as sag_reminders_api
|
2026-01-31 23:16:24 +01:00
|
|
|
from app.modules.sag.frontend import views as sag_views
|
|
|
|
|
from app.modules.hardware.backend import router as hardware_module_api
|
|
|
|
|
from app.modules.hardware.frontend import views as hardware_module_views
|
|
|
|
|
from app.modules.locations.backend import router as locations_api
|
|
|
|
|
from app.modules.locations.frontend import views as locations_views
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
from app.modules.nextcloud.backend import router as nextcloud_api
|
|
|
|
|
from app.modules.search.backend import router as search_api
|
2026-01-25 03:29:28 +01:00
|
|
|
|
2025-12-05 14:22:39 +01:00
|
|
|
# Configure logging
|
|
|
|
|
logging.basicConfig(
|
|
|
|
|
level=logging.INFO,
|
|
|
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
|
|
|
handlers=[
|
|
|
|
|
logging.StreamHandler(),
|
|
|
|
|
logging.FileHandler('logs/app.log')
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
@asynccontextmanager
|
|
|
|
|
async def lifespan(app: FastAPI):
|
|
|
|
|
"""Lifecycle management - startup and shutdown"""
|
|
|
|
|
# Startup
|
|
|
|
|
logger.info("🚀 Starting BMC Hub...")
|
|
|
|
|
logger.info(f"Database: {settings.DATABASE_URL}")
|
|
|
|
|
|
|
|
|
|
init_db()
|
|
|
|
|
|
2026-02-06 10:47:14 +01:00
|
|
|
# Start unified scheduler (handles backups + email fetch + reminders)
|
2026-01-06 15:11:28 +01:00
|
|
|
backup_scheduler.start()
|
|
|
|
|
|
2026-02-06 10:47:14 +01:00
|
|
|
# Register reminder scheduler job
|
|
|
|
|
from app.jobs.check_reminders import check_reminders
|
|
|
|
|
from apscheduler.triggers.interval import IntervalTrigger
|
|
|
|
|
|
|
|
|
|
backup_scheduler.scheduler.add_job(
|
|
|
|
|
func=check_reminders,
|
|
|
|
|
trigger=IntervalTrigger(minutes=5),
|
|
|
|
|
id='check_reminders',
|
|
|
|
|
name='Check Reminders',
|
|
|
|
|
max_instances=1,
|
|
|
|
|
replace_existing=True
|
|
|
|
|
)
|
|
|
|
|
logger.info("✅ Reminder job scheduled (every 5 minutes)")
|
|
|
|
|
|
2025-12-05 14:22:39 +01:00
|
|
|
logger.info("✅ System initialized successfully")
|
|
|
|
|
yield
|
|
|
|
|
# Shutdown
|
2026-01-06 15:11:28 +01:00
|
|
|
backup_scheduler.stop()
|
2025-12-05 14:22:39 +01:00
|
|
|
logger.info("👋 Shutting down...")
|
|
|
|
|
|
|
|
|
|
# Create FastAPI app
|
|
|
|
|
app = FastAPI(
|
|
|
|
|
title="BMC Hub API",
|
|
|
|
|
description="""
|
|
|
|
|
Central management system for BMC Networks.
|
|
|
|
|
|
|
|
|
|
**Key Features:**
|
|
|
|
|
- Customer management
|
|
|
|
|
- Hardware tracking
|
|
|
|
|
- Service management
|
|
|
|
|
- Billing integration
|
|
|
|
|
""",
|
|
|
|
|
version="1.0.0",
|
|
|
|
|
lifespan=lifespan,
|
|
|
|
|
docs_url="/api/docs",
|
|
|
|
|
redoc_url="/api/redoc",
|
|
|
|
|
openapi_url="/api/openapi.json"
|
|
|
|
|
)
|
|
|
|
|
|
2025-12-17 17:28:50 +01:00
|
|
|
# CORS middleware - use CORS_ORIGINS if set, otherwise fallback to ALLOWED_ORIGINS
|
|
|
|
|
cors_origins = settings.CORS_ORIGINS.split(",") if settings.CORS_ORIGINS else settings.ALLOWED_ORIGINS
|
2025-12-05 14:22:39 +01:00
|
|
|
app.add_middleware(
|
|
|
|
|
CORSMiddleware,
|
2025-12-17 17:28:50 +01:00
|
|
|
allow_origins=cors_origins,
|
2025-12-05 14:22:39 +01:00
|
|
|
allow_credentials=True,
|
|
|
|
|
allow_methods=["*"],
|
|
|
|
|
allow_headers=["*"],
|
|
|
|
|
)
|
|
|
|
|
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
# Global auth middleware
|
|
|
|
|
@app.middleware("http")
|
|
|
|
|
async def auth_middleware(request: Request, call_next):
|
|
|
|
|
path = request.url.path
|
|
|
|
|
|
|
|
|
|
public_paths = {
|
|
|
|
|
"/health",
|
|
|
|
|
"/login",
|
|
|
|
|
"/api/v1/auth/login"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if path in public_paths or path.startswith("/static") or path.startswith("/docs"):
|
|
|
|
|
return await call_next(request)
|
|
|
|
|
|
|
|
|
|
token = None
|
|
|
|
|
auth_header = request.headers.get("Authorization")
|
|
|
|
|
if auth_header and auth_header.lower().startswith("bearer "):
|
|
|
|
|
token = auth_header.split(" ", 1)[1]
|
|
|
|
|
else:
|
|
|
|
|
token = request.cookies.get("access_token")
|
|
|
|
|
|
|
|
|
|
payload = AuthService.verify_token(token) if token else None
|
|
|
|
|
if not payload:
|
|
|
|
|
if path.startswith("/api"):
|
|
|
|
|
from fastapi.responses import JSONResponse
|
|
|
|
|
return JSONResponse(
|
|
|
|
|
status_code=401,
|
|
|
|
|
content={"detail": "Not authenticated"}
|
|
|
|
|
)
|
|
|
|
|
return RedirectResponse(url="/login")
|
|
|
|
|
|
2026-02-06 10:47:14 +01:00
|
|
|
user_id_value = payload.get("sub") or payload.get("user_id")
|
|
|
|
|
if user_id_value is not None:
|
|
|
|
|
try:
|
|
|
|
|
request.state.user_id = int(user_id_value)
|
|
|
|
|
except (TypeError, ValueError):
|
|
|
|
|
request.state.user_id = None
|
|
|
|
|
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
if path.startswith("/api") and not payload.get("shadow_admin"):
|
|
|
|
|
if not payload.get("sub"):
|
|
|
|
|
from fastapi.responses import JSONResponse
|
|
|
|
|
return JSONResponse(
|
|
|
|
|
status_code=401,
|
|
|
|
|
content={"detail": "Invalid token"}
|
|
|
|
|
)
|
|
|
|
|
user_id = int(payload.get("sub"))
|
|
|
|
|
user = execute_query_single(
|
|
|
|
|
"SELECT is_2fa_enabled FROM users WHERE user_id = %s",
|
|
|
|
|
(user_id,)
|
|
|
|
|
)
|
|
|
|
|
is_2fa_enabled = bool(user and user.get("is_2fa_enabled"))
|
|
|
|
|
|
|
|
|
|
if not is_2fa_enabled:
|
|
|
|
|
allowed_2fa_paths = (
|
|
|
|
|
"/api/v1/auth/2fa",
|
|
|
|
|
"/api/v1/auth/me",
|
|
|
|
|
"/api/v1/auth/logout"
|
|
|
|
|
)
|
|
|
|
|
if not path.startswith(allowed_2fa_paths):
|
|
|
|
|
from fastapi.responses import JSONResponse
|
|
|
|
|
return JSONResponse(
|
|
|
|
|
status_code=403,
|
|
|
|
|
content={"detail": "2FA required"}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return await call_next(request)
|
|
|
|
|
|
2025-12-05 14:22:39 +01:00
|
|
|
# Include routers
|
2025-12-06 02:22:01 +01:00
|
|
|
app.include_router(customers_api.router, prefix="/api/v1", tags=["Customers"])
|
2026-01-06 08:21:24 +01:00
|
|
|
app.include_router(bmc_office_router.router, prefix="/api/v1", tags=["BMC Office"])
|
2026-01-31 23:16:24 +01:00
|
|
|
# app.include_router(hardware_api.router, prefix="/api/v1", tags=["Hardware"]) # Replaced by hardware module
|
2025-12-06 02:22:01 +01:00
|
|
|
app.include_router(billing_api.router, prefix="/api/v1", tags=["Billing"])
|
|
|
|
|
app.include_router(system_api.router, prefix="/api/v1", tags=["System"])
|
2026-02-01 11:58:44 +01:00
|
|
|
app.include_router(dashboard_api.router, prefix="/api/v1", tags=["Dashboard"])
|
2025-12-19 13:09:42 +01:00
|
|
|
app.include_router(sync_router.router, prefix="/api/v1/system", tags=["System Sync"])
|
2025-12-16 15:36:11 +01:00
|
|
|
app.include_router(prepaid_api.router, prefix="/api/v1", tags=["Prepaid Cards"])
|
|
|
|
|
app.include_router(ticket_api.router, prefix="/api/v1/ticket", tags=["Tickets"])
|
|
|
|
|
app.include_router(vendors_api.router, prefix="/api/v1", tags=["Vendors"])
|
2025-12-17 16:38:08 +01:00
|
|
|
app.include_router(contacts_api.router, prefix="/api/v1", tags=["Contacts"])
|
2025-12-16 22:07:20 +01:00
|
|
|
app.include_router(timetracking_api, prefix="/api/v1", tags=["Time Tracking"])
|
2025-12-17 07:56:33 +01:00
|
|
|
app.include_router(tags_api.router, prefix="/api/v1", tags=["Tags"])
|
2025-12-19 07:51:49 +01:00
|
|
|
app.include_router(emails_api.router, prefix="/api/v1", tags=["Emails"])
|
|
|
|
|
app.include_router(settings_api.router, prefix="/api/v1", tags=["Settings"])
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
app.include_router(email_templates_api.router, prefix="/api/v1", tags=["Email Templates"])
|
2026-01-02 12:52:47 +01:00
|
|
|
app.include_router(backups_api, prefix="/api/v1", tags=["Backups"])
|
2026-01-11 19:23:21 +01:00
|
|
|
app.include_router(conversations_api.router, prefix="/api/v1", tags=["Conversations"])
|
2026-01-28 07:48:10 +01:00
|
|
|
app.include_router(opportunities_api.router, prefix="/api/v1", tags=["Opportunities"])
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
app.include_router(auth_api.router, prefix="/api/v1/auth", tags=["Auth"])
|
|
|
|
|
app.include_router(auth_admin_api.router, prefix="/api/v1", tags=["Auth Admin"])
|
2025-12-06 02:22:01 +01:00
|
|
|
|
2026-01-25 03:29:28 +01:00
|
|
|
# Module Routers
|
|
|
|
|
app.include_router(webshop_api.router, prefix="/api/v1", tags=["Webshop"])
|
2026-01-31 23:16:24 +01:00
|
|
|
app.include_router(sag_api.router, prefix="/api/v1", tags=["Cases"])
|
2026-02-06 10:47:14 +01:00
|
|
|
app.include_router(sag_reminders_api.router, tags=["Reminders"]) # No prefix - endpoints have full path
|
2026-01-31 23:16:24 +01:00
|
|
|
app.include_router(hardware_module_api.router, prefix="/api/v1", tags=["Hardware Module"])
|
|
|
|
|
app.include_router(locations_api, prefix="/api/v1", tags=["Locations"])
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
app.include_router(nextcloud_api.router, prefix="/api/v1/nextcloud", tags=["Nextcloud"])
|
|
|
|
|
app.include_router(search_api.router, prefix="/api/v1", tags=["Search"])
|
2026-01-25 03:29:28 +01:00
|
|
|
|
2025-12-06 02:22:01 +01:00
|
|
|
# Frontend Routers
|
|
|
|
|
app.include_router(dashboard_views.router, tags=["Frontend"])
|
|
|
|
|
app.include_router(customers_views.router, tags=["Frontend"])
|
2025-12-16 15:36:11 +01:00
|
|
|
app.include_router(prepaid_views.router, tags=["Frontend"])
|
2025-12-06 11:04:19 +01:00
|
|
|
app.include_router(vendors_views.router, tags=["Frontend"])
|
2025-12-16 22:07:20 +01:00
|
|
|
app.include_router(timetracking_views.router, tags=["Frontend"])
|
|
|
|
|
app.include_router(billing_views.router, tags=["Frontend"])
|
2025-12-16 15:36:11 +01:00
|
|
|
app.include_router(ticket_views.router, prefix="/ticket", tags=["Frontend"])
|
2025-12-16 22:07:20 +01:00
|
|
|
app.include_router(contacts_views.router, tags=["Frontend"])
|
2025-12-17 07:56:33 +01:00
|
|
|
app.include_router(tags_views.router, tags=["Frontend"])
|
2025-12-19 07:51:49 +01:00
|
|
|
app.include_router(settings_views.router, tags=["Frontend"])
|
|
|
|
|
app.include_router(emails_views.router, tags=["Frontend"])
|
2026-01-02 01:21:00 +01:00
|
|
|
app.include_router(backups_views.router, tags=["Frontend"])
|
2026-01-11 19:23:21 +01:00
|
|
|
app.include_router(conversations_views.router, tags=["Frontend"])
|
2026-01-25 03:29:28 +01:00
|
|
|
app.include_router(webshop_views.router, tags=["Frontend"])
|
2026-01-28 07:48:10 +01:00
|
|
|
app.include_router(opportunities_views.router, tags=["Frontend"])
|
feat(sag): Add Varekøb & Salg module with database migration and frontend template
- Created a new SQL migration for the sag_salgsvarer table to manage sales and purchase items.
- Implemented a new HTML template for the Varekøb & Salg module, including summary cards and tables for sales and purchases.
- Added JavaScript functions for loading and rendering order data dynamically.
- Introduced a new backend search module for customers, contacts, hardware, and locations with autocomplete functionality.
- Developed an email templates API for managing system and customer-specific email templates.
- Created multiple migrations for Nextcloud instances, cache, audit logs, email templates, sag comments, hardware locations, and billing methods.
- Enhanced the sag module with solutions, order lines, work types, and 2FA support for user authentication.
2026-02-02 20:23:56 +01:00
|
|
|
app.include_router(auth_views.router, tags=["Frontend"])
|
2026-01-31 23:16:24 +01:00
|
|
|
app.include_router(sag_views.router, tags=["Frontend"])
|
|
|
|
|
app.include_router(hardware_module_views.router, tags=["Frontend"])
|
|
|
|
|
app.include_router(locations_views.router, tags=["Frontend"])
|
2025-12-05 14:22:39 +01:00
|
|
|
|
|
|
|
|
# Serve static files (UI)
|
|
|
|
|
app.mount("/static", StaticFiles(directory="static", html=True), name="static")
|
2026-01-11 19:23:21 +01:00
|
|
|
app.mount("/docs", StaticFiles(directory="docs"), name="docs")
|
2025-12-05 14:22:39 +01:00
|
|
|
|
|
|
|
|
@app.get("/health")
|
|
|
|
|
async def health_check():
|
|
|
|
|
"""Health check endpoint"""
|
|
|
|
|
return {
|
|
|
|
|
"status": "healthy",
|
|
|
|
|
"service": "BMC Hub",
|
2025-12-23 15:32:26 +01:00
|
|
|
"version": get_version()
|
2025-12-05 14:22:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
import uvicorn
|
|
|
|
|
import os
|
|
|
|
|
|
2026-01-10 21:09:29 +01:00
|
|
|
# Only enable reload in local development (not in Docker) - check both variables
|
|
|
|
|
enable_reload = (
|
|
|
|
|
os.getenv("ENABLE_RELOAD", "false").lower() == "true" or
|
|
|
|
|
os.getenv("API_RELOAD", "false").lower() == "true"
|
|
|
|
|
)
|
2025-12-05 14:22:39 +01:00
|
|
|
|
|
|
|
|
if enable_reload:
|
|
|
|
|
uvicorn.run(
|
|
|
|
|
"main:app",
|
|
|
|
|
host="0.0.0.0",
|
|
|
|
|
port=8000,
|
|
|
|
|
reload=True,
|
|
|
|
|
reload_includes=["*.py"],
|
|
|
|
|
reload_dirs=["app"],
|
2025-12-05 14:42:18 +01:00
|
|
|
reload_excludes=[".git/*", "*.pyc", "__pycache__/*", "logs/*", "uploads/*", "data/*"],
|
2025-12-05 14:22:39 +01:00
|
|
|
log_level="info"
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
uvicorn.run(
|
|
|
|
|
"main:app",
|
|
|
|
|
host="0.0.0.0",
|
|
|
|
|
port=8000,
|
|
|
|
|
reload=False
|
|
|
|
|
)
|