Files
sam-manage/app/Services/AppVersionService.php
권혁성 daaa77badc feat:앱버전 슈퍼관리자 소프트삭제 목록 표시, 복구/영구삭제 기능
- 슈퍼관리자: 삭제된 항목 빨간 배경으로 표시, 복구/영구삭제 버튼
- 소프트 삭제 시 APK 파일 유지, 영구 삭제 시에만 파일 제거
- restore, forceDestroy 라우트 및 서비스 메서드 추가

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 22:39:19 +09:00

91 lines
2.1 KiB
PHP

<?php
namespace App\Services;
use App\Models\AppVersion;
use Illuminate\Http\UploadedFile;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Storage;
class AppVersionService
{
/**
* 버전 목록 (페이지네이션)
*/
public function list(bool $withTrashed = false, int $perPage = 20): LengthAwarePaginator
{
$query = AppVersion::orderByDesc('version_code');
if ($withTrashed) {
$query->withTrashed();
}
return $query->paginate($perPage);
}
/**
* 새 버전 등록
*/
public function store(array $data, ?UploadedFile $apkFile = null): AppVersion
{
if ($apkFile) {
$data['apk_original_name'] = $apkFile->getClientOriginalName();
$data['apk_size'] = $apkFile->getSize();
$data['apk_path'] = $apkFile->store('apk', 'app_releases');
}
$data['created_by'] = auth()->id();
$data['published_at'] = $data['published_at'] ?? now();
return AppVersion::create($data);
}
/**
* 활성 토글
*/
public function toggleActive(int $id): AppVersion
{
$version = AppVersion::findOrFail($id);
$version->is_active = ! $version->is_active;
$version->updated_by = auth()->id();
$version->save();
return $version;
}
/**
* 삭제 (소프트)
*/
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->forceDelete();
}
}