Skip to content

Commit

Permalink
feat: avatar on contact list (monicahq/chandler#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored May 2, 2022
1 parent c003ab0 commit 704a452
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\User;
use App\Models\Vault;
use App\Helpers\AvatarHelper;

class ContactIndexViewHelper
{
Expand All @@ -14,6 +15,7 @@ public static function data($contacts, User $user, Vault $vault): array
$contactCollection->push([
'id' => $contact->id,
'name' => $contact->getName($user),
'avatar' => AvatarHelper::getSVG($contact),
'url' => [
'show' => route('contact.show', [
'vault' => $vault->id,
Expand Down
11 changes: 0 additions & 11 deletions domains/Contact/ManageLoans/Services/CreateLoan.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use App\Jobs\CreateAuditLog;
use App\Services\BaseService;
use App\Jobs\CreateContactLog;
use App\Models\ContactFeedItem;
use Illuminate\Support\Collection;
use App\Interfaces\ServiceInterface;

Expand Down Expand Up @@ -73,7 +72,6 @@ public function execute(array $data): Loan
$this->contact->save();

$this->log();
$this->createFeedItem();

return $this->loan;
}
Expand Down Expand Up @@ -146,13 +144,4 @@ private function log(): void
]),
])->onQueue('low');
}

private function createFeedItem(): void
{
$feedItem = ContactFeedItem::create([
'contact_id' => $this->contact->id,
'action' => ContactFeedItem::ACTION_LOAN_CREATED,
]);
$this->loan->feedItem()->save($feedItem);
}
}
7 changes: 0 additions & 7 deletions domains/Contact/ManageLoans/Services/DestroyLoan.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public function execute(array $data): void

$this->loan = Loan::where('vault_id', $data['vault_id'])->findOrFail($data['loan_id']);

$this->removeContactFeedItem();

$this->loan->delete();

$this->contact->last_updated_at = Carbon::now();
Expand Down Expand Up @@ -86,9 +84,4 @@ private function log(): void
'objects' => json_encode([]),
])->onQueue('low');
}

private function removeContactFeedItem(): void
{
$this->loan->feedItem()->delete();
}
}
11 changes: 0 additions & 11 deletions domains/Contact/ManageLoans/Services/UpdateLoan.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use App\Jobs\CreateAuditLog;
use App\Services\BaseService;
use App\Jobs\CreateContactLog;
use App\Models\ContactFeedItem;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use App\Interfaces\ServiceInterface;
Expand Down Expand Up @@ -70,7 +69,6 @@ public function execute(array $data): Loan
$this->data = $data;
$this->validate();
$this->update();
$this->createFeedItem();
$this->log();

return $this->loan;
Expand Down Expand Up @@ -151,13 +149,4 @@ private function log(): void
]),
])->onQueue('low');
}

private function createFeedItem(): void
{
$feedItem = ContactFeedItem::create([
'contact_id' => $this->contact->id,
'action' => ContactFeedItem::ACTION_LOAN_UPDATED,
]);
$this->loan->feedItem()->save($feedItem);
}
}
3 changes: 2 additions & 1 deletion resources/js/Pages/Vault/Contact/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
<li
v-for="contact in data.contacts"
:key="contact.id"
class="border-b border-gray-200 px-5 py-2 hover:bg-slate-50">
class="flex items-center border-b border-gray-200 px-5 py-2 hover:bg-slate-50">
<div v-html="contact.avatar" class="mr-2 h-5 w-5"></div>
<inertia-link :href="contact.url.show" class="text-sky-500 hover:text-blue-900">
{{ contact.name }}
</inertia-link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Tests\TestCase;
use App\Models\User;
use App\Models\Vault;
use App\Models\Avatar;
use App\Models\Contact;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\Contact\ManageContact\Web\ViewHelpers\ContactIndexViewHelper;
Expand All @@ -21,6 +22,12 @@ public function it_gets_the_data_needed_for_the_view(): void
$contact = Contact::factory()->create([
'vault_id' => $vault->id,
]);
$avatar = Avatar::factory()->create([
'contact_id' => $contact->id,
]);
$contact->avatar_id = $avatar->id;
$contact->save();

$user = User::factory()->create();
$contacts = Contact::all();
$array = ContactIndexViewHelper::data($contacts, $user, $vault);
Expand All @@ -38,6 +45,7 @@ public function it_gets_the_data_needed_for_the_view(): void
0 => [
'id' => $contact->id,
'name' => $contact->getName($user),
'avatar' => '123',
'url' => [
'show' => env('APP_URL').'/vaults/'.$vault->id.'/contacts/'.$contact->id,
],
Expand Down
11 changes: 0 additions & 11 deletions tests/Unit/Domains/Contact/ManageLoans/Services/CreateLoanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,6 @@ private function executeService(User $author, Account $account, Vault $vault, Co
'loanee_id' => $loanee->id,
]);

$this->assertDatabaseHas('contact_feed_items', [
'contact_id' => $contact->id,
'feedable_id' => $loan->id,
'feedable_type' => 'App\Models\Loan',
]);
$this->assertDatabaseHas('contact_feed_items', [
'contact_id' => $contact->id,
'feedable_id' => $loan->id,
'feedable_type' => 'App\Models\Loan',
]);

Queue::assertPushed(CreateAuditLog::class, function ($job) {
return $job->auditLog['action_name'] === 'loan_created';
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ private function executeService(User $author, Account $account, Vault $vault, Co
'id' => $loan->id,
]);

$this->assertDatabaseMissing('contact_feed_items', [
'contact_id' => $contact->id,
'feedable_id' => $loan->id,
]);

Queue::assertPushed(CreateAuditLog::class, function ($job) {
return $job->auditLog['action_name'] === 'loan_destroyed';
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,6 @@ private function executeService(User $author, Account $account, Vault $vault, Co
'loaned_at' => '2020-01-01 00:00:00',
]);

$this->assertDatabaseHas('contact_feed_items', [
'contact_id' => $contact->id,
'feedable_id' => $loan->id,
'feedable_type' => 'App\Models\Loan',
]);

$this->assertDatabaseHas('contact_loan', [
'loan_id' => $loan->id,
'loaner_id' => $loaner->id,
Expand Down

0 comments on commit 704a452

Please sign in to comment.