Skip to content

Commit

Permalink
refactor lastUpdated for Questions
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
  • Loading branch information
Chartman123 committed Sep 9, 2024
1 parent 1526824 commit ba2440d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
15 changes: 0 additions & 15 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,6 @@ public function newQuestion(int $formId, ?string $type = null, string $text = ''
}
}

$this->formMapper->update($form);

return new DataResponse($response);
}

Expand Down Expand Up @@ -573,7 +571,6 @@ public function updateQuestion(int $formId, int $questionId, array $keyValuePair
$question->setId($questionId);

// Update changed Columns in Db.
$this->formMapper->update($form);
$this->questionMapper->update($question);

return new DataResponse($question->getId());
Expand Down Expand Up @@ -630,8 +627,6 @@ public function deleteQuestion(int $formId, int $questionId): DataResponse {
}
}

$this->formMapper->update($form);

return new DataResponse($questionId);
}

Expand Down Expand Up @@ -719,8 +714,6 @@ public function reorderQuestions(int $formId, array $newOrder): DataResponse {
];
}

$this->formMapper->update($form);

return new DataResponse($response);
}

Expand Down Expand Up @@ -1676,8 +1669,6 @@ public function newQuestionLegacy(int $formId, string $type, string $text = ''):
$response['options'] = [];
$response['accept'] = [];

$this->formMapper->update($form);

return new DataResponse($response);
}

Expand Down Expand Up @@ -1765,8 +1756,6 @@ public function reorderQuestionsLegacy(int $formId, array $newOrder): DataRespon
];
}

$this->formMapper->update($form);

return new DataResponse($response);
}

Expand Down Expand Up @@ -1831,8 +1820,6 @@ public function updateQuestionLegacy(int $id, array $keyValuePairs): DataRespons
// Update changed Columns in Db.
$this->questionMapper->update($question);

$this->formMapper->update($form);

return new DataResponse($question->getId());
}

Expand Down Expand Up @@ -1883,8 +1870,6 @@ public function deleteQuestionLegacy(int $id): DataResponse {
}
}

$this->formMapper->update($form);

return new DataResponse($id);
}

Expand Down
25 changes: 24 additions & 1 deletion lib/Db/QuestionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace OCA\Forms\Db;

use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
Expand All @@ -37,17 +38,39 @@
class QuestionMapper extends QBMapper {
public function __construct(
IDBConnection $db,
private FormMapper $formMapper,
private OptionMapper $optionMapper
) {
parent::__construct($db, 'forms_v2_questions', Question::class);
}

/**
* @param Entity $entity
* @psalm-param Question $entity
* @return Question
* @throws \OCP\DB\Exception
*/
public function insert(Entity $entity): Question {
$this->formMapper->update($this->formMapper->findById($entity->getFormId()));
return parent::insert($entity);
}

/**
* @param Entity $entity
* @psalm-param Question $entity
* @return Question
* @throws \OCP\DB\Exception
*/
public function update(Entity $entity): Question {
$this->formMapper->update($this->formMapper->findById($entity->getFormId()));
return parent::update($entity);
}

/**
* @param int $formId
* @throws DoesNotExistException if not found
* @return Question[]
*/

public function findByForm(int $formId, bool $loadDeleted = false): array {
$qb = $this->db->getQueryBuilder();

Expand Down

0 comments on commit ba2440d

Please sign in to comment.