mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Updated API docs including new response structure
This commit is contained in:
parent
563021bdc1
commit
5d6d13c95f
@ -5,7 +5,11 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The short code for this short URL."
|
"description": "The short code for this short URL."
|
||||||
},
|
},
|
||||||
"originalUrl": {
|
"shortUrl": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The short URL."
|
||||||
|
},
|
||||||
|
"longUrl": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The original long URL."
|
"description": "The original long URL."
|
||||||
},
|
},
|
||||||
@ -24,6 +28,11 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"description": "A list of tags applied to this short URL"
|
"description": "A list of tags applied to this short URL"
|
||||||
|
},
|
||||||
|
"originalUrl": {
|
||||||
|
"deprecated": true,
|
||||||
|
"type": "string",
|
||||||
|
"description": "The original long URL. [DEPRECATED. Use longUrl instead]"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
"schema": {
|
"schema": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
"originalUrl",
|
"longUrl",
|
||||||
"shortCode",
|
"shortCode",
|
||||||
"dateCreated",
|
"dateCreated",
|
||||||
"visits"
|
"visits"
|
||||||
@ -89,7 +89,8 @@
|
|||||||
"data": [
|
"data": [
|
||||||
{
|
{
|
||||||
"shortCode": "12C18",
|
"shortCode": "12C18",
|
||||||
"originalUrl": "https://store.steampowered.com",
|
"shortUrl": "https://doma.in/12C18",
|
||||||
|
"longUrl": "https://store.steampowered.com",
|
||||||
"dateCreated": "2016-08-21T20:34:16+02:00",
|
"dateCreated": "2016-08-21T20:34:16+02:00",
|
||||||
"visitsCount": 328,
|
"visitsCount": 328,
|
||||||
"tags": [
|
"tags": [
|
||||||
@ -99,7 +100,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"shortCode": "12Kb3",
|
"shortCode": "12Kb3",
|
||||||
"originalUrl": "https://shlink.io",
|
"shortUrl": "https://doma.in/12Kb3",
|
||||||
|
"longUrl": "https://shlink.io",
|
||||||
"dateCreated": "2016-05-01T20:34:16+02:00",
|
"dateCreated": "2016-05-01T20:34:16+02:00",
|
||||||
"visitsCount": 1029,
|
"visitsCount": 1029,
|
||||||
"tags": [
|
"tags": [
|
||||||
@ -108,7 +110,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"shortCode": "123bA",
|
"shortCode": "123bA",
|
||||||
"originalUrl": "https://www.google.com",
|
"shortUrl": "https://doma.in/123bA",
|
||||||
|
"longUrl": "https://www.google.com",
|
||||||
"dateCreated": "2015-10-01T20:34:16+02:00",
|
"dateCreated": "2015-10-01T20:34:16+02:00",
|
||||||
"visitsCount": 25,
|
"visitsCount": 25,
|
||||||
"tags": []
|
"tags": []
|
||||||
|
@ -23,23 +23,24 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "The long URL behind a short code.",
|
"description": "The URL info behind a short code.",
|
||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"$ref": "../definitions/ShortUrl.json"
|
||||||
"properties": {
|
|
||||||
"longUrl": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The original long URL behind the short code."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"examples": {
|
"examples": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"longUrl": "https://shlink.io"
|
"shortCode": "12Kb3",
|
||||||
|
"shortUrl": "https://doma.in/12Kb3",
|
||||||
|
"longUrl": "https://shlink.io",
|
||||||
|
"dateCreated": "2016-05-01T20:34:16+02:00",
|
||||||
|
"visitsCount": 1029,
|
||||||
|
"tags": [
|
||||||
|
"shlink"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -47,6 +47,13 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI
|
|||||||
|
|
||||||
protected function processOrderByForList(QueryBuilder $qb, $orderBy)
|
protected function processOrderByForList(QueryBuilder $qb, $orderBy)
|
||||||
{
|
{
|
||||||
|
// Map public field names to column names
|
||||||
|
$fieldNameMap = [
|
||||||
|
'originalUrl' => 'originalUrl',
|
||||||
|
'longUrl' => 'originalUrl',
|
||||||
|
'shortCode' => 'shortCode',
|
||||||
|
'dateCreated' => 'dateCreated',
|
||||||
|
];
|
||||||
$fieldName = \is_array($orderBy) ? \key($orderBy) : $orderBy;
|
$fieldName = \is_array($orderBy) ? \key($orderBy) : $orderBy;
|
||||||
$order = \is_array($orderBy) ? $orderBy[$fieldName] : 'ASC';
|
$order = \is_array($orderBy) ? $orderBy[$fieldName] : 'ASC';
|
||||||
|
|
||||||
@ -59,8 +66,8 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI
|
|||||||
return \array_column($qb->getQuery()->getResult(), 0);
|
return \array_column($qb->getQuery()->getResult(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\in_array($fieldName, ['originalUrl', 'shortCode', 'dateCreated'], true)) {
|
if (\array_key_exists($fieldName, $fieldNameMap)) {
|
||||||
$qb->orderBy('s.' . $fieldName, $order);
|
$qb->orderBy('s.' . $fieldNameMap[$fieldName], $order);
|
||||||
}
|
}
|
||||||
return $qb->getQuery()->getResult();
|
return $qb->getQuery()->getResult();
|
||||||
}
|
}
|
||||||
|
@ -112,4 +112,28 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
|||||||
$this->assertCount(1, $result);
|
$this->assertCount(1, $result);
|
||||||
$this->assertSame($foo, $result[0]);
|
$this->assertSame($foo, $result[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function findListProperlyMapsFieldNamesToColumnNamesWhenOrdering()
|
||||||
|
{
|
||||||
|
$urls = ['a', 'z', 'c', 'b'];
|
||||||
|
foreach($urls as $url) {
|
||||||
|
$this->getEntityManager()->persist(
|
||||||
|
(new ShortUrl())->setShortCode($url)
|
||||||
|
->setLongUrl($url)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->getEntityManager()->flush();
|
||||||
|
|
||||||
|
$result = $this->repo->findList(null, null, null, [], ['longUrl' => 'ASC']);
|
||||||
|
|
||||||
|
$this->assertCount(\count($urls), $result);
|
||||||
|
$this->assertEquals('a', $result[0]->getLongUrl());
|
||||||
|
$this->assertEquals('b', $result[1]->getLongUrl());
|
||||||
|
$this->assertEquals('c', $result[2]->getLongUrl());
|
||||||
|
$this->assertEquals('z', $result[3]->getLongUrl());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user