28 lines
632 B
Go
28 lines
632 B
Go
package handlers
|
|
|
|
// form:
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.savin.nyc/alex/go-receipt-tracker-api/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})
|
|
}
|