Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“š Course Catalog API (Laravel 12)

RESTful API untuk katalog course menggunakan:

  • Laravel 12 (API Only)
  • MySQL
  • Laravel Sanctum (Authentication)
  • Repository Pattern + Service Layer
  • Global Response Format

๐Ÿš€ Features

  • Authentication (Register & Login - Sanctum Token)
  • Course Catalog (Public)
  • Admin CRUD (Course, Topic, Language)
  • Clean Architecture (Controller โ†’ Service โ†’ Repository)
  • Global JSON Response Format
  • Seeder (Course, Topic, Language, Admin)

๐Ÿงฑ Tech Stack

  • PHP 8.2+
  • Laravel 12
  • MySQL
  • Laravel Sanctum
  • Postman (API Testing)

๐Ÿ“ฆ INSTALLATION GUIDE (STEP BY STEP)

1๏ธโƒฃ Clone Repository

git clone https://github.com/justsmith262/course-catalog-api.git
cd course-catalog-api

2๏ธโƒฃ Install Dependencies

composer install

3๏ธโƒฃ Copy Environment File

cp .env.example .env

4๏ธโƒฃ Setup Database (MySQL)

Edit file .env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=course_catalog
DB_USERNAME=root
DB_PASSWORD=

Buat database baru di MySQL:

CREATE DATABASE course_catalog;

5๏ธโƒฃ Generate App Key

php artisan key:generate

6๏ธโƒฃ Install Sanctum (Jika belum)

php artisan install:api

7๏ธโƒฃ Run Migration + Seeder

php artisan migrate --seed

Seeder akan membuat:

  • 1 Admin User
  • 3 Languages (Indonesia, English, Japan)
  • 3 Topics
  • 2 Courses

8๏ธโƒฃ Run Server

php artisan serve

API Base URL:

http://127.0.0.1:8000/api

๐Ÿ‘ค DEFAULT ADMIN ACCOUNT (Seeder)

{
  "email": "admin@mail.com",
  "password": "123",
  "role": "ADMIN"
}

๐Ÿ” GLOBAL RESPONSE FORMAT

โœ… Success Response

{
  "code": 200,
  "success": true,
  "message": "Success",
  "data": []
}

โŒ Error Response

{
  "code": 404,
  "success": false,
  "message": "Error message",
  "data": []
}

๐Ÿ” AUTHENTICATION (SANCTUM)

Semua endpoint admin menggunakan:

Authorization: Bearer {token}

๐Ÿ“ฎ POSTMAN DOCUMENTATION

๐ŸŒ Environment Variables (Postman)

Buat Environment:

Variable Value
url http://127.0.0.1:8000/api
token (auto dari login)

๐Ÿ“ POSTMAN COLLECTION STRUCTURE

Folder:

  • AUTH
  • COURSE (Public + Admin)
  • TOPIC (Admin)
  • LANGUAGE (Admin)

๐Ÿ”‘ AUTH ENDPOINTS

1. Register

POST /register

Body (JSON)

{
  "name": "User Test",
  "email": "user@mail.com",
  "password": "password"
}

Response

{
  "code": 201,
  "success": true,
  "message": "Register success",
  "data": {
    "user": {},
    "token": "..."
  }
}

2. Login

POST /login

Body (JSON)

{
  "email": "admin@mail.com",
  "password": "123"
}

Postman Script (Auto Save Token)

Masukkan di tab Scripts:

const res = pm.response.json();

if (res.data && res.data.token) {
    pm.environment.set("token", res.data.token);
    console.log("Token saved:", res.data.token);
} else {
    console.log("Token not found");
}

๐Ÿ“š COURSE ENDPOINTS

๐Ÿ”“ Public

1. Get All Courses

GET /courses

Response:

{
  "code": 200,
  "success": true,
  "message": "Courses fetched successfully",
  "data": []
}

2. Get Course Detail

GET /courses/{id}


๐Ÿ”’ Admin Only (Require Token)

3. Create Course

POST /courses

Headers:

Authorization: Bearer {{token}}
Content-Type: application/json

Body:

{
  "topic_id": 1,
  "language_id": 2,
  "title": "Laravel Clean Architecture",
  "description": "Full REST API course",
  "short_description": "Learn Laravel API",
  "price": 199000,
  "discount_rate": 10,
  "thumbnail_url": "https://example.com/image.jpg",
  "level": "BEGINNER"
}

4. Update Course

PUT /courses/{id}

5. Delete Course

DELETE /courses/{id}


๐Ÿงฉ TOPIC ENDPOINTS (ADMIN)

1. Get All Topics

GET /topics

2. Create Topic

POST /topics

Body:

{
  "name": "Backend Development",
  "description": "All backend topics",
  "parent_id": null
}

3. Update Topic

PUT /topics/{id}

4. Delete Topic

DELETE /topics/{id}


๐ŸŒ LANGUAGE ENDPOINTS (ADMIN)

1. Get All Languages

GET /languages

2. Create Language

POST /languages

Body:

{
  "name": "English"
}

3. Update Language

PUT /languages/{id}

4. Delete Language

DELETE /languages/{id}


๐Ÿ—๏ธ PROJECT ARCHITECTURE

app/
 โ”œโ”€โ”€ Http/
 โ”‚   โ”œโ”€โ”€ Controllers/Api
 โ”‚   โ”œโ”€โ”€ Middleware
 โ”‚   โ””โ”€โ”€ Requests
 โ”œโ”€โ”€ Services
 โ”œโ”€โ”€ Repositories
 โ”‚   โ”œโ”€โ”€ Interfaces
 โ”‚   โ””โ”€โ”€ Implementations
 โ”œโ”€โ”€ Models

Flow:

Request โ†’ Route โ†’ Controller โ†’ Service โ†’ Repository โ†’ Model โ†’ Resource โ†’ JSON Response

๐Ÿ›ก๏ธ MIDDLEWARE

  • auth:sanctum โ†’ Authentication
  • admin โ†’ Role validation (ADMIN only)

๐Ÿงช TESTING FLOW (POSTMAN)

  1. Login (get token)
  2. Token auto save ke environment
  3. Akses endpoint admin
  4. CRUD Course / Topic / Language

โš ๏ธ COMMON ERRORS

Unauthorized (401)

Token tidak dikirim atau invalid.

Forbidden (403)

User bukan ADMIN.

Validation Error (422)

Input request tidak sesuai rules.


๐Ÿ‘จโ€๐Ÿ’ป AUTHOR

Backend API built with Clean Architecture using Laravel 12.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages