base feature
This commit is contained in:
45
handlers/grocerylist.go
Normal file
45
handlers/grocerylist.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"mealprep/database"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// GroceryListHandler handles the grocery list page
|
||||
func GroceryListHandler(w http.ResponseWriter, r *http.Request) {
|
||||
groceryItems, err := database.GetGroceryList()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
tmpl := `
|
||||
<div id="grocery-content">
|
||||
<h2>Grocery List</h2>
|
||||
<p class="info">This list is automatically generated from your week plan.</p>
|
||||
|
||||
{{if .Items}}
|
||||
<div class="grocery-list">
|
||||
{{range .Items}}
|
||||
<div class="grocery-item">
|
||||
<span class="grocery-name">{{.IngredientName}}</span>
|
||||
<span class="grocery-quantity">{{printf "%.2f" .TotalQuantity}} {{.Unit}}</span>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{else}}
|
||||
<p class="empty-state">No items in your grocery list. Add meals to your week plan to generate a grocery list.</p>
|
||||
{{end}}
|
||||
</div>
|
||||
`
|
||||
|
||||
data := struct {
|
||||
Items interface{}
|
||||
}{
|
||||
Items: groceryItems,
|
||||
}
|
||||
|
||||
t := template.Must(template.New("grocerylist").Parse(tmpl))
|
||||
t.Execute(w, data)
|
||||
}
|
||||
Reference in New Issue
Block a user