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:
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
use App\Helpers\ApiResponse;
|
use App\Helpers\ApiResponse;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Tenant\TenantLogoUploadRequest;
|
||||||
use App\Http\Requests\Tenant\TenantStoreRequest;
|
use App\Http\Requests\Tenant\TenantStoreRequest;
|
||||||
use App\Http\Requests\Tenant\TenantUpdateRequest;
|
use App\Http\Requests\Tenant\TenantUpdateRequest;
|
||||||
use App\Services\TenantService;
|
use App\Services\TenantService;
|
||||||
@@ -54,4 +55,11 @@ public function restore(Request $request)
|
|||||||
return $this->service->restoreTenant($request->all());
|
return $this->service->restoreTenant($request->all());
|
||||||
}, __('message.tenant.restored'));
|
}, __('message.tenant.restored'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function uploadLogo(TenantLogoUploadRequest $request)
|
||||||
|
{
|
||||||
|
return ApiResponse::handle(function () use ($request) {
|
||||||
|
return $this->service->uploadLogo($request->file('logo'));
|
||||||
|
}, __('message.tenant.logo_uploaded'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
30
app/Http/Requests/Tenant/TenantLogoUploadRequest.php
Normal file
30
app/Http/Requests/Tenant/TenantLogoUploadRequest.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Tenant;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class TenantLogoUploadRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'logo' => 'required|image|mimes:jpeg,png,gif,webp|max:5120', // 5MB
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'logo.required' => __('validation.required', ['attribute' => '로고 이미지']),
|
||||||
|
'logo.image' => __('validation.image', ['attribute' => '로고']),
|
||||||
|
'logo.mimes' => __('validation.mimes', ['attribute' => '로고', 'values' => 'jpeg, png, gif, webp']),
|
||||||
|
'logo.max' => __('validation.max.file', ['attribute' => '로고', 'max' => '5MB']),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
use App\Models\Members\UserTenant;
|
use App\Models\Members\UserTenant;
|
||||||
use App\Models\Tenants\Tenant;
|
use App\Models\Tenants\Tenant;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
class TenantService
|
class TenantService
|
||||||
@@ -366,4 +368,58 @@ public static function restoreTenant(array $params = [])
|
|||||||
|
|
||||||
return 'success';
|
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(),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,6 +170,7 @@
|
|||||||
'updated' => '테넌트가 수정되었습니다.',
|
'updated' => '테넌트가 수정되었습니다.',
|
||||||
'deleted' => '테넌트가 삭제되었습니다.',
|
'deleted' => '테넌트가 삭제되었습니다.',
|
||||||
'restored' => '테넌트가 복구되었습니다.',
|
'restored' => '테넌트가 복구되었습니다.',
|
||||||
|
'logo_uploaded' => '회사 로고가 업로드되었습니다.',
|
||||||
],
|
],
|
||||||
|
|
||||||
'tenant_stat_field' => [
|
'tenant_stat_field' => [
|
||||||
|
|||||||
@@ -212,6 +212,7 @@
|
|||||||
Route::post('/', [TenantController::class, 'store'])->name('v1.tenant.store'); // 테넌트 등록
|
Route::post('/', [TenantController::class, 'store'])->name('v1.tenant.store'); // 테넌트 등록
|
||||||
Route::delete('/', [TenantController::class, 'destroy'])->name('v1.tenant.destroy'); // 테넌트 삭제(탈퇴)
|
Route::delete('/', [TenantController::class, 'destroy'])->name('v1.tenant.destroy'); // 테넌트 삭제(탈퇴)
|
||||||
Route::put('/restore/{tenant_id}', [TenantController::class, 'restore'])->name('v1.tenant.restore'); // 테넌트 복구
|
Route::put('/restore/{tenant_id}', [TenantController::class, 'restore'])->name('v1.tenant.restore'); // 테넌트 복구
|
||||||
|
Route::post('/logo', [TenantController::class, 'uploadLogo'])->name('v1.tenant.upload-logo'); // 로고 업로드
|
||||||
});
|
});
|
||||||
|
|
||||||
// Tenant Statistics Field API
|
// Tenant Statistics Field API
|
||||||
|
|||||||
Reference in New Issue
Block a user