prodV1 #2

Open
RomanGolienko wants to merge 309 commits from prodV1 into main
12 changed files with 141 additions and 109 deletions
Showing only changes of commit c5abf73eb0 - Show all commits

View File

@ -1,10 +1,11 @@
<?php
namespace App\Http\Controllers\Catalog;
namespace App\Http\Controllers\admin\Catalog;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreDirectionRequest;
use App\Http\Requests\UpdateDepartmentRequest;
use App\Http\Requests\admin\Catalog\StoreDirectionRequest;
use App\Http\Requests\admin\Catalog\UpdateDepartmentRequest;
use App\Http\Requests\admin\Catalog\UpdateDirectionRequest;
use App\Models\Department;
use App\Models\Direction;
use Illuminate\Contracts\View\Factory;
@ -17,13 +18,13 @@ class DirectionController extends Controller
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
$directions = Direction::all();
return view('catalog.direction.index', compact('directions'));
return view('admin.catalog.direction.index', compact('directions'));
}
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
$departments = Department::pluck('name', 'id');
return view('catalog.direction.create', compact('departments'));
return view('admin.catalog.direction.create', compact('departments'));
}
public function store(StoreDirectionRequest $request): RedirectResponse
@ -43,22 +44,23 @@ class DirectionController extends Controller
public function show(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
return view('catalog.direction.show', compact('direction'));
return view('admin.catalog.direction.show', compact('direction'));
}
public function edit(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
$departments = Department::pluck('name', 'id');
return view('catalog.direction.edit', compact('direction', 'departments'));
return view('admin.catalog.direction.edit', compact('direction', 'departments'));
}
public function update(UpdateDepartmentRequest $request, Direction $direction): RedirectResponse
public function update(UpdateDirectionRequest $request, Direction $direction): RedirectResponse
{
$validated = $request->validated();
$direction->name = $validated['name'];
$direction->description = $validated['description'];
$direction->position = $validated['position'];
$direction->slug = $validated['slug'];
$direction->department_id = $validated['department_id'];
$direction->save();

View File

@ -1,24 +1,16 @@
<?php
namespace App\Http\Requests\Catalog;
namespace App\Http\Requests\admin\Catalog;
use Illuminate\Foundation\Http\FormRequest;
class StoreDirectionRequest 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 [

View File

@ -1,31 +1,24 @@
<?php
namespace App\Http\Requests\Catalog;
namespace App\Http\Requests\admin\Catalog;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
class UpdateDirectionRequest 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, ValidationRule|array|string>
*/
public function rules(): array
{
return [
'position' => 'int|max:255',
'description' => 'string',
'department_id' => 'int|required',
'slug' => 'required|string',
'name' => [
'required',
'string',

View File

@ -1,66 +0,0 @@
<?php
namespace App\Policies;
use App\Models\Direction;
use App\Models\User;
use Illuminate\Auth\Access\Response;
class DirectionPolicy
{
/**
* 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, Direction $direction): 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, Direction $direction): bool
{
//
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, Direction $direction): bool
{
//
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, Direction $direction): bool
{
//
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, Direction $direction): bool
{
//
}
}

View File

@ -4,20 +4,16 @@ namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Direction>
*/
class DirectionFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
//
'name' => fake()->name(),
'description' => fake()->text(),
'slug' => fake()->slug(),
'position' => fake()->randomDigit(),
'department_id' => 1,
];
}
}

View File

@ -2,16 +2,13 @@
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use App\Models\Direction;
use Illuminate\Database\Seeder;
class DirectionSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
//
Direction::factory(3)->create();
}
}

View File

@ -1,6 +1,5 @@
@extends('layouts.admin-layout')
@section('content')
@auth()
<div class="row">
<div class="col">

View File

@ -1,6 +1,5 @@
@extends('layouts.admin-layout')
@section('content')
@auth()
<div class="row">
<div class="col">

View File

@ -53,6 +53,17 @@
{{ $errors->first('educational_institution_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('slug', 'URL') }}
</div>
<div class="mt-1">
{{ Form::text('slug', $direction->slug, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('slug') }}
@endif
</div>
<div class="mt-3">
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
</div>

View File

@ -13,6 +13,7 @@
<th scope="col">Позиция</th>
<th scope="col">Название</th>
<th scope="col">Описание</th>
<th scope="col">URL</th>
<th scope="col">Кафедра</th>
<th scope="col">действия</th>
<th scope="col"></th>
@ -24,6 +25,7 @@
<th scope="row">{{ $direction->position }}</th>
<td><a href="{{ route('directions.show', $direction) }}">{{ $direction->name }}</a></td>
<td>{{ Str::words($direction->description, 10, '...') }}</td>
<td>{{ $direction->slug }}</td>
<td>{{ $direction->department->name }}</td>
<td>
<a href="{{ route("directions.edit", $direction) }}"
@ -39,5 +41,4 @@
<br>
<br>
</div>
@endsection

View File

@ -0,0 +1,108 @@
<?php
namespace Tests\Feature\admin\catalog;
use App\Models\Department;
use App\Models\Direction;
use App\Models\EducationalInstitution;
use App\Models\Faculty;
use App\Models\User;
use Tests\TestCase;
class DirectionTest extends TestCase
{
private User $user;
private Direction $direction;
private array $data;
protected function setUp(): void
{
parent::setUp();
EducationalInstitution::factory()->create();
Faculty::factory()->create();
Department::factory()->create();
$this->direction = Direction::factory()->create();
$this->data = Direction::factory()->make()->only([
'position',
'name',
'description',
'slug',
'department_id',
]);
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
public function testIndexDirectionsPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('directions.index'));
$response->assertOk();
}
public function testCreateDirectionPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('directions.create'));
$response->assertOk();
}
public function testStoreDirection(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->post(route('directions.store', $this->data));
$response->assertRedirect(route('directions.index'));
$this->assertDatabaseHas('directions', $this->data);
}
public function testShowDirectionPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('directions.show', $this->direction));
$response->assertOk();
}
public function testEditDirectionPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('directions.edit', $this->direction));
$response->assertOk();
}
public function testUpdateDirection(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('directions.update', $this->direction), $this->data);
$response->assertRedirect(route('directions.index'));
$this->assertDatabaseHas('directions', $this->data);
}
public function testDestroyDirection(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('directions.destroy', $this->direction));
$response->assertRedirect(route('directions.index'));
$this->assertDatabaseMissing('directions', $this->direction->toArray());
}
}