- Controller: 생성자 DI로 PushNotificationService 주입 - Service: 12/18 커밋에서 삭제된 토큰 관리 메서드 복원 - registerToken, unregisterToken, getUserTokens - getSettings, updateSettings - initializeDefaultSettings, getDefaultSound - 기존 비즈니스 이벤트 푸시 기능(FcmSender) 유지 Co-Authored-By: Claude <noreply@anthropic.com>
86 lines
2.3 KiB
PHP
86 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Helpers\ApiResponse;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Push\RegisterTokenRequest;
|
|
use App\Http\Requests\Push\UpdateSettingsRequest;
|
|
use App\Services\PushNotificationService;
|
|
use Illuminate\Http\Request;
|
|
|
|
class PushNotificationController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly PushNotificationService $service
|
|
) {}
|
|
|
|
/**
|
|
* FCM 토큰 등록
|
|
*/
|
|
public function registerToken(RegisterTokenRequest $request)
|
|
{
|
|
return ApiResponse::handle(function () use ($request) {
|
|
return $this->service->registerToken($request->validated());
|
|
}, __('message.push.token_registered'));
|
|
}
|
|
|
|
/**
|
|
* FCM 토큰 해제
|
|
*/
|
|
public function unregisterToken(Request $request)
|
|
{
|
|
return ApiResponse::handle(function () use ($request) {
|
|
$token = $request->input('token');
|
|
if (! $token) {
|
|
throw new \InvalidArgumentException(__('error.push.token_required'));
|
|
}
|
|
|
|
return ['unregistered' => $this->service->unregisterToken($token)];
|
|
}, __('message.push.token_unregistered'));
|
|
}
|
|
|
|
/**
|
|
* 사용자의 등록된 디바이스 토큰 목록
|
|
*/
|
|
public function getTokens()
|
|
{
|
|
return ApiResponse::handle(function () {
|
|
return $this->service->getUserTokens();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 알림 설정 조회
|
|
*/
|
|
public function getSettings()
|
|
{
|
|
return ApiResponse::handle(function () {
|
|
return $this->service->getSettings();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 알림 설정 업데이트
|
|
*/
|
|
public function updateSettings(UpdateSettingsRequest $request)
|
|
{
|
|
return ApiResponse::handle(function () use ($request) {
|
|
return $this->service->updateSettings($request->validated()['settings']);
|
|
}, __('message.push.settings_updated'));
|
|
}
|
|
|
|
/**
|
|
* 알림 유형 목록 조회
|
|
*/
|
|
public function getNotificationTypes()
|
|
{
|
|
return ApiResponse::handle(function () {
|
|
return [
|
|
'types' => \App\Models\PushNotificationSetting::getAllTypes(),
|
|
'sounds' => \App\Models\PushNotificationSetting::getAllSounds(),
|
|
];
|
|
});
|
|
}
|
|
}
|