feat: menambahkan get data materi,submateri,kategori,dan latihan
This commit is contained in:
parent
a601c2ffec
commit
c4879d6256
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Helpers\ResponseFormatter;
|
||||
use App\Models\Kategori;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class KategoryController extends Controller
|
||||
{
|
||||
public function getKategoriByMateri($id_materi)
|
||||
{
|
||||
try {
|
||||
$kategori = Kategori::where('id_materi', $id_materi)->get();
|
||||
if ($kategori->isEmpty()) {
|
||||
return ResponseFormatter::error(null, 'Kategori tidak ditemukan', 404);
|
||||
}
|
||||
return ResponseFormatter::success($kategori, 'Kategori berdasarkan materi berhasil diambil');
|
||||
} catch (\Exception $e) {
|
||||
return ResponseFormatter::error(null, 'Terjadi kesalahan saat mengambil data kategori', 500);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Models\Latihan;
|
||||
use App\Helpers\ResponseFormatter;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LatihanControler extends Controller
|
||||
{
|
||||
public function getLatihanBySubMateri($id_submateri)
|
||||
{
|
||||
try {
|
||||
$latihan = Latihan::where('id_submateri', $id_submateri)->get();
|
||||
if ($latihan->isEmpty()) {
|
||||
return ResponseFormatter::error(null, 'Latihan tidak ditemukan', 404);
|
||||
}
|
||||
return ResponseFormatter::success($latihan, 'Latihan berdasarkan sub materi berhasil diambil');
|
||||
} catch (\Exception $e) {
|
||||
return ResponseFormatter::error(null, 'Terjadi kesalahan saat mengambil data latihan', 500);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Models\Materi;
|
||||
use App\Helpers\ResponseFormatter;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MateriControler extends Controller
|
||||
{
|
||||
public function getMateri()
|
||||
{
|
||||
try {
|
||||
$materi = Materi::all();
|
||||
return ResponseFormatter::success($materi, 'Daftar materi berhasil diambil');
|
||||
} catch (\Exception $e) {
|
||||
return ResponseFormatter::error(null, 'Terjadi kesalahan saat mengambil data materi', 500);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Models\SubMateri;
|
||||
use App\Helpers\ResponseFormatter;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SubMateriControler extends Controller
|
||||
{
|
||||
public function getSubMateriByKategori($id_kategori)
|
||||
{
|
||||
try {
|
||||
$subMateri = SubMateri::where('id_kategori', $id_kategori)->get();
|
||||
if ($subMateri->isEmpty()) {
|
||||
return ResponseFormatter::error(null, 'Sub materi tidak ditemukan', 404);
|
||||
}
|
||||
return ResponseFormatter::success($subMateri, 'Sub materi berdasarkan kategori berhasil diambil');
|
||||
} catch (\Exception $e) {
|
||||
return ResponseFormatter::error(null, 'Terjadi kesalahan saat mengambil data sub materi', 500);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Kategori extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
// Tentukan tabel yang digunakan
|
||||
protected $table = 'kategori';
|
||||
|
||||
// Tentukan kolom yang bisa diisi (Mass Assignment)
|
||||
protected $fillable = [
|
||||
'id_materi',
|
||||
'nama_kategori',
|
||||
];
|
||||
|
||||
// Relasi dengan sub materi
|
||||
public function subMateri()
|
||||
{
|
||||
return $this->hasMany(SubMateri::class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Latihan extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
// Tentukan tabel yang digunakan
|
||||
protected $table = 'latihan';
|
||||
|
||||
// Tentukan kolom yang bisa diisi (Mass Assignment)
|
||||
protected $fillable = [
|
||||
'id_submateri',
|
||||
'potongan_ayat',
|
||||
'latin_text',
|
||||
'materi_description',
|
||||
'correct_audio',
|
||||
'recorder_audio',
|
||||
];
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Materi extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
// Tentukan tabel yang digunakan
|
||||
protected $table = 'materi';
|
||||
|
||||
// Tentukan kolom yang bisa diisi (Mass Assignment)
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'subtitle',
|
||||
];
|
||||
|
||||
// Relasi dengan kategori
|
||||
public function kategori()
|
||||
{
|
||||
return $this->hasMany(Kategori::class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SubMateri extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
// Tentukan tabel yang digunakan
|
||||
protected $table = 'sub_materi';
|
||||
|
||||
// Tentukan kolom yang bisa diisi (Mass Assignment)
|
||||
protected $fillable = [
|
||||
'id_kategori',
|
||||
'title',
|
||||
'subtitle',
|
||||
'video_url',
|
||||
'intro',
|
||||
];
|
||||
|
||||
// Relasi dengan latihan
|
||||
public function latihan()
|
||||
{
|
||||
return $this->hasMany(Latihan::class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('materi', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('title');
|
||||
$table->text('subtitle');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('materi');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('kategori', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('id_materi')->constrained('materi');
|
||||
$table->string('nama_kategori');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('kategori');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('sub_materi', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('id_kategori')->constrained('kategori');
|
||||
$table->string('title');
|
||||
$table->text('subtitle');
|
||||
$table->string('video_url');
|
||||
$table->text('intro');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('sub_materi');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('latihan', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('id_submateri')->constrained('sub_materi');
|
||||
$table->text('potongan_ayat');
|
||||
$table->text('latin_text');
|
||||
$table->text('materi_description');
|
||||
$table->string('correct_audio');
|
||||
$table->string('recorder_audio');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('latihan');
|
||||
}
|
||||
};
|
|
@ -12,11 +12,13 @@ class DatabaseSeeder extends Seeder
|
|||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// \App\Models\User::factory(10)->create();
|
||||
|
||||
// \App\Models\User::factory()->create([
|
||||
// 'name' => 'Test User',
|
||||
// 'email' => 'test@example.com',
|
||||
// ]);
|
||||
$this->call([
|
||||
// UsersTableSeeder::class,
|
||||
MateriTableSeeder::class,
|
||||
KategoriTableSeeder::class,
|
||||
SubMateriTableSeeder::class,
|
||||
LatihanTableSeeder::class,
|
||||
// PenyelesaianLatihanTableSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\Kategori;
|
||||
|
||||
class KategoriTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Kategori::create([
|
||||
'id_materi' => 1, // Mengacu pada materi "Makharijul Huruf"
|
||||
'nama_kategori' => 'Rongga Mulut',
|
||||
]);
|
||||
|
||||
Kategori::create([
|
||||
'id_materi' => 1,
|
||||
'nama_kategori' => 'Tenggorokan',
|
||||
]);
|
||||
Kategori::create([
|
||||
'id_materi' => 2, // Mengacu pada materi "Sifatul Huruf"
|
||||
'nama_kategori' => 'Memiliki lawan',
|
||||
]);
|
||||
|
||||
Kategori::create([
|
||||
'id_materi' => 2,
|
||||
'nama_kategori' => 'Tidak memiliki lawan',
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\Latihan;
|
||||
|
||||
class LatihanTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Latihan::create([
|
||||
'id_submateri' => 1, // Mengacu pada sub materi "Makhrijul Huruf"
|
||||
'potongan_ayat' => 'بَسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ',
|
||||
'latin_text' => 'Bismillah',
|
||||
'materi_description' => 'Latihan pengucapan huruf',
|
||||
'correct_audio' => 'audio1.mp3',
|
||||
'recorder_audio' => 'user1',
|
||||
]);
|
||||
|
||||
Latihan::create([
|
||||
'id_submateri' => 2, // Mengacu pada sub materi "Tenggorokan"
|
||||
'potongan_ayat' => 'اَلْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ',
|
||||
'latin_text' => 'Alhamdulillah',
|
||||
'materi_description' => 'Latihan pengucapan huruf',
|
||||
'correct_audio' => 'audio2.mp3',
|
||||
'recorder_audio' => 'user2',
|
||||
]);
|
||||
Latihan::create([
|
||||
'id_submateri' => 3, // Mengacu pada sub materi "Makhrijul Huruf"
|
||||
'potongan_ayat' => 'بَسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ',
|
||||
'latin_text' => 'Bismillah',
|
||||
'materi_description' => 'Latihan pengucapan huruf',
|
||||
'correct_audio' => 'audio1.mp3',
|
||||
'recorder_audio' => 'user1',
|
||||
]);
|
||||
|
||||
Latihan::create([
|
||||
'id_submateri' => 4, // Mengacu pada sub materi "Tenggorokan"
|
||||
'potongan_ayat' => 'اَلْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ',
|
||||
'latin_text' => 'Alhamdulillah',
|
||||
'materi_description' => 'Latihan pengucapan huruf',
|
||||
'correct_audio' => 'audio2.mp3',
|
||||
'recorder_audio' => 'user2',
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\Materi;
|
||||
|
||||
class MateriTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Materi::create([
|
||||
'title' => 'Makharijul Huruf',
|
||||
'subtitle' => 'Penjelasan tentang pengucapan huruf-huruf',
|
||||
]);
|
||||
|
||||
Materi::create([
|
||||
'title' => 'sifatul huruf',
|
||||
'subtitle' => 'sifat yang membedakan setiap huruf',
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class PenyelesaianLatihanTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\SubMateri;
|
||||
|
||||
class SubMateriTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
SubMateri::create([
|
||||
'id_kategori' => 1, // Mengacu pada kategori "Rongga Mulut"
|
||||
'title' => 'Mad',
|
||||
'subtitle' => 'rongga mulut',
|
||||
'video_url' => 'https://youtu.be/qF_HuLMI-B4?si=IJWIzHu-vQXBaKgD',
|
||||
'intro' => 'Pengenalan rongga mulut',
|
||||
]);
|
||||
|
||||
SubMateri::create([
|
||||
'id_kategori' => 2, // Mengacu pada kategori "Tenggorokan"
|
||||
'title' => 'Hamzah',
|
||||
'subtitle' => 'Pangkal Tenggorokan',
|
||||
'video_url' => 'https://youtu.be/qF_HuLMI-B4?si=IJWIzHu-vQXBaKgD',
|
||||
'intro' => 'Penjelasan tentang pangkaltenggorokan',
|
||||
]);
|
||||
SubMateri::create([
|
||||
'id_kategori' => 3, // Mengacu pada kategori "Rongga Mulut"
|
||||
'title' => 'Hamz vs Jahr',
|
||||
'subtitle' => 'Keluar nafas vs tidak keluar nafas',
|
||||
'video_url' => 'https://youtu.be/qF_HuLMI-B4?si=IJWIzHu-vQXBaKgD',
|
||||
'intro' => 'Pengenalan sifat hams dan jahr',
|
||||
]);
|
||||
|
||||
SubMateri::create([
|
||||
'id_kategori' => 4, // Mengacu pada kategori "Tenggorokan"
|
||||
'title' => 'Qalqalah',
|
||||
'subtitle' => 'Suara memantul',
|
||||
'video_url' => 'https://youtu.be/qF_HuLMI-B4?si=IJWIzHu-vQXBaKgD',
|
||||
'intro' => 'Penjelasan tentang qalqalah',
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class UsersTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -3,6 +3,10 @@
|
|||
use App\Http\Controllers\API\UserControler;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Http\Controllers\API\MateriControler;
|
||||
use App\Http\Controllers\API\KategoryController;
|
||||
use App\Http\Controllers\API\SubMateriControler;
|
||||
use App\Http\Controllers\API\LatihanControler;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
@ -23,3 +27,8 @@
|
|||
Route::get('user', [UserControler::class, 'fetch']);
|
||||
Route::post('logout', [UserControler::class, 'logout']);
|
||||
});
|
||||
|
||||
Route::get('/materi', [MateriControler::class, 'getMateri']);
|
||||
Route::get('/kategori/{id_materi}', [KategoryController::class, 'getKategoriByMateri']);
|
||||
Route::get('/sub_materi/{id_kategori}', [SubMateriControler::class, 'getSubMateriByKategori']);
|
||||
Route::get('/latihan/{id_submateri}', [LatihanControler::class, 'getLatihanBySubMateri']);
|
Loading…
Reference in New Issue