refactoring Reception screen to Admission
Tests & Lint & Deploy to Railway / deploy (push) Blocked by required conditions Details
Tests & Lint & Deploy to Railway / build (2.6.6, 20.x, 8.3) (push) Has been cancelled Details

This commit is contained in:
aslan 2024-02-13 15:37:41 +03:00
parent 551864fbb8
commit 3e50dee628
25 changed files with 520 additions and 648 deletions

View File

@ -1,82 +0,0 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\StoreReceptionScreenRequest;
use App\Http\Requests\UpdateReceptionScreenRequest;
use App\Models\ReceptionScreen;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Auth;
class ReceptionScreenController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
abort_if(Auth::guest(), 403);
$receptionScreens = ReceptionScreen::all()->sortBy('position');
return view('admin-reception-screen.index', compact('receptionScreens'));
}
public function create(): View
{
abort_if(Auth::guest(), 403);
$receptionScreens = ReceptionScreen::all()->sortBy('position');
return view('admin-reception-screen.create', compact('receptionScreens'));
}
public function store(StoreReceptionScreenRequest $request)
{
abort_if(Auth::guest(), 403);
$validated = $request->validated();
$receptionScreen = new ReceptionScreen();
$receptionScreen->name = $validated['name'];
$receptionScreen->position = $validated['position'];
$receptionScreen->save();
return redirect()->route('admin-reception-screen.index');
}
public function edit($id)
{
abort_if(Auth::guest(), 403);
$receptionScreen = new ReceptionScreen();
$currentReceptionScreen = $receptionScreen->find($id);
$receptionScreens = $receptionScreen->all()->sortBy('position');
return view('admin-reception-screen.edit', compact('currentReceptionScreen', 'receptionScreens'));
}
public function update(UpdateReceptionScreenRequest $request, $id)
{
abort_if(Auth::guest(), 403);
$validated = $request->validated();
$receptionScreen = new ReceptionScreen();
$currentReceptionScreen = $receptionScreen->find($id);
$currentReceptionScreen->name = $validated['name'];
$currentReceptionScreen->position = $validated['position'];
$currentReceptionScreen->save();
return redirect()->route('admin-reception-screen.index');
}
public function destroy($id)
{
$receptionScreen = new ReceptionScreen();
$currentReceptionScreen = $receptionScreen->find($id);
if ($currentReceptionScreen->files()->exists()) {
return back();
}
$currentReceptionScreen->delete();
return redirect()->route('admin-reception-screen.index');
}
}

View File

@ -0,0 +1,72 @@
<?php
namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\admin\StoreAdmissionRequest;
use App\Http\Requests\admin\UpdateAdmissionRequest;
use App\Models\Admission;
class AdmissionController extends Controller
{
public function index()
{
$admissions = Admission::all()->sortBy('position');
return view('admin.admission.index', compact('admissions'));
}
public function create()
{
$admissions = Admission::all()->sortBy('position');
return view('admin.admission.create', compact('admissions'));
}
public function store(StoreAdmissionRequest $request)
{
$validated = $request->validated();
$admission = new Admission();
$admission->name = $validated['name'];
$admission->description = $validated['description'];
$admission->slug = $validated['slug'];
$admission->position = $validated['position'];
$admission->save();
return redirect()->route('admissions.index');
}
public function show(Admission $admission)
{
return view('admin.admission.show', compact('admission'));
}
public function edit(Admission $admission)
{
return view('admin.admission.edit', compact('admission'));
}
public function update(UpdateAdmissionRequest $request, Admission $admission)
{
$validated = $request->validated();
$admission->name = $validated['name'];
$admission->description = $validated['description'];
$admission->slug = $validated['slug'];
$admission->position = $validated['position'];
$admission->save();
return redirect()->route('admissions.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Admission $admission)
{
if ($admission->documents()->exists()) {
return back();
}
$admission->delete();
return redirect()->route('admissions.index');
}
}

View File

@ -1,29 +0,0 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreReceptionScreenRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => 'required|max:255',
'position' => 'required||int|max:255',
];
}
}

View File

@ -1,29 +0,0 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdateReceptionScreenRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => 'required|max:255',
'position' => 'required||int|max:255',
];
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace App\Http\Requests\admin;
use Illuminate\Foundation\Http\FormRequest;
class StoreAdmissionRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'position' => 'required|int|max:255',
'name' => 'required|string|max:255|unique:admissions,name',
'description' => 'string',
'slug' => 'required|string',
];
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace App\Http\Requests\admin;
use Illuminate\Foundation\Http\FormRequest;
class UpdateAdmissionRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'position' => 'required|int|max:255',
'description' => 'string',
'slug' => 'string|required',
'name' => [
'required',
'string',
'max:255',
"unique:admissions,name,{$this->admission->id}",
],
];
}
}

View File

@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
class ReceptionScreen extends Model class Admission extends Model
{ {
use HasFactory; use HasFactory;
@ -16,8 +16,8 @@ class ReceptionScreen extends Model
'position' 'position'
]; ];
public function files(): HasMany public function documents(): HasMany
{ {
return $this->hasMany('App\Models\File', 'reception_screen_id'); return $this->hasMany('App\Models\Document', 'admission_id');
} }
} }

View File

@ -1,66 +0,0 @@
<?php
namespace App\Policies;
use App\Models\ReceptionScreen;
use App\Models\User;
use Illuminate\Auth\Access\Response;
class ReceptionScreenPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
//
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, ReceptionScreen $doceumentsOnline): bool
{
//
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
//
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, ReceptionScreen $doceumentsOnline): bool
{
//
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, ReceptionScreen $doceumentsOnline): bool
{
//
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, ReceptionScreen $doceumentsOnline): bool
{
//
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, ReceptionScreen $doceumentsOnline): bool
{
//
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class AdmissionFactory extends Factory
{
public function definition(): array
{
return [
'name' => fake()->name(),
'description' => fake()->text(),
'slug' => fake()->slug(),
'position' => fake()->randomDigit(),
];
}
}

View File

@ -1,23 +0,0 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\ReceptionScreen>
*/
class ReceptionScreenFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
//
];
}
}

View File

@ -11,9 +11,11 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::create('reception_screens', function (Blueprint $table) { Schema::create('admissions', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('name'); $table->string('name');
$table->text('description');
$table->string('slug');
$table->integer('position'); $table->integer('position');
$table->timestamps(); $table->timestamps();
}); });
@ -24,6 +26,6 @@ return new class extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::dropIfExists('reception_screens'); Schema::dropIfExists('admissions');
} }
}; };

View File

@ -1,33 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('submenu', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('description');
$table->string('parent');
$table->string('meta_title');
$table->string('meta_description');
$table->string('meta_keywords');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('submenu');
}
};

View File

@ -0,0 +1,37 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class AdmissionSeeder extends Seeder
{
public function run(): void
{
DB::table('admissions')->insert([
[
'name' => 'Пункт 1',
'position' => 2,
'description' => 'description 1',
'slug' => 'point-1',
'created_at' => now(),
],
[
'name' => 'Пункт 2',
'position' => 3,
'description' => 'description 2',
'slug' => 'point-2',
'created_at' => now(),
],
[
'name' => 'Пункт 3',
'description' => 'description 3',
'position' => 1,
'slug' => 'point-3',
'created_at' => now(),
]
]);
}
}

View File

@ -21,12 +21,15 @@ class DatabaseSeeder extends Seeder
User::factory(10)->create(); User::factory(10)->create();
$this->call([ $this->call([
ReceptionScreenSeeder::class,
DocumentSeeder::class,
EducationalInstitutionSeeder::class, EducationalInstitutionSeeder::class,
FacultySeeder::class, FacultySeeder::class,
DepartmentSeeder::class, DepartmentSeeder::class,
DirectionSeeder::class, DirectionSeeder::class,
]); ]);
$this->call([
AdmissionSeeder::class,
DocumentSeeder::class,
]);
} }
} }

View File

@ -1,35 +0,0 @@
<?php
namespace Database\Seeders;
use Carbon\Carbon;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class ReceptionScreenSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
DB::table('reception_screens')->insert([
[
'name' => 'Пункт 1 с файлами',
'position' => 2,
'created_at' => Carbon::now(),
],
[
'name' => 'Пункт 2 с файлами',
'position' => 3,
'created_at' => Carbon::now(),
],
[
'name' => 'Пункт 3 с файлами',
'position' => 1,
'created_at' => Carbon::now(),
]
]);
}
}

View File

@ -1,4 +1,4 @@
import './bootstrap'; // import './bootstrap';
import Alpine from 'alpinejs'; import Alpine from 'alpinejs';
import ujs from '@rails/ujs'; import ujs from '@rails/ujs';

View File

@ -1,60 +0,0 @@
@extends('layouts.admin-layout')
@section('content')
@auth()
<div class="row">
<div class="col">
<h1 class=""> Изменить пункт Экрана приема</h1>
{{ Form::open(['url' => route('admin-reception-screen.update', $currentReceptionScreen), 'method' => 'PATCH', 'class' => '']) }}
<div class="col">
<div>
{{ Form::label('position', 'Позиция') }}
</div>
<div class="mt-2">
{{ Form::text('position', $currentReceptionScreen->position, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('position') }}
@endif
</div>
<div>
{{ Form::label('name', 'Название') }}
</div>
<div class="mt-2">
{{ Form::text('name', $currentReceptionScreen->name, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('name') }}
@endif
</div>
<div class="mt-4">
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
</div>
</div>
{{ Form::close() }}
</div>
<div class="col">
<table class="table">
<thead class="border-b-2 border-solid border-black text-left" style="text-align: left">
<tr>
<th scope="col">Позиция</th>
<th scope="col">Название</th>
</tr>
</thead>
<tbody>
@foreach($receptionScreens as $receptionScreen)
<tr>
<th scope="row">{{ $receptionScreen->position }}</th>
<td>{{ $receptionScreen->name }}</td>
@endforeach
</tbody>
</table>
</div>
</div>
@endauth
@endsection

View File

@ -1,144 +0,0 @@
@extends('layouts.admin-layout')
@section('content')
<style>
.accordion-button:not(.collapsed)
{
color:#006147;
background-color: rgb(255, 255, 255);
box-shadow:inset 0 -1px 0 rgba(0,0,0,.125)
}
.accordion-button:focus {
z-index: 3;
border-color: #006147;
outline: 0;
box-shadow: 0 0 0 0.25rem #006147;
}
</style>
<div class="container">
<h2>Экран Приема</h2>
<br>
<a href="{{ route('admin-reception-screen.create') }}" class="btn btn-primary">Создать пункт Экрана приема</a>
<br>
<br>
<table class="table">
<thead class="border-b-2 border-solid border-black text-left" style="text-align: left">
<tr>
<th scope="col">Позиция</th>
<th scope="col">Название</th>
<th scope="col">действия</th>
<th scope="col"></th>
</tr>
</thead>
<tbody class="accordion" id="accordionExample">
@foreach($receptionScreens as $receptionScreen)
<?php $accordion_tmp = str_replace(' ','', $receptionScreen->name) ?>
<tr class="accordion-item ">
<th scope="row">{{ $receptionScreen->position }}</th>
<td>{{ $receptionScreen->name }}</td>
<td><a href="{{ route("admin-reception-screen.edit", $receptionScreen) }}" class="btn btn-secondary">редактировать</a>
<a rel="nofollow" data-method="delete" data-confirm="Вы действительно хотите удалить?"
href="{{ route('admin-reception-screen.destroy', $receptionScreen) }}" class="btn btn-danger">
удалить
</a>
</td>
<th class="accordion-header" id="heading<?php echo $accordion_tmp ?>">
<button class="accordion-button collapsed btn btn-secondary" type="button" data-bs-toggle="collapse" data-bs-target="#collapse<?php echo $accordion_tmp ?> " aria-expanded="false" aria-controls="collapse<?php echo $accordion_tmp ?>">
Показать
</button>
</th>
@if(count($receptionScreen->files) !== 0)
</tr>
<tr>
<td colspan="3">
<table class="table table-bordered accordion-collapse collapse" id="collapse<?php echo $accordion_tmp ?>" aria-labelledby="heading<?php echo $accordion_tmp ?>" data-bs-parent="#accordionExample">
<thead class="accordion-body">
<tr>
<th scope="col">Позиция</th>
<th scope="col">Имя Файла</th>
<th scope="col">действия</th>
</tr>
</thead>
<tbody>
@foreach($receptionScreen->files->sortBy('position') as $file)
<tr>
<th scope="row">{{ $file->position }}</th>
<td>{{ $file->name }}</td>
<td><a href="{{ route("files.edit", $file) }}"
class="btn btn-secondary">редактировать</a>
<a rel="nofollow" data-method="delete"
data-confirm="Вы действительно хотите удалить?"
href="{{ route('files.destroy', $file) }}"
class="btn btn-danger">
удалить
</a>
</td>
</tr>
@endforeach
<tr class=" border border-white border-bottom-0 border-start-0 border-end-0">
<td colspan="3"><div class="mb-2">
<a href="{{ route('files_create', $receptionScreen->id) }}"
class="btn btn-primary">
Добавить файл
</a>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
@else
<tr>
<td colspan="3">
@php($idReceptionScreen = $receptionScreen->id)
<a href="{{ route('files_create', $idReceptionScreen) }}" class="btn btn-primary">Добавить
файл</a>
</td>
</tr>
@endif
@endforeach
</tbody>
</table>
<br>
<br>
</div>
@endsection

View File

@ -1,11 +1,11 @@
@extends('layouts.admin-layout') @extends('layouts.admin_layout')
@section('content') @section('content')
@auth() @auth()
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<h1 class=""> Создать пункт Экрана приема</h1> <h1 class=""> Создать пункт Экрана приема</h1>
{{ Form::open(['url' => route('admin-reception-screen.store'), 'method' => 'POST', 'class' => '']) }} {{ Form::open(['url' => route('admissions.store'), 'method' => 'POST', 'class' => '']) }}
<div class="col"> <div class="col">
<div> <div>
{{ Form::label('position', 'Позиция') }} {{ Form::label('position', 'Позиция') }}
@ -31,6 +31,30 @@
@endif @endif
</div> </div>
<div>
{{ Form::label('description', 'Описание') }}
</div>
<div class="mt-2">
{{ Form::text('description', '', ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('description') }}
@endif
</div>
<div>
{{ Form::label('slug', 'URL') }}
</div>
<div class="mt-2">
{{ Form::text('slug', '', ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('description') }}
@endif
</div>
<div class="mt-4"> <div class="mt-4">
{{ Form::submit('создать', ['class' => 'btn btn-primary']) }} {{ Form::submit('создать', ['class' => 'btn btn-primary']) }}
</div> </div>
@ -46,10 +70,10 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach($receptionScreens as $receptionScreen) @foreach($admissions->sortBy('position') as $admission)
<tr> <tr>
<th scope="row">{{ $receptionScreen->position }}</th> <th scope="row">{{ $admission->position }}</th>
<td>{{ $receptionScreen->name }}</td> <td>{{ $admission->name }}</td>
@endforeach @endforeach
</tbody> </tbody>
</table> </table>

View File

@ -0,0 +1,66 @@
@extends('layouts.admin_layout')
@section('content')
@auth()
<div class="row">
<div class="col">
<h1 class=""> Изменить пункт меню Экрана приема</h1>
{{ Form::open(['url' => route('admissions.update', $admission), 'method' => 'PATCH', 'class' => '']) }}
<div class="col">
<div>
{{ Form::label('position', 'Позиция') }}
</div>
<div class="mt-2">
{{ Form::text('position', $admission->position, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('position') }}
@endif
</div>
<div>
{{ Form::label('name', 'Название') }}
</div>
<div class="mt-2">
{{ Form::text('name', $admission->name, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('name') }}
@endif
</div>
<div>
{{ Form::label('description', 'Описание') }}
</div>
<div class="mt-2">
{{ Form::text('description', $admission->description, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('description') }}
@endif
</div>
<div>
{{ Form::label('slug', 'URL') }}
</div>
<div class="mt-2">
{{ Form::text('slug', $admission->slug, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('description') }}
@endif
</div>
<div class="mt-4">
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
</div>
</div>
{{ Form::close() }}
</div>
</div>
@endauth
@endsection

View File

@ -0,0 +1,109 @@
@extends('layouts.admin_layout')
@section('content')
<div class="container">
<h2>Меню экрана приема</h2>
<br>
<a href="{{ route('admissions.create') }}" class="btn btn-primary">Добавить меню экрана приема</a>
<br>
<br>
<table class="table">
<thead class="border-b-2 border-solid border-black text-left" style="text-align: left">
<tr>
<th scope="col">Позиция</th>
<th scope="col">Название</th>
<th scope="col">действия</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
@foreach($admissions as $admission)
<tr class="">
<th scope="row">{{ $admission->position }}</th>
<td><a href="{{ route('admissions.show', $admission) }}">{{ $admission->name }}
@if(count($admission->documents) !== 0)
-- {{ count($admission->documents) }} файла(ов)
@endif</a></td>
<td>
<a href="{{ route("admissions.edit", $admission) }}"
class="btn btn-secondary">редактировать</a>
<a rel="nofollow" data-method="delete" data-confirm="Вы действительно хотите удалить?"
href="{{ route('admissions.destroy', $admission) }}"
class="btn btn-danger">удалить</a>
</td>
@if(count($admission->documents) !== 0)
<td>
<button class="btn btn-primary" type="button" data-bs-toggle="collapse"
data-bs-target="#collapseAdmission{{ $admission->id }}" aria-expanded="false"
aria-controls="collapseAdmission{{ $admission->id }}">
Свернуть
</button>
</td>
</tr>
<tr>
<td colspan="3">
<div class="collapse" id="collapseAdmission{{ $admission->id }}">
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Позиция</th>
<th scope="col">Имя Файла</th>
<th scope="col">действия</th>
</tr>
</thead>
<tbody>
@foreach($admission->documents as $document)
<tr>
<th scope="row">{{ $document->position }}</th>
<td>{{ $document->name }}</td>
<td><a href="{{ route("documents.edit", $document) }}"
class="btn btn-secondary">редактировать</a>
<a rel="nofollow" data-method="delete"
data-confirm="Вы действительно хотите удалить?"
href="{{ route('documents.destroy', $document) }}"
class="btn btn-danger">
удалить
</a>
</td>
</tr>
@endforeach
<tr class=" border border-white border-bottom-0 border-start-0 border-end-0">
<td colspan="4">
<div class="mb-2">
<a href="{{ route('documents_create_with_admission', $admission) }}"
class="btn btn-primary">
Добавить файл
</a>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<td></td>
</tr>
@else
<td><a class="btn btn-secondary disabled" href=""
role="button">
Сверунть
</a></td>
<tr>
<td colspan="4">
<a href="{{ route('documents_create_with_admission', $admission) }}"
class="btn btn-primary">Добавить
файл</a>
</td>
</tr>
@endif
@endforeach
</tbody>
</table>
<br>
<br>
</div>
@endsection

View File

@ -0,0 +1,19 @@
@extends('layouts.admin_layout')
@section('content')
@auth()
<div class="container mt-4">
<h2>Название</h2>
<p>{{ $admission->name }}</p>
<h2>Описание</h2>
<p>{{ $admission->description }}</p>
<h2>Позиция</h2>
<p>{{ $admission->position }}</p>
<h2>URL</h2>
<p>{{ $admission->slug }}</p>
<h2>Документы</h2>
@foreach($admission->documents as $document)
<p><a href="{{ route('documents.show', $document) }}">{{ $document->name }}</a></p>
@endforeach
</div>
@endauth
@endsection

View File

@ -1,11 +1,11 @@
<?php <?php
use App\Http\Controllers\admin\AdmissionController;
use App\Http\Controllers\admin\Catalog\DepartmentController; use App\Http\Controllers\admin\Catalog\DepartmentController;
use App\Http\Controllers\admin\Catalog\DirectionController; use App\Http\Controllers\admin\Catalog\DirectionController;
use App\Http\Controllers\admin\Catalog\EducationalInstitutionController; use App\Http\Controllers\admin\Catalog\EducationalInstitutionController;
use App\Http\Controllers\admin\Catalog\FacultyController; use App\Http\Controllers\admin\Catalog\FacultyController;
use App\Http\Controllers\admin\DocumentController; use App\Http\Controllers\admin\DocumentController;
use App\Http\Controllers\admin\ReceptionScreenController;
use App\Http\Controllers\admin\UserController; use App\Http\Controllers\admin\UserController;
Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () { Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () {
@ -13,7 +13,7 @@ Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () {
return view('admin'); return view('admin');
})->name('dashboard'); })->name('dashboard');
Route::get('/documents/create/{document?}', [DocumentController::class, 'create'])->name('documents_create'); Route::get('/documents/create/{admission}', [DocumentController::class, 'createFromAdmission'])->name('documents_create_with_admission');
Route::get('/documents/download/{Document}', [DocumentController::class, 'download'])->name('documents_download'); Route::get('/documents/download/{Document}', [DocumentController::class, 'download'])->name('documents_download');
Route::resource('/educational_institutions', EducationalInstitutionController::class) Route::resource('/educational_institutions', EducationalInstitutionController::class)
@ -25,10 +25,12 @@ Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () {
->scoped(['department' => 'slug']); ->scoped(['department' => 'slug']);
Route::resource('/faculties', FacultyController::class) Route::resource('/faculties', FacultyController::class)
->scoped(['faculty' => 'slug']); ->scoped(['faculty' => 'slug']);
Route::resource('/faculties', FacultyController::class)
->scoped(['faculty' => 'slug']);
Route::resource('/admissions', AdmissionController::class);
Route::resources([ Route::resources([
'/documents' => DocumentController::class, '/documents' => DocumentController::class,
'/users' => UserController::class, '/users' => UserController::class,
'/admin-reception-screen' => ReceptionScreenController::class,
]); ]);
}); });

View File

@ -1,131 +0,0 @@
<?php
namespace Tests\Feature;
use App\Models\User;
use Tests\TestCase;
class ReceptionScreenTest extends TestCase
{
private User $adminUser;
private User $noAdminUser;
private array $user;
protected function setUp(): void
{
parent::setUp();
$this->user = User::factory()->make()->only([
'name',
'email',
'password'
]);
$this->adminUser = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
$this->noAdminUser = User::factory()->create([
'name' => 'noadmin',
'email' => 'notest@example.com',
'password' => 'no123456'
]);
}
public function testUsersPage(): void
{
$response = $this->actingAs($this->adminUser)
->withSession(['banned' => false])
->get(route('users.index'));
$response->assertOk();
}
public function testNoAdminNoSeeUsersPage(): void
{
$response = $this->actingAs($this->noAdminUser)
->withSession(['banned' => false])
->get(route('users.index'));
$response->assertStatus(403);
}
public function testCreateUserPage(): void
{
$response = $this->actingAs($this->adminUser)
->withSession(['banned' => false])
->get(route('users.create'));
$response->assertOk();
}
public function testNoAdminCreateUserPage(): void
{
$response = $this->actingAs($this->noAdminUser)
->withSession(['banned' => false])
->get(route('users.create'));
$response->assertStatus(403);
}
public function testStoreUser(): void
{
$response = $this->actingAs($this->adminUser)
->withSession(['banned' => false])
->post(route('users.store', $this->user));
$response->assertRedirect(route('users.index'));
$this->assertDatabaseHas('users', $this->user);
}
public function testNoAdminNoStoreUser(): void
{
$response = $this->actingAs($this->noAdminUser)
->withSession(['banned' => false])
->post(route('users.store', $this->user));
$response->assertStatus(403);
$this->assertDatabaseMissing('users', $this->user);
}
public function testEditUserPage(): void
{
$response = $this->actingAs($this->adminUser)
->withSession(['banned' => false])
->get(route('users.edit', $this->adminUser));
$response->assertOk();
}
public function testNoAdminEditUserPage(): void
{
$response = $this->actingAs($this->noAdminUser)
->withSession(['banned' => false])
->get(route('users.edit', $this->noAdminUser));
$response->assertStatus(403);
}
public function testUpdateUser(): void
{
$response = $this->actingAs($this->adminUser)
->withSession(['banned' => false])
->patch(route('users.update', $this->noAdminUser), $this->user);
$response->assertRedirect(route('users.index'));
$dataWithOutHashPassword = $this->user;
unset($dataWithOutHashPassword['password']);
$this->assertDatabaseHas('users', $dataWithOutHashPassword);
}
public function testNoAdminNoUpdateUser(): void
{
$response = $this->actingAs($this->noAdminUser)
->withSession(['banned' => false])
->patch(route('users.update', $this->noAdminUser), $this->user);
$response->assertStatus(403);
$noAdminData = $this->noAdminUser->only(['name', 'email', 'password']);
$this->assertDatabaseHas('users', $noAdminData);
$this->assertDatabaseMissing('users', $this->user);
}
}

View File

@ -0,0 +1,101 @@
<?php
namespace Tests\Feature\admin;
use App\Models\Admission;
use App\Models\User;
use Tests\TestCase;
class AdmissionTest extends TestCase
{
private User $user;
private array $data;
private Admission $admission;
protected function setUp(): void
{
parent::setUp();
$this->admission = Admission::factory()->create();
$this->data = Admission::factory()->make()->only([
'position',
'name',
'description',
'slug',
]);
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
public function testIndexAdmissionsPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('admissions.index'));
$response->assertOk();
}
public function testCreateAdmissionPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('admissions.create'));
$response->assertOk();
}
public function testStoreAdmission(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->post(route('admissions.store', $this->data));
$response->assertRedirect(route('admissions.index'));
$this->assertDatabaseHas('admissions', $this->data);
}
public function testShowAdmissionPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('admissions.show', $this->admission));
$response->assertOk();
}
public function testEditAdmissionPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('admissions.edit', $this->admission));
$response->assertOk();
}
public function testUpdateAdmission(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('admissions.update', $this->admission), $this->data);
$response->assertRedirect(route('admissions.index'));
$this->assertDatabaseHas('admissions', $this->data);
}
public function testDestroyFaculty(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('admissions.destroy', $this->admission));
$response->assertRedirect(route('admissions.index'));
$this->assertDatabaseMissing('faculties', $this->admission->toArray());
}
}