Skip to content

Latest commit

 

History

History
752 lines (716 loc) · 11.9 KB

File metadata and controls

752 lines (716 loc) · 11.9 KB

API Documentation

Dokumentasi ini dibuat berdasarkan panggilan API yang benar-benar ada di kode frontend/src.


Auth - Refresh session

Method: GET Endpoint: /api/auth/me Headers:

{
  "Authorization": "Bearer {token}"
}

Request Body:

null

Response Body:

{
  "data": {
    "id": 1,
    "email": "user@example.com",
    "fullName": "User Name",
    "roles": ["customer", "staff"]
  }
}

Auth - Login

Method: POST Endpoint: /api/auth/login Headers:

{
  "Content-Type": "application/json"
}

Request Body:

{
  "email": "user@example.com",
  "password": "secret"
}

Response Body:

{
  "data": {
    "accessToken": "jwt-token"
  }
}

Auth - Register (AuthContext)

Method: POST Endpoint: /api/auth/register Headers:

{
  "Content-Type": "application/json"
}

Request Body:

{
  "email": "user@example.com",
  "password": "secret",
  "fullName": "User Name"
}

Response Body:

{
  "accessToken": "jwt-token"
}

Auth - Register (Login page direct fetch)

Method: POST Endpoint: http://localhost:8080/api/auth/register Headers:

{
  "Content-Type": "application/json"
}

Request Body:

{
  "fullName": "User Name",
  "email": "user@example.com",
  "password": "secret"
}

Response Body:

{
  "accessToken": "jwt-token"
}

Dashboard - Load stats

Method: GET Endpoint: /api/dashboard/stats Headers:

{
  "Authorization": "Bearer {token}"
}

Request Body:

null

Response Body:

{
  "totalCars": 12,
  "availableCars": 8,
  "activeRentals": 5,
  "monthlyRevenue": 12500.5,
  "pendingRequests": 3
}

Dashboard - Recent rentals for staff

Method: GET Endpoint: /api/rentals/recent Headers:

{
  "Authorization": "Bearer {token}"
}

Request Body:

null

Response Body:

[
  {
    "id": 1,
    "customer_id": "cust-1",
    "car_id": "car-1",
    "pickup_branch_id": "branch-1",
    "return_branch_id": "branch-2",
    "start_date": "2026-07-01",
    "end_date": "2026-07-05",
    "actual_return_date": null,
    "status": "active",
    "price_per_day": 120,
    "total_price": 480,
    "notes": null,
    "approved_by": "staff-1",
    "approved_at": "2026-06-30T10:00:00Z",
    "rejection_reason": null,
    "created_at": "2026-06-25T08:00:00Z",
    "updated_at": "2026-06-30T10:00:00Z",
    "car": {
      "id": "car-1",
      "brand": "Toyota",
      "model": "Avanza",
      "year": 2022,
      "plate_number": "B1234XYZ",
      "price_per_day": 120,
      "status": "active",
      "category_id": "cat-1",
      "branch_id": "branch-1",
      "image_url": null,
      "description": null,
      "seats": 7,
      "transmission": "Automatic",
      "fuel_type": "Petrol",
      "created_at": "2026-01-01T00:00:00Z",
      "updated_at": "2026-06-01T00:00:00Z"
    },
    "customer": {
      "id": "cust-1",
      "email": "user@example.com",
      "full_name": "User Name",
      "phone": null,
      "address": null,
      "driver_license": null,
      "created_at": "2026-01-01T00:00:00Z",
      "updated_at": "2026-01-01T00:00:00Z"
    }
  }
]

Dashboard - Recent rentals for customer

Method: GET Endpoint: /api/rentals/my/recent Headers:

{
  "Authorization": "Bearer {token}"
}

Request Body:

null

Response Body:

[
  {
    "id": 2,
    "customer_id": "cust-1",
    "car_id": "car-2",
    "pickup_branch_id": "branch-1",
    "return_branch_id": "branch-1",
    "start_date": "2026-07-10",
    "end_date": "2026-07-12",
    "actual_return_date": null,
    "status": "requested",
    "price_per_day": 150,
    "total_price": null,
    "notes": "Need baby seat",
    "approved_by": null,
    "approved_at": null,
    "rejection_reason": null,
    "created_at": "2026-07-01T08:00:00Z",
    "updated_at": "2026-07-01T08:00:00Z",
    "car": {
      "id": "car-2",
      "brand": "Honda",
      "model": "Mobilio",
      "year": 2021,
      "plate_number": "B5678XYZ",
      "price_per_day": 150,
      "status": "available",
      "category_id": "cat-1",
      "branch_id": "branch-1",
      "image_url": null,
      "description": null,
      "seats": 7,
      "transmission": "Manual",
      "fuel_type": "Petrol",
      "created_at": "2026-01-02T00:00:00Z",
      "updated_at": "2026-06-02T00:00:00Z"
    }
  }
]

Customers - Get all customers

Method: GET Endpoint: /api/customer/getAllCustomers Headers:

{
  "Authorization": "Bearer {token}"
}

Request Body:

null

Response Body:

{
  "data": [
    {
      "id": 1,
      "fullName": "Customer Name",
      "email": "customer@example.com",
      "phone": "081234567890",
      "createdAt": "2026-06-01T00:00:00Z"
    }
  ]
}

Settings - Get all users

Method: GET Endpoint: /api/user/getAllUsers Headers:

{
  "Authorization": "Bearer {token}"
}

Request Body:

null

Response Body:

[
  {
    "id": 1,
    "user": "user@example.com",
    "roles": ["admin", "staff"],
    "joined": "2026-01-01T00:00:00Z"
  }
]

Cars - Get car categories

Method: GET Endpoint: /api/car-categories Headers:

{
  "Authorization": "Bearer {token}"
}

Request Body:

null

Response Body:

[
  {
    "id": "cat-1",
    "name": "Economy",
    "description": "Budget cars",
    "created_at": "2026-01-01T00:00:00Z"
  }
]

Cars - Get cars list

Method: GET Endpoint: /api/cars Headers:

{
  "Authorization": "Bearer {token}"
}

Query Parameters:

  • page
  • category
  • status
  • min_price
  • max_price

Request Body:

null

Response Body:

[
  {
    "id": "car-1",
    "brand": "Toyota",
    "model": "Avanza",
    "year": 2022,
    "plate_number": "B1234XYZ",
    "price_per_day": 120,
    "status": "available",
    "category_id": "cat-1",
    "branch_id": "branch-1",
    "image_url": null,
    "description": null,
    "seats": 7,
    "transmission": "Automatic",
    "fuel_type": "Petrol",
    "created_at": "2026-01-01T00:00:00Z",
    "updated_at": "2026-06-01T00:00:00Z"
  }
]

Branches - Get branches

Method: GET Endpoint: /api/branches Headers:

{
  "Authorization": "Bearer {token}"
}

Request Body:

null

Response Body:

[
  {
    "id": "branch-1",
    "name": "Central Branch",
    "address": "Jl. Example 1",
    "phone": "081234567890",
    "is_active": true,
    "created_at": "2026-01-01T00:00:00Z",
    "updated_at": "2026-06-01T00:00:00Z"
  }
]

Branches - Create branch

Method: POST Endpoint: /api/branches Headers:

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

Request Body:

{
  "name": "New Branch",
  "address": "Jl. New",
  "phone": "081234567891"
}

Response Body:

{
  "success": true
}

Branches - Update branch

Method: PATCH Endpoint: /api/branches/{id} Headers:

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

Request Body:

{
  "id": "branch-1",
  "name": "Central Branch Updated",
  "address": "Jl. Example 1A",
  "phone": "081234567892"
}

Response Body:

{
  "success": true
}

Branches - Delete branch

Method: DELETE Endpoint: /api/branches/{id} Headers:

{
  "Authorization": "Bearer {token}"
}

Request Body:

null

Response Body:

{
  "success": true
}

Reports - Dashboard metrics

Method: GET Endpoint: /api/reports/dashboard Headers:

{
  "Authorization": "Bearer {token}"
}

Request Body:

null

Response Body:

{
  "total_revenue": 15000.5,
  "total_rentals": 42,
  "completed_rate": 0.85,
  "status_distribution": {
    "requested": 5,
    "approved": 10,
    "active": 7,
    "completed": 18,
    "cancelled": 2,
    "rejected": 0
  }
}

Reports - Monthly revenue

Method: GET Endpoint: /api/reports/revenue Headers:

{
  "Authorization": "Bearer {token}"
}

Query Parameters:

  • period=monthly

Request Body:

null

Response Body:

[
  {
    "month": "Jan",
    "revenue": 4500.0
  },
  {
    "month": "Feb",
    "revenue": 5200.0
  }
]

Reports - Rental stats

Method: GET Endpoint: /api/reports/rentals Headers:

{
  "Authorization": "Bearer {token}"
}

Query Parameters:

  • status=completed

Request Body:

null

Response Body:

{
  "requested": 5,
  "approved": 10,
  "active": 7,
  "completed": 18,
  "cancelled": 2,
  "rejected": 0
}

Rentals - My rentals

Method: GET Endpoint: /api/rentals/my Headers:

{
  "Authorization": "Bearer {token}"
}

Request Body:

null

Response Body:

[
  {
    "id": 3,
    "customer_id": "cust-1",
    "car_id": "car-3",
    "pickup_branch_id": "branch-1",
    "return_branch_id": "branch-1",
    "start_date": "2026-08-01",
    "end_date": "2026-08-05",
    "actual_return_date": null,
    "status": "requested",
    "price_per_day": 100,
    "total_price": null,
    "notes": null,
    "approved_by": null,
    "approved_at": null,
    "rejection_reason": null,
    "created_at": "2026-07-20T00:00:00Z",
    "updated_at": "2026-07-20T00:00:00Z",
    "car": {
      "id": "car-3",
      "brand": "Suzuki",
      "model": "Ertiga",
      "year": 2021,
      "plate_number": "B9101XYZ",
      "price_per_day": 100,
      "status": "available",
      "category_id": "cat-1",
      "branch_id": "branch-1",
      "image_url": null,
      "description": null,
      "seats": 7,
      "transmission": "Automatic",
      "fuel_type": "Petrol",
      "created_at": "2026-01-03T00:00:00Z",
      "updated_at": "2026-06-03T00:00:00Z"
    }
  }
]

Rentals - Rental requests

Method: GET Endpoint: /api/rentals/requests Headers:

{
  "Authorization": "Bearer {token}"
}

Request Body:

null

Response Body:

[
  {
    "id": 4,
    "customer_id": "cust-2",
    "car_id": "car-4",
    "pickup_branch_id": "branch-1",
    "return_branch_id": "branch-1",
    "start_date": "2026-08-10",
    "end_date": "2026-08-12",
    "actual_return_date": null,
    "status": "requested",
    "price_per_day": 130,
    "total_price": null,
    "notes": "Need GPS",
    "approved_by": null,
    "approved_at": null,
    "rejection_reason": null,
    "created_at": "2026-07-22T00:00:00Z",
    "updated_at": "2026-07-22T00:00:00Z"
  }
]

Rentals - All rentals

Method: GET Endpoint: /api/rentals Headers:

{
  "Authorization": "Bearer {token}"
}

Query Parameters:

  • status
  • start
  • end

Request Body:

null

Response Body:

[
  {
    "id": 5,
    "customer_id": "cust-3",
    "car_id": "car-5",
    "pickup_branch_id": "branch-2",
    "return_branch_id": "branch-2",
    "start_date": "2026-08-15",
    "end_date": "2026-08-20",
    "actual_return_date": "2026-08-20",
    "status": "completed",
    "price_per_day": 180,
    "total_price": 900,
    "notes": null,
    "approved_by": "staff-2",
    "approved_at": "2026-08-10T08:00:00Z",
    "rejection_reason": null,
    "created_at": "2026-07-25T00:00:00Z",
    "updated_at": "2026-08-20T00:00:00Z"
  }
]

User Roles - Add role to user

Method: POST Endpoint: /api/users/{id}/roles Headers:

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

Request Body:

{
  "role": "staff"
}

Response Body:

{
  "success": true
}

User Roles - Remove role from user

Method: DELETE Endpoint: /api/users/{id}/roles/{role} Headers:

{
  "Authorization": "Bearer {token}"
}

Request Body:

null

Response Body:

{
  "success": true
}