$foods->VITA = (double) $input->VITA; $foods->VITD = (double) $input->VITD; $foods->VITE = (double) $input->VITE; $foods->VITK = (double) $input->GRice; $foods->GRice = (double) $input->GRice; $foods->GVegetable = (string) $input->GVegetable; $foods->GFruit = (string) $input->GFruit; $foods->GMeat = (string) $input->GMeat; $foods->GFat = (string) $input->GFat; $foods->GMilk = (string) $input->GMilk; $foods->create_by = (string) $input->create_by; $foods->create_date = (string) $input->create_date; $foods->modify_by = (string) $input->modify_by; $foods->modify_date = (string) $input->modify_date; $fs = new FoodsService(); $rs = $fs->createFoods($foods); // $foodstyle = (array) $input->foodstyle; // $fs->updateFoodstyle($rs,$foodstyle); if ($rs) { $app->response()->header('Content-Type', 'application/json'); echo json_encode($rs); } else { throw new ResourceNotFoundException(); } } catch (ResourceNotFoundException $e) { $app->response()->status(404); $app->response()->header('X-Status-Reason', $e->getMessage()); } catch (Exception $e) { $app->response()->status(400); $app->response()->header('X-Status-Reason', $e->getMessage()); }
} }); $app->post('/foodgroups(/)', 'authenticate', function () use($app) { try { $fgs = new FoodsService(); $request = $app->request(); $mediaType = $request->getMediaType(); $body = $request->getBody(); $input = json_decode($body); $foodgs = new Foodgroups(); $foodgs->id = null; $foodgs->fg_name = (string) $input->fg_name; $foodgs->create_by = (string) $input->create_by; $foodgs->create_date = (string) $input->create_date; $foodgs->modify_by = (string) $input->modify_by; $foodgs->modify_date = (string) $input->modify_date; $rs = $fgs->createFoods($foodgs); if ($rs) { $app->response()->header('Content-Type', 'application/json'); echo json_encode($rs); } else { throw new ResourceNotFoundException(); } } catch (ResourceNotFoundException $e) { $app->response()->status(404); $app->response()->header('X-Status-Reason', $e->getMessage()); } catch (Exception $e) { $app->response()->status(400); $app->response()->header('X-Status-Reason', $e->getMessage()); } });