# ๐Ÿš€ API Service - CRUD Management System > **Sistem manajemen retribusi modern dengan arsitektur bersih untuk pengelolaan data retribusi pemerintah** ## ๐Ÿ“‘ Daftar Isi - [โœจ Fitur Utama](#-fitur-utama) - [๐Ÿ—๏ธ Arsitektur](#%EF%B8%8F-arsitektur) - [โšก Quick Start](#-quick-start) - [๐Ÿ” Autentikasi](#-autentikasi) - [๐Ÿ“Š API Endpoints](#-api-endpoints) - [๐Ÿ› ๏ธ Development](#%EF%B8%8F-development) - [๐Ÿš€ Deployment](#-deployment) - [๐Ÿ“š Dokumentasi](#-dokumentasi) *** ## โœจ Fitur Utama ### Core Features - **๐Ÿ”’ JWT Authentication** - Sistem autentikasi dengan Keycloak integration - **๐Ÿ“‹ Retribusi Management** - CRUD lengkap untuk data retribusi - **๐Ÿ” Dynamic Filtering** - Filter dan pencarian data retribusi secara dinamis - **๐Ÿ“Š Advanced Search** - Pencarian dengan multiple fields dan operators - **๐Ÿฅ BPJS Integration** - Integrasi dengan layanan kesehatan BPJS - **๐Ÿฉบ SATUSEHAT Integration** - Integrasi dengan platform kesehatan SATUSEHAT - **๐Ÿ“– API Documentation** - Swagger/OpenAPI yang interaktif ### Developer Experience - **๐Ÿ”ฅ Hot Reload** - Development dengan auto-restart - **๐Ÿณ Docker Ready** - Deployment yang mudah - **โšก Code Generator** - Tools untuk generate handler dan model - **๐Ÿงช Testing Suite** - Unit dan integration tests - **๐Ÿ“Š Health Monitoring** - Monitoring kesehatan aplikasi - **๐Ÿ—„๏ธ Multi Database** - Support PostgreSQL, MySQL, dan MongoDB *** ## ๐Ÿ—๏ธ Arsitektur ### Clean Architecture Layers ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ Presentation Layer โ”‚ โ† handlers/, routes/ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ Application Layer โ”‚ โ† middleware/, services/ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ Domain Layer โ”‚ โ† models/, validation/ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ Infrastructure Layer โ”‚ โ† database/, external APIs โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` ### Struktur Project ``` api-service/ โ”œโ”€โ”€ ๐Ÿ“ cmd/ โ”‚ โ”œโ”€โ”€ api/main.go # ๐Ÿšช Entry point aplikasi โ”‚ โ””โ”€โ”€ logging/main.go # ๐Ÿ” Logging service โ”œโ”€โ”€ ๐Ÿ“ internal/ # ๐Ÿ  Core business logic โ”‚ โ”œโ”€โ”€ config/ # โš™๏ธ Configuration management โ”‚ โ”œโ”€โ”€ database/ # ๐Ÿ—„๏ธ Database connections โ”‚ โ”œโ”€โ”€ handlers/ # ๐ŸŽฎ HTTP controllers โ”‚ โ”‚ โ”œโ”€โ”€ auth/ # ๐Ÿ” Authentication handlers โ”‚ โ”‚ โ”œโ”€โ”€ healthcheck/ # ๐Ÿ’š Health check handlers โ”‚ โ”‚ โ””โ”€โ”€ retribusi/ # ๐Ÿ“‹ Retribusi handlers โ”‚ โ”œโ”€โ”€ middleware/ # ๐Ÿ›ก๏ธ Auth & validation middleware โ”‚ โ”œโ”€โ”€ models/ # ๐Ÿ“Š Data structures โ”‚ โ”‚ โ”œโ”€โ”€ auth/ # ๐Ÿ‘ค Auth models โ”‚ โ”‚ โ””โ”€โ”€ retribusi/ # ๐Ÿ“‹ Retribusi models โ”‚ โ”œโ”€โ”€ routes/ # ๐Ÿ›ฃ๏ธ API routing โ”‚ โ”œโ”€โ”€ services/ # ๐Ÿ’ผ Business logic services โ”‚ โ”‚ โ””โ”€โ”€ auth/ # ๐Ÿ” Auth services โ”‚ โ”œโ”€โ”€ utils/ # ๐Ÿ› ๏ธ Utility functions โ”‚ โ”‚ โ”œโ”€โ”€ filters/ # ๐Ÿ” Dynamic filtering โ”‚ โ”‚ โ””โ”€โ”€ validation/ # โœ… Data validation โ”‚ โ””โ”€โ”€ server/ # ๐ŸŒ HTTP server setup โ”œโ”€โ”€ ๐Ÿ“ docs/ # ๐Ÿ“š Documentation โ”œโ”€โ”€ ๐Ÿ“ examples/ # ๐Ÿ’ก Example files โ”œโ”€โ”€ ๐Ÿ“ scripts/ # ๐Ÿ“œ Automation scripts โ””โ”€โ”€ ๐Ÿ“ tools/ # ๐Ÿ”ง Development tools ``` *** ## โšก Quick Start ### 1๏ธโƒฃ Setup Environment (2 menit) ```bash # Clone repository git clone cd api-service # Setup environment cp example.env .env ``` ### 2๏ธโƒฃ Pilih Method Setup **๐Ÿณ Docker (Recommended)** ```bash make docker-run ``` **๐Ÿ”ง Manual Setup** ```bash # Install dependencies go mod download # Start server go run cmd/api/main.go ``` ### Update Swagger Documentation ```bash swag init -g cmd/api/main.go -o docs/ ``` ### 3๏ธโƒฃ Verify Installation | Service | URL | Status | | :-- | :-- | :-- | | **API** | http://localhost:8080/api/v1 | โœ… | | **Swagger** | http://localhost:8080/swagger/index.html | ๐Ÿ“– | | **Health Check** | http://localhost:8080/api/sistem/health | ๐Ÿ’š | *** ## ๐Ÿ” Autentikasi ### Login & Mendapatkan Token ```bash curl -X POST http://localhost:8080/api/v1/auth/login \ -H "Content-Type: application/json" \ -d '{ "username": "admin", "password": "password" }' ``` **Response:** ```json { "access_token": "eyJhbGciOiJIUzI1NiIs...", "expires_in": 3600, "user": { "id": "123", "username": "admin", "role": "admin" } } ``` ### Menggunakan Token ```bash curl -X GET http://localhost:8080/api/v1/retribusi \ -H "Authorization: Bearer " ``` ### Demo Accounts | Username | Password | Role | Akses | | :-- | :-- | :-- | | `admin` | `password` | Admin | Semua endpoint | | `user` | `password` | User | Read-only | *** ## ๐Ÿ“Š API Endpoints ### ๐ŸŒ Public Endpoints | Method | Endpoint | Deskripsi | | :-- | :-- | :-- | | `POST` | `/api/v1/auth/login` | Login pengguna | | `POST` | `/api/v1/auth/register` | Registrasi pengguna baru | | `GET` | `/api/sistem/health` | Status kesehatan API | | `GET` | `/api/sistem/info` | Informasi sistem | ### ๐Ÿ”’ Protected Endpoints #### System Information | Method | Endpoint | Deskripsi | | :-- | :-- | :-- | | `GET` | `/api/sistem/databases` | Informasi database connections | #### Retribusi Management | Method | Endpoint | Deskripsi | | :-- | :-- | :-- | | `GET` | `/api/v1/retribusi` | List semua retribusi dengan pagination | | `GET` | `/api/v1/retribusi/dynamic` | Query retribusi dengan filter dinamis | | `GET` | `/api/v1/retribusi/search` | Pencarian retribusi advanced | | `GET` | `/api/v1/retribusi/id/:id` | Detail retribusi by ID | | `POST` | `/api/v1/retribusi` | Buat retribusi baru | | `PUT` | `/api/v1/retribusi/id/:id` | Update retribusi | | `DELETE` | `/api/v1/retribusi/id/:id` | Hapus retribusi (soft delete) | #### Dynamic Query Examples **Filter berdasarkan jenis:** ```bash GET /api/v1/retribusi/dynamic?filter[Jenis][_eq]=RETRIBUSI PELAYANAN KESEHATAN ``` **Kombinasi filter:** ```bash GET /api/v1/retribusi/dynamic?filter[status][_eq]=active&filter[Tarif][_gt]=100000 ``` **Pagination dan sorting:** ```bash GET /api/v1/retribusi/dynamic?sort=-date_created&limit=10&offset=20 ``` **Advanced search:** ```bash GET /api/v1/retribusi/search?q=rumah%20sakit&limit=20&offset=0 ``` ### ๐Ÿฅ External Integrations #### BPJS Integration | Method | Endpoint | Deskripsi | | :-- | :-- | :-- | | `GET` | `/api/v1/bpjs/peserta/:no` | Data peserta BPJS | | `GET` | `/api/v1/bpjs/rujukan/:no` | Data rujukan | #### SATUSEHAT Integration | Method | Endpoint | Deskripsi | | :-- | :-- | :-- | | `GET` | `/api/v1/satusehat/patient/:id` | Data pasien | | `POST` | `/api/v1/satusehat/encounter` | Buat encounter baru | *** ## ๐Ÿ› ๏ธ Development ### Development Commands ```bash # ๐Ÿ”ฅ Development dengan hot reload make watch # ๐Ÿƒ Run server make run # ๐Ÿงช Testing make test # Unit tests make itest # Integration tests # ๐Ÿณ Docker operations make docker-run # Start all services make docker-down # Stop all services # ๐Ÿ” Code quality make build # Build application make clean # Clean build artifacts ``` ### Environment Configuration **๐Ÿ“ .env File:** ```bash # Server Configuration PORT=8080 GIN_MODE=debug # Database Configuration DB_CONNECTION=postgres DB_HOST=localhost DB_PORT=5432 DB_USERNAME=postgres DB_PASSWORD=postgres DB_DATABASE=api_service # PostgreSQL Satudata Database POSTGRES_SATUDATA_CONNECTION=postgres POSTGRES_SATUDATA_HOST=localhost POSTGRES_SATUDATA_PORT=5432 POSTGRES_SATUDATA_USERNAME=postgres POSTGRES_SATUDATA_PASSWORD=postgres POSTGRES_SATUDATA_DATABASE=satu_db # MongoDB Configuration MONGODB_MONGOHL7_CONNECTION=mongodb MONGODB_MONGOHL7_HOST=localhost MONGODB_MONGOHL7_PORT=27017 MONGODB_MONGOHL7_USER=admin MONGODB_MONGOHL7_PASS=password # MySQL Medical Database MYSQL_MEDICAL_CONNECTION=mysql MYSQL_MEDICAL_HOST=localhost MYSQL_MEDICAL_PORT=3306 MYSQL_MEDICAL_USERNAME=user MYSQL_MEDICAL_PASSWORD=password MYSQL_MEDICAL_DATABASE=healtcare_database # JWT Configuration JWT_SECRET=your-super-secret-key-change-in-production # Keycloak Configuration KEYCLOAK_ISSUER=https://auth.rssa.top/realms/sandbox KEYCLOAK_AUDIENCE=nuxtsim-pendaftaran KEYCLOAK_JWKS_URL=https://auth.rssa.top/realms/sandbox/protocol/openid-connect/certs KEYCLOAK_ENABLED=true # BPJS Configuration BPJS_BASEURL=https://apijkn.bpjs-kesehatan.go.id/vclaim-dev BPJS_CONSID=52667757 BPJS_USERKEY=4cf1cbef811314fvdgrc008440bbe9ef9ba789e482 BPJS_SECRETKEY=1bV36ASDQQ3512D ``` ### Code Generation **Generate Handler untuk Retribusi:** ```bash # Generate handler dasar go run tools/general/generate-handler.go retribusi get post put delete # Generate dengan fitur advanced go run tools/general/generate-handler.go retribusi get post put delete dynamic search stats # Config go run tools/general/generate-handler.go --config tools/general/services-config.yaml --verbose ``` *** ## ๐Ÿš€ Deployment ### ๐Ÿณ Docker Deployment **Development:** ```bash # Start semua services make docker-run # Stop services make docker-down ``` **Production:** ```bash # Build production image docker build -t api-service:prod . # Run production container docker run -d \ --name api-service \ -p 8080:8080 \ --env-file .env.prod \ api-service:prod ``` ### ๐Ÿ”ง Manual Deployment ```bash # Build aplikasi make build # Start server ./main ``` ### ๐Ÿ“‹ Environment Variables untuk Production ```bash # Server Configuration APP_ENV=production PORT=8080 GIN_MODE=release # Database Configuration DB_CONNECTION=postgres DB_HOST=10.10.123.165 DB_PORT=5432 DB_USERNAME=stim DB_PASSWORD=stim*RS54 DB_DATABASE=satu_db # Security JWT_SECRET=your-production-secret-key KEYCLOAK_ENABLED=true # External Services BPJS_BASEURL=https://apijkn.bpjs-kesehatan.go.id/vclaim-rest BRIDGING_SATUSEHAT_BASE_URL=https://api-satusehat.kemkes.go.id/fhir-r4/v1 ``` *** ## ๐Ÿ“š Dokumentasi ### ๐Ÿ“– Interactive API Documentation Kunjungi **Swagger UI** di: http://localhost:8080/swagger/index.html **Cara menggunakan:** 1. ๐Ÿ”‘ Login melalui `/auth/login` endpoint 2. ๐Ÿ“‹ Copy token dari response 3. ๐Ÿ”“ Klik tombol "Authorize" di Swagger 4. ๐Ÿ“ Masukkan: `Bearer ` 5. โœ… Test semua endpoint yang tersedia ### ๐Ÿงช Testing Examples **JavaScript/Axios:** ```javascript // Login dan set token const auth = await axios.post('/api/v1/auth/login', { username: 'admin', password: 'password' }); axios.defaults.headers.common['Authorization'] = `Bearer ${auth.data.access_token}`; // Fetch retribusi data const retribusi = await axios.get('/api/v1/retribusi'); console.log(retribusi.data); ``` **cURL Examples:** ```bash # Login TOKEN=$(curl -s -X POST http://localhost:8080/api/v1/auth/login \ -H "Content-Type: application/json" \ -d '{"username":"admin","password":"password"}' | jq -r '.access_token') # Get retribusi data curl -H "Authorization: Bearer $TOKEN" \ http://localhost:8080/api/v1/retribusi # Dynamic filtering curl -H "Authorization: Bearer $TOKEN" \ "http://localhost:8080/api/v1/retribusi/dynamic?filter[Jenis][_eq]=RETRIBUSI%20PELAYANAN%20KESEHATAN" ``` ### ๐Ÿ” Health Monitoring ```bash # Basic health check curl http://localhost:8080/api/sistem/health # Database status curl http://localhost:8080/api/sistem/databases # System info curl http://localhost:8080/api/sistem/info ``` **Response:** ```json { "status": "healthy", "timestamp": "2025-01-10T05:39:00Z", "services": { "database": "connected", "keycloak": "accessible", "bpjs_api": "accessible", "satusehat_api": "accessible" }, "version": "1.0.0" } ``` *** ## ๐Ÿšจ Troubleshooting ### Masalah Umum **โŒ Database Connection Error** ```bash # Cek status database make docker-run # Check logs docker logs api-service # Verify environment variables cat .env | grep DB_ ``` **โŒ Authentication Error** - ๐Ÿ”„ Pastikan Keycloak service berjalan - โœ… Cek KEYCLOAK_ISSUER URL - ๐Ÿ“ Format token harus: `Bearer ` **โŒ Dynamic Filter Error** - โœ… Pastikan field name sesuai dengan database - ๐Ÿ” Cek syntax filter: `filter[field][operator]=value` - ๐Ÿ“ Operator yang didukung: `_eq`, `_neq`, `_gt`, `_lt`, `_contains` ### Debug Mode ```bash # Enable debug logging export GIN_MODE=debug # Run dengan verbose output make run # Monitor dengan hot reload make watch ``` *** ## ๐ŸŽฏ Next Steps ### ๐Ÿ“‹ Development Roadmap - [ ] โœ… **Setup environment selesai** - [ ] โœ… **Implementasi retribusi management** - [ ] โœ… **Setup authentication dengan Keycloak** - [ ] ๐Ÿ”„ **Integrasi BPJS dan SATUSEHAT** - [ ] ๐Ÿ”„ **Testing dan validation** - [ ] ๐Ÿ”„ **Setup monitoring dan logging** - [ ] ๐Ÿ”„ **Deploy ke production** ### ๐Ÿš€ Advanced Features - **๐Ÿ“Š Real-time Dashboard** - **๐Ÿ”’ Enhanced Security (Rate limiting, CORS)** - **๐Ÿ“ˆ Performance Monitoring** - **๐ŸŒ API Versioning** - **๐Ÿ“ฑ Mobile SDK Integration** *** **โšก Total setup time: 5 menit | ๐Ÿ”ง Generate Handler: 30 detik | ๐Ÿงช Testing: Langsung via Swagger** > **๐Ÿ’ก Pro Tip:** Gunakan `make help` untuk melihat semua command yang tersedia ***