Perbaikan Tools, Perbaikan

This commit is contained in:
2025-08-19 10:48:40 +07:00
parent 4d72e31352
commit 615db47606
9 changed files with 314 additions and 18 deletions

View File

@@ -0,0 +1,85 @@
package handlers
import (
"context"
"fmt"
"net/http"
"time"
"api-service/internal/config"
services "api-service/internal/services/bpjs"
"github.com/gin-gonic/gin"
)
// DiagnosaHandler handles BPJS diagnosa operations
type DiagnosaHandler struct {
bpjsService services.VClaimService
}
// NewDiagnosaHandler creates a new DiagnosaHandler instance
func NewDiagnosaHandler(cfg config.BpjsConfig) *DiagnosaHandler {
return &DiagnosaHandler{
bpjsService: services.NewService(cfg),
}
}
// GetAll godoc
// @Summary Get all diagnosa reference data
// @Description Get all diagnosa reference data
// @Tags bpjs/reference
// @Accept json
// @Produce json
// @Success 200 {object} models.DiagnosaResponse "Success response"
// @Failure 400 {object} map[string]interface{} "Bad request"
// @Failure 404 {object} map[string]interface{} "Data not found"
// @Failure 500 {object} map[string]interface{} "Internal server error"
// @Router /api/v1/bpjs/reference/referensi/diagnosa [get]
func (h *DiagnosaHandler) GetAll(c *gin.Context) {
// Create context with timeout
ctx, cancel := context.WithTimeout(c.Request.Context(), 30*time.Second)
defer cancel()
// Build endpoint URL
endpoint := "/referensi/diagnosa"
// 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 diagnosa data",
"message": err.Error(),
})
return
}
// Return successful response
c.JSON(http.StatusOK, gin.H{
"message": "Data diagnosa berhasil diambil",
"data": result,
})
}
// Helper methods for error handling and response formatting
// handleBPJSError handles BPJS service errors and returns appropriate HTTP responses
func (h *DiagnosaHandler) handleBPJSError(c *gin.Context, err error, operation string) {
c.JSON(http.StatusInternalServerError, gin.H{
"error": fmt.Sprintf("Failed to %s", operation),
"message": err.Error(),
})
}
// validateDateFormat validates if the date string is in yyyy-MM-dd format
func (h *DiagnosaHandler) validateDateFormat(dateStr string) error {
_, err := time.Parse("2006-01-02", dateStr)
return err
}
// buildSuccessResponse builds a standardized success response
func (h *DiagnosaHandler) buildSuccessResponse(message string, data interface{}) gin.H {
return gin.H{
"message": message,
"data": data,
}
}

View File

@@ -0,0 +1,47 @@
package models
// DiagnosaResponse represents the response structure for BPJS diagnosa data
type DiagnosaResponse struct {
Message string `json:"message"`
Data map[string]interface{} `json:"data"`
}
// DiagnosaRawResponse represents the raw response structure from BPJS API
type DiagnosaRawResponse struct {
MetaData struct {
Code string `json:"code"`
Message string `json:"message"`
} `json:"metaData"`
Response interface{} `json:"response"`
}
// DiagnosaData represents the diagnosa reference data structure
type DiagnosaData struct {
KdDiag string `json:"kdDiag"`
NmDiag string `json:"nmDiag"`
}
// DiagnosaListResponse represents the response structure for diagnosa list
type DiagnosaListResponse struct {
Diagnosa []DiagnosaData `json:"diagnosa"`
}
// ErrorResponse represents error response structure
type ErrorResponse struct {
Error string `json:"error"`
Message string `json:"message"`
Code int `json:"code,omitempty"`
}
// BPJSMetaData represents BPJS API metadata structure
type BPJSMetaData struct {
Code string `json:"code"`
Message string `json:"message"`
}
// DiagnosaFilter represents filter parameters for diagnosa queries
type DiagnosaFilter struct {
NIK *string `form:"nik" json:"nik,omitempty"`
TglSEP *string `form:"tglSEP" json:"tglSEP,omitempty"`
}

View File

@@ -1,6 +1,7 @@
package v1
import (
bpjsDiagnosaHandlers "api-service/internal/handlers/bpjs/reference"
bpjsPesertaHandlers "api-service/internal/handlers/bpjs/reference"
retribusiHandlers "api-service/internal/handlers/retribusi"
@@ -61,6 +62,10 @@ func RegisterRoutes(cfg *config.Config) *gin.Engine {
bpjsPesertaHandler := bpjsPesertaHandlers.NewPesertaHandler(cfg.Bpjs)
v1.GET("/bpjs/Peserta/nik/:nik/tglSEP/:tglSEP", bpjsPesertaHandler.GetPesertaByNIK)
// BPJS Diagnosa endpoints
bpjsDiagnosaHandler := bpjsDiagnosaHandlers.NewDiagnosaHandler(cfg.Bpjs)
v1.GET("/bpjs/reference/referensi/diagnosa", bpjsDiagnosaHandler.GetAll)
protected := v1.Group("/")
protected.Use(middleware.JWTAuthMiddleware(authService))
{