/
contract.go
73 lines (62 loc) · 2.21 KB
/
contract.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package cedarcore
import (
"context"
"strings"
"time"
"github.com/guregu/null/zero"
"github.com/cmsgov/easi-app/pkg/appcontext"
"github.com/cmsgov/easi-app/pkg/cedar/core/gen/client/contract"
"github.com/cmsgov/easi-app/pkg/local/cedarcoremock"
"github.com/cmsgov/easi-app/pkg/models"
)
// GetContractBySystem queries CEDAR for contract information associated with a particular system, taking the version-independent ID of a system
func (c *Client) GetContractBySystem(ctx context.Context, cedarSystemID string) ([]*models.CedarContract, error) {
if c.mockEnabled {
appcontext.ZLogger(ctx).Info("CEDAR Core is disabled")
if cedarcoremock.IsMockSystem(cedarSystemID) {
return cedarcoremock.GetContractsBySystem(cedarSystemID), nil
}
return nil, cedarcoremock.NoSystemFoundError()
}
cedarSystem, err := c.GetSystem(ctx, cedarSystemID)
if err != nil {
return nil, err
}
params := contract.NewContractFindParams()
// Construct the parameters
params.SetSystemID(cedarSystem.VersionID.Ptr())
params.HTTPClient = c.hc
// Make the API call
resp, err := c.sdk.Contract.ContractFind(params, c.auth)
if err != nil {
return nil, err
}
// Convert the auto-generated struct to our own pkg/models struct
retVal := make([]*models.CedarContract, 0, len(resp.Payload.Contracts))
for _, contract := range resp.Payload.Contracts {
var isDeliveryOrg bool
if strings.ToLower(contract.IsDeliveryOrg) == "yes" {
isDeliveryOrg = true
}
endDate, err := time.Parse(time.RFC3339, contract.POPEndDate)
if err != nil {
endDate = time.Time{}
}
startDate, err := time.Parse(time.RFC3339, contract.POPStartDate)
if err != nil {
startDate = time.Time{}
}
retVal = append(retVal, &models.CedarContract{
EndDate: zero.TimeFrom(endDate),
StartDate: zero.TimeFrom(startDate),
ContractNumber: zero.StringFrom(contract.ContractNumber),
ContractName: zero.StringFrom(contract.ProjectTitle),
Description: zero.StringFrom(contract.Description),
OrderNumber: zero.StringFrom(contract.OrderNumber),
ServiceProvided: zero.StringFrom(contract.ServiceProvided),
IsDeliveryOrg: isDeliveryOrg,
SystemID: zero.StringFrom(contract.SystemID),
})
}
return retVal, nil
}