Skip to content

Commit

Permalink
feat: add API v3 routes for GET/POST forms
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hartmann <[email protected]>
  • Loading branch information
Chartman123 committed Jun 22, 2024
1 parent 30d7d8d commit 74ccab8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
12 changes: 10 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
'verb' => 'OPTIONS',
'requirements' => [
'path' => '.+',
'apiVersion' => 'v2(\.[1-4])?'
'apiVersion' => 'v2(\.[1-4])?|v3'
]
],

Expand All @@ -91,7 +91,7 @@
'url' => '/api/{apiVersion}/forms',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v2(\.[1-4])?'
'apiVersion' => 'v2(\.[1-4])?|v3'
]
],
[
Expand All @@ -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}',
Expand Down
21 changes: 14 additions & 7 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
*
* @author affan98 <[email protected]>
* @author Christian Hartmann <[email protected]>
* @author Ferdinand Thiessen <[email protected]>
* @author Jan-Christoph Borchardt <[email protected]>
* @author John Molakvoæ (skjnldsv) <[email protected]>
Expand Down Expand Up @@ -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());

Check warning on line 108 in lib/Controller/ApiController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ApiController.php#L106-L108

Added lines #L106 - L108 were not covered by tests

$result = [];
foreach ($forms as $form) {
$result[] = $this->formsService->getPartialFormArray($form);
}
$result = [];
foreach ($forms as $form) {
$result[] = $this->formsService->getPartialFormArray($form);

Check warning on line 112 in lib/Controller/ApiController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ApiController.php#L110-L112

Added lines #L110 - L112 were not covered by tests
}

return new DataResponse($result);
return new DataResponse($result);
} elseif ($type == 'shared') {
return $this->getSharedForms();

Check warning on line 117 in lib/Controller/ApiController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ApiController.php#L115-L117

Added lines #L115 - L117 were not covered by tests
} else {
throw new OCSBadRequestException();

Check warning on line 119 in lib/Controller/ApiController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ApiController.php#L119

Added line #L119 was not covered by tests
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Forms.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/Integration/Api/ApiV2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 74ccab8

Please sign in to comment.