package web import ( "billit/internal/database" "net/http" "github.com/labstack/echo/v4" ) // InvoicesHandlers holds db reference for invoice operations type InvoicesHandlers struct { db database.Service } // NewInvoicesHandlers creates handlers with db access func NewInvoicesHandlers(db database.Service) *InvoicesHandlers { return &InvoicesHandlers{db: db} } // InvoicesListHandler renders the /invoice page with all invoices func (h *InvoicesHandlers) InvoicesListHandler(c echo.Context) error { userID := getUserID(c) if userID == "" { return c.Redirect(http.StatusFound, "/") } invoices, err := h.db.GetAllInvoices(userID) if err != nil { return RenderServerError(c, "Failed to load invoices. Please try again.") } return Render(c, InvoicesPage(invoices)) }