perbaikan

This commit is contained in:
2025-08-26 22:46:21 +07:00
parent 7c16fd17f8
commit e118b20129
5 changed files with 34 additions and 992 deletions

View File

@@ -1,5 +1,4 @@
// Code generated by swaggo/swag. DO NOT EDIT.
// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs
import "github.com/swaggo/swag"
@@ -663,213 +662,6 @@ const docTemplate = `{
}
}
},
"/api/v1/surkon/spri": {
"put": {
"description": "Update an existing Spri in BPJS system with enhanced validation and logging",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Surkon-Spri"
],
"summary": "Update an existing SPRI",
"parameters": [
{
"description": "Spri update request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.SpriPutRequest"
}
}
],
"responses": {
"200": {
"description": "Spri updated successfully",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"400": {
"description": "Bad request - validation error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"422": {
"description": "Unprocessable entity - business logic error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
}
}
},
"post": {
"description": "Create a new Spri in BPJS system with enhanced validation and logging",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Surkon-Spri"
],
"summary": "Create a new SPRI",
"parameters": [
{
"description": "Spri creation request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.SpriPostRequest"
}
}
],
"responses": {
"200": {
"description": "Spri created successfully",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"400": {
"description": "Bad request - validation error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"422": {
"description": "Unprocessable entity - business logic error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
}
}
}
},
"/api/v1/surkon/spri/{id}": {
"get": {
"description": "Retrieve a Spri by ID with enhanced validation and logging",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Surkon-Spri"
],
"summary": "Get an existing SPRI",
"parameters": [
{
"type": "string",
"description": "Spri ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Data Spri retrieved successfully",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"400": {
"description": "Bad request - invalid ID",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"404": {
"description": "Spri not found",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
}
}
},
"delete": {
"description": "Delete a Spri by ID with enhanced validation and logging",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Surkon-Spri"
],
"summary": "Delete an existing SPRI",
"parameters": [
{
"type": "string",
"description": "Spri ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "User identifier",
"name": "user",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "Spri deleted successfully",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"400": {
"description": "Bad request - missing parameters",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"422": {
"description": "Unprocessable entity - business logic error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
}
}
}
},
"/api/v1/token/generate": {
"post": {
"description": "Generate a JWT token for a user",
@@ -1600,161 +1392,6 @@ const docTemplate = `{
"type": "object",
"additionalProperties": {}
},
"internal_models_surkon.ErrorResponse": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"details": {
"type": "string"
},
"message": {
"type": "string"
}
}
},
"models.ResponseMetadata": {
"type": "object",
"properties": {
"request_id": {
"type": "string"
},
"timestamp": {
"type": "string"
},
"version": {
"type": "string"
}
}
},
"models.SpriPost": {
"type": "object",
"required": [
"jnsPelayanan",
"noKartu",
"ppkPelayanan",
"tglLayanan",
"user"
],
"properties": {
"catatan": {
"type": "string",
"maxLength": 200
},
"jnsPelayanan": {
"type": "string",
"enum": [
"1",
"2"
]
},
"noKartu": {
"description": "Core BPJS fields - customize based on your specific requirements",
"type": "string",
"maxLength": 13,
"minLength": 13
},
"ppkPelayanan": {
"type": "string"
},
"tglLayanan": {
"type": "string"
},
"user": {
"type": "string"
}
}
},
"models.SpriPostRequest": {
"type": "object",
"required": [
"tsep"
],
"properties": {
"request_id": {
"type": "string"
},
"timestamp": {
"type": "string"
},
"tsep": {
"$ref": "#/definitions/models.SpriPost"
}
}
},
"models.SpriPut": {
"type": "object",
"required": [
"id",
"user"
],
"properties": {
"catatan": {
"type": "string",
"maxLength": 200
},
"id": {
"type": "string"
},
"jnsPelayanan": {
"type": "string",
"enum": [
"1",
"2"
]
},
"noKartu": {
"type": "string",
"maxLength": 13,
"minLength": 13
},
"ppkPelayanan": {
"type": "string"
},
"tglLayanan": {
"type": "string"
},
"user": {
"type": "string"
}
}
},
"models.SpriPutRequest": {
"type": "object",
"required": [
"tsep"
],
"properties": {
"request_id": {
"type": "string"
},
"timestamp": {
"type": "string"
},
"tsep": {
"$ref": "#/definitions/models.SpriPut"
}
}
},
"models.SpriResponse": {
"type": "object",
"properties": {
"data": {},
"error": {
"$ref": "#/definitions/internal_models_surkon.ErrorResponse"
},
"message": {
"type": "string"
},
"metadata": {
"$ref": "#/definitions/models.ResponseMetadata"
},
"status": {
"type": "string"
}
}
},
"sql.NullString": {
"type": "object",
"properties": {
@@ -1792,6 +1429,8 @@ var SwaggerInfo = &swag.Spec{
Description: "A comprehensive Go API service with Swagger documentation",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}
func init() {

View File

@@ -660,213 +660,6 @@
}
}
},
"/api/v1/surkon/spri": {
"put": {
"description": "Update an existing Spri in BPJS system with enhanced validation and logging",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Surkon-Spri"
],
"summary": "Update an existing SPRI",
"parameters": [
{
"description": "Spri update request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.SpriPutRequest"
}
}
],
"responses": {
"200": {
"description": "Spri updated successfully",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"400": {
"description": "Bad request - validation error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"422": {
"description": "Unprocessable entity - business logic error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
}
}
},
"post": {
"description": "Create a new Spri in BPJS system with enhanced validation and logging",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Surkon-Spri"
],
"summary": "Create a new SPRI",
"parameters": [
{
"description": "Spri creation request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.SpriPostRequest"
}
}
],
"responses": {
"200": {
"description": "Spri created successfully",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"400": {
"description": "Bad request - validation error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"422": {
"description": "Unprocessable entity - business logic error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
}
}
}
},
"/api/v1/surkon/spri/{id}": {
"get": {
"description": "Retrieve a Spri by ID with enhanced validation and logging",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Surkon-Spri"
],
"summary": "Get an existing SPRI",
"parameters": [
{
"type": "string",
"description": "Spri ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Data Spri retrieved successfully",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"400": {
"description": "Bad request - invalid ID",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"404": {
"description": "Spri not found",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
}
}
},
"delete": {
"description": "Delete a Spri by ID with enhanced validation and logging",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Surkon-Spri"
],
"summary": "Delete an existing SPRI",
"parameters": [
{
"type": "string",
"description": "Spri ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "User identifier",
"name": "user",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "Spri deleted successfully",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"400": {
"description": "Bad request - missing parameters",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"422": {
"description": "Unprocessable entity - business logic error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/models.SpriResponse"
}
}
}
}
},
"/api/v1/token/generate": {
"post": {
"description": "Generate a JWT token for a user",
@@ -1597,161 +1390,6 @@
"type": "object",
"additionalProperties": {}
},
"internal_models_surkon.ErrorResponse": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"details": {
"type": "string"
},
"message": {
"type": "string"
}
}
},
"models.ResponseMetadata": {
"type": "object",
"properties": {
"request_id": {
"type": "string"
},
"timestamp": {
"type": "string"
},
"version": {
"type": "string"
}
}
},
"models.SpriPost": {
"type": "object",
"required": [
"jnsPelayanan",
"noKartu",
"ppkPelayanan",
"tglLayanan",
"user"
],
"properties": {
"catatan": {
"type": "string",
"maxLength": 200
},
"jnsPelayanan": {
"type": "string",
"enum": [
"1",
"2"
]
},
"noKartu": {
"description": "Core BPJS fields - customize based on your specific requirements",
"type": "string",
"maxLength": 13,
"minLength": 13
},
"ppkPelayanan": {
"type": "string"
},
"tglLayanan": {
"type": "string"
},
"user": {
"type": "string"
}
}
},
"models.SpriPostRequest": {
"type": "object",
"required": [
"tsep"
],
"properties": {
"request_id": {
"type": "string"
},
"timestamp": {
"type": "string"
},
"tsep": {
"$ref": "#/definitions/models.SpriPost"
}
}
},
"models.SpriPut": {
"type": "object",
"required": [
"id",
"user"
],
"properties": {
"catatan": {
"type": "string",
"maxLength": 200
},
"id": {
"type": "string"
},
"jnsPelayanan": {
"type": "string",
"enum": [
"1",
"2"
]
},
"noKartu": {
"type": "string",
"maxLength": 13,
"minLength": 13
},
"ppkPelayanan": {
"type": "string"
},
"tglLayanan": {
"type": "string"
},
"user": {
"type": "string"
}
}
},
"models.SpriPutRequest": {
"type": "object",
"required": [
"tsep"
],
"properties": {
"request_id": {
"type": "string"
},
"timestamp": {
"type": "string"
},
"tsep": {
"$ref": "#/definitions/models.SpriPut"
}
}
},
"models.SpriResponse": {
"type": "object",
"properties": {
"data": {},
"error": {
"$ref": "#/definitions/internal_models_surkon.ErrorResponse"
},
"message": {
"type": "string"
},
"metadata": {
"$ref": "#/definitions/models.ResponseMetadata"
},
"status": {
"type": "string"
}
}
},
"sql.NullString": {
"type": "object",
"properties": {

View File

@@ -307,112 +307,6 @@ definitions:
gin.H:
additionalProperties: {}
type: object
internal_models_surkon.ErrorResponse:
properties:
code:
type: string
details:
type: string
message:
type: string
type: object
models.ResponseMetadata:
properties:
request_id:
type: string
timestamp:
type: string
version:
type: string
type: object
models.SpriPost:
properties:
catatan:
maxLength: 200
type: string
jnsPelayanan:
enum:
- "1"
- "2"
type: string
noKartu:
description: Core BPJS fields - customize based on your specific requirements
maxLength: 13
minLength: 13
type: string
ppkPelayanan:
type: string
tglLayanan:
type: string
user:
type: string
required:
- jnsPelayanan
- noKartu
- ppkPelayanan
- tglLayanan
- user
type: object
models.SpriPostRequest:
properties:
request_id:
type: string
timestamp:
type: string
tsep:
$ref: '#/definitions/models.SpriPost'
required:
- tsep
type: object
models.SpriPut:
properties:
catatan:
maxLength: 200
type: string
id:
type: string
jnsPelayanan:
enum:
- "1"
- "2"
type: string
noKartu:
maxLength: 13
minLength: 13
type: string
ppkPelayanan:
type: string
tglLayanan:
type: string
user:
type: string
required:
- id
- user
type: object
models.SpriPutRequest:
properties:
request_id:
type: string
timestamp:
type: string
tsep:
$ref: '#/definitions/models.SpriPut'
required:
- tsep
type: object
models.SpriResponse:
properties:
data: {}
error:
$ref: '#/definitions/internal_models_surkon.ErrorResponse'
message:
type: string
metadata:
$ref: '#/definitions/models.ResponseMetadata'
status:
type: string
type: object
sql.NullString:
properties:
string:
@@ -865,144 +759,6 @@ paths:
summary: Get retribusi statistics
tags:
- retribusi
/api/v1/surkon/spri:
post:
consumes:
- application/json
description: Create a new Spri in BPJS system with enhanced validation and logging
parameters:
- description: Spri creation request
in: body
name: request
required: true
schema:
$ref: '#/definitions/models.SpriPostRequest'
produces:
- application/json
responses:
"200":
description: Spri created successfully
schema:
$ref: '#/definitions/models.SpriResponse'
"400":
description: Bad request - validation error
schema:
$ref: '#/definitions/models.SpriResponse'
"422":
description: Unprocessable entity - business logic error
schema:
$ref: '#/definitions/models.SpriResponse'
"500":
description: Internal server error
schema:
$ref: '#/definitions/models.SpriResponse'
summary: Create a new SPRI
tags:
- Surkon-Spri
put:
consumes:
- application/json
description: Update an existing Spri in BPJS system with enhanced validation
and logging
parameters:
- description: Spri update request
in: body
name: request
required: true
schema:
$ref: '#/definitions/models.SpriPutRequest'
produces:
- application/json
responses:
"200":
description: Spri updated successfully
schema:
$ref: '#/definitions/models.SpriResponse'
"400":
description: Bad request - validation error
schema:
$ref: '#/definitions/models.SpriResponse'
"422":
description: Unprocessable entity - business logic error
schema:
$ref: '#/definitions/models.SpriResponse'
"500":
description: Internal server error
schema:
$ref: '#/definitions/models.SpriResponse'
summary: Update an existing SPRI
tags:
- Surkon-Spri
/api/v1/surkon/spri/{id}:
delete:
consumes:
- application/json
description: Delete a Spri by ID with enhanced validation and logging
parameters:
- description: Spri ID
in: path
name: id
required: true
type: string
- description: User identifier
in: query
name: user
required: true
type: string
produces:
- application/json
responses:
"200":
description: Spri deleted successfully
schema:
$ref: '#/definitions/models.SpriResponse'
"400":
description: Bad request - missing parameters
schema:
$ref: '#/definitions/models.SpriResponse'
"422":
description: Unprocessable entity - business logic error
schema:
$ref: '#/definitions/models.SpriResponse'
"500":
description: Internal server error
schema:
$ref: '#/definitions/models.SpriResponse'
summary: Delete an existing SPRI
tags:
- Surkon-Spri
get:
consumes:
- application/json
description: Retrieve a Spri by ID with enhanced validation and logging
parameters:
- description: Spri ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: Data Spri retrieved successfully
schema:
$ref: '#/definitions/models.SpriResponse'
"400":
description: Bad request - invalid ID
schema:
$ref: '#/definitions/models.SpriResponse'
"404":
description: Spri not found
schema:
$ref: '#/definitions/models.SpriResponse'
"500":
description: Internal server error
schema:
$ref: '#/definitions/models.SpriResponse'
summary: Get an existing SPRI
tags:
- Surkon-Spri
/api/v1/token/generate:
post:
consumes:

View File

@@ -70,7 +70,6 @@ func RegisterRoutes(cfg *config.Config) *gin.Engine {
// BPJS endpoints
bpjsPesertaHandler := bpjsPesertaHandlers.NewPesertaHandler(cfg.Bpjs)
v1.GET("/bpjs/peserta/nik/:nik/tglSEP/:tglSEP", bpjsPesertaHandler.GetPesertaByNIK)
// ============= PUBLISHED ROUTES ===============================================
// // Retribusi endpoints

View File

@@ -134,7 +134,7 @@ func main() {
// Generate files
generateHandlerFile(data, handlerDir)
generateModelFile(data, modelDir)
updateRoutesFile(data)
// updateRoutesFile(data)
fmt.Printf("✅ Successfully generated handler: %s\n", entityName)
if category != "" {
@@ -186,19 +186,19 @@ import (
)
var (
db database.Service
once sync.Once
validate *validator.Validate
` + data.NameLower + `db database.Service
` + data.NameLower + `once sync.Once
` + data.NameLower + `validate *validator.Validate
)
// Initialize the database connection and validator
func init() {
once.Do(func() {
db = database.New(config.LoadConfig())
validate = validator.New()
` + data.NameLower + `once.Do(func() {
` + data.NameLower + `db = database.New(config.LoadConfig())
` + data.NameLower + `validate = validator.New()
// Register custom validations if needed
validate.RegisterValidation("` + data.NameLower + `_status", validate` + data.Name + `Status)
if db == nil {
` + data.NameLower + `validate.RegisterValidation("` + data.NameLower + `_status", validate` + data.Name + `Status)
if ` + data.NameLower + `db == nil {
log.Fatal("Failed to initialize database connection")
}
})
@@ -217,7 +217,7 @@ type ` + data.Name + `Handler struct {
// New` + data.Name + `Handler creates a new ` + data.Name + `Handler
func New` + data.Name + `Handler() *` + data.Name + `Handler {
return &` + data.Name + `Handler{
db: db,
db: ` + data.NameLower + `db,
}
}`
@@ -578,7 +578,7 @@ func (h *` + data.Name + `Handler) Create` + data.Name + `(c *gin.Context) {
}
// Validate request
if err := validate.Struct(&req); err != nil {
if err := ` + data.NameLower + `validate.Struct(&req); err != nil {
h.respondError(c, "Validation failed", err, http.StatusBadRequest)
return
}
@@ -648,7 +648,7 @@ func (h *` + data.Name + `Handler) Update` + data.Name + `(c *gin.Context) {
req.ID = id
// Validate request
if err := validate.Struct(&req); err != nil {
if err := ` + data.NameLower + `validate.Struct(&req); err != nil {
h.respondError(c, "Validation failed", err, http.StatusBadRequest)
return
}
@@ -967,18 +967,28 @@ func (h *` + data.Name + `Handler) fetch` + data.Name + `sDynamic(ctx context.Co
return items, total, nil
}
// Optimized scanning function yang menggunakan sql.Null* types langsung
func (h *` + data.Name + `Handler) scan` + data.Name + `(rows *sql.Rows) (models` + data.NameLower + `.` + data.Name + `, error) {
var item models` + data.NameLower + `.` + data.Name + `
return item, rows.Scan(
&item.ID, &item.Status, &item.Sort, &item.UserCreated,
&item.DateCreated, &item.UserUpdated, &item.DateUpdated, &item.Name,
)
}`
`
}
helperMethods += `
// Optimized scanning function
func (h *` + data.Name + `Handler) scan` + data.Name + `(rows *sql.Rows) (models` + data.NameLower + `.` + data.Name + `, error) {
var item models` + data.NameLower + `.` + data.Name + `
// Scan into individual fields to handle nullable types properly
err := rows.Scan(
&item.ID,
&item.Status,
&item.Sort.Int32, &item.Sort.Valid, // models.NullableInt32
&item.UserCreated.String, &item.UserCreated.Valid, // sql.NullString
&item.DateCreated.Time, &item.DateCreated.Valid, // sql.NullTime
&item.UserUpdated.String, &item.UserUpdated.Valid, // sql.NullString
&item.DateUpdated.Time, &item.DateUpdated.Valid, // sql.NullTime
&item.Name.String, &item.Name.Valid, // sql.NullString
)
return item, err
}
func (h *` + data.Name + `Handler) getTotalCount(ctx context.Context, dbConn *sql.DB, filter models` + data.NameLower + `.` + data.Name + `Filter, total *int) error {
whereClause, args := h.buildWhereClause(filter)