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

@@ -25,7 +25,9 @@ type VClaimService interface {
Delete(ctx context.Context, endpoint string, result interface{}) error
GetRawResponse(ctx context.Context, endpoint string) (*ResponDTOVclaim, error)
PostRawResponse(ctx context.Context, endpoint string, payload interface{}) (*ResponDTOVclaim, error)
PutRawResponse(ctx context.Context, endpoint string, payload interface{}) (*ResponDTOVclaim, error)
PatchRawResponse(ctx context.Context, endpoint string, payload interface{}) (*ResponDTOVclaim, error)
DeleteRawResponse(ctx context.Context, endpoint string) (*ResponDTOVclaim, error)
}
// Service struct for VClaim service
@@ -351,6 +353,43 @@ func (s *Service) PatchRawResponse(ctx context.Context, endpoint string, payload
return s.processResponse(res)
}
// PutRawResponse returns raw response without mapping
func (s *Service) PutRawResponse(ctx context.Context, endpoint string, payload interface{}) (*ResponDTOVclaim, error) {
var buf bytes.Buffer
if payload != nil {
if err := json.NewEncoder(&buf).Encode(payload); err != nil {
return nil, fmt.Errorf("failed to encode payload: %w", err)
}
}
req, err := s.prepareRequest(ctx, http.MethodPut, endpoint, &buf)
if err != nil {
return nil, err
}
res, err := s.httpClient.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to execute PUT request: %w", err)
}
return s.processResponse(res)
}
// DeleteRawResponse returns raw response without mapping
func (s *Service) DeleteRawResponse(ctx context.Context, endpoint string) (*ResponDTOVclaim, error) {
req, err := s.prepareRequest(ctx, http.MethodDelete, endpoint, nil)
if err != nil {
return nil, err
}
res, err := s.httpClient.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to execute DELETE request: %w", err)
}
return s.processResponse(res)
}
// mapToResult maps the final response to the result interface
func mapToResult(resp *ResponDTOVclaim, result interface{}) error {
respBytes, err := json.Marshal(resp)