Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add users|settings module by default #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/Http/BloodyCors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
namespace App\Http;

class BloodyCors
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, \Closure $next)
{
// pred('s');
$request->headers->set('Access-Control-Allow-Origin', '*');
$request->headers->set('Access-Control-Allow-Methods', '*');
$request->headers->set('Access-Control-Allow-Headers', '*');
$request->headers->set('Cache-Control', 'max-age=0');
// header("Access-Control-Allow-Origin: *");
// header('Access-Control-Allow-Methods: *');
// header("Access-Control-Allow-Headers: *");
// header('Cache-Control: max-age=0');

return $next($request);
}
}
13 changes: 12 additions & 1 deletion app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

namespace App\Http;

use App\Http\Middleware\Authenticate;
use Illuminate\Foundation\Http\Kernel as HttpKernel;

use App\Http\BloodyCors;
use App\Modules\Users\Middleware\{
Auth,
Authenticated,
Authorized
};

class Kernel extends HttpKernel
{
/**
Expand Down Expand Up @@ -39,10 +47,11 @@ class Kernel extends HttpKernel
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],

'api' => [
BloodyCors::class,
'throttle:60,1',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
Auth::class
],
];

Expand All @@ -54,6 +63,8 @@ class Kernel extends HttpKernel
* @var array
*/
protected $routeMiddleware = [
'Authenticated' => Authenticated::class,
'Authorized' => Authorized::class,
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
Expand Down
26 changes: 26 additions & 0 deletions app/Modules/Settings/Controllers/Admin/SettingsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace App\Modules\Settings\Controllers\Admin;

use HZ\Illuminate\Mongez\Managers\AdminApiController;

class SettingsController extends AdminApiController
{
/**
* Controller info
*
* @var array
*/
protected $controllerInfo = [
'repository' => 'settings',
'listOptions' => [
'select' => [],
'filterBy' => [],
'paginate' => null, // if set null, it will be automated based on repository configuration option
],
'rules' => [
'all' => [],
'store' => [],
'update' => [],
],
];
}
37 changes: 37 additions & 0 deletions app/Modules/Settings/Controllers/Site/SettingsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
namespace App\Modules\Settings\Controllers\Site;

use Illuminate\Http\Request;
use HZ\Illuminate\Mongez\Managers\ApiController;

class SettingsController extends ApiController
{
/**
* Repository name
*
* @var string
*/
protected $repository = 'settings';

/**
* {@inheritDoc}
*/
public function index(Request $request)
{
$options = [];

return $this->success([
'records' => $this->repository->list($options),
]);
}

/**
* {@inheritDoc}
*/
public function show($id, Request $request)
{
return $this->success([
'record' => $this->repository->get($id),
]);
}
}
15 changes: 15 additions & 0 deletions app/Modules/Settings/Filters/Setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace App\Modules\Settings\Filters;

use HZ\Illuminate\Mongez\Helpers\Filters\mysql\Filter;

class Setting extends Filter
{
/**
* List with all filter.
*
* Setting => functionName
* @const array
*/
const FILTER_MAP = [];
}
21 changes: 21 additions & 0 deletions app/Modules/Settings/Models/Setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
namespace App\Modules\Settings\Models;

use HZ\Illuminate\Mongez\Managers\Database\mysql\Model;

class Setting extends Model
{
/**
* Get the value of setting if file.
*
* @param string $value
* @return string
*/
public function getValueAttribute($value)
{
if ($this->type == 'file') {
return url($value);
}
return $value;
}
}
17 changes: 17 additions & 0 deletions app/Modules/Settings/Providers/SettingServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
namespace App\Modules\Settings\Providers;

use HZ\Illuminate\Mongez\Managers\Providers\ModuleServiceProvider;

class SettingServiceProvider extends ModuleServiceProvider
{
/**
* {@inheritDoc}
*/
const ROUTES_TYPES = ["admin","site"];

/**
* {@inheritDoc}
*/
protected $namespace = 'App/Modules/Settings/';
}
179 changes: 179 additions & 0 deletions app/Modules/Settings/Repositories/SettingsRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?php
namespace App\Modules\Settings\Repositories;

use App\Modules\Settings\{
Models\Setting as Model,
Resources\Setting as Resource,
Filters\Setting as Filter
};

use HZ\Illuminate\Mongez\{
Contracts\Repositories\RepositoryInterface,
Managers\Database\MYSQL\RepositoryManager
};

class settingsRepository extends RepositoryManager implements RepositoryInterface
{
/**
* {@inheritDoc}
*/
const NAME = 'settings';

/**
* {@inheritDoc}
*/
const MODEL = Model::class;

/**
* {@inheritDoc}
*/
const RESOURCE = Resource::class;

/**
* Set the columns of the data that will be auto filled in the model
*
* @const array
*/
const DATA = [
'name',
'group',
'type',
'value'
];

/**
* Auto save uploads in this list
* If it's an indexed array, in that case the request key will be as database column name
* If it's associated array, the key will be request key and the value will be the database column name
*
* @const array
*/
const UPLOADS = [];

/**
* Auto fill the following columns as arrays directly from the request
* It will encoded and stored as `JSON` format,
* it will be also auto decoded on any database retrieval either from `list` or `get` methods
*
* @const array
*/
const ARRAYBLE_DATA = [];

/**
* Set columns list of integers values.
*
* @cont array
*/
const INTEGER_DATA = [];

/**
* Set columns list of float values.
*
* @cont array
*/
const FLOAT_DATA = [];

/**
* Set columns of booleans data type.
*
* @cont array
*/
const BOOLEAN_DATA = [];

/**
* Add the column if and only if the value is passed in the request.
*
* @cont array
*/
const WHEN_AVAILABLE_DATA = [];

/**
* Filter by columns used with `list` method only
*
* @const array
*/
const FILTER_BY = [];

/**
* Set all filter class you will use in this module
*
* @const array
*/
const FILTERS = [
Filter::class
];

/**
* Determine wether to use pagination in the `list` method
* if set null, it will depend on pagination configurations
*
* @const bool
*/
const PAGINATE = null;

/**
* Number of items per page in pagination
* If set to null, then it will taken from pagination configurations
*
* @const int|null
*/
const ITEMS_PER_PAGE = null;

/**
* Set any extra data or columns that need more customizations
* Please note this method is triggered on create or update call
*
* @param mixed $model
* @param \Illuminate\Http\Request $request
* @return void
*/
protected function setData($model, $request)
{
//
if ($request->type == 'file') {
$this->upload($model, $request, ['value']);
}

if ($request->type == 'bool') {
$model->value = (bool) $request->value;
}

if ($request->type == 'int') {
$model->value = (int) $request->value;
}
}


/**
* Manage Selected Columns
*
* @return void
*/
protected function select()
{
//
}


/**
* Do any extra filtration here
*
* @return void
*/
protected function filter()
{
//
}

/**
* Get a specific record with full details
*
* @param int id
* @return mixed
*/
public function get(int $id)
{
if (static::USING_CACHE) return $this->wrap($this->getCache((int) $id));
return Model::find($id);
}
}
Loading