From 08098c215748d2a4c9245c03d0d201a8bec7bc84 Mon Sep 17 00:00:00 2001 From: Sebastian Marcet Date: Wed, 17 Oct 2018 14:16:30 -0300 Subject: [PATCH] Added new endpoints to get speaker active involvements and organization roles GET /api/v1/speakers/active-involvements scopes %s/summits/read %s/summits/read/all GET /api/v1/speakers/organizational-roles scopes %s/summits/read %s/summits/read/all Change-Id: I25a53b87228e9e9766693c8e0ab802a520c9b93e --- ...2SpeakerActiveInvolvementApiController.php | 74 +++++++++++++++++++ ...SpeakerOrganizationalRoleApiController.php | 71 ++++++++++++++++++ app/Http/routes.php | 8 ++ .../ISpeakerActiveInvolvementRepository.php | 6 +- .../ISpeakerOrganizationalRoleRepository.php | 5 ++ ...rineSpeakerActiveInvolvementRepository.php | 8 ++ ...ineSpeakerOrganizationalRoleRepository.php | 8 ++ database/seeds/ApiEndpointsSeeder.php | 34 +++++++-- .../OAuth2SpeakerActiveInvolvementApiTest.php | 46 ++++++++++++ ...OAuth2SpeakerOrganizationalRoleApiTest.php | 43 +++++++++++ 10 files changed, 294 insertions(+), 9 deletions(-) create mode 100644 app/Http/Controllers/Apis/Protected/Summit/OAuth2SpeakerActiveInvolvementApiController.php create mode 100644 app/Http/Controllers/Apis/Protected/Summit/OAuth2SpeakerOrganizationalRoleApiController.php create mode 100644 tests/OAuth2SpeakerActiveInvolvementApiTest.php create mode 100644 tests/OAuth2SpeakerOrganizationalRoleApiTest.php diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SpeakerActiveInvolvementApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SpeakerActiveInvolvementApiController.php new file mode 100644 index 00000000..70ad0e67 --- /dev/null +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SpeakerActiveInvolvementApiController.php @@ -0,0 +1,74 @@ +repository = $repository; + } + + /** + * @return mixed + */ + public function getAll(){ + try { + $involvements = $this->repository->getDefaultOnes(); + $response = new PagingResponse + ( + count($involvements), + count($involvements), + 1, + 1, + $involvements + ); + + return $this->ok($response->toArray($expand = Input::get('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); + } + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SpeakerOrganizationalRoleApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SpeakerOrganizationalRoleApiController.php new file mode 100644 index 00000000..faad2e87 --- /dev/null +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SpeakerOrganizationalRoleApiController.php @@ -0,0 +1,71 @@ +repository = $repository; + } + + /** + * @return mixed + */ + public function getAll() + { + try { + $roles = $this->repository->getDefaultOnes(); + $response = new PagingResponse + ( + count($roles), + count($roles), + 1, + 1, + $roles + ); + + return $this->ok($response->toArray($expand = Input::get('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); + } + } +} \ No newline at end of file diff --git a/app/Http/routes.php b/app/Http/routes.php index 1abb9f2d..b750dff5 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -602,6 +602,14 @@ Route::group([ Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitSpeakersApiController@addSpeaker']); Route::put('merge/{speaker_from_id}/{speaker_to_id}', 'OAuth2SummitSpeakersApiController@merge'); + Route::group(['prefix' => 'active-involvements'], function(){ + Route::get('', 'OAuth2SpeakerActiveInvolvementApiController@getAll'); + }); + + Route::group(['prefix' => 'organizational-roles'], function(){ + Route::get('', 'OAuth2SpeakerOrganizationalRoleApiController@getAll'); + }); + Route::group(['prefix' => 'me'], function(){ Route::get('', 'OAuth2SummitSpeakersApiController@getMySpeaker'); Route::post('', 'OAuth2SummitSpeakersApiController@createMySpeaker'); diff --git a/app/Models/Foundation/Summit/Repositories/ISpeakerActiveInvolvementRepository.php b/app/Models/Foundation/Summit/Repositories/ISpeakerActiveInvolvementRepository.php index 79e8596f..79b49732 100644 --- a/app/Models/Foundation/Summit/Repositories/ISpeakerActiveInvolvementRepository.php +++ b/app/Models/Foundation/Summit/Repositories/ISpeakerActiveInvolvementRepository.php @@ -11,6 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +use models\summit\SpeakerActiveInvolvement; use models\utils\IBaseRepository; /** * Interface ISpeakerActiveInvolvementRepository @@ -18,5 +19,8 @@ use models\utils\IBaseRepository; */ interface ISpeakerActiveInvolvementRepository extends IBaseRepository { - + /** + * @return SpeakerActiveInvolvement[] + */ + public function getDefaultOnes(); } \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Repositories/ISpeakerOrganizationalRoleRepository.php b/app/Models/Foundation/Summit/Repositories/ISpeakerOrganizationalRoleRepository.php index d7ecb39f..79038499 100644 --- a/app/Models/Foundation/Summit/Repositories/ISpeakerOrganizationalRoleRepository.php +++ b/app/Models/Foundation/Summit/Repositories/ISpeakerOrganizationalRoleRepository.php @@ -24,4 +24,9 @@ interface ISpeakerOrganizationalRoleRepository extends IBaseRepository * @return SpeakerOrganizationalRole|null */ public function getByRole($role); + + /** + * @return SpeakerOrganizationalRole[] + */ + public function getDefaultOnes(); } \ No newline at end of file diff --git a/app/Repositories/Summit/DoctrineSpeakerActiveInvolvementRepository.php b/app/Repositories/Summit/DoctrineSpeakerActiveInvolvementRepository.php index 11e54413..297db2d0 100644 --- a/app/Repositories/Summit/DoctrineSpeakerActiveInvolvementRepository.php +++ b/app/Repositories/Summit/DoctrineSpeakerActiveInvolvementRepository.php @@ -30,4 +30,12 @@ final class DoctrineSpeakerActiveInvolvementRepository { return SpeakerActiveInvolvement::class; } + + /** + * @return SpeakerActiveInvolvement[] + */ + public function getDefaultOnes() + { + return $this->findBy(["is_default" => true]); + } } \ No newline at end of file diff --git a/app/Repositories/Summit/DoctrineSpeakerOrganizationalRoleRepository.php b/app/Repositories/Summit/DoctrineSpeakerOrganizationalRoleRepository.php index c2c37eb3..b317e789 100644 --- a/app/Repositories/Summit/DoctrineSpeakerOrganizationalRoleRepository.php +++ b/app/Repositories/Summit/DoctrineSpeakerOrganizationalRoleRepository.php @@ -24,6 +24,14 @@ final class DoctrineSpeakerOrganizationalRoleRepository implements ISpeakerOrganizationalRoleRepository { + /** + * @return SpeakerOrganizationalRole[] + */ + public function getDefaultOnes() + { + return $this->findBy(["is_default" => true]); + } + /** * @return string */ diff --git a/database/seeds/ApiEndpointsSeeder.php b/database/seeds/ApiEndpointsSeeder.php index 68f7d9df..2b423697 100644 --- a/database/seeds/ApiEndpointsSeeder.php +++ b/database/seeds/ApiEndpointsSeeder.php @@ -253,7 +253,7 @@ class ApiEndpointsSeeder extends Seeder ], ], // speakers - array( + [ 'name' => 'get-speakers', 'route' => '/api/v1/summits/{id}/speakers', 'http_method' => 'GET', @@ -261,7 +261,7 @@ class ApiEndpointsSeeder extends Seeder sprintf(SummitScopes::ReadSummitData, $current_realm), sprintf(SummitScopes::ReadAllSummitData, $current_realm) ], - ), + ], array( 'name' => 'add-speaker-by-summit', 'route' => '/api/v1/summits/{id}/speakers', @@ -286,22 +286,22 @@ class ApiEndpointsSeeder extends Seeder sprintf(SummitScopes::WriteSpeakersData, $current_realm), ], ), - array( + [ 'name' => 'add-speaker', 'route' => '/api/v1/speakers', 'http_method' => 'POST', 'scopes' => [ sprintf(SummitScopes::WriteSpeakersData, $current_realm), ], - ), - array( + ], + [ 'name' => 'update-speaker', 'route' => '/api/v1/speakers/{speaker_id}', 'http_method' => 'PUT', 'scopes' => [ sprintf(SummitScopes::WriteSpeakersData, $current_realm), ], - ), + ], array( 'name' => 'delete-speaker', 'route' => '/api/v1/speakers/{speaker_id}', @@ -310,7 +310,7 @@ class ApiEndpointsSeeder extends Seeder sprintf(SummitScopes::WriteSpeakersData, $current_realm), ], ), - array( + [ 'name' => 'get-all-speakers', 'route' => '/api/v1/speakers', 'http_method' => 'GET', @@ -318,7 +318,25 @@ class ApiEndpointsSeeder extends Seeder sprintf(SummitScopes::ReadSummitData, $current_realm), sprintf(SummitScopes::ReadAllSummitData, $current_realm) ], - ), + ], + [ + 'name' => 'get-speakers-active-involvements', + 'route' => '/api/v1/speakers/active-involvements', + 'http_method' => 'GET', + 'scopes' => [ + sprintf(SummitScopes::ReadSummitData, $current_realm), + sprintf(SummitScopes::ReadAllSummitData, $current_realm) + ], + ], + [ + 'name' => 'get-speakers-organizational-roles', + 'route' => '/api/v1/speakers/organizational-roles', + 'http_method' => 'GET', + 'scopes' => [ + sprintf(SummitScopes::ReadSummitData, $current_realm), + sprintf(SummitScopes::ReadAllSummitData, $current_realm) + ], + ], array( 'name' => 'get-speaker', 'route' => '/api/v1/speakers/{speaker_id}', diff --git a/tests/OAuth2SpeakerActiveInvolvementApiTest.php b/tests/OAuth2SpeakerActiveInvolvementApiTest.php new file mode 100644 index 00000000..6293bb53 --- /dev/null +++ b/tests/OAuth2SpeakerActiveInvolvementApiTest.php @@ -0,0 +1,46 @@ + " Bearer " . $this->access_token, + "CONTENT_TYPE" => "application/json" + ]; + + $response = $this->action( + "GET", + "OAuth2SpeakerActiveInvolvementApiController@getAll", + $params, + [], + [], + [], + $headers + ); + + $content = $response->getContent(); + $this->assertResponseStatus(200); + $involvements = json_decode($content); + $this->assertTrue(!is_null($involvements)); + return $involvements; + } +} \ No newline at end of file diff --git a/tests/OAuth2SpeakerOrganizationalRoleApiTest.php b/tests/OAuth2SpeakerOrganizationalRoleApiTest.php new file mode 100644 index 00000000..a8903211 --- /dev/null +++ b/tests/OAuth2SpeakerOrganizationalRoleApiTest.php @@ -0,0 +1,43 @@ + " Bearer " . $this->access_token, + "CONTENT_TYPE" => "application/json" + ]; + + $response = $this->action( + "GET", + "OAuth2SpeakerOrganizationalRoleApiController@getAll", + $params, + [], + [], + [], + $headers + ); + + $content = $response->getContent(); + $this->assertResponseStatus(200); + $roles = json_decode($content); + $this->assertTrue(!is_null($roles)); + return $roles; + } +} \ No newline at end of file