Esempio n. 1
0
 protected function makeFeed(Source $source, ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     $request = $this->createFeedRequest($request);
     $entities = $this->feedService->getFeed($source, $request);
     $responseBuilder->setStatusSuccess()->setJson(['entities' => $entities]);
     return $responseBuilder->build();
 }
 public function decorate(ResponseBuilder $builder, array $response) : array
 {
     $error = $builder->getError();
     if ($error) {
         if ($error instanceof \Exception) {
             $errorMessage = $error->getMessage();
             $response['error_stack'] = $error->getTrace();
         } else {
             if ($error instanceof \TypeError) {
                 $errorMessage = $error->getMessage();
                 $response['error_stack'] = $error->getTrace();
             } else {
                 if (is_string($error)) {
                     $errorMessage = $error;
                 } else {
                     if ($error === null) {
                         $errorMessage = 'No error message available';
                     } else {
                         $errorMessage = (string) $error;
                     }
                 }
             }
         }
         return $response + ['error' => $errorMessage];
     } else {
         return $response;
     }
 }
Esempio n. 3
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $qp = $request->getQueryParams();
         $options = ['profileId' => null, 'seek' => ['limit' => $request->getAttribute('limit'), 'offset' => $request->getAttribute('offset')], 'filter' => []];
         if (isset($qp['profileId'])) {
             $options['profileId'] = (int) $qp['profileId'];
         } else {
             $options['profileId'] = $this->currentAccountService->getCurrentAccount()->getCurrentProfile()->getId();
         }
         if (isset($qp['read'])) {
             $options['filter']['read'] = QueryBoolean::extract($qp['read']);
         }
         if (isset($qp['answer'])) {
             $options['filter']['answer'] = QueryBoolean::extract($qp['answer']);
         }
         $feedbackEntities = $this->feedbackService->getFeedbackEntities($options);
         $responseBuilder->setStatusSuccess()->setJson(['entities' => array_map(function (Feedback $feedback) {
             return $feedback->toJSON();
         }, $feedbackEntities)]);
     } catch (ProfileNotFoundException $e) {
         $responseBuilder->setStatusNotFound()->setError($e);
     } catch (SeekException $e) {
         $responseBuilder->setStatusBadRequest()->setError($e);
     }
     return $responseBuilder->build();
 }
Esempio n. 4
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     $profileId = $this->currentAccountService->getCurrentAccount()->getProfileWithId($request->getAttribute('profileId'))->getId();
     $responseBuilder->setJson(['bookmarks' => array_map(function (ProfileCommunityEQ $entity) {
         return $entity->toJSON();
     }, $this->profileCommunitiesService->getBookmarksOfProfile($profileId))])->setStatusSuccess();
     return $responseBuilder->build();
 }
Esempio n. 5
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     $themes = $this->themeService->getAllThemes();
     $responseBuilder->setJson(['total' => count($themes), 'entities' => array_map(function (Theme $theme) {
         return $theme->toJSON();
     }, $themes)])->setStatusSuccess();
     return $responseBuilder->build();
 }
Esempio n. 6
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $responseBuilder->setJson(['entity' => $this->themeService->getThemeById($request->getAttribute('themeId'))->toJSON()])->setStatusSuccess();
     } catch (ThemeNotFoundException $e) {
         $responseBuilder->setError($e)->setStatusNotFound();
     }
     return $responseBuilder->build();
 }
Esempio n. 7
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $responseBuilder->setJson(['entity' => $this->profileExtendedFormatter->format($this->profileService->getProfileBySID($request->getAttribute('sid')))])->setStatusSuccess();
     } catch (ProfileNotFoundException $e) {
         $responseBuilder->setError($e)->setStatusNotFound();
     }
     return $responseBuilder->build();
 }
Esempio n. 8
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $feedback = $this->feedbackService->getFeedbackById($request->getAttribute('feedbackId'));
         $responseBuilder->setStatusSuccess()->setJson(['entity' => $feedback->toJSON()]);
     } catch (FeedbackNotFoundException $e) {
         $responseBuilder->setStatusNotFound()->setError($e);
     }
     return $responseBuilder->build();
 }
Esempio n. 9
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     $account = $this->currentAccountService->getCurrentAccount();
     try {
         $profile = $this->profileService->createProfileForAccount($account);
         return $responseBuilder->setStatusSuccess()->setJson(['entity' => $profile->toJSON()])->build();
     } catch (MaxProfilesReachedException $e) {
         throw new BadCommandCallException($e->getMessage());
     }
 }
Esempio n. 10
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : Response
 {
     try {
         $gender = $this->profileService->setGender($request->getAttribute('profileId'), Gender::createFromStringCode((new SetGenderRequest($request))->getParameters()->getGenderStringCode()));
         $responseBuilder->setStatusSuccess()->setJson(['gender' => $gender->toJSON()]);
     } catch (ProfileNotFoundException $e) {
         $responseBuilder->setError($e)->setStatusNotFound();
     }
     return $responseBuilder->build();
 }
Esempio n. 11
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $this->feedbackService->deleteFeedback($request->getAttribute('feedbackId'));
         $responseBuilder->setStatusSuccess();
     } catch (FeedbackNotFoundException $e) {
         $responseBuilder->setStatusNotFound()->setError($e->getMessage());
     }
     return $responseBuilder->build();
 }
Esempio n. 12
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $community = $this->communityService->getCommunityById($request->getAttribute('communityId'));
         $responseBuilder->setStatusSuccess()->setJson(['entity' => $this->communityFormatter->format($community)]);
     } catch (CommunityNotFoundException $e) {
         $responseBuilder->setStatusNotFound()->setError($e);
     }
     return $responseBuilder->build();
 }
Esempio n. 13
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $collection = $this->collectionService->getCollectionById($request->getAttribute('collectionId'));
         $responseBuilder->setStatusSuccess()->setJson(['entity' => $collection->toJSON()]);
     } catch (CollectionNotFoundException $e) {
         $responseBuilder->setStatusNotFound()->setError($e);
     }
     return $responseBuilder->build();
 }
Esempio n. 14
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $this->themeService->deleteTheme($request->getAttribute('themeId'));
         $responseBuilder->setStatusSuccess();
     } catch (ThemeNotFoundException $e) {
         $responseBuilder->setError($e)->setStatusNotFound();
     }
     return $responseBuilder->build();
 }
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     $currentProfile = $this->currentAccountService->getCurrentAccount()->getCurrentProfile();
     try {
         $community = $this->communityService->getCommunityById($request->getAttribute('communityId'));
         $this->subscribeService->subscribeCommunity($currentProfile, $community);
         return $responseBuilder->setStatusSuccess()->build();
     } catch (CommunityNotFoundException $e) {
         return $responseBuilder->setStatusNotFound()->build();
     }
 }
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     $currentProfile = $this->currentAccountService->getCurrentAccount()->getCurrentProfile();
     try {
         $theme = $this->themeService->getThemeById($request->getAttribute('themeId'));
         $this->subscribeService->unSubscribeTheme($currentProfile, $theme);
         return $responseBuilder->setStatusSuccess()->build();
     } catch (ThemeNotFoundException $e) {
         return $responseBuilder->setStatusNotFound()->build();
     }
 }
Esempio n. 17
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $parameters = (new CreateThemeRequest($request))->getParameters();
         $theme = $this->themeService->createTheme($parameters);
         $responseBuilder->setJson(['entity' => $theme->toJSON()])->setStatusSuccess();
     } catch (ThemeWithThisIdExistsException $e) {
         $responseBuilder->setError($e)->setStatusConflict();
     }
     return $responseBuilder->build();
 }
Esempio n. 18
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     $account = $this->currentAccountService->getCurrentAccount();
     try {
         $this->accountService->requestDelete($account);
         $responseBuilder->setStatusSuccess()->setJson(['date_account_delete_request' => $account->getDateAccountDeleteRequested()->format(\DateTime::RFC2822)]);
     } catch (AccountHasDeleteRequestException $e) {
         $responseBuilder->setStatusConflict()->setError($e);
     }
     return $responseBuilder->build();
 }
Esempio n. 19
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $parameters = (new UpdateThemeRequest($request))->getParameters();
         $themeEntity = $this->themeService->updateTheme((int) $request->getAttribute('themeId'), $parameters);
         $responseBuilder->setJson(['entity' => $themeEntity->toJSON()])->setStatusSuccess();
     } catch (ThemeNotFoundException $e) {
         $responseBuilder->setError($e)->setStatusNotFound();
     }
     return $responseBuilder->build();
 }
Esempio n. 20
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $profileId = $request->getAttribute('profileId');
         $this->profileService->unsetBirthday($profileId);
         $responseBuilder->setStatusSuccess();
     } catch (ProfileNotFoundException $e) {
         $responseBuilder->setError($e)->setStatusNotFound();
     }
     return $responseBuilder->build();
 }
Esempio n. 21
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $this->feedbackService->markAsRead($request->getAttribute('feedbackId'));
         $responseBuilder->setStatusSuccess();
     } catch (FeedbackNotFoundException $e) {
         $responseBuilder->setStatusNotFound()->setError($e);
     } catch (FeedbackHasNoAnswerException $e) {
         $responseBuilder->setStatusConflict()->setError($e);
     }
     return $responseBuilder->build();
 }
Esempio n. 22
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $collection = $this->collectionService->createCollection((new CreateCollectionRequest($request))->getParameters());
         $responseBuilder->setStatusSuccess()->setJson(['entity' => $collection->toJSON()]);
     } catch (CommunityNotFoundException $e) {
         $responseBuilder->setError($e)->setStatusNotFound();
     } catch (ProfileNotFoundException $e) {
         $responseBuilder->setError($e)->setStatusNotFound();
     }
     return $responseBuilder->build();
 }
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $this->collectionService->setPublicOptions($request->getAttribute('collectionId'), (new SetPublicOptionsRequest($request))->getParameters());
         $responseBuilder->setStatusSuccess();
     } catch (InvalidCollectionOptionsException $e) {
         $responseBuilder->setStatusConflict()->setError($e);
     } catch (CollectionNotFoundException $e) {
         $responseBuilder->setStatusNotFound()->setError($e);
     }
     return $responseBuilder->build();
 }
Esempio n. 24
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : Response
 {
     try {
         $image = $this->profileService->uploadImage($request->getAttribute('profileId'), (new UploadImageRequest($request))->getParameters());
         $responseBuilder->setStatusSuccess()->setJson(['image' => $image->toJSON()]);
     } catch (ImageServiceException $e) {
         $responseBuilder->setStatusNotProcessable()->setError($e);
     } catch (ProfileNotFoundException $e) {
         $responseBuilder->setError($e)->setStatusNotFound();
     }
     return $responseBuilder->build();
 }
Esempio n. 25
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $profileId = $request->getAttribute('profileId');
         $communitySID = $request->getAttribute('communitySID');
         $this->profileCommunitiesService->leaveCommunity($this->currentAccountService->getCurrentAccount()->getProfileWithId($profileId)->getId(), $communitySID);
         $responseBuilder->setStatusSuccess();
     } catch (AlreadyLeavedException $e) {
         $responseBuilder->setError($e)->setStatusConflict();
     }
     return $responseBuilder->build();
 }
Esempio n. 26
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     $account = $this->currentAccountService->getCurrentAccount();
     $profileId = $request->getAttribute('profileId');
     try {
         $this->accountService->switchToProfile($account, $profileId);
         $responseBuilder->setStatusSuccess()->setJson(['profile' => $account->getCurrentProfile()->toJSON()]);
     } catch (AccountNotContainsProfileException $e) {
         $responseBuilder->setError($e)->setStatusNotFound();
     }
     return $responseBuilder->build();
 }
Esempio n. 27
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $image = $this->collectionService->generateImage($request->getAttribute('collectionId'));
         return $responseBuilder->setStatusSuccess()->setJson(['image' => $image->toJSON()])->build();
     } catch (ImageServiceException $e) {
         $responseBuilder->setError($e)->setStatusConflict();
     } catch (CollectionNotFoundException $e) {
         $responseBuilder->setError($e)->setStatusNotFound();
     }
     return $responseBuilder->build();
 }
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $communityId = $request->getAttribute('communityId');
         $featureCode = $request->getAttribute('feature');
         $community = $this->communityService->getCommunityById($communityId);
         $isActivated = $this->communityFeatureService->isFeatureActivated($featureCode, $community);
         $responseBuilder->setStatusSuccess()->setJson(['is_feature_activated' => $isActivated]);
     } catch (CommunityNotFoundException $e) {
         $responseBuilder->setStatusNotFound()->setError($e);
     }
     return $responseBuilder->build();
 }
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         $parameters = (new SetPublicOptionsRequest($request))->getParameters();
         $this->communityService->setPublicOptions($request->getAttribute('communityId'), $parameters);
         $responseBuilder->setStatusSuccess();
     } catch (CommunityHasNoThemeException $e) {
         $responseBuilder->setError($e)->setStatusConflict();
     } catch (CommunityNotFoundException $e) {
         $responseBuilder->setError($e)->setStatusNotFound();
     }
     return $responseBuilder->build();
 }
Esempio n. 30
0
 public function run(ServerRequestInterface $request, ResponseBuilder $responseBuilder) : ResponseInterface
 {
     try {
         /** @var Backdrop $backdrop */
         $backdrop = $this->perform($request);
         $responseBuilder->setStatusSuccess()->setJson(['backdrop' => $backdrop->toJSON()]);
     } catch (ProfileNotFoundException $e) {
         $responseBuilder->setStatusNotFound()->setError($e);
     } catch (BackdropUploadException $e) {
         $responseBuilder->setStatusConflict()->setError($e);
     }
     return $responseBuilder->build();
 }