From 46e23228b9a9a4c00e0f765d510e7b007deba99a Mon Sep 17 00:00:00 2001 From: Paul Isaris Date: Wed, 11 Dec 2024 17:15:53 +0200 Subject: [PATCH] - Added after solution submission page --- .../Solution/SolutionManager.php | 25 +++++- .../Solution/SolutionController.php | 38 +++++++-- app/ViewModels/Solution/SolutionSubmitted.php | 21 +++++ resources/lang/en/solution.php | 6 ++ resources/views/solution/submitted.blade.php | 82 +++++++++++++++++++ routes/web.php | 2 +- 6 files changed, 160 insertions(+), 14 deletions(-) create mode 100644 app/ViewModels/Solution/SolutionSubmitted.php create mode 100644 resources/views/solution/submitted.blade.php 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') + +
+ +
+ +
+
+ {{ __("project-problems.back") }} +
+
+ +
+ +
+

{{ __("solution.thanks_for_proposal_title") }}

+
+

{!! __("solution.thanks_for_proposal_message") !!}

+
+
+ +
+ +
+ +
+ + +
+
+

{{ __('solution.solution_title') }}

+
+

{{ $viewModel->solution->defaultTranslation->title }}

+
+
+
+ +
+
+

{{ __('solution.solution_description') }}

+
+

{!! $viewModel->solution->defaultTranslation->description !!}

+
+
+
+

{{ __('solution.help_us_more_message') }}

+
+
+ + + + +
+ + +
+ +@endsection diff --git a/routes/web.php b/routes/web.php index 953537a5..d4ba3236 100644 --- a/routes/web.php +++ b/routes/web.php @@ -43,7 +43,7 @@ Route::group($localeInfo, function () use ($backOfficePrefix) { Route::get('/{project_slug}/problems/{problem_slug}/solutions/propose', [SolutionController::class, 'userProposalCreate'])->name('solutions.user-proposal-create'); Route::post('/{project_slug}/problems/{problem_slug}/solutions', [SolutionController::class, 'userProposalStore'])->name('solutions.user-proposal-store'); - Route::get('/{project_slug}/problems/{problem_slug}/solutions/solution-submitted', [SolutionController::class, 'userProposalSubmitted'])->name('solutions.user-proposal-submitted'); + Route::get('/{project_slug}/problems/{problem_slug}/solutions/{solution_slug}/submitted', [SolutionController::class, 'userProposalSubmitted'])->name('solutions.user-proposal-submitted'); Route::group(['prefix' => $backOfficePrefix], function () { Route::get('/my-dashboard', [UserController::class, 'myDashboard'])->name('my-dashboard'); Route::get('/my-account', [UserController::class, 'myAccount'])->name('my-account');