Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hamde7 committed May 6, 2024
2 parents 61ae890 + ed20583 commit ea57290
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 73 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
|The students are: | |
|--|--|
| 1. Mohammed Al-Akhras | 4. Hamdi Diab |
| 3. Baraa Berkdar | 5. Abdul Mohaimen Safaf |
|2. Aghiad Elwan Al-Hamwi | |
| 2. Baraa Berkdar | 5. Abdul Mohaimen Safaf |
|3. Aghiad Elwan Al-Hamwi | |

</div>

Expand Down
16 changes: 16 additions & 0 deletions back-end/app/Http/Controllers/CityController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\City;
use App\Trait\responseTrait;
class CityController extends Controller
{
use responseTrait;
public function index(){
$cites = City::all();
return $this->returnData('data',$cites);
}

}
37 changes: 28 additions & 9 deletions back-end/app/Http/Controllers/Doctor/DoctorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,34 @@ public function update(Request $request)
}


public function addReply(Request $request, Question $qustion){
$qustion->has_replys()->create([
"reply" =>$request->reply,
"date" =>date("y:m:h"),
"time" =>now(),
"qusation_id" =>$qustion->id,
"doctor_name" => auth('doctor')->user()->full_name
]);
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;

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

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

} elseif (auth('pation')->user()) {

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

}
else {
return $this->returnError(401, "Unauthorized");
}

} else {
return $this->returnError(401, "Unauthorized");
}
return $this->returnSucess(200, "تم ارسال الرد ");
}


Expand Down
63 changes: 36 additions & 27 deletions back-end/app/Http/Controllers/Pation/Operation/PationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
use DB;
use App\Http\Requests\Pation\{
StorePAtionRequest,
UpdatePationRequest
UpdatePationRequest,
SearchDoctorRequest
};
use App\Models\Doctor;

class PationController extends Controller
{

use responseTrait,uplodeImages;
use responseTrait, uplodeImages;
public function register(StorePAtionRequest $request)
{

$request1 = $request->except('password');
$request1['password'] = bcrypt($request->password);
$pation = Pation::create($request1);
Expand All @@ -34,35 +37,41 @@ public function update(UpdatePationRequest $request)
$pation_id = auth()->user()->id;
$pation = Pation::find($pation_id);
if ($pation) {
return DB::transaction(function () use ($request,$pation) {
$pation->update($request->except(['profile_image','cover_image']));
if($request->hasFile('profile_image')){
$old_profile_image = $pation->image()->where('type',1)->pluck('image_name');
$pation->image()->where('type',1)->delete();
// Uplode To Serve
$image_name=$this->saveImages([$request->profile_image],"Pation")[0];
$pation->image()->where('type',1)->updateOrCreate(['image_name'=>$image_name,"type"=>1]);
$this->deleteImages($old_profile_image,'Pation');
}
if($request->hasFile('cover_image')){
$old_cover_image = $pation->image()->where('type',2)->pluck('image_name');
$pation->image()->where('type',2)->delete();
// Uplode To Serve
$image_name=$this->saveImages([$request->cover_image],"Pation")[0];
$pation->image()->where('type',2)->updateOrCreate(['image_name'=>$image_name,"type"=>"2"]);
$this->deleteImages($old_cover_image,'Pation');
}
return $this->returnSucess('200', "تم تعديل البيانات بنجاح");
});
return DB::transaction(function () use ($request, $pation) {
$pation->update($request->except(['profile_image', 'cover_image']));
if ($request->hasFile('profile_image')) {
$old_profile_image = $pation->image()->where('type', 1)->pluck('image_name');
$pation->image()->where('type', 1)->delete();
// Uplode To Serve
$image_name = $this->saveImages([$request->profile_image], "Pation")[0];
$pation->image()->where('type', 1)->updateOrCreate(['image_name' => $image_name, "type" => 1]);
$this->deleteImages($old_profile_image, 'Pation');
}
if ($request->hasFile('cover_image')) {
$old_cover_image = $pation->image()->where('type', 2)->pluck('image_name');
$pation->image()->where('type', 2)->delete();
// Uplode To Serve
$image_name = $this->saveImages([$request->cover_image], "Pation")[0];
$pation->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', "المريض غير موجود ");
}
}

public function getInformation(){
$pation_id=auth()->user()->id;
$pation=Pation::with('has_diseases')->find($pation_id);
return $this->returnData("pation",$pation);
public function getInformation()
{
$pation_id = auth()->user()->id;
$pation = Pation::with('has_diseases')->find($pation_id);
return $this->returnData("pation", $pation);
}

public function search(SearchDoctorRequest $request)
{
$doctors = Doctor::with('specialazation')->filter($request->query())->get();
return $this->returnData('data', $doctors);
}
}
7 changes: 5 additions & 2 deletions back-end/app/Http/Controllers/Qustion/QustionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ class QustionController extends Controller

public function index()
{
$qustions = Question::with('has_replys')->get();
$qustions = Question::with('has_replys')->where('pation_id',auth()->user()->id)->get();
return $this->returnData('data', $qustions);
}

public function show(Question $qustion){
return $this->returnData("data",$qustion->with('has_replys')->get());
}

public function store(StoreQustionContrller $request)
{
// return $request->specializations;
return DB::transaction(function () use ($request) {
$pation_id = auth()->user()->id;
$images = $request->images;
Expand Down
15 changes: 15 additions & 0 deletions back-end/app/Http/Controllers/SpecilazationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Http\Controllers;

use App\Models\Specialization;
use Illuminate\Http\Request;
use App\Trait\responseTrait;
class SpecilazationController extends Controller
{
use responseTrait;
public function index(){
$spes= Specialization::all();
return $this->returnData('data',$spes);
}
}
36 changes: 36 additions & 0 deletions back-end/app/Http/Requests/Pation/SearchDoctorRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Http\Requests\Pation;

use Illuminate\Foundation\Http\FormRequest;
use App\Trait\responseTrait;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;

class SearchDoctorRequest extends FormRequest
{
use responseTrait;
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
*/
public function rules(): array
{
return [
"city_id" =>"exists:cites,id",
"spec_id" =>"exists:specializations,id"
];
}

public function failedValidation(Validator $validator)
{
$errors = $validator->errors();
throw new HttpResponseException($this->returnError(422, $errors->first()));
}
}
1 change: 1 addition & 0 deletions back-end/app/Models/City.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class City extends Model
{

protected $table = 'cites';
public $hidden=['created_at','updated_at','country_id'];
public $timestamps = true;

public function has_pation()
Expand Down
25 changes: 23 additions & 2 deletions back-end/app/Models/Doctor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Builder;

use Illuminate\Database\Eloquent\Factories\HasFactory;

class Doctor extends Authenticatable implements JWTSubject
Expand All @@ -15,7 +17,7 @@ class Doctor extends Authenticatable implements JWTSubject
protected $table = 'doctors';
public $timestamps = true;
public $guarded = [];
public $hidden = ['password', 'created_at', 'updated_at'];
public $hidden = ['password', 'created_at', 'updated_at','SSN','Bdate','activated','blocked','city_id','spec_id','father','mother'];
protected $appends = ['profile', 'cover', 'city'];

public function has_appointment()
Expand All @@ -31,6 +33,9 @@ public function hasCity()
return $this->belongsTo("App\Models\City", "city_id");
}

public function specialazation(){
return $this->belongsTo('App\Models\Specialization','spec_id');
}
public function getProfileAttribute()
{
$image = $this->image()->where('type', 1)->get(['image_name', 'imageable_type']);
Expand All @@ -44,7 +49,7 @@ public function getProfileAttribute()
public function getCoverAttribute()
{
$image = $this->image()->where('type', 2)->get(['image_name', 'imageable_type']);

if (count($image) > 0) {
$image = $image[0];
$model = explode('\\', $image->imageable_type);
Expand All @@ -58,6 +63,22 @@ public function getCityAttribute()
}


public function scopeFilter(Builder $q,$filters)
{
$options= array_merge([
"spec_id" =>null,
"city_id" =>null
],$filters);

$q->when($options['spec_id'],function ($q,$value){
$q->where('spec_id',$value);
});
$q->when($options['city_id'],function ($q,$value){
$q->where('city_id',$value);
})
->get();
}


public function getJWTIdentifier()
{
Expand Down
4 changes: 4 additions & 0 deletions back-end/app/Models/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public function has_replys()
{
return $this->hasMany('App\Models\Replie', 'qusation_id');
}
public function pation()
{
return $this->belongsTo('App\Models\Pation','pation_id');
}

public function image()
{
Expand Down
Binary file added back-end/public/Question/65fe6b4941adf_749.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions back-end/routes/Doctor/doctor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
->middleware('auth:doctor')
->group(function () {
Route::post('update' , "update");
Route::get('information' ,'getInformation');
Route::post('add/reply/{qustion}' ,"addReply");

Route::get('information' ,'getInformation');
});
Route::post('add/reply/{qustion}' ,[DoctorController::class,"addReply"]);
2 changes: 2 additions & 0 deletions back-end/routes/Pation/pation.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
Route::post('update' , [PationController::class,'update']);
Route::get('information' , [PationController::class,'getInformation']);
Route::post('add/chronic_dseases',[ChronicPationContrller::class,"addChronic"]);
Route::post('search/doctor',[PationController::class, "search"]);

});
50 changes: 22 additions & 28 deletions back-end/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,25 @@



// Auth Api

include __DIR__ ."/Auth/auth.php";


// Admin APi
include __DIR__ ."/Admin/admin.php";

// Pation Route
include __DIR__ .'/Pation/pation.php';
// Qustion Api

include __DIR__ ."/Qustion/qustion.php";


// Admin Api

include __DIR__ .'/Doctor/doctor.php';


// Appointment Api

include __DIR__ .'/Appointment/appointment.php';

Route::get("specializations/all",function (){
$Specializations=Specialization::all();
return response()->json(["status"=>"true","data"=>$Specializations],200);
});
// Auth Api
include __DIR__ . "/Auth/auth.php";
// Admin APi
include __DIR__ . "/Admin/admin.php";
// Pation Route
include __DIR__ . '/Pation/pation.php';
// Qustion Api
include __DIR__ . "/Qustion/qustion.php";
// Admin Api
include __DIR__ . '/Doctor/doctor.php';
// Appointment Api
include __DIR__ . '/Appointment/appointment.php';

// City Api
include __DIR__ ."/city.php";

// Specilazations Api
include __DIR__ ."/specilazations.php";
Route::get("specializations/all", function () {
$Specializations = Specialization::all();
return response()->json(["status" => "true", "data" => $Specializations], 200);
});
10 changes: 10 additions & 0 deletions back-end/routes/city.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\CityController;
use App\Models\City;

Route::apiResource('cites', CityController::class)->middleware('auth:admin')->except('index');

Route::get('cites',[CityController::class,'index']);
Loading

0 comments on commit ea57290

Please sign in to comment.