-
Notifications
You must be signed in to change notification settings - Fork 11
/
budget.go
59 lines (48 loc) · 1.8 KB
/
budget.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package cedarcore
import (
"context"
"github.com/guregu/null/zero"
"github.com/cmsgov/easi-app/pkg/appcontext"
"github.com/cmsgov/easi-app/pkg/cedar/core/gen/client/budget"
"github.com/cmsgov/easi-app/pkg/local/cedarcoremock"
"github.com/cmsgov/easi-app/pkg/models"
)
// GetBudgetBySystem queries CEDAR for budget information associated with a particular system, taking the version-independent ID of a system
func (c *Client) GetBudgetBySystem(ctx context.Context, cedarSystemID string) ([]*models.CedarBudget, error) {
if c.mockEnabled {
appcontext.ZLogger(ctx).Info("CEDAR Core is disabled")
if cedarcoremock.IsMockSystem(cedarSystemID) {
return cedarcoremock.GetBudgets(), nil
}
return nil, cedarcoremock.NoSystemFoundError()
}
cedarSystem, err := c.GetSystem(ctx, cedarSystemID)
params := budget.NewBudgetFindParams()
// Construct the parameters
params.SetSystemID(cedarSystem.VersionID.Ptr())
params.HTTPClient = c.hc
if err != nil {
return nil, err
}
// Make the API call
resp, err := c.sdk.Budget.BudgetFind(params, c.auth)
if err != nil {
return nil, err
}
// Convert the auto-generated struct to our own pkg/models struct
retVal := make([]*models.CedarBudget, 0, len(resp.Payload.Budgets))
for _, budget := range resp.Payload.Budgets {
retVal = append(retVal, &models.CedarBudget{
FiscalYear: zero.StringFrom(budget.FiscalYear),
Funding: zero.StringFrom(budget.Funding),
FundingID: zero.StringFrom(budget.FundingID),
FundingSource: zero.StringFrom(budget.FundingSource),
ID: zero.StringFrom(budget.ID),
Name: zero.StringFrom(budget.Name),
ProjectID: zero.StringFromPtr(budget.ProjectID),
ProjectTitle: zero.StringFrom(budget.ProjectTitle),
SystemID: zero.StringFrom(budget.SystemID),
})
}
return retVal, nil
}