feat(API): 테넌트 로고 업로드 API 추가

- POST /api/v1/tenants/logo 엔드포인트 추가
- TenantLogoUploadRequest: 이미지 유효성 검사 (jpeg, png, gif, webp, 5MB)
- TenantService.uploadLogo(): 기존 로고 삭제 후 새 로고 저장
- 저장 경로: /storage/tenants/{tenant_id}/logo_{timestamp}.{ext}

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-30 22:58:50 +09:00
parent 7fa03caffc
commit c3de8410ee
5 changed files with 96 additions and 0 deletions

View File

@@ -4,6 +4,8 @@
use App\Models\Members\UserTenant;
use App\Models\Tenants\Tenant;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
class TenantService
@@ -366,4 +368,58 @@ public static function restoreTenant(array $params = [])
return 'success';
}
/**
* 테넌트 로고 업로드
*
* @param UploadedFile $file 업로드된 로고 이미지
* @return array{logo_url: string, tenant: Tenant}
*/
public static function uploadLogo(UploadedFile $file): array
{
$tenantId = app('tenant_id');
if (! $tenantId) {
throw new \Exception('테넌트 정보를 찾을 수 없습니다.');
}
$tenant = Tenant::find($tenantId);
if (! $tenant) {
throw new \Exception('테넌트를 찾을 수 없습니다.');
}
// 기존 로고 삭제
if ($tenant->logo) {
// logo 필드에 저장된 경로가 전체 URL인 경우 처리
$oldPath = $tenant->logo;
if (str_starts_with($oldPath, '/storage/')) {
$oldPath = str_replace('/storage/', '', $oldPath);
}
if (Storage::disk('public')->exists($oldPath)) {
Storage::disk('public')->delete($oldPath);
}
}
// 새 로고 저장: /tenants/{tenant_id}/logo_{timestamp}.{ext}
$extension = $file->getClientOriginalExtension();
$filename = 'logo_'.time().'.'.$extension;
$path = sprintf('tenants/%d/%s', $tenantId, $filename);
Storage::disk('public')->putFileAs(
dirname($path),
$file,
basename($path)
);
// 접근 가능한 URL 생성
$logoUrl = '/storage/'.$path;
// DB 업데이트
$tenant->update(['logo' => $logoUrl]);
return [
'logo_url' => $logoUrl,
'tenant' => $tenant->fresh(),
];
}
}