Skip to content

Commit

Permalink
tobecci tasks 14,15,16
Browse files Browse the repository at this point in the history
  • Loading branch information
tobecci committed Oct 31, 2019
1 parent a652755 commit cd9bd18
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 162 deletions.
82 changes: 41 additions & 41 deletions app/Http/Controllers/EstateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public function index()
$res['status'] = fasle;
$res['message'] = 'No Record found';
return response()->json($res, 404);
}
}
}
// Display Estates by name

// Display Estates by name
public function name($name)
{
$country = ucfirst($name);
Expand All @@ -41,13 +41,13 @@ public function name($name)
//Error Handling
$res['status'] = false;
$res['message'] = 'No Estates found';
return response()->json($res, 404);
return response()->json($res, 404);

}else{
$res['status'] = true;
$res['message'] = 'Data Found (By Name)';
$res['estates'] = $estates;
return response()->json($res, 200);
return response()->json($res, 200);
}
}

Expand All @@ -62,36 +62,36 @@ public function search($info)
//Error Handling
$res['status'] = false;
$res['message'] = 'No Estates found';
return response()->json($res, 404);
return response()->json($res, 404);

}else{
$res['status'] = true;
$res['message'] = 'Data Found (By Name)';
$res['estates'] = $estates;
return response()->json($res, 200);
return response()->json($res, 200);
}
}
// Display Estates by Id
// Display Estates by Id

public function show($id)
{

$estate = Estate::where('id', $id)->first();
if (!$estate){
//Error Handling
$res['status'] = false;
$res['message'] = 'No Estate found';
return response()->json($res, 404);
return response()->json($res, 404);

}else{
$res['status'] = true;
$res['message'] = 'Data Found (By Name)';
$res['estate'] = $estate;
return response()->json($res, 200);
$res['estate'] = $estate;
return response()->json($res, 200);
}
}

// Display Estates by City
// Display Estates by City

public function showCity($city)
{
Expand All @@ -102,32 +102,32 @@ public function showCity($city)
$res['status'] = false;
$res['message'] = 'No Estates found';
return response()->json($res, 404);

}else{
$res['status'] = true;
$res['message'] = 'Data Found (By City)';
$res['estate'] = $estates;
$res['estate'] = $estates;
return response()->json($res, 200);
}
}
}

// Display Estates by Country
// Display Estates by Country

public function showCountry($country)
{
{
$country = ucfirst($country);
$estates = Estate::where('country', 'LIKE', "%{$country}%")->get();
if (!$estates){
// Error Handling
$res['Error'] = "No Estates found";
return response()->json($res, 404);
return response()->json($res, 404);
}else
$res['status'] = true;
$res['message'] = 'Data Found (By Country)';
$res['estate'] = $estates;
$res['estate'] = $estates;
return response()->json($res, 200);
}



public function store(Request $request, ImageController $image)
Expand All @@ -149,7 +149,7 @@ public function store(Request $request, ImageController $image)
->where('address', $address)
->first();


if(!$check) {
$estate->estate_name = $estate_name;
$estate->city = $city;
Expand All @@ -173,7 +173,7 @@ public function store(Request $request, ImageController $image)
$msg['message'] = 'Estate created succesfully!';
$msg['image_info'] = $data;
$msg['estate'] = $estate;
}else {
}else {

$msg['status'] = false;
$msg['status_code'] = 402;
Expand Down Expand Up @@ -211,7 +211,7 @@ public function update(Request $request, Estate $estate, $id, ImageController $i
$estate->country = ucfirst($request->input('country'));
$estate->address = ucfirst($request->input('address'));

//Upload image
//Upload image
if($request->hasFile('image')) {
$data = $this->upload($request, $image, $estate);
if($data['status_code'] != 200) {
Expand All @@ -222,20 +222,20 @@ public function update(Request $request, Estate $estate, $id, ImageController $i
$data = null;
$estate->image = 'noimage.jpg';
}

$estate->save();

$msg['status_code'] = 201;
$msg['message'] = 'Estate updated succesfully!';
$msg['estate'] = $estate;
$msg['image_info'] = $data;
}else {
}else {
$msg['status_code'] = 404;
$msg['message'] = 'Estated not found!';
}

DB::commit();
return response()->json($msg, $msg['status_code']);
return response()->json($msg, $msg['status_code']);

}catch(\Exception $e) {
//if any operation fails, Thanos snaps finger - user was not created rollback what is saved
Expand All @@ -244,21 +244,21 @@ public function update(Request $request, Estate $estate, $id, ImageController $i
$msg['status'] = false;
$msg['message'] = "Error: Estate not updated, please try again!";
$msg['hint'] = $e->getMessage();
return response()->json($msg, 501);
return response()->json($msg, 501);
}
}


// Delete Estates by id

public function deleteEstate($id) {

// Delete Estates by id

public function deleteEstate($id) {

$estates = Estate::where('id', $id)->first();
$estates->delete();

// Success message
$res['message'] = "Estate deleted";
return response()->json($res, 200);
return response()->json($res, 200);
}


Expand All @@ -282,10 +282,10 @@ public function estateMemeber(Request $request, Home $home, $id) {
$this->validate($request, [
'house_block' => 'min:2',
]);

DB::beginTransaction();
try{
if(!$check_if) {
if(!$check_if) {
$msg['message'] = 'Your estate has beed selected succesfully!';
$home->user_id = $user->id;
$home->estate_id = $id;
Expand All @@ -306,7 +306,7 @@ public function estateMemeber(Request $request, Home $home, $id) {

$msg['status'] = true;
$msg['user_details'] = $home;
return response()->json($msg, 200);
return response()->json($msg, 200);

}catch(\Exeception $e) {
//if any operation fails, Thanos snaps finger - user was not created rollback what is saved
Expand All @@ -315,7 +315,7 @@ public function estateMemeber(Request $request, Home $home, $id) {
$msg['status'] = false;
$msg['message'] = "Error: Estate Selection failed, please try again!";
$msg['hint'] = $e->getMessage();
return response()->json($msg, 501);
return response()->json($msg, 501);

}

Expand Down
20 changes: 10 additions & 10 deletions app/Http/Controllers/ServiceProviderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,16 @@ public function destroy($id)
if ($service) {
$res['status'] = 200;
$res["message"] = "Service Provider Deleted!";

return response()->json($res, 200);
} else {
$res['status'] = 404;
$res["message"] = "No service found";

return response()->json($res, $res['status']);
}
}

public function softDelete($id)
{
$service = Service_Provider::destroy($id);
Expand All @@ -279,14 +279,14 @@ public function softDelete($id)
$res["status"] = 200;
$res["message"] = "Service Provider Suspended!";
$res["data"] = $service;

return response()->json($res, $res["status"]);
}
else
{
$res["status"] = 501;
$res["message"] = "Unable To Suspend Service Provider!";

return response()->json($res, $res["status"]);
}
}
Expand All @@ -302,7 +302,7 @@ public function search($id)
$status = $db->status;
$created = $db->created_at ?? 'null';
$updated = $db->updated_at ?? 'null';

if($status == 1)
{
$res["status"] = "Active";
Expand All @@ -311,10 +311,10 @@ public function search($id)
{
$res["status"] = "Inactive";
}

$cat = Category::find($cat_id);
$cat_name = $cat->title;

$res["status_code"] = 200;
$res["message"] = "Success!";
$res["name"] = $name;
Expand All @@ -323,15 +323,15 @@ public function search($id)
$res["created"] = $created;
$res["updated"] = $updated;
$res["category"] = $cat_name;

return response()->json($res, $res["status_code"]);
}
catch (\Exception $e)
{
$res["status_code"] = 501;
$res["message"] = "Failed!";
$res["data"] = $e->getMessage();

return response()->json($res, $res["status_code"]);
}
}
Expand Down
Loading

0 comments on commit cd9bd18

Please sign in to comment.