forked from arashactive/laramint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added register form with coins compatibale
- Loading branch information
1 parent
be2594e
commit 220faed
Showing
10 changed files
with
140 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,6 @@ | |
class CoinsLog extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $guarded = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace App\Services\Coins; | ||
|
||
use App\Models\Configuration; | ||
use App\Models\User; | ||
|
||
class CoinsForRegisterNewUser extends UserCoins | ||
{ | ||
protected int $coins = 0; | ||
|
||
|
||
protected function setCoins() | ||
{ | ||
$configuration = Configuration::where('config_type', 'CoinsForNewUserRegister')->first(); | ||
if ($configuration->config_value > 0) | ||
$this->coins = $configuration->config_value; | ||
} | ||
|
||
public function executed(User $user): bool | ||
{ | ||
$this->setCoins(); | ||
|
||
if ($this->coins == 0) | ||
return false; | ||
|
||
$user->CoinsLogs()->create([ | ||
'coins' => $this->coins, | ||
'description' => trans('message/description.user_register_got_coins', ['coins' => $this->coins]), | ||
'causable_type' => User::class, | ||
'causable_id' => $user->id, | ||
'is_manual' => 0 | ||
]); | ||
|
||
$this->userUpdateCoins($user, $this->coins); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace App\Services\Coins; | ||
|
||
use App\Models\User; | ||
|
||
class UserCoins | ||
{ | ||
|
||
protected function userUpdateCoins(User $user, int $coins): bool | ||
{ | ||
if ($coins == 0) | ||
return false; | ||
|
||
$user->coins = $user->coins + ($coins); | ||
$user->save(); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\TDD\General; | ||
|
||
use Tests\BaseTest; | ||
|
||
class registerTest extends BaseTest | ||
{ | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->seed(); | ||
|
||
$this->setBaseRoute('activity'); | ||
$this->setBaseModel('App\Models\Activity'); | ||
} | ||
|
||
|
||
public function test_it_can_register_a_new_user() | ||
{ | ||
$user = [ | ||
'name' => 'Test User', | ||
'email' => '[email protected]', | ||
'password' => 'password', | ||
'password_confirmation' => 'password', | ||
]; | ||
$this->post('/register', $user); | ||
|
||
$this->assertDatabaseHas('users', [ | ||
'name' => $user['name'], | ||
'email' => $user['email'], | ||
]); | ||
} | ||
|
||
|
||
public function test_register_a_new_user_get_coins() | ||
{ | ||
|
||
$this->test_it_can_register_a_new_user(); | ||
|
||
$this->assertDatabaseCount('coins_logs', 1); | ||
} | ||
} |