Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions api/database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public function run(int $n = 1): void
{
$this->call([
UserSeeder::class,
// MatchesSeeder::class,
// MessageSeeder::class,
// TagSeeder::class,
MatchesSeeder::class,
MessageSeeder::class,
TagSeeder::class,
], $n);
}

Expand Down
4 changes: 4 additions & 0 deletions api/database/seeders/MatchesSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public function run(): void
for ($i = 0; $i < count($users); $i++) {
foreach (faker()->randomElements($users, rand(0, count($users) / 2)) as $user) {
try {
if ($user->id === $users[$i]->id) {
continue;
}

$users[$i]->like($user);
$user->like($users[$i]);
} catch (\Exception) {
Expand Down
15 changes: 15 additions & 0 deletions api/src/Exceptions/AutoLikeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Matcha\Api\Exceptions;

use Exception;

class AutoLikeException extends Exception
{

public function __construct()
{
parent::__construct("A user cannot like themselves.");
}

}
6 changes: 6 additions & 0 deletions api/src/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Firebase\JWT\JWT;
use Flight;
use Matcha\Api\Builder\JoinBuilder;
use Matcha\Api\Exceptions\AutoLikeException;
use Matcha\Api\Validator\Asserts\Email;
use Matcha\Api\Validator\Asserts\Minimum;
use Matcha\Api\Validator\Asserts\NotBlank;
Expand Down Expand Up @@ -109,9 +110,14 @@ public function getAvatar(): ?string
*
* @param User $user
* @return void
* @throws AutoLikeException
*/
public function like(User $user): void
{
if ($this->id === $user->id) {
throw new AutoLikeException();
}

$like = new Like();

$like->user_id = $this->id;
Expand Down