refactor: restructure in entirety
This commit is contained in:
33
internal/handler/invoices.go
Normal file
33
internal/handler/invoices.go
Normal file
@@ -0,0 +1,33 @@
|
||||
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))
|
||||
}
|
||||
Reference in New Issue
Block a user