Skip to content

Commit

Permalink
feat(api)! : create feedback student api
Browse files Browse the repository at this point in the history
  • Loading branch information
farahamaliaa committed Dec 4, 2024
1 parent 1f4db71 commit f2bed2c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/Http/Controllers/Api/StudentFeedbackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions app/Http/Requests/StoreFeedbackApiRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreFeedbackApiRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'student_id' => 'required',
'is_teacher_present' => 'required',
'summary' => 'required',
];
}
}
12 changes: 12 additions & 0 deletions app/Services/FeedbackService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit f2bed2c

Please sign in to comment.