Skip to content

Commit

Permalink
[wip] update database structure
Browse files Browse the repository at this point in the history
  • Loading branch information
aryala7 committed Nov 25, 2023
1 parent 7eac90a commit 3d581e7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
7 changes: 4 additions & 3 deletions database/migrations/create_sms_messages_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ return new class extends Migration
{
Schema::create('sms_messages', function (Blueprint $table) {
$table->id();
$table->string('provider'); // To store the provider name
$table->string('recipient_number'); // To store the recipient's phone number
$table->text('message'); // To store the SMS message
$table->string('provider');
$table->string('recipient_number');
$table->json('data')->nullable();
$table->tinyInteger('status');
$table->timestamps();
});
}
Expand Down
14 changes: 12 additions & 2 deletions src/Chapaar.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use TookanTech\Chapaar\Contracts\DriverConnector;
use TookanTech\Chapaar\Contracts\DriverMessage;
use TookanTech\Chapaar\Enums\Drivers;
use TookanTech\Chapaar\Events\SmsSent;

class Chapaar
{
Expand All @@ -24,12 +25,21 @@ public function getDefaultDriver(): DriverConnector

public function send($message): object
{
return $this->driver($message->driver)->send($message);
$response = $this->driver($message->getDriver())->send($message);
if(count($response)) {
SmsSent::dispatch($message->driver,$message,$response['status']);
}
return $response;

}

public function verify(DriverMessage $message): object
{
return $this->driver($message->getDriver())->verify($message);
$response = $this->driver($message->getDriver())->verify($message);
if(count($response)) {
SmsSent::dispatch($message->getDriver(),$message,$response['status']);
}
return $response;
}

public function account(): object
Expand Down
10 changes: 5 additions & 5 deletions src/Events/SmsSent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class SmsSent
use Dispatchable, InteractsWithSockets, SerializesModels;

public $provider;
public $recipientNumber;
public $message;
public $data;
public $status;

public function __construct($provider, $recipientNumber, $message)
public function __construct($provider, $data, $status)
{
$this->provider = $provider;
$this->recipientNumber = $recipientNumber;
$this->message = $message;
$this->data = $data;
$this->status = $status;
}
}
4 changes: 2 additions & 2 deletions src/Listeners/StoreSmsMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public function handle(SmsSent $event)
{
$smsMessage = new SmsMessage();
$smsMessage->provider = $event->provider;
$smsMessage->recipient_number = $event->recipientNumber;
$smsMessage->message = $event->message;
$smsMessage->data = $event->data;
$smsMessage->status = $event->status;
$smsMessage->save();
}
}
9 changes: 7 additions & 2 deletions src/Models/SmsMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

namespace TookanTech\Chapaar\Models;

use Illuminate\Database\Eloquent\Casts\AsCollection;
use Illuminate\Database\Eloquent\Model;

class SmsMessage extends Model
{

protected $fillable = [
'provider',
'recipient_number',
'message',
'data',
'status',
];

protected $cast = [
'data' => AsCollection::class
]
}

0 comments on commit 3d581e7

Please sign in to comment.