2013-07-25 23:33:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Api\Web;
|
|
|
|
|
|
|
|
use Commands\DeleteTrackCommand;
|
|
|
|
use Commands\EditTrackCommand;
|
|
|
|
use Commands\UploadTrackCommand;
|
|
|
|
use Entities\Track;
|
2013-07-26 12:29:58 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Illuminate\Support\Facades\Input;
|
|
|
|
use Illuminate\Support\Facades\Response;
|
2013-07-25 23:33:04 +02:00
|
|
|
|
|
|
|
class TracksController extends \ApiControllerBase {
|
|
|
|
public function postUpload() {
|
|
|
|
session_write_close();
|
|
|
|
return $this->execute(new UploadTrackCommand());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOwned() {
|
|
|
|
$query = Track::summary()->whereNull('deleted_at')->where('user_id', \Auth::user()->id);
|
|
|
|
|
2013-07-26 12:29:58 +02:00
|
|
|
if (Input::has('published')) {
|
2013-07-25 23:33:04 +02:00
|
|
|
$published = \Input::get('published');
|
|
|
|
if ($published)
|
|
|
|
$query->whereNotNull('published_at');
|
|
|
|
else
|
|
|
|
$query->whereNull('published_at');
|
|
|
|
}
|
|
|
|
|
2013-07-26 12:29:58 +02:00
|
|
|
if (Input::has('order')) {
|
2013-07-25 23:33:04 +02:00
|
|
|
$order = \Input::get('order');
|
|
|
|
$parts = explode(',', $order);
|
|
|
|
$query->orderBy($parts[0], $parts[1]);
|
|
|
|
}
|
|
|
|
|
2013-07-26 12:29:58 +02:00
|
|
|
if (Input::has('genres'))
|
|
|
|
$query->whereIn('genre_id', Input::get('genres'));
|
2013-07-25 23:33:04 +02:00
|
|
|
|
2013-07-26 12:29:58 +02:00
|
|
|
if (Input::has('types'))
|
|
|
|
$query->whereIn('track_type_id', Input::get('types'));
|
2013-07-25 23:33:04 +02:00
|
|
|
|
|
|
|
$dbTracks = $query->get();
|
|
|
|
$tracks = [];
|
|
|
|
|
|
|
|
foreach ($dbTracks as $track) {
|
|
|
|
$tracks[] = [
|
|
|
|
'id' => $track->id,
|
|
|
|
'title' => $track->title,
|
|
|
|
'user_id' => $track->user_id,
|
|
|
|
'slug' => $track->slug,
|
|
|
|
'is_vocal' => $track->is_vocal,
|
|
|
|
'is_explicit' => $track->is_explicit,
|
|
|
|
'is_downloadable' => $track->is_downloadable,
|
|
|
|
'is_published' => $track->published_at != null,
|
|
|
|
'created_at' => $track->created_at,
|
|
|
|
'published_at' => $track->published_at,
|
|
|
|
'duration' => $track->duration,
|
|
|
|
'genre_id' => $track->genre_id,
|
|
|
|
'track_type_id' => $track->track_type_id,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2013-07-26 12:29:58 +02:00
|
|
|
return Response::json($tracks, 200);
|
2013-07-25 23:33:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getEdit($id) {
|
|
|
|
$track = Track::find($id);
|
|
|
|
if (!$track)
|
|
|
|
return $this->notFound('Track ' . $id . ' not found!');
|
|
|
|
|
2013-07-26 12:29:58 +02:00
|
|
|
if ($track->user_id != Auth::user()->id)
|
2013-07-25 23:33:04 +02:00
|
|
|
return $this->notAuthorized();
|
|
|
|
|
2013-07-26 12:29:58 +02:00
|
|
|
return Response::json([
|
2013-07-25 23:33:04 +02:00
|
|
|
'id' => $track->id,
|
|
|
|
'title' => $track->title,
|
|
|
|
'user_id' => $track->user_id,
|
|
|
|
'slug' => $track->slug,
|
|
|
|
'is_vocal' => (bool)$track->is_vocal,
|
|
|
|
'is_explicit' => (bool)$track->is_explicit,
|
|
|
|
'is_downloadable' => $track->published_at == null ? true : (bool)$track->is_downloadable,
|
|
|
|
'is_published' => $track->published_at != null,
|
|
|
|
'created_at' => $track->created_at,
|
|
|
|
'published_at' => $track->published_at,
|
|
|
|
'duration' => $track->duration,
|
|
|
|
'genre_id' => $track->genre_id,
|
|
|
|
'track_type_id' => $track->track_type_id,
|
|
|
|
'license_id' => $track->license_id != null ? $track->license_id : 3,
|
|
|
|
'description' => $track->description,
|
|
|
|
'lyrics' => $track->lyrics,
|
|
|
|
'released_at' => $track->released_at
|
|
|
|
], 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function postDelete($id) {
|
|
|
|
return $this->execute(new DeleteTrackCommand($id));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function putEdit($id) {
|
2013-07-26 12:29:58 +02:00
|
|
|
return $this->execute(new EditTrackCommand($id, Input::all()));
|
2013-07-25 23:33:04 +02:00
|
|
|
}
|
|
|
|
}
|