2017-08-06 09:43:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API\Interaction;
|
|
|
|
|
|
|
|
use App\Events\SongStartedPlaying;
|
2017-12-09 18:34:27 +00:00
|
|
|
use App\Http\Requests\API\Interaction\StorePlayCountRequest;
|
2017-08-06 09:43:59 +00:00
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
|
2018-12-09 21:24:43 +00:00
|
|
|
/**
|
|
|
|
* @group 3. Song interactions
|
|
|
|
*/
|
2017-08-06 09:43:59 +00:00
|
|
|
class PlayCountController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
2018-12-09 21:24:43 +00:00
|
|
|
* Increase play count.
|
|
|
|
*
|
2017-08-06 09:43:59 +00:00
|
|
|
* Increase a song's play count as the currently authenticated user.
|
2018-12-09 21:24:43 +00:00
|
|
|
* This request should be made whenever a song is played.
|
|
|
|
* An "interaction" record including the song and current user's data will be returned.
|
|
|
|
*
|
|
|
|
* @bodyParam song string required The ID of the song. Example: 0146d01afb742b01f28ab8b556f9a75d
|
|
|
|
*
|
|
|
|
* @responseFile responses/interaction.json
|
2017-08-06 09:43:59 +00:00
|
|
|
*
|
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
2017-12-09 18:34:27 +00:00
|
|
|
public function store(StorePlayCountRequest $request)
|
2017-08-06 09:43:59 +00:00
|
|
|
{
|
2018-08-18 12:27:26 +00:00
|
|
|
$interaction = $this->interactionService->increasePlayCount($request->song, $request->user());
|
|
|
|
|
2017-08-06 09:43:59 +00:00
|
|
|
if ($interaction) {
|
|
|
|
event(new SongStartedPlaying($interaction->song, $interaction->user));
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json($interaction);
|
|
|
|
}
|
|
|
|
}
|