{
  "openapi": "3.0.3",
  "info": {
    "title": "API Insta — Flutter Workshop",
    "version": "1.0.0",
    "description": "REST API sederhana mirip Instagram untuk workshop consume API dengan Flutter. Sudah dilengkapi 10 post default foto member Hearts2Hearts.\n\n**Akun default (password: `123456`):** `carmen_h2h`, `jiwoo_h2h`, `yuha_h2h`, `stella_h2h`, `juun_h2h`, `ana_h2h`, `ian_h2h`, `yeon_h2h`, `hearts2hearts`.\n\n**Cara pakai Auth di Swagger UI:**\n1. Panggil endpoint `POST /api/login` atau `POST /api/register` untuk mendapatkan `token`.\n2. Klik tombol **Authorize** di kanan atas.\n3. Masukkan token tersebut (tanpa kata `Bearer`), lalu klik **Authorize**."
  },
  "servers": [
    {
      "url": "/",
      "description": "Server aktif saat ini"
    }
  ],
  "tags": [
    {
      "name": "Auth",
      "description": "Register, Login, Logout, dan Cek User Aktif"
    },
    {
      "name": "Posts",
      "description": "List, Detail, Buat, Edit, dan Hapus Post"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Token",
        "description": "Masukkan token yang didapat dari `/api/login` atau `/api/register`"
      }
    },
    "schemas": {
      "AuthRequest": {
        "type": "object",
        "required": ["username", "password"],
        "properties": {
          "username": {
            "type": "string",
            "example": "carmen_h2h"
          },
          "password": {
            "type": "string",
            "example": "123456"
          }
        }
      },
      "AuthResponse": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "example": "Login berhasil"
          },
          "data": {
            "type": "object",
            "properties": {
              "username": {
                "type": "string",
                "example": "carmen_h2h"
              },
              "token": {
                "type": "string",
                "example": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822c"
              }
            }
          }
        }
      },
      "PostItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "1"
          },
          "author": {
            "type": "object",
            "properties": {
              "username": {
                "type": "string",
                "example": "carmen_h2h"
              }
            }
          },
          "post": {
            "type": "object",
            "properties": {
              "image": {
                "type": "string",
                "format": "uri",
                "example": "http://localhost:3000/uploads/defaults/carmen.jpg"
              },
              "desc": {
                "type": "string",
                "example": "Halo S2U! Senang banget bisa ketemu kalian semua hari ini 🩵✨ #Carmen #Hearts2Hearts"
              }
            }
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "example": "2026-02-24T10:00:00.000Z"
          }
        }
      },
      "MessageResponse": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "example": "Berhasil"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "example": "Terjadi kesalahan"
          }
        }
      }
    }
  },
  "paths": {
    "/api/register": {
      "post": {
        "tags": ["Auth"],
        "summary": "Register akun baru",
        "description": "Mendaftarkan akun baru hanya dengan `username` dan `password` (minimal 4 karakter). Langsung mengembalikan `token`.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AuthRequest"
              },
              "example": {
                "username": "peserta_flutter",
                "password": "password123"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Register berhasil",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthResponse"
                }
              }
            }
          },
          "400": {
            "description": "Validasi gagal (field kosong atau password < 4 karakter)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Username sudah terdaftar",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/login": {
      "post": {
        "tags": ["Auth"],
        "summary": "Login akun",
        "description": "Masuk dengan `username` dan `password` untuk mendapatkan Bearer `token`.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AuthRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Login berhasil",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthResponse"
                }
              }
            }
          },
          "400": {
            "description": "Username atau password kosong",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Username atau password salah",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/logout": {
      "post": {
        "tags": ["Auth"],
        "summary": "Logout",
        "description": "Menghapus token aktif dari server sehingga token tidak bisa digunakan lagi.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Logout berhasil",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MessageResponse"
                },
                "example": {
                  "message": "Logout berhasil"
                }
              }
            }
          },
          "401": {
            "description": "Token tidak valid atau belum login",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/me": {
      "get": {
        "tags": ["Auth"],
        "summary": "Cek user yang sedang login",
        "description": "Mengembalikan `username` dari token yang sedang aktif. Berguna untuk mengecek status login saat aplikasi Flutter dibuka.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Authenticated",
            "content": {
              "application/json": {
                "example": {
                  "message": "Authenticated",
                  "data": {
                    "username": "carmen_h2h"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Token tidak valid atau sudah logout",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/posts": {
      "get": {
        "tags": ["Posts"],
        "summary": "Ambil list semua post (Public)",
        "description": "Endpoint public untuk mengambil semua post tanpa perlu login/autentikasi (default berisi 10 post foto member Hearts2Hearts).",
        "responses": {
          "200": {
            "description": "Berhasil mengambil list post",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Berhasil mengambil list post"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PostItem"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/posts": {
      "get": {
        "tags": ["Posts"],
        "summary": "Ambil list semua post",
        "description": "Mengembalikan semua post (default berisi 10 post foto member Hearts2Hearts). Tidak membutuhkan autentikasi.",
        "responses": {
          "200": {
            "description": "Berhasil mengambil list post",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Berhasil mengambil list post"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PostItem"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": ["Posts"],
        "summary": "Buat post baru (upload gambar + desc)",
        "description": "Membuat post baru dengan mengunggah file gambar (`image`, maksimal 5MB) dan deskripsi (`desc`) menggunakan `multipart/form-data`.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["image"],
                "properties": {
                  "image": {
                    "type": "string",
                    "format": "binary",
                    "description": "File gambar (jpg, png, webp, dll, maks 5MB)"
                  },
                  "desc": {
                    "type": "string",
                    "description": "Caption / deskripsi post",
                    "example": "Postingan pertamaku dari Flutter!"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Post berhasil dibuat",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Post berhasil dibuat"
                    },
                    "data": {
                      "$ref": "#/components/schemas/PostItem"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Gambar belum diupload atau format tidak valid",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/posts/{id}": {
      "get": {
        "tags": ["Posts"],
        "summary": "Ambil detail 1 post",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "1"
          }
        ],
        "responses": {
          "200": {
            "description": "Berhasil mengambil detail post",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Berhasil mengambil detail post"
                    },
                    "data": {
                      "$ref": "#/components/schemas/PostItem"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Post tidak ditemukan",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      },
      "put": {
        "tags": ["Posts"],
        "summary": "Edit post (milik sendiri)",
        "description": "Mengubah `desc` dan/atau `image` pada post. Mendukung `application/json` (jika hanya ubah `desc`) maupun `multipart/form-data` (jika ingin mengganti gambar). Hanya author post yang dapat mengedit.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "1"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "image": {
                    "type": "string",
                    "format": "binary",
                    "description": "File gambar baru (opsional)"
                  },
                  "desc": {
                    "type": "string",
                    "description": "Caption / deskripsi baru (opsional)",
                    "example": "Caption sudah diperbarui!"
                  }
                }
              }
            },
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "desc": {
                    "type": "string",
                    "example": "Caption sudah diperbarui!"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Post berhasil diupdate",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Post berhasil diupdate"
                    },
                    "data": {
                      "$ref": "#/components/schemas/PostItem"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Bukan pemilik post",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Post tidak ditemukan",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": ["Posts"],
        "summary": "Hapus post (milik sendiri)",
        "description": "Menghapus post berdasarkan `id`. Hanya author post yang dapat menghapus.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "1"
          }
        ],
        "responses": {
          "200": {
            "description": "Post berhasil dihapus",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MessageResponse"
                },
                "example": {
                  "message": "Post berhasil dihapus"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Bukan pemilik post",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Post tidak ditemukan",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  }
}
