first commit
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package antrol
|
||||
|
||||
// Poli merepresentasikan data referensi poli dari API Antrean RS BPJS
|
||||
type Poli struct {
|
||||
KdPoli string `json:"kdpoli"`
|
||||
NmPoli string `json:"nmpoli"`
|
||||
KdSubSpesialis string `json:"kdsubspesialis"`
|
||||
NmSubSpesialis string `json:"nmsubspesialis"`
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package antrol
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"service/internal/interfaces/bpjs"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
GetRefPoli(ctx context.Context) ([]Poli, error)
|
||||
}
|
||||
|
||||
type repository struct {
|
||||
client bpjs.BpjsClient
|
||||
}
|
||||
|
||||
func NewRepository(client bpjs.BpjsClient) Repository {
|
||||
return &repository{client: client}
|
||||
}
|
||||
|
||||
// GetRefPoli fetches referensi poli from BPJS API
|
||||
//
|
||||
// # This function will return an array of Poli and error if any
|
||||
//
|
||||
// Context is used to pass the request context to the underlying
|
||||
// client
|
||||
//
|
||||
// The function will return an error if the request to BPJS API
|
||||
// fails or if the response cannot be unmarshalled into an array
|
||||
// of Poli
|
||||
//
|
||||
// The function will return an empty array and nil error if the request
|
||||
// to BPJS API succeeds but the response is an empty array
|
||||
func (r *repository) GetRefPoli(ctx context.Context) ([]Poli, error) {
|
||||
respBytes, err := r.client.DoRequest(ctx, "GET", "ref/poli", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result []Poli
|
||||
if err := json.Unmarshal(respBytes, &result); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal ref poli antrol response: %w", err)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package antrol
|
||||
|
||||
import (
|
||||
"context"
|
||||
"service/pkg/errors"
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
GetRefPoli(ctx context.Context) ([]Poli, error)
|
||||
}
|
||||
|
||||
type service struct {
|
||||
repo Repository
|
||||
}
|
||||
|
||||
func NewService(repo Repository) Service {
|
||||
return &service{repo: repo}
|
||||
}
|
||||
|
||||
func (s *service) GetRefPoli(ctx context.Context) ([]Poli, error) {
|
||||
res, err := s.repo.GetRefPoli(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.ExternalError().Message("Gagal mengambil referensi poli Antrean RS BPJS").Cause(err).Build()
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
Reference in New Issue
Block a user