quite a lot of things
This commit is contained in:
37
internal/web/home.go
Normal file
37
internal/web/home.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"billit/internal/database"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
// HomeHandlers holds db reference for home page operations
|
||||
type HomeHandlers struct {
|
||||
db database.Service
|
||||
}
|
||||
|
||||
// NewHomeHandlers creates handlers with db access
|
||||
func NewHomeHandlers(db database.Service) *HomeHandlers {
|
||||
return &HomeHandlers{db: db}
|
||||
}
|
||||
|
||||
// HomePageHandler renders the home page with recent data
|
||||
func (h *HomeHandlers) HomePageHandler(c echo.Context) error {
|
||||
userID := getUserID(c)
|
||||
userEmail, _ := c.Get("user_email").(string)
|
||||
|
||||
// Get recent products (last 5)
|
||||
recentProducts, err := h.db.GetRecentProducts(userID, 5)
|
||||
if err != nil {
|
||||
recentProducts = []database.Product{}
|
||||
}
|
||||
|
||||
// Get recent invoices (last 5)
|
||||
recentInvoices, err := h.db.GetRecentInvoices(userID, 5)
|
||||
if err != nil {
|
||||
recentInvoices = []database.Invoice{}
|
||||
}
|
||||
|
||||
return Render(c, HomePage(userEmail, recentProducts, recentInvoices))
|
||||
}
|
||||
Reference in New Issue
Block a user