diff --git a/packages/slimkit-plus-feed/src/API2/CommentPinnedController.php b/packages/slimkit-plus-feed/src/API2/CommentPinnedController.php index 038402755..8648743f0 100755 --- a/packages/slimkit-plus-feed/src/API2/CommentPinnedController.php +++ b/packages/slimkit-plus-feed/src/API2/CommentPinnedController.php @@ -47,18 +47,21 @@ public function index(Request $request, FeedPinnedModel $model, FeedRepository $ $limit = $request->query('limit', 15); $after = $request->query('after'); + $grammar = $model->getConnection()->getQueryGrammar(); $pinneds = $model->with('comment') ->where('channel', 'comment') ->where('target_user', $user->id) ->when(boolval($after), function ($query) use ($after) { return $query->where('id', '<', $after); }) - ->orderByRaw( + ->orderByRaw(str_replace( + '{expires_at}', + $grammar->wrap('expires_at'), 'CASE - WHEN isnull(`expires_at`) THEN 1 - WHEN (`expires_at` is not null ) THEN 2 + WHEN isnull({expires_at}) THEN 1 + WHEN ({expires_at} is not null ) THEN 2 END ASC' - ) + )) ->orderBy('created_at', 'desc') ->limit($limit) ->get(); diff --git a/packages/slimkit-plus-news/src/API2/Controllers/CommentPinnedController.php b/packages/slimkit-plus-news/src/API2/Controllers/CommentPinnedController.php index f5c93c118..d5aeabcef 100644 --- a/packages/slimkit-plus-news/src/API2/Controllers/CommentPinnedController.php +++ b/packages/slimkit-plus-news/src/API2/Controllers/CommentPinnedController.php @@ -46,18 +46,19 @@ public function index(Request $request, NewsPinnedModel $model) $limit = $request->query('limit', 15); $after = $request->query('after'); + $grammar = $model->getConnection()->getQueryGrammar(); $pinneds = $model->with('comment') ->where('channel', 'news:comment') ->where('target_user', $user->id) ->when(boolval($after), function ($query) use ($after) { return $query->where('id', '<', $after); }) - ->orderByRaw(' + ->orderByRaw(str_replace('{state}', $grammar->wrap('state'), ' CASE - WHEN (`state` = 0) THEN 1 - WHEN (`state` <> 0 ) THEN 2 + WHEN ({state} = 0) THEN 1 + WHEN ({state} != 0 ) THEN 2 END ASC - ') + ')) ->orderBy('created_at', 'desc') ->orderBy('id', 'desc') ->limit($limit) diff --git a/packages/slimkit-plus-news/tests/Feature/API2/PinnedNewsTest.php b/packages/slimkit-plus-news/tests/Feature/API2/PinnedNewsTest.php index eef26be74..82debbf87 100644 --- a/packages/slimkit-plus-news/tests/Feature/API2/PinnedNewsTest.php +++ b/packages/slimkit-plus-news/tests/Feature/API2/PinnedNewsTest.php @@ -120,10 +120,8 @@ public function testGetNewsCommentPinneds() $response = $this ->actingAs($this->user, 'api') ->json('GET', '/api/v2/news/comments/pinneds'); - dd($response); $response - ->assertStatus(200) - ->assertJsonStructure([]); + ->assertStatus(200); } /**