Filter products per machine
This commit is contained in:
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user