mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-28 23:57:59 +01:00
Implement server-side track removal from playlist
This commit is contained in:
parent
f193254dbc
commit
dfefb2ad81
4 changed files with 77 additions and 0 deletions
63
app/Commands/RemoveTrackFromPlaylistCommand.php
Normal file
63
app/Commands/RemoveTrackFromPlaylistCommand.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Peter Deltchev
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Poniverse\Ponyfm\Commands;
|
||||
|
||||
use Poniverse\Ponyfm\Playlist;
|
||||
use Poniverse\Ponyfm\Track;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RemoveTrackFromPlaylistCommand extends CommandBase
|
||||
{
|
||||
private $_track;
|
||||
private $_playlist;
|
||||
|
||||
function __construct($playlistId, $trackId)
|
||||
{
|
||||
$this->_playlist = Playlist::find($playlistId);
|
||||
$this->_track = Track::find($trackId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
return $user != null && $this->_playlist && $this->_track && $this->_playlist->user_id == $user->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
* @return CommandResponse
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
// $songIndex = $this->_playlist->tracks()->count() - 1;
|
||||
$this->_playlist->tracks()->detach($this->_track);
|
||||
Playlist::whereId($this->_playlist->id)->update([
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = ' . $this->_playlist->id . ')')
|
||||
]);
|
||||
|
||||
return CommandResponse::succeed(['message' => 'Track removed!']);
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ use Poniverse\Ponyfm\Commands\AddTrackToPlaylistCommand;
|
|||
use Poniverse\Ponyfm\Commands\CreatePlaylistCommand;
|
||||
use Poniverse\Ponyfm\Commands\DeletePlaylistCommand;
|
||||
use Poniverse\Ponyfm\Commands\EditPlaylistCommand;
|
||||
use Poniverse\Ponyfm\Commands\RemoveTrackFromPlaylistCommand;
|
||||
use Poniverse\Ponyfm\Http\Controllers\ApiControllerBase;
|
||||
use Poniverse\Ponyfm\Image;
|
||||
use Poniverse\Ponyfm\Playlist;
|
||||
|
@ -56,6 +57,11 @@ class PlaylistsController extends ApiControllerBase
|
|||
return $this->execute(new AddTrackToPlaylistCommand($id, Input::get('track_id')));
|
||||
}
|
||||
|
||||
public function postRemoveTrack($id)
|
||||
{
|
||||
return $this->execute(new RemoveTrackFromPlaylistCommand($id, Input::get('track_id')));
|
||||
}
|
||||
|
||||
public function getIndex()
|
||||
{
|
||||
$page = 1;
|
||||
|
|
|
@ -119,6 +119,7 @@ Route::group(['prefix' => 'api/web'], function() {
|
|||
Route::post('/playlists/delete/{id}', 'Api\Web\PlaylistsController@postDelete');
|
||||
Route::post('/playlists/edit/{id}', 'Api\Web\PlaylistsController@postEdit');
|
||||
Route::post('/playlists/{id}/add-track', 'Api\Web\PlaylistsController@postAddTrack');
|
||||
Route::post('/playlists/{id}/remove-track', 'Api\Web\PlaylistsController@postRemoveTrack');
|
||||
|
||||
Route::post('/comments/{type}/{id}', 'Api\Web\CommentsController@postCreate')->where('id', '\d+');
|
||||
|
||||
|
|
|
@ -68,6 +68,13 @@ angular.module('ponyfm').factory('playlists', [
|
|||
|
||||
def
|
||||
|
||||
removeTrackFromPlaylist: (playlistId, trackId) ->
|
||||
def = new $.Deferred()
|
||||
$http.post('/api/web/playlists/' + playlistId + '/remove-track', {track_id: trackId}).success (res) ->
|
||||
def.resolve(res)
|
||||
|
||||
def
|
||||
|
||||
refresh: () ->
|
||||
if auth.data.isLogged
|
||||
$.getJSON('/api/web/playlists/pinned')
|
||||
|
|
Loading…
Reference in a new issue