Skip to content

Commit

Permalink
Merge pull request #2 from dicani0/feature/courses
Browse files Browse the repository at this point in the history
courses layout
  • Loading branch information
dicani0 authored May 6, 2024
2 parents c789cc7 + ee12b79 commit 027a699
Show file tree
Hide file tree
Showing 43 changed files with 1,207 additions and 782 deletions.
12 changes: 12 additions & 0 deletions app/Application/Http/Course/Commands/CreateCourseCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Application\Http\Course\Commands;

use Domains\Course\DTO\CreateCourseDto;

class CreateCourseCommand
{
public function __construct(public CreateCourseDto $data)
{
}
}
45 changes: 10 additions & 35 deletions app/Application/Http/Course/Controllers/CourseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,26 @@

namespace App\Application\Http\Course\Controllers;

use App\Application\Http\Course\Requests\CourseRequest;
use App\Application\Http\Course\Resources\CourseResource;
use App\Application\Http\Course\Commands\CreateCourseCommand;
use App\Application\Http\Course\Handlers\CreateCourseHandler;
use Domains\Course\DTO\CreateCourseDto;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Domains\Course\Models\Course;
use Inertia\Response;

class CourseController
{
use AuthorizesRequests;

public function index()
public function create(): Response
{
$this->authorize('viewAny', Course::class);

return CourseResource::collection(Course::all());
}

public function store(CourseRequest $request)
{
$this->authorize('create', Course::class);

return new CourseResource(Course::create($request->validated()));
return inertia('Course/CreateCourse');
}

public function show(Course $course)
public function store(CreateCourseDto $dto, CreateCourseHandler $handler): Response
{
$this->authorize('view', $course);

return new CourseResource($course);
}

public function update(CourseRequest $request, Course $course)
{
$this->authorize('update', $course);

$course->update($request->validated());

return new CourseResource($course);
}

public function destroy(Course $course)
{
$this->authorize('delete', $course);

$course->delete();
$command = new CreateCourseCommand(data: $dto);
$handler->handle(command: $command);

return response()->json();
return inertia(component: 'Course/CreateCourse');
}
}
13 changes: 13 additions & 0 deletions app/Application/Http/Course/Handlers/CreateCourseHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Application\Http\Course\Handlers;

use App\Application\Http\Course\Commands\CreateCourseCommand;

class CreateCourseHandler
{
public function handle(CreateCourseCommand $command)
{

}
}
12 changes: 10 additions & 2 deletions app/Application/Http/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Application\Http\Providers;

use Domains\Course\Repositories\CourseRepositoryContract;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
Expand All @@ -11,14 +13,20 @@ class AppServiceProvider extends ServiceProvider
*/
public function register(): void
{
//
$this->app->bind(
CourseRepositoryContract::class,
);
}

/**
* Bootstrap any application services.
*/
public function boot(): void
{
//
Factory::guessFactoryNamesUsing(function (string $modelName) {
$modelName = class_basename($modelName);

return "Database\\Factories\\{$modelName}Factory";
});
}
}
3 changes: 3 additions & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull;
use Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets;

return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__ . '/../routes/web.php',
api: __DIR__ . '/../routes/api.php',
commands: __DIR__ . '/../routes/console.php',
channels: __DIR__ . '/../routes/channels.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->web(append: [
HandleInertiaRequests::class,
ConvertEmptyStringsToNull::class,
AddLinkHeadersForPreloadedAssets::class,
]);

Expand Down
Loading

0 comments on commit 027a699

Please sign in to comment.