From 09fd149bd9e7035e01163d39323ced10129acde3 Mon Sep 17 00:00:00 2001 From: panabonic Date: Thu, 22 Jun 2023 18:02:59 +0300 Subject: [PATCH 1/2] registries beta --- app/Models/Publications/Publication.php | 1 - app/Models/Registries/Category.php | 50 +++++++++++++++++ .../{RegistryEntry.php => Entry.php} | 27 ++++++++- app/Models/Registries/Operation.php | 55 +++++++++++++++++++ app/Models/Registries/OperationType.php | 15 +++++ app/Models/Registries/Registry.php | 12 +++- .../Publications/PublicationTransformer.php | 1 - .../Registries/CategoryTransformer.php | 51 +++++++++++++++++ .../Registries/EntryTransformer.php | 55 +++++++++++++++++++ .../Registries/OperationTransformer.php | 54 ++++++++++++++++++ .../Registries/RegistryTransformer.php | 6 +- ...3_06_14_143616_create_registries_table.php | 2 +- ..._add_description_to_publications_table.php | 32 ----------- ...95321_create_registry_categories_table.php | 36 ++++++++++++ ...1_195350_create_registry_entries_table.php | 40 ++++++++++++++ ...create_registry_entry_operations_table.php | 41 ++++++++++++++ 16 files changed, 438 insertions(+), 40 deletions(-) create mode 100644 app/Models/Registries/Category.php rename app/Models/Registries/{RegistryEntry.php => Entry.php} (50%) create mode 100644 app/Models/Registries/Operation.php create mode 100644 app/Models/Registries/OperationType.php create mode 100644 app/Transformers/Registries/CategoryTransformer.php create mode 100644 app/Transformers/Registries/EntryTransformer.php create mode 100644 app/Transformers/Registries/OperationTransformer.php delete mode 100644 database/migrations/2023_06_21_071812_add_description_to_publications_table.php create mode 100644 database/migrations/2023_06_21_195321_create_registry_categories_table.php create mode 100644 database/migrations/2023_06_21_195350_create_registry_entries_table.php create mode 100644 database/migrations/2023_06_22_174800_create_registry_entry_operations_table.php diff --git a/app/Models/Publications/Publication.php b/app/Models/Publications/Publication.php index bf8ada1..f8b9036 100644 --- a/app/Models/Publications/Publication.php +++ b/app/Models/Publications/Publication.php @@ -29,7 +29,6 @@ class Publication extends Model { 'type', 'name', 'excerpt', - 'description', 'is_published' ]; diff --git a/app/Models/Registries/Category.php b/app/Models/Registries/Category.php new file mode 100644 index 0000000..f1d0640 --- /dev/null +++ b/app/Models/Registries/Category.php @@ -0,0 +1,50 @@ +belongsTo(Registry::class); + } + + public function parent(): BelongsTo { + return $this->belongsTo(Category::class, 'parent_id'); + } + + public function children(): HasMany { + return $this->hasMany(Category::class, 'parent_id'); + } + + public function entries(): HasMany { + return $this->hasMany(Entry::class); + } + + + +} diff --git a/app/Models/Registries/RegistryEntry.php b/app/Models/Registries/Entry.php similarity index 50% rename from app/Models/Registries/RegistryEntry.php rename to app/Models/Registries/Entry.php index 4c41b94..35eb798 100644 --- a/app/Models/Registries/RegistryEntry.php +++ b/app/Models/Registries/Entry.php @@ -2,23 +2,34 @@ namespace App\Models\Registries; +use App\Models\Asset; use App\Support\HasObjectsTrait; use App\Support\RelationValuesTrait; use App\Support\UuidScopeTrait; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; -class RegistryEntry extends Model { +class Entry extends Model { use UuidScopeTrait, SoftDeletes, HasObjectsTrait, RelationValuesTrait; + protected $table = 'registry_entries'; + protected $dates = [ + 'active_since', + 'active_till' ]; protected $fillable = [ 'uuid', 'registry_id', - 'name' + 'category_id', + 'asset_id', + 'number', + 'name', + 'active_since', + 'active_till' ]; protected $hidden = [ @@ -30,6 +41,18 @@ class RegistryEntry extends Model { return $this->belongsTo(Registry::class); } + public function category(): BelongsTo { + return $this->belongsTo(Category::class); + } + + public function asset(): BelongsTo { + return $this->belongsTo(Asset::class); + } + + public function operations(): HasMany { + return $this->hasMany(Operation::class); + } + } diff --git a/app/Models/Registries/Operation.php b/app/Models/Registries/Operation.php new file mode 100644 index 0000000..87430dc --- /dev/null +++ b/app/Models/Registries/Operation.php @@ -0,0 +1,55 @@ +belongsTo(Entry::class); + } + + public function order(): BelongsTo { + return $this->belongsTo(Asset::class); + } + + + public function getParsedTypeAttribute(): array { + return ['name' => $this->type, 'title' => OperationType::TITLES[$this->type] ?? null]; + } + + + +} diff --git a/app/Models/Registries/OperationType.php b/app/Models/Registries/OperationType.php new file mode 100644 index 0000000..7e6b625 --- /dev/null +++ b/app/Models/Registries/OperationType.php @@ -0,0 +1,15 @@ + 'Разработка', + self::REWORK => 'Пересмотр', + self::MODIFICATION => 'Изменение' + ]; +} \ No newline at end of file diff --git a/app/Models/Registries/Registry.php b/app/Models/Registries/Registry.php index 3a3f9c4..bf5279f 100644 --- a/app/Models/Registries/Registry.php +++ b/app/Models/Registries/Registry.php @@ -3,15 +3,15 @@ namespace App\Models\Registries; use App\Models\Pages\Page; -use App\Support\HasObjectsTrait; use App\Support\RelationValuesTrait; use App\Support\UuidScopeTrait; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; class Registry extends Model { - use UuidScopeTrait, SoftDeletes, HasObjectsTrait, RelationValuesTrait; + use UuidScopeTrait, SoftDeletes, RelationValuesTrait; protected $dates = [ ]; @@ -32,6 +32,14 @@ class Registry extends Model { return $this->belongsTo(Page::class); } + public function categories(): HasMany { + return $this->hasMany(Category::class); + } + + public function entries(): HasMany { + return $this->hasMany(Entry::class); + } + public function getParsedTypeAttribute(): array { diff --git a/app/Transformers/Publications/PublicationTransformer.php b/app/Transformers/Publications/PublicationTransformer.php index c8d02cb..98867e6 100644 --- a/app/Transformers/Publications/PublicationTransformer.php +++ b/app/Transformers/Publications/PublicationTransformer.php @@ -32,7 +32,6 @@ class PublicationTransformer extends TransformerAbstract { 'subtype' => $model->parsedType, 'name' => $model->name, 'excerpt' => $model->excerpt, - 'description' => $model->description, 'is_published' => boolval($model->is_published), 'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null, 'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null diff --git a/app/Transformers/Registries/CategoryTransformer.php b/app/Transformers/Registries/CategoryTransformer.php new file mode 100644 index 0000000..0804597 --- /dev/null +++ b/app/Transformers/Registries/CategoryTransformer.php @@ -0,0 +1,51 @@ + $model->uuid, + 'name' => $model->name, + 'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null, + 'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null + ]; + } + + public function includeRegistry(Category $model): ?Item { + return $model->registry ? $this->item($model->registry, new RegistryTransformer()) : null; + } + + public function includeParent(Category $model): ?Item { + return $model->parent ? $this->item($model->parent, new CategoryTransformer()) : null; + } + + public function includeChildren(Category $model): Collection { + return $this->collection($model->children, new CategoryTransformer()); + } + + public function includeEntries(Category $model): Collection { + return $this->collection($model->entries, new EntryTransformer()); + } + + public function includePermissions(Category $model): Primitive { + return $this->primitive((new PermissionsService($model))->get()); + } + + +} diff --git a/app/Transformers/Registries/EntryTransformer.php b/app/Transformers/Registries/EntryTransformer.php new file mode 100644 index 0000000..7f77a60 --- /dev/null +++ b/app/Transformers/Registries/EntryTransformer.php @@ -0,0 +1,55 @@ + $model->uuid, + 'number' => $model->number, + 'name' => $model->name, + 'active_since' => $model->active_since ? $model->active_since->toIso8601String() : null, + 'active_till' => $model->active_till ? $model->active_till->toIso8601String() : null, + 'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null, + 'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null + ]; + } + + public function includeRegistry(Entry $model): ?Item { + return $model->registry ? $this->item($model->registry, new RegistryTransformer()) : null; + } + + public function includeCategory(Entry $model): ?Item { + return $model->category ? $this->item($model->category, new CategoryTransformer()) : null; + } + + public function includeAsset(Entry $model): ?Item { + return $model->asset ? $this->item($model->asset, new AssetTransformer()) : null; + } + + public function includeOperations(Entry $model): Collection { + return $this->collection($model->operations, new OperationTransformer()); + } + + public function includePermissions(Entry $model): Primitive { + return $this->primitive((new PermissionsService($model))->get()); + } + + +} diff --git a/app/Transformers/Registries/OperationTransformer.php b/app/Transformers/Registries/OperationTransformer.php new file mode 100644 index 0000000..23d1efc --- /dev/null +++ b/app/Transformers/Registries/OperationTransformer.php @@ -0,0 +1,54 @@ + $model->uuid, + 'type' => $model->parsedType, + 'name' => $model->name, + 'developer' => $model->developer, + 'order_name' => $model->order_name, + 'order_date' => $model->order_date ? $model->order_date->toIso8601String() : null, + 'active_since' => $model->active_since ? $model->active_since->toIso8601String() : null, + 'active_till' => $model->active_till ? $model->active_till->toIso8601String() : null, + 'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null, + 'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null + ]; + } + + public function includeRegistry(Entry $model): ?Item { + return $model->registry ? $this->item($model->registry, new RegistryTransformer()) : null; + } + + public function includeCategory(Entry $model): ?Item { + return $model->category ? $this->item($model->category, new CategoryTransformer()) : null; + } + + public function includeAsset(Entry $model): ?Item { + return $model->asset ? $this->item($model->asset, new AssetTransformer()) : null; + } + + public function includePermissions(Entry $model): Primitive { + return $this->primitive((new PermissionsService($model))->get()); + } + + +} diff --git a/app/Transformers/Registries/RegistryTransformer.php b/app/Transformers/Registries/RegistryTransformer.php index da19ee4..bea402a 100644 --- a/app/Transformers/Registries/RegistryTransformer.php +++ b/app/Transformers/Registries/RegistryTransformer.php @@ -17,7 +17,7 @@ class RegistryTransformer extends TransformerAbstract { ]; protected array $availableIncludes = [ - 'page', 'entries', 'permissions' + 'page', 'categories', 'entries', 'permissions' ]; public function transform(Registry $model): array { @@ -34,6 +34,10 @@ class RegistryTransformer extends TransformerAbstract { return $model->page ? $this->item($model->page, new PageTransformer()) : null; } + public function includeCategories(Registry $model): Collection { + return $this->collection($model->categories, new CategoryTransformer()); + } + public function includeEntries(Registry $model): Collection { return $this->collection($model->objects, new ObjectTransformer()); } diff --git a/database/migrations/2023_06_14_143616_create_registries_table.php b/database/migrations/2023_06_14_143616_create_registries_table.php index bfa864f..4dbba1a 100644 --- a/database/migrations/2023_06_14_143616_create_registries_table.php +++ b/database/migrations/2023_06_14_143616_create_registries_table.php @@ -16,7 +16,7 @@ class CreateRegistriesTable extends Migration Schema::create('registries', function (Blueprint $table) { $table->id(); $table->char('uuid', 36)->index()->unique(); - $table->integer('page_id')->index()->default(0); + $table->integer('page_id')->index()->nullable(); $table->string('type')->index()->nullable(); $table->string('name')->index()->nullable(); $table->timestamps(); diff --git a/database/migrations/2023_06_21_071812_add_description_to_publications_table.php b/database/migrations/2023_06_21_071812_add_description_to_publications_table.php deleted file mode 100644 index b3aec44..0000000 --- a/database/migrations/2023_06_21_071812_add_description_to_publications_table.php +++ /dev/null @@ -1,32 +0,0 @@ -addColumn('text', 'description')->after('excerpt')->nullable(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('publications', function (Blueprint $table) { - $table->dropColumn('description'); - }); - } -} diff --git a/database/migrations/2023_06_21_195321_create_registry_categories_table.php b/database/migrations/2023_06_21_195321_create_registry_categories_table.php new file mode 100644 index 0000000..7150a00 --- /dev/null +++ b/database/migrations/2023_06_21_195321_create_registry_categories_table.php @@ -0,0 +1,36 @@ +id(); + $table->char('uuid', 36)->index()->unique(); + $table->integer('registry_id')->index()->nullable(); + $table->integer('parent_id')->index()->default(0); + $table->string('name')->index()->nullable(); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('registry_categories'); + } +} diff --git a/database/migrations/2023_06_21_195350_create_registry_entries_table.php b/database/migrations/2023_06_21_195350_create_registry_entries_table.php new file mode 100644 index 0000000..44c2ba3 --- /dev/null +++ b/database/migrations/2023_06_21_195350_create_registry_entries_table.php @@ -0,0 +1,40 @@ +id(); + $table->char('uuid', 36)->index()->unique(); + $table->integer('registry_id')->index()->nullable(); + $table->integer('category_id')->index()->nullable(); + $table->integer('asset_id')->index()->nullable(); + $table->string('number')->index()->nullable(); + $table->string('name')->index()->nullable(); + $table->date('active_since')->index()->nullable(); + $table->date('active_till')->index()->nullable(); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('registry_entries'); + } +} diff --git a/database/migrations/2023_06_22_174800_create_registry_entry_operations_table.php b/database/migrations/2023_06_22_174800_create_registry_entry_operations_table.php new file mode 100644 index 0000000..33fc39b --- /dev/null +++ b/database/migrations/2023_06_22_174800_create_registry_entry_operations_table.php @@ -0,0 +1,41 @@ +id(); + $table->char('uuid', 36)->index()->unique(); + $table->integer('entry_id')->index()->nullable(); + $table->integer('order_id')->index()->nullable(); + $table->string('type')->index()->nullable(); + $table->string('developer')->index()->nullable(); + $table->string('order_name')->index()->nullable(); + $table->date('order_date')->index()->nullable(); + $table->date('active_since')->index()->nullable(); + $table->date('active_till')->index()->nullable(); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('registry_entry_operations'); + } +} From a7ff21f2f6a14af6e075c35156c8f520fd916d12 Mon Sep 17 00:00:00 2001 From: panabonic Date: Wed, 5 Jul 2023 13:34:27 +0300 Subject: [PATCH 2/2] registries gamma --- .../Publications/PublicationsController.php | 5 +- .../Api/Registries/CategoriesController.php | 45 +++++++ .../Api/Registries/EntriesController.php | 46 +++++++ .../Api/Registries/OperationsController.php | 43 +++++++ .../Api/Registries/RegistriesController.php | 45 +++++++ app/Models/Objects/Field.php | 11 ++ app/Models/Objects/NirObject.php | 9 +- app/Models/Objects/Values/DateValue.php | 3 +- app/Models/Pages/Page.php | 9 ++ app/Models/Registries/Entry.php | 6 +- app/Models/Registries/Operation.php | 55 -------- app/Models/Registries/OperationType.php | 15 --- app/Models/Registries/Registry.php | 4 + app/Providers/AppServiceProvider.php | 7 ++ app/Services/Forms/FormsService.php | 2 + .../Forms/Registries/CategoryForms.php | 51 ++++++++ app/Services/Forms/Registries/EntryForms.php | 82 ++++++++++++ .../Forms/Registries/OperationForms.php | 117 ++++++++++++++++++ .../Registries/RegistryFormsServices.php | 11 ++ .../Objects/ObjectTransformer.php | 2 +- app/Transformers/Pages/PageTransformer.php | 12 +- .../Registries/EntryTransformer.php | 3 +- .../Registries/OperationTransformer.php | 54 -------- .../Registries/RegistryTransformer.php | 2 +- ...create_registry_entry_operations_table.php | 41 ------ .../Dictionaries/DictionariesTableSeeder.php | 8 ++ .../seeders/Objects/FieldsTableSeeder.php | 50 ++++++++ .../Objects/ObjectTypeFieldsTableSeeder.php | 7 +- .../Objects/ObjectTypesTableSeeder.php | 9 +- routes/api.php | 16 +++ 30 files changed, 585 insertions(+), 185 deletions(-) create mode 100644 app/Http/Controllers/Api/Registries/CategoriesController.php create mode 100644 app/Http/Controllers/Api/Registries/EntriesController.php create mode 100644 app/Http/Controllers/Api/Registries/OperationsController.php create mode 100644 app/Http/Controllers/Api/Registries/RegistriesController.php delete mode 100644 app/Models/Registries/Operation.php delete mode 100644 app/Models/Registries/OperationType.php create mode 100644 app/Services/Forms/Registries/CategoryForms.php create mode 100644 app/Services/Forms/Registries/EntryForms.php create mode 100644 app/Services/Forms/Registries/OperationForms.php create mode 100644 app/Services/Forms/Registries/RegistryFormsServices.php delete mode 100644 app/Transformers/Registries/OperationTransformer.php delete mode 100644 database/migrations/2023_06_22_174800_create_registry_entry_operations_table.php diff --git a/app/Http/Controllers/Api/Publications/PublicationsController.php b/app/Http/Controllers/Api/Publications/PublicationsController.php index 26968b8..2473e6f 100644 --- a/app/Http/Controllers/Api/Publications/PublicationsController.php +++ b/app/Http/Controllers/Api/Publications/PublicationsController.php @@ -6,6 +6,7 @@ use App\Http\Controllers\Controller; use App\Models\Pages\Page; use App\Models\Publications\Publication; use App\Transformers\Publications\PublicationTransformer; +use App\Transformers\Registries\RegistryTransformer; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -32,8 +33,8 @@ class PublicationsController extends Controller { } public function show(Request $request, $id): JsonResponse { - $model = $this->model->bySlug($id)->firstOrFail(); - return fractal($model, new PublicationTransformer())->respond(); + $model = $this->model->ByUuid($id)->firstOrFail(); + return fractal($model, new RegistryTransformer())->respond(); } diff --git a/app/Http/Controllers/Api/Registries/CategoriesController.php b/app/Http/Controllers/Api/Registries/CategoriesController.php new file mode 100644 index 0000000..48c2ef0 --- /dev/null +++ b/app/Http/Controllers/Api/Registries/CategoriesController.php @@ -0,0 +1,45 @@ +model = $model; + } + + public function index(Request $request): JsonResponse { + $registry = Registry::byUuid($request->get('registry'))->first(); + $parent = Category::byUuid($request->get('parent'))->first(); + $query = $this->model->query()->where(['registry_id' => $registry->id ?? 0, 'parent_id' => $parent->id ?? 0]); + $paginator = $query->paginate(config('app.pagination_limit')); + return fractal($paginator, new CategoryTransformer())->respond(); + } + + public function show(Request $request, $id): JsonResponse { + $model = $this->model->byUuid($id)->firstOrFail(); + return fractal($model, new CategoryTransformer())->respond(); + } + + + public function store(Request $request): void { + } + + + public function update(Request $request, $uuid): void { + } + + public function destroy(Request $request, $uuid): JsonResponse { + $model = $this->model->byUuid($uuid)->firstOrFail(); + $model->delete(); + return response()->json(null, 204); + } +} diff --git a/app/Http/Controllers/Api/Registries/EntriesController.php b/app/Http/Controllers/Api/Registries/EntriesController.php new file mode 100644 index 0000000..5387ad6 --- /dev/null +++ b/app/Http/Controllers/Api/Registries/EntriesController.php @@ -0,0 +1,46 @@ +model = $model; + } + + public function index(Request $request): JsonResponse { + $registry = Registry::byUuid($request->get('registry'))->first(); + $category = Category::byUuid($request->get('category'))->first(); + $query = $this->model->query()->where(['registry_id' => $registry->id ?? 0, 'category_id' => $category->id ?? 0]); + $paginator = $query->paginate(config('app.pagination_limit')); + return fractal($paginator, new EntryTransformer())->respond(); + } + + public function show(Request $request, $id): JsonResponse { + $model = $this->model->byUuid($id)->firstOrFail(); + return fractal($model, new EntryTransformer())->respond(); + } + + + public function store(Request $request): void { + } + + + public function update(Request $request, $uuid): void { + } + + public function destroy(Request $request, $uuid): JsonResponse { + $model = $this->model->byUuid($uuid)->firstOrFail(); + $model->delete(); + return response()->json(null, 204); + } +} diff --git a/app/Http/Controllers/Api/Registries/OperationsController.php b/app/Http/Controllers/Api/Registries/OperationsController.php new file mode 100644 index 0000000..858b911 --- /dev/null +++ b/app/Http/Controllers/Api/Registries/OperationsController.php @@ -0,0 +1,43 @@ +model = $model; + } + + public function index(Request $request): JsonResponse { + $query = ($entry = Entry::byUuid($request->get('entry'))->first()) ? $entry->operations() : $this->model->query(); + $paginator = $query->paginate(config('app.pagination_limit')); + return fractal($paginator, new ObjectTransformer())->respond(); + } + + public function show(Request $request, $id): JsonResponse { + $model = $this->model->byUuid($id)->firstOrFail(); + return fractal($model, new ObjectTransformer())->respond(); + } + + + public function store(Request $request): void { + } + + + public function update(Request $request, $uuid): void { + } + + public function destroy(Request $request, $uuid): JsonResponse { + $model = $this->model->byUuid($uuid)->firstOrFail(); + $model->delete(); + return response()->json(null, 204); + } +} diff --git a/app/Http/Controllers/Api/Registries/RegistriesController.php b/app/Http/Controllers/Api/Registries/RegistriesController.php new file mode 100644 index 0000000..087c7a0 --- /dev/null +++ b/app/Http/Controllers/Api/Registries/RegistriesController.php @@ -0,0 +1,45 @@ +model = $model; + } + + public function index(Request $request): JsonResponse { + $query = $this->model->query(); + if ($page = Page::byUuid($request->get('page'))->first()) $query->where(['page_id' => $page->id]); + $paginator = $query->paginate(config('app.pagination_limit')); + return fractal($paginator, new RegistryTransformer())->respond(); + } + + public function show(Request $request, $id): JsonResponse { + $model = $this->model->byUuid($id)->firstOrFail(); + return fractal($model, new PublicationTransformer())->respond(); + } + + + public function store(Request $request): void { + } + + + public function update(Request $request, $uuid): void { + } + + public function destroy(Request $request, $uuid): JsonResponse { + $model = $this->model->byUuid($uuid)->firstOrFail(); + $model->delete(); + return response()->json(null, 204); + } +} diff --git a/app/Models/Objects/Field.php b/app/Models/Objects/Field.php index 1d37bf3..47f9126 100644 --- a/app/Models/Objects/Field.php +++ b/app/Models/Objects/Field.php @@ -11,6 +11,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Database\Query\JoinClause; use Illuminate\Support\Arr; use Illuminate\Support\Collection; @@ -175,6 +176,16 @@ class Field extends Model { } + public function applyOrder(Builder $query, $dir) { + if ($table = FieldType::TABLES[$this->type] ?? null) { + $query->leftJoin("{$table} as {$this->name}", function(JoinClause $join) use($table) { + $join->on('objects.id', '=', "{$this->name}.object_id"); + })->where(["{$this->name}.field_id" => $this->id])->orderBy("{$this->name}.value", $dir); + } + } + + + public function fakeValue($objectId) { $faker = new Generator(); diff --git a/app/Models/Objects/NirObject.php b/app/Models/Objects/NirObject.php index d661ea6..ec3044d 100644 --- a/app/Models/Objects/NirObject.php +++ b/app/Models/Objects/NirObject.php @@ -2,7 +2,6 @@ namespace App\Models\Objects; -use App\Models\Catalog\Specification; use App\Models\Objects\Values\BooleanValue; use App\Models\Objects\Values\DateValue; use App\Models\Objects\Values\DocumentValue; @@ -12,7 +11,6 @@ use App\Models\Objects\Values\IntegerValue; use App\Models\Objects\Values\RelationValue; use App\Models\Objects\Values\StringValue; use App\Models\Objects\Values\TextValue; -use App\Models\Polls\PollInvitation; use App\Models\User; use App\Support\UuidScopeTrait; use Illuminate\Database\Eloquent\Builder; @@ -103,6 +101,13 @@ class NirObject extends Model { return $query; } + public function scopeApplyOrders(Builder $query, $orders): Builder { + collect($orders)->each(function($dir, $prop) use($query) { + if ($field = Field::byUuidOrName($prop)->first()) $field->applyOrder($query, $dir); + }); + return $query; + } + public function getValuesAttribute(): array { $result = []; diff --git a/app/Models/Objects/Values/DateValue.php b/app/Models/Objects/Values/DateValue.php index 090740d..cc6236e 100644 --- a/app/Models/Objects/Values/DateValue.php +++ b/app/Models/Objects/Values/DateValue.php @@ -2,7 +2,7 @@ namespace App\Models\Objects\Values; -use Carbon\Carbon; +use Illuminate\Support\Carbon; class DateValue extends Value { protected $table = 'field_date_values'; @@ -16,6 +16,7 @@ class DateValue extends Value { return $this->value ? $this->value->toIso8601String() : null; } public function set($value): bool { + $value = ($value instanceof Carbon) ? $value : ($value ? Carbon::create($value) : null); return parent::set($value); } diff --git a/app/Models/Pages/Page.php b/app/Models/Pages/Page.php index 1809557..86da58c 100644 --- a/app/Models/Pages/Page.php +++ b/app/Models/Pages/Page.php @@ -3,6 +3,7 @@ namespace App\Models\Pages; use App\Models\Publications\Publication; +use App\Models\Registries\Registry; use App\Support\HasObjectsTrait; use App\Support\RelationValuesTrait; use App\Support\UuidScopeTrait; @@ -55,6 +56,10 @@ class Page extends Model { return $this->hasMany(Publication::class); } + public function registries(): HasMany { + return $this->hasMany(Registry::class); + } + public function scopeBySlug($query, $slug) { $query->where(['slug' => $slug]); @@ -82,6 +87,10 @@ class Page extends Model { return ['name' => $this->type, 'title' => PageType::TITLES[$this->type] ?? null]; } + public function getRegistryAttribute(): Model { + return $this->registries()->firstOrCreate(); + } + public function addSection($typeName, $ord = null): ?Model { diff --git a/app/Models/Registries/Entry.php b/app/Models/Registries/Entry.php index 35eb798..e4399d8 100644 --- a/app/Models/Registries/Entry.php +++ b/app/Models/Registries/Entry.php @@ -8,7 +8,7 @@ use App\Support\RelationValuesTrait; use App\Support\UuidScopeTrait; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; -use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\MorphToMany; use Illuminate\Database\Eloquent\SoftDeletes; class Entry extends Model { @@ -49,8 +49,8 @@ class Entry extends Model { return $this->belongsTo(Asset::class); } - public function operations(): HasMany { - return $this->hasMany(Operation::class); + public function operations(): MorphToMany { + return $this->objects()->reorder()->applyOrders(['order-date' => 'desc']); } diff --git a/app/Models/Registries/Operation.php b/app/Models/Registries/Operation.php deleted file mode 100644 index 87430dc..0000000 --- a/app/Models/Registries/Operation.php +++ /dev/null @@ -1,55 +0,0 @@ -belongsTo(Entry::class); - } - - public function order(): BelongsTo { - return $this->belongsTo(Asset::class); - } - - - public function getParsedTypeAttribute(): array { - return ['name' => $this->type, 'title' => OperationType::TITLES[$this->type] ?? null]; - } - - - -} diff --git a/app/Models/Registries/OperationType.php b/app/Models/Registries/OperationType.php deleted file mode 100644 index 7e6b625..0000000 --- a/app/Models/Registries/OperationType.php +++ /dev/null @@ -1,15 +0,0 @@ - 'Разработка', - self::REWORK => 'Пересмотр', - self::MODIFICATION => 'Изменение' - ]; -} \ No newline at end of file diff --git a/app/Models/Registries/Registry.php b/app/Models/Registries/Registry.php index bf5279f..2a8fab2 100644 --- a/app/Models/Registries/Registry.php +++ b/app/Models/Registries/Registry.php @@ -36,6 +36,10 @@ class Registry extends Model { return $this->hasMany(Category::class); } + public function rootCategories(): HasMany { + return $this->categories()->where(['parent_id' => 0]); + } + public function entries(): HasMany { return $this->hasMany(Entry::class); } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 381a45a..e05d2d0 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -12,6 +12,9 @@ use App\Models\Objects\ObjectType; use App\Models\Pages\Page; use App\Models\Permission; use App\Models\Publications\Publication; +use App\Models\Registries\Category; +use App\Models\Registries\Entry; +use App\Models\Registries\Registry; use App\Models\Role; use App\Models\SocialProvider; use App\Models\User; @@ -58,6 +61,10 @@ class AppServiceProvider extends ServiceProvider 'page' => Page::class, 'publication' => Publication::class, + + 'registry' => Registry::class, + 'registry-category' => Category::class, + 'registry-entry' => Entry::class ]); } } diff --git a/app/Services/Forms/FormsService.php b/app/Services/Forms/FormsService.php index ebff592..7e2e3c2 100644 --- a/app/Services/Forms/FormsService.php +++ b/app/Services/Forms/FormsService.php @@ -4,6 +4,7 @@ namespace App\Services\Forms; use App\Services\Forms\Pages\PageFormsServices; use App\Services\Forms\Publications\PublicationFormsServices; +use App\Services\Forms\Registries\RegistryFormsServices; use App\Services\Forms\Users\UserFormsServices; class FormsService { @@ -12,6 +13,7 @@ class FormsService { public static array $services = [ PageFormsServices::class, PublicationFormsServices::class, + RegistryFormsServices::class, UserFormsServices::class ]; diff --git a/app/Services/Forms/Registries/CategoryForms.php b/app/Services/Forms/Registries/CategoryForms.php new file mode 100644 index 0000000..53914dc --- /dev/null +++ b/app/Services/Forms/Registries/CategoryForms.php @@ -0,0 +1,51 @@ + 'Создание категории', 'update' => 'Редактирование категории']; + + public function form(?string $id = null, array $data = []): array { + $model = Category::byUuid($id)->first(); + $groups = [ + ['name' => 'common', 'fields' => $this->commonGroupFields($model)] + ]; + return ['title' => $this->formTitle($model), 'data' => $groups]; + } + + public function commonGroupFields(?Category $model): array { + $fields = [ + [ + 'name' => 'name', + 'title' => 'Название категории', + 'type' => FieldType::STRING, + 'required' => true, + 'value' => $model->name ?? null + ] + ]; + return ['data' => $fields]; + } + + + + public function store(array $data): ?JsonResponse { + $registry = Registry::byUuid($data['registry'] ?? null)->firstOrFail(); + $parent = Category::byUuid($data['parent'] ?? null)->first(); + $data['parent_id'] = $parent->id ?? 0; + $model = $registry->categories()->create($data); + return fractal($model, new CategoryTransformer())->respond(); + } + + public function update(string $id, array $data): ?JsonResponse { + $model = Category::byUuid($id)->firstOrFail(); + $model->update($data); + return fractal($model->fresh(), new CategoryTransformer())->respond(); + } +} diff --git a/app/Services/Forms/Registries/EntryForms.php b/app/Services/Forms/Registries/EntryForms.php new file mode 100644 index 0000000..8eb6f68 --- /dev/null +++ b/app/Services/Forms/Registries/EntryForms.php @@ -0,0 +1,82 @@ + 'Создание записи', 'update' => 'Редактирование записи']; + + public function form(?string $id = null, array $data = []): array { + $model = Entry::byUuid($id)->first(); + $groups = [ + ['name' => 'common', 'fields' => $this->commonGroupFields($model)] + ]; + return ['title' => $this->formTitle($model), 'data' => $groups]; + } + + public function commonGroupFields(?Entry $model): array { + $fields = [ + [ + 'name' => 'number', + 'title' => 'Номер записи', + 'type' => FieldType::STRING, + 'required' => true, + 'value' => $model->number ?? null + ], + [ + 'name' => 'name', + 'title' => 'Название', + 'type' => FieldType::STRING, + 'required' => true, + 'value' => $model->name ?? null + ], + [ + 'name' => 'asset', + 'title' => 'Документ', + 'type' => FieldType::DOCUMENT, + 'required' => true, + 'value' => ($asset = $model->asset ?? null) ? fractal($asset, new AssetTransformer()) : null + ], + [ + 'name' => 'active_since', + 'title' => 'Дата начала действия', + 'type' => FieldType::DATE, + 'value' => ($v = $model->active_since ?? null) ? $v->toIso8601String() : null + ], + [ + 'name' => 'active_till', + 'title' => 'Дата окончания действия', + 'type' => FieldType::DATE, + 'value' => ($v = $model->active_till ?? null) ? $v->toIso8601String() : null + ] + ]; + return ['data' => $fields]; + } + + + + public function store(array $data): ?JsonResponse { + $registry = Registry::byUuid($data['registry'] ?? null)->firstOrFail(); + $category = Category::byUuid($data['category'] ?? null)->first(); + $data['asset_id'] = ($asset = Asset::byUuid($data['asset'])->first()) ? $asset->id : null; + $data['category_id'] = $category->id ?? 0; + $model = $registry->entries()->create($data); + return fractal($model, new EntryTransformer())->respond(); + } + + public function update(string $id, array $data): ?JsonResponse { + $model = Entry::byUuid($id)->firstOrFail(); + $data['asset_id'] = ($asset = Asset::byUuid($data['asset'])->first()) ? $asset->id : null; + $model->update($data); + return fractal($model->fresh(), new EntryTransformer())->respond(); + } +} diff --git a/app/Services/Forms/Registries/OperationForms.php b/app/Services/Forms/Registries/OperationForms.php new file mode 100644 index 0000000..a393cef --- /dev/null +++ b/app/Services/Forms/Registries/OperationForms.php @@ -0,0 +1,117 @@ + 'Создание операции', 'update' => 'Редактирование операции']; + + public function form(?string $id = null, array $data = []): array { + $model = NirObject::byUuid($id)->first(); + $groups = [ + ['name' => 'common', 'fields' => $this->commonGroupFields($model)] + ]; + return ['title' => $this->formTitle($model), 'data' => $groups]; + } + + public function commonGroupFields(?NirObject $model): array { + return $model ? fractal($model->groups->first()->fields, new ObjectPropertyTransformer($model))->toArray() : + fractal(ObjectType::byName('entry-operation')->first()->groups()->first()->fields, new FieldTransformer())->toArray(); + + /* + $fields = [ + [ + 'name' => 'type', + 'title' => 'Вид работы', + 'type' => FieldType::RELATION, + 'required' => true, + 'appearance' => 'radio', + 'options' => $this->getRelationItems(OperationType::TITLES), + 'value' => $this->getRelationValue(OperationType::TITLES, $model->type ?? null) + ], + [ + 'name' => 'order_name', + 'title' => 'Наименование приказа', + 'type' => FieldType::STRING, + 'required' => true, + 'value' => $model->order_name ?? null + ], + [ + 'name' => 'order_date', + 'title' => 'Дата приказа', + 'required' => true, + 'type' => FieldType::DATE, + 'value' => ($v = $model->order_date ?? null) ? $v->toIso8601String() : null + ], + [ + 'name' => 'order', + 'title' => 'Документ приказа', + 'type' => FieldType::DOCUMENT, + 'required' => true, + 'value' => ($order = $model->order ?? null) ? fractal($order, new AssetTransformer()) : null + ], + [ + 'name' => 'listing', + 'title' => 'Вхождение в перечень ПП', + 'type' => FieldType::RELATION, + 'multiple' => true, + 'appearance' => 'checkbox', + 'options' => fractal(Dictionary::byName('listings')->first()->items, new DictionaryItemTransformer()), + 'value' => null + ], + [ + 'name' => 'active_since', + 'title' => 'Дата начала действия', + 'type' => FieldType::DATE, + 'required' => true, + 'value' => ($v = $model->active_since ?? null) ? $v->toIso8601String() : null + ], + [ + 'name' => 'active_till', + 'title' => 'Дата окончания действия', + 'type' => FieldType::DATE, + 'value' => ($v = $model->active_till ?? null) ? $v->toIso8601String() : null + ], + [ + 'name' => 'developer', + 'title' => 'Разработчик', + 'type' => FieldType::STRING, + 'required' => true, + 'value' => $model->developer ?? null + ] + ]; + return ['data' => $fields]; + */ + } + + + + public function store(array $data): ?JsonResponse { + $entry = Entry::byUuid($data['entry'] ?? null)->firstOrFail(); + $model = $entry->createObject('entry-operation', null, 'operations'); + $model->setValues($data); + return fractal($model, new ObjectTransformer())->respond(); + } + + public function update(string $id, array $data): ?JsonResponse { + $model = NirObject::byUuid($id)->firstOrFail(); + $model->setValues($data); + return fractal($model->fresh(), new ObjectTransformer())->respond(); + } +} diff --git a/app/Services/Forms/Registries/RegistryFormsServices.php b/app/Services/Forms/Registries/RegistryFormsServices.php new file mode 100644 index 0000000..56e5afb --- /dev/null +++ b/app/Services/Forms/Registries/RegistryFormsServices.php @@ -0,0 +1,11 @@ + CategoryForms::class, + 'registryEntry' => EntryForms::class, + 'entryOperation' => OperationForms::class + ]; +} diff --git a/app/Transformers/Objects/ObjectTransformer.php b/app/Transformers/Objects/ObjectTransformer.php index f577a5b..d9212fc 100644 --- a/app/Transformers/Objects/ObjectTransformer.php +++ b/app/Transformers/Objects/ObjectTransformer.php @@ -23,7 +23,7 @@ class ObjectTransformer extends TransformerAbstract { return [ 'id' => $model->uuid, 'name' => $model->name, - 'type_title' => $model->type->title, + 'type_title' => $model->type->title ?? null, 'pivot' => ['group' => $model->pivot->group ?? null, 'ord' => $model->pivot->ord ?? null], 'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null, 'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null diff --git a/app/Transformers/Pages/PageTransformer.php b/app/Transformers/Pages/PageTransformer.php index 4f547a4..201c6c2 100644 --- a/app/Transformers/Pages/PageTransformer.php +++ b/app/Transformers/Pages/PageTransformer.php @@ -6,6 +6,7 @@ use App\Models\Pages\Page; use App\Services\PermissionsService; use App\Transformers\Objects\ObjectTransformer; use App\Transformers\Publications\PublicationTransformer; +use App\Transformers\Registries\RegistryTransformer; use League\Fractal\Resource\Collection; use League\Fractal\Resource\Item; use League\Fractal\Resource\Primitive; @@ -17,7 +18,8 @@ class PageTransformer extends TransformerAbstract { ]; protected array $availableIncludes = [ - 'children', 'parent', 'parents', 'sections', 'sidebars', 'publications', 'permissions' + 'children', 'parent', 'parents', 'sections', 'sidebars', 'publications', + 'registries', 'registry', 'permissions' ]; public function transform(Page $model): array { @@ -58,6 +60,14 @@ class PageTransformer extends TransformerAbstract { return $this->collection($model->publications, new PublicationTransformer()); } + public function includeRegistries(Page $model): Collection { + return $this->collection($model->registries, new RegistryTransformer()); + } + + public function includeRegistry(Page $model): ?Item { + return $model->registry ? $this->item($model->registry, new RegistryTransformer()) : null; + } + public function includePermissions(Page $model): Primitive { return $this->primitive((new PermissionsService($model))->get()); } diff --git a/app/Transformers/Registries/EntryTransformer.php b/app/Transformers/Registries/EntryTransformer.php index 7f77a60..50ed8a8 100644 --- a/app/Transformers/Registries/EntryTransformer.php +++ b/app/Transformers/Registries/EntryTransformer.php @@ -5,6 +5,7 @@ namespace App\Transformers\Registries; use App\Models\Registries\Entry; use App\Services\PermissionsService; use App\Transformers\Assets\AssetTransformer; +use App\Transformers\Objects\ObjectTransformer; use League\Fractal\Resource\Collection; use League\Fractal\Resource\Item; use League\Fractal\Resource\Primitive; @@ -44,7 +45,7 @@ class EntryTransformer extends TransformerAbstract { } public function includeOperations(Entry $model): Collection { - return $this->collection($model->operations, new OperationTransformer()); + return $this->collection($model->operations, new ObjectTransformer()); } public function includePermissions(Entry $model): Primitive { diff --git a/app/Transformers/Registries/OperationTransformer.php b/app/Transformers/Registries/OperationTransformer.php deleted file mode 100644 index 23d1efc..0000000 --- a/app/Transformers/Registries/OperationTransformer.php +++ /dev/null @@ -1,54 +0,0 @@ - $model->uuid, - 'type' => $model->parsedType, - 'name' => $model->name, - 'developer' => $model->developer, - 'order_name' => $model->order_name, - 'order_date' => $model->order_date ? $model->order_date->toIso8601String() : null, - 'active_since' => $model->active_since ? $model->active_since->toIso8601String() : null, - 'active_till' => $model->active_till ? $model->active_till->toIso8601String() : null, - 'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null, - 'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null - ]; - } - - public function includeRegistry(Entry $model): ?Item { - return $model->registry ? $this->item($model->registry, new RegistryTransformer()) : null; - } - - public function includeCategory(Entry $model): ?Item { - return $model->category ? $this->item($model->category, new CategoryTransformer()) : null; - } - - public function includeAsset(Entry $model): ?Item { - return $model->asset ? $this->item($model->asset, new AssetTransformer()) : null; - } - - public function includePermissions(Entry $model): Primitive { - return $this->primitive((new PermissionsService($model))->get()); - } - - -} diff --git a/app/Transformers/Registries/RegistryTransformer.php b/app/Transformers/Registries/RegistryTransformer.php index bea402a..437162a 100644 --- a/app/Transformers/Registries/RegistryTransformer.php +++ b/app/Transformers/Registries/RegistryTransformer.php @@ -35,7 +35,7 @@ class RegistryTransformer extends TransformerAbstract { } public function includeCategories(Registry $model): Collection { - return $this->collection($model->categories, new CategoryTransformer()); + return $this->collection($model->rootCategories, new CategoryTransformer()); } public function includeEntries(Registry $model): Collection { diff --git a/database/migrations/2023_06_22_174800_create_registry_entry_operations_table.php b/database/migrations/2023_06_22_174800_create_registry_entry_operations_table.php deleted file mode 100644 index 33fc39b..0000000 --- a/database/migrations/2023_06_22_174800_create_registry_entry_operations_table.php +++ /dev/null @@ -1,41 +0,0 @@ -id(); - $table->char('uuid', 36)->index()->unique(); - $table->integer('entry_id')->index()->nullable(); - $table->integer('order_id')->index()->nullable(); - $table->string('type')->index()->nullable(); - $table->string('developer')->index()->nullable(); - $table->string('order_name')->index()->nullable(); - $table->date('order_date')->index()->nullable(); - $table->date('active_since')->index()->nullable(); - $table->date('active_till')->index()->nullable(); - $table->timestamps(); - $table->softDeletes(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('registry_entry_operations'); - } -} diff --git a/database/seeders/Dictionaries/DictionariesTableSeeder.php b/database/seeders/Dictionaries/DictionariesTableSeeder.php index 20dac8d..6e41f0a 100644 --- a/database/seeders/Dictionaries/DictionariesTableSeeder.php +++ b/database/seeders/Dictionaries/DictionariesTableSeeder.php @@ -10,6 +10,14 @@ class DictionariesTableSeeder extends Seeder { 'list-types' => [ 'title' => 'Виды списка', 'items' => ['marked' => 'Маркированный', 'numeric' => 'Нумерованный'] + ], + 'operation-types' => [ + 'title' => 'Виды операций', + 'items' => ['development' => 'Разработка', 'rework' => 'Пересмотр', 'modification' => 'Изменение'] + ], + 'listings' => [ + 'title' => 'Перечни ПП', + 'items' => ['pp1521' => 'ПП №1521 от 26.12.2014 г.', 'pp985' => 'ПП № 985 от 04.07.2020 г.', 'pp815' => 'ПП № 815 от 28.05.2021 г.'] ] ]; diff --git a/database/seeders/Objects/FieldsTableSeeder.php b/database/seeders/Objects/FieldsTableSeeder.php index 5d9ea3b..c9a8d51 100644 --- a/database/seeders/Objects/FieldsTableSeeder.php +++ b/database/seeders/Objects/FieldsTableSeeder.php @@ -74,6 +74,56 @@ class FieldsTableSeeder extends Seeder { 'title' => 'Ссылка на видео', 'type' => FieldType::STRING, 'required' => true + ], + + // Registry entry operation fields + 'operation-type' => [ + 'title' => 'Вид работы', + 'type' => FieldType::RELATION, + 'required' => true, + 'params' => [ + 'appearance' => 'radio', + 'related' => DictionaryItem::class, 'transformer' => DictionaryItemTransformer::class, + 'options' => ['show' => true, 'whereHas' => ['dictionary' => ['name' => 'operation-types']]] + ] + ], + 'order-name' => [ + 'title' => 'Наименование приказа', + 'type' => FieldType::STRING, + 'required' => true + ], + 'order-date' => [ + 'title' => 'Дата приказа', + 'type' => FieldType::DATE, + 'required' => true + ], + 'order-document' => [ + 'title' => 'Документ приказа', + 'type' => FieldType::DOCUMENT, + 'required' => true + ], + 'listings' => [ + 'title' => 'Вхождение в перечень ПП', + 'type' => FieldType::RELATION, + 'multiple' => true, + 'params' => [ + 'appearance' => 'checkbox', + 'related' => DictionaryItem::class, 'transformer' => DictionaryItemTransformer::class, + 'options' => ['show' => true, 'whereHas' => ['dictionary' => ['name' => 'listings']]] + ] + ], + 'active-since' => [ + 'title' => 'Дата начала действия', + 'type' => FieldType::DATE, + 'required' => true + ], + 'active-till' => [ + 'title' => 'Дата окончания действия', + 'type' => FieldType::DATE + ], + 'developer' => [ + 'title' => 'Разработчик', + 'type' => FieldType::STRING ] ]; diff --git a/database/seeders/Objects/ObjectTypeFieldsTableSeeder.php b/database/seeders/Objects/ObjectTypeFieldsTableSeeder.php index 39df52d..8f0dbd3 100644 --- a/database/seeders/Objects/ObjectTypeFieldsTableSeeder.php +++ b/database/seeders/Objects/ObjectTypeFieldsTableSeeder.php @@ -44,8 +44,13 @@ class ObjectTypeFieldsTableSeeder extends Seeder { 'common' => [ 'fields' => ['video-url'] ] - ] + ], + 'entry-operation' => [ + 'common' => [ + 'fields' => ['operation-type', 'order-name', 'order-date', 'order-document', 'listings', 'active-since', 'active-till', 'developer'] + ] + ] ]; public function run() { diff --git a/database/seeders/Objects/ObjectTypesTableSeeder.php b/database/seeders/Objects/ObjectTypesTableSeeder.php index 887f895..e7f18bc 100644 --- a/database/seeders/Objects/ObjectTypesTableSeeder.php +++ b/database/seeders/Objects/ObjectTypesTableSeeder.php @@ -35,13 +35,8 @@ class ObjectTypesTableSeeder extends Seeder { ] ], - 'registry-entry' => [ - 'title' => 'Запись в реестре', - 'children' => [ - 'registry-entry-document' => [ - 'title' => 'Документ' - ] - ] + 'entry-operation' => [ + 'title' => 'Действие с записью в реестре' ] ]; diff --git a/routes/api.php b/routes/api.php index bd62a53..f7b0369 100644 --- a/routes/api.php +++ b/routes/api.php @@ -23,6 +23,22 @@ Route::get('publications', 'Api\Publications\PublicationsController@index'); Route::get('publications/find', 'Api\Publications\PublicationsController@find'); Route::get('publications/{id}', 'Api\Publications\PublicationsController@show'); +Route::group(['prefix' => 'registries'], function() { + Route::get('/categories', 'Api\Registries\CategoriesController@index'); + Route::get('/categories/{id}', 'Api\Registries\CategoriesController@show'); + Route::get('/entries', 'Api\Registries\EntriesController@index'); + Route::get('/entries/{id}', 'Api\Registries\EntriesController@show'); + Route::get('/operations', 'Api\Registries\OperationsController@index'); + Route::get('/operations/{id}', 'Api\Registries\OperationsController@show'); + Route::get('/', 'Api\Registries\RegistriesController@index'); + Route::get('/{id}', 'Api\Registries\RegistriesController@show'); + Route::group(['middleware' => ['auth:api']], function() { + Route::delete('/categories/{id}', 'Api\Registries\CategoriesController@destroy'); + Route::delete('/entries/{id}', 'Api\Registries\EntriesController@destroy'); + Route::delete('/operations/{id}', 'Api\Registries\OperationsController@destroy'); + }); +}); + Route::group(['middleware' => ['auth:api']], function() { Route::apiResource('users', 'Api\Users\UsersController'); Route::apiResource('roles', 'Api\Users\RolesController');