Filter products per machine

This commit is contained in:
Eden Kirin
2024-01-14 22:12:57 +01:00
parent 018fd310cb
commit 1f3195d992
2 changed files with 28 additions and 4 deletions

View File

@ -24,7 +24,22 @@ func handlePing(c *gin.Context) {
func handleGetProducts(dbConn *gorm.DB) gin.HandlerFunc {
return func(c *gin.Context) {
products := db.GetProducts(dbConn)
var (
machineId *int = nil
err error
mId int
)
machineIdStr, ok := c.GetQuery("machineId")
if ok && len(machineIdStr) > 0 {
if mId, err = strconv.Atoi(machineIdStr); err != nil {
raiseBadRequestError(c, "Invalid machineId filter")
return
}
machineId = &mId
}
products := db.GetProducts(dbConn, machineId)
c.JSON(
http.StatusOK,