소스 검색

feat(support): altera migration e adiciona escopo e setor

ebagabee 4 주 전
부모
커밋
408ea0905d

+ 7 - 2
app/Http/Controllers/SupportTicketController.php

@@ -21,7 +21,11 @@ public function index(): JsonResponse
 
     public function store(SupportTicketRequest $request): JsonResponse
     {
-        $item = $this->service->create($request->validated());
+        $data = $request->validated();
+        $data['applicant_user_id'] = auth()->id();
+        $data['responsable_user_id'] = auth()->id();
+
+        $item = $this->service->create($data);
         return $this->successResponse(payload: new SupportTicketResource($item), message: __('messages.created'), code: 201);
     }
 
@@ -33,7 +37,8 @@ public function show(int $id): JsonResponse
 
     public function update(SupportTicketRequest $request, int $id): JsonResponse
     {
-        $item = $this->service->update($id, $request->validated());
+        $data = $request->validated();
+        $item = $this->service->update($id, $data);
         return $this->successResponse(payload: new SupportTicketResource($item), message: __('messages.updated'));
     }
 

+ 7 - 21
app/Http/Requests/SupportTicketRequest.php

@@ -8,27 +8,13 @@ class SupportTicketRequest extends FormRequest
 {
     public function rules(): array
     {
-        $rules = [
-            // Add your validation rules here
-            //'field' => 'sometimes|string|max:255',
+        return [
+            'title'       => 'required|string|max:255',
+            'description' => 'nullable|string',
+            'severity'    => 'required|string|in:alta,normal,baixa',
+            'scope'       => 'required|string|in:all,internal,specific',
+            'unit_id'     => 'nullable|integer|exists:units,id',
+            'sector'      => 'nullable|string|max:255',
         ];
-
-        // Different rules for creation
-        //if ($this->isMethod('POST')) {
-            // Make fields required if needed
-            // $rules['field'] = 'required|string|max:255';
-        //}
-
-        return $rules;
     }
-
-    /**
-    * Add custom messages when needed
-    * public function messages(): array
-    * {
-    *   return [
-    *        'field.required' => __('message.algo'),
-    *    ];
-    * }
-    */
 }

+ 12 - 18
app/Http/Resources/SupportTicketResource.php

@@ -10,27 +10,21 @@
 
 class SupportTicketResource extends JsonResource
 {
-    /**
-     * Transform the resource into an array.
-     *
-     * @return array<string, mixed>
-     */
     public function toArray(Request $request): array
     {
         return [
-            'id' => $this->id,
-            'name' => $this->name,
-            'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
-            'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
-            // Add your fields here
-
-            // Conditional fields
-            // $this->mergeWhen($request->user()?->isAdmin(), [
-            //     'internal_notes' => $this->internal_notes,
-            // ]),
-
-            // Relationships
-            // 'user' => new UserResource($this->whenLoaded('user')),
+            'id'                   => $this->id,
+            'title'                => $this->title,
+            'description'          => $this->description,
+            'severity'             => $this->severity,
+            'scope'                => $this->scope,
+            'unit_id'              => $this->unit_id,
+            'sector'               => $this->sector,
+            'support_status_id'    => $this->support_status_id,
+            'applicant_user_id'    => $this->applicant_user_id,
+            'responsable_user_id'  => $this->responsable_user_id,
+            'created_at'           => Carbon::parse($this->created_at)->format('d/m/Y H:i'),
+            'updated_at'           => Carbon::parse($this->updated_at)->format('d/m/Y H:i'),
         ];
     }
 

+ 33 - 0
database/migrations/2026_05_18_165110_modify_support_tickets_add_scope_sector.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    public function up(): void
+    {
+        Schema::table('support_tickets', function (Blueprint $table) {
+            $table->unsignedBigInteger('unit_id')->nullable()->change();
+            $table->unsignedBigInteger('student_id')->nullable()->change();
+            $table->unsignedBigInteger('support_status_id')->nullable()->change();
+            $table->unsignedBigInteger('responsable_user_id')->nullable()->change();
+
+            $table->string('scope')->nullable()->after('unit_id');
+            $table->string('sector')->nullable()->after('description');
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::table('support_tickets', function (Blueprint $table) {
+            $table->dropColumn(['scope', 'sector']);
+
+            $table->unsignedBigInteger('unit_id')->nullable(false)->change();
+            $table->unsignedBigInteger('student_id')->nullable(false)->change();
+            $table->unsignedBigInteger('support_status_id')->nullable(false)->change();
+            $table->unsignedBigInteger('responsable_user_id')->nullable(false)->change();
+        });
+    }
+};