diff --git a/appinfo/routes.php b/appinfo/routes.php index 0c1fea1a9e..d549613707 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -81,7 +81,7 @@ 'verb' => 'OPTIONS', 'requirements' => [ 'path' => '.+', - 'apiVersion' => 'v2(\.[1-4])?' + 'apiVersion' => 'v2(\.[1-4])?|v3' ] ], @@ -91,7 +91,7 @@ 'url' => '/api/{apiVersion}/forms', 'verb' => 'GET', 'requirements' => [ - 'apiVersion' => 'v2(\.[1-4])?' + 'apiVersion' => 'v2(\.[1-4])?|v3' ] ], [ @@ -102,6 +102,14 @@ 'apiVersion' => 'v2(\.[1-4])?' ] ], + [ + 'name' => 'api#newForm', + 'url' => '/api/{apiVersion}/forms', + 'verb' => 'POST', + 'requirements' => [ + 'apiVersion' => 'v3' + ] + ], [ 'name' => 'api#getForm', 'url' => '/api/{apiVersion}/form/{id}', diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index b2efe1d8db..09d21476d2 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2017 Vinzenz Rosenkranz * * @author affan98 + * @author Christian Hartmann * @author Ferdinand Thiessen * @author Jan-Christoph Borchardt * @author John Molakvoæ (skjnldsv) @@ -102,15 +103,21 @@ public function __construct( * Return only with necessary information for Listing. * @return DataResponse */ - public function getForms(): DataResponse { - $forms = $this->formMapper->findAllByOwnerId($this->currentUser->getUID()); + public function getForms(string $type='owned'): DataResponse { + if ($type == 'owned') { + $forms = $this->formMapper->findAllByOwnerId($this->currentUser->getUID()); - $result = []; - foreach ($forms as $form) { - $result[] = $this->formsService->getPartialFormArray($form); - } + $result = []; + foreach ($forms as $form) { + $result[] = $this->formsService->getPartialFormArray($form); + } - return new DataResponse($result); + return new DataResponse($result); + } elseif ($type == 'shared') { + return $this->getSharedForms(); + } else { + throw new OCSBadRequestException(); + } } /** diff --git a/src/Forms.vue b/src/Forms.vue index 1d8f9da61c..d5a653e60d 100644 --- a/src/Forms.vue +++ b/src/Forms.vue @@ -362,7 +362,7 @@ export default { // Load Owned forms try { const response = await axios.get( - generateOcsUrl('apps/forms/api/v2.4/forms'), + generateOcsUrl('apps/forms/api/v3/forms'), ) this.forms = OcsResponse2Data(response) } catch (error) { @@ -375,7 +375,7 @@ export default { // Load shared forms try { const response = await axios.get( - generateOcsUrl('apps/forms/api/v2.4/shared_forms'), + generateOcsUrl('apps/forms/api/v3/forms?type=shared'), ) this.allSharedForms = OcsResponse2Data(response) } catch (error) { @@ -443,7 +443,7 @@ export default { try { // Request a new empty form const response = await axios.post( - generateOcsUrl('apps/forms/api/v2.4/form'), + generateOcsUrl('apps/forms/api/v3/forms'), ) const newForm = OcsResponse2Data(response) this.forms.unshift(newForm) diff --git a/tests/Integration/Api/ApiV2Test.php b/tests/Integration/Api/ApiV2Test.php index f3a49a86ff..6593f89ed9 100644 --- a/tests/Integration/Api/ApiV2Test.php +++ b/tests/Integration/Api/ApiV2Test.php @@ -320,7 +320,7 @@ public function dataGetForms() { * @param array $expected */ public function testGetForms(array $expected): void { - $resp = $this->http->request('GET', 'api/v2.4/forms'); + $resp = $this->http->request('GET', 'api/v3/forms'); $data = $this->OcsResponse2Data($resp); $data = $this->arrayUnsetId($data); @@ -354,7 +354,7 @@ public function dataGetSharedForms() { * @param array $expected */ public function testGetSharedForms(array $expected): void { - $resp = $this->http->request('GET', 'api/v2.4/shared_forms'); + $resp = $this->http->request('GET', 'api/v3/forms?type=shared'); $data = $this->OcsResponse2Data($resp); $data = $this->arrayUnsetId($data); @@ -432,7 +432,7 @@ public function dataGetNewForm() { * @param array $expected */ public function testGetNewForm(array $expected): void { - $resp = $this->http->request('POST', 'api/v2.4/form'); + $resp = $this->http->request('POST', 'api/v3/forms'); $data = $this->OcsResponse2Data($resp); // Store for deletion on tearDown