# Project Jahit API Documentation

## Deskripsi Proyek

Project Jahit adalah platform yang menghubungkan pelanggan dengan penjahit. API ini menyediakan endpoint untuk mengelola registrasi pengguna, pencarian penjahit, pemesanan jasa, manajemen galeri dan layanan penjahit, serta sistem rating.

## Base URL

```
http://localhost:8000/api
```

## Autentikasi

API ini menggunakan Laravel Sanctum untuk autentikasi. Token akan diberikan setelah login dan harus disertakan dalam header setiap permintaan ke endpoint yang terproteksi.

Format header:

```
Authorization: Bearer {token}
```

## Roles dan Hak Akses

Sistem memiliki 3 role pengguna:

-   **admin** - Administrator platform
-   **penjahit** - Penjahit/Penyedia jasa
-   **pelanggan** - Pelanggan/Pengguna jasa

## Endpoint API

### Endpoint Publik

#### Test API

```
GET /test
```

Response:

```json
{
    "message": "API is working"
}
```

#### Spesialisasi

```
GET /specializations
```

Mendapatkan semua spesialisasi penjahit yang tersedia.

```
GET /specializations/all
```

Mendapatkan semua spesialisasi dengan detail lengkap.

#### Pencarian Penjahit

```
GET /tailors/search?specialization={id}
```

Mencari penjahit berdasarkan spesialisasi.

#### Detail Penjahit

```
GET /tailors/{id}
```

Mendapatkan detail informasi penjahit berdasarkan ID.

```
GET /tailors/{tailor}/services
```

Mendapatkan daftar layanan yang disediakan penjahit.

```
GET /tailors/{tailor}/gallery
```

Mendapatkan galeri foto penjahit.

```
GET /tailors/{tailor}/ratings
```

Mendapatkan ulasan dan rating untuk penjahit.

### Autentikasi

#### Pelanggan

```
POST /pelanggan/register
```

Registrasi akun pelanggan baru.

Body:

```json
{
    "name": "Nama Pelanggan",
    "email": "pelanggan@example.com",
    "password": "password",
    "password_confirmation": "password",
    "phone_number": "08123456789",
    "address": "Alamat Lengkap"
}
```

```
POST /pelanggan/login
```

Login sebagai pelanggan.

Body:

```json
{
    "email": "pelanggan@example.com",
    "password": "password"
}
```

Response:

```json
{
  "user": {
    "id": 1,
    "name": "Nama Pelanggan",
    "email": "pelanggan@example.com",
    "role": "pelanggan",
    ...
  },
  "token": "access_token_string"
}
```

#### Penjahit

```
POST /penjahit/register
```

Registrasi akun penjahit baru.

Body:

```json
{
    "name": "Nama Penjahit",
    "email": "penjahit@example.com",
    "password": "password",
    "password_confirmation": "password",
    "phone_number": "08123456789",
    "address": "Alamat Lengkap",
    "shop_description": "Deskripsi toko jahit",
    "latitude": -6.123456,
    "longitude": 106.123456,
    "specializations": [1, 2]
}
```

```
POST /penjahit/login
```

Login sebagai penjahit.

Body:

```json
{
    "email": "penjahit@example.com",
    "password": "password"
}
```

#### Admin

```
POST /admin/login
```

Login sebagai admin.

Body:

```json
{
    "email": "admin@example.com",
    "password": "password"
}
```

#### Lupa Password

```
POST /pelanggan/forgot-password
POST /penjahit/forgot-password
```

Mengirimkan email reset password.

Body:

```json
{
    "email": "user@example.com"
}
```

```
POST /pelanggan/reset-password
POST /penjahit/reset-password
```

Reset password dengan token.

Body:

```json
{
    "email": "user@example.com",
    "password": "new_password",
    "password_confirmation": "new_password",
    "token": "reset_token"
}
```

#### Logout

```
POST /logout
```

Logout pengguna (invalidasi token).

Header:

```
Authorization: Bearer {token}
```

### Endpoint Profil

```
GET /profile
```

Mendapatkan informasi profil pengguna yang terautentikasi.

```
POST /profile
```

Mengupdate informasi profil pengguna.

Body:

```json
{
    "name": "Nama Baru",
    "phone_number": "08123456789",
    "address": "Alamat Baru"
}
```

```
POST /profile/photo
```

Mengupload foto profil.

Body (multipart/form-data):

```
profile_photo: [file]
```

### Endpoint Pelanggan

#### Dashboard

```
GET /dashboard
```

Mendapatkan data dashboard pelanggan.

#### Booking

```
GET /bookings/customer
```

Mendapatkan semua booking yang dilakukan pelanggan.

```
GET /bookings/customer/status/{status}
```

Mendapatkan booking pelanggan berdasarkan status (reservasi, diproses, selesai, dibatalkan).

```
GET /bookings/{booking}
```

Mendapatkan detail booking.

```
POST /tailors/{tailor}/book
```

Membuat booking baru ke penjahit.

Body:

```json
{
    "appointment_date": "2023-05-01",
    "appointment_time": "10:00",
    "service_type": "Jahit Baju",
    "category": "Baju Wanita",
    "notes": "Catatan tambahan",
    "total_price": 150000
}
```

```
POST /bookings
```

Membuat booking baru.

Body (multipart/form-data):

```
customer_id: 1
tailor_id: 2
appointment_date: 2023-05-01
appointment_time: 10:00
service_type: Jahit Baju
category: Baju Wanita
notes: Catatan tambahan
design_photo: [file]
total_price: 150000
```

```
POST /bookings/{booking}/cancel
```

Membatalkan booking.

```
POST /bookings/{booking}/rate
```

Memberikan rating dan ulasan.

Body:

```json
{
    "rating": 5,
    "review": "Pelayanan sangat baik"
}
```

```
PUT /ratings/{rating}
```

Mengupdate rating dan ulasan.

Body:

```json
{
    "rating": 4,
    "review": "Pelayanan baik"
}
```

```
POST /bookings/{booking}/completion-payment
```

Menyelesaikan pembayaran akhir booking.

### Endpoint Penjahit

#### Dashboard

```
GET /penjahit/dashboard
```

Mendapatkan data dashboard penjahit.

#### Pembayaran

```
POST /bookings/{booking}/payment
```

Mengubah status pembayaran booking menjadi paid (hanya penjahit yang dapat melakukan).

Body:

```json
{
    "payment_status": "paid"
}
```

```
POST /bookings/{booking}/completion-payment
```

Menyelesaikan pembayaran akhir booking dan mengatur tanggal pengambilan (hanya penjahit yang dapat melakukan).

Body:

```json
{
    "pickup_date": "2023-05-15"
}
```

#### Spesialisasi

```
POST /penjahit/specializations
```

Mengupdate spesialisasi penjahit.

Body:

```json
{
    "specializations": [1, 3, 5]
}
```

#### Kalender

```
GET /penjahit/calendar/{month}/{year}
```

Mendapatkan jadwal booking dalam bulan dan tahun tertentu.

```
GET /penjahit/calendar/date/{date}
```

Mendapatkan jadwal booking pada tanggal tertentu.

#### Profil Toko

```
GET /penjahit/shop-profile
```

Mendapatkan profil toko penjahit.

```
POST /penjahit/shop-profile
```

Mengupdate profil toko penjahit.

Body:

```json
{
    "shop_description": "Deskripsi toko baru",
    "address": "Alamat toko baru",
    "latitude": -6.123456,
    "longitude": 106.123456
}
```

```
DELETE /penjahit/shop-profile/photo
```

Menghapus foto profil toko.

#### Galeri

```
GET /penjahit/gallery
```

Mendapatkan semua galeri penjahit.

```
POST /penjahit/gallery
```

Menambahkan foto ke galeri penjahit.

Body (multipart/form-data):

```
photo: [file]
description: Deskripsi foto
```

```
PUT /penjahit/gallery/{gallery}
```

Mengupdate deskripsi foto galeri.

Body:

```json
{
    "description": "Deskripsi baru"
}
```

```
DELETE /penjahit/gallery/{gallery}
```

Menghapus foto dari galeri.

#### Layanan

```
GET /penjahit/services
```

Mendapatkan semua layanan penjahit.

```
POST /penjahit/services
```

Menambahkan layanan baru.

Body:

```json
{
    "name": "Nama Layanan",
    "description": "Deskripsi layanan",
    "price": 100000,
    "is_available": true
}
```

```
PUT /penjahit/services/{service}
```

Mengupdate informasi layanan.

Body:

```json
{
    "name": "Nama Layanan Baru",
    "description": "Deskripsi baru",
    "price": 150000,
    "is_available": true
}
```

```
DELETE /penjahit/services/{service}
```

Menghapus layanan.

```
PATCH /penjahit/services/{service}/toggle
```

Mengaktifkan/menonaktifkan layanan.

#### Booking

```
GET /penjahit/bookings
```

Mendapatkan semua booking penjahit.

```
GET /penjahit/bookings/status/{status}
```

Mendapatkan booking penjahit berdasarkan status.

```
POST /bookings/{booking}/accept
```

Menerima booking baru.

```
POST /bookings/{booking}/reject
```

Menolak booking.

Body:

```json
{
    "rejection_reason": "Jadwal penuh"
}
```

```
PATCH /bookings/{booking}/status
```

Mengupdate status booking.

Body:

```json
{
    "status": "diproses"
}
```

```
PATCH /bookings/{booking}/price
```

Mengupdate harga booking.

Body:

```json
{
    "total_price": 200000
}
```

```
POST /bookings/{booking}/measurements
```

Mengupdate ukuran jahitan.

Body:

```json
{
    "measurements": {
        "lingkar_dada": 90,
        "lingkar_pinggang": 70,
        "panjang_lengan": 60
    }
}
```

```
POST /bookings/{booking}/repair
```

Mengupdate detail perbaikan.

Body (multipart/form-data):

```
repair_details: {"jenis_perbaikan": "Ubah ukuran", "bagian": "Lengan"}
repair_notes: Catatan perbaikan
repair_photo: [file]
```

```
POST /bookings/{booking}/complete
```

Menyelesaikan booking.

Body (multipart/form-data):

```
completion_notes: Catatan penyelesaian
completion_photo: [file]
pickup_date: 2023-05-15
```

### Endpoint Admin

#### Dashboard

```
GET /admin/dashboard
```

Mendapatkan data dashboard admin.

#### Manajemen Pelanggan

```
GET /customers
```

Mendapatkan semua data pelanggan.

```
GET /customers/{id}
```

Mendapatkan detail pelanggan.

#### Manajemen Booking

```
GET /bookings
```

Mendapatkan semua data booking.

#### Manajemen Penjahit

```
GET /tailors
```

Mendapatkan semua data penjahit.

```
GET /tailors/all
```

Mendapatkan semua data penjahit tanpa filter rating.

## Model Data

### User

-   id
-   name
-   email
-   password
-   role (admin, penjahit, pelanggan)
-   phone_number
-   address
-   shop_description (untuk penjahit)
-   profile_photo
-   latitude
-   longitude
-   created_at
-   updated_at

### Booking

-   id
-   customer_id
-   tailor_id
-   appointment_date
-   appointment_time
-   service_type
-   category
-   design_photo
-   notes
-   status (reservasi, diproses, selesai, dibatalkan)
-   total_price
-   payment_status (unpaid, paid)
-   measurements
-   repair_details
-   repair_photo
-   repair_notes
-   completion_photo
-   completion_notes
-   accepted_at
-   rejected_at
-   completed_at
-   rejection_reason
-   pickup_date
-   created_at
-   updated_at

### TailorSpecialization

-   id
-   name
-   description
-   photo
-   created_at
-   updated_at

### TailorService

-   id
-   user_id
-   name
-   description
-   price
-   is_available
-   created_at
-   updated_at

### TailorGallery

-   id
-   user_id
-   photo
-   description
-   created_at
-   updated_at

### TailorRating

-   id
-   booking_id
-   tailor_id
-   customer_id
-   rating
-   review
-   created_at
-   updated_at

## Kode Status HTTP

-   200 OK - Request berhasil
-   201 Created - Resource berhasil dibuat
-   400 Bad Request - Request tidak valid
-   401 Unauthorized - Tidak terotentikasi
-   403 Forbidden - Tidak memiliki izin
-   404 Not Found - Resource tidak ditemukan
-   422 Unprocessable Entity - Validasi gagal
-   500 Internal Server Error - Kesalahan server

## Format Error Response

```json
{
    "message": "Pesan error",
    "errors": {
        "field1": ["Error message 1", "Error message 2"],
        "field2": ["Error message"]
    }
}
```

## Contoh Penggunaan

### Registrasi Pelanggan

Request:

```
POST /api/pelanggan/register
Content-Type: application/json

{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "password123",
  "password_confirmation": "password123",
  "phone_number": "08123456789",
  "address": "Jl. Example No. 123"
}
```

Response:

```
200 OK
Content-Type: application/json

{
  "user": {
    "id": 1,
    "name": "John Doe",
    "email": "john@example.com",
    "role": "pelanggan",
    "phone_number": "08123456789",
    "address": "Jl. Example No. 123",
    "created_at": "2023-05-01T10:00:00.000000Z",
    "updated_at": "2023-05-01T10:00:00.000000Z"
  },
  "token": "access_token_string"
}
```

### Penjahit Mengubah Status Pembayaran

Request:

```
POST /api/bookings/1/payment
Content-Type: application/json
Authorization: Bearer {token_penjahit}

{
  "payment_status": "paid"
}
```

Response:

```
200 OK
Content-Type: application/json

{
  "status": "success",
  "message": "Status pembayaran berhasil diubah menjadi paid oleh penjahit.",
  "data": {
    "booking": {
      "id": 1,
      "customer_name": "John Doe",
      "payment_status": "paid",
      "status": "reservasi",
      "total_price": "150000.00",
      "appointment_date": "2023-05-10"
    }
  }
}
```

### Penjahit Menyelesaikan Pembayaran Akhir

Request:

```
POST /api/bookings/1/completion-payment
Content-Type: application/json
Authorization: Bearer {token_penjahit}

{
  "pickup_date": "2023-05-15"
}
```

Response:

```
200 OK
Content-Type: application/json

{
  "status": "success",
  "message": "Pembayaran telah dikonfirmasi dan tanggal pengambilan berhasil diatur",
  "data": {
    "booking": {
      "id": 1,
      "customer_name": "John Doe",
      "customer_phone": "08123456789",
      "payment_status": "paid",
      "status": "selesai",
      "pickup_date": "2023-05-15"
    },
    "message": "Pembayaran telah dikonfirmasi oleh penjahit",
    "pickup_info": {
      "date": "2023-05-15",
      "status": "Sudah dibayar"
    }
  }
}
```

### Pencarian Penjahit

Request:

```
GET /api/tailors/search?specialization=1
Authorization: Bearer {token}
```

Response:

```
200 OK
Content-Type: application/json

{
  "tailors": [
    {
      "id": 2,
      "name": "Tailor Shop",
      "address": "Jl. Tailor No. 456",
      "shop_description": "Toko jahit profesional",
      "profile_photo": "storage/profile_photos/photo.jpg",
      "rating": 4.5,
      "specializations": [
        {
          "id": 1,
          "name": "Jahit Baju Wanita"
        }
      ]
    }
  ]
}
```

### Membuat Booking

Request:

```
POST /api/bookings
Content-Type: multipart/form-data
Authorization: Bearer {token}

customer_id: 1
tailor_id: 2
appointment_date: 2023-05-10
appointment_time: 14:00
service_type: Jahit Baju
category: Kemeja
notes: Bahan sudah tersedia
design_photo: [file upload]
total_price: 150000
```

Response:

```
201 Created
Content-Type: application/json

{
  "booking": {
    "id": 1,
    "customer_id": 1,
    "tailor_id": 2,
    "appointment_date": "2023-05-10",
    "appointment_time": "14:00",
    "service_type": "Jahit Baju",
    "category": "Kemeja",
    "notes": "Bahan sudah tersedia",
    "design_photo": "storage/design_photos/design.jpg",
    "status": "reservasi",
    "total_price": "150000.00",
    "payment_status": "unpaid",
    "created_at": "2023-05-01T10:30:00.000000Z",
    "updated_at": "2023-05-01T10:30:00.000000Z"
  }
}
```

## File dan Media

### Upload File

Untuk endpoint yang memerlukan upload file, gunakan format `multipart/form-data` dan kirimkan file sebagai form field.

### Akses File Media

File media bisa diakses dengan URL:

```
http://localhost:8000/storage/{path}
```

Contoh:

```
http://localhost:8000/storage/design_photos/file.jpg
http://localhost:8000/storage/gallery_photos/photo.jpg
http://localhost:8000/storage/profile_photos/avatar.jpg
```
