34 lines
835 B
Go
34 lines
835 B
Go
package handler
|
|
|
|
import "billit/internal/view"
|
|
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 view.RenderServerError(c, "Failed to load invoices. Please try again.")
|
|
}
|
|
return view.Render(c, view.InvoicesPage(invoices))
|
|
}
|