-
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.
Add a list of dictionary words for the user (#3)
* Dictionary CRUD * Fix phpstan * DictionaryWord CRUD * WIP * Fix phpstan * WIP * Fix test namespace * Add a list of dictionary words for the user * fix phpstan
- Loading branch information
Showing
27 changed files
with
630 additions
and
28 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
database/migrations/2024_03_05_073918_create_dictionary_user_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,24 @@ | ||
<?php | ||
|
||
use EscolaLms\Dictionaries\Models\Dictionary; | ||
use EscolaLms\Dictionaries\Models\User; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
public function up(): void | ||
{ | ||
Schema::create('dictionary_user', function (Blueprint $table) { | ||
$table->foreignIdFor(Dictionary::class)->constrained()->cascadeOnDelete(); | ||
$table->foreignIdFor(User::class)->constrained()->cascadeOnDelete(); | ||
$table->dateTime('end_date')->nullable(); | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::dropIfExists('dictionary_word_user'); | ||
} | ||
}; |
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
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,33 @@ | ||
<?php | ||
|
||
namespace EscolaLms\Dictionaries\Http\Controllers; | ||
|
||
use EscolaLms\Core\Http\Controllers\EscolaLmsBaseController; | ||
use EscolaLms\Dictionaries\Http\Controllers\Swagger\DictionaryWordApiControllerSwagger; | ||
use EscolaLms\Dictionaries\Http\Requests\DictionaryWord\ListDictionaryWordRequest; | ||
use EscolaLms\Dictionaries\Http\Resources\CategorySimpleResource; | ||
use EscolaLms\Dictionaries\Http\Resources\DictionaryWordSimpleResource; | ||
use EscolaLms\Dictionaries\Services\Contracts\DictionaryWordServiceContract; | ||
use Illuminate\Http\JsonResponse; | ||
|
||
class DictionaryWordApiController extends EscolaLmsBaseController implements DictionaryWordApiControllerSwagger | ||
{ | ||
|
||
public function __construct(private readonly DictionaryWordServiceContract $dictionaryWordService) | ||
{ | ||
} | ||
|
||
public function index(ListDictionaryWordRequest $request): JsonResponse | ||
{ | ||
$results = $this->dictionaryWordService->list($request->getCriteria(), $request->getPage(), $request->getOrder()); | ||
|
||
return $this->sendResponseForResource(DictionaryWordSimpleResource::collection($results)); | ||
} | ||
|
||
public function categories(ListDictionaryWordRequest $request): JsonResponse | ||
{ | ||
$result = $this->dictionaryWordService->categories($request->getCriteria()); | ||
|
||
return $this->sendResponseForResource(CategorySimpleResource::collection($result)); | ||
} | ||
} |
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
125 changes: 125 additions & 0 deletions
125
src/Http/Controllers/Swagger/DictionaryWordApiControllerSwagger.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,125 @@ | ||
<?php | ||
|
||
namespace EscolaLms\Dictionaries\Http\Controllers\Swagger; | ||
|
||
use EscolaLms\Dictionaries\Http\Requests\DictionaryWord\ListDictionaryWordRequest; | ||
use Illuminate\Http\JsonResponse; | ||
|
||
interface DictionaryWordApiControllerSwagger | ||
{ | ||
/** | ||
* @OA\Get( | ||
* path="/api/dictionaries/{slug}/words", | ||
* summary="Get a listing of the Dictionary Word", | ||
* tags={"Dictionaries"}, | ||
* @OA\Parameter( | ||
* name="slug", | ||
* required=true, | ||
* in="path", | ||
* @OA\Schema( | ||
* type="string", | ||
* ), | ||
* ), | ||
* @OA\Parameter( | ||
* name="word", | ||
* description="word %LIKE%", | ||
* required=false, | ||
* in="query", | ||
* @OA\Schema( | ||
* type="string", | ||
* ), | ||
* ), | ||
* @OA\Parameter( | ||
* name="category_ids[]", | ||
* required=false, | ||
* in="query", | ||
* @OA\Schema( | ||
* type="array", | ||
* @OA\Items(type="number") | ||
* ), | ||
* ), | ||
* @OA\Response( | ||
* response=200, | ||
* description="successful operation", | ||
* @OA\MediaType( | ||
* mediaType="application/json", | ||
* @OA\Schema( | ||
* type="object", | ||
* @OA\Property( | ||
* property="success", | ||
* type="boolean" | ||
* ), | ||
* @OA\Property( | ||
* property="data", | ||
* type="array", | ||
* @OA\Items(ref="#/components/schemas/DictionaryWordSimpleResource") | ||
* ), | ||
* @OA\Property( | ||
* property="message", | ||
* type="string" | ||
* ) | ||
* ) | ||
* ) | ||
* ) | ||
* ) | ||
*/ | ||
public function index(ListDictionaryWordRequest $request): JsonResponse; | ||
|
||
/** | ||
* @OA\Get( | ||
* path="/api/dictionaries/{slug}/words/categories", | ||
* summary="Get the categories used in the dictionary for a given slug", | ||
* tags={"Dictionaries"}, | ||
* @OA\Parameter( | ||
* name="slug", | ||
* required=true, | ||
* in="path", | ||
* @OA\Schema( | ||
* type="string", | ||
* ), | ||
* ), | ||
* @OA\Parameter( | ||
* name="word", | ||
* description="word %LIKE%", | ||
* required=false, | ||
* in="query", | ||
* @OA\Schema( | ||
* type="string", | ||
* ), | ||
* ), | ||
* @OA\Parameter( | ||
* name="category_ids[]", | ||
* required=false, | ||
* in="query", | ||
* @OA\Schema( | ||
* type="array", | ||
* @OA\Items(type="number") | ||
* ), | ||
* ), | ||
* @OA\Response( | ||
* response=200, | ||
* description="successful operation", | ||
* @OA\MediaType( | ||
* mediaType="application/json", | ||
* @OA\Schema( | ||
* type="object", | ||
* @OA\Property( | ||
* property="success", | ||
* type="boolean" | ||
* ), | ||
* @OA\Property( | ||
* property="data", | ||
* type="array", | ||
* @OA\Items(ref="#/components/schemas/DictionaryWordCategorySimpleResource") | ||
* ), | ||
* @OA\Property( | ||
* property="message", | ||
* type="string" | ||
* ) | ||
* ) | ||
* ) | ||
* ) | ||
* ) | ||
*/ | ||
public function categories(ListDictionaryWordRequest $request): JsonResponse; | ||
} |
65 changes: 65 additions & 0 deletions
65
src/Http/Requests/DictionaryWord/Admin/CreateDictionaryWordRequest.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,65 @@ | ||
<?php | ||
|
||
namespace EscolaLms\Dictionaries\Http\Requests\DictionaryWord\Admin; | ||
|
||
use EscolaLms\Dictionaries\Dtos\DictionaryWordDto; | ||
use EscolaLms\Dictionaries\Models\DictionaryWord; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Support\Facades\Gate; | ||
|
||
/** | ||
* @OA\Schema( | ||
* schema="CreateDictionaryWordRequest", | ||
* required={"word", "dictionary_id"}, | ||
* @OA\Property( | ||
* property="word", | ||
* type="string" | ||
* ), | ||
* @OA\Property( | ||
* property="dictionary_id", | ||
* type="integer" | ||
* ), | ||
* @OA\Property( | ||
* property="description", | ||
* type="string" | ||
* ), | ||
* @OA\Property( | ||
* property="data", | ||
* type="object" | ||
* ), | ||
* @OA\Property( | ||
* property="categories", | ||
* description="categories", | ||
* type="array", | ||
* @OA\Items( | ||
* type="integer", | ||
* ) | ||
* ), | ||
* ) | ||
* | ||
*/ | ||
class CreateDictionaryWordRequest extends FormRequest | ||
{ | ||
public function authorize(): bool | ||
{ | ||
return Gate::allows('create', DictionaryWord::class); | ||
} | ||
|
||
public function rules(): array | ||
{ | ||
return [ | ||
'word' => ['required', 'string', 'max:255'], | ||
'dictionary_id' => ['required', 'integer', 'exists:dictionaries,id'], | ||
'description' => ['nullable', 'string'], | ||
'data' => ['nullable', 'array'], | ||
'categories' => ['nullable', 'array'], | ||
'categories.*' => ['integer', 'exists:categories,id'], | ||
]; | ||
} | ||
|
||
|
||
public function toDto(): DictionaryWordDto | ||
{ | ||
return DictionaryWordDto::instantiateFromRequest($this); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Http/Requests/DictionaryWord/Admin/DeleteDictionaryWordRequest.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,20 @@ | ||
<?php | ||
|
||
namespace EscolaLms\Dictionaries\Http\Requests\DictionaryWord\Admin; | ||
|
||
use EscolaLms\Dictionaries\Models\DictionaryWord; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Support\Facades\Gate; | ||
|
||
class DeleteDictionaryWordRequest extends FormRequest | ||
{ | ||
public function authorize(): bool | ||
{ | ||
return Gate::allows('delete', $this->getDictionaryWord()); | ||
} | ||
|
||
public function getDictionaryWord(): DictionaryWord | ||
{ | ||
return DictionaryWord::findOrFail($this->route('id')); | ||
} | ||
} |
Oops, something went wrong.