From be71a6eeb41eef54c4332945f20cece18feaf5f5 Mon Sep 17 00:00:00 2001
From: Alejandro Celaya <alejandro@alejandrocelaya.com>
Date: Mon, 21 Sep 2020 22:03:43 +0200
Subject: [PATCH] Replaced colon by hyphen as the ordering field-dir separator
 as it's a valid URL character

---
 docs/swagger/paths/v1_short-urls.json             | 14 +++++++++-----
 module/Core/src/Model/ShortUrlsOrdering.php       |  2 +-
 module/Rest/test-api/Action/ListShortUrlsTest.php |  4 ++--
 3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/docs/swagger/paths/v1_short-urls.json b/docs/swagger/paths/v1_short-urls.json
index ee8a6060..2467de24 100644
--- a/docs/swagger/paths/v1_short-urls.json
+++ b/docs/swagger/paths/v1_short-urls.json
@@ -31,7 +31,7 @@
             {
                 "name": "tags[]",
                 "in": "query",
-                "description": "A list of tags used to filter the resultset. Only short URLs tagged with at least one of the provided tags will be returned. (Since v1.3.0)",
+                "description": "A list of tags used to filter the result set. Only short URLs tagged with at least one of the provided tags will be returned. (Since v1.3.0)",
                 "required": false,
                 "schema": {
                     "type": "array",
@@ -48,10 +48,14 @@
                 "schema": {
                     "type": "string",
                     "enum": [
-                        "longUrl",
-                        "shortCode",
-                        "dateCreated",
-                        "visits"
+                        "longUrl-ASC",
+                        "longUrl-DESC",
+                        "shortCode-ASC",
+                        "shortCode-DESC",
+                        "dateCreated-ASC",
+                        "dateCreated-DESC",
+                        "visits-ASC",
+                        "visits-DESC"
                     ]
                 }
             },
diff --git a/module/Core/src/Model/ShortUrlsOrdering.php b/module/Core/src/Model/ShortUrlsOrdering.php
index 3f1dbd88..25c7c940 100644
--- a/module/Core/src/Model/ShortUrlsOrdering.php
+++ b/module/Core/src/Model/ShortUrlsOrdering.php
@@ -50,7 +50,7 @@ final class ShortUrlsOrdering
         }
 
         if (! $isArray) {
-            $parts = explode(':', $orderBy);
+            $parts = explode('-', $orderBy);
             $this->orderField = $parts[0];
             $this->orderDirection = $parts[1] ?? self::DEFAULT_ORDER_DIRECTION;
         } else {
diff --git a/module/Rest/test-api/Action/ListShortUrlsTest.php b/module/Rest/test-api/Action/ListShortUrlsTest.php
index 32d87bdf..d59c488d 100644
--- a/module/Rest/test-api/Action/ListShortUrlsTest.php
+++ b/module/Rest/test-api/Action/ListShortUrlsTest.php
@@ -137,7 +137,7 @@ class ListShortUrlsTest extends ApiTestCase
             self::SHORT_URL_DOCS,
             self::SHORT_URL_CUSTOM_DOMAIN,
         ]];
-        yield [['orderBy' => ['shortCode' => 'DESC']], [
+        yield [['orderBy' => ['shortCode' => 'DESC']], [ // Deprecated
             self::SHORT_URL_DOCS,
             self::SHORT_URL_CUSTOM_DOMAIN,
             self::SHORT_URL_META,
@@ -145,7 +145,7 @@ class ListShortUrlsTest extends ApiTestCase
             self::SHORT_URL_CUSTOM_SLUG,
             self::SHORT_URL_SHLINK,
         ]];
-        yield [['orderBy' => 'shortCode:DESC'], [
+        yield [['orderBy' => 'shortCode-DESC'], [
             self::SHORT_URL_DOCS,
             self::SHORT_URL_CUSTOM_DOMAIN,
             self::SHORT_URL_META,