-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from spira/feature/default-order-by
allow default ordering for getAllEntities
- Loading branch information
Showing
11 changed files
with
223 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Spira framework. | ||
* | ||
* @link https://github.com/spira/spira | ||
* | ||
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Spira\Core\Model\Test; | ||
|
||
use Illuminate\Database\Eloquent\Collection; | ||
use Spira\Core\Model\Model\BaseModel; | ||
use Spira\Core\Model\Model\LocalizableModelInterface; | ||
use Spira\Core\Model\Model\LocalizableModelTrait; | ||
|
||
/** | ||
* Class OrderedTestEntity. | ||
* | ||
* @property Collection $testMany | ||
*/ | ||
class OrderedTestEntity extends BaseModel implements LocalizableModelInterface | ||
{ | ||
use LocalizableModelTrait; | ||
|
||
/** | ||
* The database table used by the model. | ||
* | ||
* @var string | ||
*/ | ||
public $table = 'ordered_test_entities'; | ||
protected $primaryKey = 'entity_id'; | ||
public $timestamps = false; | ||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = ['entity_id', 'varchar', 'integer']; | ||
/** | ||
* Override default order by value. | ||
* | ||
* @var string | ||
*/ | ||
protected $defaultOrderBy = 'varchar'; | ||
} |
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
49 changes: 49 additions & 0 deletions
49
database/migrations/2016_04_16_012124_create_ordered_test_entities_table.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,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Spira framework. | ||
* | ||
* @link https://github.com/spira/spira | ||
* | ||
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Spira\Core\Model\Test\OrderedTestEntity; | ||
|
||
class CreateOrderedTestEntitiesTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
if (env('APP_ENV') !== 'spira-core-testing') { | ||
return true; | ||
} | ||
Schema::create(OrderedTestEntity::getTableName(), function (Blueprint $table) { | ||
$table->uuid('entity_id'); | ||
$table->string('varchar', 255); | ||
$table->integer('integer'); | ||
|
||
$table->primary('entity_id'); | ||
} | ||
); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
if (env('APP_ENV') !== 'spira-core-testing') { | ||
return true; | ||
} | ||
Schema::drop(OrderedTestEntity::getTableName()); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Spira framework. | ||
* | ||
* @link https://github.com/spira/spira | ||
* | ||
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Spira\Core\tests\integration; | ||
|
||
use Illuminate\Http\Request; | ||
use Spira\Core\Controllers\EntityController; | ||
use Spira\Core\Controllers\LocalizableTrait; | ||
use Spira\Core\Model\Test\OrderedTestEntity; | ||
use Spira\Core\Responder\Transformers\EloquentModelTransformer; | ||
|
||
class OrderedEntityTestController extends EntityController | ||
{ | ||
use LocalizableTrait; | ||
|
||
protected $permissionsEnabled = false; | ||
|
||
protected $defaultRole = 'user'; | ||
|
||
public function __construct(OrderedTestEntity $model, EloquentModelTransformer $transformer) | ||
{ | ||
parent::__construct($model, $transformer); | ||
} | ||
|
||
/** | ||
* Get ordered entities. | ||
* | ||
* @param Request $request | ||
* @return ApiResponse | ||
*/ | ||
public function getOrdered() | ||
{ | ||
$collection = $this->getAllEntities(); | ||
|
||
return $this->getResponse() | ||
->transformer($this->getTransformer()) | ||
->collection($collection); | ||
} | ||
} |
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