|
|
@@ -0,0 +1,57 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Controllers;
|
|
|
+
|
|
|
+use App\Http\Requests\AppointmentRequest;
|
|
|
+use App\Http\Resources\AppointmentResource;
|
|
|
+use App\Services\AppointmentService;
|
|
|
+use Illuminate\Http\JsonResponse;
|
|
|
+use Illuminate\Support\Facades\Auth;
|
|
|
+
|
|
|
+class AppointmentController extends Controller
|
|
|
+{
|
|
|
+ public function __construct(protected AppointmentService $service) {}
|
|
|
+
|
|
|
+ public function index(): JsonResponse
|
|
|
+ {
|
|
|
+ $items = $this->service->getAll();
|
|
|
+ return $this->successResponse(payload: AppointmentResource::collection($items));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function myAppointments(): JsonResponse
|
|
|
+ {
|
|
|
+ $items = $this->service->getAllByUser(Auth::id());
|
|
|
+ return $this->successResponse(payload: AppointmentResource::collection($items));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function store(AppointmentRequest $request): JsonResponse
|
|
|
+ {
|
|
|
+ $item = $this->service->create($request->validated());
|
|
|
+ return $this->successResponse(
|
|
|
+ payload: new AppointmentResource($item),
|
|
|
+ message: __('messages.created'),
|
|
|
+ code: 201,
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public function show(int $id): JsonResponse
|
|
|
+ {
|
|
|
+ $item = $this->service->findById($id);
|
|
|
+ return $this->successResponse(payload: new AppointmentResource($item));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function update(AppointmentRequest $request, int $id): JsonResponse
|
|
|
+ {
|
|
|
+ $item = $this->service->update($id, $request->validated());
|
|
|
+ return $this->successResponse(
|
|
|
+ payload: new AppointmentResource($item),
|
|
|
+ message: __('messages.updated'),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public function destroy(int $id): JsonResponse
|
|
|
+ {
|
|
|
+ $this->service->delete($id);
|
|
|
+ return $this->successResponse(message: __('messages.deleted'), code: 204);
|
|
|
+ }
|
|
|
+}
|