From 8b8e480d53a709dc727016cd01deb70425f41df3 Mon Sep 17 00:00:00 2001 From: Mohammad Hafijul Islam Date: Mon, 4 Dec 2023 02:25:44 +0600 Subject: [PATCH] chat option stub added --- composer.json | 5 +- config/chat.php | 36 +++ ..._12_03_194233_create_chat_groups_table.php | 37 +++ ..._194247_create_chat_participants_table.php | 37 +++ ...2_03_194256_create_chat_messages_table.php | 37 +++ .../migrations/create_chat_table.php.stub | 19 -- routes/api.php | 11 +- src/Chat.php | 27 ++ src/Facades/Chat.php | 3 + src/Http/Controllers/ChatGroupController.php | 285 ++++++++++++++++++ .../Controllers/ChatMessageController.php | 285 ++++++++++++++++++ .../Controllers/ChatParticipantController.php | 285 ++++++++++++++++++ src/Http/Requests/ImportChatGroupRequest.php | 53 ++++ .../Requests/ImportChatMessageRequest.php | 53 ++++ .../Requests/ImportChatParticipantRequest.php | 53 ++++ src/Http/Requests/IndexChatGroupRequest.php | 60 ++++ src/Http/Requests/IndexChatMessageRequest.php | 60 ++++ .../Requests/IndexChatParticipantRequest.php | 60 ++++ src/Http/Requests/StoreChatGroupRequest.php | 53 ++++ src/Http/Requests/StoreChatMessageRequest.php | 53 ++++ .../Requests/StoreChatParticipantRequest.php | 53 ++++ src/Http/Requests/UpdateChatGroupRequest.php | 53 ++++ .../Requests/UpdateChatMessageRequest.php | 53 ++++ .../Requests/UpdateChatParticipantRequest.php | 53 ++++ src/Http/Resources/ChatGroupCollection.php | 39 +++ src/Http/Resources/ChatGroupResource.php | 19 ++ src/Http/Resources/ChatMessageCollection.php | 39 +++ src/Http/Resources/ChatMessageResource.php | 19 ++ .../Resources/ChatParticipantCollection.php | 39 +++ .../Resources/ChatParticipantResource.php | 19 ++ src/Interfaces/ChatGroupRepository.php | 64 ++++ src/Interfaces/ChatMessageRepository.php | 64 ++++ src/Interfaces/ChatParticipantRepository.php | 64 ++++ src/Models/.gitkeep | 0 src/Models/ChatGroup.php | 95 ++++++ src/Models/ChatMessage.php | 92 ++++++ src/Models/ChatParticipant.php | 82 +++++ .../Eloquent/ChatGroupRepository.php | 61 ++++ .../Eloquent/ChatMessageRepository.php | 61 ++++ .../Eloquent/ChatParticipantRepository.php | 61 ++++ .../Mongodb/ChatGroupRepository.php | 61 ++++ .../Mongodb/ChatMessageRepository.php | 61 ++++ .../Mongodb/ChatParticipantRepository.php | 61 ++++ src/Seeders/ChatGroupSeeder.php | 29 ++ src/Seeders/ChatMessageSeeder.php | 29 ++ src/Seeders/ChatParticipantSeeder.php | 29 ++ src/Services/ChatGroupService.php | 67 ++++ src/Services/ChatMessageService.php | 67 ++++ src/Services/ChatParticipantService.php | 67 ++++ 49 files changed, 2991 insertions(+), 22 deletions(-) create mode 100644 database/migrations/2023_12_03_194233_create_chat_groups_table.php create mode 100644 database/migrations/2023_12_03_194247_create_chat_participants_table.php create mode 100644 database/migrations/2023_12_03_194256_create_chat_messages_table.php delete mode 100644 database/migrations/create_chat_table.php.stub create mode 100644 src/Http/Controllers/ChatGroupController.php create mode 100644 src/Http/Controllers/ChatMessageController.php create mode 100644 src/Http/Controllers/ChatParticipantController.php create mode 100644 src/Http/Requests/ImportChatGroupRequest.php create mode 100644 src/Http/Requests/ImportChatMessageRequest.php create mode 100644 src/Http/Requests/ImportChatParticipantRequest.php create mode 100644 src/Http/Requests/IndexChatGroupRequest.php create mode 100644 src/Http/Requests/IndexChatMessageRequest.php create mode 100644 src/Http/Requests/IndexChatParticipantRequest.php create mode 100644 src/Http/Requests/StoreChatGroupRequest.php create mode 100644 src/Http/Requests/StoreChatMessageRequest.php create mode 100644 src/Http/Requests/StoreChatParticipantRequest.php create mode 100644 src/Http/Requests/UpdateChatGroupRequest.php create mode 100644 src/Http/Requests/UpdateChatMessageRequest.php create mode 100644 src/Http/Requests/UpdateChatParticipantRequest.php create mode 100644 src/Http/Resources/ChatGroupCollection.php create mode 100644 src/Http/Resources/ChatGroupResource.php create mode 100644 src/Http/Resources/ChatMessageCollection.php create mode 100644 src/Http/Resources/ChatMessageResource.php create mode 100644 src/Http/Resources/ChatParticipantCollection.php create mode 100644 src/Http/Resources/ChatParticipantResource.php create mode 100644 src/Interfaces/ChatGroupRepository.php create mode 100644 src/Interfaces/ChatMessageRepository.php create mode 100644 src/Interfaces/ChatParticipantRepository.php delete mode 100644 src/Models/.gitkeep create mode 100644 src/Models/ChatGroup.php create mode 100644 src/Models/ChatMessage.php create mode 100644 src/Models/ChatParticipant.php create mode 100644 src/Repositories/Eloquent/ChatGroupRepository.php create mode 100644 src/Repositories/Eloquent/ChatMessageRepository.php create mode 100644 src/Repositories/Eloquent/ChatParticipantRepository.php create mode 100644 src/Repositories/Mongodb/ChatGroupRepository.php create mode 100644 src/Repositories/Mongodb/ChatMessageRepository.php create mode 100644 src/Repositories/Mongodb/ChatParticipantRepository.php create mode 100644 src/Seeders/ChatGroupSeeder.php create mode 100644 src/Seeders/ChatMessageSeeder.php create mode 100644 src/Seeders/ChatParticipantSeeder.php create mode 100644 src/Services/ChatGroupService.php create mode 100644 src/Services/ChatMessageService.php create mode 100644 src/Services/ChatParticipantService.php diff --git a/composer.json b/composer.json index ef7931c..2ffb1e5 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ "php": "^8.1", "fintech/core": "*", "illuminate/contracts": "^10.0", - "owen-it/laravel-auditing": "^13.5" + "owen-it/laravel-auditing": "^13.5", + "spatie/laravel-medialibrary": "^10.13" }, "require-dev": { "laravel/pint": "^1.0", @@ -69,4 +70,4 @@ }, "minimum-stability": "dev", "prefer-stable": true -} \ No newline at end of file +} diff --git a/config/chat.php b/config/chat.php index cbde31d..5605362 100644 --- a/config/chat.php +++ b/config/chat.php @@ -24,6 +24,36 @@ 'root_prefix' => 'test/', + + /* + |-------------------------------------------------------------------------- + | ChatGroup Model + |-------------------------------------------------------------------------- + | + | This value will be used to across system where model is needed + */ + 'chat_group_model' => \Fintech\Chat\Models\ChatGroup::class, + + + /* + |-------------------------------------------------------------------------- + | ChatParticipant Model + |-------------------------------------------------------------------------- + | + | This value will be used to across system where model is needed + */ + 'chat_participant_model' => \Fintech\Chat\Models\ChatParticipant::class, + + + /* + |-------------------------------------------------------------------------- + | ChatMessage Model + |-------------------------------------------------------------------------- + | + | This value will be used to across system where model is needed + */ + 'chat_message_model' => \Fintech\Chat\Models\ChatMessage::class, + //** Model Config Point Do not Remove **// /* @@ -35,6 +65,12 @@ */ 'repositories' => [ + \Fintech\Chat\Interfaces\ChatGroupRepository::class => \Fintech\Chat\Repositories\Eloquent\ChatGroupRepository::class, + + \Fintech\Chat\Interfaces\ChatParticipantRepository::class => \Fintech\Chat\Repositories\Eloquent\ChatParticipantRepository::class, + + \Fintech\Chat\Interfaces\ChatMessageRepository::class => \Fintech\Chat\Repositories\Eloquent\ChatMessageRepository::class, + //** Repository Binding Config Point Do not Remove **// ], diff --git a/database/migrations/2023_12_03_194233_create_chat_groups_table.php b/database/migrations/2023_12_03_194233_create_chat_groups_table.php new file mode 100644 index 0000000..d9afebe --- /dev/null +++ b/database/migrations/2023_12_03_194233_create_chat_groups_table.php @@ -0,0 +1,37 @@ +id(); + $table->string('name'); + $table->string('link')->nullable(); + $table->string('type')->default('direct'); + $table->json('chat_group_data')->nullable(); + $table->foreignId('creator_id')->nullable(); + $table->foreignId('editor_id')->nullable(); + $table->foreignId('destroyer_id')->nullable(); + $table->foreignId('restorer_id')->nullable(); + $table->timestamps(); + $table->softDeletes(); + $table->timestamp('restored_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('chat_groups'); + } +}; diff --git a/database/migrations/2023_12_03_194247_create_chat_participants_table.php b/database/migrations/2023_12_03_194247_create_chat_participants_table.php new file mode 100644 index 0000000..bc4d157 --- /dev/null +++ b/database/migrations/2023_12_03_194247_create_chat_participants_table.php @@ -0,0 +1,37 @@ +id(); + $table->foreignId('chart_group_id'); + $table->morphs('model'); + $table->boolean('enabled')->default(true); + $table->json('chat_participant_data')->nullable(); + $table->foreignId('creator_id')->nullable(); + $table->foreignId('editor_id')->nullable(); + $table->foreignId('destroyer_id')->nullable(); + $table->foreignId('restorer_id')->nullable(); + $table->timestamps(); + $table->softDeletes(); + $table->timestamp('restored_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('chat_participants'); + } +}; diff --git a/database/migrations/2023_12_03_194256_create_chat_messages_table.php b/database/migrations/2023_12_03_194256_create_chat_messages_table.php new file mode 100644 index 0000000..18bb47d --- /dev/null +++ b/database/migrations/2023_12_03_194256_create_chat_messages_table.php @@ -0,0 +1,37 @@ +id(); + $table->foreignId('chat_group_id'); + $table->foreignId('chat_participant_id'); + $table->longText('content'); + $table->json('chat_messages_data')->nullable(); + $table->foreignId('creator_id')->nullable(); + $table->foreignId('editor_id')->nullable(); + $table->foreignId('destroyer_id')->nullable(); + $table->foreignId('restorer_id')->nullable(); + $table->timestamps(); + $table->softDeletes(); + $table->timestamp('restored_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('chat_messages'); + } +}; diff --git a/database/migrations/create_chat_table.php.stub b/database/migrations/create_chat_table.php.stub deleted file mode 100644 index 3c1c3ae..0000000 --- a/database/migrations/create_chat_table.php.stub +++ /dev/null @@ -1,19 +0,0 @@ -id(); - - // add fields - - $table->timestamps(); - }); - } -}; diff --git a/routes/api.php b/routes/api.php index 647eb45..eb03f34 100644 --- a/routes/api.php +++ b/routes/api.php @@ -16,6 +16,15 @@ if (Config::get('fintech.chat.enabled')) { Route::prefix('chat')->name('chat.')->group(function () { - //DO NOT REMOVE THIS LINE// + Route::apiResource('chat-groups', \Fintech\Chat\Http\Controllers\ChatGroupController::class); + Route::post('chat-groups/{chat_group}/restore', [\Fintech\Chat\Http\Controllers\ChatGroupController::class, 'restore'])->name('chat-groups.restore'); + + Route::apiResource('chat-participants', \Fintech\Chat\Http\Controllers\ChatParticipantController::class); + Route::post('chat-participants/{chat_participant}/restore', [\Fintech\Chat\Http\Controllers\ChatParticipantController::class, 'restore'])->name('chat-participants.restore'); + + Route::apiResource('chat-messages', \Fintech\Chat\Http\Controllers\ChatMessageController::class); + Route::post('chat-messages/{chat_message}/restore', [\Fintech\Chat\Http\Controllers\ChatMessageController::class, 'restore'])->name('chat-messages.restore'); + + //DO NOT REMOVE THIS LINE// }); } diff --git a/src/Chat.php b/src/Chat.php index 0dab6cd..636b55a 100644 --- a/src/Chat.php +++ b/src/Chat.php @@ -4,5 +4,32 @@ class Chat { + /** + * @return \Fintech\Chat\Services\ChatGroupService + */ + public function chatGroup() + { + return app(\Fintech\Chat\Services\ChatGroupService::class); + } + + /** + * @return \Fintech\Chat\Services\ChatParticipantService + */ + public function chatParticipant() + { + return app(\Fintech\Chat\Services\ChatParticipantService::class); + } + + /** + * @return \Fintech\Chat\Services\ChatMessageService + */ + public function chatMessage() + { + return app(\Fintech\Chat\Services\ChatMessageService::class); + } + //** Crud Service Method Point Do not Remove **// + + + } diff --git a/src/Facades/Chat.php b/src/Facades/Chat.php index 3d22d4b..f3867a7 100644 --- a/src/Facades/Chat.php +++ b/src/Facades/Chat.php @@ -5,6 +5,9 @@ use Illuminate\Support\Facades\Facade; /** + * @method static \Fintech\Chat\Services\ChatGroupService chatGroup() + * @method static \Fintech\Chat\Services\ChatParticipantService chatParticipant() + * @method static \Fintech\Chat\Services\ChatMessageService chatMessage() * // Crud Service Method Point Do not Remove // * * @see \Fintech\Chat\Chat diff --git a/src/Http/Controllers/ChatGroupController.php b/src/Http/Controllers/ChatGroupController.php new file mode 100644 index 0000000..6ef7c39 --- /dev/null +++ b/src/Http/Controllers/ChatGroupController.php @@ -0,0 +1,285 @@ +validated(); + + $chatGroupPaginate = Chat::chatGroup()->list($inputs); + + return new ChatGroupCollection($chatGroupPaginate); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Create a new *ChatGroup* resource in storage. + * @lrd:end + * + * @param StoreChatGroupRequest $request + * @return JsonResponse + * @throws StoreOperationException + */ + public function store(StoreChatGroupRequest $request): JsonResponse + { + try { + $inputs = $request->validated(); + + $chatGroup = Chat::chatGroup()->create($inputs); + + if (!$chatGroup) { + throw (new StoreOperationException)->setModel(config('fintech.chat.chat_group_model')); + } + + return $this->created([ + 'message' => __('core::messages.resource.created', ['model' => 'Chat Group']), + 'id' => $chatGroup->id + ]); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Return a specified *ChatGroup* resource found by id. + * @lrd:end + * + * @param string|int $id + * @return ChatGroupResource|JsonResponse + * @throws ModelNotFoundException + */ + public function show(string|int $id): ChatGroupResource|JsonResponse + { + try { + + $chatGroup = Chat::chatGroup()->find($id); + + if (!$chatGroup) { + throw (new ModelNotFoundException)->setModel(config('fintech.chat.chat_group_model'), $id); + } + + return new ChatGroupResource($chatGroup); + + } catch (ModelNotFoundException $exception) { + + return $this->notfound($exception->getMessage()); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Update a specified *ChatGroup* resource using id. + * @lrd:end + * + * @param UpdateChatGroupRequest $request + * @param string|int $id + * @return JsonResponse + * @throws ModelNotFoundException + * @throws UpdateOperationException + */ + public function update(UpdateChatGroupRequest $request, string|int $id): JsonResponse + { + try { + + $chatGroup = Chat::chatGroup()->find($id); + + if (!$chatGroup) { + throw (new ModelNotFoundException)->setModel(config('fintech.chat.chat_group_model'), $id); + } + + $inputs = $request->validated(); + + if (!Chat::chatGroup()->update($id, $inputs)) { + + throw (new UpdateOperationException)->setModel(config('fintech.chat.chat_group_model'), $id); + } + + return $this->updated(__('core::messages.resource.updated', ['model' => 'Chat Group'])); + + } catch (ModelNotFoundException $exception) { + + return $this->notfound($exception->getMessage()); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Soft delete a specified *ChatGroup* resource using id. + * @lrd:end + * + * @param string|int $id + * @return JsonResponse + * @throws ModelNotFoundException + * @throws DeleteOperationException + */ + public function destroy(string|int $id) + { + try { + + $chatGroup = Chat::chatGroup()->find($id); + + if (!$chatGroup) { + throw (new ModelNotFoundException)->setModel(config('fintech.chat.chat_group_model'), $id); + } + + if (!Chat::chatGroup()->destroy($id)) { + + throw (new DeleteOperationException())->setModel(config('fintech.chat.chat_group_model'), $id); + } + + return $this->deleted(__('core::messages.resource.deleted', ['model' => 'Chat Group'])); + + } catch (ModelNotFoundException $exception) { + + return $this->notfound($exception->getMessage()); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Restore the specified *ChatGroup* resource from trash. + * ** ```Soft Delete``` needs to enabled to use this feature** + * @lrd:end + * + * @param string|int $id + * @return JsonResponse + */ + public function restore(string|int $id) + { + try { + + $chatGroup = Chat::chatGroup()->find($id, true); + + if (!$chatGroup) { + throw (new ModelNotFoundException)->setModel(config('fintech.chat.chat_group_model'), $id); + } + + if (!Chat::chatGroup()->restore($id)) { + + throw (new RestoreOperationException())->setModel(config('fintech.chat.chat_group_model'), $id); + } + + return $this->restored(__('core::messages.resource.restored', ['model' => 'Chat Group'])); + + } catch (ModelNotFoundException $exception) { + + return $this->notfound($exception->getMessage()); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Create a exportable list of the *ChatGroup* resource as document. + * After export job is done system will fire export completed event + * + * @lrd:end + * + * @param IndexChatGroupRequest $request + * @return JsonResponse + */ + public function export(IndexChatGroupRequest $request): JsonResponse + { + try { + $inputs = $request->validated(); + + $chatGroupPaginate = Chat::chatGroup()->export($inputs); + + return $this->exported(__('core::messages.resource.exported', ['model' => 'Chat Group'])); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Create a exportable list of the *ChatGroup* resource as document. + * After export job is done system will fire export completed event + * + * @lrd:end + * + * @param ImportChatGroupRequest $request + * @return ChatGroupCollection|JsonResponse + */ + public function import(ImportChatGroupRequest $request): JsonResponse + { + try { + $inputs = $request->validated(); + + $chatGroupPaginate = Chat::chatGroup()->list($inputs); + + return new ChatGroupCollection($chatGroupPaginate); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } +} diff --git a/src/Http/Controllers/ChatMessageController.php b/src/Http/Controllers/ChatMessageController.php new file mode 100644 index 0000000..bc2d7d9 --- /dev/null +++ b/src/Http/Controllers/ChatMessageController.php @@ -0,0 +1,285 @@ +validated(); + + $chatMessagePaginate = Chat::chatMessage()->list($inputs); + + return new ChatMessageCollection($chatMessagePaginate); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Create a new *ChatMessage* resource in storage. + * @lrd:end + * + * @param StoreChatMessageRequest $request + * @return JsonResponse + * @throws StoreOperationException + */ + public function store(StoreChatMessageRequest $request): JsonResponse + { + try { + $inputs = $request->validated(); + + $chatMessage = Chat::chatMessage()->create($inputs); + + if (!$chatMessage) { + throw (new StoreOperationException)->setModel(config('fintech.chat.chat_message_model')); + } + + return $this->created([ + 'message' => __('core::messages.resource.created', ['model' => 'Chat Message']), + 'id' => $chatMessage->id + ]); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Return a specified *ChatMessage* resource found by id. + * @lrd:end + * + * @param string|int $id + * @return ChatMessageResource|JsonResponse + * @throws ModelNotFoundException + */ + public function show(string|int $id): ChatMessageResource|JsonResponse + { + try { + + $chatMessage = Chat::chatMessage()->find($id); + + if (!$chatMessage) { + throw (new ModelNotFoundException)->setModel(config('fintech.chat.chat_message_model'), $id); + } + + return new ChatMessageResource($chatMessage); + + } catch (ModelNotFoundException $exception) { + + return $this->notfound($exception->getMessage()); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Update a specified *ChatMessage* resource using id. + * @lrd:end + * + * @param UpdateChatMessageRequest $request + * @param string|int $id + * @return JsonResponse + * @throws ModelNotFoundException + * @throws UpdateOperationException + */ + public function update(UpdateChatMessageRequest $request, string|int $id): JsonResponse + { + try { + + $chatMessage = Chat::chatMessage()->find($id); + + if (!$chatMessage) { + throw (new ModelNotFoundException)->setModel(config('fintech.chat.chat_message_model'), $id); + } + + $inputs = $request->validated(); + + if (!Chat::chatMessage()->update($id, $inputs)) { + + throw (new UpdateOperationException)->setModel(config('fintech.chat.chat_message_model'), $id); + } + + return $this->updated(__('core::messages.resource.updated', ['model' => 'Chat Message'])); + + } catch (ModelNotFoundException $exception) { + + return $this->notfound($exception->getMessage()); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Soft delete a specified *ChatMessage* resource using id. + * @lrd:end + * + * @param string|int $id + * @return JsonResponse + * @throws ModelNotFoundException + * @throws DeleteOperationException + */ + public function destroy(string|int $id) + { + try { + + $chatMessage = Chat::chatMessage()->find($id); + + if (!$chatMessage) { + throw (new ModelNotFoundException)->setModel(config('fintech.chat.chat_message_model'), $id); + } + + if (!Chat::chatMessage()->destroy($id)) { + + throw (new DeleteOperationException())->setModel(config('fintech.chat.chat_message_model'), $id); + } + + return $this->deleted(__('core::messages.resource.deleted', ['model' => 'Chat Message'])); + + } catch (ModelNotFoundException $exception) { + + return $this->notfound($exception->getMessage()); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Restore the specified *ChatMessage* resource from trash. + * ** ```Soft Delete``` needs to enabled to use this feature** + * @lrd:end + * + * @param string|int $id + * @return JsonResponse + */ + public function restore(string|int $id) + { + try { + + $chatMessage = Chat::chatMessage()->find($id, true); + + if (!$chatMessage) { + throw (new ModelNotFoundException)->setModel(config('fintech.chat.chat_message_model'), $id); + } + + if (!Chat::chatMessage()->restore($id)) { + + throw (new RestoreOperationException())->setModel(config('fintech.chat.chat_message_model'), $id); + } + + return $this->restored(__('core::messages.resource.restored', ['model' => 'Chat Message'])); + + } catch (ModelNotFoundException $exception) { + + return $this->notfound($exception->getMessage()); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Create a exportable list of the *ChatMessage* resource as document. + * After export job is done system will fire export completed event + * + * @lrd:end + * + * @param IndexChatMessageRequest $request + * @return JsonResponse + */ + public function export(IndexChatMessageRequest $request): JsonResponse + { + try { + $inputs = $request->validated(); + + $chatMessagePaginate = Chat::chatMessage()->export($inputs); + + return $this->exported(__('core::messages.resource.exported', ['model' => 'Chat Message'])); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Create a exportable list of the *ChatMessage* resource as document. + * After export job is done system will fire export completed event + * + * @lrd:end + * + * @param ImportChatMessageRequest $request + * @return ChatMessageCollection|JsonResponse + */ + public function import(ImportChatMessageRequest $request): JsonResponse + { + try { + $inputs = $request->validated(); + + $chatMessagePaginate = Chat::chatMessage()->list($inputs); + + return new ChatMessageCollection($chatMessagePaginate); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } +} diff --git a/src/Http/Controllers/ChatParticipantController.php b/src/Http/Controllers/ChatParticipantController.php new file mode 100644 index 0000000..3f1b409 --- /dev/null +++ b/src/Http/Controllers/ChatParticipantController.php @@ -0,0 +1,285 @@ +validated(); + + $chatParticipantPaginate = Chat::chatParticipant()->list($inputs); + + return new ChatParticipantCollection($chatParticipantPaginate); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Create a new *ChatParticipant* resource in storage. + * @lrd:end + * + * @param StoreChatParticipantRequest $request + * @return JsonResponse + * @throws StoreOperationException + */ + public function store(StoreChatParticipantRequest $request): JsonResponse + { + try { + $inputs = $request->validated(); + + $chatParticipant = Chat::chatParticipant()->create($inputs); + + if (!$chatParticipant) { + throw (new StoreOperationException)->setModel(config('fintech.chat.chat_participant_model')); + } + + return $this->created([ + 'message' => __('core::messages.resource.created', ['model' => 'Chat Participant']), + 'id' => $chatParticipant->id + ]); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Return a specified *ChatParticipant* resource found by id. + * @lrd:end + * + * @param string|int $id + * @return ChatParticipantResource|JsonResponse + * @throws ModelNotFoundException + */ + public function show(string|int $id): ChatParticipantResource|JsonResponse + { + try { + + $chatParticipant = Chat::chatParticipant()->find($id); + + if (!$chatParticipant) { + throw (new ModelNotFoundException)->setModel(config('fintech.chat.chat_participant_model'), $id); + } + + return new ChatParticipantResource($chatParticipant); + + } catch (ModelNotFoundException $exception) { + + return $this->notfound($exception->getMessage()); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Update a specified *ChatParticipant* resource using id. + * @lrd:end + * + * @param UpdateChatParticipantRequest $request + * @param string|int $id + * @return JsonResponse + * @throws ModelNotFoundException + * @throws UpdateOperationException + */ + public function update(UpdateChatParticipantRequest $request, string|int $id): JsonResponse + { + try { + + $chatParticipant = Chat::chatParticipant()->find($id); + + if (!$chatParticipant) { + throw (new ModelNotFoundException)->setModel(config('fintech.chat.chat_participant_model'), $id); + } + + $inputs = $request->validated(); + + if (!Chat::chatParticipant()->update($id, $inputs)) { + + throw (new UpdateOperationException)->setModel(config('fintech.chat.chat_participant_model'), $id); + } + + return $this->updated(__('core::messages.resource.updated', ['model' => 'Chat Participant'])); + + } catch (ModelNotFoundException $exception) { + + return $this->notfound($exception->getMessage()); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Soft delete a specified *ChatParticipant* resource using id. + * @lrd:end + * + * @param string|int $id + * @return JsonResponse + * @throws ModelNotFoundException + * @throws DeleteOperationException + */ + public function destroy(string|int $id) + { + try { + + $chatParticipant = Chat::chatParticipant()->find($id); + + if (!$chatParticipant) { + throw (new ModelNotFoundException)->setModel(config('fintech.chat.chat_participant_model'), $id); + } + + if (!Chat::chatParticipant()->destroy($id)) { + + throw (new DeleteOperationException())->setModel(config('fintech.chat.chat_participant_model'), $id); + } + + return $this->deleted(__('core::messages.resource.deleted', ['model' => 'Chat Participant'])); + + } catch (ModelNotFoundException $exception) { + + return $this->notfound($exception->getMessage()); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Restore the specified *ChatParticipant* resource from trash. + * ** ```Soft Delete``` needs to enabled to use this feature** + * @lrd:end + * + * @param string|int $id + * @return JsonResponse + */ + public function restore(string|int $id) + { + try { + + $chatParticipant = Chat::chatParticipant()->find($id, true); + + if (!$chatParticipant) { + throw (new ModelNotFoundException)->setModel(config('fintech.chat.chat_participant_model'), $id); + } + + if (!Chat::chatParticipant()->restore($id)) { + + throw (new RestoreOperationException())->setModel(config('fintech.chat.chat_participant_model'), $id); + } + + return $this->restored(__('core::messages.resource.restored', ['model' => 'Chat Participant'])); + + } catch (ModelNotFoundException $exception) { + + return $this->notfound($exception->getMessage()); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Create a exportable list of the *ChatParticipant* resource as document. + * After export job is done system will fire export completed event + * + * @lrd:end + * + * @param IndexChatParticipantRequest $request + * @return JsonResponse + */ + public function export(IndexChatParticipantRequest $request): JsonResponse + { + try { + $inputs = $request->validated(); + + $chatParticipantPaginate = Chat::chatParticipant()->export($inputs); + + return $this->exported(__('core::messages.resource.exported', ['model' => 'Chat Participant'])); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } + + /** + * @lrd:start + * Create a exportable list of the *ChatParticipant* resource as document. + * After export job is done system will fire export completed event + * + * @lrd:end + * + * @param ImportChatParticipantRequest $request + * @return ChatParticipantCollection|JsonResponse + */ + public function import(ImportChatParticipantRequest $request): JsonResponse + { + try { + $inputs = $request->validated(); + + $chatParticipantPaginate = Chat::chatParticipant()->list($inputs); + + return new ChatParticipantCollection($chatParticipantPaginate); + + } catch (Exception $exception) { + + return $this->failed($exception->getMessage()); + } + } +} diff --git a/src/Http/Requests/ImportChatGroupRequest.php b/src/Http/Requests/ImportChatGroupRequest.php new file mode 100644 index 0000000..5a4d08f --- /dev/null +++ b/src/Http/Requests/ImportChatGroupRequest.php @@ -0,0 +1,53 @@ + + */ + public function rules(): array + { + return [ + // + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/src/Http/Requests/ImportChatMessageRequest.php b/src/Http/Requests/ImportChatMessageRequest.php new file mode 100644 index 0000000..ab04d5c --- /dev/null +++ b/src/Http/Requests/ImportChatMessageRequest.php @@ -0,0 +1,53 @@ + + */ + public function rules(): array + { + return [ + // + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/src/Http/Requests/ImportChatParticipantRequest.php b/src/Http/Requests/ImportChatParticipantRequest.php new file mode 100644 index 0000000..ca4acf8 --- /dev/null +++ b/src/Http/Requests/ImportChatParticipantRequest.php @@ -0,0 +1,53 @@ + + */ + public function rules(): array + { + return [ + // + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/src/Http/Requests/IndexChatGroupRequest.php b/src/Http/Requests/IndexChatGroupRequest.php new file mode 100644 index 0000000..779bcd3 --- /dev/null +++ b/src/Http/Requests/IndexChatGroupRequest.php @@ -0,0 +1,60 @@ + + */ + public function rules(): array + { + return [ + 'search' => ['string', 'nullable', 'max:255'], + 'per_page' => ['integer', 'nullable', 'min:10', 'max:500'], + 'page' => ['integer', 'nullable', 'min:1'], + 'paginate' => ['boolean'], + 'sort' => ['string', 'nullable', 'min:2', 'max:255'], + 'dir' => ['string', 'min:3', 'max:4'], + 'trashed' => ['boolean', 'nullable'], + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/src/Http/Requests/IndexChatMessageRequest.php b/src/Http/Requests/IndexChatMessageRequest.php new file mode 100644 index 0000000..240fc55 --- /dev/null +++ b/src/Http/Requests/IndexChatMessageRequest.php @@ -0,0 +1,60 @@ + + */ + public function rules(): array + { + return [ + 'search' => ['string', 'nullable', 'max:255'], + 'per_page' => ['integer', 'nullable', 'min:10', 'max:500'], + 'page' => ['integer', 'nullable', 'min:1'], + 'paginate' => ['boolean'], + 'sort' => ['string', 'nullable', 'min:2', 'max:255'], + 'dir' => ['string', 'min:3', 'max:4'], + 'trashed' => ['boolean', 'nullable'], + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/src/Http/Requests/IndexChatParticipantRequest.php b/src/Http/Requests/IndexChatParticipantRequest.php new file mode 100644 index 0000000..2bdd568 --- /dev/null +++ b/src/Http/Requests/IndexChatParticipantRequest.php @@ -0,0 +1,60 @@ + + */ + public function rules(): array + { + return [ + 'search' => ['string', 'nullable', 'max:255'], + 'per_page' => ['integer', 'nullable', 'min:10', 'max:500'], + 'page' => ['integer', 'nullable', 'min:1'], + 'paginate' => ['boolean'], + 'sort' => ['string', 'nullable', 'min:2', 'max:255'], + 'dir' => ['string', 'min:3', 'max:4'], + 'trashed' => ['boolean', 'nullable'], + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/src/Http/Requests/StoreChatGroupRequest.php b/src/Http/Requests/StoreChatGroupRequest.php new file mode 100644 index 0000000..08b0b97 --- /dev/null +++ b/src/Http/Requests/StoreChatGroupRequest.php @@ -0,0 +1,53 @@ + + */ + public function rules(): array + { + return [ + // + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/src/Http/Requests/StoreChatMessageRequest.php b/src/Http/Requests/StoreChatMessageRequest.php new file mode 100644 index 0000000..e4dda97 --- /dev/null +++ b/src/Http/Requests/StoreChatMessageRequest.php @@ -0,0 +1,53 @@ + + */ + public function rules(): array + { + return [ + // + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/src/Http/Requests/StoreChatParticipantRequest.php b/src/Http/Requests/StoreChatParticipantRequest.php new file mode 100644 index 0000000..b29d7bd --- /dev/null +++ b/src/Http/Requests/StoreChatParticipantRequest.php @@ -0,0 +1,53 @@ + + */ + public function rules(): array + { + return [ + // + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/src/Http/Requests/UpdateChatGroupRequest.php b/src/Http/Requests/UpdateChatGroupRequest.php new file mode 100644 index 0000000..c4211a7 --- /dev/null +++ b/src/Http/Requests/UpdateChatGroupRequest.php @@ -0,0 +1,53 @@ + + */ + public function rules(): array + { + return [ + // + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/src/Http/Requests/UpdateChatMessageRequest.php b/src/Http/Requests/UpdateChatMessageRequest.php new file mode 100644 index 0000000..5fae073 --- /dev/null +++ b/src/Http/Requests/UpdateChatMessageRequest.php @@ -0,0 +1,53 @@ + + */ + public function rules(): array + { + return [ + // + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/src/Http/Requests/UpdateChatParticipantRequest.php b/src/Http/Requests/UpdateChatParticipantRequest.php new file mode 100644 index 0000000..7111bd9 --- /dev/null +++ b/src/Http/Requests/UpdateChatParticipantRequest.php @@ -0,0 +1,53 @@ + + */ + public function rules(): array + { + return [ + // + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/src/Http/Resources/ChatGroupCollection.php b/src/Http/Resources/ChatGroupCollection.php new file mode 100644 index 0000000..9fa9769 --- /dev/null +++ b/src/Http/Resources/ChatGroupCollection.php @@ -0,0 +1,39 @@ + + */ + public function with(Request $request): array + { + return [ + 'options' => [ + 'dir' => Constant::SORT_DIRECTIONS, + 'per_page' => Constant::PAGINATE_LENGTHS, + 'sort' => ['id', 'name', 'created_at', 'updated_at'], + ], + 'query' => $request->all(), + ]; + } +} diff --git a/src/Http/Resources/ChatGroupResource.php b/src/Http/Resources/ChatGroupResource.php new file mode 100644 index 0000000..df66039 --- /dev/null +++ b/src/Http/Resources/ChatGroupResource.php @@ -0,0 +1,19 @@ + + */ + public function with(Request $request): array + { + return [ + 'options' => [ + 'dir' => Constant::SORT_DIRECTIONS, + 'per_page' => Constant::PAGINATE_LENGTHS, + 'sort' => ['id', 'name', 'created_at', 'updated_at'], + ], + 'query' => $request->all(), + ]; + } +} diff --git a/src/Http/Resources/ChatMessageResource.php b/src/Http/Resources/ChatMessageResource.php new file mode 100644 index 0000000..80258f1 --- /dev/null +++ b/src/Http/Resources/ChatMessageResource.php @@ -0,0 +1,19 @@ + + */ + public function with(Request $request): array + { + return [ + 'options' => [ + 'dir' => Constant::SORT_DIRECTIONS, + 'per_page' => Constant::PAGINATE_LENGTHS, + 'sort' => ['id', 'name', 'created_at', 'updated_at'], + ], + 'query' => $request->all(), + ]; + } +} diff --git a/src/Http/Resources/ChatParticipantResource.php b/src/Http/Resources/ChatParticipantResource.php new file mode 100644 index 0000000..5099beb --- /dev/null +++ b/src/Http/Resources/ChatParticipantResource.php @@ -0,0 +1,19 @@ + 'array', 'restored_at' => 'datetime']; + + protected $hidden = ['creator_id', 'editor_id', 'destroyer_id', 'restorer_id']; + + /* + |-------------------------------------------------------------------------- + | FUNCTIONS + |-------------------------------------------------------------------------- + */ + public function registerMediaCollections(): void + { + $this->addMediaCollection('logo') + ->acceptsMimeTypes(['image/jpeg', 'image/png', 'image/gif', 'image/jpg', 'image/svg+xml']) + ->useFallbackUrl(asset('storage/images/anonymous-user.jpg')) + ->useFallbackPath(storage_path('/app/public/images/anonymous-user.jpg')) + ->useFallbackUrl(asset('storage/images/anonymous-user.jpg'), 'thumb') + ->useFallbackPath(storage_path('/app/public/images/anonymous-user.jpg'), 'thumb') + ->useDisk(config('filesystems.default', 'public')) + ->singleFile(); + } + /* + |-------------------------------------------------------------------------- + | RELATIONS + |-------------------------------------------------------------------------- + */ + + /* + |-------------------------------------------------------------------------- + | SCOPES + |-------------------------------------------------------------------------- + */ + + /* + |-------------------------------------------------------------------------- + | ACCESSORS + |-------------------------------------------------------------------------- + */ + + /** + * @return array + */ + public function getLinksAttribute() + { + $primaryKey = $this->getKey(); + + $links = [ + 'show' => action_link(route('chat.chat-groups.show', $primaryKey), __('core::messages.action.show'), 'get'), + 'update' => action_link(route('chat.chat-groups.update', $primaryKey), __('core::messages.action.update'), 'put'), + 'destroy' => action_link(route('chat.chat-groups.destroy', $primaryKey), __('core::messages.action.destroy'), 'delete'), + 'restore' => action_link(route('chat.chat-groups.restore', $primaryKey), __('core::messages.action.restore'), 'post'), + ]; + + if ($this->getAttribute('deleted_at') == null) { + unset($links['restore']); + } else { + unset($links['destroy']); + } + + return $links; + } + + /* + |-------------------------------------------------------------------------- + | MUTATORS + |-------------------------------------------------------------------------- + */ +} diff --git a/src/Models/ChatMessage.php b/src/Models/ChatMessage.php new file mode 100644 index 0000000..bf36b58 --- /dev/null +++ b/src/Models/ChatMessage.php @@ -0,0 +1,92 @@ + 'array', 'restored_at' => 'datetime', 'enabled' => 'bool']; + + protected $hidden = ['creator_id', 'editor_id', 'destroyer_id', 'restorer_id']; + + /* + |-------------------------------------------------------------------------- + | FUNCTIONS + |-------------------------------------------------------------------------- + */ + + /* + |-------------------------------------------------------------------------- + | RELATIONS + |-------------------------------------------------------------------------- + */ + public function registerMediaCollections(): void + { + $this->addMediaCollection('attachment') + ->acceptsMimeTypes(['image/jpeg', 'image/png', 'image/gif', 'image/jpg', 'image/svg+xml']) + ->useFallbackUrl(asset('storage/images/anonymous-user.jpg')) + ->useFallbackPath(storage_path('/app/public/images/anonymous-user.jpg')) + ->useFallbackUrl(asset('storage/images/anonymous-user.jpg'), 'thumb') + ->useFallbackPath(storage_path('/app/public/images/anonymous-user.jpg'), 'thumb') + ->useDisk(config('filesystems.default', 'public')); + } + + /* + |-------------------------------------------------------------------------- + | SCOPES + |-------------------------------------------------------------------------- + */ + + /* + |-------------------------------------------------------------------------- + | ACCESSORS + |-------------------------------------------------------------------------- + */ + + /** + * @return array + */ + public function getLinksAttribute() + { + $primaryKey = $this->getKey(); + + $links = [ + 'show' => action_link(route('chat.chat-messages.show', $primaryKey), __('core::messages.action.show'), 'get'), + 'update' => action_link(route('chat.chat-messages.update', $primaryKey), __('core::messages.action.update'), 'put'), + 'destroy' => action_link(route('chat.chat-messages.destroy', $primaryKey), __('core::messages.action.destroy'), 'delete'), + 'restore' => action_link(route('chat.chat-messages.restore', $primaryKey), __('core::messages.action.restore'), 'post'), + ]; + + if ($this->getAttribute('deleted_at') == null) { + unset($links['restore']); + } else { + unset($links['destroy']); + } + + return $links; + } + + /* + |-------------------------------------------------------------------------- + | MUTATORS + |-------------------------------------------------------------------------- + */ +} diff --git a/src/Models/ChatParticipant.php b/src/Models/ChatParticipant.php new file mode 100644 index 0000000..11ab0ba --- /dev/null +++ b/src/Models/ChatParticipant.php @@ -0,0 +1,82 @@ + 'array', 'restored_at' => 'datetime', 'enabled' => 'bool']; + + protected $hidden = ['creator_id', 'editor_id', 'destroyer_id', 'restorer_id']; + + /* + |-------------------------------------------------------------------------- + | FUNCTIONS + |-------------------------------------------------------------------------- + */ + + /* + |-------------------------------------------------------------------------- + | RELATIONS + |-------------------------------------------------------------------------- + */ + + /* + |-------------------------------------------------------------------------- + | SCOPES + |-------------------------------------------------------------------------- + */ + + /* + |-------------------------------------------------------------------------- + | ACCESSORS + |-------------------------------------------------------------------------- + */ + + /** + * @return array + */ + public function getLinksAttribute() + { + $primaryKey = $this->getKey(); + + $links = [ + 'show' => action_link(route('chat.chat-participants.show', $primaryKey), __('core::messages.action.show'), 'get'), + 'update' => action_link(route('chat.chat-participants.update', $primaryKey), __('core::messages.action.update'), 'put'), + 'destroy' => action_link(route('chat.chat-participants.destroy', $primaryKey), __('core::messages.action.destroy'), 'delete'), + 'restore' => action_link(route('chat.chat-participants.restore', $primaryKey), __('core::messages.action.restore'), 'post'), + ]; + + if ($this->getAttribute('deleted_at') == null) { + unset($links['restore']); + } else { + unset($links['destroy']); + } + + return $links; + } + + /* + |-------------------------------------------------------------------------- + | MUTATORS + |-------------------------------------------------------------------------- + */ +} diff --git a/src/Repositories/Eloquent/ChatGroupRepository.php b/src/Repositories/Eloquent/ChatGroupRepository.php new file mode 100644 index 0000000..5695bd7 --- /dev/null +++ b/src/Repositories/Eloquent/ChatGroupRepository.php @@ -0,0 +1,61 @@ +model = $model; + } + + /** + * return a list or pagination of items from + * filtered options + * + * @return Paginator|Collection + */ + public function list(array $filters = []) + { + $query = $this->model->newQuery(); + + //Searching + if (! empty($filters['search'])) { + if (is_numeric($filters['search'])) { + $query->where($this->model->getKeyName(), 'like', "%{$filters['search']}%"); + } else { + $query->where('name', 'like', "%{$filters['search']}%"); + $query->orWhere('chat_group_data', 'like', "%{$filters['search']}%"); + } + } + + //Display Trashed + if (isset($filters['trashed']) && $filters['trashed'] === true) { + $query->onlyTrashed(); + } + + //Handle Sorting + $query->orderBy($filters['sort'] ?? $this->model->getKeyName(), $filters['dir'] ?? 'asc'); + + //Execute Output + return $this->executeQuery($query, $filters); + + } +} diff --git a/src/Repositories/Eloquent/ChatMessageRepository.php b/src/Repositories/Eloquent/ChatMessageRepository.php new file mode 100644 index 0000000..c4a812b --- /dev/null +++ b/src/Repositories/Eloquent/ChatMessageRepository.php @@ -0,0 +1,61 @@ +model = $model; + } + + /** + * return a list or pagination of items from + * filtered options + * + * @return Paginator|Collection + */ + public function list(array $filters = []) + { + $query = $this->model->newQuery(); + + //Searching + if (! empty($filters['search'])) { + if (is_numeric($filters['search'])) { + $query->where($this->model->getKeyName(), 'like', "%{$filters['search']}%"); + } else { + $query->where('name', 'like', "%{$filters['search']}%"); + $query->orWhere('chat_message_data', 'like', "%{$filters['search']}%"); + } + } + + //Display Trashed + if (isset($filters['trashed']) && $filters['trashed'] === true) { + $query->onlyTrashed(); + } + + //Handle Sorting + $query->orderBy($filters['sort'] ?? $this->model->getKeyName(), $filters['dir'] ?? 'asc'); + + //Execute Output + return $this->executeQuery($query, $filters); + + } +} diff --git a/src/Repositories/Eloquent/ChatParticipantRepository.php b/src/Repositories/Eloquent/ChatParticipantRepository.php new file mode 100644 index 0000000..1e46f82 --- /dev/null +++ b/src/Repositories/Eloquent/ChatParticipantRepository.php @@ -0,0 +1,61 @@ +model = $model; + } + + /** + * return a list or pagination of items from + * filtered options + * + * @return Paginator|Collection + */ + public function list(array $filters = []) + { + $query = $this->model->newQuery(); + + //Searching + if (! empty($filters['search'])) { + if (is_numeric($filters['search'])) { + $query->where($this->model->getKeyName(), 'like', "%{$filters['search']}%"); + } else { + $query->where('name', 'like', "%{$filters['search']}%"); + $query->orWhere('chat_participant_data', 'like', "%{$filters['search']}%"); + } + } + + //Display Trashed + if (isset($filters['trashed']) && $filters['trashed'] === true) { + $query->onlyTrashed(); + } + + //Handle Sorting + $query->orderBy($filters['sort'] ?? $this->model->getKeyName(), $filters['dir'] ?? 'asc'); + + //Execute Output + return $this->executeQuery($query, $filters); + + } +} diff --git a/src/Repositories/Mongodb/ChatGroupRepository.php b/src/Repositories/Mongodb/ChatGroupRepository.php new file mode 100644 index 0000000..03b5e23 --- /dev/null +++ b/src/Repositories/Mongodb/ChatGroupRepository.php @@ -0,0 +1,61 @@ +model = $model; + } + + /** + * return a list or pagination of items from + * filtered options + * + * @return Paginator|Collection + */ + public function list(array $filters = []) + { + $query = $this->model->newQuery(); + + //Searching + if (! empty($filters['search'])) { + if (is_numeric($filters['search'])) { + $query->where($this->model->getKeyName(), 'like', "%{$filters['search']}%"); + } else { + $query->where('name', 'like', "%{$filters['search']}%"); + $query->orWhere('chat_group_data', 'like', "%{$filters['search']}%"); + } + } + + //Display Trashed + if (isset($filters['trashed']) && $filters['trashed'] === true) { + $query->onlyTrashed(); + } + + //Handle Sorting + $query->orderBy($filters['sort'] ?? $this->model->getKeyName(), $filters['dir'] ?? 'asc'); + + //Execute Output + return $this->executeQuery($query, $filters); + + } +} diff --git a/src/Repositories/Mongodb/ChatMessageRepository.php b/src/Repositories/Mongodb/ChatMessageRepository.php new file mode 100644 index 0000000..4e45467 --- /dev/null +++ b/src/Repositories/Mongodb/ChatMessageRepository.php @@ -0,0 +1,61 @@ +model = $model; + } + + /** + * return a list or pagination of items from + * filtered options + * + * @return Paginator|Collection + */ + public function list(array $filters = []) + { + $query = $this->model->newQuery(); + + //Searching + if (! empty($filters['search'])) { + if (is_numeric($filters['search'])) { + $query->where($this->model->getKeyName(), 'like', "%{$filters['search']}%"); + } else { + $query->where('name', 'like', "%{$filters['search']}%"); + $query->orWhere('chat_message_data', 'like', "%{$filters['search']}%"); + } + } + + //Display Trashed + if (isset($filters['trashed']) && $filters['trashed'] === true) { + $query->onlyTrashed(); + } + + //Handle Sorting + $query->orderBy($filters['sort'] ?? $this->model->getKeyName(), $filters['dir'] ?? 'asc'); + + //Execute Output + return $this->executeQuery($query, $filters); + + } +} diff --git a/src/Repositories/Mongodb/ChatParticipantRepository.php b/src/Repositories/Mongodb/ChatParticipantRepository.php new file mode 100644 index 0000000..4df2e66 --- /dev/null +++ b/src/Repositories/Mongodb/ChatParticipantRepository.php @@ -0,0 +1,61 @@ +model = $model; + } + + /** + * return a list or pagination of items from + * filtered options + * + * @return Paginator|Collection + */ + public function list(array $filters = []) + { + $query = $this->model->newQuery(); + + //Searching + if (! empty($filters['search'])) { + if (is_numeric($filters['search'])) { + $query->where($this->model->getKeyName(), 'like', "%{$filters['search']}%"); + } else { + $query->where('name', 'like', "%{$filters['search']}%"); + $query->orWhere('chat_participant_data', 'like', "%{$filters['search']}%"); + } + } + + //Display Trashed + if (isset($filters['trashed']) && $filters['trashed'] === true) { + $query->onlyTrashed(); + } + + //Handle Sorting + $query->orderBy($filters['sort'] ?? $this->model->getKeyName(), $filters['dir'] ?? 'asc'); + + //Execute Output + return $this->executeQuery($query, $filters); + + } +} diff --git a/src/Seeders/ChatGroupSeeder.php b/src/Seeders/ChatGroupSeeder.php new file mode 100644 index 0000000..2c22211 --- /dev/null +++ b/src/Seeders/ChatGroupSeeder.php @@ -0,0 +1,29 @@ +data(); + + foreach (array_chunk($data, 200) as $block) { + set_time_limit(2100); + foreach ($block as $entry) { + Chat::chatGroup()->create($entry); + } + } + } + + private function data() + { + return array(); + } +} diff --git a/src/Seeders/ChatMessageSeeder.php b/src/Seeders/ChatMessageSeeder.php new file mode 100644 index 0000000..0134f02 --- /dev/null +++ b/src/Seeders/ChatMessageSeeder.php @@ -0,0 +1,29 @@ +data(); + + foreach (array_chunk($data, 200) as $block) { + set_time_limit(2100); + foreach ($block as $entry) { + Chat::chatMessage()->create($entry); + } + } + } + + private function data() + { + return array(); + } +} diff --git a/src/Seeders/ChatParticipantSeeder.php b/src/Seeders/ChatParticipantSeeder.php new file mode 100644 index 0000000..6163d25 --- /dev/null +++ b/src/Seeders/ChatParticipantSeeder.php @@ -0,0 +1,29 @@ +data(); + + foreach (array_chunk($data, 200) as $block) { + set_time_limit(2100); + foreach ($block as $entry) { + Chat::chatParticipant()->create($entry); + } + } + } + + private function data() + { + return array(); + } +} diff --git a/src/Services/ChatGroupService.php b/src/Services/ChatGroupService.php new file mode 100644 index 0000000..c004791 --- /dev/null +++ b/src/Services/ChatGroupService.php @@ -0,0 +1,67 @@ +chatGroupRepository = $chatGroupRepository; + } + + /** + * @param array $filters + * @return mixed + */ + public function list(array $filters = []) + { + return $this->chatGroupRepository->list($filters); + + } + + public function create(array $inputs = []) + { + return $this->chatGroupRepository->create($inputs); + } + + public function find($id, $onlyTrashed = false) + { + return $this->chatGroupRepository->find($id, $onlyTrashed); + } + + public function update($id, array $inputs = []) + { + return $this->chatGroupRepository->update($id, $inputs); + } + + public function destroy($id) + { + return $this->chatGroupRepository->delete($id); + } + + public function restore($id) + { + return $this->chatGroupRepository->restore($id); + } + + public function export(array $filters) + { + return $this->chatGroupRepository->list($filters); + } + + public function import(array $filters) + { + return $this->chatGroupRepository->create($filters); + } +} diff --git a/src/Services/ChatMessageService.php b/src/Services/ChatMessageService.php new file mode 100644 index 0000000..cab4534 --- /dev/null +++ b/src/Services/ChatMessageService.php @@ -0,0 +1,67 @@ +chatMessageRepository = $chatMessageRepository; + } + + /** + * @param array $filters + * @return mixed + */ + public function list(array $filters = []) + { + return $this->chatMessageRepository->list($filters); + + } + + public function create(array $inputs = []) + { + return $this->chatMessageRepository->create($inputs); + } + + public function find($id, $onlyTrashed = false) + { + return $this->chatMessageRepository->find($id, $onlyTrashed); + } + + public function update($id, array $inputs = []) + { + return $this->chatMessageRepository->update($id, $inputs); + } + + public function destroy($id) + { + return $this->chatMessageRepository->delete($id); + } + + public function restore($id) + { + return $this->chatMessageRepository->restore($id); + } + + public function export(array $filters) + { + return $this->chatMessageRepository->list($filters); + } + + public function import(array $filters) + { + return $this->chatMessageRepository->create($filters); + } +} diff --git a/src/Services/ChatParticipantService.php b/src/Services/ChatParticipantService.php new file mode 100644 index 0000000..bc58307 --- /dev/null +++ b/src/Services/ChatParticipantService.php @@ -0,0 +1,67 @@ +chatParticipantRepository = $chatParticipantRepository; + } + + /** + * @param array $filters + * @return mixed + */ + public function list(array $filters = []) + { + return $this->chatParticipantRepository->list($filters); + + } + + public function create(array $inputs = []) + { + return $this->chatParticipantRepository->create($inputs); + } + + public function find($id, $onlyTrashed = false) + { + return $this->chatParticipantRepository->find($id, $onlyTrashed); + } + + public function update($id, array $inputs = []) + { + return $this->chatParticipantRepository->update($id, $inputs); + } + + public function destroy($id) + { + return $this->chatParticipantRepository->delete($id); + } + + public function restore($id) + { + return $this->chatParticipantRepository->restore($id); + } + + public function export(array $filters) + { + return $this->chatParticipantRepository->list($filters); + } + + public function import(array $filters) + { + return $this->chatParticipantRepository->create($filters); + } +}