Skip to content

Commit

Permalink
IP-325: As a platform user, when a solution I submitted is published,…
Browse files Browse the repository at this point in the history
… I receive an email so that I can view the solution I submitted
  • Loading branch information
PavlosIsaris committed Dec 16, 2024
1 parent cad429e commit 11e2563
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/Http/Controllers/Solution/SolutionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\BusinessLogicLayer\Solution\SolutionManager;
use App\Http\Controllers\Controller;
use App\Models\Solution\Solution;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
Expand All @@ -29,6 +30,17 @@ public function index(): View {
* Show the form for creating a new resource.
*/
public function create(Request $request): View|RedirectResponse {
$user = auth()->user();
$solution = Solution::find(1);
// notify the user that their solution has been submitted
$user->notify(new \App\Notifications\SolutionSubmitted($solution));

// get the creator of the solution problem
$problem_creator = $solution->problem->creator;

// notify the creator of the solution submission
$problem_creator->notify(new \App\Notifications\SolutionPublished($solution));

$this->validate($request, [
'problem_id' => 'required|different:execute_solution|exists:problems,id',
]);
Expand Down
58 changes: 58 additions & 0 deletions app/Notifications/SolutionPublished.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace App\Notifications;

use App\Models\Solution\Solution;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class SolutionPublished extends Notification implements ShouldQueue {
use Queueable;

protected Solution $solution;

/**
* Create a new notification instance.
*/
public function __construct(Solution $solution) {
$this->solution = $solution;
}

/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array {
return ['mail'];
}

/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage {
return (new MailMessage)
->subject('Crowdsourcing Platform | ' . __('notifications.solution_published') . ': ' . $this->solution->defaultTranslation->title)
->line(__('notifications.solution_published_intro'))
->line('<div style="text-align:center; height: 200px; margin-bottom: 10px;"><img style="height: 200px; margin-bottom: 0;" src=' . asset('images/dancing.png') . '></div>')
->line('<div style="text-align:center; font-size: 10px; margin-bottom: 10px;"><a href="https://www.flaticon.com/free-stickers/people" title="people stickers">People stickers created by Stickers - Flaticon</a></div>')
->greeting(__('notifications.hello') . ' ' . $notifiable->nickname . '!')
->line(__('notifications.solution_published_message'))
->action(__('notifications.see_the_solution'), route('problem.show.solutions', ['problem_slug' => $this->solution->problem->slug, 'project_slug' => $this->solution->problem->project->slug]) . '?solution_id=' . $this->solution->id)
->line(__('notifications.making_impact'))
->salutation(__('notifications.thanks_message_2'));
}

/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array {
return [
//
];
}
}
3 changes: 2 additions & 1 deletion app/Notifications/SolutionSubmitted.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public function toMail(object $notifiable): MailMessage {
return (new MailMessage)
->subject('Crowdsourcing Platform | ' . __('notifications.solution_submitted') . ': ' . $this->solution->defaultTranslation->title)
->line(__('notifications.thank_you_for_contribution'))
->line('<div style="text-align:center; height: 200px; margin-bottom: 20px;"><img class="badgeImg" style="height: 200px; margin-bottom: 0;" src=' . asset('images/active_participation.webp') . '></div>')
->line('<div style="text-align:center; height: 200px; margin-bottom: 10px;"><img style="height: 200px; margin-bottom: 0;" src=' . asset('images/team-spirit.png') . '></div>')
->line('<div style="text-align:center; font-size: 10px; margin-bottom: 10px;"><a href="https://www.flaticon.com/free-stickers/people" title="people stickers">People stickers created by Stickers - Flaticon</a></div>')
->greeting(__('notifications.hello') . ' ' . $notifiable->nickname . '!')
->line(__('notifications.thanks_for_proposing_solution'))
->action(__('notifications.visit_your_dashboard'), route('my-dashboard', ['locale' => app()->getLocale()]))
Expand Down
Binary file added public/images/dancing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/team-spirit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions resources/lang/en/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@
'a_user_has_proposed_solution' => 'A user has proposed a solution.',
'check_solution_and_review' => 'Please check the solution and review it.',
'see_submitted_solutions' => 'See Submitted Solutions',
'solution_published' => 'Solution Published',
'solution_published_intro' => 'Your solution has been published!',
'solution_published_message' => 'Your solution has been published and is now available for other users to vote on!',
'see_the_solution' => 'See the solution',
];

0 comments on commit 11e2563

Please sign in to comment.