Merge rPF47b172ccc49d: T366: Explicitly return ints and boolean values as such in the website API.

This commit is contained in:
Kelvin Zhang 2015-09-10 12:41:35 +01:00
parent 5a2fb2f05e
commit 05f1745b1f
4 changed files with 38 additions and 38 deletions

View file

@ -126,24 +126,24 @@ class Album extends Model
$userRow = $album->users[0]; $userRow = $album->users[0];
$userData = [ $userData = [
'stats' => [ 'stats' => [
'views' => $userRow->view_count, 'views' => (int) $userRow->view_count,
'downloads' => $userRow->download_count, 'downloads' => (int) $userRow->download_count,
], ],
'is_favourited' => $userRow->is_favourited 'is_favourited' => (bool) $userRow->is_favourited
]; ];
} }
return [ return [
'id' => $album->id, 'id' => (int) $album->id,
'track_count' => $album->track_count, 'track_count' => (int) $album->track_count,
'title' => $album->title, 'title' => $album->title,
'slug' => $album->slug, 'slug' => $album->slug,
'created_at' => $album->created_at, 'created_at' => $album->created_at,
'stats' => [ 'stats' => [
'views' => $album->view_count, 'views' => (int) $album->view_count,
'downloads' => $album->download_count, 'downloads' => (int) $album->download_count,
'comments' => $album->comment_count, 'comments' => (int) $album->comment_count,
'favourites' => $album->favourite_count 'favourites' => (int) $album->favourite_count
], ],
'covers' => [ 'covers' => [
'small' => $album->getCoverUrl(Image::SMALL), 'small' => $album->getCoverUrl(Image::SMALL),
@ -151,7 +151,7 @@ class Album extends Model
], ],
'url' => $album->url, 'url' => $album->url,
'user' => [ 'user' => [
'id' => $album->user->id, 'id' => (int) $album->user->id,
'name' => $album->user->display_name, 'name' => $album->user->display_name,
'url' => $album->user->url, 'url' => $album->user->url,
], ],

View file

@ -133,16 +133,16 @@ class ArtistsController extends ApiControllerBase
if ($user->users->count()) { if ($user->users->count()) {
$userRow = $user->users[0]; $userRow = $user->users[0];
$userData = [ $userData = [
'is_following' => $userRow->is_followed 'is_following' => (bool)$userRow->is_followed
]; ];
} }
return Response::json([ return Response::json([
'artist' => [ 'artist' => [
'id' => $user->id, 'id' => (int)$user->id,
'name' => $user->display_name, 'name' => $user->display_name,
'slug' => $user->slug, 'slug' => $user->slug,
'is_archived' => $user->is_archived, 'is_archived' => (bool)$user->is_archived,
'avatars' => [ 'avatars' => [
'small' => $user->getAvatarUrl(Image::SMALL), 'small' => $user->getAvatarUrl(Image::SMALL),
'normal' => $user->getAvatarUrl(Image::NORMAL) 'normal' => $user->getAvatarUrl(Image::NORMAL)

View file

@ -86,25 +86,25 @@ class Playlist extends Model
$userRow = $playlist->users[0]; $userRow = $playlist->users[0];
$userData = [ $userData = [
'stats' => [ 'stats' => [
'views' => $userRow->view_count, 'views' => (int) $userRow->view_count,
'downloads' => $userRow->download_count, 'downloads' => (int) $userRow->download_count,
], ],
'is_favourited' => $userRow->is_favourited 'is_favourited' => (bool) $userRow->is_favourited
]; ];
} }
return [ return [
'id' => $playlist->id, 'id' => (int) $playlist->id,
'track_count' => $playlist->track_count, 'track_count' => $playlist->track_count,
'title' => $playlist->title, 'title' => $playlist->title,
'slug' => $playlist->slug, 'slug' => $playlist->slug,
'created_at' => $playlist->created_at, 'created_at' => $playlist->created_at,
'is_public' => $playlist->is_public, 'is_public' => (bool) $playlist->is_public,
'stats' => [ 'stats' => [
'views' => $playlist->view_count, 'views' => (int) $playlist->view_count,
'downloads' => $playlist->download_count, 'downloads' => (int) $playlist->download_count,
'comments' => $playlist->comment_count, 'comments' => (int) $playlist->comment_count,
'favourites' => $playlist->favourite_count 'favourites' => (int) $playlist->favourite_count
], ],
'covers' => [ 'covers' => [
'small' => $playlist->getCoverUrl(Image::SMALL), 'small' => $playlist->getCoverUrl(Image::SMALL),
@ -112,7 +112,7 @@ class Playlist extends Model
], ],
'url' => $playlist->url, 'url' => $playlist->url,
'user' => [ 'user' => [
'id' => $playlist->user->id, 'id' => (int) $playlist->user->id,
'name' => $playlist->user->display_name, 'name' => $playlist->user->display_name,
'url' => $playlist->user->url, 'url' => $playlist->user->url,
], ],

View file

@ -229,41 +229,41 @@ class Track extends Model
$userRow = $track->users[0]; $userRow = $track->users[0];
$userData = [ $userData = [
'stats' => [ 'stats' => [
'views' => $userRow->view_count, 'views' => (int) $userRow->view_count,
'plays' => $userRow->play_count, 'plays' => (int) $userRow->play_count,
'downloads' => $userRow->download_count, 'downloads' => $userRow->download_count,
], ],
'is_favourited' => $userRow->is_favourited 'is_favourited' => (bool) $userRow->is_favourited
]; ];
} }
return [ return [
'id' => $track->id, 'id' => (int) $track->id,
'title' => $track->title, 'title' => $track->title,
'user' => [ 'user' => [
'id' => $track->user->id, 'id' => (int) $track->user->id,
'name' => $track->user->display_name, 'name' => $track->user->display_name,
'url' => $track->user->url 'url' => $track->user->url
], ],
'stats' => [ 'stats' => [
'views' => $track->view_count, 'views' => (int) $track->view_count,
'plays' => $track->play_count, 'plays' => (int) $track->play_count,
'downloads' => $track->download_count, 'downloads' => (int) $track->download_count,
'comments' => $track->comment_count, 'comments' => (int) $track->comment_count,
'favourites' => $track->favourite_count 'favourites' => (int) $track->favourite_count
], ],
'url' => $track->url, 'url' => $track->url,
'slug' => $track->slug, 'slug' => $track->slug,
'is_vocal' => $track->is_vocal, 'is_vocal' => (bool) $track->is_vocal,
'is_explicit' => $track->is_explicit, 'is_explicit' => (bool) $track->is_explicit,
'is_downloadable' => $track->is_downloadable, 'is_downloadable' => (bool) $track->is_downloadable,
'is_published' => $track->isPublished(), 'is_published' => (bool) $track->isPublished(),
'published_at' => $track->published_at, 'published_at' => $track->published_at,
'duration' => $track->duration, 'duration' => $track->duration,
'genre' => $track->genre != null 'genre' => $track->genre != null
? ?
[ [
'id' => $track->genre->id, 'id' => (int) $track->genre->id,
'slug' => $track->genre->slug, 'slug' => $track->genre->slug,
'name' => $track->genre->name 'name' => $track->genre->name
] : null, ] : null,