Files
sam-manage/app/Services/AppVersionService.php
권혁성 78e67eb928 feat: 앱 버전 관리 페이지 구현
- AppVersion 모델, Service, Controller
- 버전 등록 폼 (APK 업로드, 강제 업데이트 설정)
- 버전 목록 테이블 (활성 토글, 다운로드 수, 삭제)
- /app-versions 라우트 추가
- app_releases 스토리지 디스크 추가

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

66 lines
1.6 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(int $perPage = 20): LengthAwarePaginator
{
return AppVersion::orderByDesc('version_code')
->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);
// APK 파일 삭제
if ($version->apk_path && Storage::disk('app_releases')->exists($version->apk_path)) {
Storage::disk('app_releases')->delete($version->apk_path);
}
$version->delete();
}
}