style: Laravel Pint 코드 포맷팅 적용

- PSR-12 스타일 가이드 준수
- 302개 파일 스타일 이슈 자동 수정
- 코드 로직 변경 없음 (포맷팅만)
This commit is contained in:
2025-11-06 17:45:49 +09:00
parent 48e76432ee
commit cc206fdbed
294 changed files with 4476 additions and 2561 deletions

View File

@@ -2,15 +2,13 @@
namespace App\Services;
use App\Models\Members\User;
use App\Models\Members\UserTenant;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
use App\Models\Members\User;
use App\Models\Members\UserTenant;
class AdminService
{
/**
@@ -21,24 +19,24 @@ class AdminService
public static function getTenants(array $params = [])
{
$tenantId = app('tenant_id');
if (!$tenantId) {
if (! $tenantId) {
return ['error' => '성 테넌트가 없습니다.', 'code' => 400];
}
$page = isset($params['page']) ? (int)$params['page'] : 1;
$size = isset($params['size']) ? (int)$params['size'] : 10;
$keyword = $params['q'] ?? null;
$active = $params['is_active'] ?? null; // 0/1
$sortBy = $params['sort_by'] ?? 'users.id';
$sortDir = strtolower($params['sort_dir'] ?? 'desc') === 'asc' ? 'asc' : 'desc';
$page = isset($params['page']) ? (int) $params['page'] : 1;
$size = isset($params['size']) ? (int) $params['size'] : 10;
$keyword = $params['q'] ?? null;
$active = $params['is_active'] ?? null; // 0/1
$sortBy = $params['sort_by'] ?? 'users.id';
$sortDir = strtolower($params['sort_dir'] ?? 'desc') === 'asc' ? 'asc' : 'desc';
$q = UserTenant::query()
->with(['user:id,name,email,phone'])
->where('tenant_id', $tenantId);
if ($keyword) {
$q->whereHas('user', function($sub) use ($keyword) {
$sub->where(function($w) use ($keyword) {
$q->whereHas('user', function ($sub) use ($keyword) {
$sub->where(function ($w) use ($keyword) {
$w->where('name', 'like', "%{$keyword}%")
->orWhere('email', 'like', "%{$keyword}%")
->orWhere('phone', 'like', "%{$keyword}%");
@@ -47,7 +45,7 @@ public static function getTenants(array $params = [])
}
if ($active !== null && $active !== '') {
$q->where('is_active', (int)$active);
$q->where('is_active', (int) $active);
}
// 조인 정렬용
@@ -77,19 +75,19 @@ public static function getTenants(array $params = [])
public static function store(array $params = [])
{
$tenantId = app('tenant_id');
if (!$tenantId) {
if (! $tenantId) {
return ['error' => '활성 테넌트가 없습니다.', 'code' => 400];
}
// 신규 회원 생성 + 역할 부여 지원
$v = Validator::make($params, [
'user_id' => 'required|string|max:255|unique:users,user_id',
'name' => 'required|string|max:255',
'email' => 'required|email|max:100|unique:users,email',
'phone' => 'nullable|string|max:30',
'user_id' => 'required|string|max:255|unique:users,user_id',
'name' => 'required|string|max:255',
'email' => 'required|email|max:100|unique:users,email',
'phone' => 'nullable|string|max:30',
'password' => 'required|string|min:8|max:64',
'roles' => 'nullable|array',
'roles.*' => 'string|max:100', // 각각의 역할 이름
'roles' => 'nullable|array',
'roles.*' => 'string|max:100', // 각각의 역할 이름
]);
if ($v->fails()) {
@@ -101,24 +99,24 @@ public static function store(array $params = [])
return DB::transaction(function () use ($payload, $tenantId) {
// 신규 사용자 생성
$user = User::create([
'user_id' => $payload['user_id'],
'name' => $payload['name'],
'email' => $payload['email'],
'phone' => $payload['phone'] ?? null,
'user_id' => $payload['user_id'],
'name' => $payload['name'],
'email' => $payload['email'],
'phone' => $payload['phone'] ?? null,
'password' => $payload['password'], // 캐스트가 알아서 해싱
]);
// 현재 테넌트에 활성 연결
UserTenant::create([
'user_id' => $user->id,
'tenant_id' => $tenantId,
'is_active' => 1,
'user_id' => $user->id,
'tenant_id' => $tenantId,
'is_active' => 1,
'is_default' => 0,
'joined_at' => now(),
'joined_at' => now(),
]);
// 역할 부여 (Spatie Permission teams 모드 가정)
if (!empty($payload['roles']) && method_exists($user, 'assignRole')) {
if (! empty($payload['roles']) && method_exists($user, 'assignRole')) {
$previousTeam = app()->has('permission.team_id') ? app('permission.team_id') : null;
app()->instance('permission.team_id', $tenantId);
@@ -132,7 +130,7 @@ public static function store(array $params = [])
}
return [
'user' => $user->only(['id','user_id','name','email','phone']),
'user' => $user->only(['id', 'user_id', 'name', 'email', 'phone']),
];
});
}
@@ -144,17 +142,17 @@ public static function store(array $params = [])
public static function show(int $userNo)
{
$tenantId = app('tenant_id');
if (!$tenantId) {
if (! $tenantId) {
return ['error' => '활성 테넌트가 없습니다.', 'code' => 400];
}
if (!$userNo) {
if (! $userNo) {
return ['error' => '회원 정보가 없습니다.', 'code' => 422];
}
$user = User::whereHas('userTenants')->find($userNo);
if (!$user) {
if (! $user) {
return ['error' => '해당 사용자를 찾을 수 없습니다.', 'code' => 404];
}
@@ -166,38 +164,38 @@ public static function show(int $userNo)
* - 회원 기본정보(user_id, name, email, phone, password) 변경
* - 역할(roles) 변경 및 삭제 처리
*/
public static function update(array $params = [], int $userNo)
public static function update(array $params, int $userNo)
{
$tenantId = app('tenant_id');
if (!$tenantId) {
if (! $tenantId) {
return ['error' => '활성 테넌트가 없습니다.', 'code' => 400];
}
if (!$userNo) {
if (! $userNo) {
return ['error' => '회원 정보가 없습니다.', 'code' => 422];
}
// 1) 유저 존재/테넌트 소속 확인
$user = User::find($userNo);
if (!$user) {
if (! $user) {
return ['error' => '해당 회원을 찾을 수 없습니다.', 'code' => 404];
}
$linked = UserTenant::where('tenant_id', $tenantId)
->where('user_id', $userNo)
->exists();
if (!$linked) {
if (! $linked) {
return ['error' => '이 테넌트에 소속된 회원이 아닙니다.', 'code' => 403];
}
// 2) 프로필 + roles만 수정
$v = Validator::make($params, [
'user_id' => ['nullable','string','max:255', Rule::unique('users','user_id')->ignore($userNo)],
'name' => 'nullable|string|max:255',
'email' => ['nullable','email','max:100', Rule::unique('users','email')->ignore($userNo)],
'phone' => 'nullable|string|max:30',
'user_id' => ['nullable', 'string', 'max:255', Rule::unique('users', 'user_id')->ignore($userNo)],
'name' => 'nullable|string|max:255',
'email' => ['nullable', 'email', 'max:100', Rule::unique('users', 'email')->ignore($userNo)],
'phone' => 'nullable|string|max:30',
'password' => 'nullable|string|min:8|max:64',
'roles' => 'nullable|array',
'roles.*' => 'string|max:100',
'roles' => 'nullable|array',
'roles.*' => 'string|max:100',
]);
if ($v->fails()) {
return ['error' => $v->errors()->first(), 'code' => 422];
@@ -205,10 +203,10 @@ public static function update(array $params = [], int $userNo)
$payload = $v->validated();
// 아무 필드도 없으면 방어
$updatableKeys = ['user_id','name','email','phone','password'];
$updatableKeys = ['user_id', 'name', 'email', 'phone', 'password'];
$hasProfileInput = (bool) array_intersect(array_keys($payload), $updatableKeys);
$hasRolesInput = array_key_exists('roles', $payload);
if (!$hasProfileInput && !$hasRolesInput) {
$hasRolesInput = array_key_exists('roles', $payload);
if (! $hasProfileInput && ! $hasRolesInput) {
return ['error' => '수정할 항목이 없습니다.', 'code' => 422];
}
@@ -229,7 +227,7 @@ public static function update(array $params = [], int $userNo)
}
}
if (!empty($updateData)) {
if (! empty($updateData)) {
$user->fill($updateData);
$user->save();
}
@@ -248,7 +246,7 @@ public static function update(array $params = [], int $userNo)
}
return [
'user' => $user->only(['id','user_id','name','email','phone']),
'user' => $user->only(['id', 'user_id', 'name', 'email', 'phone']),
'roles' => method_exists($user, 'getRoleNames') ? $user->getRoleNames() : [],
];
});
@@ -261,18 +259,18 @@ public static function update(array $params = [], int $userNo)
public static function destroy(int $userNo)
{
$tenantId = app('tenant_id');
if (!$tenantId) {
if (! $tenantId) {
return ['error' => '활성 테넌트가 없습니다.', 'code' => 400];
}
if (!$userNo) {
if (! $userNo) {
return ['error' => '회원 정보가 없습니다.', 'code' => 422];
}
$ut = UserTenant::where('user_id',$userNo)
$ut = UserTenant::where('user_id', $userNo)
->where('tenant_id', $tenantId)
->first();
if (!$ut) {
if (! $ut) {
return ['error' => '해당 사용자를 찾을 수 없습니다.', 'code' => 404];
}
@@ -289,10 +287,10 @@ public static function destroy(int $userNo)
public static function restore(int $userNo)
{
$tenantId = app('tenant_id');
if (!$tenantId) {
if (! $tenantId) {
return ['error' => '활성 테넌트가 없습니다.', 'code' => 400];
}
if (!$userNo) {
if (! $userNo) {
return ['error' => '회원 정보가 없습니다.', 'code' => 422];
}
@@ -301,7 +299,7 @@ public static function restore(int $userNo)
->where('user_id', $userNo)
->first();
if (!$ut) {
if (! $ut) {
return ['error' => '해당 사용자를 찾을 수 없습니다.', 'code' => 404];
}
@@ -320,10 +318,10 @@ public static function restore(int $userNo)
public static function toggle(int $userNo)
{
$tenantId = app('tenant_id');
if (!$tenantId) {
if (! $tenantId) {
return ['error' => '활성 테넌트가 없습니다.', 'code' => 400];
}
if (!$userNo) {
if (! $userNo) {
return ['error' => '회원 정보가 없습니다.', 'code' => 422];
}
@@ -331,7 +329,7 @@ public static function toggle(int $userNo)
->where('user_id', $userNo)
->first();
if (!$ut) {
if (! $ut) {
return ['error' => '해당 사용자를 찾을 수 없습니다.', 'code' => 404];
}
@@ -348,12 +346,12 @@ public static function toggle(int $userNo)
public static function attach(array $params = [])
{
$tenantId = app('tenant_id');
if (!$tenantId) {
if (! $tenantId) {
return ['error' => '활성 테넌트가 없습니다.', 'code' => 400];
}
$v = Validator::make($params, [
'user_id' => 'required|integer|exists:users,id',
'user_id' => 'required|integer|exists:users,id',
'role_name' => 'required|string|max:100',
]);
if ($v->fails()) {
@@ -361,7 +359,7 @@ public static function attach(array $params = [])
}
$user = User::find($params['user_id']);
if (!method_exists($user, 'assignRole')) {
if (! method_exists($user, 'assignRole')) {
// Spatie 미사용 환경 방어
return ['error' => '역할 시스템이 활성화되어 있지 않습니다.', 'code' => 501];
}
@@ -387,12 +385,12 @@ public static function attach(array $params = [])
public static function detach(array $params = [])
{
$tenantId = app('tenant_id');
if (!$tenantId) {
if (! $tenantId) {
return ['error' => '활성 테넌트가 없습니다.', 'code' => 400];
}
$v = Validator::make($params, [
'user_id' => 'required|integer|exists:users,id',
'user_id' => 'required|integer|exists:users,id',
'role_name' => 'required|string|max:100',
]);
if ($v->fails()) {
@@ -400,7 +398,7 @@ public static function detach(array $params = [])
}
$user = User::find($params['user_id']);
if (!method_exists($user, 'removeRole')) {
if (! method_exists($user, 'removeRole')) {
return ['error' => '역할 시스템이 활성화되어 있지 않습니다.', 'code' => 501];
}
@@ -422,18 +420,18 @@ public static function detach(array $params = [])
* - 새 임시 비밀번호를 설정(응답으로 직접 노출 X 권장)
* - 여기서는 옵션에 따라 노출/미노출 선택 가능하도록 구현
*/
public static function reset(array $params = [],int $userNo)
public static function reset(array $params, int $userNo)
{
$tenantId = app('tenant_id');
if (!$tenantId) {
if (! $tenantId) {
return ['error' => '활성 테넌트가 없습니다.', 'code' => 400];
}
if (!$userNo) {
if (! $userNo) {
return ['error' => '회원 정보가 없습니다.', 'code' => 422];
}
$v = Validator::make($params, [
'new_password' => 'nullable|string|min:8|max:64',
'new_password' => 'nullable|string|min:8|max:64',
'return_password' => 'nullable|in:0,1', // 1이면 응답에 임시 비번 포함(개발용)
]);
if ($v->fails()) {
@@ -442,7 +440,7 @@ public static function reset(array $params = [],int $userNo)
$payload = $v->validated();
$user = User::find($userNo);
if (!$user) {
if (! $user) {
return ['error' => '유저를 찾을 수 없습니다.', 'code' => 404];
}
@@ -454,7 +452,7 @@ public static function reset(array $params = [],int $userNo)
// if (method_exists($user, 'tokens')) { $user->tokens()->delete(); }
$resp = ['status' => 'ok'];
if (!empty($payload['return_password'])) {
if (! empty($payload['return_password'])) {
// 운영에선 반환하지 말고 메일/문자 발송을 권장
$resp['temp_password'] = $new;
}