refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This is a single action class, totally inspired by
|
||||
* https://medium.com/@remi_collin/keeping-your-laravel-applications-dry-with-single-action-classes-6a950ec54d1d.
|
||||
*/
|
||||
|
||||
namespace App\Services\Contact\Conversation;
|
||||
|
||||
use App\Services\BaseService;
|
||||
use App\Models\Contact\Contact;
|
||||
use App\Models\Contact\Message;
|
||||
use App\Models\Contact\Conversation;
|
||||
|
||||
class AddMessageToConversation extends BaseService
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the service.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'account_id' => 'required|integer|exists:accounts,id',
|
||||
'contact_id' => 'required|integer|exists:contacts,id',
|
||||
'conversation_id' => 'required|integer|exists:conversations,id',
|
||||
'written_at' => 'required|date',
|
||||
'written_by_me' => 'required|boolean',
|
||||
'content' => 'required|string',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add message to a conversation.
|
||||
*
|
||||
* @param array $data
|
||||
* @return Message
|
||||
*/
|
||||
public function execute(array $data): Message
|
||||
{
|
||||
$this->validate($data);
|
||||
|
||||
$contact = Contact::where('account_id', $data['account_id'])
|
||||
->findOrFail($data['contact_id']);
|
||||
|
||||
$contact->throwInactive();
|
||||
|
||||
Conversation::where('contact_id', $data['contact_id'])
|
||||
->where('account_id', $data['account_id'])
|
||||
->findOrFail($data['conversation_id']);
|
||||
|
||||
return Message::create($data);
|
||||
}
|
||||
}
|
||||
52
app/Services/Contact/Conversation/CreateConversation.php
Normal file
52
app/Services/Contact/Conversation/CreateConversation.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This is a single action class, totally inspired by
|
||||
* https://medium.com/@remi_collin/keeping-your-laravel-applications-dry-with-single-action-classes-6a950ec54d1d.
|
||||
*/
|
||||
|
||||
namespace App\Services\Contact\Conversation;
|
||||
|
||||
use App\Services\BaseService;
|
||||
use App\Models\Contact\Contact;
|
||||
use App\Models\Contact\Conversation;
|
||||
use App\Models\Contact\ContactFieldType;
|
||||
|
||||
class CreateConversation extends BaseService
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the service.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'happened_at' => 'required|date',
|
||||
'account_id' => 'required|integer|exists:accounts,id',
|
||||
'contact_id' => 'required|integer|exists:contacts,id',
|
||||
'contact_field_type_id' => 'required|integer|exists:contact_field_types,id',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a conversation.
|
||||
*
|
||||
* @param array $data
|
||||
* @return Conversation
|
||||
*/
|
||||
public function execute(array $data): Conversation
|
||||
{
|
||||
$this->validate($data);
|
||||
|
||||
$contact = Contact::where('account_id', $data['account_id'])
|
||||
->findOrFail($data['contact_id']);
|
||||
|
||||
$contact->throwInactive();
|
||||
|
||||
ContactFieldType::where('account_id', $data['account_id'])
|
||||
->findOrFail($data['contact_field_type_id']);
|
||||
|
||||
return Conversation::create($data);
|
||||
}
|
||||
}
|
||||
47
app/Services/Contact/Conversation/DestroyConversation.php
Normal file
47
app/Services/Contact/Conversation/DestroyConversation.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This is a single action class, totally inspired by
|
||||
* https://medium.com/@remi_collin/keeping-your-laravel-applications-dry-with-single-action-classes-6a950ec54d1d.
|
||||
*/
|
||||
|
||||
namespace App\Services\Contact\Conversation;
|
||||
|
||||
use App\Services\BaseService;
|
||||
use App\Models\Contact\Conversation;
|
||||
|
||||
class DestroyConversation extends BaseService
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the service.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'account_id' => 'required|integer|exists:accounts,id',
|
||||
'conversation_id' => 'required|integer|exists:conversations,id',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy a conversation.
|
||||
*
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function execute(array $data): bool
|
||||
{
|
||||
$this->validate($data);
|
||||
|
||||
$conversation = Conversation::where('account_id', $data['account_id'])
|
||||
->findOrFail($data['conversation_id']);
|
||||
|
||||
$conversation->contact->throwInactive();
|
||||
|
||||
$conversation->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
53
app/Services/Contact/Conversation/DestroyMessage.php
Normal file
53
app/Services/Contact/Conversation/DestroyMessage.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This is a single action class, totally inspired by
|
||||
* https://medium.com/@remi_collin/keeping-your-laravel-applications-dry-with-single-action-classes-6a950ec54d1d.
|
||||
*/
|
||||
|
||||
namespace App\Services\Contact\Conversation;
|
||||
|
||||
use App\Services\BaseService;
|
||||
use App\Models\Contact\Message;
|
||||
use App\Models\Contact\Conversation;
|
||||
|
||||
class DestroyMessage extends BaseService
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the service.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'account_id' => 'required|integer|exists:accounts,id',
|
||||
'conversation_id' => 'required|integer|exists:conversations,id',
|
||||
'message_id' => 'required|integer|exists:messages,id',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy a message.
|
||||
*
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function execute(array $data): bool
|
||||
{
|
||||
$this->validate($data);
|
||||
|
||||
Conversation::where('account_id', $data['account_id'])
|
||||
->findOrFail($data['conversation_id']);
|
||||
|
||||
$message = Message::where('account_id', $data['account_id'])
|
||||
->where('conversation_id', $data['conversation_id'])
|
||||
->findOrFail($data['message_id']);
|
||||
|
||||
$message->contact->throwInactive();
|
||||
|
||||
$message->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
57
app/Services/Contact/Conversation/UpdateConversation.php
Normal file
57
app/Services/Contact/Conversation/UpdateConversation.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This is a single action class, totally inspired by
|
||||
* https://medium.com/@remi_collin/keeping-your-laravel-applications-dry-with-single-action-classes-6a950ec54d1d.
|
||||
*/
|
||||
|
||||
namespace App\Services\Contact\Conversation;
|
||||
|
||||
use App\Services\BaseService;
|
||||
use App\Models\Contact\Conversation;
|
||||
use App\Models\Contact\ContactFieldType;
|
||||
|
||||
class UpdateConversation extends BaseService
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the service.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'account_id' => 'required|integer|exists:accounts,id',
|
||||
'happened_at' => 'required|date',
|
||||
'contact_field_type_id' => 'required|integer',
|
||||
'conversation_id' => 'required|integer|exists:conversations,id',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a conversation.
|
||||
*
|
||||
* @param array $data
|
||||
* @return Conversation
|
||||
*/
|
||||
public function execute(array $data): Conversation
|
||||
{
|
||||
$this->validate($data);
|
||||
|
||||
/** @var Conversation */
|
||||
$conversation = Conversation::where('account_id', $data['account_id'])
|
||||
->findOrFail($data['conversation_id']);
|
||||
|
||||
$conversation->contact->throwInactive();
|
||||
|
||||
ContactFieldType::where('account_id', $data['account_id'])
|
||||
->findOrFail($data['contact_field_type_id']);
|
||||
|
||||
$conversation->update([
|
||||
'happened_at' => $data['happened_at'],
|
||||
'contact_field_type_id' => $data['contact_field_type_id'],
|
||||
]);
|
||||
|
||||
return $conversation;
|
||||
}
|
||||
}
|
||||
68
app/Services/Contact/Conversation/UpdateMessage.php
Normal file
68
app/Services/Contact/Conversation/UpdateMessage.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This is a single action class, totally inspired by
|
||||
* https://medium.com/@remi_collin/keeping-your-laravel-applications-dry-with-single-action-classes-6a950ec54d1d.
|
||||
*/
|
||||
|
||||
namespace App\Services\Contact\Conversation;
|
||||
|
||||
use App\Services\BaseService;
|
||||
use App\Models\Contact\Contact;
|
||||
use App\Models\Contact\Message;
|
||||
use App\Models\Contact\Conversation;
|
||||
|
||||
class UpdateMessage extends BaseService
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the service.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'account_id' => 'required|integer|exists:accounts,id',
|
||||
'contact_id' => 'required|integer|exists:contacts,id',
|
||||
'conversation_id' => 'required|integer|exists:conversations,id',
|
||||
'message_id' => 'required|integer|exists:messages,id',
|
||||
'written_at' => 'required|date',
|
||||
'written_by_me' => 'required|boolean',
|
||||
'content' => 'required|string',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Update message in a conversation.
|
||||
*
|
||||
* @param array $data
|
||||
* @return Message
|
||||
*/
|
||||
public function execute(array $data): Message
|
||||
{
|
||||
$this->validate($data);
|
||||
|
||||
$contact = Contact::where('account_id', $data['account_id'])
|
||||
->findOrFail($data['contact_id']);
|
||||
|
||||
$contact->throwInactive();
|
||||
|
||||
Conversation::where('contact_id', $data['contact_id'])
|
||||
->where('account_id', $data['account_id'])
|
||||
->findOrFail($data['conversation_id']);
|
||||
|
||||
/** @var Message */
|
||||
$message = Message::where('contact_id', $data['contact_id'])
|
||||
->where('conversation_id', $data['conversation_id'])
|
||||
->where('account_id', $data['account_id'])
|
||||
->findOrFail($data['message_id']);
|
||||
|
||||
$message->update([
|
||||
'written_at' => $data['written_at'],
|
||||
'written_by_me' => $data['written_by_me'],
|
||||
'content' => $data['content'],
|
||||
]);
|
||||
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user