Skip to content

Commit e7f2eb8

Browse files
committed
Add library's tracks cumulative search on artist, album and track title
1 parent 19f40a6 commit e7f2eb8

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

API.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,14 @@ Notes:
169169

170170
#### Get all tracks from the library
171171
````
172-
GET /server/api/library/tracks
172+
GET /server/api/library/tracks[?trackTitle=:title|artistName=:artist|albumName=:album|search=:anything]
173173
````
174+
Following search criteria should be added in query string:
175+
- `trackTitle`,
176+
- `artistName`,
177+
- `albumName`,
178+
- `search` (cumulative search on track title, artist and album).
179+
174180
The API returns:
175181
- 200 with an array of tracks,
176182
- 204 if there is no track in library,

server/api/library.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Provides the list of all the tracks included in the library
77
*
8-
* @version 1.0.0
8+
* @version 1.1.0
99
*
1010
* @api
1111
*/
@@ -38,6 +38,7 @@
3838
$api->checkParameterExists('title', $parameter['trackTitle']);
3939
$api->checkParameterExists('artist', $parameter['artistName']);
4040
$api->checkParameterExists('album', $parameter['albumName']);
41+
$api->checkParameterExists('search', $parameter['search']);
4142
//querying the library
4243
if (!$library->populateTracks($parameter)) {
4344
$api->output(500, 'Querying error');

server/lib/Track.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public function getBase64()
339339
*
340340
* This is a set of tracks (library, search, ...)
341341
*
342-
* @version 1.0.0
342+
* @version 1.1.0
343343
*
344344
* @internal
345345
*/
@@ -387,6 +387,9 @@ public function populateTracks($parameters)
387387
case 'albumName':
388388
$sqlCondition .= ' AND `album`.`name` LIKE :albumName';
389389
break;
390+
case 'search':
391+
$sqlCondition .= ' AND (`track`.`title` LIKE :trackTitle OR `artist`.`name` LIKE :artistName OR `album`.`name` LIKE :albumName)';
392+
break;
390393
}
391394
}
392395
}
@@ -405,6 +408,11 @@ public function populateTracks($parameters)
405408
case 'albumName':
406409
$query->bindValue(':albumName', "%$value%", PDO::PARAM_STR);
407410
break;
411+
case 'search':
412+
$query->bindValue(':trackTitle', "%$value%", PDO::PARAM_STR);
413+
$query->bindValue(':artistName', "%$value%", PDO::PARAM_STR);
414+
$query->bindValue(':albumName', "%$value%", PDO::PARAM_STR);
415+
break;
408416
}
409417
}
410418
}

0 commit comments

Comments
 (0)