diff --git a/app/BusinessLogicLayer/Solution/SolutionManager.php b/app/BusinessLogicLayer/Solution/SolutionManager.php
index 747794fc..41475c56 100644
--- a/app/BusinessLogicLayer/Solution/SolutionManager.php
+++ b/app/BusinessLogicLayer/Solution/SolutionManager.php
@@ -7,6 +7,7 @@
use App\BusinessLogicLayer\Problem\ProblemTranslationManager;
use App\Models\Solution\Solution;
use App\Models\Solution\SolutionTranslation;
+use App\Repository\CrowdSourcingProject\CrowdSourcingProjectRepository;
use App\Repository\LanguageRepository;
use App\Repository\Problem\ProblemRepository;
use App\Repository\RepositoryException;
@@ -14,6 +15,7 @@
use App\Utils\FileHandler;
use App\ViewModels\Solution\CreateEditSolution;
use App\ViewModels\Solution\ProposeSolutionPage;
+use App\ViewModels\Solution\SolutionSubmitted;
use Exception;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
@@ -24,6 +26,7 @@
class SolutionManager {
protected SolutionRepository $solutionRepository;
protected ProblemRepository $problemRepository;
+ protected CrowdSourcingProjectRepository $crowdSourcingProjectRepository;
protected SolutionTranslationManager $solutionTranslationManager;
protected SolutionStatusManager $solutionStatusManager;
protected LanguageRepository $languageRepository;
@@ -33,6 +36,7 @@ class SolutionManager {
public function __construct(
SolutionRepository $solutionRepository,
ProblemRepository $problemRepository,
+ CrowdSourcingProjectRepository $crowdSourcingProjectRepository,
SolutionTranslationManager $solutionTranslationManager,
SolutionStatusManager $solutionStatusManager,
LanguageRepository $languageRepository,
@@ -41,6 +45,7 @@ public function __construct(
) {
$this->solutionRepository = $solutionRepository;
$this->problemRepository = $problemRepository;
+ $this->crowdSourcingProjectRepository = $crowdSourcingProjectRepository;
$this->solutionTranslationManager = $solutionTranslationManager;
$this->solutionStatusManager = $solutionStatusManager;
$this->languageRepository = $languageRepository;
@@ -85,7 +90,7 @@ public function getCreateEditSolutionViewModel(?int $problem_id, ?int $solution_
* @param array $attributes the attributes of the solution
* @throws Exception
*/
- public function storeSolution(array $attributes): int {
+ public function storeSolution(array $attributes): Solution {
return $this->storeSolutionWithStatus($attributes, $attributes['solution-status']);
}
@@ -94,7 +99,7 @@ public function storeSolution(array $attributes): int {
* @param array $attributes the attributes of the solution
* @throws Exception
*/
- public function storeSolutionFromPublicForm(array $attributes): int {
+ public function storeSolutionFromPublicForm(array $attributes): Solution {
return $this->storeSolutionWithStatus($attributes, SolutionStatusLkp::UNPUBLISHED);
}
@@ -103,7 +108,7 @@ public function storeSolutionFromPublicForm(array $attributes): int {
* @param array $attributes the attributes of the solution
* @throws Exception
*/
- protected function storeSolutionWithStatus(array $attributes, int $status_id): int {
+ protected function storeSolutionWithStatus(array $attributes, int $status_id): Solution {
if (isset($attributes['solution-image']) && $attributes['solution-image']->isValid()) {
$imgPath = FileHandler::uploadAndGetPath($attributes['solution-image'], 'solution_img');
} else {
@@ -132,7 +137,7 @@ protected function storeSolutionWithStatus(array $attributes, int $status_id): i
]);
DB::commit();
- return $solution->id;
+ return $solution;
} catch (\Exception $e) {
Log::error('Error: ' . $e->getCode() . ' ' . $e->getMessage());
DB::rollBack();
@@ -234,4 +239,16 @@ public function getProposeSolutionPageViewModel(string $locale, string $project_
return new ProposeSolutionPage($project, $problem, $localeLanguage);
}
+
+ public function getSolutionSubmittedViewModel(string $project_slug, string $problem_slug, string $solution_slug): SolutionSubmitted {
+ $project = $this->crowdSourcingProjectRepository->findBy('slug', $project_slug);
+ $project->currentTranslation = $this->crowdSourcingProjectTranslationManager->getFieldsTranslationForProject($project);
+
+ $problem = $this->problemRepository->findBy('slug', $problem_slug);
+ $problem->currentTranslation = $this->problemTranslationManager->getProblemCurrentTranslation($problem->id, app()->getLocale());
+
+ $solution = $this->solutionRepository->findBy('slug', $solution_slug);
+
+ return new SolutionSubmitted($solution, $problem, $project);
+ }
}
diff --git a/app/Http/Controllers/Solution/SolutionController.php b/app/Http/Controllers/Solution/SolutionController.php
index b80872f6..2d290ce3 100644
--- a/app/Http/Controllers/Solution/SolutionController.php
+++ b/app/Http/Controllers/Solution/SolutionController.php
@@ -56,7 +56,7 @@ public function store(Request $request): RedirectResponse {
]);
try {
- $createdSolutionId = $this->solutionManager->storeSolution($validated);
+ $createdSolutionId = $this->solutionManager->storeSolution($validated)->id;
} catch (\Exception $e) {
session()->flash('flash_message_error', 'Error: ' . $e->getCode() . ' ' . $e->getMessage());
@@ -79,17 +79,22 @@ public function userProposalStore(Request $request): RedirectResponse {
]);
try {
- $this->solutionManager->storeSolutionFromPublicForm($validated);
+ $solution = $this->solutionManager->storeSolutionFromPublicForm($validated);
+ $problem = $solution->problem;
+ $project = $problem->project;
+
+ $route = route('solutions.user-proposal-submitted', [
+ 'project_slug' => $project->slug,
+ 'problem_slug' => $problem->slug,
+ 'solution_slug' => $solution->slug,
+ ]);
+
+ return redirect($route);
} catch (\Exception $e) {
session()->flash('flash_message_error', 'Error: ' . $e->getCode() . ' ' . $e->getMessage());
return back()->withInput();
}
-
- session()->flash('flash_message_success', 'Solution Created Successfully.');
-
- // redirect to the same route as the current one, with a "/solution-submitted" suffix
- return redirect($request->path() . '/solution-submitted');
}
/**
@@ -198,7 +203,22 @@ public function userProposalCreate(string $locale, string $project_slug, string
}
}
- public function userProposalSubmitted(Request $request) {
- return 'userProposalSubmitted';
+ public function userProposalSubmitted(string $locale, string $project_slug, string $problem_slug, string $solution_slug): View {
+ $validator = Validator::make([
+ 'project_slug' => $project_slug,
+ 'problem_slug' => $problem_slug,
+ 'solution_slug' => $solution_slug,
+ ], [
+ 'solution_slug' => 'required|exists:solutions,slug',
+ 'problem_slug' => 'required|exists:problems,slug',
+ 'project_slug' => 'required|exists:crowd_sourcing_projects,slug',
+ ]);
+
+ if ($validator->fails()) {
+ abort(ResponseAlias::HTTP_NOT_FOUND);
+ }
+ $viewModel = $this->solutionManager->getSolutionSubmittedViewModel($project_slug, $problem_slug, $solution_slug);
+
+ return view('solution.submitted', ['viewModel' => $viewModel]);
}
}
diff --git a/app/ViewModels/Solution/SolutionSubmitted.php b/app/ViewModels/Solution/SolutionSubmitted.php
new file mode 100644
index 00000000..80fe0edb
--- /dev/null
+++ b/app/ViewModels/Solution/SolutionSubmitted.php
@@ -0,0 +1,21 @@
+solution = $solution;
+ $this->problem = $problem;
+ $this->project = $project;
+ $this->page_title = $project->currentTranslation->name . ' | ' . $problem->currentTranslation->title . ' ➔ ' . __('solution.proposal_submitted_title');
+ }
+}
diff --git a/resources/lang/en/solution.php b/resources/lang/en/solution.php
index 9088de65..ce8618c8 100644
--- a/resources/lang/en/solution.php
+++ b/resources/lang/en/solution.php
@@ -2,4 +2,10 @@
return [
'propose_solution' => 'Propose Solution',
+ 'proposal_submitted_title' => 'Proposal Submitted',
+ 'thanks_for_proposal_title' => 'Thanks for your proposal! It means a lot to us.',
+ 'thanks_for_proposal_message' => 'Your proposal has been submitted successfully! It will be thoroughly reviewed by our team. We will get back to you as soon as possible.
With your help, we can make the world a better place!',
+ 'solution_title' => 'Solution Title',
+ 'solution_description' => 'Solution Description',
+ 'help_us_more_message' => 'Help us more by submitting more solutions!',
];
diff --git a/resources/views/solution/submitted.blade.php b/resources/views/solution/submitted.blade.php
new file mode 100644
index 00000000..de842acd
--- /dev/null
+++ b/resources/views/solution/submitted.blade.php
@@ -0,0 +1,82 @@
+@extends('crowdsourcing-project.layout')
+@push('css')
+ @vite('resources/assets/sass/problem/show-page.scss')
+
+@endpush
+
+@section('content')
+
+
{!! __("solution.thanks_for_proposal_message") !!}
+{{ $viewModel->solution->defaultTranslation->title }}
+{!! $viewModel->solution->defaultTranslation->description !!}
+