-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
936 additions
and
114 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?php | ||
|
||
return [ | ||
'name' => 'Events' | ||
'name' => 'Events', | ||
]; |
This file contains 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
This file contains 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
This file contains 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
113 changes: 113 additions & 0 deletions
113
Modules/Events/Http/Controllers/Api/EventsController.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
|
||
namespace Modules\Events\Http\Controllers\Api; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Modules\Events\Http\Requests\StoreEventRequest; | ||
use Modules\Events\Http\Requests\UpdateEventRequest; | ||
use Modules\Events\Services\Contracts\EventsServiceInterface; | ||
use Modules\Events\Transformers\EventCollection; | ||
use Modules\Events\Transformers\EventsCollection; | ||
|
||
class EventsController extends Controller | ||
{ | ||
/** | ||
* @var \Modules\Events\Services\Contracts\EventsServiceInterface | ||
*/ | ||
private $eventsService; | ||
|
||
public function __construct(EventsServiceInterface $eventsService) | ||
{ | ||
$this->eventsService = $eventsService; | ||
} | ||
|
||
public function getEvents() | ||
{ | ||
try { | ||
$data = EventsCollection::collection($this->eventsService->getEvents()); | ||
|
||
return $this->responseJson(['data' => $data]); | ||
} catch (Exception $e) { | ||
return $this->responseJsonError($e); | ||
} | ||
} | ||
|
||
public function edit(int $id) | ||
{ | ||
try { | ||
$result['event'] = new EventCollection($this->eventsService->find($id)); | ||
|
||
return $this->responseJson($result); | ||
} catch (Exception $e) { | ||
return $this->responseJsonError($e); | ||
} | ||
} | ||
|
||
public function store(StoreEventRequest $request) | ||
{ | ||
try { | ||
$result['event'] = new EventCollection( | ||
$this->eventsService->storeEvent( | ||
$request->only('title', 'description', 'content', 'address', 'start', 'end', 'url', 'color', 'online', 'user_id'), | ||
$request->get('categories', []), | ||
$request->get('tags', []) | ||
) | ||
); | ||
|
||
return $this->responseJson($result); | ||
} catch (Exception $e) { | ||
return $this->responseJsonError($e); | ||
} | ||
} | ||
|
||
public function update(UpdateEventRequest $request, int $id) | ||
{ | ||
try { | ||
$event = $this->eventsService->updateEvent( | ||
$id, | ||
$request->only('title', 'description', 'content', 'address', 'start', 'end', 'url', 'color', 'online', 'user_id'), | ||
$request->get('categories', []), | ||
$request->get('tags', []) | ||
); | ||
|
||
$result['data'] = new EventCollection($event); | ||
|
||
return $this->responseJson($result); | ||
} catch (Exception $e) { | ||
return $this->responseJsonError($e); | ||
} | ||
} | ||
|
||
public function destroy(int $id) | ||
{ | ||
try { | ||
$result['event'] = new EventCollection($this->eventsService->delete($id)); | ||
|
||
return $this->responseJson($result); | ||
} catch (Exception $e) { | ||
return $this->responseJsonError($e); | ||
} | ||
} | ||
|
||
public function restore(int $id) | ||
{ | ||
try { | ||
$result['event'] = new EventCollection($this->eventsService->restore($id)); | ||
|
||
return $this->responseJson($result); | ||
} catch (Exception $e) { | ||
return $this->responseJsonError($e); | ||
} | ||
} | ||
|
||
public function forceDelete(int $id) | ||
{ | ||
try { | ||
$result['event'] = new EventCollection($this->eventsService->forceDelete($id)); | ||
|
||
return $this->responseJson($result); | ||
} catch (Exception $e) { | ||
return $this->responseJsonError($e); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Modules\Events\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class StoreEventRequest extends FormRequest | ||
{ | ||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'title' => 'required|string|min:4|max:255', | ||
'description' => 'required|string|min:4', | ||
'address' => 'required|string|min:4', | ||
'start' => 'required|date', | ||
'end' => 'required|date', | ||
'color' => 'required|string', | ||
'online' => 'required|boolean', | ||
'categories' => 'required|array|min:1', | ||
'tags' => 'array', | ||
]; | ||
} | ||
|
||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Modules\Events\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class UpdateEventRequest extends FormRequest | ||
{ | ||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'title' => 'required|string|min:4|max:255', | ||
'description' => 'required|string|min:4', | ||
'address' => 'required|string|min:4', | ||
'user_id' => 'required|integer', | ||
'start' => 'required|date', | ||
'end' => 'required|date', | ||
'color' => 'required|string', | ||
'online' => 'required|boolean', | ||
'categories' => 'required|array|min:1', | ||
'tags' => 'array', | ||
]; | ||
} | ||
|
||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
} |
Oops, something went wrong.