Ubah dari Swagger ke Dedoc lalu buat API Ticket dan TicketType
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Traits\ApiResponse;
|
||||
|
||||
class ApiController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
}
|
||||
@@ -5,38 +5,10 @@ namespace App\Http\Controllers;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
#[OA\Post(
|
||||
path: "/api/login",
|
||||
summary: "Login User",
|
||||
tags: ["Authentication"]
|
||||
)]
|
||||
#[OA\RequestBody(
|
||||
required: true,
|
||||
content: new OA\JsonContent(
|
||||
required: ["email", "password"],
|
||||
properties: [
|
||||
new OA\Property(
|
||||
property: "email",
|
||||
type: "string",
|
||||
example: "admin@test.co.id"
|
||||
),
|
||||
new OA\Property(
|
||||
property: "password",
|
||||
type: "string",
|
||||
example: "123456"
|
||||
)
|
||||
]
|
||||
)
|
||||
)]
|
||||
#[OA\Response(
|
||||
response: 200,
|
||||
description: "Login Success"
|
||||
)]
|
||||
|
||||
|
||||
public function login(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Ticket;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Http\Requests\Ticket\StoreTicketRequest;
|
||||
use App\Http\Requests\Ticket\UpdateTicketRequest;
|
||||
use App\Http\Resources\Ticket\TicketResource;
|
||||
use App\Models\Ticket;
|
||||
use App\Services\Ticket\TicketService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TicketController extends ApiController
|
||||
{
|
||||
public function __construct(
|
||||
protected TicketService $service
|
||||
) {}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$tickets = Ticket::latest()->paginate(
|
||||
$request->get('per_page', 10)
|
||||
);
|
||||
|
||||
return $this->success($tickets);
|
||||
}
|
||||
|
||||
public function store(StoreTicketRequest $request)
|
||||
{
|
||||
$ticket = $this->service->create(
|
||||
$request->validated()
|
||||
);
|
||||
|
||||
return $this->created(
|
||||
new TicketResource($ticket),
|
||||
'Ticket berhasil dibuat'
|
||||
);
|
||||
}
|
||||
|
||||
public function show(Ticket $ticket)
|
||||
{
|
||||
return $this->success(
|
||||
new TicketResource($ticket)
|
||||
);
|
||||
}
|
||||
|
||||
public function update(
|
||||
UpdateTicketRequest $request,
|
||||
Ticket $ticket
|
||||
) {
|
||||
$ticket = $this->service->update(
|
||||
$ticket,
|
||||
$request->validated()
|
||||
);
|
||||
|
||||
return $this->updated(
|
||||
new TicketResource($ticket),
|
||||
'Ticket berhasil diperbarui'
|
||||
);
|
||||
}
|
||||
|
||||
public function destroy(Ticket $ticket)
|
||||
{
|
||||
$this->service->delete($ticket);
|
||||
|
||||
return $this->deleted(
|
||||
'Ticket berhasil dibatalkan'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Ticket;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Http\Requests\TicketType\StoreTicketTypeRequest;
|
||||
use App\Http\Requests\TicketType\UpdateTicketTypeRequest;
|
||||
use App\Http\Resources\TicketType\TicketTypeResource;
|
||||
use App\Models\TicketType;
|
||||
use App\Services\Ticket\TicketTypeService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TicketTypeController extends ApiController
|
||||
{
|
||||
public function __construct(
|
||||
protected TicketTypeService $service
|
||||
) {}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$data = TicketType::latest()->paginate(
|
||||
$request->get('per_page', 10)
|
||||
);
|
||||
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
public function store(StoreTicketTypeRequest $request)
|
||||
{
|
||||
$type = $this->service->create(
|
||||
$request->validated()
|
||||
);
|
||||
|
||||
return $this->created(
|
||||
new TicketTypeResource($type),
|
||||
'Ticket Type berhasil dibuat'
|
||||
);
|
||||
}
|
||||
|
||||
public function show(TicketType $ticket_type)
|
||||
{
|
||||
return $this->success(
|
||||
new TicketTypeResource($ticket_type)
|
||||
);
|
||||
}
|
||||
|
||||
public function update(
|
||||
UpdateTicketTypeRequest $request,
|
||||
TicketType $ticket_type
|
||||
) {
|
||||
$type = $this->service->update(
|
||||
$ticket_type,
|
||||
$request->validated()
|
||||
);
|
||||
|
||||
return $this->updated(
|
||||
new TicketTypeResource($type),
|
||||
'Ticket Type berhasil diupdate'
|
||||
);
|
||||
}
|
||||
|
||||
public function destroy(TicketType $ticket_type)
|
||||
{
|
||||
$this->service->delete($ticket_type);
|
||||
|
||||
return $this->deleted(
|
||||
'Ticket Type berhasil dihapus'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Ticket;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreTicketRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'ticket_type_id' => 'required|integer',
|
||||
'customer_id' => 'nullable|integer',
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'priority' => 'required|in:low,medium,high,critical'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Ticket;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateTicketRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'ticket_type_id' => 'sometimes|integer',
|
||||
'customer_id' => 'nullable|integer',
|
||||
'title' => 'sometimes|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'priority' => 'sometimes|in:low,medium,high,critical',
|
||||
'status' => 'sometimes|in:draft,open,approved,assigned,progress,pending,resolved,closed,cancelled,rejected'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\TicketType;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreTicketTypeRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'code' => 'required|string|max:50|unique:ticket_types,code',
|
||||
'name' => 'required|string|max:100',
|
||||
'need_approval' => 'boolean',
|
||||
'sla_minutes' => 'nullable|integer'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\TicketType;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateTicketTypeRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'code' => 'sometimes|string|max:50|unique:ticket_types,code,' . $this->route('ticket_type'),
|
||||
'name' => 'sometimes|string|max:100',
|
||||
'need_approval' => 'sometimes|boolean',
|
||||
'sla_minutes' => 'nullable|integer'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Ticket;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TicketResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'ticket_no' => $this->ticket_no,
|
||||
'ticket_type_id' => $this->ticket_type_id,
|
||||
'customer_id' => $this->customer_id,
|
||||
'title' => $this->title,
|
||||
'description' => $this->description,
|
||||
'priority' => $this->priority,
|
||||
'status' => $this->status,
|
||||
'created_by' => $this->created_by,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\TicketType;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TicketTypeResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'need_approval' => $this->need_approval,
|
||||
'sla_minutes' => $this->sla_minutes,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user