package handlers import ( "context" "fmt" "net/http" "time" "api-service/internal/config" models "api-service/internal/models/bpjs/vclaim" services "api-service/internal/services/bpjs" "github.com/gin-gonic/gin" ) type SepHandler struct { service services.VClaimService } func NewSepHandler(cfg config.BpjsConfig) *SepHandler { return &SepHandler{ service: services.NewService(cfg), } } // CreateSEP godoc // @Summary Create a new SEP // @Description Create a new Surat Eligibilitas Peserta // @Tags bpjs // @Accept json // @Produce json // @Param request body models.SepPostRequest true "SEP creation request" // @Success 200 {object} models.SepResponse "SEP created successfully" // @Failure 400 {object} gin.H "Invalid request" // @Failure 500 {object} gin.H "Internal server error" // @Router /sep [post] func (h *SepHandler) CreateSEP(c *gin.Context) { var req models.SepPostRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": "invalid body", "message": err.Error()}) return } ctx, cancel := context.WithTimeout(c, 30*time.Second) defer cancel() var result map[string]interface{} if err := h.service.Post(ctx, "/SEP/2.0/insert", req, &result); err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": "create failed", "message": err.Error()}) return } c.JSON(http.StatusOK, models.SepResponse{ Message: "SEP berhasil dibuat", Data: result, }) } // UpdateSEP godoc // @Summary Update an existing SEP // @Description Update an existing Surat Eligibilitas Peserta // @Tags bpjs // @Accept json // @Produce json // @Param request body models.SepPutRequest true "SEP update request" // @Success 200 {object} models.SepResponse "SEP updated successfully" // @Failure 400 {object} gin.H "Invalid request" // @Failure 500 {object} gin.H "Internal server error" // @Router /sep [put] func (h *SepHandler) UpdateSEP(c *gin.Context) { var req models.SepPutRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": "invalid body", "message": err.Error()}) return } ctx, cancel := context.WithTimeout(c, 30*time.Second) defer cancel() var result map[string]interface{} if err := h.service.Put(ctx, "/SEP/2.0/update", req, &result); err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": "update failed", "message": err.Error()}) return } c.JSON(http.StatusOK, models.SepResponse{ Message: "SEP berhasil diperbarui", Data: result, }) } // DeleteSEP godoc // @Summary Delete an existing SEP // @Description Delete a Surat Eligibilitas Peserta by noSep // @Tags bpjs // @Accept json // @Produce json // @Param noSep path string true "No SEP" // @Param user query string true "User" // @Success 200 {object} models.SepResponse "SEP deleted successfully" // @Failure 400 {object} gin.H "Invalid request" // @Failure 500 {object} gin.H "Internal server error" // @Router /sep/{noSep} [delete] func (h *SepHandler) DeleteSEP(c *gin.Context) { noSep := c.Param("noSep") user := c.Query("user") if noSep == "" || user == "" { c.JSON(http.StatusBadRequest, gin.H{"error": "noSep & user required"}) return } body := models.SepDeleteRequest{} body.TSep.NoSep = noSep body.TSep.User = user ctx, cancel := context.WithTimeout(c, 30*time.Second) defer cancel() if err := h.service.Delete(ctx, "/SEP/2.0/delete", body); err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": "delete failed", "message": err.Error()}) return } var result map[string]interface{} c.JSON(http.StatusOK, models.SepResponse{ Message: "SEP berhasil dihapus", Data: result, }) } // GetSEP godoc // @Summary Get an existing SEP // @Description Retrieve a Surat Eligibilitas Peserta by noSep // @Tags bpjs // @Accept json // @Produce json // @Param noSep path string true "No SEP" // @Success 200 {object} models.SepResponse "Data SEP retrieved successfully" // @Failure 400 {object} gin.H "Invalid request" // @Failure 500 {object} gin.H "Internal server error" // @Router /sep/{noSep} [get] func (h *SepHandler) GetSEP(c *gin.Context) { noSep := c.Param("noSep") if noSep == "" { c.JSON(http.StatusBadRequest, gin.H{"error": "noSep required"}) return } ctx, cancel := context.WithTimeout(c, 30*time.Second) defer cancel() endpoint := fmt.Sprintf("/SEP/%s", noSep) var result map[string]interface{} if err := h.service.Get(ctx, endpoint, &result); err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": "fetch failed", "message": err.Error()}) return } c.JSON(http.StatusOK, models.SepResponse{ Message: "Data SEP berhasil diambil", Data: result, }) }