From 62c505c11aa64dca60eebc3e1ab779005b1c259d Mon Sep 17 00:00:00 2001 From: sayliraut Date: Mon, 15 Jul 2024 12:29:18 +0530 Subject: [PATCH] changes --- .../Customer_API/CustomerControllerApi.php | 25 ++++++ .../APIs/CustomerAPIs/CustomerApiServices.php | 79 +++++++++++-------- routes/customer_api.php | 3 + 3 files changed, 76 insertions(+), 31 deletions(-) diff --git a/app/Http/Controllers/APIs/Customer_API/CustomerControllerApi.php b/app/Http/Controllers/APIs/Customer_API/CustomerControllerApi.php index 94292a4..3c4214d 100644 --- a/app/Http/Controllers/APIs/Customer_API/CustomerControllerApi.php +++ b/app/Http/Controllers/APIs/Customer_API/CustomerControllerApi.php @@ -187,4 +187,29 @@ class CustomerControllerApi extends Controller return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); } } + + + /** + * Created By : sayli Raut + * Created at : 15 July 2024 + * Use : To get user subscription status. + */ + public function CheckSubscription() + { + try { + $token = readHeaderToken(); + + if ($token) { + $customerIamId = $token['sub']; + $response = $this->CustomerApiServices->CheckSubscription($customerIamId); + return jsonResponseWithSuccessMessageApi(__('auth.data_fetched_successfully'), ['is_subscribed' => $response], 200); + + } else { + return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409); + } + } catch (Exception $e) { + Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]); + return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); + } + } } diff --git a/app/Services/APIs/CustomerAPIs/CustomerApiServices.php b/app/Services/APIs/CustomerAPIs/CustomerApiServices.php index da5b8f3..561c636 100644 --- a/app/Services/APIs/CustomerAPIs/CustomerApiServices.php +++ b/app/Services/APIs/CustomerAPIs/CustomerApiServices.php @@ -12,43 +12,43 @@ use Illuminate\Support\Facades\DB; class CustomerApiServices { public function getUserProfileDetailService($customerIamId) -{ - try { - $user = IamPrincipal::findOrFail($customerIamId); + { + try { + $user = IamPrincipal::findOrFail($customerIamId); - $data = IamPrincipal::select( - 'id', - 'first_name', - 'last_name', - 'email_address', - 'phone_number', - 'date_of_birth', - 'state_xid', - 'profile_photo', - 'referral_code' - )->find($user->id); + $data = IamPrincipal::select( + 'id', + 'first_name', + 'last_name', + 'email_address', + 'phone_number', + 'date_of_birth', + 'state_xid', + 'profile_photo', + 'referral_code' + )->find($user->id); - $dateTime = now(); - $formattedDateTime = $dateTime->format('Y-m-d H:i:s'); + $dateTime = now(); + $formattedDateTime = $dateTime->format('Y-m-d H:i:s'); - $isSubscribedUser = Subscriptions::where('iam_principal_xid', $customerIamId) - ->where('next_payment_date', '>=', $formattedDateTime) - ->exists(); + $isSubscribedUser = Subscriptions::where('iam_principal_xid', $customerIamId) + ->where('next_payment_date', '>=', $formattedDateTime) + ->exists(); - if ($data->profile_photo) { - $data->profile_photo = ListingImageUrl('profile_image', $data->profile_photo); - } else { - $data->profile_photo = asset('public/assets/img/blankProfile.png'); + if ($data->profile_photo) { + $data->profile_photo = ListingImageUrl('profile_image', $data->profile_photo); + } else { + $data->profile_photo = asset('public/assets/img/blankProfile.png'); + } + + $data->is_subscribed = $isSubscribedUser; + + return $data; + } catch (Exception $ex) { + Log::error('Customer Get data service failed : ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); } - - $data->is_subscribed = $isSubscribedUser; - - return $data; - } catch (Exception $ex) { - Log::error('Customer Get data service failed : ' . $ex->getMessage()); - return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); } -} @@ -143,4 +143,21 @@ class CustomerApiServices return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); } } + + public function CheckSubscription($customerIamId) + { + try { + + $dateTime = now(); + $formattedDateTime = $dateTime->format('Y-m-d H:i:s'); + $isSubscribedUser = Subscriptions::where('iam_principal_xid', $customerIamId) + ->where('next_payment_date', '>=', $formattedDateTime) + ->exists(); + + return $isSubscribedUser; + } catch (Exception $ex) { + Log::error('Customer Get data service failed : ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } } diff --git a/routes/customer_api.php b/routes/customer_api.php index 0738f40..f70fc74 100644 --- a/routes/customer_api.php +++ b/routes/customer_api.php @@ -63,6 +63,7 @@ Route::middleware(['customerApiBasicAuth'])->group(function () { Route::post('/v1/reset-user-password', [CustomerControllerApi::class, 'resetUserPassword']); Route::post('/v1/customer-logout', [CustomerControllerApi::class, 'customerLogout']); Route::post('/v1/delete_account', [CustomerControllerApi::class, 'destroyAccount']); + Route::get('/v1/check_subscription', [CustomerControllerApi::class, 'CheckSubscription']); //*******************************************************Restaurant******************************************************** Route::get('/v1/detail-of-restaurant/{id}', [RestaurantControllerApi::class, 'DetailRestaurant']); @@ -93,6 +94,8 @@ Route::middleware(['customerApiBasicAuth'])->group(function () { //*******************************************************Rules ******************************************************** Route::get('/v1/voucher-rules', [RulesControllerAPI::class, 'getVoucherRules']); + + });