Commit b227dfc3 authored by Matthias Larisch's avatar Matthias Larisch

API changes

parent 937ff0ac
......@@ -2,9 +2,9 @@ CREATE TABLE `fs_reaction` (
`target` VARCHAR(63) NOT NULL,
`time` DATETIME NOT NULL,
`foodsaver_id` INT NOT NULL,
`emoji` VARCHAR(63),
`key` VARCHAR(63),
INDEX (`target`),
UNIQUE KEY `target-foodsaver-emoji` (`target`, `foodsaver_id`, `emoji`)
UNIQUE KEY `target-foodsaver-key` (`target`, `foodsaver_id`, `key`)
)
ENGINE = InnoDB;
......@@ -32,8 +32,8 @@ class ForumRestController extends FOSRestController
'id' => $thread['id'],
'name' => $thread['name'],
'createdAt' => $thread['time'],
'sticky' => $thread['sticky'],
'active' => $thread['active'] ?? 1,
'isSticky' => (bool)$thread['sticky'],
'isActive' => (bool)$thread['active'] ?? true,
'lastPost' => [
'id' => $thread['last_post_id'],
],
......@@ -73,7 +73,7 @@ class ForumRestController extends FOSRestController
'id' => $post['author_id'],
'name' => $post['author_name'],
'avatar' => '/images/130_q_' . $post['author_photo'],
'sleep_status' => $post['author_sleep_status']
'sleepStatus' => $post['author_sleep_status']
],
'reactions' => $reactions[$post['id']] ?? []
];
......@@ -115,6 +115,8 @@ class ForumRestController extends FOSRestController
$reactions = $this->forumService->getReactionsForThread($threadId);
$thread = $this->normalizeThread($thread);
$thread['isFollowing'] = $this->forumGateway->isFollowing($this->session->id(), $threadId);
$thread['mayModerate'] = $this->forumPermissions->mayModerate($threadId);
$thread['posts'] = array_map(function ($post) use ($reactions) { return $this->normalizePost($post, $reactions); }, $posts);
$view = $this->view([
......@@ -131,7 +133,7 @@ class ForumRestController extends FOSRestController
*/
public function patchThreadAction($threadId, ParamFetcher $paramFetcher)
{
if (!$this->forumPermissions->mayAdministrateThread($threadId)) {
if (!$this->forumPermissions->mayModerate($threadId)) {
throw new HttpException(403);
}
$sticky = $paramFetcher->get('sticky');
......
......@@ -22,7 +22,7 @@ class ReactionGateway extends BaseGateway
$q = '
SELECT
r.target,
r.emoji,
r.`key`,
r.time,
r.foodsaver_id,
fs.name as foodsaver_name
......@@ -48,14 +48,14 @@ class ReactionGateway extends BaseGateway
return $res;
}
public function addReaction($target, $fsId, $emoji): bool
public function addReaction($target, $fsId, $key): bool
{
$this->db->insert(
'fs_reaction',
[
'target' => $target,
'foodsaver_id' => $fsId,
'emoji' => $emoji,
'key' => $key,
'time' => $this->db->now()
]
);
......@@ -63,14 +63,14 @@ class ReactionGateway extends BaseGateway
return true;
}
public function removeReaction($target, $fsId, $emoji)
public function removeReaction($target, $fsId, $key)
{
$this->db->delete(
'fs_reaction',
[
'target' => $target,
'foodsaver_id' => $fsId,
'emoji' => $emoji
'key' => $key
]
);
}
......
......@@ -59,7 +59,7 @@ class ForumPermissions
return false;
}
public function mayAdministrateThread($threadId): bool
public function mayModerate($threadId): bool
{
if ($this->session->isOrgaTeam()) {
return true;
......
......@@ -291,20 +291,20 @@ class ForumService
return $target;
}
public function addReaction($fsId, $threadId, $postId, $emoji)
public function addReaction($fsId, $threadId, $postId, $key)
{
if (!$fsId || !$threadId || !$postId || !$emoji) {
if (!$fsId || !$threadId || !$postId || !$key) {
throw new \InvalidArgumentException();
}
$this->reactionGateway->addReaction($this->getReactionTarget($threadId, $postId), $fsId, $emoji);
$this->reactionGateway->addReaction($this->getReactionTarget($threadId, $postId), $fsId, $key);
}
public function removeReaction($fsId, $threadId, $postId, $emoji)
public function removeReaction($fsId, $threadId, $postId, $key)
{
if (!$fsId || !$threadId || !$postId || !$emoji) {
if (!$fsId || !$threadId || !$postId || !$key) {
throw new \InvalidArgumentException();
}
$this->reactionGateway->removeReaction($this->getReactionTarget($threadId, $postId), $fsId, $emoji);
$this->reactionGateway->removeReaction($this->getReactionTarget($threadId, $postId), $fsId, $key);
}
public function getReactionsForThread($threadId)
......@@ -321,7 +321,7 @@ class ForumService
}
if (!isset($reactions[$postId])) {
$reactions[$postId] = [
'emoji' => $r['emoji'],
'key' => $r['key'],
'users' => []
];
}
......
Markdown is supported
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