Skip to content

Commit

Permalink
after edit appointments
Browse files Browse the repository at this point in the history
  • Loading branch information
BaraaBerkdar committed Jun 18, 2024
1 parent 06bc9b0 commit e868aea
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class AppointmentController extends Controller
use responseTrait;
// تخزين موعد لمريض
public function store(Request $request){

$appointment=Appointment::create([
"doctor_id" =>$request->doctor_id,
"time" =>$request->time,
"date" =>$request->date,
"pation_id" =>auth()->user()->id
"pation_id" =>auth()->user()->id,
"ReqInfo" =>$request->optinal_info
]);
if($appointment){
return $this->returnSucess("200","تم اضافة الموعد بجاح ");
Expand Down
78 changes: 37 additions & 41 deletions back-end/app/Http/Controllers/Doctor/DoctorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,59 +27,55 @@ public function register(StoreDoctorRequest $request)

public function update(Request $request)
{
$doctor_id = $request->user()->id;
$doctor = Doctor::find($doctor_id);
if ($doctor) {
return DB::transaction(function () use ($request, $doctor) {
$doctor->update($request->except(['profile_image', 'cover_image']));
if ($request->hasFile('profile_image')) {
$old_profile_image = $doctor->image()->where('type', 1)->pluck('image_name');
$doctor->image()->where('type', 1)->delete();
// Uplode To Serve
$image_name = $this->saveImages([$request->profile_image], "Doctor")[0];
$doctor->image()->where('type', 1)->updateOrCreate(['image_name' => $image_name, "type" => 1]);
$this->deleteImages($old_profile_image, 'Doctor');
}
if ($request->hasFile('cover_image')) {
$old_cover_image = $doctor->image()->where('type', 2)->pluck('image_name');
$doctor->image()->where('type', 2)->delete();
// Uplode To Serve
$image_name = $this->saveImages([$request->cover_image], "Doctor")[0];
$doctor->image()->where('type', 2)->updateOrCreate(['image_name' => $image_name, "type" => "2"]);
$this->deleteImages($old_cover_image, 'Pation');
}
return $this->returnSucess('200', "تم تعديل البيانات بنجاح");
});
} else {
return $this->returnError('201', "الدكتور غير موجود ");
}
// $doctor_id = $request->user()->id;
$doctor = Doctor::find($request->user()->id);
return DB::transaction(function () use ($request, $doctor) {
$doctor->update($request->except(['profile_image', 'cover_image']));
if ($request->hasFile('profile_image')) {
$old_profile_image = $doctor->image()->where('type', 1)->pluck('image_name');
$doctor->image()->where('type', 1)->delete();
// Uplode To Serve
$image_name = $this->saveImages([$request->profile_image], "Doctor")[0];
$doctor->image()->where('type', 1)->updateOrCreate(['image_name' => $image_name, "type" => 1]);
$this->deleteImages($old_profile_image, 'Doctor');
}
if ($request->hasFile('cover_image')) {
$old_cover_image = $doctor->image()->where('type', 2)->pluck('image_name');
$doctor->image()->where('type', 2)->delete();
// Uplode To Serve
$image_name = $this->saveImages([$request->cover_image], "Doctor")[0];
$doctor->image()->where('type', 2)->updateOrCreate(['image_name' => $image_name, "type" => "2"]);
$this->deleteImages($old_cover_image, 'Pation');
}
return $this->returnSucess('200', "تم تعديل البيانات بنجاح");
});
}


public function addReply(Request $request, Question $qustion)
{
$data = [];
$data['reply'] = $request->reply;
$data['date'] = date('y:m:h');
$data['time'] = now();
$data['qusation_id'] = $qustion->id;
$request->merge([
"date" => date('y:m:h'),
"time" => now(),
"qusation_id" => $qustion->id
]);
// $data = [];
// $data['reply'] = $request->reply;
// $data['date'] = date('y:m:h');
// $data['time'] = now();
// $data['qusation_id'] = $qustion->id;

if (auth('doctor')->user()) {

$data['doctor_name'] = auth('doctor')->user()->full_name;
$qustion->has_replys()->create($data);


$request->merge(['doctor_name' => auth('doctor')->user()->full_name]);
$qustion->has_replys()->create($request->all());
} elseif (auth('pation')->user()) {

$pation_id = $qustion->pation->id;
if (auth('pation')->user()->id == $pation_id) {
$qustion->has_replys()->create($data);

}
else {
$qustion->has_replys()->create($request->all());
} else {
return $this->returnError(401, "Unauthorized");
}

} else {
return $this->returnError(401, "Unauthorized");
}
Expand Down
6 changes: 6 additions & 0 deletions back-end/app/Http/Controllers/Qustion/QustionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public function index()
return $this->returnData('data', $qustions);
}

public function allQustion(Request $request){
$qustions = Question::filter($request->filter)->get();
return $this->returnData('data', $qustions);

}

public function show(Question $qustion){
return $this->returnData("data",$qustion->with('has_replys')->get());
}
Expand Down
4 changes: 2 additions & 2 deletions back-end/app/Http/Middleware/ComplateInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class ComplateInformation

public function handle(Request $request, Closure $next): Response
{
$user = auth()->user()->mobile;
if(!empty($user))
$user = auth()->user();
if(!empty($user->mobile))
return $next($request);
else{
return $this->returnError("401","يجب اكمال معلوماتك الشخصضية اولا ");
Expand Down
6 changes: 6 additions & 0 deletions back-end/app/Models/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public function image()
public function scopeNotDoctorReply(Builder $query){
$query->whereDoesntHave('has_replys')->get();
}
public function scopeFilter(Builder $query ,$filter){
if(!isset($filter)){$filter = null;}
$query->when($filter , function($query) use ($filter){
$query->where('message','LIKE',"%$filter%");
});
}

public function getSpecializationsAttribute($val){
return $val=unserialize($val);
Expand Down
17 changes: 8 additions & 9 deletions back-end/app/Trait/uplodeImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ trait uplodeImages
public function saveImages($images, $path)
{
for ($i = 0; $i < count($images); $i++) {
$names[] = uniqid() . '_' . rand(1, 1000) .'.'. $images[$i]->getClientOriginalExtension();
$images[$i]->storeAs($path,$names[$i]);
$names[] = uniqid() . '_' . rand(1, 1000) . '.' . $images[$i]->getClientOriginalExtension();
$images[$i]->storeAs($path, $names[$i]);
}
return $names;
}

public function deleteImages($images,$path){

foreach ($images as $image){

unlink(public_path($path."/".$image));
public function deleteImages($images, $path)
{
if (count($images) > 0) {
foreach ($images as $image) {
unlink(public_path($path . "/" . $image));
}
}

}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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('appointments', function (Blueprint $table) {
$table->date('date')->nullable()->change();
$table->time('time')->nullable()->change();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('appointments', function (Blueprint $table) {
$table->date('date');
$table->time('time');
});
}
};
Binary file added back-end/public/Doctor/664242f90ee13_977.jfif
Binary file not shown.
2 changes: 1 addition & 1 deletion back-end/routes/Appointment/appointment.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Http\Controllers\Appointment\AppointmentController;


Route::group(["middleware"=>["auth.api:pation",'competInfo']],function(){
Route::group(["middleware"=>["auth:pation",'competInfo']],function(){

Route::apiResource('appointments' ,AppointmentController::class);
Route::get('get/appointments' ,[AppointmentController::class,'getAppointmentPAtion']);
Expand Down
4 changes: 2 additions & 2 deletions back-end/routes/Doctor/doctor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

Route::controller(DoctorController::class)
->prefix('doctor')
->middleware('auth:doctor')
->middleware('auth:doctor','competInfo')
->group(function () {
Route::post('update' , "update");
Route::get('information' ,'getInformation');
Route::post('add/reply/{qustion}' ,[DoctorController::class,"addReply"]);
});
Route::post('add/reply/{qustion}' ,[DoctorController::class,"addReply"]);
1 change: 0 additions & 1 deletion back-end/routes/Pation/pation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
Route::get('information' , [PationController::class,'getInformation']);
Route::post('add/chronic_dseases',[ChronicPationContrller::class,"addChronic"]);
Route::post('search/doctor',[PationController::class, "search"]);

});
11 changes: 6 additions & 5 deletions back-end/routes/Qustion/qustion.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
use App\Http\Controllers\Qustion\QustionController;


Route::group(["middleware"=>"auth:pation"],function(){
Route::group(["middleware" => "auth:pation"], function () {

Route::apiResource('qustions',QustionController::class);
Route::get('incress/{id}' ,[QustionController::class,"incresView"]);
Route::get('qustion/famus' ,[QustionController::class, 'getFamus']);
});
Route::apiResource('qustions', QustionController::class);
Route::get('incress/{id}', [QustionController::class, "incresView"]);
Route::get('qustion/famus', [QustionController::class, 'getFamus']);
Route::get('qustion/all', [QustionController::class, 'allQustion']);
});

0 comments on commit e868aea

Please sign in to comment.