feat: 회원가입 + 테넌트 생성 통합 API 추가 (/api/v1/register)

- 사용자 등록 + 테넌트 생성 + 시스템 관리자 권한 자동 부여
- 사업자번호 조건부 검증 (active 테넌트만 unique)
- 글로벌 메뉴 자동 복제 (parent_id 매핑 알고리즘)
- DB 트랜잭션으로 전체 프로세스 원자성 보장

추가:
- RegisterRequest: FormRequest 검증 (conditional unique)
- RegisterService: 9-step 통합 비즈니스 로직
- RegisterController: ApiResponse::handle() 패턴
- RegisterApi: 완전한 Swagger 문서

수정:
- MenusStep: 글로벌 메뉴 복제 로직 구현
- message.php: 'registered' 키 추가
- error.php: 4개 에러 메시지 추가
- routes/api.php: POST /api/v1/register 라우트

SAM API Rules 준수:
- Service-First, FormRequest, i18n, Swagger, DB Transaction
This commit is contained in:
2025-11-06 17:24:42 +09:00
parent b7cf045a81
commit 48e76432ee
9 changed files with 862 additions and 1329 deletions

View File

@@ -7,22 +7,62 @@
class MenusStep implements TenantBootstrapStep
{
public function key(): string { return 'menus_seed'; }
public function key(): string
{
return 'menus_seed';
}
public function run(int $tenantId): void
{
// 예시: menus 테이블이 있다고 가정한 최소 스텁 (스키마에 맞춰 수정)
if (!DB::getSchemaBuilder()->hasTable('menus')) return;
if (! DB::getSchemaBuilder()->hasTable('menus')) {
return;
}
$exists = DB::table('menus')->where(['tenant_id'=>$tenantId, 'code'=>'ROOT'])->exists();
if (!$exists) {
DB::table('menus')->insert([
'tenant_id'=>$tenantId,
'name'=>'메인',
'parent_id'=>null, 'sort_order'=>0,
'is_active'=>1, 'created_at'=>now(), 'updated_at'=>now(),
// Check if tenant already has menus
$exists = DB::table('menus')->where('tenant_id', $tenantId)->exists();
if ($exists) {
return;
}
// Get all global menus ordered by parent_id, sort_order
// Order by: root menus first (parent_id IS NULL), then by parent_id ASC, then sort_order ASC
$globalMenus = DB::table('menus')
->whereNull('tenant_id')
->orderByRaw('parent_id IS NULL DESC, parent_id ASC, sort_order ASC')
->get();
if ($globalMenus->isEmpty()) {
return;
}
$parentIdMap = []; // old_id => new_id mapping
foreach ($globalMenus as $menu) {
// Map parent_id: if parent exists in map, use new parent_id, else null
$newParentId = null;
if ($menu->parent_id !== null && isset($parentIdMap[$menu->parent_id])) {
$newParentId = $parentIdMap[$menu->parent_id];
}
// Insert new menu for tenant
$newId = DB::table('menus')->insertGetId([
'tenant_id' => $tenantId,
'parent_id' => $newParentId,
'name' => $menu->name,
'code' => $menu->code ?? null,
'icon' => $menu->icon ?? null,
'url' => $menu->url ?? null,
'route_name' => $menu->route_name ?? null,
'sort_order' => $menu->sort_order ?? 0,
'is_active' => $menu->is_active ?? 1,
'depth' => $menu->depth ?? 0,
'description' => $menu->description ?? null,
'created_at' => now(),
'updated_at' => now(),
]);
// 필요 시 하위 기본 메뉴들 추가…
// Store mapping for children menus
$parentIdMap[$menu->id] = $newId;
}
}
}