koel/app/Http/Controllers/V6/API/PlayCountController.php

28 lines
837 B
PHP
Raw Normal View History

2022-06-10 10:47:46 +00:00
<?php
namespace App\Http\Controllers\V6\API;
use App\Events\SongStartedPlaying;
2022-07-29 06:47:10 +00:00
use App\Http\Controllers\Controller;
2022-06-10 10:47:46 +00:00
use App\Http\Requests\API\Interaction\StorePlayCountRequest;
use App\Http\Resources\InteractionResource;
2022-07-29 06:47:10 +00:00
use App\Models\User;
use App\Services\InteractionService;
use Illuminate\Contracts\Auth\Authenticatable;
2022-06-10 10:47:46 +00:00
class PlayCountController extends Controller
{
2022-07-29 06:47:10 +00:00
/** @param User $user */
public function __construct(private InteractionService $interactionService, private ?Authenticatable $user)
{
}
2022-06-10 10:47:46 +00:00
public function store(StorePlayCountRequest $request)
{
$interaction = $this->interactionService->increasePlayCount($request->song, $this->user);
event(new SongStartedPlaying($interaction->song, $interaction->user));
return InteractionResource::make($interaction);
}
}