From 7e73aff3587be7c7a4645a76fc2213558f3495e2 Mon Sep 17 00:00:00 2001 From: Nico Di Rocco Date: Thu, 29 Oct 2015 20:35:53 +0100 Subject: [PATCH] Support new lookup type `__day` to filter by day. --- src/RestApi/RestApi.php | 8 ++++++++ src/RestApi/Tests/RestApiTest.php | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/RestApi/RestApi.php b/src/RestApi/RestApi.php index fe646e8..bdacecd 100644 --- a/src/RestApi/RestApi.php +++ b/src/RestApi/RestApi.php @@ -20,6 +20,7 @@ class RestApi 'contains' => 'LIKE', 'icontains' => 'LIKE', //TODO: on postgres this is ilike + 'day' => '=', 'month' => '=', 'year' => '=', ]; @@ -525,6 +526,13 @@ public function addWhere($key, $value) return "date_part('month', {$column}) = {$this->database->quote($value)}"; } throw new \RuntimeException("Unsupported platform {$platform}"); + } elseif ('day' === $lookupType) { + if ('sqlite' === $platform) { + return "strftime('%d', {$column}) = {$this->database->quote($value)}"; + } elseif ('postgresql' === $platform) { + return "date_part('day', {$column}) = {$this->database->quote($value)}"; + } + throw new \RuntimeException("Unsupported platform {$platform}"); } if ('postgresql' === $platform) { diff --git a/src/RestApi/Tests/RestApiTest.php b/src/RestApi/Tests/RestApiTest.php index 77d1164..cf2fecb 100644 --- a/src/RestApi/Tests/RestApiTest.php +++ b/src/RestApi/Tests/RestApiTest.php @@ -120,7 +120,12 @@ public function testReadCollectionFilter() { $api = $this->getApiWithDataLoaded(); - $todos = $api->readCollection('todos', ['file__notnull' => 'yes', 'created__year' => 2014, 'updated__month' => 6]); + $todos = $api->readCollection('todos', [ + 'file__notnull' => 'yes', + 'created__year' => 2014, + 'updated__month' => 6, + 'updated__day' => 1 + ]); $this->assertEquals(200, $todos['code']); $this->assertEquals(0, $todos['headers']['X-Pagination-Total']); $this->assertEmpty($todos['body']);