Skip to content

Commit

Permalink
Merge branch 'main' into MAIN-B-21675-final
Browse files Browse the repository at this point in the history
  • Loading branch information
WeatherfordAaron authored Jan 9, 2025
2 parents 72178bd + d45a6a6 commit 5854709
Show file tree
Hide file tree
Showing 117 changed files with 8,066 additions and 551 deletions.
3 changes: 3 additions & 0 deletions migrations/app/migrations_manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,9 @@
20241217180136_add_AK_zips_to_zip3_distances.up.sql
20241218201833_add_PPPO_BASE_ELIZABETH.up.sql
20241220171035_add_additional_AK_zips_to_zip3_distances.up.sql
20241220213134_add_destination_gbloc_db_function.up.sql
20241224172258_add_and_update_po_box_zip.up.sql
20241226173330_add_intl_param_values_to_service_params_table.up.sql
20241227153723_remove_empty_string_emplid_values.up.sql
20241227202424_insert_transportation_offices_camp_pendelton.up.sql
20241230190638_remove_AK_zips_from_zip3.up.sql
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
-- this function will handle getting the destination GBLOC associated with a shipment's destination address
-- this only applies to OCONUS destination addresses on a shipment, but this can also checks domestic shipments
CREATE OR REPLACE FUNCTION get_destination_gbloc_for_shipment(shipment_id UUID)
RETURNS TEXT AS $$
DECLARE
service_member_affiliation TEXT;
zip TEXT;
gbloc_result TEXT;
alaska_zone_ii BOOLEAN;
market_code TEXT;
BEGIN
-- get the shipment's market code to determine conditionals
SELECT ms.market_code
INTO market_code
FROM mto_shipments ms
WHERE ms.id = shipment_id;

-- if it's a domestic shipment, use postal_code_to_gblocs
IF market_code = 'd' THEN
SELECT upc.uspr_zip_id
INTO zip
FROM addresses a
JOIN us_post_region_cities upc ON a.us_post_region_cities_id = upc.id
WHERE a.id = (SELECT destination_address_id FROM mto_shipments WHERE id = shipment_id);

SELECT gbloc
INTO gbloc_result
FROM postal_code_to_gblocs
WHERE postal_code = zip
LIMIT 1;

IF gbloc_result IS NULL THEN
RETURN NULL;
END IF;

RETURN gbloc_result;

ELSEIF market_code = 'i' THEN
-- if it's 'i' then we need to check for some exceptions
SELECT sm.affiliation
INTO service_member_affiliation
FROM service_members sm
JOIN orders o ON o.service_member_id = sm.id
JOIN moves m ON m.orders_id = o.id
JOIN mto_shipments ms ON ms.move_id = m.id
WHERE ms.id = shipment_id;

-- if the service member is USMC, return 'USMC'
IF service_member_affiliation = 'MARINES' THEN
RETURN 'USMC';
END IF;

SELECT upc.uspr_zip_id
INTO zip
FROM addresses a
JOIN us_post_region_cities upc ON a.us_post_region_cities_id = upc.id
WHERE a.id = (SELECT destination_address_id FROM mto_shipments WHERE id = shipment_id);

-- check if the postal code (uspr_zip_id) is in Alaska Zone II
SELECT EXISTS (
SELECT 1
FROM re_oconus_rate_areas ro
JOIN re_rate_areas ra ON ro.rate_area_id = ra.id
JOIN us_post_region_cities upc ON upc.id = ro.us_post_region_cities_id
WHERE upc.uspr_zip_id = zip
AND ra.code = 'US8190100' -- Alaska Zone II Code
)
INTO alaska_zone_ii;

-- if the service member is USAF or USSF and the address is in Alaska Zone II, return 'MBFL'
IF (service_member_affiliation = 'AIR_FORCE' OR service_member_affiliation = 'SPACE_FORCE') AND alaska_zone_ii THEN
RETURN 'MBFL';
END IF;

-- for all other branches except USMC, return the gbloc from the postal_code_to_gbloc table based on the zip
SELECT gbloc
INTO gbloc_result
FROM postal_code_to_gblocs
WHERE postal_code = zip
LIMIT 1;

IF gbloc_result IS NULL THEN
RETURN NULL;
END IF;

RETURN gbloc_result;
END IF;

END;
$$ LANGUAGE plpgsql;
2,721 changes: 2,721 additions & 0 deletions migrations/app/schema/20241224172258_add_and_update_po_box_zip.up.sql

Large diffs are not rendered by default.

Large diffs are not rendered by default.

34 changes: 25 additions & 9 deletions pkg/factory/address_factory.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package factory

import (
"database/sql"

"github.com/gobuffalo/pop/v6"
"github.com/gofrs/uuid"

"github.com/transcom/mymove/pkg/models"
"github.com/transcom/mymove/pkg/testdatagen"
Expand All @@ -24,15 +27,17 @@ func BuildAddress(db *pop.Connection, customs []Customization, traits []Trait) m
}

// Create default Address
beverlyHillsUsprc := uuid.FromStringOrNil("3b9f0ae6-3b2b-44a6-9fcd-8ead346648c4")
address := models.Address{
StreetAddress1: "123 Any Street",
StreetAddress2: models.StringPointer("P.O. Box 12345"),
StreetAddress3: models.StringPointer("c/o Some Person"),
City: "Beverly Hills",
State: "CA",
PostalCode: "90210",
County: models.StringPointer("LOS ANGELES"),
IsOconus: models.BoolPointer(false),
StreetAddress1: "123 Any Street",
StreetAddress2: models.StringPointer("P.O. Box 12345"),
StreetAddress3: models.StringPointer("c/o Some Person"),
City: "Beverly Hills",
State: "CA",
PostalCode: "90210",
County: models.StringPointer("LOS ANGELES"),
IsOconus: models.BoolPointer(false),
UsPostRegionCityID: &beverlyHillsUsprc,
}

// Find/create the Country if customization is provided
Expand All @@ -56,7 +61,7 @@ func BuildAddress(db *pop.Connection, customs []Customization, traits []Trait) m
// Overwrite values with those from customizations
testdatagen.MergeModels(&address, cAddress)

// This helps assign counties when the factory is called for seed data or tests
// This helps assign counties & us_post_region_cities_id values when the factory is called for seed data or tests
// Additionally, also only run if not 90210. 90210's county is by default populated
if db != nil && address.PostalCode != "90210" {
county, err := models.FindCountyByZipCode(db, address.PostalCode)
Expand All @@ -72,6 +77,17 @@ func BuildAddress(db *pop.Connection, customs []Customization, traits []Trait) m
address.County = models.StringPointer("db nil when created")
}

if db != nil && address.PostalCode != "90210" && cAddress.UsPostRegionCityID == nil {
usprc, err := models.FindByZipCode(db, address.PostalCode)
if err != nil && err != sql.ErrNoRows {
address.UsPostRegionCityID = nil
address.UsPostRegionCity = nil
} else if usprc.ID != uuid.Nil {
address.UsPostRegionCityID = &usprc.ID
address.UsPostRegionCity = usprc
}
}

// If db is false, it's a stub. No need to create in database.
if db != nil {
mustCreate(db, &address)
Expand Down
1 change: 1 addition & 0 deletions pkg/factory/address_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (suite *FactorySuite) TestBuildAddress() {
suite.Equal(defaultPostalCode, address.PostalCode)
suite.Equal(country.ID, *address.CountryId)
suite.Equal(defaultCounty, *address.County)
suite.NotNil(*address.UsPostRegionCityID)
})

suite.Run("Successful creation of an address with customization", func() {
Expand Down
10 changes: 10 additions & 0 deletions pkg/gen/ghcapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions pkg/gen/ghcmessages/address.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions pkg/gen/internalapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions pkg/gen/internalmessages/address.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions pkg/gen/pptasapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions pkg/gen/pptasmessages/address.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5854709

Please sign in to comment.