# API Quick Reference - Mobile Absensi

**Base URL:** `https://your-domain.com/api`

---

## Quick Reference Table

| No | Endpoint | Method | Auth | Description |
|----|----------|--------|------|-------------|
| 1 | `/app-version/check` | POST | No | Check app version & maintenance |
| 2 | `/app-version/latest/{platform}` | GET | No | Get latest version info |
| 3 | `/login` | POST | No | Login & get JWT token |
| 4 | `/absenmasuk` | POST | Yes | Check-in |
| 5 | `/absenpulang` | POST | Yes | Check-out |
| 6 | `/getabsen` | POST | Yes | Get attendance history |
| 7 | `/kantor` | POST | Yes | Get office location |
| 8 | `/device-reset/request` | POST | No | Request device reset |
| 9 | `/device-reset/my-request` | POST | No | Check reset status |
| 10 | `/blogs/published` | GET | Yes | Get news list |
| 11 | `/blogs/featured` | GET | Yes | Get featured news |
| 12 | `/blogs/{id}` | GET | Yes | Get news detail |
| 13 | `/notifications` | GET | Yes | Get notifications |
| 14 | `/notifications/unread-count` | GET | Yes | Get unread count |
| 15 | `/notifications/{id}/read` | POST | Yes | Mark as read |
| 16 | `/notifications/read-all` | POST | Yes | Mark all as read |
| 17 | `/fcm/register` | POST | Yes | Register FCM token |
| 18 | `/fcm/unregister` | POST | Yes | Unregister FCM token |

---

## Request/Response Examples

### 0. Check App Version (CALL FIRST!)
```http
POST /api/app-version/check
Content-Type: application/json

{
    "platform": "android",
    "build_number": 15
}
```
```json
// Response 200 - No update
{
    "rcode": "00",
    "message": "Version check completed",
    "data": {
        "needs_update": false,
        "force_update": false,
        "maintenance_mode": false
    }
}

// Response 200 - Force update required
{
    "rcode": "00",
    "message": "Update required",
    "data": {
        "needs_update": true,
        "force_update": true,
        "maintenance_mode": false,
        "update_message": "Update wajib!",
        "store_url": "https://play.google.com/..."
    }
}

// Response 200 - Maintenance mode
{
    "rcode": "00",
    "message": "App under maintenance",
    "data": {
        "maintenance_mode": true,
        "maintenance_message": "Sedang maintenance..."
    }
}
```

### 1. Login
```http
POST /api/login
Content-Type: application/json

{
    "npp": "10001",
    "password": "password123",
    "device_id": "unique-device-id"
}
```
```json
// Response 200
{
    "rcode": "00",
    "nama": "John Doe",
    "kode_kantor": "0001",
    "nama_kantor": "Kantor Pusat",
    "group": "User",
    "access_token": "eyJ0eXAiOiJKV1QiLCJhbGci...",
    "token_type": "Bearer",
    "message": "authenticated"
}
```

### 2. Check-in
```http
POST /api/absenmasuk
Authorization: Bearer {token}
Content-Type: application/json

{
    "latitude": "-6.2088",
    "longitude": "106.8456",
    "branch_id": "0001"
}
```
```json
// Response 200
{
    "rcode": "00",
    "message": "Check-in successful"
}
```

### 3. Check-out
```http
POST /api/absenpulang
Authorization: Bearer {token}
Content-Type: application/json

{
    "latitude": "-6.2088",
    "longitude": "106.8456",
    "branch_id": "0001"
}
```
```json
// Response 200
{
    "rcode": "00",
    "message": "Check-out successful"
}
```

### 4. Get Attendance History
```http
POST /api/getabsen
Authorization: Bearer {token}
Content-Type: application/json

{
    "year": "2026",
    "month": "1"
}
```
```json
// Response 200
{
    "rcode": "00",
    "message": "Success",
    "data": [
        {
            "tanggal": "2026-01-30",
            "jam_masuk": "08:00",
            "jam_keluar": "17:00",
            "ket_absensi": "-"
        }
    ]
}
```

### 5. Get Office Location
```http
POST /api/kantor
Authorization: Bearer {token}
Content-Type: application/json

{
    "kode_kantor": "0001",
    "npp": "10001"
}
```
```json
// Response 200
{
    "rcode": "00",
    "message": "Success",
    "data": {
        "kode_kantor": "0001",
        "nama_kantor": "Kantor Pusat",
        "latitude": "-6.2088",
        "longitude": "106.8456",
        "radius": 100
    }
}
```

### 6. Request Device Reset
```http
POST /api/device-reset/request
Content-Type: application/json

{
    "npp": "10001",
    "reason": "Handphone rusak dan sudah diganti dengan yang baru"
}
```
```json
// Response 201
{
    "rcode": "00",
    "message": "Permintaan reset device berhasil diajukan. Mohon tunggu approval dari admin.",
    "data": {
        "id": 1,
        "npp": "10001",
        "status": "pending"
    }
}
```

### 7. Check Reset Status
```http
POST /api/device-reset/my-request
Content-Type: application/json

{
    "npp": "10001"
}
```
```json
// Response 200
{
    "rcode": "00",
    "message": "Success",
    "data": [
        {
            "id": 1,
            "status": "approved",
            "created_at": "2026-01-30T10:00:00Z"
        }
    ]
}
```

### 8. Get Published Blogs
```http
GET /api/blogs/published?limit=10&category=announcement
Authorization: Bearer {token}
```
```json
// Response 200
{
    "rcode": "00",
    "message": "Success",
    "data": [
        {
            "id": 1,
            "title": "Pengumuman Libur",
            "slug": "pengumuman-libur",
            "excerpt": "...",
            "image_thumbnail": "blogs/thumb.jpg",
            "category": "announcement",
            "published_at": "2026-01-15T08:00:00Z"
        }
    ]
}
```

### 9. Get Notifications
```http
GET /api/notifications?npp=10001&is_read=false
Authorization: Bearer {token}
```
```json
// Response 200
{
    "rcode": "00",
    "message": "Success",
    "data": {
        "data": [
            {
                "id": 1,
                "title": "Reminder Absen",
                "body": "Jangan lupa absen!",
                "is_read": false
            }
        ],
        "total": 5
    }
}
```

### 10. Register FCM Token
```http
POST /api/fcm/register
Authorization: Bearer {token}
Content-Type: application/json

{
    "npp": "10001",
    "fcm_token": "cKPLxxx:APA91bHxxx...",
    "device_type": "android",
    "device_id": "unique-device-id"
}
```
```json
// Response 200
{
    "rcode": "00",
    "message": "FCM token registered successfully"
}
```

---

## Response Codes

| rcode | Description |
|-------|-------------|
| `00` | Success |
| `01` | Validation Error |
| `81` | Not Found |
| `82` | Duplicate/Conflict |
| `83` | Business Rule Error |
| `99` | Server Error |

---

## Error Responses

### Validation Error (422)
```json
{
    "rcode": "01",
    "message": "Validation failed",
    "errors": {
        "field_name": ["Error message"]
    }
}
```

### Not Found (404)
```json
{
    "rcode": "81",
    "message": "Resource not found"
}
```

### Unauthorized (401)
```json
{
    "message": "Token is expired"
}
```

---

## Important Notes

1. **Authorization Header Format:**
   ```
   Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGci...
   ```

2. **NPP Auto-detect:** Endpoints absensi otomatis mengambil NPP dari JWT token

3. **Device Binding:** 1 device = 1 user

4. **Image URLs:** Prefix with `https://your-domain.com/storage/`

5. **Rate Limits:**
   - Login: 5 req/min
   - Others: 60 req/min
