Changed default ordering of short URLs, returning newest first

This commit is contained in:
Alejandro Celaya 2022-01-05 14:10:24 +01:00
parent d3f4263639
commit 44e3f9b49f
4 changed files with 23 additions and 22 deletions

View file

@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
* [#1277](https://github.com/shlinkio/shlink/issues/1277) Reduced docker image size to 45% the original size. * [#1277](https://github.com/shlinkio/shlink/issues/1277) Reduced docker image size to 45% the original size.
* [#1268](https://github.com/shlinkio/shlink/issues/1268) Updated dependencies, including symfony/console 6 and mezzio/mezzio-swoole 4. * [#1268](https://github.com/shlinkio/shlink/issues/1268) Updated dependencies, including symfony/console 6 and mezzio/mezzio-swoole 4.
* [#1283](https://github.com/shlinkio/shlink/issues/1283) Changed behavior of `DELETE_SHORT_URL_THRESHOLD` env var, disabling the feature if a value was not provided. * [#1283](https://github.com/shlinkio/shlink/issues/1283) Changed behavior of `DELETE_SHORT_URL_THRESHOLD` env var, disabling the feature if a value was not provided.
* [#1300](https://github.com/shlinkio/shlink/issues/1300) Changed default ordering for short URLs list, returning always from newest to oldest.
### Deprecated ### Deprecated
* *Nothing* * *Nothing*

View file

@ -6,8 +6,9 @@
* The `type` property returned when trying to delete a URL that reached the visits threshold, when using the `DELETE /short-urls/{shortCode}` endpoint, is now `INVALID_SHORT_URL_DELETION` instead pf `INVALID_SHORTCODE_DELETION`. * The `type` property returned when trying to delete a URL that reached the visits threshold, when using the `DELETE /short-urls/{shortCode}` endpoint, is now `INVALID_SHORT_URL_DELETION` instead pf `INVALID_SHORTCODE_DELETION`.
* The `INVALID_AUTHORIZATION` error no longer includes the `expectedTypes` property. Use `expectedHeaders` one instead. * The `INVALID_AUTHORIZATION` error no longer includes the `expectedTypes` property. Use `expectedHeaders` one instead.
* The `GET /rest/v2/short-urls` endpoint no longer allows ordering by `visitsCount`, `visitCount` or `originalUrl`. Use `visits` to replace the first two, and `longUrl` to replace the last one. * The `GET /rest/v2/short-urls` endpoint no longer allows ordering by `visitsCount`, `visitCount` or `originalUrl`. Use `visits` instead of the first two, and `longUrl` instead of the last one.
* The `GET /rest/v2/short-urls` endpoint no longer allows providing the ordering params with array notation, as in `/shortUrls?orderBy[longUrl]=DESC`. Instead, use the following notation `/shortUrls?orderBy?longUrl-DESC`. * The `GET /rest/v2/short-urls` endpoint no longer allows providing the ordering params with array notation, as in `/shortUrls?orderBy[longUrl]=DESC`. Instead, use the following notation `/shortUrls?orderBy?longUrl-DESC`.
* The `GET /rest/v2/short-urls` endpoint now has a default ordering of newest-to-oldest. Use `/shortUrls?orderBy=dateCreated-ASC` in order to keep the oldest-to-newest behavior.
* Requests expecting a body no longer support url-encoded payloads. Instead, always use JSON bodies. * Requests expecting a body no longer support url-encoded payloads. Instead, always use JSON bodies.
* The next endpoints have been removed: * The next endpoints have been removed:
* `PUT /rest/v2/short-urls/{shortCode}/tags`: Use the `PATCH /rest/v2/short-urls/{shortCode}` endpoint to set the short URL tags. * `PUT /rest/v2/short-urls/{shortCode}/tags`: Use the `PATCH /rest/v2/short-urls/{shortCode}` endpoint to set the short URL tags.

View file

@ -49,9 +49,8 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU
return $this->processOrderByForList($qb, $orderBy); return $this->processOrderByForList($qb, $orderBy);
} }
// With no order by, order by date and just return the list of ShortUrls // With no explicit order by, fallback to dateCreated-DESC
$qb->orderBy('s.dateCreated'); return $qb->orderBy('s.dateCreated', 'DESC')->getQuery()->getResult();
return $qb->getQuery()->getResult();
} }
private function processOrderByForList(QueryBuilder $qb, ShortUrlsOrdering $orderBy): array private function processOrderByForList(QueryBuilder $qb, ShortUrlsOrdering $orderBy): array

View file

@ -140,12 +140,12 @@ class ListShortUrlsTest extends ApiTestCase
public function provideFilteredLists(): iterable public function provideFilteredLists(): iterable
{ {
yield [[], [ yield [[], [
self::SHORT_URL_CUSTOM_DOMAIN,
self::SHORT_URL_CUSTOM_SLUG,
self::SHORT_URL_META,
self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN,
self::SHORT_URL_SHLINK_WITH_TITLE, self::SHORT_URL_SHLINK_WITH_TITLE,
self::SHORT_URL_DOCS, self::SHORT_URL_DOCS,
self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN,
self::SHORT_URL_META,
self::SHORT_URL_CUSTOM_SLUG,
self::SHORT_URL_CUSTOM_DOMAIN,
], 'valid_api_key']; ], 'valid_api_key'];
yield [['orderBy' => 'shortCode'], [ yield [['orderBy' => 'shortCode'], [
self::SHORT_URL_SHLINK_WITH_TITLE, self::SHORT_URL_SHLINK_WITH_TITLE,
@ -172,48 +172,48 @@ class ListShortUrlsTest extends ApiTestCase
self::SHORT_URL_SHLINK_WITH_TITLE, self::SHORT_URL_SHLINK_WITH_TITLE,
], 'valid_api_key']; ], 'valid_api_key'];
yield [['startDate' => Chronos::parse('2018-12-01')->toAtomString()], [ yield [['startDate' => Chronos::parse('2018-12-01')->toAtomString()], [
self::SHORT_URL_META,
self::SHORT_URL_CUSTOM_SLUG,
self::SHORT_URL_CUSTOM_DOMAIN, self::SHORT_URL_CUSTOM_DOMAIN,
self::SHORT_URL_CUSTOM_SLUG,
self::SHORT_URL_META,
], 'valid_api_key']; ], 'valid_api_key'];
yield [['endDate' => Chronos::parse('2018-12-01')->toAtomString()], [ yield [['endDate' => Chronos::parse('2018-12-01')->toAtomString()], [
self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN,
self::SHORT_URL_SHLINK_WITH_TITLE, self::SHORT_URL_SHLINK_WITH_TITLE,
self::SHORT_URL_DOCS, self::SHORT_URL_DOCS,
self::SHORT_URL_CUSTOM_SLUG_AND_DOMAIN,
], 'valid_api_key']; ], 'valid_api_key'];
yield [['tags' => ['foo']], [ yield [['tags' => ['foo']], [
self::SHORT_URL_SHLINK_WITH_TITLE,
self::SHORT_URL_META,
self::SHORT_URL_CUSTOM_DOMAIN, self::SHORT_URL_CUSTOM_DOMAIN,
self::SHORT_URL_META,
self::SHORT_URL_SHLINK_WITH_TITLE,
], 'valid_api_key']; ], 'valid_api_key'];
yield [['tags' => ['bar']], [ yield [['tags' => ['bar']], [
self::SHORT_URL_META, self::SHORT_URL_META,
], 'valid_api_key']; ], 'valid_api_key'];
yield [['tags' => ['foo', 'bar']], [ yield [['tags' => ['foo', 'bar']], [
self::SHORT_URL_SHLINK_WITH_TITLE,
self::SHORT_URL_META,
self::SHORT_URL_CUSTOM_DOMAIN, self::SHORT_URL_CUSTOM_DOMAIN,
self::SHORT_URL_META,
self::SHORT_URL_SHLINK_WITH_TITLE,
], 'valid_api_key']; ], 'valid_api_key'];
yield [['tags' => ['foo', 'bar'], 'tagsMode' => 'any'], [ yield [['tags' => ['foo', 'bar'], 'tagsMode' => 'any'], [
self::SHORT_URL_SHLINK_WITH_TITLE,
self::SHORT_URL_META,
self::SHORT_URL_CUSTOM_DOMAIN, self::SHORT_URL_CUSTOM_DOMAIN,
self::SHORT_URL_META,
self::SHORT_URL_SHLINK_WITH_TITLE,
], 'valid_api_key']; ], 'valid_api_key'];
yield [['tags' => ['foo', 'bar'], 'tagsMode' => 'all'], [ yield [['tags' => ['foo', 'bar'], 'tagsMode' => 'all'], [
self::SHORT_URL_META, self::SHORT_URL_META,
], 'valid_api_key']; ], 'valid_api_key'];
yield [['tags' => ['foo', 'bar', 'baz']], [ yield [['tags' => ['foo', 'bar', 'baz']], [
self::SHORT_URL_SHLINK_WITH_TITLE,
self::SHORT_URL_META,
self::SHORT_URL_CUSTOM_DOMAIN, self::SHORT_URL_CUSTOM_DOMAIN,
self::SHORT_URL_META,
self::SHORT_URL_SHLINK_WITH_TITLE,
], 'valid_api_key']; ], 'valid_api_key'];
yield [['tags' => ['foo', 'bar', 'baz'], 'tagsMode' => 'all'], [], 'valid_api_key']; yield [['tags' => ['foo', 'bar', 'baz'], 'tagsMode' => 'all'], [], 'valid_api_key'];
yield [['tags' => ['foo'], 'endDate' => Chronos::parse('2018-12-01')->toAtomString()], [ yield [['tags' => ['foo'], 'endDate' => Chronos::parse('2018-12-01')->toAtomString()], [
self::SHORT_URL_SHLINK_WITH_TITLE, self::SHORT_URL_SHLINK_WITH_TITLE,
], 'valid_api_key']; ], 'valid_api_key'];
yield [['searchTerm' => 'alejandro'], [ yield [['searchTerm' => 'alejandro'], [
self::SHORT_URL_META,
self::SHORT_URL_CUSTOM_DOMAIN, self::SHORT_URL_CUSTOM_DOMAIN,
self::SHORT_URL_META,
], 'valid_api_key']; ], 'valid_api_key'];
yield [['searchTerm' => 'cool'], [ yield [['searchTerm' => 'cool'], [
self::SHORT_URL_SHLINK_WITH_TITLE, self::SHORT_URL_SHLINK_WITH_TITLE,
@ -222,9 +222,9 @@ class ListShortUrlsTest extends ApiTestCase
self::SHORT_URL_CUSTOM_DOMAIN, self::SHORT_URL_CUSTOM_DOMAIN,
], 'valid_api_key']; ], 'valid_api_key'];
yield [[], [ yield [[], [
self::SHORT_URL_SHLINK_WITH_TITLE,
self::SHORT_URL_META,
self::SHORT_URL_CUSTOM_SLUG, self::SHORT_URL_CUSTOM_SLUG,
self::SHORT_URL_META,
self::SHORT_URL_SHLINK_WITH_TITLE,
], 'author_api_key']; ], 'author_api_key'];
yield [[], [ yield [[], [
self::SHORT_URL_CUSTOM_DOMAIN, self::SHORT_URL_CUSTOM_DOMAIN,