feat(item-master): 잠금 기능 추가 및 FK 레거시 코드 정리
## 잠금 기능 (Lock Feature) - entity_relationships 테이블에 is_locked, locked_by, locked_at 컬럼 추가 - EntityRelationship 모델에 잠금 관련 헬퍼 메서드 추가 - LockCheckTrait 생성 (destroy 시 잠금 체크 공통 로직) - 각 Service의 destroy() 메서드에 잠금 체크 적용 - API 응답에 is_locked 필드 포함 - 한국어 에러 메시지 추가 ## FK 레거시 코드 정리 - ItemMasterSeeder: entity_relationships 기반으로 전환 - ItemPage 모델: FK 기반 sections() 관계 제거 - ItemSectionService: clone() 메서드 FK 제거 - SectionTemplateService: page_id 컬럼 참조 제거 - EntityRelationship::link() 파라미터 순서 통일 ## 기타 - Swagger 스키마에 is_locked 속성 추가 - 프론트엔드 가이드 문서 추가
This commit is contained in:
@@ -28,6 +28,9 @@ class EntityRelationship extends Model
|
||||
'child_id',
|
||||
'order_no',
|
||||
'metadata',
|
||||
'is_locked',
|
||||
'locked_by',
|
||||
'locked_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
];
|
||||
@@ -38,6 +41,8 @@ class EntityRelationship extends Model
|
||||
'child_id' => 'integer',
|
||||
'order_no' => 'integer',
|
||||
'metadata' => 'array',
|
||||
'is_locked' => 'boolean',
|
||||
'locked_at' => 'datetime',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
@@ -146,6 +151,8 @@ public static function link(
|
||||
|
||||
/**
|
||||
* 관계 해제
|
||||
*
|
||||
* @throws \App\Exceptions\BusinessException 잠금된 연결인 경우
|
||||
*/
|
||||
public static function unlink(
|
||||
int $tenantId,
|
||||
@@ -155,18 +162,31 @@ public static function unlink(
|
||||
int $childId,
|
||||
int $groupId = self::GROUP_ITEM_MASTER
|
||||
): bool {
|
||||
return self::where([
|
||||
$relationship = self::where([
|
||||
'tenant_id' => $tenantId,
|
||||
'group_id' => $groupId,
|
||||
'parent_type' => $parentType,
|
||||
'parent_id' => $parentId,
|
||||
'child_type' => $childType,
|
||||
'child_id' => $childId,
|
||||
])->delete() > 0;
|
||||
])->first();
|
||||
|
||||
if (! $relationship) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 잠금 체크
|
||||
if ($relationship->is_locked) {
|
||||
throw new \App\Exceptions\BusinessException(__('error.relationship_locked'));
|
||||
}
|
||||
|
||||
return $relationship->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 부모의 모든 자식 관계 해제
|
||||
* 특정 부모의 모든 자식 관계 해제 (잠금되지 않은 것만)
|
||||
*
|
||||
* @throws \App\Exceptions\BusinessException 잠금된 연결이 있는 경우
|
||||
*/
|
||||
public static function unlinkAllChildren(
|
||||
int $tenantId,
|
||||
@@ -186,6 +206,43 @@ public static function unlinkAllChildren(
|
||||
$query->where('child_type', $childType);
|
||||
}
|
||||
|
||||
// 잠금된 연결이 있는지 확인
|
||||
if ($query->clone()->where('is_locked', true)->exists()) {
|
||||
throw new \App\Exceptions\BusinessException(__('error.has_locked_relationships'));
|
||||
}
|
||||
|
||||
return $query->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 자식 엔티티가 잠금된 연결을 가지고 있는지 확인
|
||||
*/
|
||||
public static function hasLockedParentRelationship(string $childType, int $childId): bool
|
||||
{
|
||||
return self::where('child_type', $childType)
|
||||
->where('child_id', $childId)
|
||||
->where('is_locked', true)
|
||||
->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 자식 엔티티의 잠금 상태 조회 (computed)
|
||||
* 연결이 잠겨있으면 엔티티도 잠금 상태로 간주
|
||||
*/
|
||||
public static function getChildLockStatus(string $childType, int $childId): array
|
||||
{
|
||||
$lockedRelationships = self::where('child_type', $childType)
|
||||
->where('child_id', $childId)
|
||||
->where('is_locked', true)
|
||||
->get(['id', 'parent_type', 'parent_id']);
|
||||
|
||||
return [
|
||||
'is_locked' => $lockedRelationships->isNotEmpty(),
|
||||
'locked_by_relationships' => $lockedRelationships->map(fn ($rel) => [
|
||||
'relationship_id' => $rel->id,
|
||||
'parent_type' => $rel->parent_type,
|
||||
'parent_id' => $rel->parent_id,
|
||||
])->toArray(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user