3.0: room controller. Index rooms, create a new room.
This commit is contained in:
parent
f8c1421bdd
commit
dfa0b6505d
@ -2,11 +2,16 @@
|
|||||||
|
|
||||||
namespace App\Domain\Room\Repositories;
|
namespace App\Domain\Room\Repositories;
|
||||||
|
|
||||||
|
use App\Models\Room;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class RoomRepository
|
* Class RoomRepository
|
||||||
* @package App\Domain\Room\Repositories
|
* @package App\Domain\Room\Repositories
|
||||||
*/
|
*/
|
||||||
class RoomRepository
|
class RoomRepository
|
||||||
{
|
{
|
||||||
|
public function all()
|
||||||
|
{
|
||||||
|
return Room::all();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
43
app/Http/Controllers/RoomController.php
Normal file
43
app/Http/Controllers/RoomController.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Domain\Room\Factories\RoomFactory;
|
||||||
|
use App\Domain\Room\Repositories\RoomRepository;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class RoomController extends Controller
|
||||||
|
{
|
||||||
|
private RoomRepository $roomRepository;
|
||||||
|
|
||||||
|
public function __construct(RoomRepository $roomRepository)
|
||||||
|
{
|
||||||
|
$this->roomRepository = $roomRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index(): JsonResponse
|
||||||
|
{
|
||||||
|
$rooms = $this->roomRepository->all();
|
||||||
|
return response()->json(
|
||||||
|
$rooms->toArray()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(RoomFactory $roomFactory): JsonResponse
|
||||||
|
{
|
||||||
|
$this->validate(request(), [
|
||||||
|
'name' => 'required|string|unique:rooms,name'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$room = $roomFactory->create(
|
||||||
|
request()->post('name')
|
||||||
|
);
|
||||||
|
|
||||||
|
return response()->json(
|
||||||
|
$room->toArray()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user