update All feture and service
This commit is contained in:
@@ -14,16 +14,27 @@ type Service interface {
|
||||
GetByID(ctx context.Context, id string) (*satusehat.FHIRResponse, error)
|
||||
Search(ctx context.Context, queryParams url.Values) (*satusehat.FHIRResponse, error)
|
||||
}
|
||||
type service struct{ repo Repository }
|
||||
type service struct {
|
||||
repo Repository
|
||||
orgID string
|
||||
}
|
||||
|
||||
func NewService(repo Repository) Service { return &service{repo: repo} }
|
||||
func NewService(repo Repository, orgID string) Service {
|
||||
return &service{repo: repo, orgID: orgID}
|
||||
}
|
||||
func (s *service) Create(ctx context.Context, req ImmunizationRequest) (*satusehat.FHIRResponse, error) {
|
||||
if req.OrganizationID == "" {
|
||||
req.OrganizationID = s.orgID
|
||||
}
|
||||
return s.repo.Create(ctx, MapRequestToFHIR(req))
|
||||
}
|
||||
func (s *service) Update(ctx context.Context, id string, req ImmunizationRequest) (*satusehat.FHIRResponse, error) {
|
||||
if id == "" {
|
||||
return nil, errors.NewValidationError().Message("ID is required").Build()
|
||||
}
|
||||
if req.OrganizationID == "" {
|
||||
req.OrganizationID = s.orgID
|
||||
}
|
||||
payload := MapRequestToFHIR(req)
|
||||
payload.Set("id", id)
|
||||
return s.repo.Update(ctx, id, payload)
|
||||
|
||||
Reference in New Issue
Block a user