diff --git a/app/Http/Controllers/Admin/APIs/Customer_API/FeedbackApiController.php b/app/Http/Controllers/Admin/APIs/Customer_API/FeedbackApiController.php new file mode 100644 index 0000000..96d597c --- /dev/null +++ b/app/Http/Controllers/Admin/APIs/Customer_API/FeedbackApiController.php @@ -0,0 +1,83 @@ +FeedbackApiServices = $FeedbackApiServices; + } + + /** + * Created By : Sayli Raut + * Created at : 07 June 2024 + * Use : Storing feedback. + */ + + public function getFeedbackReaction(Request $request) + { + try { + $token = readHeaderToken(); + if ($token) { + + $feedbackReactions = FeedbackReaction::select('id', 'feedback_reaction_title')->get(); + + if ($feedbackReactions->isEmpty()) { + Log::info('Reactions not found.'); + return jsonResponseWithSuccessMessageApi(__('success.data_not_found'), [], 200); + } + + $responseData['result'] = $feedbackReactions; + return jsonResponseWithSuccessMessageApi(__('success.data_fetched_successfully'), $feedbackReactions, 200); + } else { + return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409); + } + } catch (Exception $e) { + Log::error('Feedback Reaction API failed: ' . $e); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } + + + public function storeFeedback(Request $request) + { + try { + $token = readHeaderToken(); + $validator = Validator::make($request->all(), [ + 'reaction' => 'required|numeric', + // 'comment' => 'required', + ]); + + if ($validator->fails()) { + $validationErrors = $validator->errors()->all(); + Log::error("Validation error: " . implode(", ", $validationErrors)); + return jsonResponseWithErrorMessageApi($validationErrors, 403); + } + + if ($token) { + $customerIamId = $token['sub']; + $response = $this->FeedbackApiServices->storeFeedback($customerIamId, $request); + return $response; + } 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/Models/FeedbackReaction.php b/app/Models/FeedbackReaction.php new file mode 100644 index 0000000..43bde2a --- /dev/null +++ b/app/Models/FeedbackReaction.php @@ -0,0 +1,22 @@ +belongsTo(FeedbackReaction::class, 'feedback_reaction_xid', 'feedback_reaction_xid'); + return $this->belongsTo(feedbackReaction::class, 'feedback_reaction_xid', 'feedback_reaction_xid'); } diff --git a/app/Services/APIs/CustomerAPIs/FeedbackApiServices.php b/app/Services/APIs/CustomerAPIs/FeedbackApiServices.php new file mode 100644 index 0000000..cf715a6 --- /dev/null +++ b/app/Services/APIs/CustomerAPIs/FeedbackApiServices.php @@ -0,0 +1,45 @@ +first(); + $now = Carbon::now(); + $reaction = $request->input('reaction'); + $comment = $request->input('comment'); + + $feedbackData = [ + 'principal_xid' => $user_data->id, + 'feedback_reaction_xid' => $reaction, + 'comment' => $comment, + 'default_comment' => $request->default_comment, + ]; + + $feedback = ManageFeedback::create($feedbackData); + + DB::commit(); + Log::info('Feedback added successfully'); + return jsonResponseWithSuccessMessageApi(__('auth.feedback_store'), [], 200); + } catch (Exception $ex) { + DB::rollBack(); + Log::error('Update Quantity service failed: ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } +} diff --git a/database/migrations/2024_02_02_061343_create_feedback_reaction.php b/database/migrations/2024_02_02_061343_create_feedback_reaction.php index 44cfd9b..142e7f0 100644 --- a/database/migrations/2024_02_02_061343_create_feedback_reaction.php +++ b/database/migrations/2024_02_02_061343_create_feedback_reaction.php @@ -14,6 +14,7 @@ return new class extends Migration Schema::create('feedback_reaction', function (Blueprint $table) { $table->id(); $table->integer('feedback_reaction_xid')->nullable(); + $table->string('feedback_reaction_title')->nullable(); $table->integer('created_by')->nullable(); $table->integer('modified_by')->nullable(); $table->timestamps(); diff --git a/routes/customer_api.php b/routes/customer_api.php index 5950075..6623340 100644 --- a/routes/customer_api.php +++ b/routes/customer_api.php @@ -4,6 +4,7 @@ use App\Http\Controllers\Admin\APIs\Customer_API\AuthController; use App\Http\Controllers\Admin\APIs\Customer_API\CMSApiController; use App\Http\Controllers\Admin\APIs\Customer_API\ContactUsApiController; use App\Http\Controllers\Admin\APIs\Customer_API\CustomerControllerApi; +use App\Http\Controllers\Admin\APIs\Customer_API\FeedbackApiController; use App\Http\Controllers\Admin\APIs\Customer_API\NotificationController; use App\Http\Controllers\Admin\APIs\Customer_API\RestaurantControllerApi; use Illuminate\Support\Facades\Route; @@ -62,8 +63,9 @@ Route::middleware(['customerApiBasicAuth'])->group(function () { Route::post('/v1/send-notification', [NotificationController::class, 'sendNotificationApi']); Route::post('/v1/customer-alert-notification', [NotificationController::class, 'AlertNotificationApi']); + //*******************************************************Feedback******************************************************** - - + Route::get('/v1/feedback-reactions', [FeedbackApiController::class, 'getFeedbackReaction']); + Route::post('/v1/store-feedback', [FeedbackApiController::class, 'storeFeedback']); }); });