Compare commits
merge into: odon:master
odon:family_member_connections
odon:master
pull from: odon:family_member_connections
odon:family_member_connections
odon:master
11 Commits
master
...
family_mem
| Author | SHA1 | Message | Date |
|---|---|---|---|
|
|
be449bb0a4 |
User can cancel family connection request
|
5 years ago |
|
|
ca9972843c |
User can accept and reject family connection requests
|
5 years ago |
|
|
a1ab542407 |
Add cancel family connection request button
|
5 years ago |
|
|
f0b1e8ebb9 |
Change entities from FamilyMemberConnection to FamilyConnection
|
5 years ago |
|
|
be6eac814b |
User can send family connetion request to other person
|
5 years ago |
|
|
e425e07c89 |
Add family member connection status_id column
|
5 years ago |
|
|
d1846431e9 |
Add model for family_member_connections table
|
5 years ago |
|
|
c8ea7a0bf4 |
Swap requester and requested id for adding childs
|
5 years ago |
|
|
3912055b37 |
Move family_member_connections entry to controller
|
5 years ago |
|
|
23c82bfbf5 |
Make test passed for family_member_connections entries
|
5 years ago |
|
|
d2eb94c257 |
Draft a test
|
5 years ago |
10 changed files with 418 additions and 3 deletions
-
19app/FamilyConnection.php
-
62app/Http/Controllers/FamilyActionsController.php
-
55app/Http/Controllers/Users/FamilyConnectionRequestController.php
-
24app/User.php
-
36database/migrations/2021_03_28_091809_create_family_connections_table.php
-
14resources/views/users/partials/action-buttons.blade.php
-
9routes/web.php
-
110tests/Feature/FamilyConnectionRequestTest.php
-
56tests/Feature/ManageUserFamiliesTest.php
-
36tests/Unit/UserTest.php
@ -0,0 +1,19 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App; |
||||
|
|
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
|
||||
|
class FamilyConnection extends Model |
||||
|
{ |
||||
|
const STATUS_WAITING = 0; |
||||
|
const STATUS_APPROVED = 1; |
||||
|
|
||||
|
protected $fillable = [ |
||||
|
'id', 'requester_id', 'requested_id', 'status_id', |
||||
|
]; |
||||
|
|
||||
|
public $incrementing = false; |
||||
|
|
||||
|
protected $keyType = 'string'; |
||||
|
} |
||||
@ -0,0 +1,55 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Http\Controllers\Users; |
||||
|
|
||||
|
use App\FamilyConnection; |
||||
|
use App\Http\Controllers\Controller; |
||||
|
use App\User; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Ramsey\Uuid\Uuid; |
||||
|
|
||||
|
class FamilyConnectionRequestController extends Controller |
||||
|
{ |
||||
|
public function store(Request $request, User $user) |
||||
|
{ |
||||
|
FamilyConnection::create([ |
||||
|
'id' => Uuid::uuid4()->toString(), |
||||
|
'requester_id' => auth()->id(), |
||||
|
'requested_id' => $user->id, |
||||
|
'status_id' => FamilyConnection::STATUS_WAITING, |
||||
|
]); |
||||
|
|
||||
|
return back(); |
||||
|
} |
||||
|
|
||||
|
public function update(Request $request, User $user) |
||||
|
{ |
||||
|
$familyConnection = FamilyConnection::where([ |
||||
|
'requester_id' => $user->id, |
||||
|
'requested_id' => auth()->id(), |
||||
|
'status_id' => FamilyConnection::STATUS_WAITING, |
||||
|
])->first(); |
||||
|
|
||||
|
$familyConnection->status_id = FamilyConnection::STATUS_APPROVED; |
||||
|
$familyConnection->save(); |
||||
|
|
||||
|
return back(); |
||||
|
} |
||||
|
|
||||
|
public function destroy(Request $request, User $user) |
||||
|
{ |
||||
|
$familyConnection = FamilyConnection::where([ |
||||
|
'requester_id' => $user->id, |
||||
|
'requested_id' => auth()->id(), |
||||
|
'status_id' => FamilyConnection::STATUS_WAITING, |
||||
|
])->orWhere([ |
||||
|
'requester_id' => auth()->id(), |
||||
|
'requested_id' => $user->id, |
||||
|
'status_id' => FamilyConnection::STATUS_WAITING, |
||||
|
])->first(); |
||||
|
|
||||
|
$familyConnection->delete(); |
||||
|
|
||||
|
return back(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use Illuminate\Database\Migrations\Migration; |
||||
|
use Illuminate\Database\Schema\Blueprint; |
||||
|
use Illuminate\Support\Facades\Schema; |
||||
|
|
||||
|
class CreateFamilyConnectionsTable extends Migration |
||||
|
{ |
||||
|
/** |
||||
|
* Run the migrations. |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function up() |
||||
|
{ |
||||
|
Schema::create('family_connections', function (Blueprint $table) { |
||||
|
$table->uuid('id')->primary(); |
||||
|
$table->uuid('requester_id'); |
||||
|
$table->uuid('requested_id'); |
||||
|
$table->unsignedTinyInteger('status_id')->default(0); |
||||
|
$table->timestamps(); |
||||
|
|
||||
|
$table->unique(['requester_id', 'requested_id']); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Reverse the migrations. |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function down() |
||||
|
{ |
||||
|
Schema::dropIfExists('family_member_connections'); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,110 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Tests\Feature; |
||||
|
|
||||
|
use App\FamilyConnection; |
||||
|
use App\User; |
||||
|
use Illuminate\Foundation\Testing\RefreshDatabase; |
||||
|
use Ramsey\Uuid\Uuid; |
||||
|
use Tests\TestCase; |
||||
|
|
||||
|
class FamilyConnectionRequestTest extends TestCase |
||||
|
{ |
||||
|
use RefreshDatabase; |
||||
|
|
||||
|
/** @test */ |
||||
|
public function user_can_send_family_connection_request_to_other_user() |
||||
|
{ |
||||
|
$user = $this->loginAsUser(); |
||||
|
$otherPerson = factory(User::class)->create(); |
||||
|
|
||||
|
$this->dontSeeInDatabase('family_connections', [ |
||||
|
'requester_id' => $user->id, |
||||
|
'requested_id' => $otherPerson->id, |
||||
|
]); |
||||
|
|
||||
|
$this->visitRoute('users.show', $otherPerson); |
||||
|
$this->seeElement('button', ['id' => 'send_family_connection_request']); |
||||
|
$this->press('send_family_connection_request'); |
||||
|
$this->seeRouteIs('users.show', $otherPerson); |
||||
|
$this->seeElement('button', ['id' => 'cancel_family_connection_request']); |
||||
|
|
||||
|
$this->seeInDatabase('family_connections', [ |
||||
|
'requester_id' => $user->id, |
||||
|
'requested_id' => $otherPerson->id, |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** @test */ |
||||
|
public function user_can_cancel_family_connection_request_to_other_user() |
||||
|
{ |
||||
|
$user = $this->loginAsUser(); |
||||
|
$otherPerson = factory(User::class)->create(); |
||||
|
|
||||
|
FamilyConnection::create([ |
||||
|
'id' => Uuid::uuid4()->toString(), |
||||
|
'requester_id' => $user->id, |
||||
|
'requested_id' => $otherPerson->id, |
||||
|
]); |
||||
|
|
||||
|
$this->visitRoute('users.show', $otherPerson); |
||||
|
$this->seeElement('button', ['id' => 'cancel_family_connection_request']); |
||||
|
$this->press('cancel_family_connection_request'); |
||||
|
|
||||
|
$this->dontSeeInDatabase('family_connections', [ |
||||
|
'requester_id' => $otherPerson->id, |
||||
|
'requested_id' => $user->id, |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** @test */ |
||||
|
public function user_can_accept_family_connection_request_from_other_user() |
||||
|
{ |
||||
|
$user = $this->loginAsUser(); |
||||
|
$otherPerson = factory(User::class)->create(); |
||||
|
|
||||
|
FamilyConnection::create([ |
||||
|
'id' => Uuid::uuid4()->toString(), |
||||
|
'requester_id' => $otherPerson->id, |
||||
|
'requested_id' => $user->id, |
||||
|
]); |
||||
|
|
||||
|
$this->visitRoute('users.show', $otherPerson); |
||||
|
$this->seeElement('button', ['id' => 'accept_family_connection_request']); |
||||
|
$this->press('accept_family_connection_request'); |
||||
|
|
||||
|
$this->seeRouteIs('users.show', $otherPerson); |
||||
|
$this->seeInDatabase('family_connections', [ |
||||
|
'requester_id' => $otherPerson->id, |
||||
|
'requested_id' => $user->id, |
||||
|
'status_id' => FamilyConnection::STATUS_APPROVED, |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** @test */ |
||||
|
public function user_can_reject_family_connection_request_from_other_user() |
||||
|
{ |
||||
|
$user = $this->loginAsUser(); |
||||
|
$otherPerson = factory(User::class)->create(); |
||||
|
|
||||
|
FamilyConnection::create([ |
||||
|
'id' => Uuid::uuid4()->toString(), |
||||
|
'requester_id' => $otherPerson->id, |
||||
|
'requested_id' => $user->id, |
||||
|
]); |
||||
|
$this->seeInDatabase('family_connections', [ |
||||
|
'requester_id' => $otherPerson->id, |
||||
|
'requested_id' => $user->id, |
||||
|
]); |
||||
|
|
||||
|
$this->visitRoute('users.show', $otherPerson); |
||||
|
$this->seeElement('button', ['id' => 'reject_family_connection_request']); |
||||
|
$this->press('reject_family_connection_request'); |
||||
|
|
||||
|
$this->seeRouteIs('users.show', $otherPerson); |
||||
|
$this->dontSeeInDatabase('family_connections', [ |
||||
|
'requester_id' => $otherPerson->id, |
||||
|
'requested_id' => $user->id, |
||||
|
]); |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue