added info to meal
This commit is contained in:
@@ -31,6 +31,9 @@ func MealsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
<option value="lunch">Lunch</option>
|
||||
<option value="snack">Snack</option>
|
||||
</select>
|
||||
<input type="number" name="prep_time" placeholder="Prep time (minutes)" min="0" />
|
||||
<input type="url" name="image_url" placeholder="Image URL (optional)" />
|
||||
<textarea name="instructions" placeholder="Instructions (optional)" rows="3"></textarea>
|
||||
<button type="submit">Add Meal</button>
|
||||
</form>
|
||||
|
||||
@@ -38,10 +41,24 @@ func MealsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
{{range .}}
|
||||
<div class="meal-item" id="meal-{{.ID}}">
|
||||
<div class="meal-header">
|
||||
<div>
|
||||
<span class="item-name">{{.Name}}</span>
|
||||
<span class="meal-type-tag tag-{{.MealType}}">{{.MealType}}</span>
|
||||
{{if .ImageURL}}
|
||||
<img src="{{.ImageURL}}" alt="{{.Name}}" class="meal-image" />
|
||||
{{end}}
|
||||
<div class="meal-info-section">
|
||||
<div>
|
||||
<span class="item-name">{{.Name}}</span>
|
||||
<span class="meal-type-tag tag-{{.MealType}}">{{.MealType}}</span>
|
||||
{{if gt .PrepTime 0}}
|
||||
<span class="prep-time">⏱️ {{.PrepTime}} min</span>
|
||||
{{end}}
|
||||
</div>
|
||||
<span class="item-description">{{.Description}}</span>
|
||||
{{if .Instructions}}
|
||||
<details class="instructions-preview">
|
||||
<summary>Instructions</summary>
|
||||
<p class="instructions-text">{{.Instructions}}</p>
|
||||
</details>
|
||||
{{end}}
|
||||
</div>
|
||||
<div>
|
||||
<button
|
||||
@@ -84,6 +101,13 @@ func AddMealHandler(w http.ResponseWriter, r *http.Request) {
|
||||
name := strings.TrimSpace(r.FormValue("name"))
|
||||
description := strings.TrimSpace(r.FormValue("description"))
|
||||
mealType := r.FormValue("meal_type")
|
||||
instructions := strings.TrimSpace(r.FormValue("instructions"))
|
||||
imageURL := strings.TrimSpace(r.FormValue("image_url"))
|
||||
|
||||
prepTime := 0
|
||||
if prepTimeStr := r.FormValue("prep_time"); prepTimeStr != "" {
|
||||
prepTime, _ = strconv.Atoi(prepTimeStr)
|
||||
}
|
||||
|
||||
if name == "" || mealType == "" {
|
||||
http.Error(w, "Name and meal type are required", http.StatusBadRequest)
|
||||
@@ -96,7 +120,7 @@ func AddMealHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
id, err := database.AddMeal(userID, name, description, mealType)
|
||||
id, err := database.AddMeal(userID, name, description, mealType, instructions, imageURL, prepTime)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -105,10 +129,24 @@ func AddMealHandler(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl := `
|
||||
<div class="meal-item" id="meal-{{.ID}}">
|
||||
<div class="meal-header">
|
||||
<div>
|
||||
<span class="item-name">{{.Name}}</span>
|
||||
<span class="meal-type-tag tag-{{.MealType}}">{{.MealType}}</span>
|
||||
{{if .ImageURL}}
|
||||
<img src="{{.ImageURL}}" alt="{{.Name}}" class="meal-image" />
|
||||
{{end}}
|
||||
<div class="meal-info-section">
|
||||
<div>
|
||||
<span class="item-name">{{.Name}}</span>
|
||||
<span class="meal-type-tag tag-{{.MealType}}">{{.MealType}}</span>
|
||||
{{if gt .PrepTime 0}}
|
||||
<span class="prep-time">⏱️ {{.PrepTime}} min</span>
|
||||
{{end}}
|
||||
</div>
|
||||
<span class="item-description">{{.Description}}</span>
|
||||
{{if .Instructions}}
|
||||
<details class="instructions-preview">
|
||||
<summary>Instructions</summary>
|
||||
<p class="instructions-text">{{.Instructions}}</p>
|
||||
</details>
|
||||
{{end}}
|
||||
</div>
|
||||
<div>
|
||||
<button
|
||||
@@ -133,11 +171,14 @@ func AddMealHandler(w http.ResponseWriter, r *http.Request) {
|
||||
`
|
||||
|
||||
data := struct {
|
||||
ID int64
|
||||
Name string
|
||||
Description string
|
||||
MealType string
|
||||
}{id, name, description, mealType}
|
||||
ID int64
|
||||
Name string
|
||||
Description string
|
||||
MealType string
|
||||
Instructions string
|
||||
PrepTime int
|
||||
ImageURL string
|
||||
}{id, name, description, mealType, instructions, prepTime, imageURL}
|
||||
|
||||
t := template.Must(template.New("meal").Parse(tmpl))
|
||||
t.Execute(w, data)
|
||||
|
||||
Reference in New Issue
Block a user