Skip to content

Commit 62ea64b

Browse files
authored
Merge pull request #38 from laravelcm/badges-reputations
Badges reputations
2 parents 1fa6dc5 + b7bb099 commit 62ea64b

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

app/Gamify/Points/ReplyCreated.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22

33
namespace App\Gamify\Points;
44

5+
use App\Models\User;
56
use QCod\Gamify\PointType;
67

78
class ReplyCreated extends PointType
89
{
910
public int $points = 2;
1011

11-
public function __construct($subject)
12+
public User $author;
13+
14+
public function __construct($subject, $author)
1215
{
1316
$this->subject = $subject;
17+
$this->author = $author;
1418
}
1519

1620
public function payee()
1721
{
18-
return $this->getSubject()->author;
22+
return $this->author;
1923
}
2024
}

app/Http/Controllers/Api/ReplyController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function store(CreateReplyRequest $request): ReplyResource
4747
$reply->to($target);
4848
$reply->save();
4949

50-
givePoint(new ReplyCreated($target), $author);
50+
$author->givePoint(new ReplyCreated($target, $author));
5151

5252
// On envoie un event pour une nouvelle réponse à tous les abonnés de la discussion
5353
event(new CommentWasAdded($reply, $target));
@@ -79,6 +79,9 @@ public function delete(int $id): JsonResponse
7979
{
8080
/** @var Reply $reply */
8181
$reply = Reply::findOrFail($id);
82+
83+
undoPoint(new ReplyCreated($reply->replyAble, $reply->author));
84+
8285
$reply->delete();
8386

8487
return response()->json(['message' => 'Commentaire supprimé avec succès']);

app/Http/Livewire/Forum/CreateReply.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public function save()
4040
$reply->to($this->thread);
4141
$reply->save();
4242

43-
event(new ReplyWasCreated($reply));
43+
givePoint(new ReplyCreated($this->thread, Auth::user()));
4444

45-
givePoint(new ReplyCreated($this->thread));
45+
event(new ReplyWasCreated($reply));
4646

4747
session()->flash('status', 'Réponse ajoutée avec succès!');
4848

0 commit comments

Comments
 (0)