Last active
February 5, 2020 04:38
-
-
Save zhanang19/98c8802bb6dc77e0f76e3833d4711c66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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