Files
go-receipt-tracker/listeners/handlers/items.go
Alex Savin d01e6a050f
All checks were successful
Build and Push Docker Image / testing (1.24.x, ubuntu-latest) (push) Successful in 2m30s
Build and Push Docker Image / build-and-push (push) Successful in 11m56s
Added an API listener
2025-04-30 18:34:57 -04:00

28 lines
628 B
Go

package handlers
// form:
import (
"net/http"
"git.savin.nyc/alex/go-receipt-tracker/models"
"github.com/gin-gonic/gin"
)
func GetItems(ctx *gin.Context) {
receiptID := ctx.Param("id")
// Create a slice to store the retrieved tasks
var items models.Items
// Execute the database query to retrieve tasks using Go bun
err := DB.NewSelect().Model(&items).Where("receipt_id = ?", receiptID).Scan(ctx.Request.Context())
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
// Return the retrieved tasks in the response
ctx.JSON(http.StatusOK, gin.H{"items": items})
}