diff --git a/app/Http/Controllers/Api/StudentFeedbackController.php b/app/Http/Controllers/Api/StudentFeedbackController.php index 87354499..1db9d415 100644 --- a/app/Http/Controllers/Api/StudentFeedbackController.php +++ b/app/Http/Controllers/Api/StudentFeedbackController.php @@ -4,6 +4,7 @@ use App\Contracts\Interfaces\FeedbackInterface; use App\Http\Controllers\Controller; +use App\Http\Requests\StoreFeedbackApiRequest; use App\Http\Requests\StoreFeedbackRequest; use App\Models\LessonSchedule; use App\Services\FeedbackService; @@ -21,11 +22,10 @@ public function __construct(FeedbackInterface $feedback, FeedbackService $servic $this->service = $service; } - public function store(StoreFeedbackRequest $request, LessonSchedule $lessonSchedule) + public function store(StoreFeedbackApiRequest $request, LessonSchedule $lessonSchedule) { DB::beginTransaction(); - $id = auth()->user()->student->id; - $data = $this->service->store($request, $lessonSchedule, $id); + $data = $this->service->storeApi($request, $lessonSchedule); $this->feedback->store($data); DB::commit(); return response()->json(['status' => 'success', 'message' => "Berhasil mengirim tanggapan", 'code' => 200], 200); diff --git a/app/Http/Requests/StoreFeedbackApiRequest.php b/app/Http/Requests/StoreFeedbackApiRequest.php new file mode 100644 index 00000000..7ec39469 --- /dev/null +++ b/app/Http/Requests/StoreFeedbackApiRequest.php @@ -0,0 +1,30 @@ +|string> + */ + public function rules(): array + { + return [ + 'student_id' => 'required', + 'is_teacher_present' => 'required', + 'summary' => 'required', + ]; + } +} diff --git a/app/Services/FeedbackService.php b/app/Services/FeedbackService.php index 3faecaf0..e4bbb305 100644 --- a/app/Services/FeedbackService.php +++ b/app/Services/FeedbackService.php @@ -2,6 +2,7 @@ namespace App\Services; +use App\Http\Requests\StoreFeedbackApiRequest; use App\Http\Requests\StoreFeedbackRequest; use App\Http\Requests\UpdateFeedbackRequest; use App\Models\LessonSchedule; @@ -24,6 +25,17 @@ public function store(StoreFeedbackRequest $request, LessonSchedule $lessonSched ]; } + public function storeApi(StoreFeedbackApiRequest $request, LessonSchedule $lessonSchedule): mixed + { + $data = $request->validated(); + return [ + 'lesson_schedule_id' => $lessonSchedule->id, + 'student_id' => $request->student_id, + 'is_teacher_present' => $data['is_teacher_present'], + 'summary' => $data['summary'], + ]; + } + public function update(UpdateFeedbackRequest $request): mixed { $data = $request->validated();