perbaikan
This commit is contained in:
92
internal/handlers/reference/peserta.go
Normal file
92
internal/handlers/reference/peserta.go
Normal file
@@ -0,0 +1,92 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"api-service/internal/config"
|
||||
services "api-service/internal/services/bpjs"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// PesertaHandler handles BPJS participant operations
|
||||
type PesertaHandler struct {
|
||||
bpjsService services.VClaimService
|
||||
}
|
||||
|
||||
// NewPesertaHandler creates a new PesertaHandler instance
|
||||
func NewPesertaHandler(cfg config.BpjsConfig) *PesertaHandler {
|
||||
return &PesertaHandler{
|
||||
bpjsService: services.NewService(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
// GetPesertaByNIK godoc
|
||||
// @Summary Get participant data by NIK
|
||||
// @Description Search participant data based on Population NIK and service date
|
||||
// @Tags bpjs
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param nik path string true "NIK KTP"
|
||||
// @Param tglSEP path string true "Service date/SEP date (format: yyyy-MM-dd)"
|
||||
// @Success 200 {object} map[string]interface{} "Participant data"
|
||||
// @Failure 400 {object} map[string]interface{} "Bad request"
|
||||
// @Failure 404 {object} map[string]interface{} "Participant not found"
|
||||
// @Failure 500 {object} map[string]interface{} "Internal server error"
|
||||
// @Router /api/v1/bpjs/Peserta/nik/{nik}/tglSEP/{tglSEP} [get]
|
||||
func (h *PesertaHandler) GetPesertaByNIK(c *gin.Context) {
|
||||
nik := c.Param("nik")
|
||||
tglSEP := c.Param("tglSEP")
|
||||
|
||||
// Validate parameters
|
||||
if nik == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "NIK parameter is required",
|
||||
"message": "NIK KTP tidak boleh kosong",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if tglSEP == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "tglSEP parameter is required",
|
||||
"message": "Tanggal SEP tidak boleh kosong",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Validate date format
|
||||
if _, err := time.Parse("2006-01-02", tglSEP); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "Invalid date format",
|
||||
"message": "Format tanggal harus yyyy-MM-dd",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Create context with timeout
|
||||
ctx, cancel := context.WithTimeout(c.Request.Context(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// Build endpoint URL
|
||||
endpoint := fmt.Sprintf("/Peserta/nik/%s/tglSEP/%s", nik, tglSEP)
|
||||
|
||||
// Call BPJS service
|
||||
var result map[string]interface{}
|
||||
if err := h.bpjsService.Get(ctx, endpoint, &result); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "Failed to fetch participant data",
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Return successful response
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "Data peserta berhasil diambil",
|
||||
"data": result,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user