-
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.
Statments browser list endpoint (#12)
* WIP * WIP * Add policy * Add order by filter * fix Co-authored-by: Tomasz Smolarek <[email protected]>
- Loading branch information
Showing
24 changed files
with
865 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace EscolaLms\Lrs\Database\Factories; | ||
|
||
use EscolaLms\Lrs\Models\Statement; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Illuminate\Support\Str; | ||
use Trax\Auth\Stores\Accesses\Access; | ||
use Trax\Auth\Stores\Owners\Owner; | ||
|
||
class StatementFactory extends Factory | ||
{ | ||
protected $model = Statement::class; | ||
|
||
public function definition() | ||
{ | ||
return [ | ||
'uuid' => (string) Str::uuid(), | ||
'data' => $this->getJsonData(), | ||
'voided' => false, | ||
'owner_id' => Owner::inRandomOrder()->first(), | ||
'entity_id' => null, | ||
'client_id' => null, | ||
'access_id' => Access::inRandomOrder()->first(), | ||
'pending' => false, | ||
'validation' => 1 | ||
]; | ||
} | ||
|
||
private function getJsonData(): array | ||
{ | ||
return [ | ||
'id' => (string) Str::uuid(), | ||
'actor' => [ | ||
'objectType' => 'Agent', | ||
'account' => [ | ||
'homePage' => "https://escolalms.com", | ||
'name' => $this->faker->firstName . ' ' . $this->faker->lastName, | ||
] | ||
], | ||
'context' => [ | ||
'registration' => (string) Str::uuid(), | ||
], | ||
'verb' => [ | ||
'id' => "http://adlnet.gov/expapi/verbs/progressed", | ||
"display" => [ | ||
"en-US" => "progressed" | ||
] | ||
], | ||
'object' => [ | ||
'objectType' => 'Activity' | ||
], | ||
'version' => '1.0.0' | ||
]; | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace EscolaLms\Lrs\Database\Seeders; | ||
|
||
use EscolaLms\Lrs\Enums\LrsPermissionEnum; | ||
use Illuminate\Database\Seeder; | ||
use Spatie\Permission\Models\Permission; | ||
use Spatie\Permission\Models\Role; | ||
|
||
class LrsPermissionSeeder extends Seeder | ||
{ | ||
public function run() | ||
{ | ||
$admin = Role::findOrCreate('admin', 'api'); | ||
|
||
foreach (LrsPermissionEnum::asArray() as $const => $value) { | ||
Permission::findOrCreate($value, 'api'); | ||
} | ||
|
||
$admin->givePermissionTo([ | ||
LrsPermissionEnum::STATEMENT_LIST, | ||
]); | ||
} | ||
} |
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,81 @@ | ||
<?php | ||
|
||
namespace EscolaLms\Lrs\Dto; | ||
|
||
use Carbon\Carbon; | ||
use EscolaLms\Core\Dtos\Contracts\DtoContract; | ||
use EscolaLms\Core\Dtos\Contracts\InstantiateFromRequest; | ||
use EscolaLms\Core\Dtos\CriteriaDto; | ||
use EscolaLms\Core\Repositories\Criteria\Primitives\DateCriterion; | ||
use EscolaLms\Lrs\Enums\QueryEnum; | ||
use EscolaLms\Lrs\Repositories\Criteria\JsonCriteria; | ||
use EscolaLms\Lrs\Repositories\Criteria\OrderCriterion; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Collection; | ||
|
||
class StatementSearchDto extends CriteriaDto implements DtoContract, InstantiateFromRequest | ||
{ | ||
public static function instantiateFromRequest(Request $request): self | ||
{ | ||
$criteria = new Collection(); | ||
|
||
$criteria->push( | ||
new OrderCriterion( | ||
$request->get('order_by') ?? QueryEnum::DEFAULT_SORT, | ||
$request->get('order') ?? QueryEnum::DEFAULT_SORT_DIRECTION | ||
) | ||
); | ||
|
||
if ($request->get('verb')) { | ||
$criteria->push( | ||
new JsonCriteria('data->verb->display->en-US', $request->get('verb')) | ||
); | ||
$criteria->push( | ||
new JsonCriteria('data->verb->id', $request->get('verb'), null, false) | ||
); | ||
} | ||
if ($request->get('account')) { | ||
$criteria->push( | ||
new JsonCriteria('data->actor->account->name', $request->get('account')) | ||
); | ||
$criteria->push( | ||
new JsonCriteria('data->actor->account->homePage', $request->get('account'), null, false) | ||
); | ||
} | ||
if ($request->get('registration')) { | ||
$criteria->push( | ||
new JsonCriteria('data->context->registration', $request->get('registration')) | ||
); | ||
} | ||
if ($request->get('object')) { | ||
$criteria->push( | ||
new JsonCriteria('data->object->objectType', $request->get('object')) | ||
); | ||
} | ||
if ($request->get('version')) { | ||
$criteria->push( | ||
new JsonCriteria('data->version', $request->get('version')) | ||
); | ||
} | ||
if ($request->get('date_from')) { | ||
$criteria->push( | ||
new DateCriterion( | ||
'created_at', | ||
new Carbon($request->get('date_from')), | ||
'>=' | ||
) | ||
); | ||
} | ||
if ($request->get('date_to')) { | ||
$criteria->push( | ||
new DateCriterion( | ||
'created_at', | ||
new Carbon($request->get('date_to')), | ||
'<=' | ||
) | ||
); | ||
} | ||
|
||
return new static($criteria); | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace EscolaLms\Lrs\Enums; | ||
|
||
use EscolaLms\Core\Enums\BasicEnum; | ||
|
||
class LrsPermissionEnum extends BasicEnum | ||
{ | ||
public const STATEMENT_LIST = 'lrs_statement-list'; | ||
} |
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,11 @@ | ||
<?php | ||
|
||
namespace EscolaLms\Lrs\Enums; | ||
|
||
use EscolaLms\Core\Enums\BasicEnum; | ||
|
||
class QueryEnum extends BasicEnum | ||
{ | ||
public const DEFAULT_SORT = 'id'; | ||
public const DEFAULT_SORT_DIRECTION = 'desc'; | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace EscolaLms\Lrs\Http\Controllers; | ||
|
||
use EscolaLms\Core\Http\Controllers\EscolaLmsBaseController; | ||
use EscolaLms\Lrs\Dto\StatementSearchDto; | ||
use EscolaLms\Lrs\Http\Controllers\Swagger\StatementSwagger; | ||
use EscolaLms\Lrs\Http\Requests\StatementListRequest; | ||
use EscolaLms\Lrs\Http\Resources\StatementResource; | ||
use EscolaLms\Lrs\Services\Contracts\StatementServiceContract; | ||
use Illuminate\Http\JsonResponse; | ||
|
||
class StatementController extends EscolaLmsBaseController implements StatementSwagger | ||
{ | ||
private StatementServiceContract $statementService; | ||
|
||
public function __construct(StatementServiceContract $statementService) | ||
{ | ||
$this->statementService = $statementService; | ||
} | ||
|
||
public function statements(StatementListRequest $request): JsonResponse | ||
{ | ||
$results = $this->statementService->searchAndPaginate( | ||
StatementSearchDto::instantiateFromRequest($request), | ||
$request->get('per_page') ?? 15 | ||
); | ||
|
||
return $this->sendResponseForResource(StatementResource::make($results), 'Statements retrieved successfully'); | ||
} | ||
} |
Oops, something went wrong.