Added repositories

This commit is contained in:
m.zargarov 2024-01-10 12:56:02 +04:00
parent 283953d64d
commit efaf634867
10 changed files with 207 additions and 0 deletions

View File

@ -0,0 +1,35 @@
<?php
namespace App\Providers;
use App\Repositories\Interfaces\CarRepositoryInterface;
use App\Repositories\Interfaces\DeliveryRepositoryInterface;
use App\Repositories\Interfaces\UserRepositoryInterface;
use App\Repositories\Interfaces\WarehouseRepositoryInterface;
use App\Repositories\SQL\CarRepository;
use App\Repositories\SQL\DeliveryRepository;
use App\Repositories\SQL\UserRepository;
use App\Repositories\SQL\WarehouseRepository;
use Illuminate\Support\ServiceProvider;
class RepositoryServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
$this->app->bind(UserRepositoryInterface::class, UserRepository::class);
$this->app->bind(DeliveryRepositoryInterface::class, DeliveryRepository::class);
$this->app->bind(CarRepositoryInterface::class, CarRepository::class);
$this->app->bind(WarehouseRepositoryInterface::class, WarehouseRepository::class);
}
/**
* Bootstrap services.
*/
public function boot(): void
{
//
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\Repositories\Interfaces;
use App\Models\Car;
interface CarRepositoryInterface
{
public function getAllCars();
public function createCar(array $data);
public function updateCar(Car $car, array $data);
public function deleteCar(Car $car);
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\Repositories\Interfaces;
use App\Models\Delivery;
interface DeliveryRepositoryInterface
{
public function getAllDeliveries();
public function createDelivery(array $data);
public function updateDelivery(Delivery $delivery, array $data);
public function deleteDelivery(Delivery $delivery);
}

View File

@ -0,0 +1,14 @@
<?php
namespace App\Repositories\Interfaces;
use App\Models\User;
interface UserRepositoryInterface
{
public function getAllUsers();
public function createUser(array $data);
public function updateUser(User $user, array $data);
public function deleteUser(User $user);
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\Repositories\Interfaces;
use App\Models\Warehouse;
interface WarehouseRepositoryInterface
{
public function getAllWarehouses();
public function createWarehouse(array $data);
public function updateWarehouse(Warehouse $warehouse, array $data);
public function deleteWarehouse(Warehouse $warehouse);
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Repositories\SQL;
use App\Models\Car;
use App\Repositories\Interfaces\CarRepositoryInterface;
class CarRepository implements CarRepositoryInterface
{
public function getAllCars()
{
return Car::paginate(5)->get();
}
public function createCar(array $data)
{
Car::create($data);
}
public function updateCar(Car $car, array $data)
{
$car->update($data);
}
public function deleteCar(Car $car)
{
$car->delete();
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Repositories\SQL;
use App\Models\Delivery;
use App\Repositories\Interfaces\DeliveryRepositoryInterface;
class DeliveryRepository implements DeliveryRepositoryInterface
{
public function getAllDeliveries()
{
return Delivery::paginate(5)->get();
}
public function createDelivery(array $data)
{
Delivery::create($data);
}
public function updateDelivery(Delivery $delivery, array $data)
{
$delivery->update($data);
}
public function deleteDelivery(Delivery $delivery)
{
$delivery->delete();
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace App\Repositories\SQL;
use App\Models\User;
use App\Repositories\Interfaces\UserRepositoryInterface;
class UserRepository implements UserRepositoryInterface
{
public function getAllUsers()
{
return User::paginate(5)->get();
}
public function createUser(array $data)
{
User::create($data);
}
public function updateUser(User $user, array $data)
{
$user->update($data);
}
public function deleteUser(User $user)
{
$user->delete();
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace App\Repositories\SQL;
use App\Models\Warehouse;
use App\Repositories\Interfaces\WarehouseRepositoryInterface;
class WarehouseRepository implements WarehouseRepositoryInterface
{
public function getAllWarehouses()
{
return Warehouse::paginate(5)->get();
}
public function createWarehouse(array $data)
{
Warehouse::create($data);
}
public function updateWarehouse(Warehouse $warehouse, array $data)
{
$warehouse->update($data);
}
public function deleteWarehouse(Warehouse $warehouse)
{
$warehouse->delete();
}
}

View File

@ -168,6 +168,7 @@ return [
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
App\Providers\RepositoryServiceProvider::class,
])->toArray(),
/*