목록이 뒤쪽 페이지로 갈수록 느려지는 원인은 건너뛰는 행의 넓은 컬럼까지 읽는 것이었다. 지연 조인(inner 는 키 컬럼만, outer 는 이번 페이지 행만 전체 컬럼)과 정렬 컬럼 해석을 코어 공통 트레이트로 두고 코어 8 + 확장 6 저장소에 적용했다. 감사 지적 처리: - 그룹 쿼리의 총 건수 오산 — count 는 groupBy 를 벗기지 않아 첫 그룹의 행 수를 총 건수로 돌려준다. getCountForPagination 으로 교정. - audit 전수 스캔이 버퍼 한계로 한 번도 동작하지 않던 결함과, 확장 경로를 놓치던 정규식 5건을 함께 고쳤다. 그동안 번들 확장의 위반이 보이지 않았다. raw 20건을 빌더 표현으로 치환하고 하드코딩 테이블명 16건을 모델 유래로 바꿨다. 이 과정에서 마이페이지 「내가 댓글 단 글」 검색이 조인 별칭 충돌로 SQL 오류를 내던 결함이 해소됐다. 재발 차단용 룰 2종을 신설하고, 컬럼 프루닝 룰을 error 로 승격했다 (전역 위반 0건 — warning 으로 두면 "0 error" 판정을 통과하며 무음으로 재누적된다). 정렬 허용 목록은 FormRequest 게이트를 덮어야 한다. 좁으면 검증을 통과한 정렬이 422 도 로그도 없이 기본값으로 되돌아간다(스케줄 실행 이력의 종료시각·소요시간 정렬이 그랬다). 호출처를 스캔해 매핑 완전성까지 검사하는 계약 테스트로 전수 강제한다. 해외 배송지 결함도 함께 고쳤다 — 조회는 city/state/postal_code 로 내려주고 폼은 intl_* 로 제출하는 비대칭 때문에, 수정 시 입력칸이 비어 보이고 저장하면 기존 값이 유실됐다. 쿠폰 수정의 유효기간 미검증과 1인당 사용 제한 부분 수정 차단도 함께 수정.
205 lines
6.2 KiB
PHP
205 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Contracts\Repositories\IdentityMessageDefinitionRepositoryInterface;
|
|
use App\Models\IdentityMessageDefinition;
|
|
use App\Repositories\Concerns\ResolvesSortSpec;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
class IdentityMessageDefinitionRepository implements IdentityMessageDefinitionRepositoryInterface
|
|
{
|
|
use ResolvesSortSpec;
|
|
|
|
/** 허용 정렬 컬럼 (AdminIdentityMessageDefinitionIndexRequest 와 동일 집합) */
|
|
private const SORTABLE_COLUMNS = [
|
|
'id',
|
|
'provider_id',
|
|
'scope_type',
|
|
'scope_value',
|
|
'is_active',
|
|
'created_at',
|
|
'updated_at',
|
|
];
|
|
|
|
/**
|
|
* ID로 메시지 정의 조회.
|
|
*
|
|
* @param int $id
|
|
* @return IdentityMessageDefinition|null
|
|
*/
|
|
public function findById(int $id): ?IdentityMessageDefinition
|
|
{
|
|
return IdentityMessageDefinition::find($id);
|
|
}
|
|
|
|
/**
|
|
* (provider, scope_type, scope_value) 조합으로 메시지 정의 조회.
|
|
*
|
|
* @param string $providerId
|
|
* @param string $scopeType
|
|
* @param string|null $scopeValue
|
|
* @return IdentityMessageDefinition|null
|
|
*/
|
|
public function findByScope(string $providerId, string $scopeType, ?string $scopeValue = null): ?IdentityMessageDefinition
|
|
{
|
|
return IdentityMessageDefinition::byProvider($providerId)
|
|
->byScope($scopeType, $scopeValue)
|
|
->first();
|
|
}
|
|
|
|
/**
|
|
* 활성 상태인 (provider, scope_type, scope_value) 메시지 정의 조회.
|
|
*
|
|
* @param string $providerId
|
|
* @param string $scopeType
|
|
* @param string|null $scopeValue
|
|
* @return IdentityMessageDefinition|null
|
|
*/
|
|
public function getActiveByScope(string $providerId, string $scopeType, ?string $scopeValue = null): ?IdentityMessageDefinition
|
|
{
|
|
return IdentityMessageDefinition::active()
|
|
->byProvider($providerId)
|
|
->byScope($scopeType, $scopeValue)
|
|
->first();
|
|
}
|
|
|
|
/**
|
|
* 모든 활성 메시지 정의 조회.
|
|
*
|
|
* @return Collection
|
|
*/
|
|
public function getAllActive(): Collection
|
|
{
|
|
return IdentityMessageDefinition::active()->get();
|
|
}
|
|
|
|
/**
|
|
* 활성 메시지 정의의 로케일별 라벨 맵.
|
|
*
|
|
* 키: "{provider_id}|{scope_type}|{scope_value}", 값: 다국어 라벨
|
|
*
|
|
* @param string|null $locale
|
|
* @return array<string, string>
|
|
*/
|
|
public function getLabelMap(?string $locale = null): array
|
|
{
|
|
$locale = $locale ?? app()->getLocale();
|
|
|
|
return IdentityMessageDefinition::active()
|
|
->get(['id', 'provider_id', 'scope_type', 'scope_value', 'name'])
|
|
->mapWithKeys(fn (IdentityMessageDefinition $def) => [
|
|
"{$def->provider_id}|{$def->scope_type->value}|{$def->scope_value}" => $def->getLocalizedName($locale),
|
|
])
|
|
->all();
|
|
}
|
|
|
|
/**
|
|
* 전체 메시지 정의 조회.
|
|
*
|
|
* @return Collection
|
|
*/
|
|
public function getAll(): Collection
|
|
{
|
|
return IdentityMessageDefinition::all();
|
|
}
|
|
|
|
/**
|
|
* 특정 확장의 메시지 정의 목록 조회.
|
|
*
|
|
* @param string $extensionType
|
|
* @param string $extensionIdentifier
|
|
* @return Collection
|
|
*/
|
|
public function getByExtension(string $extensionType, string $extensionIdentifier): Collection
|
|
{
|
|
return IdentityMessageDefinition::byExtension($extensionType, $extensionIdentifier)->get();
|
|
}
|
|
|
|
/**
|
|
* 메시지 정의 신규 생성.
|
|
*
|
|
* @param array $data
|
|
* @return IdentityMessageDefinition
|
|
*/
|
|
public function store(array $data): IdentityMessageDefinition
|
|
{
|
|
return IdentityMessageDefinition::create($data)->fresh();
|
|
}
|
|
|
|
/**
|
|
* 메시지 정의 수정.
|
|
*
|
|
* @param IdentityMessageDefinition $definition
|
|
* @param array $data
|
|
* @return IdentityMessageDefinition
|
|
*/
|
|
public function update(IdentityMessageDefinition $definition, array $data): IdentityMessageDefinition
|
|
{
|
|
$definition->update($data);
|
|
|
|
return $definition->fresh();
|
|
}
|
|
|
|
/**
|
|
* 페이지네이션 목록 조회.
|
|
*
|
|
* @param array $filters
|
|
* @param int $perPage
|
|
* @return LengthAwarePaginator
|
|
*/
|
|
public function getPaginated(array $filters = [], int $perPage = 20): LengthAwarePaginator
|
|
{
|
|
$query = IdentityMessageDefinition::with('templates');
|
|
|
|
if (! empty($filters['provider_id'])) {
|
|
$query->where('provider_id', $filters['provider_id']);
|
|
}
|
|
|
|
if (! empty($filters['scope_type'])) {
|
|
$query->where('scope_type', $filters['scope_type']);
|
|
}
|
|
|
|
if (! empty($filters['scope_value'])) {
|
|
$query->where('scope_value', $filters['scope_value']);
|
|
}
|
|
|
|
if (! empty($filters['extension_type'])) {
|
|
$query->where('extension_type', $filters['extension_type']);
|
|
}
|
|
|
|
if (! empty($filters['extension_identifier'])) {
|
|
$query->where('extension_identifier', $filters['extension_identifier']);
|
|
}
|
|
|
|
if (isset($filters['is_active'])) {
|
|
$query->where('is_active', $filters['is_active']);
|
|
}
|
|
|
|
if (! empty($filters['channel'])) {
|
|
$query->whereJsonContains('channels', $filters['channel']);
|
|
}
|
|
|
|
if (! empty($filters['search'])) {
|
|
$search = $filters['search'];
|
|
$locales = config('app.supported_locales', ['ko', 'en']);
|
|
|
|
$query->where(function ($q) use ($search, $locales) {
|
|
$q->where('provider_id', 'like', "%{$search}%")
|
|
->orWhere('scope_value', 'like', "%{$search}%");
|
|
foreach ($locales as $locale) {
|
|
$q->orWhere("name->{$locale}", 'like', "%{$search}%");
|
|
}
|
|
});
|
|
}
|
|
|
|
foreach ($this->resolveSortSpec($filters, self::SORTABLE_COLUMNS, 'id', 'asc') as $sort) {
|
|
$query->orderBy($sort['column'], $sort['direction']);
|
|
}
|
|
|
|
// audit:allow repository-paginate-column-pruning reason: 본인인증 메시지 정의 테이블 — 정의 수가 고정이고 넓은 컬럼이 없다
|
|
return $query->paginate($perPage);
|
|
}
|
|
}
|