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) -