feat(construction): 구조검토관리 API 구현
- Migration: structure_reviews 테이블 생성
- Model: StructureReview (BelongsToTenant, SoftDeletes)
- Service: StructureReviewService (CRUD + 통계 + 일괄삭제)
- Controller: StructureReviewController (7 endpoints)
- FormRequest: Store/Update 검증 규칙
API Endpoints:
- GET /construction/structure-reviews (목록)
- POST /construction/structure-reviews (생성)
- GET /construction/structure-reviews/stats (통계)
- DELETE /construction/structure-reviews/bulk (일괄삭제)
- GET /construction/structure-reviews/{id} (상세)
- PUT /construction/structure-reviews/{id} (수정)
- DELETE /construction/structure-reviews/{id} (삭제)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
170
app/Models/Construction/StructureReview.php
Normal file
170
app/Models/Construction/StructureReview.php
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Construction;
|
||||
|
||||
use App\Models\Members\User;
|
||||
use App\Models\Site;
|
||||
use App\Traits\BelongsToTenant;
|
||||
use App\Traits\ModelTrait;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* 구조검토 모델
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $tenant_id
|
||||
* @property string|null $review_number
|
||||
* @property int|null $partner_id
|
||||
* @property string|null $partner_name
|
||||
* @property int|null $site_id
|
||||
* @property string|null $site_name
|
||||
* @property string|null $request_date
|
||||
* @property string|null $review_company
|
||||
* @property string|null $reviewer_name
|
||||
* @property string|null $review_date
|
||||
* @property string|null $completion_date
|
||||
* @property string $status
|
||||
* @property string|null $file_url
|
||||
* @property string|null $remarks
|
||||
* @property bool $is_active
|
||||
* @property int|null $created_by
|
||||
* @property int|null $updated_by
|
||||
* @property int|null $deleted_by
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property \Illuminate\Support\Carbon|null $deleted_at
|
||||
*/
|
||||
class StructureReview extends Model
|
||||
{
|
||||
use BelongsToTenant, ModelTrait, SoftDeletes;
|
||||
|
||||
protected $table = 'structure_reviews';
|
||||
|
||||
// 상태 상수
|
||||
public const STATUS_PENDING = 'pending';
|
||||
|
||||
public const STATUS_COMPLETED = 'completed';
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id',
|
||||
'review_number',
|
||||
'partner_id',
|
||||
'partner_name',
|
||||
'site_id',
|
||||
'site_name',
|
||||
'request_date',
|
||||
'review_company',
|
||||
'reviewer_name',
|
||||
'review_date',
|
||||
'completion_date',
|
||||
'status',
|
||||
'file_url',
|
||||
'remarks',
|
||||
'is_active',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'request_date' => 'date:Y-m-d',
|
||||
'review_date' => 'date:Y-m-d',
|
||||
'completion_date' => 'date:Y-m-d',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
protected $attributes = [
|
||||
'is_active' => true,
|
||||
'status' => self::STATUS_PENDING,
|
||||
];
|
||||
|
||||
// =========================================================================
|
||||
// 관계 정의
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 현장
|
||||
*/
|
||||
public function site(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Site::class, 'site_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 생성자
|
||||
*/
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* 수정자
|
||||
*/
|
||||
public function updater(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'updated_by');
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 스코프
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 상태별 필터
|
||||
*/
|
||||
public function scopeStatus($query, string $status)
|
||||
{
|
||||
return $query->where('status', $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 현장별 필터
|
||||
*/
|
||||
public function scopeSite($query, int $siteId)
|
||||
{
|
||||
return $query->where('site_id', $siteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 거래처별 필터
|
||||
*/
|
||||
public function scopePartner($query, int $partnerId)
|
||||
{
|
||||
return $query->where('partner_id', $partnerId);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 헬퍼 메서드
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 상태 라벨 반환
|
||||
*/
|
||||
public function getStatusLabelAttribute(): string
|
||||
{
|
||||
return match ($this->status) {
|
||||
self::STATUS_PENDING => '검토대기',
|
||||
self::STATUS_COMPLETED => '검토완료',
|
||||
default => $this->status,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 검토대기 여부
|
||||
*/
|
||||
public function isPending(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_PENDING;
|
||||
}
|
||||
|
||||
/**
|
||||
* 검토완료 여부
|
||||
*/
|
||||
public function isCompleted(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_COMPLETED;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user