change the migration columns and add form request

This commit is contained in:
2024-11-03 06:26:26 +00:00
parent e9098b0a55
commit 1a15a5d7ed
16 changed files with 444 additions and 66 deletions

View File

@@ -10,6 +10,8 @@ use App\Models\AzmayeshType;
use App\Models\Province;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Http\Requests\V3\Azmayesh\StoreRequest;
use App\Http\Requests\V3\Azmayesh\UpdateRequest;
class AzmayeshController extends Controller
{
@@ -48,27 +50,27 @@ class AzmayeshController extends Controller
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): JsonResponse
public function store(StoreRequest $request): JsonResponse
{
$azmayeshType = AzmayeshType::query()->find($request->azmayesh_type_id);
$province = Province::query()->find($request->province_id);
$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->lat,
'report_date' => $request->lat,
'request_number' => $request->lat,
'employer' => $request->lat,
'contractor' => $request->lat,
'work_number' => $request->lat,
'project_name' => $request->lat,
'consultant' => $request->lat,
'applicant' => $request->lat,
'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,
'province_name' => $province->name_fa,
]);
return $this->successResponse();
@@ -85,19 +87,27 @@ class AzmayeshController extends Controller
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Azmayesh $azmayesh): JsonResponse
public function update(UpdateRequest $request, Azmayesh $azmayesh): JsonResponse
{
$province = Province::query()->find($request->province_id);
$province = Province::query()->findOrFail($request->province_id);
$azmayeshType = AzmayeshType::query()->findOrFail($request->azmayesh_type_id);
$azmayesh->update([
'name' => $request->name,
'username' => $request->username,
'email' => $request->email,
'phone_number' => $request->phone_number,
'national_id' => $request->national_id,
'position' => $request->position,
'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,
'province_name' => $province->name_fa,
]);
return $this->successResponse();

View File

@@ -0,0 +1,90 @@
<?php
namespace App\Http\Controllers\V3\Azmayesh;
use App\Http\Controllers\Controller;
use App\Facades\DataTable\DataTableFacade;
use App\Http\Traits\ApiResponse;
use App\Models\Azmayesh;
use App\Models\AzmayeshType;
use App\Models\AzmayeshSample;
use App\Models\Province;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Http\Requests\V3\AzmayeshSample\StoreRequest;
use App\Http\Requests\V3\AzmayeshSample\UpdateRequest;
class AzmayeshSampleController extends Controller
{
use ApiResponse;
/**
* Display a listing of the resource.
*/
public function index(Request $request, string $azmayesh_id): JsonResponse
{
$columns = array(
'id',
);
$allowedFilters = $columns;
$allowedSortings = $columns;
$query = AzmayeshSample::query()->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)
{
$azmayeshSample->update([
'azmayesh_id' => $azmayesh->id,
'azmayesh_project_name' => $azmayesh->project_name,
'data' => json_encode($request->data),
]);
return $this->successResponse();
}
/**
* Remove the specified resource from storage.
*/
public function destroy(AzmayeshSample $azmayeshSample)
{
$azmayeshSample->delete();
return $this->successResponse();
}
}

View File

@@ -21,7 +21,7 @@ class AzmayeshTypeController extends Controller
public function fields(AzmayeshType $azmayeshType): JsonResponse
{
$fields = $azmayeshType->azmayeshFields;
$fields = $azmayeshType->azmayeshFields->select('id', 'name', 'unit', 'type', 'option');
return $this->successResponse($fields);
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Http\Requests\V3\Azmayesh;
use Illuminate\Foundation\Http\FormRequest;
class StoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|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',
];
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Http\Requests\V3\Azmayesh;
use Illuminate\Foundation\Http\FormRequest;
class UpdateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|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',
];
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Http\Requests\V3\AzmayeshSample;
use Illuminate\Foundation\Http\FormRequest;
class StoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'azmayesh_id' => 'required|exists:azmayeshes,id',
'data' => 'required',
];
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Http\Requests\V3\AzmayeshSample;
use Illuminate\Foundation\Http\FormRequest;
class UpdateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'azmayesh_id' => 'required|exists:azmayeshes,id',
'data' => 'required',
];
}
}

View File

@@ -5,6 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Casts\Attribute;
class AzmayeshField extends Model
{
@@ -12,8 +13,15 @@ class AzmayeshField extends Model
protected $guarded = [];
protected function option(): Attribute
{
return Attribute::make(
get: fn ($value) => json_decode($value),
);
}
public function azmayeshTypes(): BelongsToMany
{
return $this->belongsToMany(AzmayeshType::class);
return $this->belongsToMany(AzmayeshType::class, 'azmayesh_field_azmayesh_type');
}
}

View File

@@ -14,9 +14,9 @@ return new class extends Migration
Schema::create('azmayesh_fields', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('unit');
$table->string('unit')->nullable();
$table->string('type');
$table->string('option')->nullable();
$table->json('option')->nullable();
$table->timestamps();
});
}

View File

@@ -20,12 +20,12 @@ return new class extends Migration
$table->unsignedTinyInteger('province_id');
$table->foreign('province_id')->references('id')->on('provinces');
$table->string('province_name');
$table->date('request_date');
$table->date('report_date');
$table->integer('request_number');
$table->date('request_date')->nullable();
$table->date('report_date')->nullable();
$table->string('request_number');
$table->string('employer');
$table->string('contractor');
$table->integer('work_number');
$table->string('work_number');
$table->string('project_name');
$table->string('consultant');
$table->string('applicant');

View File

@@ -13,8 +13,8 @@ return new class extends Migration
{
Schema::create('azmayesh_samples', function (Blueprint $table) {
$table->id();
$table->foreignId('azmayesh_id')->constrained('azmayeshes');
$table->string('azmayesh_name');
$table->foreignId('azmayesh_id')->constrained('azmayeshes')->cascadeOnDelete();
$table->string('azmayesh_project_name');
$table->json('data');
$table->timestamps();
});

View File

@@ -32,6 +32,24 @@ class AzmayeshFieldSeeder extends Seeder
'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()
],
]);
}
}

View File

@@ -17,10 +17,8 @@ class AzmayeshSampleSeeder extends Seeder
DB::table('azmayesh_samples')->insert([
[
'id' => 1,
'azmayesh_id' => Azmayesh::factory(),
'azmayesh_name' => function (array $attributes) {
return Azmayesh::query()->find($attributes['azmayesh_id'])->name;
},
'azmayesh_id' => 1,
'azmayesh_project_name' => 'اجرای پروژه پل میرزای شیرازی شریفیه',
'data' => json_encode([
1 => 'test'
]),

View File

@@ -16,41 +16,121 @@ class AzmayeshSeeder extends Seeder
DB::table('azmayeshes')->insert([
[
'id' => 1,
'lat' => '13.45',
'lng' => '11.85',
'lat' => '36.2816000000',
'lng' => '50.0153000000',
'azmayesh_type_id' => 1,
'azmayesh_type_name' => 'test',
'province_id' => 11,
'province_name' => 'test',
'request_date' => '1403-07-04',
'report_date' => '1403-07-05',
'request_number' => 0,
'employer' => 'test',
'contractor' => 'test',
'work_number' => 0,
'project_name' => 'test',
'consultant' => 'test',
'applicant' => 'test',
'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' => '13.45',
'lng' => '11.85',
'azmayesh_type_id' => 1,
'azmayesh_type_name' => 'test',
'province_id' => 11,
'province_name' => 'test',
'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' => '0',
'employer' => 'test',
'contractor' => 'test',
'work_number' => '0',
'project_name' => 'test',
'consultant' => 'test',
'applicant' => 'test',
'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()
],

View File

@@ -20,6 +20,30 @@ class AzmayeshTypeSeeder extends Seeder
'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()
],
]);
}
}

View File

@@ -1,6 +1,7 @@
<?php
use App\Http\Controllers\V3\Azmayesh\AzmayeshController;
use App\Http\Controllers\V3\Azmayesh\AzmayeshSampleController;
use App\Http\Controllers\V3\Azmayesh\AzmayeshTypeController;
use App\Http\Controllers\V3\Harim\DivarkeshiController;
use App\Http\Controllers\V3\ProfileController;
@@ -36,14 +37,25 @@ Route::prefix('profile')
});
Route::prefix('azmayesh_types')
->name('azmayesh_types')
->name('azmayesh_types.')
->controller(AzmayeshTypeController::class)
->group(function () {
Route::get('/', 'index')->name('index');
Route::get('/fields/{azmayeshType}', 'fields')->name('fields');
});
Route::prefix('azmayeshes')
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 () {
@@ -51,5 +63,5 @@ Route::prefix('azmayeshes')
Route::get('/{azmayesh}', 'show')->name('show');
Route::post('/store', 'store')->name('store');
Route::post('/update/{azmayesh}', 'update')->name('update');
Route::post('/delete/{azmayesh}', 'delete')->name('delete');
Route::post('/delete/{azmayesh}', 'destroy')->name('delete');
});