2015-12-13 04:42:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
|
2015-12-23 06:26:16 +00:00
|
|
|
use App\Events\SongStartedPlaying;
|
2015-12-13 04:42:28 +00:00
|
|
|
use App\Http\Requests\API\BatchInteractionRequest;
|
2015-12-14 13:22:39 +00:00
|
|
|
use App\Models\Interaction;
|
2015-12-13 04:42:28 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class InteractionController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Increase a song's play count as the currently authenticated user.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function play(Request $request)
|
|
|
|
{
|
2015-12-23 06:26:16 +00:00
|
|
|
if ($interaction = Interaction::increasePlayCount($request->input('id'), $request->user())) {
|
|
|
|
event(new SongStartedPlaying($interaction->song, $interaction->user));
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json($interaction);
|
2015-12-13 04:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Like or unlike a song as the currently authenticated user.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function like(Request $request)
|
|
|
|
{
|
2015-12-21 04:32:15 +00:00
|
|
|
return response()->json(Interaction::toggleLike($request->input('id'), $request->user()));
|
2015-12-13 04:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Like several songs at once as the currently authenticated user.
|
|
|
|
*
|
|
|
|
* @param BatchInteractionRequest $request
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function batchLike(BatchInteractionRequest $request)
|
|
|
|
{
|
2015-12-21 04:32:15 +00:00
|
|
|
return response()->json(Interaction::batchLike((array) $request->input('ids'), $request->user()));
|
2015-12-13 04:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unlike several songs at once as the currently authenticated user.
|
|
|
|
*
|
|
|
|
* @param BatchInteractionRequest $request
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function batchUnlike(BatchInteractionRequest $request)
|
|
|
|
{
|
2015-12-21 04:32:15 +00:00
|
|
|
return response()->json(Interaction::batchUnlike((array) $request->input('ids'), $request->user()));
|
2015-12-13 04:42:28 +00:00
|
|
|
}
|
|
|
|
}
|