Skip to content

Commit

Permalink
convert lifecycle costlines to use 64bit integers
Browse files Browse the repository at this point in the history
  • Loading branch information
mynar7 committed Jan 14, 2025
1 parent 33e1ec8 commit a3f3f5d
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 15 deletions.
6 changes: 3 additions & 3 deletions cmd/devdata/system_intake_business_case_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func makeFinalBusinessCaseV1(ctx context.Context, name string, store *storage.St
for i, v := range []string{"1", "2", "3", "4", "5"} {
phase1 := models.LifecycleCostPhaseDEVELOPMENT
phase2 := models.LifecycleCostPhaseOPERATIONMAINTENANCE
cost := (i + 1) * 100
cost := int64((i + 1) * 10000000000000000)
estimatedLifeCycleCost := models.EstimatedLifecycleCost{
Solution: models.LifecycleCostSolutionPREFERRED,
Year: models.LifecycleCostYear(v),
Expand Down Expand Up @@ -86,8 +86,8 @@ func makeBusinessCaseV1(ctx context.Context, name string, store *storage.Store,
}

phase := models.LifecycleCostPhaseDEVELOPMENT
cost := 123456
noCost := 0
cost := int64(123456)
noCost := int64(0)
businessCase := models.BusinessCase{
CreatedAt: helpers.PointerTo(time.Now().AddDate(0, 0, -2)),
UpdatedAt: helpers.PointerTo(time.Now()),
Expand Down
2 changes: 1 addition & 1 deletion cmd/test_cedar_intake/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func makeTestBusinessCase(times usefulTimes, systemIntake models.SystemIntake) *
phase := phase

// make a copy, so when we increment costAmount, previously created lifecycleCost.Cost's don't point to the updated value
cost := increasingCost
cost := int64(increasingCost)

lifecycleCost := models.EstimatedLifecycleCost{
ID: uuid.New(),
Expand Down
1 change: 1 addition & 0 deletions migrations/V198__Make_Costs_BigInt.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE estimated_lifecycle_costs ALTER COLUMN cost TYPE bigint;
6 changes: 3 additions & 3 deletions pkg/appvalidation/business_case.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func alternativeBRequired(businessCase *models.BusinessCaseWithCosts) bool {
businessCase.AlternativeBCostSavings.Valid
}

type solutionCostLines map[string]map[string]int
type solutionCostLines map[string]map[string]int64

func validateRequiredCost(lines solutionCostLines) string {
years := []string{}
Expand Down Expand Up @@ -142,14 +142,14 @@ func validateAllRequiredLifecycleCosts(businessCase *models.BusinessCaseWithCost
valid = false
}

if validate.RequireInt(cost.Cost) {
if validate.RequireInt64(cost.Cost) {
solutionYearPhase := string(cost.Solution) + string(cost.Year) + string(*cost.Phase)
validations[solutionYearPhase] = "requires a cost"
valid = false
}

if valid {
value := map[string]int{
value := map[string]int64{
string(*cost.Phase): *cost.Cost,
}
switch cost.Solution {
Expand Down
4 changes: 2 additions & 2 deletions pkg/appvalidation/business_case_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (s *AppValidateTestSuite) TestValidateAllRequiredLifecycleCosts() {
intake := testhelpers.NewSystemIntake()
businessCase := testhelpers.NewBusinessCase(intake.ID)
dev := models.LifecycleCostPhaseDEVELOPMENT
cost := 300
cost := int64(300)

s.Run("golden path", func() {
businessCase.LifecycleCostLines = testhelpers.NewValidLifecycleCosts(&businessCase.ID)
Expand Down Expand Up @@ -266,7 +266,7 @@ func (s *AppValidateTestSuite) TestBusinessCaseForSubmit() {
businessCase := models.BusinessCaseWithCosts{
BusinessCase: models.BusinessCase{},
}
cost := 300
cost := int64(300)
businessCase.LifecycleCostLines = models.EstimatedLifecycleCosts{
models.EstimatedLifecycleCost{
Solution: models.LifecycleCostSolutionPREFERRED,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cedar/intake/translation/biz.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (bc *TranslatableBusinessCase) CreateIntakeModel(ctx context.Context) (*wir

cost := ""
if line.Cost != nil {
cost = strconv.Itoa(*line.Cost)
cost = strconv.FormatInt(*line.Cost, 10)
}
lc.Cost = pStr(cost)

Expand Down
2 changes: 1 addition & 1 deletion pkg/graph/schema.resolvers_business_case_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (s *GraphQLTestSuite) TestFetchBusinessCaseWithCostLinesForSystemIntakeQuer
dev := models.LifecycleCostPhaseDEVELOPMENT
oam := models.LifecycleCostPhaseOPERATIONMAINTENANCE
other := models.LifecycleCostPhaseOTHER
cost := 1234
cost := int64(1234)
lifecycleCostLines := models.EstimatedLifecycleCosts{
models.EstimatedLifecycleCost{
Solution: models.LifecycleCostSolutionPREFERRED,
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/business_case.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type EstimatedLifecycleCost struct {
Solution LifecycleCostSolution `json:"solution"`
Phase *LifecycleCostPhase `json:"phase"`
Year LifecycleCostYear `json:"year"`
Cost *int `json:"cost"`
Cost *int64 `json:"cost"`
}

func (e EstimatedLifecycleCost) GetMappingKey() uuid.UUID {
Expand Down
6 changes: 3 additions & 3 deletions pkg/testhelpers/business_case.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ type EstimatedLifecycleCostOptions struct {
Solution *models.LifecycleCostSolution
Phase *models.LifecycleCostPhase
Year *models.LifecycleCostYear
Cost *int
Cost *int64
}

// NewEstimatedLifecycleCost helps generate a new lifecycle cost for a given business case
func NewEstimatedLifecycleCost(opts EstimatedLifecycleCostOptions) models.EstimatedLifecycleCost {
development := models.LifecycleCostPhaseDEVELOPMENT
cost := 100
cost := int64(100)
elc := models.EstimatedLifecycleCost{
ID: uuid.New(),
BusinessCaseID: uuid.New(),
Expand Down Expand Up @@ -53,7 +53,7 @@ func NewValidLifecycleCosts(id *uuid.UUID) models.EstimatedLifecycleCosts {
dev := models.LifecycleCostPhaseDEVELOPMENT
om := models.LifecycleCostPhaseOPERATIONMAINTENANCE
other := models.LifecycleCostPhaseOTHER
cost := 100
cost := int64(100)
return models.EstimatedLifecycleCosts{
models.EstimatedLifecycleCost{
BusinessCaseID: *id,
Expand Down
5 changes: 5 additions & 0 deletions pkg/validate/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func RequireInt(i *int) bool {
return i == nil
}

// RequireInt64 checks if it's not nil
func RequireInt64(i *int64) bool {
return i == nil
}

// RequireCostPhase checks if it's not nil
func RequireCostPhase(p *models.LifecycleCostPhase) bool {
return p == nil
Expand Down

0 comments on commit a3f3f5d

Please sign in to comment.