Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mh-Asmi committed Sep 10, 2024
1 parent c40b7c2 commit 8060251
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Ushahidi/Modules/V5/Http/Controllers/MessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ public function update(int $id, MessageRequest $request)
return $this->show($id);
}// end update

private function getPost(int $id, ?array $fields = null, ?array $haydrates = null)
{
if (!$fields) {
$fields = Post::ALLOWED_FIELDS;
}
if (!$haydrates) {
$haydrates = array_keys(Post::ALLOWED_RELATIONSHIPS);
}
$find_post_query = new FindPostByIdQuery($id);
$find_post_query->addOnlyValues(
$fields,
$haydrates,
Post::ALLOWED_RELATIONSHIPS,
Post::REQUIRED_FIELDS
);
return $this->queryBus->handle($find_post_query);
}

/**
* Display the specified resource.
*
Expand All @@ -99,7 +117,7 @@ public function showPost(int $id)
$message = $this->queryBus->handle(new FetchMessageByIdQuery($id));
$this->authorize('show', $message);
if ($message->post_id) {
$post = $this->queryBus->handle(new FindPostByIdQuery($message->post_id, Post::ALLOWED_FIELDS));
$post = $this->getPost($message->post_id);
return new postResource($post);
}
throw new NotFoundException("Post does not exist for this message");
Expand Down

0 comments on commit 8060251

Please sign in to comment.