This commit is contained in:
sayliraut
2024-06-07 12:32:04 +05:30
parent e40b33f847
commit 741e233920
6 changed files with 158 additions and 5 deletions

View File

@@ -0,0 +1,83 @@
<?php
namespace App\Http\Controllers\Admin\APIs\Customer_API;
use App\Http\Controllers\Controller;
use App\Models\FeedbackReaction;
use App\Services\APIs\CustomerAPIs\FeedbackApiServices;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\Request;
use Exception;
use Illuminate\Support\Facades\Validator;
class FeedbackApiController extends Controller
{
protected $FeedbackApiServices;
public function __construct(FeedbackApiServices $FeedbackApiServices)
{
$this->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);
}
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class FeedbackReaction extends Model
{
use HasFactory;
protected $table = "feedback_reaction";
protected $fillable = [
"id",
"feedback_reaction_xid",
"feedback_reaction_title",
"is_active",
"created_by",
"modified_by",
"created_at",
"updated_at",
];}

View File

@@ -1,12 +1,12 @@
<?php
namespace App\Models\admin;
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\IamPrincipal;
use App\Models\admin\FeedbackReaction;
use App\Models\FeedbackReaction;
class ManageFeedback extends Model
{
@@ -26,7 +26,7 @@ class ManageFeedback extends Model
public function feedbackReaction()
{
return $this->belongsTo(FeedbackReaction::class, 'feedback_reaction_xid', 'feedback_reaction_xid');
return $this->belongsTo(feedbackReaction::class, 'feedback_reaction_xid', 'feedback_reaction_xid');
}

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Services\APIs\CustomerAPIs;
use App\Models\ManageFeedback;
use App\Models\IamPrincipal;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use Exception;
use Carbon\Carbon;
class FeedbackApiServices
{
public function storeFeedback($customerIamId, $request)
{
try {
DB::beginTransaction();
$user_data = IamPrincipal::where('id', $customerIamId)->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);
}
}
}

View File

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

View File

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