Skip to content

Commit

Permalink
fix: Adjust API version, fix API test and make code naming consistent
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Dec 18, 2023
1 parent 2928d33 commit 1471fd0
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 68 deletions.
64 changes: 32 additions & 32 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
'verb' => 'OPTIONS',
'requirements' => [
'path' => '.+',
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],

Expand All @@ -83,31 +83,31 @@
'url' => '/api/{apiVersion}/forms',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#newForm',
'url' => '/api/{apiVersion}/form',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#getForm',
'url' => '/api/{apiVersion}/form/{id}',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#cloneForm',
'url' => '/api/{apiVersion}/form/clone/{id}',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
// TODO: Remove POST in next API release
Expand All @@ -116,47 +116,47 @@
'url' => '/api/{apiVersion}/form/update',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#updateForm',
'url' => '/api/{apiVersion}/form/update',
'verb' => 'PATCH',
'requirements' => [
'apiVersion' => 'v2.2'
'apiVersion' => 'v2\.[2-3]'
]
],
[
'name' => 'api#transferOwner',
'url' => '/api/{apiVersion}/form/transfer',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2.2'
'apiVersion' => 'v2\.[2-3]'
]
],
[
'name' => 'api#deleteForm',
'url' => '/api/{apiVersion}/form/{id}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#getPartialForm',
'url' => '/api/{apiVersion}/partial_form/{hash}',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#getSharedForms',
'url' => '/api/{apiVersion}/shared_forms',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],

Expand All @@ -166,7 +166,7 @@
'url' => '/api/{apiVersion}/question',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
// TODO: Remove POST in next API release
Expand All @@ -175,15 +175,15 @@
'url' => '/api/{apiVersion}/question/update',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#updateQuestion',
'url' => '/api/{apiVersion}/question/update',
'verb' => 'PATCH',
'requirements' => [
'apiVersion' => 'v2.2'
'apiVersion' => 'v2\.[2-3]'
]
],
// TODO: Remove POST in next API release
Expand All @@ -192,31 +192,31 @@
'url' => '/api/{apiVersion}/question/reorder',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#reorderQuestions',
'url' => '/api/{apiVersion}/question/reorder',
'verb' => 'PUT',
'requirements' => [
'apiVersion' => 'v2.2'
'apiVersion' => 'v2\.[2-3]'
]
],
[
'name' => 'api#deleteQuestion',
'url' => '/api/{apiVersion}/question/{id}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#duplicateQuestion',
'name' => 'api#cloneQuestion',
'url' => '/api/{apiVersion}/question/clone/{id}',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2.1'
'apiVersion' => 'v2.3'
]
],

Expand All @@ -226,7 +226,7 @@
'url' => '/api/{apiVersion}/option',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
// TODO: Remove POST in next API release
Expand All @@ -235,23 +235,23 @@
'url' => '/api/{apiVersion}/option/update',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#updateOption',
'url' => '/api/{apiVersion}/option/update',
'verb' => 'PATCH',
'requirements' => [
'apiVersion' => 'v2.2'
'apiVersion' => 'v2\.[2-3]'
]
],
[
'name' => 'api#deleteOption',
'url' => '/api/{apiVersion}/option/{id}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],

Expand All @@ -261,15 +261,15 @@
'url' => '/api/{apiVersion}/share',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'shareApi#deleteShare',
'url' => '/api/{apiVersion}/share/{id}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
// TODO: Remove POST in next API release
Expand All @@ -286,7 +286,7 @@
'url' => '/api/{apiVersion}/share/update',
'verb' => 'PATCH',
'requirements' => [
'apiVersion' => 'v2.2'
'apiVersion' => 'v2\.[2-3]'
]
],

Expand All @@ -296,47 +296,47 @@
'url' => '/api/{apiVersion}/submissions/{hash}',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#exportSubmissions',
'url' => '/api/{apiVersion}/submissions/export/{hash}',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#exportSubmissionsToCloud',
'url' => '/api/{apiVersion}/submissions/export',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#deleteAllSubmissions',
'url' => '/api/{apiVersion}/submissions/{formId}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#insertSubmission',
'url' => '/api/{apiVersion}/submission/insert',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#deleteSubmission',
'url' => '/api/{apiVersion}/submission/{id}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
]
Expand Down
15 changes: 15 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ This file contains the API-Documentation. For more information on the returned D

### Other API changes
- In API version 2.1 the endpoint `/api/v2.1/share/update` was added to update a Share
- In API version 2.2 the endpoint `/api/v2.2/form/transfer` was added to transfer ownership of a form
- In API version 2.3 the endpoint `/api/v2.3/question/clone` was added to clone a question

## Form Endpoints
### List owned Forms
Expand Down Expand Up @@ -329,6 +331,19 @@ Reorders all Questions of a single form
"data": 4
```

### Clone a question
Creates a clone of a question with all its options.
- Endpoint: `/api/v2.3/question/clone/{id}`
- Url-Parameter:
| Parameter | Type | Description |
|-----------|---------|-------------|
| _id_ | Integer | ID of the question to clone |
- Method: `POST`
- Response: Returns cloned question object with the new ID set.
```
See section 'Create a new question'.
```

## Option Endpoints
Contains only manipulative question-endpoints. To retrieve options, request the full form data.

Expand Down
9 changes: 5 additions & 4 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
Expand Down Expand Up @@ -717,14 +718,14 @@ public function deleteQuestion(int $id): DataResponse {
* @CORS
* @NoAdminRequired
*
* Duplicate a question
* Clone a question
*
* @param int $id the question id
* @return DataResponse
* @throws OCSBadRequestException|OCSForbiddenException
*/
public function duplicateQuestion(int $id): DataResponse {
$this->logger->debug('Question to be duplicated: {id}', [
public function cloneQuestion(int $id): DataResponse {
$this->logger->debug('Question to be cloned: {id}', [
'id' => $id
]);

Expand All @@ -734,7 +735,7 @@ public function duplicateQuestion(int $id): DataResponse {
$form = $this->formMapper->findById($sourceQuestion->getFormId());
} catch (IMapperException $e) {
$this->logger->debug('Could not find form or question');
throw new OCSBadRequestException('Could not find form or question');
throw new OCSNotFoundException('Could not find form or question');
}

if ($form->getOwnerId() !== $this->currentUser->getUID()) {
Expand Down
8 changes: 4 additions & 4 deletions src/components/Questions/Question.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
</template>
{{ t('forms', 'Technical name') }}
</NcActionInput>
<NcActionButton @click="onDuplicate">
<NcActionButton @click="onClone">
<template #icon>
<IconContentDuplicate :size="20" />
</template>
Expand Down Expand Up @@ -315,10 +315,10 @@ export default {
},
/**
* Duplicate this question
* Clone this question
*/
onDuplicate() {
this.$emit('duplicate')
onClone() {
this.$emit('clone')
},
},
}
Expand Down
8 changes: 4 additions & 4 deletions src/mixins/QuestionMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ export default {
*/
commonListeners() {
return {
clone: this.onClone,
delete: this.onDelete,
duplicate: this.onDuplicate,
'update:text': this.onTitleChange,
'update:description': this.onDescriptionChange,
'update:isRequired': this.onRequiredChange,
Expand Down Expand Up @@ -292,10 +292,10 @@ export default {
},

/**
* Duplicate this question.
* Clone this question.
*/
onDuplicate() {
this.$emit('duplicate')
onClone() {
this.$emit('clone')
},

/**
Expand Down
Loading

0 comments on commit 1471fd0

Please sign in to comment.