Skip to content

Instantly share code, notes, and snippets.

@zhanang19
Last active February 5, 2020 04:38
Show Gist options
  • Save zhanang19/98c8802bb6dc77e0f76e3833d4711c66 to your computer and use it in GitHub Desktop.
Save zhanang19/98c8802bb6dc77e0f76e3833d4711c66 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers\API\V1;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Gazeboin\Event\Domain\Services\AttemptEventService;
use Gazeboin\Event\Domain\Entities\EventEntity;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class EventController extends Controller
{
private $attemptEventService;
public function __construct(AttemptEventService $attemptEventService)
{
$this->attemptEventService = $attemptEventService;
}
public function index(Request $request)
{
try {
return response()->json([
'success' => true,
'message' => 'Event data.',
'data' => EventEntity::all()
]);
} catch (ModelNotFoundException $e) {
return response()->json([
'success' => true,
'message' => 'Data not found.',
'data' => []
], 404);
} catch (\Exception $e) {
report($e);
return response()->json([
'success' => false,
'message' => 'Something was wrong.',
'data' => []
], 500);
}
}
public function attempt(Request $request, $id)
{
try {
$result = $this->attemptEventService->attempt($id, $request->all());
return response()->json([
'success' => $result->success,
'message' => $result->message,
'data' => $result->data
]);
} catch (ModelNotFoundException $e) {
return response()->json([
'success' => true,
'message' => 'Data not found.',
'data' => []
], 404);
} catch (\Exception $e) {
report($e);
return response()->json([
'success' => false,
'message' => 'Something was wrong.',
'data' => []
], 500);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment