Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions app/Http/Controllers/User/SolutionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ class SolutionController extends Controller

public function __construct(ActivityService $activityService)
{
$this->authorizeResource(Solution::class, 'solution');
// $this->authorizeResource(Solution::class, 'solution', [
// 'except' => ['show'],
// ]);
$this->activityService = $activityService;
}

public function store(Request $request, User $user): RedirectResponse
{
$this->authorize('create', Solution::class);

$validatedData = $request->validate([
'content' => 'required|string|min:1',
]);
Expand All @@ -45,23 +49,30 @@ public function store(Request $request, User $user): RedirectResponse

public function show(User $user, Solution $solution): View
{

$currentExercise = $solution->exercise;

$solutionsListForCurrentExercise = $solution->exercise
$solutionsOfCurrentUser = $solution->exercise
->solutions()
->where('user_id', $user->id)
->get();

return view('solution.show', compact(
$solutionsOfOtherUsers = $solution->exercise
->solutions()
->whereNot('user_id', $user->id)
->get();

return view('user.solution.show', compact(
'currentExercise',
'solutionsListForCurrentExercise',
'user'
'solutionsOfCurrentUser',
'solutionsOfOtherUsers',
'user',
));
}

public function destroy(User $user, Solution $solution): RedirectResponse
{
$this->authorize('delete', $solution);

if ($solution->delete()) {
flash()->success(__('layout.flash.success'));
} else {
Expand Down
3 changes: 3 additions & 0 deletions resources/lang/en/solution.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
'code_review' => 'Code Review',
'sub_title' => 'Compare your solutions',
'solution_for_title' => 'Solution for Exercise :exercise',
'solutions_of_others' => 'Solution of other users',
'login_to_view' => 'Log in to see the solution',
'please_login_to_view_solution' => 'Please log in to view the solution',
];
3 changes: 3 additions & 0 deletions resources/lang/ru/solution.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
'code_review' => 'Код Ревью',
'sub_title' => 'Сравни свои решения',
'solution_for_title' => 'Решение для упражнения :exercise',
'solutions_of_others' => 'Решение других пользователей',
'login_to_view' => 'Войдите чтобы увидеть решение',
'please_login_to_view_solution' => 'Пожалуйста, войдите в систему для просмотра решения',
];
59 changes: 9 additions & 50 deletions resources/views/solution/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
{{ getTitleContent(__('solution.solution_for_title', ['exercise' => $currentExercise->getFullTitle()])) }}
@endsection
@section('description'){{ $user->id }} - {{ __('solution.code_review') }} - {{ $user->name }} -
{{ __('solution.exercise') }} {{ $currentExercise->getFullTitle() }}@endsection
{{ __('solution.exercise') }} {{ $currentExercise->getFullTitle() }}@endsection

@section('content')

<div class="d-flex flex-wrap justify-content-between mb-2 mb-lg-4">
<div class="h5">
<a href="{{ route('exercises.show', $currentExercise) }}">
{{ __('solution.exercise') }} {{ $currentExercise->getFullTitle() }}
{{ __('solution.exercise') }} {{ $currentExercise->getFullTitle() }}
</div>
<div class="h5">
<a href="{{ route('users.show', $user) }}">{{ $user->name }}</a>
</div>
</div>

<h2 class="text-center">{{ __('solution.code_review') }}</h2>
<div class="text-center h5">{{ __('solution.sub_title') }}</div>
<h2 class="text-center">{{ __('solution.title_add_solution') }}</h2>
<hr>
<div class="row no-gutters">
<div class="col-12 col-md p-2 p-lg-4">
Expand All @@ -29,14 +28,14 @@
@if ($loop->first)
<li class="nav-item" role="presentation">
<a class="nav-link active" id="pills-{{ $currentSolution->id }}-tab" data-bs-toggle="pill"
href="#pills-{{ $currentSolution->id }}" role="tab" aria-controls="pills-{{ $currentSolution->id }}"
aria-selected="true">v.{{ $loop->iteration }}</a>
href="#pills-{{ $currentSolution->id }}" role="tab" aria-controls="pills-{{ $currentSolution->id }}"
aria-selected="true">v.{{ $loop->iteration }}</a>
</li>
@else
<li class="nav-item" role="presentation">
<a class="nav-link" id="pills-{{ $currentSolution->id }}-tab" data-bs-toggle="pill"
href="#pills-{{ $currentSolution->id }}" role="tab" aria-controls="pills-{{ $currentSolution->id }}"
aria-selected="true">v.{{ $loop->iteration }}</a>
href="#pills-{{ $currentSolution->id }}" role="tab" aria-controls="pills-{{ $currentSolution->id }}"
aria-selected="true">v.{{ $loop->iteration }}</a>
</li>
@endif
@endforeach
Expand All @@ -45,57 +44,17 @@
@foreach ($solutionsListForCurrentExercise as $currentSolution)
@if ($loop->first)
<div class="tab-pane fade show active" id="pills-{{ $currentSolution->id }}" role="tabpanel"
aria-labelledby="pills-{{ $currentSolution->id }}-tab">
aria-labelledby="pills-{{ $currentSolution->id }}-tab">
@solution(['solution' => $currentSolution])
</div>
@else
<div class="tab-pane fade show" id="pills-{{ $currentSolution->id }}" role="tabpanel"
aria-labelledby="pills-{{ $currentSolution->id }}-tab">
aria-labelledby="pills-{{ $currentSolution->id }}-tab">
@solution(['solution' => $currentSolution])
</div>
@endif
@endforeach
</div>
</div>

@if (count($solutionsListForCurrentExercise) > 1)
<div class="d-none d-md-block border-left"></div>
<div class="col p-2 p-lg-4">
<ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
@foreach ($solutionsListForCurrentExercise as $currentSolution)
@if ($loop->first)
<li class="nav-item" role="presentation">
<a class="nav-link active" id="pills-{{ $currentSolution->id }}double-tab" data-bs-toggle="pill"
href="#pills-{{ $currentSolution->id }}double" role="tab"
aria-controls="pills-{{ $currentSolution->id }}double"
aria-selected="true">v.{{ $loop->iteration }}</a>
</li>
@else
<li class="nav-item" role="presentation">
<a class="nav-link" id="pills-{{ $currentSolution->id }}double-tab" data-bs-toggle="pill"
href="#pills-{{ $currentSolution->id }}double" role="tab"
aria-controls="pills-{{ $currentSolution->id }}double"
aria-selected="true">v.{{ $loop->iteration }}</a>
</li>
@endif
@endforeach
</ul>
<div class="tab-content" id="pills-tabContent">
@foreach ($solutionsListForCurrentExercise as $currentSolution)
@if ($loop->first)
<div class="tab-pane fade show active" id="pills-{{ $currentSolution->id }}double" role="tabpanel"
aria-labelledby="pills-{{ $currentSolution->id }}double-tab">
@solution(['solution' => $currentSolution])
</div>
@else
<div class="tab-pane fade show" id="pills-{{ $currentSolution->id }}double" role="tabpanel"
aria-labelledby="pills-{{ $currentSolution->id }}double-tab">
@solution(['solution' => $currentSolution])
</div>
@endif
@endforeach
</div>
</div>
@endif
</div>
@endsection
123 changes: 123 additions & 0 deletions resources/views/user/solution/show.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
@extends('layouts.app')

@section('meta-robots', 'nofollow, noindex')
@section('title')
{{ getTitleContent(__('solution.solution_for_title', ['exercise' => $currentExercise->getFullTitle()])) }}
@endsection
@section('description'){{ $user->id }} - {{ __('solution.code_review') }} - {{ $user->name }} -
{{ __('solution.exercise') }} {{ $currentExercise->getFullTitle() }}@endsection

@section('content')

@auth
<div class="d-flex flex-wrap justify-content-between mb-2 mb-lg-4">
<div class="h5">
<a href="{{ route('exercises.show', $currentExercise) }}">
{{ __('solution.exercise') }} {{ $currentExercise->getFullTitle() }}
</div>
<div class="h5">
<a href="{{ route('users.show', $user) }}">{{ $user->name }}</a>
</div>
</div>

<h2 class="text-center">{{ __('solution.code_review') }}</h2>
<div class="text-center h5">{{ __('solution.sub_title') }}</div>
<hr>

<div class="row no-gutters mb-3">
<div class="col-12 col-md-6 text-center">
<h5>{{ __('solution.title_output_solution') }}</h5>
</div>
@if ($solutionsOfOtherUsers->isNotEmpty())
<div class="col-12 col-md-6 text-center">
<h5>{{ __('solution.solutions_of_others') }}</h5>
</div>
@endif
</div>

<div class="row no-gutters">
<div class="col-12 col-md-6 p-2 p-lg-4">
<ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
@foreach ($solutionsOfCurrentUser as $currentSolution)
@if ($loop->first)
<li class="nav-item" role="presentation">
<a class="nav-link active" id="pills-{{ $currentSolution->id }}-tab" data-bs-toggle="pill"
href="#pills-{{ $currentSolution->id }}" role="tab" aria-controls="pills-{{ $currentSolution->id }}"
aria-selected="true">v.{{ $loop->iteration }}</a>
</li>
@else
<li class="nav-item" role="presentation">
<a class="nav-link" id="pills-{{ $currentSolution->id }}-tab" data-bs-toggle="pill"
href="#pills-{{ $currentSolution->id }}" role="tab" aria-controls="pills-{{ $currentSolution->id }}"
aria-selected="true">v.{{ $loop->iteration }}</a>
</li>
@endif
@endforeach
</ul>
<div class="tab-content" id="pills-tabContent">
@foreach ($solutionsOfCurrentUser as $currentSolution)
@if ($loop->first)
<div class="tab-pane fade show active" id="pills-{{ $currentSolution->id }}" role="tabpanel"
aria-labelledby="pills-{{ $currentSolution->id }}-tab">
@solution(['solution' => $currentSolution])
</div>
@else
<div class="tab-pane fade show" id="pills-{{ $currentSolution->id }}" role="tabpanel"
aria-labelledby="pills-{{ $currentSolution->id }}-tab">
@solution(['solution' => $currentSolution])
</div>
@endif
@endforeach
</div>
</div>

@if ($solutionsOfOtherUsers->isNotEmpty())
<div class="col-12 col-md-6 p-2 p-lg-4">
<div class="border-start d-none d-md-block"></div>
<ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
@foreach ($solutionsOfOtherUsers as $currentSolution)
@if ($loop->first)
<li class="nav-item" role="presentation">
<a class="nav-link active" id="pills-{{ $currentSolution->id }}double-tab" data-bs-toggle="pill"
href="#pills-{{ $currentSolution->id }}double" role="tab"
aria-controls="pills-{{ $currentSolution->id }}double"
aria-selected="true">v.{{ $loop->iteration }}</a>
</li>
@else
<li class="nav-item" role="presentation">
<a class="nav-link" id="pills-{{ $currentSolution->id }}double-tab" data-bs-toggle="pill"
href="#pills-{{ $currentSolution->id }}double" role="tab"
aria-controls="pills-{{ $currentSolution->id }}double"
aria-selected="true">v.{{ $loop->iteration }}</a>
</li>
@endif
@endforeach
</ul>
<div class="tab-content" id="pills-tabContent">
@foreach ($solutionsOfOtherUsers as $currentSolution)
@if ($loop->first)
<div class="tab-pane fade show active" id="pills-{{ $currentSolution->id }}double" role="tabpanel"
aria-labelledby="pills-{{ $currentSolution->id }}double-tab">
@solution(['solution' => $currentSolution])
</div>
@else
<div class="tab-pane fade show" id="pills-{{ $currentSolution->id }}double" role="tabpanel"
aria-labelledby="pills-{{ $currentSolution->id }}double-tab">
@solution(['solution' => $currentSolution])
</div>
@endif
@endforeach
</div>
</div>
@endif
</div>
@else
<div class="text-center py-5">
<h3>{{ __('solution.login_to_view') }}</h3>
<p class="text-muted">{{ __('solution.please_login_to_view_solution') }}</p>
<a href="{{ route('login') }}" class="btn btn-primary mt-3">
{{ __('login.submit') }}
</a>
</div>
@endauth
@endsection
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Feature\Http\Controllers\User;

use App\Models\Solution;
use App\Models\User;
use Database\Seeders\ChaptersTableSeeder;
use Database\Seeders\ExercisesTableSeeder;
use Tests\ControllerTestCase;
Expand Down