From ad472a9880d78059843a576830db6f4a4e960d68 Mon Sep 17 00:00:00 2001 From: Wian Drs Date: Thu, 25 Jun 2026 13:06:24 +0700 Subject: [PATCH] CRUD Ticket Insidace Type --- .../Ticket/TicketIncidentTypeController.php | 77 +++++++++++++++++++ .../StoreTicketIncidentTypeRequest.php | 39 ++++++++++ .../UpdateTicketIncidentTypeRequest.php | 40 ++++++++++ .../TicketIncidentTypeResource.php | 25 ++++++ app/Models/TicketIncidentType.php | 20 +++++ .../Ticket/TicketIncidentTypeService.php | 38 +++++++++ ...651_create_ticket_incident_types_table.php | 29 +++++++ ..._06_25_051723_alter_ticket_types_table.php | 30 ++++++++ ...5410_alter_ticket_incident_types_table.php | 37 +++++++++ routes/api.php | 3 + 10 files changed, 338 insertions(+) create mode 100644 app/Http/Controllers/Ticket/TicketIncidentTypeController.php create mode 100644 app/Http/Requests/TicketIncidentType/StoreTicketIncidentTypeRequest.php create mode 100644 app/Http/Requests/TicketIncidentType/UpdateTicketIncidentTypeRequest.php create mode 100644 app/Http/Resources/TicketIncidentType/TicketIncidentTypeResource.php create mode 100644 app/Models/TicketIncidentType.php create mode 100644 app/Services/Ticket/TicketIncidentTypeService.php create mode 100644 database/migrations/2026_06_25_051651_create_ticket_incident_types_table.php create mode 100644 database/migrations/2026_06_25_051723_alter_ticket_types_table.php create mode 100644 database/migrations/2026_06_25_055410_alter_ticket_incident_types_table.php diff --git a/app/Http/Controllers/Ticket/TicketIncidentTypeController.php b/app/Http/Controllers/Ticket/TicketIncidentTypeController.php new file mode 100644 index 0000000..878a109 --- /dev/null +++ b/app/Http/Controllers/Ticket/TicketIncidentTypeController.php @@ -0,0 +1,77 @@ +success( + TicketIncidentTypeResource::collection( + $this->service->getAll() + ) + ); + } + + public function store( + StoreTicketIncidentTypeRequest $request + ): JsonResponse { + $incidentType = $this->service->create( + $request->validated() + ); + + return $this->created( + new TicketIncidentTypeResource($incidentType), + 'Incident Type berhasil dibuat' + ); + } + + public function show( + TicketIncidentType $ticketIncidentType + ): JsonResponse { + return $this->success( + new TicketIncidentTypeResource( + $ticketIncidentType + ) + ); + } + + public function update( + UpdateTicketIncidentTypeRequest $request, + TicketIncidentType $ticketIncidentType + ): JsonResponse { + $incidentType = $this->service->update( + $ticketIncidentType, + $request->validated() + ); + + return $this->updated( + new TicketIncidentTypeResource($incidentType), + 'Incident Type berhasil diupdate' + ); + } + + public function destroy( + TicketIncidentType $ticketIncidentType + ): JsonResponse { + $this->service->delete( + $ticketIncidentType + ); + + return $this->deleted( + 'Incident Type berhasil dihapus' + ); + } +} \ No newline at end of file diff --git a/app/Http/Requests/TicketIncidentType/StoreTicketIncidentTypeRequest.php b/app/Http/Requests/TicketIncidentType/StoreTicketIncidentTypeRequest.php new file mode 100644 index 0000000..4e8c5a6 --- /dev/null +++ b/app/Http/Requests/TicketIncidentType/StoreTicketIncidentTypeRequest.php @@ -0,0 +1,39 @@ +|string> + */ + + public function rules(): array + { + return [ + 'name' => [ + 'required', + 'string', + 'max:255', + 'unique:ticket_incident_types,name' + ], + 'is_active' => [ + 'sometimes', + 'boolean' + ] + ]; + } +} diff --git a/app/Http/Requests/TicketIncidentType/UpdateTicketIncidentTypeRequest.php b/app/Http/Requests/TicketIncidentType/UpdateTicketIncidentTypeRequest.php new file mode 100644 index 0000000..d8bcd75 --- /dev/null +++ b/app/Http/Requests/TicketIncidentType/UpdateTicketIncidentTypeRequest.php @@ -0,0 +1,40 @@ +|string> + */ + public function rules(): array + { + return [ + 'name' => [ + 'required', + 'string', + 'max:255', + Rule::unique('ticket_incident_types', 'name') + ->ignore($this->route('ticketIncidentType')) + ], + 'is_active' => [ + 'required', + 'boolean' + ] + ]; + } +} diff --git a/app/Http/Resources/TicketIncidentType/TicketIncidentTypeResource.php b/app/Http/Resources/TicketIncidentType/TicketIncidentTypeResource.php new file mode 100644 index 0000000..4a4f157 --- /dev/null +++ b/app/Http/Resources/TicketIncidentType/TicketIncidentTypeResource.php @@ -0,0 +1,25 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'name' => $this->name, + 'is_active' => $this->is_active, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]; + } +} diff --git a/app/Models/TicketIncidentType.php b/app/Models/TicketIncidentType.php new file mode 100644 index 0000000..0669c22 --- /dev/null +++ b/app/Models/TicketIncidentType.php @@ -0,0 +1,20 @@ + 'boolean' + ]; +} diff --git a/app/Services/Ticket/TicketIncidentTypeService.php b/app/Services/Ticket/TicketIncidentTypeService.php new file mode 100644 index 0000000..e637fda --- /dev/null +++ b/app/Services/Ticket/TicketIncidentTypeService.php @@ -0,0 +1,38 @@ +get(); + } + + public function create(array $data): TicketIncidentType + { + return TicketIncidentType::create([ + 'name' => $data['name'], + 'is_active' => $data['is_active'] ?? true + ]); + } + + public function update( + TicketIncidentType $ticketIncidentType, + array $data + ): TicketIncidentType { + $ticketIncidentType->update([ + 'name' => $data['name'], + 'is_active' => $data['is_active'] + ]); + + return $ticketIncidentType->fresh(); + } + + public function delete(TicketIncidentType $ticketIncidentType): void + { + $ticketIncidentType->delete(); + } +} \ No newline at end of file diff --git a/database/migrations/2026_06_25_051651_create_ticket_incident_types_table.php b/database/migrations/2026_06_25_051651_create_ticket_incident_types_table.php new file mode 100644 index 0000000..a9a9a90 --- /dev/null +++ b/database/migrations/2026_06_25_051651_create_ticket_incident_types_table.php @@ -0,0 +1,29 @@ +id(); + $table->string('name'); + $table->boolean('is_active')->default(true); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('ticket_incident_types'); + } +}; diff --git a/database/migrations/2026_06_25_051723_alter_ticket_types_table.php b/database/migrations/2026_06_25_051723_alter_ticket_types_table.php new file mode 100644 index 0000000..08160de --- /dev/null +++ b/database/migrations/2026_06_25_051723_alter_ticket_types_table.php @@ -0,0 +1,30 @@ +boolean('need_incident_type') + ->default(false) + ->after('name'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('ticket_types', function (Blueprint $table) { + $table->dropColumn('need_incident_type'); + }); + } +}; \ No newline at end of file diff --git a/database/migrations/2026_06_25_055410_alter_ticket_incident_types_table.php b/database/migrations/2026_06_25_055410_alter_ticket_incident_types_table.php new file mode 100644 index 0000000..8cb85d0 --- /dev/null +++ b/database/migrations/2026_06_25_055410_alter_ticket_incident_types_table.php @@ -0,0 +1,37 @@ +boolean('deleted') + ->default(false) + ->after('is_active'); + + $table->timestamp('deleted_at') + ->nullable() + ->after('deleted'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('ticket_incident_types', function (Blueprint $table) { + $table->dropColumn([ + 'deleted', + 'deleted_at' + ]); + }); + } +}; \ No newline at end of file diff --git a/routes/api.php b/routes/api.php index 96e5ac0..e21a058 100644 --- a/routes/api.php +++ b/routes/api.php @@ -6,6 +6,7 @@ use App\Http\Controllers\AuthController; use App\Http\Controllers\Ticket\TicketController; use App\Http\Controllers\Ticket\TicketTypeController; use App\Http\Controllers\Ticket\TicketWorkflowController; +use App\Http\Controllers\Ticket\TicketIncidentTypeController; use App\Http\Controllers\Material\MaterialController; Route::post('/login', [AuthController::class, 'login']); @@ -30,6 +31,7 @@ Route::middleware('auth:sanctum')->group(function () { Route::apiResource('tickets', TicketController::class); Route::apiResource('ticket-types', TicketTypeController::class); + Route::apiResource('ticket-incident-types', TicketIncidentTypeController::class); Route::prefix('tickets/{ticket}') ->controller(TicketWorkflowController::class) @@ -67,5 +69,6 @@ Route::middleware('auth:sanctum')->group(function () { Route::get('/history/{barcode_id}', [MaterialController::class, 'history']); }); + });