diff --git a/app/Http/Controllers/V3/Azmayesh/AzmayeshController.php b/app/Http/Controllers/V3/Azmayesh/AzmayeshController.php new file mode 100644 index 00000000..e6aa7574 --- /dev/null +++ b/app/Http/Controllers/V3/Azmayesh/AzmayeshController.php @@ -0,0 +1,125 @@ +json($data); + } + + /** + * Store a newly created resource in storage. + */ + public function store(StoreRequest $request): JsonResponse + { + $azmayeshType = AzmayeshType::query()->findOrFail($request->azmayesh_type_id); + $province = Province::query()->findOrFail($request->province_id); + + Azmayesh::query()->create([ + 'lat' => $request->lat, + 'lng' => $request->lng, + 'azmayesh_type_id' => $azmayeshType->id, + 'azmayesh_type_name' => $azmayeshType->name, + 'request_date' => $request->request_date, + 'report_date' => $request->report_date, + 'request_number' => $request->request_number ?? '-', + 'employer' => $request->employer ?? '-', + 'contractor' => $request->contractor ?? '-', + 'work_number' => $request->work_number ?? '-', + 'project_name' => $request->project_name, + 'consultant' => $request->consultant ?? '-', + 'applicant' => $request->applicant ?? '-', + 'province_id' => $province->id, + 'province_name' => $province->name_fa, + ]); + + return $this->successResponse(); + } + + /** + * Display the specified resource. + */ + public function show(Azmayesh $azmayesh): JsonResponse + { + return $this->successResponse($azmayesh->load('azmayeshSamples')); + } + + /** + * Update the specified resource in storage. + */ + public function update(UpdateRequest $request, Azmayesh $azmayesh): JsonResponse + { + $province = Province::query()->findOrFail($request->province_id); + $azmayeshType = AzmayeshType::query()->findOrFail($request->azmayesh_type_id); + + $azmayesh->update([ + 'lat' => $request->lat, + 'lng' => $request->lng, + 'azmayesh_type_id' => $azmayeshType->id, + 'azmayesh_type_name' => $azmayeshType->name, + 'request_date' => $request->request_date, + 'report_date' => $request->report_date, + 'request_number' => $request->request_number ?? '-', + 'employer' => $request->employer ?? '-', + 'contractor' => $request->contractor ?? '-', + 'work_number' => $request->work_number ?? '-', + 'project_name' => $request->project_name, + 'consultant' => $request->consultant ?? '-', + 'applicant' => $request->applicant ?? '-', + 'province_id' => $province->id, + 'province_name' => $province->name_fa, + ]); + + return $this->successResponse(); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(Azmayesh $azmayesh): JsonResponse + { + $azmayesh->delete(); + + return $this->successResponse(); + } +} diff --git a/app/Http/Controllers/V3/Azmayesh/AzmayeshSampleController.php b/app/Http/Controllers/V3/Azmayesh/AzmayeshSampleController.php new file mode 100644 index 00000000..2dee40af --- /dev/null +++ b/app/Http/Controllers/V3/Azmayesh/AzmayeshSampleController.php @@ -0,0 +1,92 @@ +where('azmayesh_id', '=', $azmayesh_id); + + $data = DataTableFacade::run( + $query, + $request, + allowedFilters: $allowedFilters, + allowedSortings: $allowedSortings); + + return response()->json($data); + } + + /** + * Store a newly created resource in storage. + */ + public function store(StoreRequest $request): JsonResponse + { + $azmayesh = Azmayesh::query()->findOrFail($request->azmayesh_id); + + AzmayeshSample::query()->create([ + 'azmayesh_id' => $azmayesh->id, + 'azmayesh_project_name' => $azmayesh->project_name, + 'data' => $request->data, + ]); + + return $this->successResponse(); + } + + /** + * Display the specified resource. + */ + public function show(AzmayeshSample $azmayeshSample) + { + return $this->successResponse($azmayeshSample); + } + + /** + * Update the specified resource in storage. + */ + public function update(UpdateRequest $request, AzmayeshSample $azmayeshSample) + { + $azmayesh = Azmayesh::query()->findOrFail($request->azmayesh_id); + + $azmayeshSample->update([ + 'azmayesh_id' => $azmayesh->id, + 'azmayesh_project_name' => $azmayesh->project_name, + 'data' => $request->data, + ]); + + return $this->successResponse(); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(AzmayeshSample $azmayeshSample) + { + $azmayeshSample->delete(); + + return $this->successResponse(); + } +} diff --git a/app/Http/Controllers/V3/Azmayesh/AzmayeshTypeController.php b/app/Http/Controllers/V3/Azmayesh/AzmayeshTypeController.php new file mode 100644 index 00000000..1f9f0b8d --- /dev/null +++ b/app/Http/Controllers/V3/Azmayesh/AzmayeshTypeController.php @@ -0,0 +1,28 @@ +successResponse($allTypes); + } + + public function fields(AzmayeshType $azmayeshType): JsonResponse + { + $fields = $azmayeshType->azmayeshFields->select('id', 'name', 'unit', 'type', 'option'); + + return $this->successResponse($fields); + } +} diff --git a/app/Http/Requests/V3/Azmayesh/StoreRequest.php b/app/Http/Requests/V3/Azmayesh/StoreRequest.php new file mode 100644 index 00000000..aea7c1c4 --- /dev/null +++ b/app/Http/Requests/V3/Azmayesh/StoreRequest.php @@ -0,0 +1,40 @@ +|string> + */ + public function rules(): array + { + return [ + 'lat' => 'required|string', + 'lng' => 'required|string', + 'azmayesh_type_id' => 'required|exists:azmayesh_types,id', + 'request_date' => 'date', + 'report_date' => 'date', + 'request_number' => 'string', + 'employer' => 'string', + 'contractor' => 'string', + 'work_number' => 'string', + 'project_name' => 'required|string', + 'consultant' => 'string', + 'applicant' => 'string', + 'province_id' => 'required|exists:provinces,id', + ]; + } +} diff --git a/app/Http/Requests/V3/Azmayesh/UpdateRequest.php b/app/Http/Requests/V3/Azmayesh/UpdateRequest.php new file mode 100644 index 00000000..ad2854b2 --- /dev/null +++ b/app/Http/Requests/V3/Azmayesh/UpdateRequest.php @@ -0,0 +1,40 @@ +|string> + */ + public function rules(): array + { + return [ + 'lat' => 'required|string', + 'lng' => 'required|string', + 'azmayesh_type_id' => 'required|exists:azmayesh_types,id', + 'request_date' => 'date', + 'report_date' => 'date', + 'request_number' => 'string', + 'employer' => 'string', + 'contractor' => 'string', + 'work_number' => 'string', + 'project_name' => 'required|string', + 'consultant' => 'string', + 'applicant' => 'string', + 'province_id' => 'required|exists:provinces,id', + ]; + } +} diff --git a/app/Http/Requests/V3/AzmayeshSample/StoreRequest.php b/app/Http/Requests/V3/AzmayeshSample/StoreRequest.php new file mode 100644 index 00000000..fb1a5ea5 --- /dev/null +++ b/app/Http/Requests/V3/AzmayeshSample/StoreRequest.php @@ -0,0 +1,29 @@ +|string> + */ + public function rules(): array + { + return [ + 'azmayesh_id' => 'required|exists:azmayeshes,id', + 'data' => 'required', + ]; + } +} diff --git a/app/Http/Requests/V3/AzmayeshSample/UpdateRequest.php b/app/Http/Requests/V3/AzmayeshSample/UpdateRequest.php new file mode 100644 index 00000000..4ce5d38d --- /dev/null +++ b/app/Http/Requests/V3/AzmayeshSample/UpdateRequest.php @@ -0,0 +1,29 @@ +|string> + */ + public function rules(): array + { + return [ + 'azmayesh_id' => 'required|exists:azmayeshes,id', + 'data' => 'required', + ]; + } +} diff --git a/app/Models/Azmayesh.php b/app/Models/Azmayesh.php new file mode 100644 index 00000000..88adfa5e --- /dev/null +++ b/app/Models/Azmayesh.php @@ -0,0 +1,24 @@ +hasMany(AzmayeshSample::class); + } + + public function getRouteKeyName(): string + { + return 'id'; + } +} diff --git a/app/Models/AzmayeshField.php b/app/Models/AzmayeshField.php new file mode 100644 index 00000000..efb49a4a --- /dev/null +++ b/app/Models/AzmayeshField.php @@ -0,0 +1,27 @@ + json_decode($value), + ); + } + + public function azmayeshTypes(): BelongsToMany + { + return $this->belongsToMany(AzmayeshType::class, 'azmayesh_field_azmayesh_type'); + } +} diff --git a/app/Models/AzmayeshSample.php b/app/Models/AzmayeshSample.php new file mode 100644 index 00000000..e79b544a --- /dev/null +++ b/app/Models/AzmayeshSample.php @@ -0,0 +1,13 @@ +hasMany(Azmayesh::class); + } + + public function azmayeshFields(): BelongsToMany + { + return $this->belongsToMany(AzmayeshField::class,'azmayesh_field_azmayesh_type'); + } +} diff --git a/database/factories/AzmayeshFactory.php b/database/factories/AzmayeshFactory.php new file mode 100644 index 00000000..e8aa9d2e --- /dev/null +++ b/database/factories/AzmayeshFactory.php @@ -0,0 +1,43 @@ + + */ +class AzmayeshFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'lat' => $this->faker->numerify, + 'lng' => $this->faker->numerify, + 'azmayesh_type_id' => AzmayeshType::factory(), + 'azmayesh_type_name' => function (array $attributes) { + return AzmayeshType::query()->find($attributes['azmayesh_type_id'])->name; + }, + 'province_id' => Province::factory(), + 'province_name' => function (array $attributes) { + return Province::query()->find($attributes['province_id'])->name_fa; + }, + 'request_date' => $this->faker->date, + 'report_date' => $this->faker->date, + 'request_number' => $this->faker->numerify, + 'employer' => $this->faker->name, + 'contractor' => $this->faker->name, + 'work_number' => $this->faker->numerify, + 'project_name' => $this->faker->name, + 'consultant' => $this->faker->name, + 'applicant' => $this->faker->name, + ]; + } +} diff --git a/database/factories/AzmayeshFieldFactory.php b/database/factories/AzmayeshFieldFactory.php new file mode 100644 index 00000000..e0729e35 --- /dev/null +++ b/database/factories/AzmayeshFieldFactory.php @@ -0,0 +1,25 @@ + + */ +class AzmayeshFieldFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => $this->faker->name, + 'unit' => $this->faker->name, + 'type' => $this->faker->name, + ]; + } +} diff --git a/database/factories/AzmayeshSampleFactory.php b/database/factories/AzmayeshSampleFactory.php new file mode 100644 index 00000000..c288abf4 --- /dev/null +++ b/database/factories/AzmayeshSampleFactory.php @@ -0,0 +1,28 @@ + + */ +class AzmayeshSampleFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'azmayesh_id' => Azmayesh::factory(), + 'azmayesh_project_name' => function (array $attributes) { + return Azmayesh::query()->find($attributes['azmayesh_id'])->project_name; + }, + 'data' => json_encode(['test']), + ]; + } +} diff --git a/database/factories/AzmayeshTypeFactory.php b/database/factories/AzmayeshTypeFactory.php new file mode 100644 index 00000000..0a0cf008 --- /dev/null +++ b/database/factories/AzmayeshTypeFactory.php @@ -0,0 +1,23 @@ + + */ +class AzmayeshTypeFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => $this->faker->name + ]; + } +} diff --git a/database/migrations/2024_10_22_092756_create_azmayesh_fields_table.php b/database/migrations/2024_10_22_092756_create_azmayesh_fields_table.php new file mode 100644 index 00000000..56584489 --- /dev/null +++ b/database/migrations/2024_10_22_092756_create_azmayesh_fields_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('name'); + $table->string('unit')->nullable(); + $table->string('type'); + $table->json('option')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('azmayesh_fields'); + } +}; diff --git a/database/migrations/2024_10_22_092762_create_azmayesh_types_table.php b/database/migrations/2024_10_22_092762_create_azmayesh_types_table.php new file mode 100644 index 00000000..db0e636c --- /dev/null +++ b/database/migrations/2024_10_22_092762_create_azmayesh_types_table.php @@ -0,0 +1,28 @@ +id(); + $table->string('name'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('azmayesh_types'); + } +}; diff --git a/database/migrations/2024_10_22_092800_create_azmayeshes_table.php b/database/migrations/2024_10_22_092800_create_azmayeshes_table.php new file mode 100644 index 00000000..a740e91d --- /dev/null +++ b/database/migrations/2024_10_22_092800_create_azmayeshes_table.php @@ -0,0 +1,43 @@ +id(); + $table->foreignId('azmayesh_type_id')->constrained('azmayesh_types'); + $table->string('azmayesh_type_name'); + $table->string('lat'); + $table->string('lng'); + $table->unsignedTinyInteger('province_id'); + $table->foreign('province_id')->references('id')->on('provinces'); + $table->string('province_name'); + $table->date('request_date')->nullable(); + $table->date('report_date')->nullable(); + $table->string('request_number'); + $table->string('employer'); + $table->string('contractor'); + $table->string('work_number'); + $table->string('project_name'); + $table->string('consultant'); + $table->string('applicant'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('azmayeshes'); + } +}; diff --git a/database/migrations/2024_10_22_114035_create_azmayesh_samples_table.php b/database/migrations/2024_10_22_114035_create_azmayesh_samples_table.php new file mode 100644 index 00000000..ae579b37 --- /dev/null +++ b/database/migrations/2024_10_22_114035_create_azmayesh_samples_table.php @@ -0,0 +1,30 @@ +id(); + $table->foreignId('azmayesh_id')->constrained('azmayeshes')->cascadeOnDelete(); + $table->string('azmayesh_project_name'); + $table->json('data'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('azmayesh_samples'); + } +}; diff --git a/database/migrations/2024_10_22_152052_create_azmayesh_field_azmayesh_type_table.php b/database/migrations/2024_10_22_152052_create_azmayesh_field_azmayesh_type_table.php new file mode 100644 index 00000000..5507811c --- /dev/null +++ b/database/migrations/2024_10_22_152052_create_azmayesh_field_azmayesh_type_table.php @@ -0,0 +1,29 @@ +id(); + $table->foreignId('azmayesh_field_id')->constrained('azmayesh_fields'); + $table->foreignId('azmayesh_type_id')->constrained('azmayesh_types'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('azmayesh_field_azmayesh_type'); + } +}; diff --git a/database/seeders/AzmayeshFieldSeeder.php b/database/seeders/AzmayeshFieldSeeder.php new file mode 100644 index 00000000..c1b720ab --- /dev/null +++ b/database/seeders/AzmayeshFieldSeeder.php @@ -0,0 +1,118 @@ +insert([ + [ + 'id' => 1, + 'name' => 'طول', + 'unit' => 'cm', + 'type' => 'input', + 'option' => null, + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 2, + 'name' => 'عرض', + 'unit' => 'cm', + 'type' => 'input', + 'option' => null, + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 3, + 'name' => 'تاریخ آزمایش', + 'unit' => '-', + 'type' => 'date', + 'option' => null, + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 4, + 'name' => 'وضعیت سینی', + 'unit' => '-', + 'type' => 'select', + 'option' => json_encode(['طولی', 'عرضی']), + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 5, + 'name' => 'ضخامت', + 'unit' => 'cm', + 'type' => 'input', + 'option' => null, + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 6, + 'name' => 'نوع لایه', + 'unit' => '-', + 'type' => 'select', + 'option' => json_encode(['اساس']), + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 7, + 'name' => 'مشخصات تراکم نسبی', + 'unit' => 'percent', + 'type' => 'input', + 'option' => null, + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 8, + 'name' => 'نیروی تصحیح شده', + 'unit' => 'kg', + 'type' => 'input', + 'option' => null, + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 9, + 'name' => 'مقاومت فشاری آزمونه', + 'unit' => 'kg/cm2', + 'type' => 'input', + 'option' => null, + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 10, + 'name' => 'مقاومت فشاری آزمونه استوانه ای متناظر', + 'unit' => 'kg/cm2', + 'type' => 'input', + 'option' => null, + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 11, + 'name' => 'مقاومت فشاری آزمونه استوانه ای متناظر', + 'unit' => 'kg/cm2', + 'type' => 'input', + 'option' => null, + 'created_at' => now(), + 'updated_at' => now() + ], + ]); + } +} diff --git a/database/seeders/AzmayeshSampleSeeder.php b/database/seeders/AzmayeshSampleSeeder.php new file mode 100644 index 00000000..c602e92e --- /dev/null +++ b/database/seeders/AzmayeshSampleSeeder.php @@ -0,0 +1,30 @@ +insert([ + [ + 'id' => 1, + 'azmayesh_id' => 1, + 'azmayesh_project_name' => 'اجرای پروژه پل میرزای شیرازی شریفیه', + 'data' => json_encode([ + 1 => 'test' + ]), + 'created_at' => now(), + 'updated_at' => now() + ], + ]); + } +} diff --git a/database/seeders/AzmayeshSeeder.php b/database/seeders/AzmayeshSeeder.php new file mode 100644 index 00000000..b404afdb --- /dev/null +++ b/database/seeders/AzmayeshSeeder.php @@ -0,0 +1,139 @@ +insert([ + [ + 'id' => 1, + 'lat' => '36.2816000000', + 'lng' => '50.0153000000', + 'azmayesh_type_id' => 1, + 'azmayesh_type_name' => 'تعیین مقاومت فشاری بتن', + 'province_id' => 20, + 'province_name' => 'قزوین', + 'request_date' => '1403-02-12', + 'report_date' => '1403-02-12', + 'request_number' => '-', + 'employer' => 'شهرداری شریفیه', + 'contractor' => 'شرکت طرح گستر رواق', + 'work_number' => '020040035', + 'project_name' => 'اجرای پروژه پل میرزای شیرازی شریفیه', + 'consultant' => '-', + 'applicant' => 'شهرداری شریفیه', + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 2, + 'lat' => '36.2816000000', + 'lng' => '50.0153000000', + 'azmayesh_type_id' => 4, + 'azmayesh_type_name' => 'تعیین تراکم نسبی', + 'province_id' => 20, + 'province_name' => 'قزوین', + 'request_date' => '1403-01-15', + 'report_date' => '1403-07-07', + 'request_number' => '-', + 'employer' => 'شهرداری الوند', + 'contractor' => '-', + 'work_number' => '020040001', + 'project_name' => 'کنترل کیفی پروژه های اجرایی شهرداری الوند', + 'consultant' => '-', + 'applicant' => 'شهرداری الوند', + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 3, + 'lat' => '36.2816000000', + 'lng' => '50.0153000000', + 'azmayesh_type_id' => 3, + 'azmayesh_type_name' => 'مقدار قیر پاشیده شده', + 'province_id' => 20, + 'province_name' => 'قزوین', + 'request_date' => '1403-07-04', + 'report_date' => '1403-07-05', + 'request_number' => '-', + 'employer' => 'بنیاد مسکن استان قزوین', + 'contractor' => 'امور اجرایی و ماشین آلات عمرانی بنیاد مسکن', + 'work_number' => '-', + 'project_name' => 'کنترل کیفی پروژه های روستای ولدآباد', + 'consultant' => '-', + 'applicant' => 'بنیاد مسکن استان قزوین', + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 4, + 'lat' => '36.2816000000', + 'lng' => '50.0153000000', + 'azmayesh_type_id' => 1, + 'azmayesh_type_name' => 'تعیین مقاومت فشاری بتن', + 'province_id' => 20, + 'province_name' => 'قزوین', + 'request_date' => '1403-06-15', + 'report_date' => null, + 'request_number' => '15/28296', + 'employer' => 'اداره کل راهداری و حمل و نقل جاده ای استان قزوین', + 'contractor' => 'شرکت تاژه صنعت سنگسر', + 'work_number' => '010060027', + 'project_name' => 'نیوجرسی مفصلی جهت ایمن سازی آزادراه های قزوین-کرج و قزوین-زنجان', + 'consultant' => '-', + 'applicant' => 'اداره کل راهداری و حمل و نقل جاده ای استان قزوین', + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 5, + 'lat' => '36.2816000000', + 'lng' => '50.0153000000', + 'azmayesh_type_id' => 2, + 'azmayesh_type_name' => 'دانه بندی و نتایج آزمایش های آسفالت گرم', + 'province_id' => 20, + 'province_name' => 'قزوین', + 'request_date' => '1403-06-27', + 'report_date' => '1403-07-07', + 'request_number' => 'راهداری-مجتمع آقای کلانی', + 'employer' => 'اداره کل راهداری و حمل و نقل جاده ای استان قزوین', + 'contractor' => 'شرکت آرتان راهسازان البرز قزوین', + 'work_number' => '010100005', + 'project_name' => 'احداث راه های دسترسی مجتمع خدمات رفاهی حوزه آبیک-مجتمع آقای کلانی', + 'consultant' => '-', + 'applicant' => 'اداره کل راهداری و حمل و نقل جاده ای استان قزوین', + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 6, + 'lat' => '36.2816000000', + 'lng' => '50.0153000000', + 'azmayesh_type_id' => 5, + 'azmayesh_type_name' => 'دانه بندی و نتایج آزمایش های مصالح سنگی', + 'province_id' => 20, + 'province_name' => 'قزوین', + 'request_date' => '1403-03-20', + 'report_date' => '1403-07-09', + 'request_number' => '1400/4361-ص', + 'employer' => 'شرکت سهامی عام کارخانجات قند قزوین', + 'contractor' => '-', + 'work_number' => '070020123', + 'project_name' => 'آماده سازی محوطه دپوی سیلو کارخانه قند قزوین', + 'consultant' => '-', + 'applicant' => 'شرکت سهامی عام کارخانجات قند قزوین', + 'created_at' => now(), + 'updated_at' => now() + ], + ]); + } +} diff --git a/database/seeders/AzmayeshTypeSeeder.php b/database/seeders/AzmayeshTypeSeeder.php new file mode 100644 index 00000000..77244255 --- /dev/null +++ b/database/seeders/AzmayeshTypeSeeder.php @@ -0,0 +1,49 @@ +insert([ + [ + 'id' => 1, + 'name' => 'تعیین مقاومت فشاری بتن', + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 2, + 'name' => 'دانه بندی و نتایج آزمایش های آسفالت گرم', + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 3, + 'name' => 'مقدار قیر پاشیده شده', + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 4, + 'name' => 'تعیین تراکم نسبی', + 'created_at' => now(), + 'updated_at' => now() + ], + [ + 'id' => 5, + 'name' => 'دانه بندی و نتایج آزمایش های مصالح سنگی', + 'created_at' => now(), + 'updated_at' => now() + ], + ]); + } +} diff --git a/resources/lang/fa/validation.php b/resources/lang/fa/validation.php index 8fc265b8..377a776d 100644 --- a/resources/lang/fa/validation.php +++ b/resources/lang/fa/validation.php @@ -179,6 +179,21 @@ return [ 'new_password' => 'رمز عبور جدید', 'degree' => 'مدرک تحصیلی', 'major' => 'شغل', - 'avatar' => 'آواتار' + 'avatar' => 'آواتار', + 'lat' => 'طول جغرافیایی', + 'lng' => 'عرض جغرافیایی', + 'azmayesh_type_id' => 'نوع آزمایش', + 'request_date' => 'تاریخ درخواست', + 'report_date' => 'تاریخ گزارش', + 'request_number' => 'شماره درخواست', + 'employer' => 'کارفرما', + 'contractor' => 'پیمانکار', + 'work_number' => 'شماره کار', + 'project_name' => 'نام پروژه', + 'consultant' => 'مشاور', + 'applicant' => 'متقاضی', + 'province_id' => 'استان', + 'azmayesh_id' => 'آزمایش', + 'data' => 'داده' ], ]; diff --git a/routes/v3.php b/routes/v3.php index 9597fc93..7dc98798 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -1,5 +1,8 @@ name('edit'); Route::post('change_password', 'changePassword')->name('changePassword'); }); + +Route::prefix('azmayesh_types') + ->name('azmayesh_types.') + ->controller(AzmayeshTypeController::class) + ->group(function () { + Route::get('/', 'index')->name('index'); + Route::get('/fields/{azmayeshType}', 'fields')->name('fields'); + }); + +Route::prefix('azmayesh_samples') + ->name('azmayesh_samples.') + ->controller(AzmayeshSampleController::class) + ->group(function () { + Route::get('/index/{azmayesh_id}', 'index')->name('index'); + Route::get('/{azmayeshSample}', 'show')->name('show'); + Route::post('/store', 'store')->name('store'); + Route::post('/update/{azmayeshSample}', 'update')->name('update'); + Route::post('/delete/{azmayeshSample}', 'destroy')->name('delete'); + }); + + Route::prefix('azmayeshes') + ->name('azmayeshes.') + ->controller(AzmayeshController::class) + ->group(function () { + Route::get('/', 'index')->name('index'); + Route::get('/{azmayesh}', 'show')->name('show'); + Route::post('/store', 'store')->name('store'); + Route::post('/update/{azmayesh}', 'update')->name('update'); + Route::post('/delete/{azmayesh}', 'destroy')->name('delete'); + }); diff --git a/tests/Feature/V3/Azmayesh/DeleteTest.php b/tests/Feature/V3/Azmayesh/DeleteTest.php new file mode 100644 index 00000000..cafa4f74 --- /dev/null +++ b/tests/Feature/V3/Azmayesh/DeleteTest.php @@ -0,0 +1,44 @@ +create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.delete', [$azmayesh->id])); + + $response->assertOk(); + + $this->assertDatabaseMissing('azmayeshes', [ + 'lat' => $azmayesh->lat, + 'lng' => $azmayesh->lng, + 'azmayesh_type_id' => $azmayesh->azmayesh_type_id, + 'azmayesh_type_name' => $azmayesh->azmayesh_type_name, + 'request_date' => $azmayesh->request_date, + 'report_date' => $azmayesh->report_date, + 'request_number' => $azmayesh->request_number, + 'employer' => $azmayesh->employer, + 'contractor' => $azmayesh->contractor, + 'work_number' => $azmayesh->work_number, + 'project_name' => $azmayesh->project_name, + 'consultant' => $azmayesh->consultant, + 'applicant' => $azmayesh->applicant, + 'province_id' => $azmayesh->province_id, + 'province_name' => $azmayesh->province_name, + ]); + } +} diff --git a/tests/Feature/V3/Azmayesh/IndexTest.php b/tests/Feature/V3/Azmayesh/IndexTest.php new file mode 100644 index 00000000..eae71b0c --- /dev/null +++ b/tests/Feature/V3/Azmayesh/IndexTest.php @@ -0,0 +1,55 @@ +create(); + + Azmayesh::factory(5)->create(); + + $response = $this->actingAs($user)->getJson(route('v3.azmayeshes.index', [ + 'start' => 0, + 'size' => 10, + 'filters' => json_encode([]), + 'sorting' => json_encode([]), + ])); + + $response->assertOk(); + + $response->assertJsonStructure([ + 'data' => [ + '*' => [ + 'id', + 'lat', + 'lng', + 'request_date', + 'report_date', + 'request_number', + 'employer', + 'contractor', + 'work_number', + 'consultant', + 'applicant', + 'project_name', + 'province_id', + ], + ], + "meta" => [ + "totalRowCount" + ] + ]); + } +} diff --git a/tests/Feature/V3/Azmayesh/StoreTest.php b/tests/Feature/V3/Azmayesh/StoreTest.php new file mode 100644 index 00000000..6ee556cf --- /dev/null +++ b/tests/Feature/V3/Azmayesh/StoreTest.php @@ -0,0 +1,305 @@ +create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'lat' => __('validation.required', ['attribute' => 'طول جغرافیایی']) + ]); + } + + public function test_lat_attribute_should_be_string(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'lat' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'lat' => __('validation.string', ['attribute' => 'طول جغرافیایی']) + ]); + } + + public function test_lng_attribute_is_required(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'lng' => __('validation.required', ['attribute' => 'عرض جغرافیایی']) + ]); + } + + public function test_lng_attribute_should_be_string(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'lng' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'lng' => __('validation.string', ['attribute' => 'عرض جغرافیایی']) + ]); + } + + public function test_azmayesh_type_id_attribute_is_required(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'azmayesh_type_id' => __('validation.required', ['attribute' => 'نوع آزمایش']) + ]); + } + + public function test_azmayesh_type_id_attribute_should_exist_on_azmayesh_types_table(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'azmayesh_type_id' => $this->faker->numberBetween(10, 100) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'azmayesh_type_id' => __('validation.exists', ['attribute' => 'نوع آزمایش']) + ]); + } + + public function test_request_date_attribute_should_be_date_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'request_date' => $this->faker->lexify + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'request_date' => __('validation.date', ['attribute' => 'تاریخ درخواست']) + ]); + } + + public function test_report_date_attribute_should_be_date_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'report_date' => $this->faker->lexify + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'report_date' => __('validation.date', ['attribute' => 'تاریخ گزارش']) + ]); + } + + public function test_request_number_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'request_number' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'request_number' => __('validation.string', ['attribute' => 'شماره درخواست']) + ]); + } + + public function test_employer_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'employer' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'employer' => __('validation.string', ['attribute' => 'کارفرما']) + ]); + } + + public function test_contractor_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'contractor' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'contractor' => __('validation.string', ['attribute' => 'پیمانکار']) + ]); + } + + public function test_work_number_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'work_number' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'work_number' => __('validation.string', ['attribute' => 'شماره کار']) + ]); + } + + public function test_project_name_attribute_is_required(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'project_name' => __('validation.required', ['attribute' => 'نام پروژه']) + ]); + } + + public function test_project_name_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'project_name' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'project_name' => __('validation.string', ['attribute' => 'نام پروژه']) + ]); + } + + public function test_consultant_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'consultant' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'consultant' => __('validation.string', ['attribute' => 'مشاور']) + ]); + } + + public function test_applicant_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'applicant' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'applicant' => __('validation.string', ['attribute' => 'متقاضی']) + ]); + } + + public function test_province_id_attribute_is_required(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'province_id' => __('validation.required', ['attribute' => 'استان']) + ]); + } + + public function test_province_id_attribute_should_exists_on_province_table(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), [ + 'province_id' => $this->faker->numberBetween(10, 100) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'province_id' => __('validation.exists', ['attribute' => 'استان']) + ]); + } + + public function test_user_can_store_a_new_azmayesh(): void + { + $user = User::factory()->create(); + $province = Province::factory()->create(); + $azmayeshType = AzmayeshType::factory()->create(); + + $data = [ + 'lat' => $this->faker->numerify, + 'lng' => $this->faker->numerify, + 'azmayesh_type_id' => $azmayeshType->id, + 'request_date' => $this->faker->date, + 'report_date' => $this->faker->date, + 'request_number' => $this->faker->numerify, + 'employer' => $this->faker->name, + 'contractor' => $this->faker->name, + 'work_number' => $this->faker->numerify, + 'project_name' => $this->faker->name, + 'consultant' => $this->faker->name, + 'applicant' => $this->faker->name, + 'province_id' => $province->id, + ]; + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.store'), $data); + + $response->assertOk() + ->assertExactJson([ + 'message' => __('messages.successful') + ]); + + $this->assertDatabaseHas('azmayeshes', [ + 'lat' => $data['lat'], + 'lng' => $data['lng'], + 'azmayesh_type_id' => $data['azmayesh_type_id'], + 'request_date' => $data['request_date'], + 'report_date' => $data['report_date'], + 'request_number' => $data['request_number'], + 'employer' => $data['employer'], + 'contractor' => $data['contractor'], + 'work_number' => $data['work_number'], + 'project_name' => $data['project_name'], + 'consultant' => $data['consultant'], + 'applicant' => $data['applicant'], + 'province_id' => $data['province_id'], + ]); + } +} diff --git a/tests/Feature/V3/Azmayesh/UpdateTest.php b/tests/Feature/V3/Azmayesh/UpdateTest.php new file mode 100644 index 00000000..b20a0d8e --- /dev/null +++ b/tests/Feature/V3/Azmayesh/UpdateTest.php @@ -0,0 +1,309 @@ +create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id])); + + $response->assertUnprocessable() + ->assertInvalid([ + 'lat' => __('validation.required', ['attribute' => 'طول جغرافیایی']) + ]); + } + + public function test_lat_attribute_should_be_string(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'lat' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'lat' => __('validation.string', ['attribute' => 'طول جغرافیایی']) + ]); + } + + public function test_lng_attribute_is_required(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id])); + + $response->assertUnprocessable() + ->assertInvalid([ + 'lng' => __('validation.required', ['attribute' => 'عرض جغرافیایی']) + ]); + } + + public function test_lng_attribute_should_be_string(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'lng' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'lng' => __('validation.string', ['attribute' => 'عرض جغرافیایی']) + ]); + } + + public function test_azmayesh_type_id_attribute_is_required(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id])); + + $response->assertUnprocessable() + ->assertInvalid([ + 'azmayesh_type_id' => __('validation.required', ['attribute' => 'نوع آزمایش']) + ]); + } + + public function test_azmayesh_type_id_attribute_should_exist_on_azmayesh_types_table(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'azmayesh_type_id' => $this->faker->numberBetween(10, 100) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'azmayesh_type_id' => __('validation.exists', ['attribute' => 'نوع آزمایش']) + ]); + } + + public function test_request_date_attribute_should_be_date_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'request_date' => $this->faker->lexify + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'request_date' => __('validation.date', ['attribute' => 'تاریخ درخواست']) + ]); + } + + public function test_report_date_attribute_should_be_date_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'report_date' => $this->faker->lexify + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'report_date' => __('validation.date', ['attribute' => 'تاریخ گزارش']) + ]); + } + + public function test_request_number_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'request_number' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'request_number' => __('validation.string', ['attribute' => 'شماره درخواست']) + ]); + } + + public function test_employer_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'employer' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'employer' => __('validation.string', ['attribute' => 'کارفرما']) + ]); + } + + public function test_contractor_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'contractor' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'contractor' => __('validation.string', ['attribute' => 'پیمانکار']) + ]); + } + + public function test_work_number_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'work_number' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'work_number' => __('validation.string', ['attribute' => 'شماره کار']) + ]); + } + + public function test_project_name_attribute_is_required(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id])); + + $response->assertUnprocessable() + ->assertInvalid([ + 'project_name' => __('validation.required', ['attribute' => 'نام پروژه']) + ]); + } + + public function test_project_name_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'project_name' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'project_name' => __('validation.string', ['attribute' => 'نام پروژه']) + ]); + } + + public function test_consultant_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'consultant' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'consultant' => __('validation.string', ['attribute' => 'مشاور']) + ]); + } + + public function test_applicant_attribute_should_be_string_type(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'applicant' => $this->faker->numberBetween(1, 10) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'applicant' => __('validation.string', ['attribute' => 'متقاضی']) + ]); + } + + public function test_province_id_attribute_is_required(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id])); + + $response->assertUnprocessable() + ->assertInvalid([ + 'province_id' => __('validation.required', ['attribute' => 'استان']) + ]); + } + + public function test_province_id_attribute_should_exists_on_province_table(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), [ + 'province_id' => $this->faker->numberBetween(10, 100) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'province_id' => __('validation.exists', ['attribute' => 'استان']) + ]); + } + + public function test_user_can_update_the_azmayesh(): void + { + $user = User::factory()->create(); + $province = Province::factory()->create(); + $azmayeshType = AzmayeshType::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $data = [ + 'lat' => $this->faker->numerify, + 'lng' => $this->faker->numerify, + 'azmayesh_type_id' => $azmayeshType->id, + 'request_date' => $this->faker->date, + 'report_date' => $this->faker->date, + 'request_number' => $this->faker->numerify, + 'employer' => $this->faker->name, + 'contractor' => $this->faker->name, + 'work_number' => $this->faker->numerify, + 'project_name' => $this->faker->name, + 'consultant' => $this->faker->name, + 'applicant' => $this->faker->name, + 'province_id' => $province->id, + ]; + + $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.update', [$azmayesh->id]), $data); + + $response->assertOk() + ->assertExactJson([ + 'message' => __('messages.successful') + ]); + } +} diff --git a/tests/Feature/V3/AzmayeshSample/DeleteTest.php b/tests/Feature/V3/AzmayeshSample/DeleteTest.php new file mode 100644 index 00000000..ac901f6e --- /dev/null +++ b/tests/Feature/V3/AzmayeshSample/DeleteTest.php @@ -0,0 +1,32 @@ +create(); + $azmayeshSample = AzmayeshSample::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.delete', [$azmayeshSample->id])); + + $response->assertOk(); + + $this->assertDatabaseMissing('azmayesh_samples', [ + 'azmayesh_id' => $azmayeshSample->azmayesh_id, + 'data' => $azmayeshSample->data, + ]); + } +} diff --git a/tests/Feature/V3/AzmayeshSample/IndexTest.php b/tests/Feature/V3/AzmayeshSample/IndexTest.php new file mode 100644 index 00000000..4a447d99 --- /dev/null +++ b/tests/Feature/V3/AzmayeshSample/IndexTest.php @@ -0,0 +1,86 @@ +create(); + + Azmayesh::factory(5) + ->sequence( + ['id' => 1], + ['id' => 2], + ['id' => 3], + ['id' => 4], + ['id' => 5] + ) + ->create(); + + AzmayeshSample::factory(5) + ->sequence( + [ + 'azmayesh_id' => 1, + 'azmayesh_project_name' => $this->faker->name, + 'data' => json_encode([$this->faker->numerify]), + ], + [ + 'azmayesh_id' => 2, + 'azmayesh_project_name' => $this->faker->name, + 'data' => json_encode([$this->faker->numerify]), + ], + [ + 'azmayesh_id' => 3, + 'azmayesh_project_name' => $this->faker->name, + 'data' => json_encode([$this->faker->numerify]), + ], + [ + 'azmayesh_id' => 4, + 'azmayesh_project_name' => $this->faker->name, + 'data' => json_encode([$this->faker->numerify]), + ], + [ + 'azmayesh_id' => 1, + 'azmayesh_project_name' => $this->faker->name, + 'data' => json_encode([$this->faker->numerify]), + ], + ) + ->create(); + + $response = $this->actingAs($user)->getJson(route('v3.azmayesh_samples.index', [ + 1, + 'start' => 0, + 'size' => 10, + 'filters' => json_encode([]), + 'sorting' => json_encode([]), + ])); + + $response->assertOk(); + + $response->assertJsonStructure([ + 'data' => [ + '*' => [ + 'id', + 'azmayesh_id', + 'azmayesh_project_name', + 'data', + ], + ], + "meta" => [ + "totalRowCount" + ] + ]); + } +} diff --git a/tests/Feature/V3/AzmayeshSample/StoreTest.php b/tests/Feature/V3/AzmayeshSample/StoreTest.php new file mode 100644 index 00000000..28a6e1e0 --- /dev/null +++ b/tests/Feature/V3/AzmayeshSample/StoreTest.php @@ -0,0 +1,79 @@ +create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'azmayesh_id' => __('validation.required', ['attribute' => 'آزمایش']) + ]); + } + + public function test_azmayesh_id_attribute_should_exists_on_azmayeshes_table(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.store'), [ + 'azmayesh_id' => $this->faker->numberBetween(10, 100) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'azmayesh_id' => __('validation.exists', ['attribute' => 'آزمایش']) + ]); + } + + public function test_data_attribute_is_required(): void + { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.store')); + + $response->assertUnprocessable() + ->assertInvalid([ + 'data' => __('validation.required', ['attribute' => 'داده']) + ]); + } + + public function test_user_can_store_a_new_azmayesh_sample(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + + $data = [ + 'azmayesh_id' => $azmayesh->id, + 'data' => json_encode([$this->faker->numerify]), + ]; + + $response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.store'), $data); + + $response->assertOk() + ->assertExactJson([ + 'message' => __('messages.successful') + ]); + + $this->assertDatabaseHas('azmayesh_samples', [ + 'azmayesh_id' => $data['azmayesh_id'], + 'data' => $data['data'], + ]); + } +} diff --git a/tests/Feature/V3/AzmayeshSample/UpdateTest.php b/tests/Feature/V3/AzmayeshSample/UpdateTest.php new file mode 100644 index 00000000..c79fef01 --- /dev/null +++ b/tests/Feature/V3/AzmayeshSample/UpdateTest.php @@ -0,0 +1,82 @@ +create(); + $azmayeshSample = AzmayeshSample::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.update', [$azmayeshSample->id])); + + $response->assertUnprocessable() + ->assertInvalid([ + 'azmayesh_id' => __('validation.required', ['attribute' => 'آزمایش']) + ]); + } + + public function test_azmayesh_id_attribute_should_exists_on_azmayeshes_table(): void + { + $user = User::factory()->create(); + $azmayeshSample = AzmayeshSample::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.update', [$azmayeshSample->id]), [ + 'azmayesh_id' => $this->faker->numberBetween(10, 100) + ]); + + $response->assertUnprocessable() + ->assertInvalid([ + 'azmayesh_id' => __('validation.exists', ['attribute' => 'آزمایش']) + ]); + } + + public function test_data_attribute_is_required(): void + { + $user = User::factory()->create(); + $azmayeshSample = AzmayeshSample::factory()->create(); + + $response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.update', [$azmayeshSample->id])); + + $response->assertUnprocessable() + ->assertInvalid([ + 'data' => __('validation.required', ['attribute' => 'داده']) + ]); + } + + public function test_user_can_update_the_azmayesh_sample(): void + { + $user = User::factory()->create(); + $azmayesh = Azmayesh::factory()->create(); + $azmayeshSample = AzmayeshSample::factory()->create(); + + $data = [ + 'azmayesh_id' => $azmayesh->id, + 'data' => json_encode([$this->faker->numerify]), + ]; + + $response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.update', [$azmayeshSample->id]), $data); + + $response->assertOk() + ->assertExactJson([ + 'message' => __('messages.successful') + ]); + + $this->assertDatabaseHas('azmayesh_samples', [ + 'azmayesh_id' => $data['azmayesh_id'], + 'data' => $data['data'], + ]); + } +} diff --git a/tests/Feature/V3/AzmayeshType/FieldsTest.php b/tests/Feature/V3/AzmayeshType/FieldsTest.php new file mode 100644 index 00000000..c6e5f7c4 --- /dev/null +++ b/tests/Feature/V3/AzmayeshType/FieldsTest.php @@ -0,0 +1,64 @@ +sequence( + [ + 'id' => 1, + 'name' => $this->faker->name, + 'unit' => $this->faker->name, + 'type' => $this->faker->name, + ], + [ + 'id' => 2, + 'name' => $this->faker->name, + 'unit' => $this->faker->name, + 'type' => $this->faker->name, + ], + [ + 'id' => 3, + 'name' => $this->faker->name, + 'unit' => $this->faker->name, + 'type' => $this->faker->name, + ], + ) + ->create(); + + $azmayeshType = AzmayeshType::factory()->create(); + + $azmayeshType->azmayeshFields()->attach(1); + + $user = User::factory()->create(); + + $response = $this->actingAs($user)->getJson(route('v3.azmayesh_types.fields', [$azmayeshType->id])); + + $response->assertOk(); + + $response->assertJsonStructure([ + 'data' => [ + '*' => [ + 'name', + 'unit', + 'type', + 'option' + ], + ] + ]); + } +} diff --git a/tests/Feature/V3/AzmayeshType/IndexTest.php b/tests/Feature/V3/AzmayeshType/IndexTest.php new file mode 100644 index 00000000..e96695f2 --- /dev/null +++ b/tests/Feature/V3/AzmayeshType/IndexTest.php @@ -0,0 +1,35 @@ +create(); + + $user = User::factory()->create(); + + $response = $this->actingAs($user)->getJson(route('v3.azmayesh_types.index')); + + $response->assertOk(); + + $response->assertJsonStructure([ + 'data' => [ + '*' => [ + 'name', + ], + ] + ]); + } +}