fix : 부서관리 기능 수정

- Route, Controller, Service, Swagger, DB 수정
- 모델 위치 이동
This commit is contained in:
2025-08-21 18:38:27 +09:00
parent 52352f7896
commit 3ee7719cbc
16 changed files with 727 additions and 285 deletions

View File

@@ -0,0 +1,65 @@
<?php
namespace App\Models\Tenants;
use App\Models\Members\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Spatie\Permission\Traits\HasRoles;
use App\Traits\ModelTrait;
use App\Models\Tenants\Pivots\DepartmentUser;
use App\Models\Permissions\PermissionOverride;
class Department extends Model
{
use HasRoles, ModelTrait; // 부서도 권한/역할을 가짐
protected $table = 'departments';
protected $guarded = ['id'];
protected $casts = [
'tenant_id' => 'int',
'parent_id' => 'int',
'is_active' => 'bool',
'sort_order'=> 'int',
];
protected $hidden = [
'deleted_by','deleted_at'
];
// 스파티 가드명(프로젝트 설정에 맞게 조정)
protected string $guard_name = 'web';
/** 상위/하위 부서 */
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id');
}
public function children()
{
return $this->hasMany(self::class, 'parent_id');
}
/** 부서-사용자 N:N (추가 컬럼 포함 Pivot) */
public function users()
{
return $this->belongsToMany(User::class, 'department_user')
->using(DepartmentUser::class)
->withTimestamps()
->withPivot(['tenant_id','is_primary','joined_at','left_at']);
}
/** 부서의 권한 오버라이드(DENY/임시허용) */
public function permissionOverrides(): MorphMany
{
return $this->morphMany(PermissionOverride::class, 'model');
}
/** 부서-사용자 매핑 로우들(피벗 테이블의 레코드들) */
public function departmentUsers()
{
return $this->hasMany(DepartmentUser::class, 'department_id');
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Models\Tenants\Pivots;
use App\Models\Commons\IdeHelperDepartmentUser;
use App\Models\Members\User;
use App\Models\Tenants\Department;
use App\Traits\BelongsToTenant;
use App\Traits\ModelTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* @mixin IdeHelperDepartmentUser
*/
class DepartmentUser extends Model
{
use SoftDeletes, BelongsToTenant, ModelTrait;
protected $table = 'department_user';
protected $fillable = [
'tenant_id','department_id','user_id','is_primary','joined_at','left_at',
];
protected $casts = [
'tenant_id' => 'integer',
'department_id' => 'integer',
'user_id' => 'integer',
'is_primary' => 'integer',
'joined_at' => 'datetime',
'left_at' => 'datetime',
];
public function department()
{
return $this->belongsTo(Department::class, 'department_id');
}
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
}

View File

@@ -2,11 +2,11 @@
namespace App\Models\Tenants;
use App\Models\Commons\Role;
use App\Models\Commons\File;
use App\Models\Members\User;
use App\Models\Members\UserRole;
use App\Models\Members\UserTenant;
use App\Models\Permissions\Role;
use App\Traits\ModelTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

View File

@@ -3,7 +3,6 @@
namespace App\Models\Tenants;
use App\Models\Members\User;
use App\Models\Commons\Department;
use Illuminate\Database\Eloquent\Model;
/**