Skip to content

Commit

Permalink
feat: interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
kaioken committed Dec 21, 2024
1 parent 9f3cf52 commit 63eaa41
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public function up(): void
{
Schema::table('user_messages', function (Blueprint $table) {
$table->tinyInteger('is_purchase')->after('is_shared')->default(0)->index('is_purchase');
$table->tinyInteger('is_purchased')->after('is_shared')->default(0)->index('is_purchased');
});
}

Expand All @@ -21,7 +21,7 @@ public function up(): void
public function down(): void
{
Schema::table('user_messages', function (Blueprint $table) {
$table->dropColumn('is_purchase');
$table->dropColumn('is_purchased');
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {

public function up(): void
{
Schema::table('messages', function (Blueprint $table) {
$table->tinyInteger('total_purchased')->after('total_shared')->default(0)->index('total_purchased');
});
}

public function down(): void
{
Schema::table('messages', function (Blueprint $table) {
$table->dropColumn('total_purchased');
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function execute(int $pageSize = 350): int
$query->where('is_liked', 0)
->where('is_disliked', 0)
->where('is_saved', 0)
->where('is_purchased', 0)
->where('is_shared', 0);
})
->lockForUpdate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Kanvas\Social\Channels\DataTransferObject\Channel;
use Kanvas\Social\Messages\Actions\CreateAppModuleMessageAction;
use Kanvas\Social\Messages\Models\Message;
use Kanvas\Social\Messages\Services\MessageInteractionService;
use Kanvas\Souk\Orders\Models\Order;
use Kanvas\SystemModules\Repositories\SystemModulesRepository;
use Kanvas\Users\Models\Users;
Expand Down Expand Up @@ -61,6 +62,8 @@ public function execute(Model $order, AppInterface $app, array $params): array
$purchaseChannel->addMessage($message, $user);

$user->set('purchase_channel', $purchaseChannel->uuid);
$messageInteractionService = new MessageInteractionService($message);
$messageInteractionService->purchase($user);

return [
'order' => $order->id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function executeRandomMessages(int $pageSize = 350): int
$query->where('is_liked', 0)
->where('is_disliked', 0)
->where('is_saved', 0)
->where('is_purchased', 0)
->where('is_shared', 0);
})
->lockForUpdate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use Baka\Users\Contracts\UserInterface;
use Kanvas\Social\Enums\AppEnum;
use Kanvas\Social\Enums\InteractionEnum;
use Kanvas\Social\Interactions\Actions\CreateInteraction;
use Kanvas\Social\Interactions\Actions\CreateUserInteractionAction;
use Kanvas\Social\Interactions\DataTransferObject\Interaction;
use Kanvas\Social\Interactions\DataTransferObject\UserInteraction;
use Kanvas\Social\Interactions\Models\Interactions;
use Kanvas\Social\Interactions\Models\UsersInteractions;
Expand Down Expand Up @@ -83,6 +85,18 @@ public function dislike(UserInterface $who): UsersInteractions
return $userInteraction;
}

public function purchase(UserInterface $who): UsersInteractions
{
$this->incrementInteractionCount('total_purchased');

$userInteraction = $this->createInteraction($who, InteractionEnum::PURCHASE->getValue());
$userMessage = $this->addToUserMessage($who);
$userMessage->is_purchased = 1;
$userMessage->saveOrFail();

return $userInteraction;
}

protected function incrementInteractionCount(string $interactionType): void
{
$this->message->$interactionType++;
Expand All @@ -97,7 +111,14 @@ protected function decrementInteractionCount(string $interactionType): void

protected function createInteraction(UserInterface $who, string $interactionType, ?string $note = null): UsersInteractions
{
$interaction = Interactions::getByName($interactionType, $this->message->app);
//$interaction = Interactions::getByName($interactionType, $this->message->app);
$interaction = (new CreateInteraction(
new Interaction(
$interactionType,
$this->message->app,
$interactionType,
)
))->execute();
$createUserInteraction = new CreateUserInteractionAction(
new UserInteraction(
$who,
Expand Down

0 comments on commit 63eaa41

Please sign in to comment.