feat: [hr] 인사관리 사원관리 Phase 1 구현
- Employee, Position 모델 생성 (tenant_user_profiles, positions 테이블) - EmployeeService 생성 (CRUD, 통계, 필터/검색/페이지네이션) - 뷰 컨트롤러(HR/EmployeeController) + API 컨트롤러 생성 - Blade 뷰: index(통계카드+HTMX테이블), create, edit, show, partials/table - 라우트: web.php(/hr/employees/*), api.php(/admin/hr/employees/*)
This commit is contained in:
173
app/Http/Controllers/Api/Admin/HR/EmployeeController.php
Normal file
173
app/Http/Controllers/Api/Admin/HR/EmployeeController.php
Normal file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\HR;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\HR\EmployeeService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class EmployeeController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private EmployeeService $employeeService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 사원 목록 조회 (HTMX → HTML / 일반 → JSON)
|
||||
*/
|
||||
public function index(Request $request): JsonResponse|Response
|
||||
{
|
||||
$employees = $this->employeeService->getEmployees(
|
||||
$request->all(),
|
||||
$request->integer('per_page', 20)
|
||||
);
|
||||
|
||||
if ($request->header('HX-Request')) {
|
||||
return response(view('hr.employees.partials.table', compact('employees')));
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $employees->items(),
|
||||
'meta' => [
|
||||
'current_page' => $employees->currentPage(),
|
||||
'last_page' => $employees->lastPage(),
|
||||
'per_page' => $employees->perPage(),
|
||||
'total' => $employees->total(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 사원 통계
|
||||
*/
|
||||
public function stats(): JsonResponse
|
||||
{
|
||||
$stats = $this->employeeService->getStats();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $stats,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 사원 등록
|
||||
*/
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:50',
|
||||
'email' => 'nullable|email|max:100|unique:users,email',
|
||||
'phone' => 'nullable|string|max:20',
|
||||
'password' => 'nullable|string|min:6',
|
||||
'department_id' => 'nullable|integer|exists:departments,id',
|
||||
'position_key' => 'nullable|string|max:50',
|
||||
'job_title_key' => 'nullable|string|max:50',
|
||||
'work_location_key' => 'nullable|string|max:50',
|
||||
'employment_type_key' => 'nullable|string|max:50',
|
||||
'employee_status' => 'nullable|string|in:active,leave,resigned',
|
||||
'manager_user_id' => 'nullable|integer|exists:users,id',
|
||||
'display_name' => 'nullable|string|max:50',
|
||||
'employee_code' => 'nullable|string|max:30',
|
||||
'hire_date' => 'nullable|date',
|
||||
'address' => 'nullable|string|max:200',
|
||||
'emergency_contact' => 'nullable|string|max:100',
|
||||
]);
|
||||
|
||||
$employee = $this->employeeService->createEmployee($validated);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '사원이 등록되었습니다.',
|
||||
'data' => $employee,
|
||||
], 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* 사원 상세 조회
|
||||
*/
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$employee = $this->employeeService->getEmployeeById($id);
|
||||
|
||||
if (! $employee) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '사원 정보를 찾을 수 없습니다.',
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $employee,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 사원 수정
|
||||
*/
|
||||
public function update(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'sometimes|required|string|max:50',
|
||||
'email' => 'nullable|email|max:100',
|
||||
'phone' => 'nullable|string|max:20',
|
||||
'department_id' => 'nullable|integer|exists:departments,id',
|
||||
'position_key' => 'nullable|string|max:50',
|
||||
'job_title_key' => 'nullable|string|max:50',
|
||||
'work_location_key' => 'nullable|string|max:50',
|
||||
'employment_type_key' => 'nullable|string|max:50',
|
||||
'employee_status' => 'nullable|string|in:active,leave,resigned',
|
||||
'manager_user_id' => 'nullable|integer|exists:users,id',
|
||||
'display_name' => 'nullable|string|max:50',
|
||||
'employee_code' => 'nullable|string|max:30',
|
||||
'hire_date' => 'nullable|date',
|
||||
'address' => 'nullable|string|max:200',
|
||||
'emergency_contact' => 'nullable|string|max:100',
|
||||
]);
|
||||
|
||||
$employee = $this->employeeService->updateEmployee($id, $validated);
|
||||
|
||||
if (! $employee) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '사원 정보를 찾을 수 없습니다.',
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '사원 정보가 수정되었습니다.',
|
||||
'data' => $employee,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 사원 삭제 (퇴직 처리)
|
||||
*/
|
||||
public function destroy(Request $request, int $id): JsonResponse|Response
|
||||
{
|
||||
$result = $this->employeeService->deleteEmployee($id);
|
||||
|
||||
if (! $result) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '사원 정보를 찾을 수 없습니다.',
|
||||
], 404);
|
||||
}
|
||||
|
||||
if ($request->header('HX-Request')) {
|
||||
$employees = $this->employeeService->getEmployees($request->all(), $request->integer('per_page', 20));
|
||||
|
||||
return response(view('hr.employees.partials.table', compact('employees')));
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '퇴직 처리되었습니다.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user