Merge branch 'feature/AddColumnToAzmayeshTable' into 'develop'

Feature/add column to azmayesh table

See merge request witelgroup/rms_v2!38
This commit is contained in:
2024-12-02 07:28:09 +00:00
6 changed files with 71 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ use App\Http\Traits\ApiResponse;
use App\Models\Azmayesh; use App\Models\Azmayesh;
use App\Models\AzmayeshType; use App\Models\AzmayeshType;
use App\Models\Province; use App\Models\Province;
use Illuminate\Database\QueryException;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Requests\V3\Azmayesh\StoreRequest; use App\Http\Requests\V3\Azmayesh\StoreRequest;
@@ -34,7 +35,8 @@ class AzmayeshController extends Controller
'azmayesh_type_name', 'azmayesh_type_name',
'project_name', 'project_name',
'updated_at', 'updated_at',
'created_at' 'created_at',
'user_name'
); );
$allowedFilters = $columns; $allowedFilters = $columns;
@@ -58,6 +60,7 @@ class AzmayeshController extends Controller
{ {
$azmayeshType = AzmayeshType::query()->findOrFail($request->azmayesh_type_id); $azmayeshType = AzmayeshType::query()->findOrFail($request->azmayesh_type_id);
$province = Province::query()->findOrFail($request->province_id); $province = Province::query()->findOrFail($request->province_id);
$user = auth()->user();
Azmayesh::query()->create([ Azmayesh::query()->create([
'lat' => $request->lat, 'lat' => $request->lat,
@@ -75,6 +78,8 @@ class AzmayeshController extends Controller
'applicant' => $request->applicant ?? '-', 'applicant' => $request->applicant ?? '-',
'province_id' => $province->id, 'province_id' => $province->id,
'province_name' => $province->name_fa, 'province_name' => $province->name_fa,
'user_id' => $user->id,
'user_name' => $user->name,
]); ]);
return $this->successResponse(); return $this->successResponse();
@@ -122,8 +127,13 @@ class AzmayeshController extends Controller
*/ */
public function destroy(Azmayesh $azmayesh): JsonResponse public function destroy(Azmayesh $azmayesh): JsonResponse
{ {
$azmayesh->delete(); try {
$azmayesh->delete();
return $this->successResponse(); return $this->successResponse();
}
catch (QueryException $exception) {
return $this->errorResponse('can not be deleted');
}
} }
} }

View File

@@ -9,6 +9,7 @@ use App\Http\Requests\V3\AzmayeshType\UpdateRequest;
use App\Http\Traits\ApiResponse; use App\Http\Traits\ApiResponse;
use App\Models\AzmayeshField; use App\Models\AzmayeshField;
use App\Models\AzmayeshType; use App\Models\AzmayeshType;
use Illuminate\Database\QueryException;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@@ -109,8 +110,13 @@ class AzmayeshTypeController extends Controller
*/ */
public function destroy(AzmayeshType $azmayeshType): JsonResponse public function destroy(AzmayeshType $azmayeshType): JsonResponse
{ {
$azmayeshType->delete(); try {
$azmayeshType->delete();
return $this->successResponse(); return $this->successResponse();
}
catch (QueryException $exception) {
return $this->errorResponse('امکان حذف وجود ندارد. ابتدا آزمایش های مرتبط با این نوع را حذف نمایید');
}
} }
} }

View File

@@ -4,6 +4,7 @@ namespace Database\Factories;
use App\Models\AzmayeshType; use App\Models\AzmayeshType;
use App\Models\Province; use App\Models\Province;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
/** /**
@@ -38,6 +39,10 @@ class AzmayeshFactory extends Factory
'project_name' => $this->faker->name, 'project_name' => $this->faker->name,
'consultant' => $this->faker->name, 'consultant' => $this->faker->name,
'applicant' => $this->faker->name, 'applicant' => $this->faker->name,
'user_id' => User::factory(),
'user_name' => function (array $attributes) {
return User::query()->find($attributes['user_id'])->name;
},
]; ];
} }
} }

View File

@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('azmayeshes', function (Blueprint $table) {
$table->unsignedInteger('user_id')->nullable();
$table->foreign('user_id')->references('id')->on('users');
$table->string('user_name');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('azmayeshes', function (Blueprint $table) {
$table->dropColumn('user_id');
$table->dropColumn('user_name');
});
}
};

View File

@@ -31,6 +31,8 @@ class AzmayeshSeeder extends Seeder
'project_name' => 'اجرای پروژه پل میرزای شیرازی شریفیه', 'project_name' => 'اجرای پروژه پل میرزای شیرازی شریفیه',
'consultant' => '-', 'consultant' => '-',
'applicant' => 'شهرداری شریفیه', 'applicant' => 'شهرداری شریفیه',
'user_id' => 470,
'user_name' => 'اداره کل ستاد',
'created_at' => now(), 'created_at' => now(),
'updated_at' => now() 'updated_at' => now()
], ],
@@ -51,6 +53,8 @@ class AzmayeshSeeder extends Seeder
'project_name' => 'کنترل کیفی پروژه های اجرایی شهرداری الوند', 'project_name' => 'کنترل کیفی پروژه های اجرایی شهرداری الوند',
'consultant' => '-', 'consultant' => '-',
'applicant' => 'شهرداری الوند', 'applicant' => 'شهرداری الوند',
'user_id' => 470,
'user_name' => 'اداره کل ستاد',
'created_at' => now(), 'created_at' => now(),
'updated_at' => now() 'updated_at' => now()
], ],
@@ -71,6 +75,8 @@ class AzmayeshSeeder extends Seeder
'project_name' => 'کنترل کیفی پروژه های روستای ولدآباد', 'project_name' => 'کنترل کیفی پروژه های روستای ولدآباد',
'consultant' => '-', 'consultant' => '-',
'applicant' => 'بنیاد مسکن استان قزوین', 'applicant' => 'بنیاد مسکن استان قزوین',
'user_id' => 470,
'user_name' => 'اداره کل ستاد',
'created_at' => now(), 'created_at' => now(),
'updated_at' => now() 'updated_at' => now()
], ],
@@ -91,6 +97,8 @@ class AzmayeshSeeder extends Seeder
'project_name' => 'نیوجرسی مفصلی جهت ایمن سازی آزادراه های قزوین-کرج و قزوین-زنجان', 'project_name' => 'نیوجرسی مفصلی جهت ایمن سازی آزادراه های قزوین-کرج و قزوین-زنجان',
'consultant' => '-', 'consultant' => '-',
'applicant' => 'اداره کل راهداری و حمل و نقل جاده ای استان قزوین', 'applicant' => 'اداره کل راهداری و حمل و نقل جاده ای استان قزوین',
'user_id' => 470,
'user_name' => 'اداره کل ستاد',
'created_at' => now(), 'created_at' => now(),
'updated_at' => now() 'updated_at' => now()
], ],
@@ -111,6 +119,8 @@ class AzmayeshSeeder extends Seeder
'project_name' => 'احداث راه های دسترسی مجتمع خدمات رفاهی حوزه آبیک-مجتمع آقای کلانی', 'project_name' => 'احداث راه های دسترسی مجتمع خدمات رفاهی حوزه آبیک-مجتمع آقای کلانی',
'consultant' => '-', 'consultant' => '-',
'applicant' => 'اداره کل راهداری و حمل و نقل جاده ای استان قزوین', 'applicant' => 'اداره کل راهداری و حمل و نقل جاده ای استان قزوین',
'user_id' => 470,
'user_name' => 'اداره کل ستاد',
'created_at' => now(), 'created_at' => now(),
'updated_at' => now() 'updated_at' => now()
], ],
@@ -131,6 +141,8 @@ class AzmayeshSeeder extends Seeder
'project_name' => 'آماده سازی محوطه دپوی سیلو کارخانه قند قزوین', 'project_name' => 'آماده سازی محوطه دپوی سیلو کارخانه قند قزوین',
'consultant' => '-', 'consultant' => '-',
'applicant' => 'شرکت سهامی عام کارخانجات قند قزوین', 'applicant' => 'شرکت سهامی عام کارخانجات قند قزوین',
'user_id' => 470,
'user_name' => 'اداره کل ستاد',
'created_at' => now(), 'created_at' => now(),
'updated_at' => now() 'updated_at' => now()
], ],

View File

@@ -386,6 +386,8 @@ class StoreTest extends TestCase
'consultant' => $data['consultant'], 'consultant' => $data['consultant'],
'applicant' => $data['applicant'], 'applicant' => $data['applicant'],
'province_id' => $data['province_id'], 'province_id' => $data['province_id'],
'user_id' => $user->id,
'user_name' => $user->name,
]); ]);
} }
} }