diff --git a/app/Http/Controllers/AppVersionController.php b/app/Http/Controllers/AppVersionController.php index a8f42528..b264fa6c 100644 --- a/app/Http/Controllers/AppVersionController.php +++ b/app/Http/Controllers/AppVersionController.php @@ -18,9 +18,10 @@ public function __construct( */ public function index(Request $request): View { - $versions = $this->appVersionService->list(); + $isSuperAdmin = auth()->user()?->is_super_admin ?? false; + $versions = $this->appVersionService->list(withTrashed: $isSuperAdmin); - return view('app-versions.index', compact('versions')); + return view('app-versions.index', compact('versions', 'isSuperAdmin')); } /** @@ -68,4 +69,26 @@ public function destroy(int $id): RedirectResponse return redirect()->route('app-versions.index') ->with('success', '버전이 삭제되었습니다.'); } + + /** + * 복구 (슈퍼관리자 전용) + */ + public function restore(int $id): RedirectResponse + { + $version = $this->appVersionService->restore($id); + + return redirect()->route('app-versions.index') + ->with('success', "v{$version->version_name}이 복구되었습니다."); + } + + /** + * 영구 삭제 (슈퍼관리자 전용) + */ + public function forceDestroy(int $id): RedirectResponse + { + $this->appVersionService->forceDestroy($id); + + return redirect()->route('app-versions.index') + ->with('success', '버전이 영구 삭제되었습니다.'); + } } diff --git a/app/Services/AppVersionService.php b/app/Services/AppVersionService.php index b70439dd..2276acd1 100644 --- a/app/Services/AppVersionService.php +++ b/app/Services/AppVersionService.php @@ -12,10 +12,15 @@ class AppVersionService /** * 버전 목록 (페이지네이션) */ - public function list(int $perPage = 20): LengthAwarePaginator + public function list(bool $withTrashed = false, int $perPage = 20): LengthAwarePaginator { - return AppVersion::orderByDesc('version_code') - ->paginate($perPage); + $query = AppVersion::orderByDesc('version_code'); + + if ($withTrashed) { + $query->withTrashed(); + } + + return $query->paginate($perPage); } /** @@ -49,17 +54,37 @@ public function toggleActive(int $id): AppVersion } /** - * 삭제 + * 삭제 (소프트) */ public function destroy(int $id): void { $version = AppVersion::findOrFail($id); + $version->delete(); + } + + /** + * 복구 + */ + public function restore(int $id): AppVersion + { + $version = AppVersion::onlyTrashed()->findOrFail($id); + $version->restore(); + + return $version; + } + + /** + * 영구 삭제 + */ + public function forceDestroy(int $id): void + { + $version = AppVersion::onlyTrashed()->findOrFail($id); // APK 파일 삭제 if ($version->apk_path && Storage::disk('app_releases')->exists($version->apk_path)) { Storage::disk('app_releases')->delete($version->apk_path); } - $version->delete(); + $version->forceDelete(); } } diff --git a/resources/views/app-versions/index.blade.php b/resources/views/app-versions/index.blade.php index da81cc39..e5526dcf 100644 --- a/resources/views/app-versions/index.blade.php +++ b/resources/views/app-versions/index.blade.php @@ -96,57 +96,83 @@ class="rounded border-gray-300 text-blue-600 shadow-sm focus:ring-blue-500"> @forelse($versions as $version) - + @php $isTrashed = $version->trashed(); @endphp + -
v{{ $version->version_name }}
-
code: {{ $version->version_code }}
+
v{{ $version->version_name }}
+
code: {{ $version->version_code }}
+ @if($isTrashed) +
삭제됨 {{ $version->deleted_at->format('m-d H:i') }}
+ @endif - + {{ strtoupper($version->platform) }} - + {{ $version->release_notes ? \Illuminate\Support\Str::limit($version->release_notes, 60) : '-' }} - @if($version->force_update) + @if($isTrashed) + - + @elseif($version->force_update) 필수 @else - @endif -
- @csrf - -
+ @if($isTrashed) + - + @else +
+ @csrf + +
+ @endif - + {{ number_format($version->download_count) }} - + @if($version->apk_path) - + {{ $version->apk_original_name ? \Illuminate\Support\Str::limit($version->apk_original_name, 20) : 'APK' }} @if($version->apk_size) - ({{ number_format($version->apk_size / 1024 / 1024, 1) }}MB) + ({{ number_format($version->apk_size / 1024 / 1024, 1) }}MB) @endif @else - - + - @endif - + {{ $version->published_at?->format('Y-m-d') ?? '-' }} -
- @csrf - @method('DELETE') - -
+ @if($isTrashed && ($isSuperAdmin ?? false)) +
+
+ @csrf + +
+
+ @csrf + @method('DELETE') + +
+
+ @elseif(!$isTrashed) +
+ @csrf + @method('DELETE') + +
+ @endif @empty diff --git a/routes/web.php b/routes/web.php index 90a1984e..a1e9d114 100644 --- a/routes/web.php +++ b/routes/web.php @@ -358,6 +358,8 @@ Route::post('/', [AppVersionController::class, 'store'])->name('store'); Route::post('/{id}/toggle', [AppVersionController::class, 'toggleActive'])->name('toggle'); Route::delete('/{id}', [AppVersionController::class, 'destroy'])->name('destroy'); + Route::post('/{id}/restore', [AppVersionController::class, 'restore'])->name('restore'); + Route::delete('/{id}/force-delete', [AppVersionController::class, 'forceDestroy'])->name('force-destroy'); }); // AI 설정 관리