repository = $repository; $this->summit_repository = $summit_repository; $this->service = $service; } use GetAll; /** * @return array */ protected function getFilterRules(): array { return [ 'name' => ['==', '=@'], 'label' => ['==', '=@'], 'size' => ['==', '=@'], ]; } /** * @return array */ protected function getFilterValidatorRules(): array { return [ 'name' => 'sometimes|required|string', 'label' => 'sometimes|required|string', 'size' => 'sometimes|required|string', ]; } /** * @return array */ protected function getOrderRules(): array { return [ 'id', 'name', 'order', 'label', 'size', ]; } /** * @return ISummitRepository */ protected function getSummitRepository(): ISummitRepository { return $this->summit_repository; } /** * @return \Illuminate\Http\JsonResponse|mixed */ public function add() { try { if (!Request::isJson()) return $this->error400(); $data = Request::json(); $payload = $data->all(); // Creates a Validator instance and validates the data. $validation = Validator::make($payload, SponsorshipTypeValidationRulesFactory::build($payload)); if ($validation->fails()) { $messages = $validation->messages()->toArray(); return $this->error412 ( $messages ); } $sponsorship_type = $this->service->addSponsorShipType($payload); return $this->created(SerializerRegistry::getInstance()->getSerializer($sponsorship_type)->serialize()); } catch (ValidationException $ex1) { Log::warning($ex1); return $this->error412(array($ex1->getMessage())); } catch (EntityNotFoundException $ex2) { Log::warning($ex2); return $this->error404(array('message' => $ex2->getMessage())); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param $id * @return \Illuminate\Http\JsonResponse|mixed */ public function get($id) { try { $sponsorship_type = $this->repository->getById($id); if(is_null($sponsorship_type)) return $this->error404(); return $this->ok(SerializerRegistry::getInstance()->getSerializer($sponsorship_type)->serialize( Request::input('expand', ''))); } catch (ValidationException $ex1) { Log::warning($ex1); return $this->error412(array($ex1->getMessage())); } catch (EntityNotFoundException $ex2) { Log::warning($ex2); return $this->error404(array('message' => $ex2->getMessage())); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param $id * @return \Illuminate\Http\JsonResponse|mixed */ public function update($id) { try { if (!Request::isJson()) return $this->error400(); $data = Request::json(); $payload = $data->all(); // Creates a Validator instance and validates the data. $validation = Validator::make($payload, SponsorshipTypeValidationRulesFactory::build($payload, true)); if ($validation->fails()) { $messages = $validation->messages()->toArray(); return $this->error412 ( $messages ); } $sponsorship_type = $this->service->updateSponsorShipType($id, $payload); return $this->updated(SerializerRegistry::getInstance()->getSerializer($sponsorship_type)->serialize()); } catch (ValidationException $ex1) { Log::warning($ex1); return $this->error412(array($ex1->getMessage())); } catch (EntityNotFoundException $ex2) { Log::warning($ex2); return $this->error404(array('message' => $ex2->getMessage())); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param $id * @return \Illuminate\Http\JsonResponse|mixed */ public function delete($id) { try { $this->service->deleteSponsorShipType($id); return $this->deleted(); } catch (ValidationException $ex1) { Log::warning($ex1); return $this->error412(array($ex1->getMessage())); } catch (EntityNotFoundException $ex2) { Log::warning($ex2); return $this->error404(array('message' => $ex2->getMessage())); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } }