migrate to gtea from bistbucket

This commit is contained in:
2026-03-15 17:08:23 +07:00
commit 129ca2260c
3716 changed files with 566316 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
<?php
namespace Modules\SupportTicket\Http\Controllers\API;
use App\Http\Controllers\Controller;
use Exception;
use Illuminate\Http\JsonResponse;
use Modules\SupportTicket\Http\Requests\SupportTicketCategory\SupportTicketCategoryStoreRequest;
use Modules\SupportTicket\Http\Requests\SupportTicketCategory\SupportTicketCategoryUpdateRequest;
use Modules\SupportTicket\Repositories\SupportTicketCategoryRepository;
class SupportTicketCategoryController extends Controller
{
public function __construct(private SupportTicketCategoryRepository $repo) {}
public function index(): JsonResponse
{
try {
return $this->responseSuccess($this->repo->getAll(request()->all()), 'SupportTicketCategory has been fetched successfully.');
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
public function store(SupportTicketCategoryStoreRequest $request): JsonResponse
{
try {
return $this->responseSuccess($this->repo->create($request->all()), 'SupportTicketCategory has been created successfully.');
} catch (\Illuminate\Database\QueryException $exception) {
return $this->responseError([], 'Database error: '.$exception->getMessage());
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
public function show(int $id): JsonResponse
{
try {
return $this->responseSuccess($this->repo->getById($id), 'SupportTicketCategory has been fetched successfully.');
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
public function update(SupportTicketCategoryUpdateRequest $request, int $id): JsonResponse
{
try {
return $this->responseSuccess($this->repo->update($id, $request->all()), 'SupportTicketCategory has been updated successfully.');
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
public function destroy(int $id): JsonResponse
{
try {
return $this->responseSuccess($this->repo->delete($id), 'SupportTicketCategory has been deleted successfully.');
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
}

View File

@@ -0,0 +1,152 @@
<?php
namespace Modules\SupportTicket\Http\Controllers\API;
use App\Http\Controllers\Controller;
use App\Services\Firebase\FirebaseService;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Modules\SupportTicket\Http\Requests\SupportTicket\SupportTicketReplyRequest;
use Modules\SupportTicket\Http\Requests\SupportTicket\SupportTicketStoreRequest;
use Modules\SupportTicket\Http\Requests\SupportTicket\SupportTicketUpdateRequest;
use Modules\SupportTicket\Models\SupportTicket;
use Modules\SupportTicket\Models\SupportTicketConversation;
use Modules\SupportTicket\Repositories\SupportTicketRepository;
class SupportTicketController extends Controller
{
public function __construct(private SupportTicketRepository $repo) {}
public function index(): JsonResponse
{
try {
return $this->responseSuccess($this->repo->getAll(request()->all()), 'SupportTicket has been fetched successfully.');
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
public function store(SupportTicketStoreRequest $request): JsonResponse
{
try {
return $this->responseSuccess($this->repo->create($request->all()), 'SupportTicket has been created successfully.');
} catch (\Illuminate\Database\QueryException $exception) {
return $this->responseError([], 'Database error: '.$exception->getMessage());
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
public function show(int $id): JsonResponse
{
$supportTicket = SupportTicket::with('user', 'category', 'lastTicketConversation', 'supportLicenses', 'conversations')->find($id);
try {
return $this->responseSuccess($supportTicket, 'SupportTicket has been fetched successfully.');
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
public function update(SupportTicketUpdateRequest $request, int $id): JsonResponse
{
try {
return $this->responseSuccess($this->repo->update($id, $request->all()), 'SupportTicket has been updated successfully.');
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
public function destroy(int $id): JsonResponse
{
try {
return $this->responseSuccess($this->repo->delete($id), 'SupportTicket has been deleted successfully.');
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
public function ticketReply(Request $request, int $ticketId): JsonResponse
{
$perPage = (int) $request->per_page ?: 10;
$supportTicketConversations = SupportTicketConversation::with('ticket', 'user')->where('ticket_id', $ticketId)
->orderBy('id', 'desc')
->paginate($perPage);
if (! $supportTicketConversations) {
return $this->ResponseError([], 'Something went wrong. Conversation cannot be found.', 404);
}
// Ensure attachments are properly decoded before returning the response
$supportTicketConversations->getCollection()->transform(function ($conversation) {
$conversation->attachments = is_string($conversation->attachments)
? json_decode($conversation->attachments, true) ?? []
: $conversation->attachments;
return $conversation;
});
return $this->ResponseSuccess($supportTicketConversations, 'Ticket Conversation has been fetched.');
}
public function myTickets(Request $request): JsonResponse
{
$query = SupportTicket::query();
$tickets = $query->where('user_id', Auth::id())
->orderBy('id', 'desc')
->with('user', 'category', 'restaurant', 'lastTicketConversation', 'conversations', 'supportLicenses')
->paginate($request->perPage);
return $this->ResponseSuccess($tickets, 'Ticket fetch successfully.');
}
public function reply(SupportTicketReplyRequest $request, FirebaseService $firebase): JsonResponse
{
$data = $request->validated();
$data['user_id'] = auth()->user()->id;
$data['attachments'] = null;
if ($request->hasFile('attachments')) {
$attachments = [];
foreach ($request->file('attachments') as $file) {
$path = $file->store('uploads/tickets', 'public'); // Store in storage/app/public/uploads/tickets
$attachments[] = asset('storage/'.$path);
}
$data['attachments'] = json_encode($attachments); // Store as array
}
$reply = SupportTicketConversation::create($data);
// $supportTicket = SupportTicket::find($data['ticket_id']);
// $token = $supportTicket->user->fcm_token;
// if ($token) {
// $firebase->sendNotification(
// $token,
// 'New Reply on Your Ticket',
// 'Check the latest reply on your support ticket.',
// ['ticket_id' => $supportTicket->id]
// );
// }
if (! $reply) {
return $this->ResponseError([], 'Something went wrong. supportTicket Reply cannot be sent.');
}
return $this->ResponseSuccess($reply, 'supportTicket Reply has been sent.');
}
public function closeTicket(int $ticketId): JsonResponse
{
$supportTicket = SupportTicket::find($ticketId);
if (! $supportTicket) {
return $this->ResponseError([], 'Something went wrong. supportTicket cannot be closed.', 404);
}
$supportTicket->update([
'status' => 'closed',
]);
return $this->ResponseSuccess([], 'supportTicket has been closed.');
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace Modules\SupportTicket\Http\Controllers\API;
use App\Http\Controllers\Controller;
use Exception;
use Illuminate\Http\JsonResponse;
use Modules\SupportTicket\Http\Requests\SupportTicketFAQ\SupportTicketFAQStoreRequest;
use Modules\SupportTicket\Http\Requests\SupportTicketFAQ\SupportTicketFAQUpdateRequest;
use Modules\SupportTicket\Repositories\SupportTicketFAQRepository;
class SupportTicketFAQController extends Controller
{
public function __construct(private SupportTicketFAQRepository $repo) {}
public function index(): JsonResponse
{
try {
return $this->responseSuccess($this->repo->getAll(request()->all()), 'SupportTicketFAQ has been fetched successfully.');
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
public function store(SupportTicketFAQStoreRequest $request): JsonResponse
{
try {
return $this->responseSuccess($this->repo->create($request->all()), 'SupportTicketFAQ has been created successfully.');
} catch (\Illuminate\Database\QueryException $exception) {
return $this->responseError([], 'Database error: '.$exception->getMessage());
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
public function show(int $id): JsonResponse
{
try {
return $this->responseSuccess($this->repo->getById($id), 'SupportTicketFAQ has been fetched successfully.');
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
public function update(SupportTicketFAQUpdateRequest $request, int $id): JsonResponse
{
try {
return $this->responseSuccess($this->repo->update($id, $request->all()), 'SupportTicketFAQ has been updated successfully.');
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
public function destroy(int $id): JsonResponse
{
try {
return $this->responseSuccess($this->repo->delete($id), 'SupportTicketFAQ has been deleted successfully.');
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace Modules\SupportTicket\Http\Controllers\API;
use App\Http\Controllers\Controller;
use Exception;
use Illuminate\Http\JsonResponse;
use Modules\SupportTicket\Http\Requests\SupportTicketLicense\SupportTicketLicenseStoreRequest;
use Modules\SupportTicket\Http\Requests\SupportTicketLicense\SupportTicketLicenseUpdateRequest;
use Modules\SupportTicket\Repositories\SupportTicketLicenseRepository;
class SupportTicketLicenseController extends Controller
{
public function __construct(private SupportTicketLicenseRepository $repo) {}
public function index(): JsonResponse
{
try {
return $this->responseSuccess($this->repo->getAll(request()->all()), 'SupportTicketLicense has been fetched successfully.');
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
public function store(SupportTicketLicenseStoreRequest $request): JsonResponse
{
try {
return $this->responseSuccess($this->repo->create($request->all()), 'SupportTicketLicense has been created successfully.');
} catch (\Illuminate\Database\QueryException $exception) {
return $this->responseError([], 'Database error: '.$exception->getMessage());
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
public function show(int $id): JsonResponse
{
try {
return $this->responseSuccess($this->repo->getById($id), 'SupportTicketLicense has been fetched successfully.');
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
public function update(SupportTicketLicenseUpdateRequest $request, int $id): JsonResponse
{
try {
return $this->responseSuccess($this->repo->update($id, $request->all()), 'SupportTicketLicense has been updated successfully.');
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
public function destroy(int $id): JsonResponse
{
try {
return $this->responseSuccess($this->repo->delete($id), 'SupportTicketLicense has been deleted successfully.');
} catch (Exception $e) {
return $this->responseError([], $e->getMessage());
}
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Modules\SupportTicket\Http\Requests\SupportTicket;
use Illuminate\Foundation\Http\FormRequest;
class SupportTicketReplyRequest extends FormRequest
{
public function rules(): array
{
return [
'user_type' => 'nullable|string|in:user,agent,admin',
'ticket_id' => 'required|exists:support_tickets,id',
'message' => 'required|string|max:1000',
'conversation_type' => 'nullable|string',
'attachments' => 'nullable|array',
];
}
public function authorize(): bool
{
return true;
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Modules\SupportTicket\Http\Requests\SupportTicket;
use Illuminate\Foundation\Http\FormRequest;
class SupportTicketStoreRequest extends FormRequest
{
public function rules(): array
{
return [
'title' => 'required|string|max:255',
'description' => 'required|string',
'category_id' => 'nullable|exists:categories,id',
'purchase_code' => 'nullable|string',
'related_url' => 'nullable|url',
'support_plan' => 'nullable|string',
'attachments' => 'nullable',
];
}
public function authorize(): bool
{
return true;
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Modules\SupportTicket\Http\Requests\SupportTicket;
use Illuminate\Foundation\Http\FormRequest;
class SupportTicketUpdateRequest extends FormRequest
{
public function rules(): array
{
return [
'title' => 'required|string|max:255',
'description' => 'required|string',
'category_id' => 'nullable|exists:categories,id',
'purchase_code' => 'nullable|string',
'related_url' => 'nullable|url',
'support_plan' => 'nullable|string',
'attachments' => 'nullable',
];
}
public function authorize(): bool
{
return true;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Modules\SupportTicket\Http\Requests\SupportTicketCategory;
use Illuminate\Foundation\Http\FormRequest;
class SupportTicketCategoryStoreRequest extends FormRequest
{
public function rules(): array
{
return [
'name' => 'required|string|max:255',
'description' => 'nullable|string|max:1000',
];
}
public function authorize(): bool
{
return true;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Modules\SupportTicket\Http\Requests\SupportTicketCategory;
use Illuminate\Foundation\Http\FormRequest;
class SupportTicketCategoryUpdateRequest extends FormRequest
{
public function rules(): array
{
return [
'name' => 'required|string|max:255',
'description' => 'nullable|string|max:1000',
];
}
public function authorize(): bool
{
return true;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Modules\SupportTicket\Http\Requests\SupportTicketFAQ;
use Illuminate\Foundation\Http\FormRequest;
class SupportTicketFAQStoreRequest extends FormRequest
{
public function rules(): array
{
return [
'question' => 'required|string|max:255',
'answer' => 'required|string|max:1000',
];
}
public function authorize(): bool
{
return true;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Modules\SupportTicket\Http\Requests\SupportTicketFAQ;
use Illuminate\Foundation\Http\FormRequest;
class SupportTicketFAQUpdateRequest extends FormRequest
{
public function rules(): array
{
return [
'question' => 'required|string|max:255',
'answer' => 'required|string|max:1000',
];
}
public function authorize(): bool
{
return true;
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Modules\SupportTicket\Http\Requests\SupportTicketLicense;
use Illuminate\Foundation\Http\FormRequest;
class SupportTicketLicenseStoreRequest extends FormRequest
{
public function rules(): array
{
return [
// validation rules
];
}
public function authorize(): bool
{
return true;
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Modules\SupportTicket\Http\Requests\SupportTicketLicense;
use Illuminate\Foundation\Http\FormRequest;
class SupportTicketLicenseUpdateRequest extends FormRequest
{
public function rules(): array
{
return [
// validation rules
];
}
public function authorize(): bool
{
return true;
}
}