Skip to content

Commit

Permalink
- Added after solution submission page
Browse files Browse the repository at this point in the history
  • Loading branch information
PavlosIsaris committed Dec 11, 2024
1 parent 2f19479 commit 46e2322
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 14 deletions.
25 changes: 21 additions & 4 deletions app/BusinessLogicLayer/Solution/SolutionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
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;
use App\Repository\Solution\SolutionRepository;
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;
Expand All @@ -24,6 +26,7 @@
class SolutionManager {
protected SolutionRepository $solutionRepository;
protected ProblemRepository $problemRepository;
protected CrowdSourcingProjectRepository $crowdSourcingProjectRepository;
protected SolutionTranslationManager $solutionTranslationManager;
protected SolutionStatusManager $solutionStatusManager;
protected LanguageRepository $languageRepository;
Expand All @@ -33,6 +36,7 @@ class SolutionManager {
public function __construct(
SolutionRepository $solutionRepository,
ProblemRepository $problemRepository,
CrowdSourcingProjectRepository $crowdSourcingProjectRepository,
SolutionTranslationManager $solutionTranslationManager,
SolutionStatusManager $solutionStatusManager,
LanguageRepository $languageRepository,
Expand All @@ -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;
Expand Down Expand Up @@ -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']);
}

Expand All @@ -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);
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
38 changes: 29 additions & 9 deletions app/Http/Controllers/Solution/SolutionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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');
}

/**
Expand Down Expand Up @@ -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]);
}
}
21 changes: 21 additions & 0 deletions app/ViewModels/Solution/SolutionSubmitted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\ViewModels\Solution;

use App\Models\CrowdSourcingProject\CrowdSourcingProject;
use App\Models\Problem\Problem;
use App\Models\Solution\Solution;

class SolutionSubmitted {
public Solution $solution;
public Problem $problem;
public CrowdSourcingProject $project;
public string $page_title;

public function __construct(Solution $solution, Problem $problem, CrowdSourcingProject $project) {
$this->solution = $solution;
$this->problem = $problem;
$this->project = $project;
$this->page_title = $project->currentTranslation->name . ' | ' . $problem->currentTranslation->title . '' . __('solution.proposal_submitted_title');
}
}
6 changes: 6 additions & 0 deletions resources/lang/en/solution.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. <br><br><b>With your help</b>, 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!',
];
82 changes: 82 additions & 0 deletions resources/views/solution/submitted.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
@extends('crowdsourcing-project.layout')
@push('css')
@vite('resources/assets/sass/problem/show-page.scss')
<style>
:root {
--project-primary-color: {{ $viewModel->project->lp_primary_color}};
--btn-text-color: {{ $viewModel->project->lp_btn_text_color_theme == "light" ? "#ffffff" : "#212529"}};
}
</style>
@endpush

@section('content')

<div id="single-problem-page" class="pb-5">

<div class="container px-sm-0">

<div class="row">
<div class="col-12 mt-2 mb-4 pt-1">
<x-go-back-link href="/{{ app()->getLocale() .'/'. $viewModel->project->slug . '/problems' }}"
class="d-none d-lg-block">{{ __("project-problems.back") }}</x-go-back-link>
</div>
</div>

<div class="row how-to-vote">

<div class="col-12 col-lg-7">
<h2 class="section-title">{{ __("solution.thanks_for_proposal_title") }}</h2>
<div class="section-body pb-5 pb-lg-0">
<p>{!! __("solution.thanks_for_proposal_message") !!}</p>
</div>
</div>

<div class="col-12 col-lg-4 offset-lg-1 align-self-end text-center">
<img src="/images/problems/[email protected]" alt="" width="384" height="344"
class="img-fluid">
</div>

</div>


<div class="row">
<div class="col-12 my-4 my-lg-3 pt-2">
<h3 class="section-title">{{ __('solution.solution_title') }}</h3>
<div class="section-body pb-5 pb-lg-0">
<p>{{ $viewModel->solution->defaultTranslation->title }}</p>
</div>
</div>
</div>

<div class="row">
<div class="col-12 pt-4">
<h3 class="section-title">{{ __('solution.solution_description') }}</h3>
<div class="section-body pb-5 pb-lg-0">
<p>{!! $viewModel->solution->defaultTranslation->description !!}</p>
</div>
</div>
<div class="col-12 py-4">
<h3>{{ __('solution.help_us_more_message') }}</h3>
</div>
</div>


<div class="row">
<div class="col-lg-5 col-sm-11 mx-auto my-1 my-lg-1 py-3">
<a class="btn btn-primary btn-block"
href="{{ route('project.problems-page', [
'locale' => app()->getLocale(),
'project_slug' => $viewModel->project->slug
]) }}">
{{ __("menu.see_all_problems") }} & {{ __('project-problems.suggest_solution') }}<i
class="fas fa-arrow-right ml-2"></i>
</a>
</div>
</div>

</div>


</div>

@endsection
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 46e2322

Please sign in to comment.