repository = $company_repository; $this->service = $service; } /** * @return mixed */ public function getAllCompanies(){ return $this->_getAll( function(){ return [ 'name' => ['=@', '=='], ]; }, function(){ return [ 'name' => 'sometimes|string', ]; }, function() { return [ 'name', 'id', ]; }, function($filter){ return $filter; }, function(){ return SerializerRegistry::SerializerType_Public; } ); } /** * @param array $payload * @return array */ function getAddValidationRules(array $payload): array { return CompanyValidationRulesFactory::build($payload); } /** * @param array $payload * @return IEntity * @throws ValidationException */ protected function addEntity(array $payload): IEntity { return $this->service->addCompany($payload); } /** * @inheritDoc */ protected function deleteEntity(int $id): void { $this->service->deleteCompany($id); } /** * @inheritDoc */ protected function getEntity(int $id): IEntity { return $this->repository->getById($id); } /** * @inheritDoc */ function getUpdateValidationRules(array $payload): array { return CompanyValidationRulesFactory::build($payload, true); } /** * @inheritDoc */ protected function updateEntity($id, array $payload): IEntity { return $this->service->updateCompany($id, $payload); } // Logos /** * @param LaravelRequest $request * @param $speaker_id * @return mixed */ public function addCompanyLogo(LaravelRequest $request, $company_id) { try { $file = $request->file('file'); if (is_null($file)) { return $this->error412(array('file param not set!')); } $logo = $this->service->addCompanyLogo($company_id, $file); return $this->created(SerializerRegistry::getInstance()->getSerializer($logo)->serialize()); } catch (EntityNotFoundException $ex1) { Log::warning($ex1); return $this->error404(); } catch (ValidationException $ex2) { Log::warning($ex2); return $this->error412(array($ex2->getMessage())); } catch (\HTTP401UnauthorizedException $ex3) { Log::warning($ex3); return $this->error401(); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param $company_id * @return \Illuminate\Http\JsonResponse|mixed */ public function deleteCompanyLogo($company_id){ try { $this->service->deleteCompanyLogo($company_id); return $this->deleted(); } catch (EntityNotFoundException $ex1) { Log::warning($ex1); return $this->error404(); } catch (ValidationException $ex2) { Log::warning($ex2); return $this->error412(array($ex2->getMessage())); } catch (\HTTP401UnauthorizedException $ex3) { Log::warning($ex3); return $this->error401(); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param LaravelRequest $request * @param $speaker_id * @return mixed */ public function addCompanyBigLogo(LaravelRequest $request, $company_id) { try { $file = $request->file('file'); if (is_null($file)) { return $this->error412(array('file param not set!')); } $logo = $this->service->addCompanyBigLogo($company_id, $file); return $this->created(SerializerRegistry::getInstance()->getSerializer($logo)->serialize()); } catch (EntityNotFoundException $ex1) { Log::warning($ex1); return $this->error404(); } catch (ValidationException $ex2) { Log::warning($ex2); return $this->error412(array($ex2->getMessage())); } catch (\HTTP401UnauthorizedException $ex3) { Log::warning($ex3); return $this->error401(); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param $company_id * @return \Illuminate\Http\JsonResponse|mixed */ public function deleteCompanyBigLogo($company_id){ try { $this->service->deleteCompanyBigLogo($company_id); return $this->deleted(); } catch (EntityNotFoundException $ex1) { Log::warning($ex1); return $this->error404(); } catch (ValidationException $ex2) { Log::warning($ex2); return $this->error412(array($ex2->getMessage())); } catch (\HTTP401UnauthorizedException $ex3) { Log::warning($ex3); return $this->error401(); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } }