Unverified Commit 1f95e3f1 authored by Christian Hartmann's avatar Christian Hartmann
Browse files

Adjust API to isRequired


Signed-off-by: default avatarChristian Hartmann <chris-hartmann@gmx.de>
parent 352ee256
......@@ -26,40 +26,192 @@
return [
'routes' => [
// Internal views
['name' => 'page#views', 'url' => '/{hash}/{view}', 'verb' => 'GET'],
[
'name' => 'page#views',
'url' => '/{hash}/{view}',
'verb' => 'GET'
],
// Share-Link & public submit
['name' => 'page#goto_form', 'url' => '/{hash}', 'verb' => 'GET'],
[
'name' => 'page#goto_form',
'url' => '/{hash}',
'verb' => 'GET'
],
// App Root
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
[
'name' => 'page#index',
'url' => '/',
'verb' => 'GET'
],
],
'ocs' => [
// Forms
['name' => 'api#getForms', 'url' => '/api/v1/forms', 'verb' => 'GET'],
['name' => 'api#newForm', 'url' => '/api/v1/form', 'verb' => 'POST'],
['name' => 'api#getForm', 'url' => '/api/v1/form/{id}', 'verb' => 'GET'],
['name' => 'api#cloneForm', 'url' => '/api/v1/form/clone/{id}', 'verb' => 'POST'],
['name' => 'api#updateForm', 'url' => '/api/v1/form/update', 'verb' => 'POST'],
['name' => 'api#deleteForm', 'url' => '/api/v1/form/{id}', 'verb' => 'DELETE'],
['name' => 'api#getSharedForms', 'url' => '/api/v1/shared_forms', 'verb' => 'GET'],
[
'name' => 'api#getForms',
'url' => '/api/{apiVersion}/forms',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
[
'name' => 'api#newForm',
'url' => '/api/{apiVersion}/form',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
[
'name' => 'api#getForm',
'url' => '/api/{apiVersion}/form/{id}',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
[
'name' => 'api#cloneForm',
'url' => '/api/{apiVersion}/form/clone/{id}',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
[
'name' => 'api#updateForm',
'url' => '/api/{apiVersion}/form/update',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
[
'name' => 'api#deleteForm',
'url' => '/api/{apiVersion}/form/{id}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
[
'name' => 'api#getSharedForms',
'url' => '/api/{apiVersion}/shared_forms',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
// Questions
['name' => 'api#newQuestion', 'url' => '/api/v1/question', 'verb' => 'POST'],
['name' => 'api#updateQuestion', 'url' => '/api/v1/question/update', 'verb' => 'POST'],
['name' => 'api#reorderQuestions', 'url' => '/api/v1/question/reorder', 'verb' => 'POST'],
['name' => 'api#deleteQuestion', 'url' => '/api/v1/question/{id}', 'verb' => 'DELETE'],
[
'name' => 'api#newQuestion',
'url' => '/api/{apiVersion}/question',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
[
'name' => 'api#updateQuestion',
'url' => '/api/{apiVersion}/question/update',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
[
'name' => 'api#reorderQuestions',
'url' => '/api/{apiVersion}/question/reorder',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
[
'name' => 'api#deleteQuestion',
'url' => '/api/{apiVersion}/question/{id}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
// Answers
['name' => 'api#newOption', 'url' => '/api/v1/option', 'verb' => 'POST'],
['name' => 'api#updateOption', 'url' => '/api/v1/option/update', 'verb' => 'POST'],
['name' => 'api#deleteOption', 'url' => '/api/v1/option/{id}', 'verb' => 'DELETE'],
// Options
[
'name' => 'api#newOption',
'url' => '/api/{apiVersion}/option',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
[
'name' => 'api#updateOption',
'url' => '/api/{apiVersion}/option/update',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
[
'name' => 'api#deleteOption',
'url' => '/api/{apiVersion}/option/{id}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
// Submissions
['name' => 'api#getSubmissions', 'url' => '/api/v1/submissions/{hash}', 'verb' => 'GET'],
['name' => 'api#exportSubmissions', 'url' => '/api/v1/submissions/export/{hash}', 'verb' => 'GET'],
['name' => 'api#exportSubmissionsToCloud', 'url' => '/api/v1/submissions/export', 'verb' => 'POST'],
['name' => 'api#deleteAllSubmissions', 'url' => '/api/v1/submissions/{formId}', 'verb' => 'DELETE'],
['name' => 'api#insertSubmission', 'url' => '/api/v1/submission/insert', 'verb' => 'POST'],
['name' => 'api#deleteSubmission', 'url' => '/api/v1/submission/{id}', 'verb' => 'DELETE'],
[
'name' => 'api#getSubmissions',
'url' => '/api/{apiVersion}/submissions/{hash}',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
[
'name' => 'api#exportSubmissions',
'url' => '/api/{apiVersion}/submissions/export/{hash}',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
[
'name' => 'api#exportSubmissionsToCloud',
'url' => '/api/{apiVersion}/submissions/export',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
[
'name' => 'api#deleteAllSubmissions',
'url' => '/api/{apiVersion}/submissions/{formId}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
[
'name' => 'api#insertSubmission',
'url' => '/api/{apiVersion}/submission/insert',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
[
'name' => 'api#deleteSubmission',
'url' => '/api/{apiVersion}/submission/{id}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v1(\.1)?'
]
],
]
];
......@@ -215,6 +215,12 @@ class ApiController extends OCSController {
throw new OCSForbiddenException();
}
// TODO remove after removal of API v1.1
// Backward compatibility for mandatory
foreach ($form['questions'] as $index => $question) {
$form['questions'][$index]['mandatory'] = $question['isRequired'];
}
return new DataResponse($form);
}
......@@ -483,13 +489,17 @@ class ApiController extends OCSController {
$question->setOrder($questionOrder);
$question->setType($type);
$question->setText($text);
$question->setMandatory(false);
$question->setIsRequired(false);
$question = $this->questionMapper->insert($question);
$response = $question->read();
$response['options'] = [];
// TODO remove after removal of API v1.1
// Backward compatibility for mandatory
$response['mandatory'] = $response['isRequired'];
return new DataResponse($response);
}
......@@ -634,6 +644,14 @@ class ApiController extends OCSController {
throw new OCSForbiddenException('Please use reorderQuestions() to change order');
}
// TODO remove after removal of API v1.1
// Rename deprecated mandatory key to isRequired
if (key_exists('mandatory', $keyValuePairs)) {
$this->logger->info('Key \'mandatory\' is deprecated, please use \'isRequired\'.');
$keyValuePairs['isRequired'] = $keyValuePairs['mandatory'];
unset($keyValuePairs['mandatory']);
}
// Create QuestionEntity with given Params & Id.
$question = Question::fromParams($keyValuePairs);
$question->setId($id);
......@@ -903,6 +921,12 @@ class ApiController extends OCSController {
// Load currently active questions
$questions = $this->formsService->getQuestions($form->getId());
// TODO remove after removal of API v1.1
// Backward compatibility for mandatory
foreach ($questions as $index => $question) {
$questions[$index]['mandatory'] = $question['isRequired'];
}
$response = [
'submissions' => $submissions,
'questions' => $questions,
......
......@@ -47,7 +47,7 @@ class Question extends Entity {
protected $formId;
protected $order;
protected $type;
protected $mandatory;
protected $isRequired;
protected $text;
public const TYPES = [
......@@ -64,7 +64,7 @@ class Question extends Entity {
$this->addType('formId', 'integer');
$this->addType('order', 'integer');
$this->addType('type', 'string');
$this->addType('mandatory', 'bool');
$this->addType('isRequired', 'bool');
$this->addType('text', 'string');
}
......@@ -74,7 +74,7 @@ class Question extends Entity {
'formId' => $this->getFormId(),
'order' => $this->getOrder(),
'type' => htmlspecialchars_decode($this->getType()),
'isRequired' => $this->getMandatory(),
'isRequired' => $this->getIsRequired(),
'text' => htmlspecialchars_decode($this->getText()),
];
}
......
......@@ -202,7 +202,7 @@ export default {
// Load Owned forms
try {
const response = await axios.get(generateOcsUrl('apps/forms/api/v1', 2) + 'forms')
const response = await axios.get(generateOcsUrl('apps/forms/api/v1.1', 2) + 'forms')
this.forms = OcsResponse2Data(response)
} catch (error) {
showError(t('forms', 'An error occurred while loading the forms list'))
......@@ -211,7 +211,7 @@ export default {
// Load shared forms
try {
const response = await axios.get(generateOcsUrl('apps/forms/api/v1', 2) + 'shared_forms')
const response = await axios.get(generateOcsUrl('apps/forms/api/v1.1', 2) + 'shared_forms')
this.sharedForms = OcsResponse2Data(response)
} catch (error) {
showError(t('forms', 'An error occurred while loading the forms list'))
......@@ -227,7 +227,7 @@ export default {
async onNewForm() {
try {
// Request a new empty form
const response = await axios.post(generateOcsUrl('apps/forms/api/v1', 2) + 'form')
const response = await axios.post(generateOcsUrl('apps/forms/api/v1.1', 2) + 'form')
const newForm = OcsResponse2Data(response)
this.forms.unshift(newForm)
this.$router.push({ name: 'edit', params: { hash: newForm.hash } })
......@@ -245,7 +245,7 @@ export default {
*/
async onCloneForm(id) {
try {
const response = await axios.post(generateOcsUrl('apps/forms/api/v1', 2) + `form/clone/${id}`)
const response = await axios.post(generateOcsUrl('apps/forms/api/v1.1', 2) + `form/clone/${id}`)
const newForm = OcsResponse2Data(response)
this.forms.unshift(newForm)
this.$router.push({ name: 'edit', params: { hash: newForm.hash } })
......
......@@ -183,7 +183,7 @@ export default {
// All good, let's delete
this.loading = true
try {
await axios.delete(generateOcsUrl('apps/forms/api/v1', 2) + `form/${this.form.id}`)
await axios.delete(generateOcsUrl('apps/forms/api/v1.1', 2) + `form/${this.form.id}`)
this.$emit('delete', this.form.id)
} catch (error) {
showError(t('forms', 'Error while deleting {title}', { title: this.formTitle }))
......
......@@ -146,7 +146,7 @@ export default {
*/
async createAnswer(answer) {
try {
const response = await axios.post(generateOcsUrl('apps/forms/api/v1', 2) + 'option', {
const response = await axios.post(generateOcsUrl('apps/forms/api/v1.1', 2) + 'option', {
questionId: answer.questionId,
text: answer.text,
})
......@@ -174,7 +174,7 @@ export default {
*/
async updateAnswer(answer) {
try {
await axios.post(generateOcsUrl('apps/forms/api/v1', 2) + 'option/update', {
await axios.post(generateOcsUrl('apps/forms/api/v1.1', 2) + 'option/update', {
id: this.answer.id,
keyValuePairs: {
text: answer.text,
......
......@@ -305,7 +305,7 @@ export default {
if (!option.local) {
// let's not await, deleting in background
axios.delete(generateOcsUrl('apps/forms/api/v1', 2) + `option/${option.id}`)
axios.delete(generateOcsUrl('apps/forms/api/v1.1', 2) + `option/${option.id}`)
.catch(error => {
showError(t('forms', 'There was an issue deleting this option'))
console.error(error)
......
......@@ -312,7 +312,7 @@ export default {
if (!option.local) {
// let's not await, deleting in background
axios.delete(generateOcsUrl('apps/forms/api/v1', 2) + `option/${option.id}`)
axios.delete(generateOcsUrl('apps/forms/api/v1.1', 2) + `option/${option.id}`)
.catch(error => {
showError(t('forms', 'There was an issue deleting this option'))
console.error(error)
......
......@@ -121,11 +121,11 @@ export default {
/**
* Forward the required change to the parent and store to db
*
* @param {Boolean} isRequiredValue new mandatory Value
* @param {Boolean} isRequiredValue new isRequired Value
*/
onRequiredChange: debounce(function(isRequiredValue) {
this.$emit('update:isRequired', isRequiredValue)
this.saveQuestionProperty('mandatory', isRequiredValue)
this.saveQuestionProperty('isRequired', isRequiredValue)
}, 200),
/**
......@@ -170,7 +170,7 @@ export default {
async saveQuestionProperty(key, value) {
try {
// TODO: add loading status feedback ?
await axios.post(generateOcsUrl('apps/forms/api/v1', 2) + 'question/update', {
await axios.post(generateOcsUrl('apps/forms/api/v1.1', 2) + 'question/update', {
id: this.id,
keyValuePairs: {
[key]: value,
......
......@@ -88,7 +88,7 @@ export default {
this.cancelFetchFullForm = cancel
try {
const response = await request(generateOcsUrl('apps/forms/api/v1', 2) + `form/${id}`)
const response = await request(generateOcsUrl('apps/forms/api/v1.1', 2) + `form/${id}`)
this.$emit('update:form', OcsResponse2Data(response))
this.isLoadingForm = false
} catch (error) {
......@@ -108,7 +108,7 @@ export default {
async saveFormProperty(key) {
try {
// TODO: add loading status feedback ?
await axios.post(generateOcsUrl('apps/forms/api/v1', 2) + 'form/update', {
await axios.post(generateOcsUrl('apps/forms/api/v1.1', 2) + 'form/update', {
id: this.form.id,
keyValuePairs: {
[key]: this.form[key],
......
......@@ -269,7 +269,7 @@ export default {
this.isLoadingQuestions = true
try {
const response = await axios.post(generateOcsUrl('apps/forms/api/v1', 2) + 'question', {
const response = await axios.post(generateOcsUrl('apps/forms/api/v1.1', 2) + 'question', {
formId: this.form.id,
type,
text,
......@@ -307,7 +307,7 @@ export default {
this.isLoadingQuestions = true
try {
await axios.delete(generateOcsUrl('apps/forms/api/v1', 2) + `question/${id}`)
await axios.delete(generateOcsUrl('apps/forms/api/v1.1', 2) + `question/${id}`)
const index = this.form.questions.findIndex(search => search.id === id)
this.form.questions.splice(index, 1)
} catch (error) {
......@@ -326,7 +326,7 @@ export default {
const newOrder = this.form.questions.map(question => question.id)
try {
await axios.post(generateOcsUrl('apps/forms/api/v1', 2) + 'question/reorder', {
await axios.post(generateOcsUrl('apps/forms/api/v1.1', 2) + 'question/reorder', {
formId: this.form.id,
newOrder,
})
......
......@@ -192,7 +192,7 @@ export default {
* @returns {string}
*/
downloadUrl() {
return generateOcsUrl('apps/forms/api/v1', 2) + `submissions/export/${this.form.hash}`
return generateOcsUrl('apps/forms/api/v1.1', 2) + `submissions/export/${this.form.hash}`
},
},
......@@ -223,7 +223,7 @@ export default {
console.debug('Loading results for form', this.form.hash)
try {
const response = await axios.get(generateOcsUrl('apps/forms/api/v1', 2) + `submissions/${this.form.hash}`)
const response = await axios.get(generateOcsUrl('apps/forms/api/v1.1', 2) + `submissions/${this.form.hash}`)
// Append questions & submissions
this.$set(this.form, 'submissions', OcsResponse2Data(response).submissions)
......@@ -242,7 +242,7 @@ export default {
picker.pick()
.then(async(path) => {
try {
const response = await axios.post(generateOcsUrl('apps/forms/api/v1', 2) + 'submissions/export', {
const response = await axios.post(generateOcsUrl('apps/forms/api/v1.1', 2) + 'submissions/export', {
hash: this.form.hash,
path,
})
......@@ -258,7 +258,7 @@ export default {
this.loadingResults = true
try {
await axios.delete(generateOcsUrl('apps/forms/api/v1', 2) + `submission/${id}`)
await axios.delete(generateOcsUrl('apps/forms/api/v1.1', 2) + `submission/${id}`)
const index = this.form.submissions.findIndex(search => search.id === id)
this.form.submissions.splice(index, 1)
} catch (error) {
......@@ -276,7 +276,7 @@ export default {
this.loadingResults = true
try {
await axios.delete(generateOcsUrl('apps/forms/api/v1', 2) + `submissions/${this.form.id}`)
await axios.delete(generateOcsUrl('apps/forms/api/v1.1', 2) + `submissions/${this.form.id}`)
this.form.submissions = []
} catch (error) {
console.error(error)
......
......@@ -226,7 +226,7 @@ export default {
this.loading = true
try {
await axios.post(generateOcsUrl('apps/forms/api/v1', 2) + 'submission/insert', {
await axios.post(generateOcsUrl('apps/forms/api/v1.1', 2) + 'submission/insert', {
formId: this.form.id,
answers: this.answers,
})
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment