Perbaikan tool bpjs

This commit is contained in:
2025-09-03 19:24:55 +07:00
parent 1ab7687e68
commit 8311311615
11 changed files with 1896 additions and 415 deletions

View File

@@ -42,6 +42,7 @@ type Service struct {
Name string `yaml:"name"`
Category string `yaml:"category"`
Package string `yaml:"package"`
SubPackage string `yaml:"sub_package"`
Description string `yaml:"description"`
BaseURL string `yaml:"base_url"`
Timeout int `yaml:"timeout"`
@@ -113,6 +114,7 @@ type EndpointData struct {
PatchPath string
Model string
ResponseModel string
DataModel string // Data model name (e.g., PesertaData)
Description string
Summary string
Tags []string
@@ -142,6 +144,7 @@ package {{.Package}}
import (
"context"
"encoding/json"
"strings"
"net/http"
"time"
@@ -244,9 +247,9 @@ func (h *{{$.ServiceName}}Handler) Get{{.Name}}(c *gin.Context) {
{{range .PathParams}}
endpoint = strings.Replace(endpoint, ":{{.}}", {{.}}, 1)
{{end}}
err := h.service.Get(ctx, endpoint, &response)
rawResponse, err := h.service.GetRawResponse(ctx, endpoint)
{{else}}
err := h.service.Get(ctx, "{{.GetPath}}", &response)
rawResponse, err := h.service.GetRawResponse(ctx, "{{.GetPath}}")
{{end}}
if err != nil {
{{if $.HasLogger}}
@@ -263,7 +266,25 @@ func (h *{{$.ServiceName}}Handler) Get{{.Name}}(c *gin.Context) {
return
}
// Ensure response has proper fields
// Map raw response to structured data
var data {{.ModelPackage}}.{{.DataModel}}
if err := json.Unmarshal(rawResponse, &data); err != nil {
{{if $.HasLogger}}
h.logger.Error("Failed to unmarshal {{.Name}} data", map[string]interface{}{
"error": err.Error(),
"request_id": requestID,
})
{{end}}
c.JSON(http.StatusInternalServerError, models.ErrorResponseBpjs{
Status: "error",
Message: "Failed to process response data",
RequestID: requestID,
})
return
}
// Set response data
response.Data = data
response.Status = "success"
response.RequestID = requestID
c.JSON(http.StatusOK, response)
@@ -336,7 +357,7 @@ func (h *{{$.ServiceName}}Handler) Create{{.Name}}(c *gin.Context) {
// Call service method
var response {{.ModelPackage}}.{{.ResponseModel}}
err := h.service.Post(ctx, "{{.PostPath}}", &req, &response)
rawResponse, err := h.service.PostRawResponse(ctx, "{{.PostPath}}", &req)
if err != nil {
{{if $.HasLogger}}
h.logger.Error("Failed to create {{.Name}}", map[string]interface{}{
@@ -352,7 +373,25 @@ func (h *{{$.ServiceName}}Handler) Create{{.Name}}(c *gin.Context) {
return
}
// Ensure response has proper fields
// Map raw response to structured data
var data {{.ModelPackage}}.{{.DataModel}}
if err := json.Unmarshal(rawResponse, &data); err != nil {
{{if $.HasLogger}}
h.logger.Error("Failed to unmarshal {{.Name}} data", map[string]interface{}{
"error": err.Error(),
"request_id": requestID,
})
{{end}}
c.JSON(http.StatusInternalServerError, models.ErrorResponseBpjs{
Status: "error",
Message: "Failed to process response data",
RequestID: requestID,
})
return
}
// Set response data
response.Data = data
response.Status = "success"
response.RequestID = requestID
c.JSON(http.StatusCreated, response)
@@ -448,9 +487,9 @@ func (h *{{$.ServiceName}}Handler) Update{{.Name}}(c *gin.Context) {
{{range .PathParams}}
endpoint = strings.Replace(endpoint, ":{{.}}", {{.}}, 1)
{{end}}
err := h.service.Put(ctx, endpoint, &req, &response)
rawResponse, err := h.service.PutRawResponse(ctx, endpoint, &req)
{{else}}
err := h.service.Put(ctx, "{{.PutPath}}", &req, &response)
rawResponse, err := h.service.PutRawResponse(ctx, "{{.PutPath}}", &req)
{{end}}
if err != nil {
{{if $.HasLogger}}
@@ -467,7 +506,25 @@ func (h *{{$.ServiceName}}Handler) Update{{.Name}}(c *gin.Context) {
return
}
// Ensure response has proper fields
// Map raw response to structured data
var data {{.ModelPackage}}.{{.DataModel}}
if err := json.Unmarshal(rawResponse, &data); err != nil {
{{if $.HasLogger}}
h.logger.Error("Failed to unmarshal {{.Name}} data", map[string]interface{}{
"error": err.Error(),
"request_id": requestID,
})
{{end}}
c.JSON(http.StatusInternalServerError, models.ErrorResponseBpjs{
Status: "error",
Message: "Failed to process response data",
RequestID: requestID,
})
return
}
// Set response data
response.Data = data
response.Status = "success"
response.RequestID = requestID
c.JSON(http.StatusOK, response)
@@ -530,9 +587,9 @@ func (h *{{$.ServiceName}}Handler) Delete{{.Name}}(c *gin.Context) {
{{range .PathParams}}
endpoint = strings.Replace(endpoint, ":{{.}}", {{.}}, 1)
{{end}}
err := h.service.Delete(ctx, endpoint, &response)
rawResponse, err := h.service.DeleteRawResponse(ctx, endpoint)
{{else}}
err := h.service.Delete(ctx, "{{.DeletePath}}", &response)
rawResponse, err := h.service.DeleteRawResponse(ctx, "{{.DeletePath}}")
{{end}}
if err != nil {
{{if $.HasLogger}}
@@ -549,7 +606,25 @@ func (h *{{$.ServiceName}}Handler) Delete{{.Name}}(c *gin.Context) {
return
}
// Ensure response has proper fields
// Map raw response to structured data
var data {{.ModelPackage}}.{{.DataModel}}
if err := json.Unmarshal(rawResponse, &data); err != nil {
{{if $.HasLogger}}
h.logger.Error("Failed to unmarshal {{.Name}} data", map[string]interface{}{
"error": err.Error(),
"request_id": requestID,
})
{{end}}
c.JSON(http.StatusInternalServerError, models.ErrorResponseBpjs{
Status: "error",
Message: "Failed to process response data",
RequestID: requestID,
})
return
}
// Set response data
response.Data = data
response.Status = "success"
response.RequestID = requestID
c.JSON(http.StatusOK, response)
@@ -940,6 +1015,7 @@ func processEndpoint(name string, endpoint Endpoint, endpointGroup string) Endpo
PatchPath: endpoint.PatchPath,
Model: endpoint.Model,
ResponseModel: endpoint.ResponseModel,
DataModel: strings.Replace(endpoint.ResponseModel, "Response", "Data", 1),
Description: endpoint.Description,
Summary: endpoint.Summary,
Tags: endpoint.Tags,