* scoped to the page which the comment is on. The 'parent_id' is used for replies
* and refers to the 'local_id' of the parent comment on the same page, not the main
* globally unique 'id'.
+ *
+ * If you want to get all comments for a page in a tree-like structure, as reflected in
+ * the UI, then that is provided on pages-read API responses.
*/
class CommentApiController extends ApiController
{
- // TODO - Add tree-style comment listing to page-show responses.
-
- // TODO - Test visibility controls
- // TODO - Test permissions of each action
-
protected array $rules = [
'create' => [
'page_id' => ['required', 'integer'],
'content_ref' => ['string'],
],
'update' => [
- 'html' => ['required', 'string'],
+ 'html' => ['string'],
'archived' => ['boolean'],
]
];
public function read(string $id): JsonResponse
{
$comment = $this->commentRepo->getVisibleById(intval($id));
+ $comment->load('createdBy', 'updatedBy');
$replies = $this->commentRepo->getQueryForVisible()
->where('parent_id', '=', $comment->local_id)
$this->checkOwnablePermission(Permission::CommentUpdate, $comment);
$input = $this->validate($request, $this->rules()['update']);
+ $hasHtml = isset($input['html']);
if (isset($input['archived'])) {
- $archived = $input['archived'];
- if ($archived) {
- $this->commentRepo->archive($comment, false);
+ if ($input['archived']) {
+ $this->commentRepo->archive($comment, !$hasHtml);
} else {
- $this->commentRepo->unarchive($comment, false);
+ $this->commentRepo->unarchive($comment, !$hasHtml);
}
}
- $comment = $this->commentRepo->update($comment, $input['html']);
+ if ($hasHtml) {
+ $comment = $this->commentRepo->update($comment, $input['html']);
+ }
return response()->json($comment);
}