Merge pull request #321 from WDI-Ideas/sayli

Sayli
This commit is contained in:
Sayli Raut
2024-07-15 12:28:25 +05:30
committed by GitHub
3 changed files with 76 additions and 31 deletions

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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']);
});